api.js 21.5 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6
"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
7 8 9 10
const fs = require("fs");
const ts = require("typescript");
const path = require("path");
const util = require("gulp-util");
11
const dtsv = '1';
12 13 14
const tsfmt = require('../../tsfmt.json');
function log(message, ...rest) {
    util.log(util.colors.cyan('[monaco.d.ts]'), message, ...rest);
J
Joao Moreno 已提交
15
}
16 17
const SRC = path.join(__dirname, '../../src');
const OUT_ROOT = path.join(__dirname, '../../');
A
Alex Dima 已提交
18
exports.RECIPE_PATH = path.join(__dirname, './monaco.d.ts.recipe');
19
const DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts');
J
Joao Moreno 已提交
20
var CURRENT_PROCESSING_RULE = '';
21
function logErr(message, ...rest) {
J
Joao Moreno 已提交
22
    util.log(util.colors.red('[monaco.d.ts]'), 'WHILE HANDLING RULE: ', CURRENT_PROCESSING_RULE);
23
    util.log(util.colors.red('[monaco.d.ts]'), message, ...rest);
J
Joao Moreno 已提交
24
}
25 26 27
function _logErr(message, ...rest) {
    util.log(util.colors.red(`[monaco.d.ts]`), message, ...rest);
}
J
Joao Moreno 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
function moduleIdToPath(out, moduleId) {
    if (/\.d\.ts/.test(moduleId)) {
        return path.join(SRC, moduleId);
    }
    return path.join(OUT_ROOT, out, moduleId) + '.d.ts';
}
function isDeclaration(a) {
    return (a.kind === ts.SyntaxKind.InterfaceDeclaration
        || a.kind === ts.SyntaxKind.EnumDeclaration
        || a.kind === ts.SyntaxKind.ClassDeclaration
        || a.kind === ts.SyntaxKind.TypeAliasDeclaration
        || a.kind === ts.SyntaxKind.FunctionDeclaration
        || a.kind === ts.SyntaxKind.ModuleDeclaration);
}
function visitTopLevelDeclarations(sourceFile, visitor) {
43 44
    let stop = false;
    let visit = (node) => {
J
Joao Moreno 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
        if (stop) {
            return;
        }
        switch (node.kind) {
            case ts.SyntaxKind.InterfaceDeclaration:
            case ts.SyntaxKind.EnumDeclaration:
            case ts.SyntaxKind.ClassDeclaration:
            case ts.SyntaxKind.VariableStatement:
            case ts.SyntaxKind.TypeAliasDeclaration:
            case ts.SyntaxKind.FunctionDeclaration:
            case ts.SyntaxKind.ModuleDeclaration:
                stop = visitor(node);
        }
        if (stop) {
            return;
        }
        ts.forEachChild(node, visit);
    };
    visit(sourceFile);
}
function getAllTopLevelDeclarations(sourceFile) {
66 67
    let all = [];
    visitTopLevelDeclarations(sourceFile, (node) => {
J
Joao Moreno 已提交
68
        if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) {
69 70 71 72
            let interfaceDeclaration = node;
            let triviaStart = interfaceDeclaration.pos;
            let triviaEnd = interfaceDeclaration.name.pos;
            let triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd });
J
Joao Moreno 已提交
73 74 75 76 77
            if (triviaText.indexOf('@internal') === -1) {
                all.push(node);
            }
        }
        else {
78
            let nodeText = getNodeText(sourceFile, node);
J
Joao Moreno 已提交
79 80 81 82 83 84 85 86 87
            if (nodeText.indexOf('@internal') === -1) {
                all.push(node);
            }
        }
        return false /*continue*/;
    });
    return all;
}
function getTopLevelDeclaration(sourceFile, typeName) {
88 89
    let result = null;
    visitTopLevelDeclarations(sourceFile, (node) => {
M
Matt Bierner 已提交
90
        if (isDeclaration(node) && node.name) {
J
Joao Moreno 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
            if (node.name.text === typeName) {
                result = node;
                return true /*stop*/;
            }
            return false /*continue*/;
        }
        // node is ts.VariableStatement
        if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) {
            result = node;
            return true /*stop*/;
        }
        return false /*continue*/;
    });
    return result;
}
function getNodeText(sourceFile, node) {
    return sourceFile.getFullText().substring(node.pos, node.end);
}
109 110
function hasModifier(modifiers, kind) {
    if (modifiers) {
111 112
        for (let i = 0; i < modifiers.length; i++) {
            let mod = modifiers[i];
113 114 115 116 117 118 119 120 121 122 123 124 125 126
            if (mod.kind === kind) {
                return true;
            }
        }
    }
    return false;
}
function isStatic(member) {
    return hasModifier(member.modifiers, ts.SyntaxKind.StaticKeyword);
}
function isDefaultExport(declaration) {
    return (hasModifier(declaration.modifiers, ts.SyntaxKind.DefaultKeyword)
        && hasModifier(declaration.modifiers, ts.SyntaxKind.ExportKeyword));
}
127
function getMassagedTopLevelDeclarationText(sourceFile, declaration, importName, usage, enums) {
128
    let result = getNodeText(sourceFile, declaration);
J
Joao Moreno 已提交
129
    if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) {
130 131 132 133 134 135
        let interfaceDeclaration = declaration;
        const staticTypeName = (isDefaultExport(interfaceDeclaration)
            ? `${importName}.default`
            : `${importName}.${declaration.name.text}`);
        let instanceTypeName = staticTypeName;
        const typeParametersCnt = (interfaceDeclaration.typeParameters ? interfaceDeclaration.typeParameters.length : 0);
136
        if (typeParametersCnt > 0) {
137 138
            let arr = [];
            for (let i = 0; i < typeParametersCnt; i++) {
139 140
                arr.push('any');
            }
141
            instanceTypeName = `${instanceTypeName}<${arr.join(',')}>`;
142
        }
143 144
        const members = interfaceDeclaration.members;
        members.forEach((member) => {
J
Joao Moreno 已提交
145
            try {
146
                let memberText = getNodeText(sourceFile, member);
J
Joao Moreno 已提交
147 148 149
                if (memberText.indexOf('@internal') >= 0 || memberText.indexOf('private') >= 0) {
                    result = result.replace(memberText, '');
                }
150
                else {
151
                    const memberName = member.name.text;
152
                    if (isStatic(member)) {
153
                        usage.push(`a = ${staticTypeName}.${memberName};`);
154 155
                    }
                    else {
156
                        usage.push(`a = (<${instanceTypeName}>b).${memberName};`);
157 158
                    }
                }
J
Joao Moreno 已提交
159 160 161 162 163 164 165 166
            }
            catch (err) {
                // life..
            }
        });
    }
    result = result.replace(/export default/g, 'export');
    result = result.replace(/export declare/g, 'export');
