From dcbd8121d91046b97b30419f80a3e332f5dd08a1 Mon Sep 17 00:00:00 2001 From: Alexandru Dima Date: Fri, 12 Nov 2021 13:26:25 +0100 Subject: [PATCH] Adopt `esbuild` for `monaco-typescript` --- build/utils.js | 3 + gulpfile.js | 2 - monaco-json/test/index.html | 120 ------------------ monaco-languages/README.md | 25 +--- monaco-typescript/README.md | 23 +--- monaco-typescript/build.js | 46 +++++++ monaco-typescript/package.json | 5 +- monaco-typescript/scripts/bundle.js | 64 ---------- monaco-typescript/scripts/dts.js | 44 ------- monaco-typescript/scripts/release.js | 17 --- .../src/fillers/monaco-editor-core-amd.ts | 12 -- monaco-typescript/src/monaco.contribution.ts | 11 +- monaco-typescript/src/tsconfig.esm.json | 11 -- package-lock.json | 17 --- package.json | 1 - 15 files changed, 66 insertions(+), 335 deletions(-) delete mode 100644 monaco-json/test/index.html create mode 100644 monaco-typescript/build.js delete mode 100644 monaco-typescript/scripts/bundle.js delete mode 100644 monaco-typescript/scripts/dts.js delete mode 100644 monaco-typescript/scripts/release.js delete mode 100644 monaco-typescript/src/fillers/monaco-editor-core-amd.ts delete mode 100644 monaco-typescript/src/tsconfig.esm.json diff --git a/build/utils.js b/build/utils.js index 26579a52..4e31de6f 100644 --- a/build/utils.js +++ b/build/utils.js @@ -142,6 +142,9 @@ function dts(_source, _destination, namespace) { if (/^import/.test(line)) { continue; } + if (line === 'export {};') { + continue; + } line = line.replace(/ /g, '\t'); line = line.replace(/declare /g, ''); if (line.length > 0) { diff --git a/gulpfile.js b/gulpfile.js index c1509bcf..ca1e5ac4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -347,8 +347,6 @@ function ESM_pluginStream(plugin, destinationPath) { } } - contents = contents.replace(/\/\/# sourceMappingURL=.*((\r?\n)|$)/g, ''); - data.contents = Buffer.from(contents); this.emit('data', data); } diff --git a/monaco-json/test/index.html b/monaco-json/test/index.html deleted file mode 100644 index 90fedaba..00000000 --- a/monaco-json/test/index.html +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - -

Monaco Editor JSON test page

-
- - - - - - - - - diff --git a/monaco-languages/README.md b/monaco-languages/README.md index e7abb55f..05224ce6 100644 --- a/monaco-languages/README.md +++ b/monaco-languages/README.md @@ -1,23 +1,14 @@ -# Monaco Languages [![Build Status](https://dev.azure.com/ms/monaco-languages/_apis/build/status/microsoft.monaco-languages?branchName=master)](https://dev.azure.com/ms/monaco-languages/_build/latest?definitionId=140&branchName=master) +# Monaco Languages Colorization and configuration supports for multiple languages for the Monaco Editor: ![monaco-languages](https://cloud.githubusercontent.com/assets/5047891/15938606/1fd4bac6-2e74-11e6-8839-d455da8bc8a7.gif) -## Issues +## Development -Please file issues concerning `monaco-languages` in the [`monaco-editor`-repository](https://github.com/Microsoft/monaco-editor/issues). - -## Installing - -This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module. - -## Dev: cheat sheet - -- initial setup with `npm install .` -- compile with `npm run watch` +- watch with `npm run watch` +- compile with `npm run prepublishOnly` - test with `npm run test` -- bundle with `npm run prepublishOnly` ## Dev: Adding a new language @@ -29,11 +20,3 @@ This npm module is bundled and distributed in the [monaco-editor](https://www.np ```js import './myLang/myLang.contribution'; ``` - -## Code of Conduct - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -## License - -[MIT](https://github.com/Microsoft/monaco-languages/blob/master/LICENSE.md) diff --git a/monaco-typescript/README.md b/monaco-typescript/README.md index 40558795..7f848d5a 100644 --- a/monaco-typescript/README.md +++ b/monaco-typescript/README.md @@ -6,21 +6,10 @@ Simple TypeScript and JavaScript language support for the Monaco Editor. _Note_ that this project focuses on single-file scenarios and that things like project-isolation, cross-file-features like Rename etc. are _outside_ the scope of this project and not supported. -## Issues - -Please file issues concerning `monaco-typescript` in the [`monaco-editor` repository](https://github.com/Microsoft/monaco-editor/issues). - -## Installing - -This npm module is bundled and distributed in the [monaco-editor](https://www.npmjs.com/package/monaco-editor) npm module. - ## Development -- `git clone https://github.com/Microsoft/monaco-typescript` -- `cd monaco-typescript` -- `npm install .` -- `npm run compile` -- `npm run watch` +- watch with `npm run watch` +- compile with `npm run prepublishOnly` - open `$/monaco-typescript/test/index.html` in your favorite browser. ## Updating TypeScript @@ -29,11 +18,3 @@ This npm module is bundled and distributed in the [monaco-editor](https://www.np - execute `npm install .` - execute `npm run import-typescript` - adopt new APIs - -## Code of Conduct - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. - -## License - -[MIT](https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md) diff --git a/monaco-typescript/build.js b/monaco-typescript/build.js new file mode 100644 index 00000000..e2622e3e --- /dev/null +++ b/monaco-typescript/build.js @@ -0,0 +1,46 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +//@ts-check + +const { copyFile, removeDir, tsc, dts, buildESM, buildAMD } = require('../build/utils'); + +removeDir(`monaco-typescript/release`); +removeDir(`monaco-typescript/out`); + +copyFile( + `monaco-typescript/src/lib/typescriptServices-amd.js`, + `monaco-typescript/out/amd/lib/typescriptServices.js` +); + +copyFile( + `monaco-typescript/src/lib/typescriptServices.js`, + `monaco-typescript/out/esm/lib/typescriptServices.js` +); + +tsc(`monaco-typescript/src/tsconfig.json`); + +dts( + `monaco-typescript/out/amd/monaco.contribution.d.ts`, + `monaco-typescript/monaco.d.ts`, + 'monaco.languages.typescript' +); + +buildESM({ + entryPoints: ['src/monaco.contribution.ts', 'src/tsMode.ts', 'src/ts.worker.ts'], + external: ['monaco-editor-core', '*/tsMode'] +}); +buildAMD({ + entryPoint: 'src/monaco.contribution.ts', + banner: 'define("vs/language/typescript/monaco.contribution",["vs/editor/editor.api"],()=>{' +}); +buildAMD({ + entryPoint: 'src/tsMode.ts', + banner: 'define("vs/language/typescript/tsMode",["vs/editor/editor.api"],()=>{' +}); +buildAMD({ + entryPoint: 'src/tsWorker.ts', + banner: 'define("vs/language/typescript/tsWorker",[],()=>{' +}); diff --git a/monaco-typescript/package.json b/monaco-typescript/package.json index 2df93d36..15bd4f17 100644 --- a/monaco-typescript/package.json +++ b/monaco-typescript/package.json @@ -1,10 +1,7 @@ { "scripts": { - "compile-amd": "../node_modules/.bin/mcopy ./src/lib/typescriptServices-amd.js ./out/amd/lib/typescriptServices.js && ../node_modules/.bin/tsc -p ./src/tsconfig.json", - "compile-esm": "../node_modules/.bin/mcopy ./src/lib/typescriptServices.js ./out/esm/lib/typescriptServices.js && ../node_modules/.bin/tsc -p ./src/tsconfig.esm.json", - "compile": "../node_modules/.bin/mrmdir ./out && npm run compile-amd && npm run compile-esm && node ./scripts/dts && ../node_modules/.bin/prettier --write ./monaco.d.ts", "watch": "../node_modules/.bin/tsc -p ./src --watch", - "prepublishOnly": "../node_modules/.bin/mrmdir ./release && npm run compile && node ./scripts/release.js && node ./scripts/bundle && ../node_modules/.bin/mcopy ./out/esm/monaco.contribution.d.ts ./release/esm/monaco.contribution.d.ts && ../node_modules/.bin/mcopy ./out/esm/fillers/monaco-editor-core.d.ts ./release/esm/fillers/monaco-editor-core.d.ts", + "prepublishOnly": "node ./build", "import-typescript": "node ./scripts/importTypescript" } } diff --git a/monaco-typescript/scripts/bundle.js b/monaco-typescript/scripts/bundle.js deleted file mode 100644 index 2478682d..00000000 --- a/monaco-typescript/scripts/bundle.js +++ /dev/null @@ -1,64 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -const requirejs = require('requirejs'); -const path = require('path'); -const fs = require('fs'); -const terser = require('terser'); -const helpers = require('monaco-plugin-helpers'); - -const REPO_ROOT = path.resolve(__dirname, '..', '..'); - -const sha1 = helpers.getGitVersion(REPO_ROOT); -const semver = require('../../package.json').version; -const headerVersion = semver + '(' + sha1 + ')'; - -const BUNDLED_FILE_HEADER = [ - '/*!-----------------------------------------------------------------------------', - ' * Copyright (c) Microsoft Corporation. All rights reserved.', - ' * monaco-typescript version: ' + headerVersion, - ' * Released under the MIT license', - ' * https://github.com/Microsoft/monaco-typescript/blob/master/LICENSE.md', - ' *-----------------------------------------------------------------------------*/', - '' -].join('\n'); - -bundleOne('monaco.contribution'); -bundleOne('tsMode', ['vs/language/typescript/monaco.contribution']); -bundleOne('tsWorker'); - -function bundleOne(moduleId, exclude) { - requirejs.optimize( - { - baseUrl: 'out/amd/', - name: 'vs/language/typescript/' + moduleId, - out: 'release/dev/' + moduleId + '.js', - exclude: exclude, - paths: { - 'vs/language/typescript': REPO_ROOT + '/monaco-typescript/out/amd', - 'vs/language/typescript/fillers/monaco-editor-core': - REPO_ROOT + '/monaco-typescript/out/amd/fillers/monaco-editor-core-amd' - }, - optimize: 'none' - }, - async function (buildResponse) { - const devFilePath = path.join(REPO_ROOT, 'monaco-typescript/release/dev/' + moduleId + '.js'); - const minFilePath = path.join(REPO_ROOT, 'monaco-typescript/release/min/' + moduleId + '.js'); - const fileContents = fs.readFileSync(devFilePath).toString(); - console.log(); - console.log(`Minifying ${devFilePath}...`); - const result = await terser.minify(fileContents, { - output: { - comments: 'some' - } - }); - console.log(`Done minifying ${devFilePath}.`); - try { - fs.mkdirSync(path.join(REPO_ROOT, 'monaco-typescript/release/min')); - } catch (err) {} - fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code); - } - ); -} diff --git a/monaco-typescript/scripts/dts.js b/monaco-typescript/scripts/dts.js deleted file mode 100644 index 06b18768..00000000 --- a/monaco-typescript/scripts/dts.js +++ /dev/null @@ -1,44 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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 REPO_ROOT = path.join(__dirname, '../'); -const SRC_PATH = path.join(REPO_ROOT, 'out/amd/monaco.contribution.d.ts'); -const DST_PATH = path.join(REPO_ROOT, 'monaco.d.ts'); - -const lines = fs - .readFileSync(SRC_PATH) - .toString() - .split(/\r\n|\r|\n/); -let result = [ - `/*---------------------------------------------------------------------------------------------`, - ` * Copyright (c) Microsoft Corporation. All rights reserved.`, - ` * Licensed under the MIT License. See License.txt in the project root for license information.`, - ` *--------------------------------------------------------------------------------------------*/`, - ``, - `/// `, - ``, - `declare namespace monaco.languages.typescript {` -]; -for (let line of lines) { - if (/^import/.test(line)) { - continue; - } - if (line === 'export {};') { - continue; - } - line = line.replace(/ /g, '\t'); - line = line.replace(/declare /g, ''); - if (line.length > 0) { - line = `\t${line}`; - result.push(line); - } -} -result.push(`}`); -result.push(``); - -fs.writeFileSync(DST_PATH, result.join('\n')); diff --git a/monaco-typescript/scripts/release.js b/monaco-typescript/scripts/release.js deleted file mode 100644 index c679f130..00000000 --- a/monaco-typescript/scripts/release.js +++ /dev/null @@ -1,17 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * 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 helpers = require('monaco-plugin-helpers'); - -const REPO_ROOT = path.join(__dirname, '../../'); - -helpers.packageESM({ - repoRoot: REPO_ROOT, - esmSource: 'monaco-typescript/out/esm', - esmDestination: 'monaco-typescript/release/esm', - entryPoints: ['monaco.contribution.js', 'tsMode.js', 'ts.worker.js'], - resolveSkip: ['monaco-editor-core'] -}); diff --git a/monaco-typescript/src/fillers/monaco-editor-core-amd.ts b/monaco-typescript/src/fillers/monaco-editor-core-amd.ts deleted file mode 100644 index 6af108be..00000000 --- a/monaco-typescript/src/fillers/monaco-editor-core-amd.ts +++ /dev/null @@ -1,12 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -// Resolves with the global monaco API - -declare const define: any; - -define([], function () { - return (self).monaco; -}); diff --git a/monaco-typescript/src/monaco.contribution.ts b/monaco-typescript/src/monaco.contribution.ts index 7027bd20..0334106e 100644 --- a/monaco-typescript/src/monaco.contribution.ts +++ b/monaco-typescript/src/monaco.contribution.ts @@ -693,8 +693,17 @@ export const getJavaScriptWorker = (): Promise<(...uris: Uri[]) => Promise { - return import('./tsMode'); + if (AMD) { + return new Promise((resolve, reject) => { + require(['vs/language/typescript/tsMode'], resolve, reject); + }); + } else { + return import('./tsMode'); + } } languages.onLanguage('typescript', () => { diff --git a/monaco-typescript/src/tsconfig.esm.json b/monaco-typescript/src/tsconfig.esm.json deleted file mode 100644 index b47f127d..00000000 --- a/monaco-typescript/src/tsconfig.esm.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "moduleResolution": "node", - "outDir": "../out/esm", - "declaration": true, - "target": "es5", - "lib": ["dom", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"], - "strict": true - } -} diff --git a/package-lock.json b/package-lock.json index 24d8f10c..5de3ff57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2991,23 +2991,6 @@ "integrity": "sha512-WNxfchYafMZXVfysqg/ESW4MtOpYLPaIKrzudNlgwYvfYID+O/nwSZI5X+KxW84roVzHsNgFGyOOesfHFZwYUA==", "dev": true }, - "monaco-plugin-helpers": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/monaco-plugin-helpers/-/monaco-plugin-helpers-1.0.3.tgz", - "integrity": "sha512-6AYI3ONAy8ki74qG2JqtFrLdiJHQlgeO5l4Rwr0OMyIpGXhc94y5rZuFxOtgGkxgSrZfHSwOt/MulUNZ/mOQOw==", - "dev": true, - "requires": { - "typescript": "^2.7.2" - }, - "dependencies": { - "typescript": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", - "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", - "dev": true - } - } - }, "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", diff --git a/package.json b/package.json index 21640fbe..b59ed045 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "jsdom": "^17.0.0", "jsonc-parser": "^3.0.0", "monaco-editor-core": "0.30.1", - "monaco-plugin-helpers": "^1.0.3", "prettier": "^2.4.1", "requirejs": "^2.3.6", "rimraf": "^3.0.2",