From c419101f73d1c086bd5345448296bffd60892ca9 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 11 Nov 2021 22:35:29 +0100 Subject: [PATCH] Improve `monaco-html` scripts --- monaco-css/README.md | 3 +- monaco-css/test/index.html | 876 --------------------- monaco-editor-webpack-plugin/test/index.js | 4 +- monaco-html/README.md | 23 +- monaco-html/package.json | 3 +- monaco-html/scripts/build.js | 43 + monaco-html/scripts/bundle.js | 4 +- monaco-html/scripts/dts.js | 41 - monaco-html/scripts/release.js | 26 - monaco-html/src/tsconfig.esm.json | 10 - monaco-html/test/index.html | 75 -- 11 files changed, 53 insertions(+), 1055 deletions(-) delete mode 100644 monaco-css/test/index.html create mode 100644 monaco-html/scripts/build.js delete mode 100644 monaco-html/scripts/dts.js delete mode 100644 monaco-html/scripts/release.js delete mode 100644 monaco-html/src/tsconfig.esm.json delete mode 100644 monaco-html/test/index.html diff --git a/monaco-css/README.md b/monaco-css/README.md index 2e079fe3..7de819d1 100644 --- a/monaco-css/README.md +++ b/monaco-css/README.md @@ -19,5 +19,4 @@ in [Visual Studio Code](https://github.com/microsoft/vscode) to power the CSS, L ## Development - watch with `npm run watch` -- `npm run prepublishOnly` -- open `$/monaco-css/test/index.html` in your favorite browser. +- compile with `npm run prepublishOnly` diff --git a/monaco-css/test/index.html b/monaco-css/test/index.html deleted file mode 100644 index 8d345999..00000000 --- a/monaco-css/test/index.html +++ /dev/null @@ -1,876 +0,0 @@ - - - - - - - -

Monaco Editor CSS test page

-
- - - - - - - - - diff --git a/monaco-editor-webpack-plugin/test/index.js b/monaco-editor-webpack-plugin/test/index.js index ace82c62..255201db 100644 --- a/monaco-editor-webpack-plugin/test/index.js +++ b/monaco-editor-webpack-plugin/test/index.js @@ -1,6 +1,6 @@ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'; monaco.editor.create(document.getElementById('container'), { - value: 'sel {\nbackground: red;\n}', - language: 'css' + value: '', + language: 'html' }); diff --git a/monaco-html/README.md b/monaco-html/README.md index cb80ab18..0be612bc 100644 --- a/monaco-html/README.md +++ b/monaco-html/README.md @@ -8,26 +8,11 @@ HTML language plugin for the Monaco Editor. It provides the following features w - Link detection - Syntax highlighting -Internally the HTML plugin uses the [vscode-html-languageservice](https://github.com/Microsoft/vscode-html-languageservice) +Internally the HTML plugin uses the [`vscode-html-languageservice`](https://github.com/microsoft/vscode-html-languageservice) node module, providing the implementation of the functionally listed above. The same module is also used -in [Visual Studio Code](https://github.com/Microsoft/vscode) to power the HTML editing experience. - -## Issues - -Please file issues concering `monaco-html` 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. +in [Visual Studio Code](https://github.com/microsoft/vscode) to power the HTML editing experience. ## Development -- `git clone https://github.com/Microsoft/monaco-html` -- `cd monaco-html` -- `npm install .` -- `npm run watch` -- open `$/monaco-html/test/index.html` in your favorite browser. - -## License - -[MIT](https://github.com/Microsoft/monaco-html/blob/master/LICENSE.md) +- watch with `npm run watch` +- compile with `npm run prepublishOnly` diff --git a/monaco-html/package.json b/monaco-html/package.json index b0a007e9..82a29a5c 100644 --- a/monaco-html/package.json +++ b/monaco-html/package.json @@ -1,7 +1,6 @@ { "scripts": { - "compile": "../node_modules/.bin/mrmdir ./out && ../node_modules/.bin/tsc -p ./src/tsconfig.json && ../node_modules/.bin/tsc -p ./src/tsconfig.esm.json && 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 ./scripts/build" } } diff --git a/monaco-html/scripts/build.js b/monaco-html/scripts/build.js new file mode 100644 index 00000000..7c1c1672 --- /dev/null +++ b/monaco-html/scripts/build.js @@ -0,0 +1,43 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +const esbuild = require('esbuild'); +const alias = require('esbuild-plugin-alias'); +const path = require('path'); +const cp = require('child_process'); +const { copyFile, removeDir, tsc, dts } = require('../../build/utils'); + +removeDir(`monaco-html/release`); +removeDir(`monaco-html/out`); + +tsc(`monaco-html/src/tsconfig.json`); + +dts(`monaco-html/out/amd/monaco.contribution.d.ts`, `monaco-html/monaco.d.ts`, 'monaco.languages.html'); + +esbuild.build({ + entryPoints: ['src/htmlMode.ts', 'src/html.worker.ts', 'src/monaco.contribution.ts'], + bundle: true, + target: 'esnext', + format: 'esm', + external: ['monaco-editor-core', '*/htmlMode'], + outdir: 'release/esm/', + plugins: [ + alias({ + 'vscode-nls': path.join(__dirname, '../src/fillers/vscode-nls.ts'), + }), + ], +}).then((result) => { + if (result.errors.length > 0) { + console.error(result.errors); + } + if (result.warnings.length > 0) { + console.error(result.warnings); + } +}); + +copyFile('monaco-html/out/amd/monaco.contribution.d.ts', 'monaco-html/release/esm/monaco.contribution.d.ts'); +copyFile('monaco-html/out/amd/fillers/monaco-editor-core.d.ts', 'monaco-html/release/esm/fillers/monaco-editor-core.d.ts'); + +cp.spawnSync(process.execPath, [path.join(__dirname, './bundle.js')], { stdio: 'inherit', stderr: 'inherit' }); diff --git a/monaco-html/scripts/bundle.js b/monaco-html/scripts/bundle.js index d5932edf..82a594bf 100644 --- a/monaco-html/scripts/bundle.js +++ b/monaco-html/scripts/bundle.js @@ -13,9 +13,9 @@ const headerVersion = semver + '(' + sha1 + ')'; const BUNDLED_FILE_HEADER = [ '/*!-----------------------------------------------------------------------------', ' * Copyright (c) Microsoft Corporation. All rights reserved.', - ' * monaco-html version: ' + headerVersion, + ' * Version: ' + headerVersion, ' * Released under the MIT license', - ' * https://github.com/Microsoft/monaco-html/blob/master/LICENSE.md', + ' * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt', ' *-----------------------------------------------------------------------------*/', '' ].join('\n'); diff --git a/monaco-html/scripts/dts.js b/monaco-html/scripts/dts.js deleted file mode 100644 index d2c98bcc..00000000 --- a/monaco-html/scripts/dts.js +++ /dev/null @@ -1,41 +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.html {` -]; -for (let line of lines) { - if (/^import/.test(line)) { - 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-html/scripts/release.js b/monaco-html/scripts/release.js deleted file mode 100644 index 29ce7afb..00000000 --- a/monaco-html/scripts/release.js +++ /dev/null @@ -1,26 +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-html/out/esm', - esmDestination: 'monaco-html/release/esm', - entryPoints: ['monaco.contribution.js', 'htmlMode.js', 'html.worker.js'], - resolveAlias: { - 'vscode-nls': path.join(REPO_ROOT, 'monaco-html/out/esm/fillers/vscode-nls.js') - }, - resolveSkip: ['monaco-editor-core'], - destinationFolderSimplification: { - node_modules: '_deps', - 'vscode-languageserver-types/lib/esm': 'vscode-languageserver-types', - 'vscode-uri/lib/esm': 'vscode-uri', - 'vscode-html-languageservice/lib/esm': 'vscode-html-languageservice' - } -}); diff --git a/monaco-html/src/tsconfig.esm.json b/monaco-html/src/tsconfig.esm.json deleted file mode 100644 index 3edf3ca4..00000000 --- a/monaco-html/src/tsconfig.esm.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "moduleResolution": "node", - "outDir": "../out/esm", - "declaration": true, - "target": "es5", - "lib": ["dom", "es5", "es2015.collection", "es2015.promise", "es2015.iterable"] - } -} diff --git a/monaco-html/test/index.html b/monaco-html/test/index.html deleted file mode 100644 index 8b98c1b6..00000000 --- a/monaco-html/test/index.html +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - -

Monaco Editor HTML test page

-
- - - - - - - - -