167 168 169 170
    if (declaration.kind === ts.SyntaxKind.EnumDeclaration) {
        result = result.replace(/const enum/, 'enum');
        enums.push(result);
    }
J
Joao Moreno 已提交
171 172
    return result;
}
A
Alex Dima 已提交
173 174 175 176 177 178
function format(text, endl) {
    const REALLY_FORMAT = false;
    text = preformat(text, endl);
    if (!REALLY_FORMAT) {
        return text;
    }
J
Joao Moreno 已提交
179
    // Parse the source text
180
    let sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true);
J
Joao Moreno 已提交
181
    // Get the formatting edits on the input sources
182
    let edits = ts.formatting.formatDocument(sourceFile, getRuleProvider(tsfmt), tsfmt);
J
Joao Moreno 已提交
183 184
    // Apply the edits on the input code
    return applyEdits(text, edits);
A
Alex Dima 已提交
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    function countParensCurly(text) {
        let cnt = 0;
        for (let i = 0; i < text.length; i++) {
            if (text.charAt(i) === '(' || text.charAt(i) === '{') {
                cnt++;
            }
            if (text.charAt(i) === ')' || text.charAt(i) === '}') {
                cnt--;
            }
        }
        return cnt;
    }
    function repeatStr(s, cnt) {
        let r = '';
        for (let i = 0; i < cnt; i++) {
            r += s;
        }
        return r;
    }
    function preformat(text, endl) {
        let lines = text.split(endl);
        let inComment = false;
        let inCommentDeltaIndent = 0;
        let indent = 0;
        for (let i = 0; i < lines.length; i++) {
            let line = lines[i].replace(/\s$/, '');
            let repeat = false;
            let lineIndent = 0;
            do {
                repeat = false;
                if (line.substring(0, 4) === '    ') {
                    line = line.substring(4);
                    lineIndent++;
                    repeat = true;
                }
                if (line.charAt(0) === '\t') {
                    line = line.substring(1);
                    lineIndent++;
                    repeat = true;
                }
            } while (repeat);
            if (line.length === 0) {
                continue;
            }
            if (inComment) {
                if (/\*\//.test(line)) {
                    inComment = false;
                }
                lines[i] = repeatStr('\t', lineIndent + inCommentDeltaIndent) + line;
                continue;
            }
            if (/\/\*/.test(line)) {
                inComment = true;
                inCommentDeltaIndent = indent - lineIndent;
                lines[i] = repeatStr('\t', indent) + line;
                continue;
            }
            const cnt = countParensCurly(line);
            let shouldUnindentAfter = false;
            let shouldUnindentBefore = false;
            if (cnt < 0) {
                if (/[({]/.test(line)) {
                    shouldUnindentAfter = true;
                }
                else {
                    shouldUnindentBefore = true;
                }
            }
            else if (cnt === 0) {
                shouldUnindentBefore = /^\}/.test(line);
            }
            let shouldIndentAfter = false;
            if (cnt > 0) {
                shouldIndentAfter = true;
            }
            else if (cnt === 0) {
                shouldIndentAfter = /{$/.test(line);
            }
            if (shouldUnindentBefore) {
                indent--;
            }
            lines[i] = repeatStr('\t', indent) + line;
            if (shouldUnindentAfter) {
                indent--;
            }
            if (shouldIndentAfter) {
                indent++;
            }
        }
        return lines.join(endl);
    }
J
Joao Moreno 已提交
276 277 278
    function getRuleProvider(options) {
        // Share this between multiple formatters using the same options.
        // This represents the bulk of the space the formatter uses.
M
Matt Bierner 已提交
279
        return ts.formatting.getFormatContext(options);
J
Joao Moreno 已提交
280 281 282
    }
    function applyEdits(text, edits) {
        // Apply edits in reverse on the existing text
283 284 285 286 287
        let result = text;
        for (let i = edits.length - 1; i >= 0; i--) {
            let change = edits[i];
            let head = result.slice(0, change.span.start);
            let tail = result.slice(change.span.start + change.span.length);
J
Joao Moreno 已提交
288 289 290 291 292 293 294
            result = head + change.newText + tail;
        }
        return result;
    }
}
function createReplacer(data) {
    data = data || '';
295 296 297
    let rawDirectives = data.split(';');
    let directives = [];
    rawDirectives.forEach((rawDirective) => {
J
Joao Moreno 已提交
298 299 300
        if (rawDirective.length === 0) {
            return;
        }
301 302 303
        let pieces = rawDirective.split('=>');
        let findStr = pieces[0];
        let replaceStr = pieces[1];
J
Joao Moreno 已提交
304 305 306 307
        findStr = findStr.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&');
        findStr = '\\b' + findStr + '\\b';
        directives.push([new RegExp(findStr, 'g'), replaceStr]);
    });
308 309
    return (str) => {
        for (let i = 0; i < directives.length; i++) {
J
Joao Moreno 已提交
310 311 312 313 314
            str = str.replace(directives[i][0], directives[i][1]);
        }
        return str;
    };
}
315
function generateDeclarationFile(recipe, sourceFileGetter) {
316 317 318 319 320 321
    const endl = /\r\n/.test(recipe) ? '\r\n' : '\n';
    let lines = recipe.split(endl);
    let result = [];
    let usageCounter = 0;
    let usageImports = [];
    let usage = [];
322
    let failed = false;
323 324 325 326 327
    usage.push(`var a;`);
    usage.push(`var b;`);
    const generateUsageImport = (moduleId) => {
        let importName = 'm' + (++usageCounter);
        usageImports.push(`import * as ${importName} from './${moduleId.replace(/\.d\.ts$/, '')}';`);
328 329
        return importName;
    };
330
    let enums = [];
331
    let version = null;
332
    lines.forEach(line => {
333 334 335 336 337 338 339
        if (failed) {
            return;
        }
        let m0 = line.match(/^\/\/dtsv=(\d+)$/);
        if (m0) {
            version = m0[1];
        }
340
        let m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
J
Joao Moreno 已提交
341 342
        if (m1) {
            CURRENT_PROCESSING_RULE = line;
343
            let moduleId = m1[1];
344
            const sourceFile = sourceFileGetter(moduleId);
345
            if (!sourceFile) {
346 347
                _logErr(`gulp watch restart required. ${moduleId} was added to 'monaco.d.ts.recipe'.`);
                failed = true;
J
Joao Moreno 已提交
348 349
                return;
            }
350 351 352 353
            const importName = generateUsageImport(moduleId);
            let replacer = createReplacer(m1[2]);
            let typeNames = m1[3].split(/,/);
            typeNames.forEach((typeName) => {
J
Joao Moreno 已提交
354 355 356 357
                typeName = typeName.trim();
                if (typeName.length === 0) {
                    return;
                }
358
                let declaration = getTopLevelDeclaration(sourceFile, typeName);
J
Joao Moreno 已提交
359 360 361 362
                if (!declaration) {
                    logErr('Cannot find type ' + typeName);
                    return;
                }
363
                result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration, importName, usage, enums)));
J
Joao Moreno 已提交
364 365 366
            });
            return;
        }
367
        let m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
J
Joao Moreno 已提交
368 369
        if (m2) {
            CURRENT_PROCESSING_RULE = line;
370
            let moduleId = m2[1];
371
            const sourceFile = sourceFileGetter(moduleId);
372
            if (!sourceFile) {
373 374
                _logErr(`gulp watch restart required. ${moduleId} was added to 'monaco.d.ts.recipe'.`);
                failed = true;
J
Joao Moreno 已提交
375 376
                return;
            }
377 378 379 380 381 382
            const importName = generateUsageImport(moduleId);
            let replacer = createReplacer(m2[2]);
            let typeNames = m2[3].split(/,/);
            let typesToExcludeMap = {};
            let typesToExcludeArr = [];
            typeNames.forEach((typeName) => {
J
Joao Moreno 已提交
383 384 385 386
                typeName = typeName.trim();
                if (typeName.length === 0) {
                    return;
                }
387 388
                typesToExcludeMap[typeName] = true;
                typesToExcludeArr.push(typeName);
J
Joao Moreno 已提交
389
            });
390
            getAllTopLevelDeclarations(sourceFile).forEach((declaration) => {
M
Matt Bierner 已提交
391
                if (isDeclaration(declaration) && declaration.name) {
392
                    if (typesToExcludeMap[declaration.name.text]) {
J
Joao Moreno 已提交
393 394 395 396 397
                        return;
                    }
                }
                else {
                    // node is ts.VariableStatement
398 399 400
                    let nodeText = getNodeText(sourceFile, declaration);
                    for (let i = 0; i < typesToExcludeArr.length; i++) {
                        if (nodeText.indexOf(typesToExcludeArr[i]) >= 0) {
J
Joao Moreno 已提交
401 402 403 404
                            return;
                        }
                    }
                }
405
                result.push(replacer(getMassagedTopLevelDeclarationText(sourceFile, declaration, importName, usage, enums)));
J
Joao Moreno 已提交
406 407 408 409 410
            });
            return;
        }
        result.push(line);
    });
