Adopt esbuild for monaco-typescript

This commit is contained in:
Alexandru Dima 2021-11-12 13:26:25 +01:00
parent c0d4493bd9
commit dcbd8121d9
No known key found for this signature in database
GPG key ID: 39563C1504FDD0C9
15 changed files with 66 additions and 335 deletions

View file

@ -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);
}
);
}

View file

@ -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.`,
` *--------------------------------------------------------------------------------------------*/`,
``,
`/// <reference path="../node_modules/monaco-editor-core/monaco.d.ts" />`,
``,
`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'));

View file

@ -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']
});