Use the global monaco only in the AMD case (see microsoft/monaco-editor#1974)

This commit is contained in:
Alex Dima 2020-09-07 21:52:41 +02:00
parent b87c75d7e9
commit ee95401a40
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
22 changed files with 842 additions and 391 deletions

View file

@ -26,29 +26,45 @@ const BUNDLED_FILE_HEADER = [
].join('\n');
bundleOne('monaco.contribution');
bundleOne('tsMode');
bundleOne('tsMode', ['vs/language/typescript/monaco.contribution']);
bundleOne('tsWorker');
function bundleOne(moduleId, exclude) {
requirejs.optimize(
{
baseUrl: 'release/dev/',
baseUrl: 'out/amd/',
name: 'vs/language/typescript/' + moduleId,
out: 'release/min/' + moduleId + '.js',
out: 'release/dev/' + moduleId + '.js',
exclude: exclude,
paths: {
'vs/language/typescript': REPO_ROOT + '/release/dev'
'vs/language/typescript': REPO_ROOT + '/out/amd',
'vs/language/typescript/fillers/monaco-editor-core':
REPO_ROOT + '/out/amd/fillers/monaco-editor-core-amd'
},
optimize: 'none'
},
async function (buildResponse) {
const filePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
const fileContents = fs.readFileSync(filePath).toString();
const devFilePath = path.join(
REPO_ROOT,
'release/dev/' + moduleId + '.js'
);
const minFilePath = path.join(
REPO_ROOT,
'release/min/' + moduleId + '.js'
);
const fileContents = fs.readFileSync(devFilePath).toString();
console.log();
console.log(`Minifying ${filePath}...`);
const result = await terser.minify(fileContents);
console.log(`Done minifying ${filePath}.`);
fs.writeFileSync(filePath, BUNDLED_FILE_HEADER + result.code);
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, 'release/min'));
} catch (err) {}
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
}
);
}

44
scripts/dts.js Normal file
View file

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* 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(/export declare/g, 'export');
if (line.length > 0) {
line = `\t${line}`;
result.push(line);
}
}
result.push(`}`);
result.push(``);
fs.writeFileSync(DST_PATH, result.join('\n'));

17
scripts/release.js Normal file
View file

@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------------------------
* 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: 'out/esm',
esmDestination: 'release/esm',
entryPoints: ['monaco.contribution.js', 'tsMode.js', 'ts.worker.js'],
resolveSkip: ['monaco-editor-core']
});