411 412 413 414 415 416 417 418 419 420 421 422
    if (failed) {
        return null;
    }
    if (version !== dtsv) {
        if (!version) {
            _logErr(`gulp watch restart required. 'monaco.d.ts.recipe' is written before versioning was introduced.`);
        }
        else {
            _logErr(`gulp watch restart required. 'monaco.d.ts.recipe' v${version} does not match runtime v${dtsv}.`);
        }
        return null;
    }
423
    let resultTxt = result.join(endl);
J
Joao Moreno 已提交
424 425
    resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri');
    resultTxt = resultTxt.replace(/\bEvent</g, 'IEvent<');
A
Alex Dima 已提交
426
    resultTxt = format(resultTxt, endl);
427 428 429 430 431 432 433 434 435
    let resultEnums = [
        '/*---------------------------------------------------------------------------------------------',
        ' *  Copyright (c) Microsoft Corporation. All rights reserved.',
        ' *  Licensed under the MIT License. See License.txt in the project root for license information.',
        ' *--------------------------------------------------------------------------------------------*/',
        '',
        '// THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY.',
        ''
    ].concat(enums).join(endl);
436
    resultEnums = resultEnums.split(/\r\n|\n|\r/).join(endl);
437
    resultEnums = format(resultEnums, endl);
