/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ const path = require('path'); const fs = require('fs'); const TYPESCRIPT_LIB_SOURCE = path.join(__dirname, '../node_modules/typescript/lib'); const TYPESCRIPT_LIB_DESTINATION = path.join(__dirname, '../src/lib'); (function() { try { fs.statSync(TYPESCRIPT_LIB_DESTINATION); } catch (err) { fs.mkdirSync(TYPESCRIPT_LIB_DESTINATION); } importLibDeclarationFile('lib.d.ts'); importLibDeclarationFile('lib.es6.d.ts'); var tsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.js')).toString(); // Ensure we never run into the node system... // (this also removes require calls that trick webpack into shimming those modules...) tsServices = ( tsServices.replace(/\n ts\.sys =([^]*)\n \}\)\(\);/m, `\n // MONACOCHANGE\n ts.sys = undefined;\n // END MONACOCHANGE`) ); var tsServices_amd = tsServices + ` // MONACOCHANGE // Defining the entire module name because r.js has an issue and cannot bundle this file // correctly with an anonymous define call define("vs/language/typescript/lib/typescriptServices", [], function() { return ts; }); // END MONACOCHANGE `; fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices-amd.js'), tsServices_amd); var tsServices_esm = tsServices + ` // MONACOCHANGE export const createClassifier = ts.createClassifier; export const createLanguageService = ts.createLanguageService; export const displayPartsToString = ts.displayPartsToString; export const EndOfLineState = ts.EndOfLineState; export const flattenDiagnosticMessageText = ts.flattenDiagnosticMessageText; export const IndentStyle = ts.IndentStyle; export const ScriptKind = ts.ScriptKind; export const ScriptTarget = ts.ScriptTarget; export const TokenClass = ts.TokenClass; // END MONACOCHANGE `; fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.js'), tsServices_esm); var dtsServices = fs.readFileSync(path.join(TYPESCRIPT_LIB_SOURCE, 'typescriptServices.d.ts')).toString(); dtsServices += ` // MONACOCHANGE export = ts; // END MONACOCHANGE `; fs.writeFileSync(path.join(TYPESCRIPT_LIB_DESTINATION, 'typescriptServices.d.ts'), dtsServices); })(); /** * Import a lib*.d.ts file from TypeScript's dist */ function importLibDeclarationFile(name) { var dstName = name.replace(/\.d\.ts$/, '').replace(/\./g, '-') + '-ts'; var contents = resolveLibFile(null, name); var dstPath = path.join(TYPESCRIPT_LIB_DESTINATION, dstName + '.ts'); fs.writeFileSync(dstPath, `/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ export const contents = "${escapeText(contents)}"; `); } function resolveLibFile(name, filename) { var srcPath; if (filename) { srcPath = path.join(TYPESCRIPT_LIB_SOURCE, filename); } else { srcPath = path.join(TYPESCRIPT_LIB_SOURCE, `lib.${name}.d.ts`); } var contents = fs.readFileSync(srcPath).toString(); var lines = contents.split(/\r\n|\r|\n/); var result = []; for (let i = 0; i < lines.length; i++) { let m = lines[i].match(/\/\/\/\s*