Adopt esbuild for the esm release of monaco-css

This commit is contained in:
Alex Dima 2021-11-11 21:52:33 +01:00
parent 8430c538b4
commit 70d1828179
No known key found for this signature in database
GPG Key ID: 39563C1504FDD0C9
8 changed files with 272 additions and 41 deletions

70
build/utils.js Normal file
View File

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const fs = require('fs');
const path = require('path');
const REPO_ROOT = path.join(__dirname, '..');
/**
* @param {string} _source
* @param {string} _destination
*/
function copyFile(_source, _destination) {
const source = path.join(REPO_ROOT, _source);
const destination = path.join(REPO_ROOT, _destination);
// ensure target dir
(function () {
/** @type {string[]} */
const dirs = [];
/** @type {string} */
let dirname = path.dirname(destination);
while (dirname.length > REPO_ROOT.length) {
dirs.push(dirname);
dirname = path.dirname(dirname);
}
dirs.reverse();
dirs.forEach(function (dir) {
try {
fs.mkdirSync(dir);
} catch (err) {}
});
})();
fs.writeFileSync(destination, fs.readFileSync(source));
console.log(`Copied ${_source} to ${_destination}`);
}
exports.copyFile = copyFile;
/**
* @param {string} _dirPath
*/
function removeDir(_dirPath) {
const dirPath = path.join(REPO_ROOT, _dirPath);
if (!fs.existsSync(dirPath)) {
return;
}
rmDir(dirPath);
console.log(`Deleted ${_dirPath}`);
/**
* @param {string} dirPath
*/
function rmDir(dirPath) {
const entries = fs.readdirSync(dirPath);
for (const entry of entries) {
const filePath = path.join(dirPath, entry);
if (fs.statSync(filePath).isFile()) {
fs.unlinkSync(filePath);
} else {
rmDir(filePath);
}
}
fs.rmdirSync(dirPath);
}
}
exports.removeDir = removeDir;

View File

@ -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"
}
}

View File

@ -0,0 +1,45 @@
/*---------------------------------------------------------------------------------------------
* 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 } = require('../../build/utils');
removeDir(`monaco-css/release`);
removeDir(`monaco-css/out`);
cp.spawnSync(process.execPath, [path.join(__dirname, '../../node_modules/typescript/lib/tsc.js'), '-p', path.join(__dirname, '../src/tsconfig.json')], { stdio: 'inherit', stderr: 'inherit' });
cp.spawnSync(process.execPath, [path.join(__dirname, './dts.js')], { stdio: 'inherit', stderr: 'inherit' });
cp.spawnSync(process.execPath, [path.join(__dirname, '../../node_modules/prettier/bin-prettier.js'), '--write', path.join(__dirname, '../monaco.d.ts')], { stdio: 'inherit', stderr: 'inherit' });
esbuild.build({
entryPoints: ['src/cssMode.ts', 'src/css.worker.ts', 'src/monaco.contribution.ts'],
bundle: true,
target: 'esnext',
format: 'esm',
external: ['monaco-editor-core', '*/cssMode'],
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-css/out/amd/monaco.contribution.d.ts', 'monaco-css/release/esm/monaco.contribution.d.ts');
copyFile('monaco-css/out/amd/fillers/monaco-editor-core.d.ts', 'monaco-css/release/esm/fillers/monaco-editor-core.d.ts');
cp.spawnSync(process.execPath, [path.join(__dirname, './bundle.js')], { stdio: 'inherit', stderr: 'inherit' });

View File

@ -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-css/out/esm',
esmDestination: 'monaco-css/release/esm',
entryPoints: ['monaco.contribution.js', 'cssMode.js', 'css.worker.js'],
resolveAlias: {
'vscode-nls': path.join(REPO_ROOT, 'monaco-css/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-css-languageservice/lib/esm': 'vscode-css-languageservice'
}
});

View File

@ -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"]
}
}

View File

@ -1,6 +1,6 @@
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
monaco.editor.create(document.getElementById('container'), {
value: 'console.log("Hello, world")',
language: 'javascript'
value: 'sel {\nbackground: red;\n}',
language: 'css'
});

150
package-lock.json generated
View File

