mirror of
https://github.com/microsoft/vscode.git
synced 2026-02-14 23:18:36 +00:00
Add nls info to monaco-editor-core and remove left-over AMD tasks
This commit is contained in:
2
.github/workflows/monaco-editor.yml
vendored
2
.github/workflows/monaco-editor.yml
vendored
@@ -65,7 +65,7 @@ jobs:
|
||||
run: npm run monaco-compile-check
|
||||
|
||||
- name: Editor Distro & ESM
|
||||
run: npm run gulp editor-esm
|
||||
run: npm run gulp editor-distro
|
||||
|
||||
- name: Editor ESM sources check
|
||||
working-directory: ./test/monaco
|
||||
|
||||
@@ -3,12 +3,13 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
//@ts-check
|
||||
|
||||
const gulp = require('gulp');
|
||||
const path = require('path');
|
||||
const util = require('./lib/util');
|
||||
const { getVersion } = require('./lib/getVersion');
|
||||
const task = require('./lib/task');
|
||||
const optimize = require('./lib/optimize');
|
||||
const es = require('event-stream');
|
||||
const File = require('vinyl');
|
||||
const i18n = require('./lib/i18n');
|
||||
@@ -17,39 +18,13 @@ const cp = require('child_process');
|
||||
const compilation = require('./lib/compilation');
|
||||
const monacoapi = require('./lib/monaco-api');
|
||||
const fs = require('fs');
|
||||
const filter = require('gulp-filter');
|
||||
|
||||
const root = path.dirname(__dirname);
|
||||
const sha1 = getVersion(root);
|
||||
const semver = require('./monaco/package.json').version;
|
||||
const headerVersion = semver + '(' + sha1 + ')';
|
||||
|
||||
// Build
|
||||
|
||||
const editorEntryPoints = [
|
||||
{
|
||||
name: 'vs/editor/editor.main',
|
||||
include: [],
|
||||
exclude: ['vs/css'],
|
||||
prepend: [
|
||||
{ path: 'out-editor-build/vs/css.js', amdModuleId: 'vs/css' }
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'vs/base/common/worker/simpleWorker',
|
||||
include: ['vs/editor/common/services/editorSimpleWorker'],
|
||||
exclude: [],
|
||||
prepend: [
|
||||
{ path: 'vs/loader.js' },
|
||||
{ path: 'vs/base/worker/workerMain.js' }
|
||||
],
|
||||
dest: 'vs/base/worker/workerMain.js'
|
||||
}
|
||||
];
|
||||
|
||||
const editorResources = [
|
||||
'out-editor-build/vs/base/browser/ui/codicons/**/*.ttf'
|
||||
];
|
||||
|
||||
const BUNDLED_FILE_HEADER = [
|
||||
'/*!-----------------------------------------------------------',
|
||||
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
||||
@@ -60,8 +35,6 @@ const BUNDLED_FILE_HEADER = [
|
||||
''
|
||||
].join('\n');
|
||||
|
||||
const languages = i18n.defaultLanguages.concat([]); // i18n.defaultLanguages.concat(process.env.VSCODE_QUALITY !== 'stable' ? i18n.extraLanguages : []);
|
||||
|
||||
const extractEditorSrcTask = task.define('extract-editor-src', () => {
|
||||
const apiusages = monacoapi.execute().usageContent;
|
||||
const extrausages = fs.readFileSync(path.join(root, 'build', 'monaco', 'monaco.usage.recipe')).toString();
|
||||
@@ -70,127 +43,41 @@ const extractEditorSrcTask = task.define('extract-editor-src', () => {
|
||||
entryPoints: [
|
||||
'vs/editor/editor.main',
|
||||
'vs/editor/editor.worker',
|
||||
'vs/base/worker/workerMain',
|
||||
],
|
||||
inlineEntryPoints: [
|
||||
apiusages,
|
||||
extrausages
|
||||
],
|
||||
typings: [],
|
||||
shakeLevel: 2, // 0-Files, 1-InnerFile, 2-ClassMembers
|
||||
importIgnorePattern: /\.css$/,
|
||||
destRoot: path.join(root, 'out-editor-src'),
|
||||
tsOutDir: '../out-monaco-editor-core/esm/vs',
|
||||
redirects: {
|
||||
'@vscode/tree-sitter-wasm': '../node_modules/@vscode/tree-sitter-wasm/wasm/web-tree-sitter',
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Disable mangling for the editor, as it complicates debugging & quite a few users rely on private/protected fields.
|
||||
// Disable NLS task to remove english strings to preserve backwards compatibility when we removed the `vs/nls!` AMD plugin.
|
||||
const compileEditorAMDTask = task.define('compile-editor-amd', compilation.compileTask('out-editor-src', 'out-editor-build', true, { disableMangle: true, preserveEnglish: true }));
|
||||
|
||||
const bundleEditorAMDTask = task.define('bundle-editor-amd', optimize.bundleTask(
|
||||
{
|
||||
out: 'out-editor',
|
||||
esm: {
|
||||
src: 'out-editor-build',
|
||||
entryPoints: editorEntryPoints,
|
||||
resources: editorResources
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
const minifyEditorAMDTask = task.define('minify-editor-amd', optimize.minifyTask('out-editor'));
|
||||
|
||||
const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () => {
|
||||
standalone.createESMSourcesAndResources2({
|
||||
srcFolder: './out-editor-src',
|
||||
outFolder: './out-editor-esm',
|
||||
outResourcesFolder: './out-monaco-editor-core/esm',
|
||||
ignores: [
|
||||
'inlineEntryPoint:0.ts',
|
||||
'inlineEntryPoint:1.ts',
|
||||
'vs/loader.js',
|
||||
'vs/base/worker/workerMain.ts',
|
||||
],
|
||||
renames: {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const compileEditorESMTask = task.define('compile-editor-esm', () => {
|
||||
const KEEP_PREV_ANALYSIS = false;
|
||||
const FAIL_ON_PURPOSE = false;
|
||||
console.log(`Launching the TS compiler at ${path.join(__dirname, '../out-editor-esm')}...`);
|
||||
let result;
|
||||
if (process.platform === 'win32') {
|
||||
result = cp.spawnSync(`..\\node_modules\\.bin\\tsc.cmd`, {
|
||||
cwd: path.join(__dirname, '../out-editor-esm'),
|
||||
shell: true
|
||||
});
|
||||
} else {
|
||||
result = cp.spawnSync(`node`, [`../node_modules/.bin/tsc`], {
|
||||
cwd: path.join(__dirname, '../out-editor-esm')
|
||||
});
|
||||
}
|
||||
|
||||
console.log(result.stdout.toString());
|
||||
console.log(result.stderr.toString());
|
||||
const src = 'out-editor-src';
|
||||
const out = 'out-monaco-editor-core/esm';
|
||||
|
||||
if (FAIL_ON_PURPOSE || result.status !== 0) {
|
||||
console.log(`The TS Compilation failed, preparing analysis folder...`);
|
||||
const destPath = path.join(__dirname, '../../vscode-monaco-editor-esm-analysis');
|
||||
const keepPrevAnalysis = (KEEP_PREV_ANALYSIS && fs.existsSync(destPath));
|
||||
const cleanDestPath = (keepPrevAnalysis ? Promise.resolve() : util.rimraf(destPath)());
|
||||
return cleanDestPath.then(() => {
|
||||
// build a list of files to copy
|
||||
const files = util.rreddir(path.join(__dirname, '../out-editor-esm'));
|
||||
const compile = compilation.createCompile(src, { build: true, emitError: true, transpileOnly: false, preserveEnglish: true });
|
||||
const srcPipe = gulp.src(`${src}/**`, { base: `${src}` });
|
||||
|
||||
if (!keepPrevAnalysis) {
|
||||
fs.mkdirSync(destPath);
|
||||
|
||||
// initialize a new repository
|
||||
cp.spawnSync(`git`, [`init`], {
|
||||
cwd: destPath
|
||||
});
|
||||
|
||||
// copy files from src
|
||||
for (const file of files) {
|
||||
const srcFilePath = path.join(__dirname, '../src', file);
|
||||
const dstFilePath = path.join(destPath, file);
|
||||
if (fs.existsSync(srcFilePath)) {
|
||||
util.ensureDir(path.dirname(dstFilePath));
|
||||
const contents = fs.readFileSync(srcFilePath).toString().replace(/\r\n|\r|\n/g, '\n');
|
||||
fs.writeFileSync(dstFilePath, contents);
|
||||
}
|
||||
}
|
||||
|
||||
// create an initial commit to diff against
|
||||
cp.spawnSync(`git`, [`add`, `.`], {
|
||||
cwd: destPath
|
||||
});
|
||||
|
||||
// create the commit
|
||||
cp.spawnSync(`git`, [`commit`, `-m`, `"original sources"`, `--no-gpg-sign`], {
|
||||
cwd: destPath
|
||||
});
|
||||
}
|
||||
|
||||
// copy files from tree shaken src
|
||||
for (const file of files) {
|
||||
const srcFilePath = path.join(__dirname, '../out-editor-src', file);
|
||||
const dstFilePath = path.join(destPath, file);
|
||||
if (fs.existsSync(srcFilePath)) {
|
||||
util.ensureDir(path.dirname(dstFilePath));
|
||||
const contents = fs.readFileSync(srcFilePath).toString().replace(/\r\n|\r|\n/g, '\n');
|
||||
fs.writeFileSync(dstFilePath, contents);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Open in VS Code the folder at '${destPath}' and you can analyze the compilation error`);
|
||||
throw new Error('Standalone Editor compilation failed. If this is the build machine, simply launch `npm run gulp editor-distro` on your machine to further analyze the compilation problem.');
|
||||
});
|
||||
}
|
||||
return (
|
||||
srcPipe
|
||||
.pipe(compile())
|
||||
.pipe(i18n.processNlsFiles({
|
||||
out,
|
||||
fileHeader: BUNDLED_FILE_HEADER,
|
||||
languages: i18n.defaultLanguages,
|
||||
}))
|
||||
.pipe(filter(['**', '!**/inlineEntryPoint*', '!**/tsconfig.json', '!**/loader.js']))
|
||||
.pipe(gulp.dest(out))
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -239,18 +126,6 @@ function toExternalDTS(contents) {
|
||||
return lines.join('\n').replace(/\n\n\n+/g, '\n\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{ (path: string): boolean }} testFunc
|
||||
*/
|
||||
function filterStream(testFunc) {
|
||||
return es.through(function (data) {
|
||||
if (!testFunc(data.relative)) {
|
||||
return;
|
||||
}
|
||||
this.emit('data', data);
|
||||
});
|
||||
}
|
||||
|
||||
const finalEditorResourcesTask = task.define('final-editor-resources', () => {
|
||||
return es.merge(
|
||||
// other assets
|
||||
@@ -299,42 +174,6 @@ const finalEditorResourcesTask = task.define('final-editor-resources', () => {
|
||||
}));
|
||||
}))
|
||||
.pipe(gulp.dest('out-monaco-editor-core')),
|
||||
|
||||
// dev folder
|
||||
es.merge(
|
||||
gulp.src('out-editor/**/*')
|
||||
).pipe(gulp.dest('out-monaco-editor-core/dev')),
|
||||
|
||||
// min folder
|
||||
es.merge(
|
||||
gulp.src('out-editor-min/**/*')
|
||||
).pipe(filterStream(function (path) {
|
||||
// no map files
|
||||
return !/(\.js\.map$)|(nls\.metadata\.json$)|(bundleInfo\.json$)/.test(path);
|
||||
})).pipe(es.through(function (data) {
|
||||
// tweak the sourceMappingURL
|
||||
if (!/\.js$/.test(data.path)) {
|
||||
this.emit('data', data);
|
||||
return;
|
||||
}
|
||||
|
||||
const relativePathToMap = path.relative(path.join(data.relative), path.join('min-maps', data.relative + '.map'));
|
||||
|
||||
let strContents = data.contents.toString();
|
||||
const newStr = '//# sourceMappingURL=' + relativePathToMap.replace(/\\/g, '/');
|
||||
strContents = strContents.replace(/\/\/# sourceMappingURL=[^ ]+$/, newStr);
|
||||
|
||||
data.contents = Buffer.from(strContents);
|
||||
this.emit('data', data);
|
||||
})).pipe(gulp.dest('out-monaco-editor-core/min')),
|
||||
|
||||
// min-maps folder
|
||||
es.merge(
|
||||
gulp.src('out-editor-min/**/*')
|
||||
).pipe(filterStream(function (path) {
|
||||
// no map files
|
||||
return /\.js\.map$/.test(path);
|
||||
})).pipe(gulp.dest('out-monaco-editor-core/min-maps'))
|
||||
);
|
||||
});
|
||||
|
||||
@@ -349,38 +188,11 @@ gulp.task('editor-distro',
|
||||
task.series(
|
||||
task.parallel(
|
||||
util.rimraf('out-editor-src'),
|
||||
util.rimraf('out-editor-build'),
|
||||
util.rimraf('out-editor-esm'),
|
||||
util.rimraf('out-monaco-editor-core'),
|
||||
util.rimraf('out-editor'),
|
||||
util.rimraf('out-editor-min')
|
||||
),
|
||||
extractEditorSrcTask,
|
||||
task.parallel(
|
||||
task.series(
|
||||
compileEditorAMDTask,
|
||||
bundleEditorAMDTask,
|
||||
minifyEditorAMDTask
|
||||
),
|
||||
task.series(
|
||||
createESMSourcesAndResourcesTask,
|
||||
compileEditorESMTask,
|
||||
)
|
||||
),
|
||||
finalEditorResourcesTask
|
||||
)
|
||||
);
|
||||
|
||||
gulp.task('editor-esm',
|
||||
task.series(
|
||||
task.parallel(
|
||||
util.rimraf('out-editor-src'),
|
||||
util.rimraf('out-editor-esm'),
|
||||
util.rimraf('out-monaco-editor-core'),
|
||||
),
|
||||
extractEditorSrcTask,
|
||||
createESMSourcesAndResourcesTask,
|
||||
compileEditorESMTask,
|
||||
finalEditorResourcesTask
|
||||
)
|
||||
);
|
||||
|
||||
@@ -393,6 +205,9 @@ gulp.task('monacodts', task.define('monacodts', () => {
|
||||
|
||||
//#region monaco type checking
|
||||
|
||||
/**
|
||||
* @param {boolean} watch
|
||||
*/
|
||||
function createTscCompileTask(watch) {
|
||||
return () => {
|
||||
const createReporter = require('./lib/reporter').createReporter;
|
||||
@@ -421,6 +236,7 @@ function createTscCompileTask(watch) {
|
||||
report = reporter.end(false);
|
||||
|
||||
} else if (str.indexOf('Compilation complete') >= 0) {
|
||||
// @ts-ignore
|
||||
report.end();
|
||||
|
||||
} else if (str) {
|
||||
|
||||
@@ -41,6 +41,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.watchApiProposalNamesTask = exports.compileApiProposalNamesTask = void 0;
|
||||
exports.createCompile = createCompile;
|
||||
exports.transpileTask = transpileTask;
|
||||
exports.compileTask = compileTask;
|
||||
exports.watchTask = watchTask;
|
||||
|
||||
@@ -49,7 +49,7 @@ interface ICompileTaskOptions {
|
||||
readonly preserveEnglish: boolean;
|
||||
}
|
||||
|
||||
function createCompile(src: string, { build, emitError, transpileOnly, preserveEnglish }: ICompileTaskOptions) {
|
||||
export function createCompile(src: string, { build, emitError, transpileOnly, preserveEnglish }: ICompileTaskOptions) {
|
||||
const tsb = require('./tsb') as typeof import('./tsb');
|
||||
const sourcemaps = require('gulp-sourcemaps') as typeof import('gulp-sourcemaps');
|
||||
|
||||
|
||||
@@ -319,9 +319,10 @@ globalThis._VSCODE_NLS_LANGUAGE=${JSON.stringify(language.id)};`),
|
||||
function processNlsFiles(opts) {
|
||||
return (0, event_stream_1.through)(function (file) {
|
||||
const fileName = path_1.default.basename(file.path);
|
||||
if (fileName === 'bundleInfo.json') { // pick a root level file to put the core bundles (TODO@esm this file is not created anymore, pick another)
|
||||
if (fileName === 'nls.keys.json') {
|
||||
try {
|
||||
const json = JSON.parse(fs_1.default.readFileSync(path_1.default.join(REPO_ROOT_PATH, opts.out, 'nls.keys.json')).toString());
|
||||
const contents = file.contents.toString('utf8');
|
||||
const json = JSON.parse(contents);
|
||||
if (NLSKeysFormat.is(json)) {
|
||||
processCoreBundleFormat(file.base, opts.fileHeader, opts.languages, json, this);
|
||||
}
|
||||
|
||||
@@ -387,9 +387,10 @@ globalThis._VSCODE_NLS_LANGUAGE=${JSON.stringify(language.id)};`),
|
||||
export function processNlsFiles(opts: { out: string; fileHeader: string; languages: Language[] }): ThroughStream {
|
||||
return through(function (this: ThroughStream, file: File) {
|
||||
const fileName = path.basename(file.path);
|
||||
if (fileName === 'bundleInfo.json') { // pick a root level file to put the core bundles (TODO@esm this file is not created anymore, pick another)
|
||||
if (fileName === 'nls.keys.json') {
|
||||
try {
|
||||
const json = JSON.parse(fs.readFileSync(path.join(REPO_ROOT_PATH, opts.out, 'nls.keys.json')).toString());
|
||||
const contents = file.contents.toString('utf8');
|
||||
const json = JSON.parse(contents);
|
||||
if (NLSKeysFormat.is(json)) {
|
||||
processCoreBundleFormat(file.base, opts.fileHeader, opts.languages, json, this);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.extractEditor = extractEditor;
|
||||
exports.createESMSourcesAndResources2 = createESMSourcesAndResources2;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const tss = __importStar(require("./treeshaking"));
|
||||
@@ -75,6 +74,9 @@ function extractEditor(options) {
|
||||
compilerOptions = tsConfig.compilerOptions;
|
||||
}
|
||||
tsConfig.compilerOptions = compilerOptions;
|
||||
tsConfig.compilerOptions.sourceMap = true;
|
||||
tsConfig.compilerOptions.module = 'es2022';
|
||||
tsConfig.compilerOptions.outDir = options.tsOutDir;
|
||||
compilerOptions.noEmit = false;
|
||||
compilerOptions.noUnusedLocals = false;
|
||||
compilerOptions.preserveConstEnums = false;
|
||||
@@ -142,102 +144,6 @@ function extractEditor(options) {
|
||||
'vs/loader.js'
|
||||
].forEach(copyFile);
|
||||
}
|
||||
function createESMSourcesAndResources2(options) {
|
||||
const SRC_FOLDER = path_1.default.join(REPO_ROOT, options.srcFolder);
|
||||
const OUT_FOLDER = path_1.default.join(REPO_ROOT, options.outFolder);
|
||||
const OUT_RESOURCES_FOLDER = path_1.default.join(REPO_ROOT, options.outResourcesFolder);
|
||||
const getDestAbsoluteFilePath = (file) => {
|
||||
const dest = options.renames[file.replace(/\\/g, '/')] || file;
|
||||
if (dest === 'tsconfig.json') {
|
||||
return path_1.default.join(OUT_FOLDER, `tsconfig.json`);
|
||||
}
|
||||
if (/\.ts$/.test(dest)) {
|
||||
return path_1.default.join(OUT_FOLDER, dest);
|
||||
}
|
||||
return path_1.default.join(OUT_RESOURCES_FOLDER, dest);
|
||||
};
|
||||
const allFiles = walkDirRecursive(SRC_FOLDER);
|
||||
for (const file of allFiles) {
|
||||
if (options.ignores.indexOf(file.replace(/\\/g, '/')) >= 0) {
|
||||
continue;
|
||||
}
|
||||
if (file === 'tsconfig.json') {
|
||||
const tsConfig = JSON.parse(fs_1.default.readFileSync(path_1.default.join(SRC_FOLDER, file)).toString());
|
||||
tsConfig.compilerOptions.module = 'es2022';
|
||||
tsConfig.compilerOptions.outDir = path_1.default.join(path_1.default.relative(OUT_FOLDER, OUT_RESOURCES_FOLDER), 'vs').replace(/\\/g, '/');
|
||||
write(getDestAbsoluteFilePath(file), JSON.stringify(tsConfig, null, '\t'));
|
||||
continue;
|
||||
}
|
||||
if (/\.ts$/.test(file) || /\.d\.ts$/.test(file) || /\.css$/.test(file) || /\.js$/.test(file) || /\.ttf$/.test(file)) {
|
||||
// Transport the files directly
|
||||
write(getDestAbsoluteFilePath(file), fs_1.default.readFileSync(path_1.default.join(SRC_FOLDER, file)));
|
||||
continue;
|
||||
}
|
||||
console.log(`UNKNOWN FILE: ${file}`);
|
||||
}
|
||||
function walkDirRecursive(dir) {
|
||||
if (dir.charAt(dir.length - 1) !== '/' || dir.charAt(dir.length - 1) !== '\\') {
|
||||
dir += '/';
|
||||
}
|
||||
const result = [];
|
||||
_walkDirRecursive(dir, result, dir.length);
|
||||
return result;
|
||||
}
|
||||
function _walkDirRecursive(dir, result, trimPos) {
|
||||
const files = fs_1.default.readdirSync(dir);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = path_1.default.join(dir, files[i]);
|
||||
if (fs_1.default.statSync(file).isDirectory()) {
|
||||
_walkDirRecursive(file, result, trimPos);
|
||||
}
|
||||
else {
|
||||
result.push(file.substr(trimPos));
|
||||
}
|
||||
}
|
||||
}
|
||||
function write(absoluteFilePath, contents) {
|
||||
if (/(\.ts$)|(\.js$)/.test(absoluteFilePath)) {
|
||||
contents = toggleComments(contents.toString());
|
||||
}
|
||||
writeFile(absoluteFilePath, contents);
|
||||
function toggleComments(fileContents) {
|
||||
const lines = fileContents.split(/\r\n|\r|\n/);
|
||||
let mode = 0;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (mode === 0) {
|
||||
if (/\/\/ ESM-comment-begin/.test(line)) {
|
||||
mode = 1;
|
||||
continue;
|
||||
}
|
||||
if (/\/\/ ESM-uncomment-begin/.test(line)) {
|
||||
mode = 2;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (mode === 1) {
|
||||
if (/\/\/ ESM-comment-end/.test(line)) {
|
||||
mode = 0;
|
||||
continue;
|
||||
}
|
||||
lines[i] = '// ' + line;
|
||||
continue;
|
||||
}
|
||||
if (mode === 2) {
|
||||
if (/\/\/ ESM-uncomment-end/.test(line)) {
|
||||
mode = 0;
|
||||
continue;
|
||||
}
|
||||
lines[i] = line.replace(/^(\s*)\/\/ ?/, function (_, indent) {
|
||||
return indent;
|
||||
});
|
||||
}
|
||||
}
|
||||
return lines.join('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
function transportCSS(module, enqueue, write) {
|
||||
if (!/\.css/.test(module)) {
|
||||
return false;
|
||||
|
||||
@@ -29,7 +29,7 @@ function writeFile(filePath: string, contents: Buffer | string): void {
|
||||
fs.writeFileSync(filePath, contents);
|
||||
}
|
||||
|
||||
export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: string }): void {
|
||||
export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: string; tsOutDir: string }): void {
|
||||
const ts = require('typescript') as typeof import('typescript');
|
||||
|
||||
const tsConfig = JSON.parse(fs.readFileSync(path.join(options.sourcesRoot, 'tsconfig.monaco.json')).toString());
|
||||
@@ -41,6 +41,9 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str
|
||||
compilerOptions = tsConfig.compilerOptions;
|
||||
}
|
||||
tsConfig.compilerOptions = compilerOptions;
|
||||
tsConfig.compilerOptions.sourceMap = true;
|
||||
tsConfig.compilerOptions.module = 'es2022';
|
||||
tsConfig.compilerOptions.outDir = options.tsOutDir;
|
||||
|
||||
compilerOptions.noEmit = false;
|
||||
compilerOptions.noUnusedLocals = false;
|
||||
@@ -119,125 +122,6 @@ export function extractEditor(options: tss.ITreeShakingOptions & { destRoot: str
|
||||
].forEach(copyFile);
|
||||
}
|
||||
|
||||
export interface IOptions2 {
|
||||
srcFolder: string;
|
||||
outFolder: string;
|
||||
outResourcesFolder: string;
|
||||
ignores: string[];
|
||||
renames: { [filename: string]: string };
|
||||
}
|
||||
|
||||
export function createESMSourcesAndResources2(options: IOptions2): void {
|
||||
|
||||
const SRC_FOLDER = path.join(REPO_ROOT, options.srcFolder);
|
||||
const OUT_FOLDER = path.join(REPO_ROOT, options.outFolder);
|
||||
const OUT_RESOURCES_FOLDER = path.join(REPO_ROOT, options.outResourcesFolder);
|
||||
|
||||
const getDestAbsoluteFilePath = (file: string): string => {
|
||||
const dest = options.renames[file.replace(/\\/g, '/')] || file;
|
||||
if (dest === 'tsconfig.json') {
|
||||
return path.join(OUT_FOLDER, `tsconfig.json`);
|
||||
}
|
||||
if (/\.ts$/.test(dest)) {
|
||||
return path.join(OUT_FOLDER, dest);
|
||||
}
|
||||
return path.join(OUT_RESOURCES_FOLDER, dest);
|
||||
};
|
||||
|
||||
const allFiles = walkDirRecursive(SRC_FOLDER);
|
||||
for (const file of allFiles) {
|
||||
|
||||
if (options.ignores.indexOf(file.replace(/\\/g, '/')) >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file === 'tsconfig.json') {
|
||||
const tsConfig = JSON.parse(fs.readFileSync(path.join(SRC_FOLDER, file)).toString());
|
||||
tsConfig.compilerOptions.module = 'es2022';
|
||||
tsConfig.compilerOptions.outDir = path.join(path.relative(OUT_FOLDER, OUT_RESOURCES_FOLDER), 'vs').replace(/\\/g, '/');
|
||||
write(getDestAbsoluteFilePath(file), JSON.stringify(tsConfig, null, '\t'));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (/\.ts$/.test(file) || /\.d\.ts$/.test(file) || /\.css$/.test(file) || /\.js$/.test(file) || /\.ttf$/.test(file)) {
|
||||
// Transport the files directly
|
||||
write(getDestAbsoluteFilePath(file), fs.readFileSync(path.join(SRC_FOLDER, file)));
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log(`UNKNOWN FILE: ${file}`);
|
||||
}
|
||||
|
||||
|
||||
function walkDirRecursive(dir: string): string[] {
|
||||
if (dir.charAt(dir.length - 1) !== '/' || dir.charAt(dir.length - 1) !== '\\') {
|
||||
dir += '/';
|
||||
}
|
||||
const result: string[] = [];
|
||||
_walkDirRecursive(dir, result, dir.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
function _walkDirRecursive(dir: string, result: string[], trimPos: number): void {
|
||||
const files = fs.readdirSync(dir);
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = path.join(dir, files[i]);
|
||||
if (fs.statSync(file).isDirectory()) {
|
||||
_walkDirRecursive(file, result, trimPos);
|
||||
} else {
|
||||
result.push(file.substr(trimPos));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function write(absoluteFilePath: string, contents: string | Buffer): void {
|
||||
if (/(\.ts$)|(\.js$)/.test(absoluteFilePath)) {
|
||||
contents = toggleComments(contents.toString());
|
||||
}
|
||||
writeFile(absoluteFilePath, contents);
|
||||
|
||||
function toggleComments(fileContents: string): string {
|
||||
const lines = fileContents.split(/\r\n|\r|\n/);
|
||||
let mode = 0;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
if (mode === 0) {
|
||||
if (/\/\/ ESM-comment-begin/.test(line)) {
|
||||
mode = 1;
|
||||
continue;
|
||||
}
|
||||
if (/\/\/ ESM-uncomment-begin/.test(line)) {
|
||||
mode = 2;
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode === 1) {
|
||||
if (/\/\/ ESM-comment-end/.test(line)) {
|
||||
mode = 0;
|
||||
continue;
|
||||
}
|
||||
lines[i] = '// ' + line;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mode === 2) {
|
||||
if (/\/\/ ESM-uncomment-end/.test(line)) {
|
||||
mode = 0;
|
||||
continue;
|
||||
}
|
||||
lines[i] = line.replace(/^(\s*)\/\/ ?/, function (_, indent) {
|
||||
return indent;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function transportCSS(module: string, enqueue: (module: string) => void, write: (path: string, contents: string | Buffer) => void): boolean {
|
||||
|
||||
if (!/\.css/.test(module)) {
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
"vs/editor/contrib/clipboard/browser/clipboard.ts"
|
||||
],
|
||||
"ban-eval-calls": [
|
||||
"vs/workbench/api/worker/extHostExtensionService.ts",
|
||||
"vs/base/worker/workerMain.ts"
|
||||
"vs/workbench/api/worker/extHostExtensionService.ts"
|
||||
],
|
||||
"ban-function-calls": [
|
||||
"vs/workbench/api/worker/extHostExtensionService.ts",
|
||||
"vs/base/worker/workerMain.ts",
|
||||
"vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts",
|
||||
"vs/workbench/services/keybinding/test/node/keyboardMapperTestUtils.ts"
|
||||
],
|
||||
@@ -17,7 +15,6 @@
|
||||
"bootstrap-window.ts",
|
||||
"vs/amdX.ts",
|
||||
"vs/base/browser/trustedTypes.ts",
|
||||
"vs/base/worker/workerMain.ts",
|
||||
"vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads.ts"
|
||||
],
|
||||
"ban-worker-calls": [
|
||||
@@ -27,8 +24,7 @@
|
||||
"ban-worker-importscripts": [
|
||||
"vs/amdX.ts",
|
||||
"vs/workbench/services/extensions/worker/polyfillNestedWorker.ts",
|
||||
"vs/workbench/api/worker/extensionHostWorker.ts",
|
||||
"vs/base/worker/workerMain.ts"
|
||||
"vs/workbench/api/worker/extensionHostWorker.ts"
|
||||
],
|
||||
"ban-domparser-parsefromstring": [
|
||||
"vs/base/browser/markdownRenderer.ts",
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// TODO @hediet @alexdima check where this code is used or remove this file
|
||||
// (code oss runs fine without this file, but is probably needed by the monaco-editor).
|
||||
|
||||
(function () {
|
||||
|
||||
function loadCode(moduleId: string): Promise<SimpleWorkerModule> {
|
||||
const moduleUrl = new URL(`${moduleId}.js`, globalThis._VSCODE_FILE_ROOT);
|
||||
return import(moduleUrl.href);
|
||||
}
|
||||
|
||||
interface MessageHandler {
|
||||
onmessage(msg: any, ports: readonly MessagePort[]): void;
|
||||
}
|
||||
|
||||
// shape of vs/base/common/worker/simpleWorker.ts
|
||||
interface SimpleWorkerModule {
|
||||
create(postMessage: (msg: any, transfer?: Transferable[]) => void): MessageHandler;
|
||||
}
|
||||
|
||||
function setupWorkerServer(ws: SimpleWorkerModule) {
|
||||
setTimeout(function () {
|
||||
const messageHandler = ws.create((msg: any, transfer?: Transferable[]) => {
|
||||
(<any>globalThis).postMessage(msg, transfer);
|
||||
});
|
||||
|
||||
self.onmessage = (e: MessageEvent) => messageHandler.onmessage(e.data, e.ports);
|
||||
while (beforeReadyMessages.length > 0) {
|
||||
self.onmessage(beforeReadyMessages.shift()!);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
let isFirstMessage = true;
|
||||
const beforeReadyMessages: MessageEvent[] = [];
|
||||
globalThis.onmessage = (message: MessageEvent) => {
|
||||
if (!isFirstMessage) {
|
||||
beforeReadyMessages.push(message);
|
||||
return;
|
||||
}
|
||||
|
||||
isFirstMessage = false;
|
||||
loadCode(message.data).then((ws) => {
|
||||
setupWorkerServer(ws);
|
||||
}, (err) => {
|
||||
console.error(err);
|
||||
});
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user