438 439 440 441 442
    return {
        result: resultTxt,
        usageContent: `${usageImports.join('\n')}\n\n${usage.join('\n')}`,
        enums: resultEnums
    };
J
Joao Moreno 已提交
443
}
444
function getIncludesInRecipe() {
A
Alex Dima 已提交
445
    let recipe = fs.readFileSync(exports.RECIPE_PATH).toString();
446 447 448 449
    let lines = recipe.split(/\r\n|\n|\r/);
    let result = [];
    lines.forEach(line => {
        let m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
J
Joao Moreno 已提交
450
        if (m1) {
451
            let moduleId = m1[1];
452
            result.push(moduleId);
J
Joao Moreno 已提交
453 454
            return;
        }
455
        let m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/);
J
Joao Moreno 已提交
456
        if (m2) {
457
            let moduleId = m2[1];
458
            result.push(moduleId);
J
Joao Moreno 已提交
459 460 461 462 463
            return;
        }
    });
    return result;
}
A
Alex Dima 已提交
464
exports.getIncludesInRecipe = getIncludesInRecipe;
465
function getFilesToWatch(out) {
466
    return getIncludesInRecipe().map((moduleId) => moduleIdToPath(out, moduleId));
467
}
J
Joao Moreno 已提交
468
exports.getFilesToWatch = getFilesToWatch;
469
function _run(sourceFileGetter) {
J
Joao Moreno 已提交
470
    log('Starting monaco.d.ts generation');
A
Alex Dima 已提交
471
    const recipe = fs.readFileSync(exports.RECIPE_PATH).toString();
472 473 474 475 476 477 478
    const t = generateDeclarationFile(recipe, sourceFileGetter);
    if (!t) {
        return null;
    }
    const result = t.result;
    const usageContent = t.usageContent;
    const enums = t.enums;
A
Alex Dima 已提交
479
    const currentContent = fs.readFileSync(DECLARATION_PATH).toString();
480 481
    const one = currentContent.replace(/\r\n/gm, '\n');
    const other = result.replace(/\r\n/gm, '\n');
482
    const isTheSame = (one === other);
A
Alex Dima 已提交
483
    log('Finished monaco.d.ts generation');
J
Joao Moreno 已提交
484 485
    return {
        content: result,
486
        usageContent: usageContent,
487
        enums: enums,
J
Joao Moreno 已提交
488
        filePath: DECLARATION_PATH,
489
        isTheSame
J
Joao Moreno 已提交
490 491
    };
}
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
function run(out, inputFiles) {
    let SOURCE_FILE_MAP = {};
    const sourceFileGetter = (moduleId) => {
        if (!SOURCE_FILE_MAP[moduleId]) {
            let filePath = path.normalize(moduleIdToPath(out, moduleId));
            if (!inputFiles.hasOwnProperty(filePath)) {
                logErr('CANNOT FIND FILE ' + filePath + '. YOU MIGHT NEED TO RESTART gulp');
                return null;
            }
            let fileContents = inputFiles[filePath];
            let sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5);
            SOURCE_FILE_MAP[moduleId] = sourceFile;
        }
        return SOURCE_FILE_MAP[moduleId];
    };
    return _run(sourceFileGetter);
}
function run2(out, sourceFileMap) {
    const sourceFileGetter = (moduleId) => {
        let filePath = path.normalize(moduleIdToPath(out, moduleId));
        return sourceFileMap[filePath];
    };
    return _run(sourceFileGetter);
}
exports.run2 = run2;
J
Joao Moreno 已提交
517 518 519 520
function complainErrors() {
    logErr('Not running monaco.d.ts generation due to compile errors');
}
exports.complainErrors = complainErrors;
521 522
class TypeScriptLanguageServiceHost {
    constructor(libs, files, compilerOptions) {
523 524 525 526 527
        this._libs = libs;
        this._files = files;
        this._compilerOptions = compilerOptions;
    }
    // --- language service host ---------------
528
    getCompilationSettings() {
529
        return this._compilerOptions;
530 531
    }
    getScriptFileNames() {
532 533 534
        return ([]
            .concat(Object.keys(this._libs))
            .concat(Object.keys(this._files)));
535 536
    }
    getScriptVersion(_fileName) {
537
        return '1';
538 539
    }
    getProjectVersion() {
540
        return '1';
541 542
    }
    getScriptSnapshot(fileName) {
543 544 545 546 547 548 549 550 551
        if (this._files.hasOwnProperty(fileName)) {
            return ts.ScriptSnapshot.fromString(this._files[fileName]);
        }
        else if (this._libs.hasOwnProperty(fileName)) {
            return ts.ScriptSnapshot.fromString(this._libs[fileName]);
        }
        else {
            return ts.ScriptSnapshot.fromString('');
        }
552 553
    }
    getScriptKind(_fileName) {
554
        return ts.ScriptKind.TS;
555 556
    }
    getCurrentDirectory() {
557
        return '';
558 559
    }
    getDefaultLibFileName(_options) {
560
        return 'defaultLib:es5';
561 562
    }
    isDefaultLibFileName(fileName) {
563
        return fileName === this.getDefaultLibFileName(this._compilerOptions);
564 565
    }
}
A
Alex Dima 已提交
566
exports.TypeScriptLanguageServiceHost = TypeScriptLanguageServiceHost;
567
function execute() {
568 569 570 571
    const OUTPUT_FILES = {};
    const SRC_FILES = {};
    const SRC_FILE_TO_EXPECTED_NAME = {};
    getIncludesInRecipe().forEach((moduleId) => {
572
        if (/\.d\.ts$/.test(moduleId)) {
573 574
            let fileName = path.join(SRC, moduleId);
            OUTPUT_FILES[moduleIdToPath('src', moduleId)] = fs.readFileSync(fileName).toString();
575 576
            return;
        }
577
        let fileName = path.join(SRC, moduleId) + '.ts';
578 579 580
        SRC_FILES[fileName] = fs.readFileSync(fileName).toString();
        SRC_FILE_TO_EXPECTED_NAME[fileName] = moduleIdToPath('src', moduleId);
    });
581
    const languageService = ts.createLanguageService(new TypeScriptLanguageServiceHost({}, SRC_FILES, {}));
582
    var t1 = Date.now();
583 584
    Object.keys(SRC_FILES).forEach((fileName) => {
        const emitOutput = languageService.getEmitOutput(fileName, true);
585 586
        OUTPUT_FILES[SRC_FILE_TO_EXPECTED_NAME[fileName]] = emitOutput.outputFiles[0].text;
    });
587
    console.log(`Generating .d.ts took ${Date.now() - t1} ms`);
588 589 590 591 592
    let r = run('src', OUTPUT_FILES);
    if (!r) {
        throw new Error(`monaco.d.ts genration error - Cannot continue`);
    }
    return r;
593
}
A
Alex Dima 已提交
594
exports.execute = execute;