@ -1233,6 +1233,156 @@
"es6-symbol": "^3.1.1"
}
},
"esbuild": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.13.13.tgz",
"integrity": "sha512-Z17A/R6D0b4s3MousytQ/5i7mTCbaF+Ua/yPfoe71vdTv4KBvVAvQ/6ytMngM2DwGJosl8WxaD75NOQl2QF26Q==",
"dev": true,
"requires": {
"esbuild-android-arm64": "0.13.13",
"esbuild-darwin-64": "0.13.13",
"esbuild-darwin-arm64": "0.13.13",
"esbuild-freebsd-64": "0.13.13",
"esbuild-freebsd-arm64": "0.13.13",
"esbuild-linux-32": "0.13.13",
"esbuild-linux-64": "0.13.13",
"esbuild-linux-arm": "0.13.13",
"esbuild-linux-arm64": "0.13.13",
"esbuild-linux-mips64le": "0.13.13",
"esbuild-linux-ppc64le": "0.13.13",
"esbuild-netbsd-64": "0.13.13",
"esbuild-openbsd-64": "0.13.13",
"esbuild-sunos-64": "0.13.13",
"esbuild-windows-32": "0.13.13",
"esbuild-windows-64": "0.13.13",
"esbuild-windows-arm64": "0.13.13"
}
},
"esbuild-android-arm64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.13.13.tgz",
"integrity": "sha512-T02aneWWguJrF082jZworjU6vm8f4UQ+IH2K3HREtlqoY9voiJUwHLRL6khRlsNLzVglqgqb7a3HfGx7hAADCQ==",
"dev": true,
"optional": true
},
"esbuild-darwin-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.13.13.tgz",
"integrity": "sha512-wkaiGAsN/09X9kDlkxFfbbIgR78SNjMOfUhoel3CqKBDsi9uZhw7HBNHNxTzYUK8X8LAKFpbODgcRB3b/I8gHA==",
"dev": true,
"optional": true
},
"esbuild-darwin-arm64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.13.13.tgz",
"integrity": "sha512-b02/nNKGSV85Gw9pUCI5B48AYjk0vFggDeom0S6QMP/cEDtjSh1WVfoIFNAaLA0MHWfue8KBwoGVsN7rBshs4g==",
"dev": true,
"optional": true
},
"esbuild-freebsd-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.13.13.tgz",
"integrity": "sha512-ALgXYNYDzk9YPVk80A+G4vz2D22Gv4j4y25exDBGgqTcwrVQP8rf/rjwUjHoh9apP76oLbUZTmUmvCMuTI1V9A==",
"dev": true,
"optional": true
},
"esbuild-freebsd-arm64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.13.13.tgz",
"integrity": "sha512-uFvkCpsZ1yqWQuonw5T1WZ4j59xP/PCvtu6I4pbLejhNo4nwjW6YalqnBvBSORq5/Ifo9S/wsIlVHzkzEwdtlw==",
"dev": true,
"optional": true
},
"esbuild-linux-32": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.13.13.tgz",
"integrity": "sha512-yxR9BBwEPs9acVEwTrEE2JJNHYVuPQC9YGjRfbNqtyfK/vVBQYuw8JaeRFAvFs3pVJdQD0C2BNP4q9d62SCP4w==",
"dev": true,
"optional": true
},
"esbuild-linux-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.13.13.tgz",
"integrity": "sha512-kzhjlrlJ+6ESRB/n12WTGll94+y+HFeyoWsOrLo/Si0s0f+Vip4b8vlnG0GSiS6JTsWYAtGHReGczFOaETlKIw==",
"dev": true,
"optional": true
},
"esbuild-linux-arm": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.13.13.tgz",
"integrity": "sha512-hXub4pcEds+U1TfvLp1maJ+GHRw7oizvzbGRdUvVDwtITtjq8qpHV5Q5hWNNn6Q+b3b2UxF03JcgnpzCw96nUQ==",
"dev": true,
"optional": true
},
"esbuild-linux-arm64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.13.13.tgz",
"integrity": "sha512-KMrEfnVbmmJxT3vfTnPv/AiXpBFbbyExH13BsUGy1HZRPFMi5Gev5gk8kJIZCQSRfNR17aqq8sO5Crm2KpZkng==",
"dev": true,
"optional": true
},
"esbuild-linux-mips64le": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.13.13.tgz",
"integrity": "sha512-cJT9O1LYljqnnqlHaS0hdG73t7hHzF3zcN0BPsjvBq+5Ad47VJun+/IG4inPhk8ta0aEDK6LdP+F9299xa483w==",
"dev": true,
"optional": true
},
"esbuild-linux-ppc64le": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.13.13.tgz",
"integrity": "sha512-+rghW8st6/7O6QJqAjVK3eXzKkZqYAw6LgHv7yTMiJ6ASnNvghSeOcIvXFep3W2oaJc35SgSPf21Ugh0o777qQ==",
"dev": true,
"optional": true
},
"esbuild-netbsd-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.13.13.tgz",
"integrity": "sha512-A/B7rwmzPdzF8c3mht5TukbnNwY5qMJqes09ou0RSzA5/jm7Jwl/8z853ofujTFOLhkNHUf002EAgokzSgEMpQ==",
"dev": true,
"optional": true
},
"esbuild-openbsd-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.13.13.tgz",
"integrity": "sha512-szwtuRA4rXKT3BbwoGpsff6G7nGxdKgUbW9LQo6nm0TVCCjDNDC/LXxT994duIW8Tyq04xZzzZSW7x7ttDiw1w==",
"dev": true,
"optional": true
},
"esbuild-plugin-alias": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/esbuild-plugin-alias/-/esbuild-plugin-alias-0.2.0.tgz",
"integrity": "sha512-biAUOtI9cinWE1ZeO7xyoSEJDb3cTTljLtLZEJJ8sZAe3wLWICrvkyG0zejT7e36S2jQywC0JL067tvCi/fxVw==",
"dev": true
},
"esbuild-sunos-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.13.13.tgz",
"integrity": "sha512-ihyds9O48tVOYF48iaHYUK/boU5zRaLOXFS+OOL3ceD39AyHo46HVmsJLc7A2ez0AxNZCxuhu+P9OxfPfycTYQ==",
"dev": true,
"optional": true
},
"esbuild-windows-32": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.13.13.tgz",
"integrity": "sha512-h2RTYwpG4ldGVJlbmORObmilzL8EECy8BFiF8trWE1ZPHLpECE9//J3Bi+W3eDUuv/TqUbiNpGrq4t/odbayUw==",
"dev": true,
"optional": true
},
"esbuild-windows-64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.13.13.tgz",
"integrity": "sha512-oMrgjP4CjONvDHe7IZXHrMk3wX5Lof/IwFEIbwbhgbXGBaN2dke9PkViTiXC3zGJSGpMvATXVplEhlInJ0drHA==",
"dev": true,
"optional": true
},
"esbuild-windows-arm64": {
"version": "0.13.13",
"resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.13.13.tgz",
"integrity": "sha512-6fsDfTuTvltYB5k+QPah/x7LrI2+OLAJLE3bWLDiZI6E8wXMQU+wLqtEO/U/RvJgVY1loPs5eMpUBpVajczh1A==",
"dev": true,
"optional": true
},
"escodegen": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.0.0.tgz",

View File

@ -16,7 +16,8 @@
"website": "gulp build-website && npm run typedoc && gulp prepare-website-branch",
"build-website": "gulp build-website && npm run typedoc",
"typedoc": "cd monaco-editor/typedoc && \"../../node_modules/.bin/typedoc\" --options ./typedoc.json",
"prettier": "prettier --write ."
"prettier": "prettier --write .",
"gulp": "node ./node_modules/gulp/bin/gulp.js"
},
"typings": "./esm/vs/editor/editor.api.d.ts",
"module": "./esm/vs/editor/editor.main.js",
@ -29,6 +30,8 @@
"@types/tape": "^4.13.2",
"@typescript/vfs": "^1.3.5",
"clean-css": "^5.1.1",
"esbuild": "^0.13.13",
"esbuild-plugin-alias": "^0.2.0",
"event-stream": "4.0.1",
"glob": "^7.2.0",
"gulp": "^4.0.2",