diff --git a/build/gulpfile.compile.js b/build/gulpfile.compile.js index c3049784fe4..5b6ce2d70be 100644 --- a/build/gulpfile.compile.js +++ b/build/gulpfile.compile.js @@ -9,13 +9,15 @@ const gulp = require('gulp'); const util = require('./lib/util'); const task = require('./lib/task'); const compilation = require('./lib/compilation'); +const optimize = require('./lib/optimize'); // Full compile, including nls and inline sources in sourcemaps, for build const compileBuildTask = task.define('compile-build', task.series( util.rimraf('out-build'), util.buildWebNodePaths('out-build'), - compilation.compileTask('src', 'out-build', true) + compilation.compileTask('src', 'out-build', true), + optimize.optimizeLoaderTask('out-build', 'out-build', true) ) ); gulp.task(compileBuildTask); diff --git a/build/gulpfile.editor.js b/build/gulpfile.editor.js index 8e7ff5e3af3..94724bb410d 100644 --- a/build/gulpfile.editor.js +++ b/build/gulpfile.editor.js @@ -7,7 +7,7 @@ const gulp = require('gulp'); const path = require('path'); const util = require('./lib/util'); const task = require('./lib/task'); -const common = require('./lib/optimize'); +const optimize = require('./lib/optimize'); const es = require('event-stream'); const File = require('vinyl'); const i18n = require('./lib/i18n'); @@ -86,26 +86,29 @@ const extractEditorSrcTask = task.define('extract-editor-src', () => { const compileEditorAMDTask = task.define('compile-editor-amd', compilation.compileTask('out-editor-src', 'out-editor-build', true)); -const optimizeEditorAMDTask = task.define('optimize-editor-amd', common.optimizeTask({ - src: 'out-editor-build', - entryPoints: editorEntryPoints, - resources: editorResources, - loaderConfig: { - paths: { - 'vs': 'out-editor-build/vs', - 'vs/css': 'out-editor-build/vs/css.build', - 'vs/nls': 'out-editor-build/vs/nls.build', - 'vscode': 'empty:' +const optimizeEditorAMDTask = task.define('optimize-editor-amd', optimize.optimizeTask( + { + out: 'out-editor', + amd: { + src: 'out-editor-build', + entryPoints: editorEntryPoints, + resources: editorResources, + loaderConfig: { + paths: { + 'vs': 'out-editor-build/vs', + 'vs/css': 'out-editor-build/vs/css.build', + 'vs/nls': 'out-editor-build/vs/nls.build', + 'vscode': 'empty:' + } + }, + header: BUNDLED_FILE_HEADER, + bundleInfo: true, + languages } - }, - bundleLoader: false, - header: BUNDLED_FILE_HEADER, - bundleInfo: true, - out: 'out-editor', - languages: languages -})); + } +)); -const minifyEditorAMDTask = task.define('minify-editor-amd', common.minifyTask('out-editor')); +const minifyEditorAMDTask = task.define('minify-editor-amd', optimize.minifyTask('out-editor')); const createESMSourcesAndResourcesTask = task.define('extract-editor-esm', () => { standalone.createESMSourcesAndResources2({ diff --git a/build/gulpfile.extensions.js b/build/gulpfile.extensions.js index 1e3a9e4daa3..4023b3860e9 100644 --- a/build/gulpfile.extensions.js +++ b/build/gulpfile.extensions.js @@ -20,7 +20,6 @@ const root = path.dirname(__dirname); const commit = util.getVersion(root); const plumber = require('gulp-plumber'); const ext = require('./lib/extensions'); -const product = require('../product.json'); const extensionsPath = path.join(path.dirname(__dirname), 'extensions'); diff --git a/build/gulpfile.reh.js b/build/gulpfile.reh.js index a07c55232de..980f647c854 100644 --- a/build/gulpfile.reh.js +++ b/build/gulpfile.reh.js @@ -10,7 +10,7 @@ const path = require('path'); const es = require('event-stream'); const util = require('./lib/util'); const task = require('./lib/task'); -const common = require('./lib/optimize'); +const optimize = require('./lib/optimize'); const product = require('../product.json'); const rename = require('gulp-rename'); const replace = require('gulp-replace'); @@ -58,15 +58,10 @@ const serverResources = [ 'out-build/bootstrap-fork.js', 'out-build/bootstrap-amd.js', 'out-build/bootstrap-node.js', - 'out-build/paths.js', // Performance 'out-build/vs/base/common/performance.js', - // main entry points - 'out-build/server-cli.js', - 'out-build/server-main.js', - // Watcher 'out-build/vs/platform/files/**/*.exe', 'out-build/vs/platform/files/**/*.md', @@ -254,7 +249,7 @@ function packageTask(type, platform, arch, sourceFolderName, destinationFolderNa const date = new Date().toISOString(); const productJsonStream = gulp.src(['product.json'], { base: '.' }) - .pipe(json({ commit, date })); + .pipe(json({ commit, date, version })); const license = gulp.src(['remote/LICENSE'], { base: 'remote', allowEmpty: true }); @@ -357,23 +352,42 @@ function tweakProductForServerWeb(product) { ['reh', 'reh-web'].forEach(type => { const optimizeTask = task.define(`optimize-vscode-${type}`, task.series( util.rimraf(`out-vscode-${type}`), - common.optimizeTask({ - src: 'out-build', - entryPoints: _.flatten(type === 'reh' ? serverEntryPoints : serverWithWebEntryPoints), - otherSources: [], - resources: type === 'reh' ? serverResources : serverWithWebResources, - loaderConfig: common.loaderConfig(), - out: `out-vscode-${type}`, - inlineAmdImages: true, - bundleInfo: undefined, - fileContentMapper: createVSCodeWebFileContentMapper('.build/extensions', type === 'reh-web' ? tweakProductForServerWeb(product) : product) - }) + optimize.optimizeTask( + { + out: `out-vscode-${type}`, + amd: { + src: 'out-build', + entryPoints: _.flatten(type === 'reh' ? serverEntryPoints : serverWithWebEntryPoints), + otherSources: [], + resources: type === 'reh' ? serverResources : serverWithWebResources, + loaderConfig: optimize.loaderConfig(), + inlineAmdImages: true, + bundleInfo: undefined, + fileContentMapper: createVSCodeWebFileContentMapper('.build/extensions', type === 'reh-web' ? tweakProductForServerWeb(product) : product) + }, + commonJS: { + src: 'out-build', + entryPoints: [ + 'out-build/server-main.js', + 'out-build/server-cli.js' + ], + platform: 'node', + external: [ + 'minimist', + // TODO: we cannot inline `product.json` because + // it is being changed during build time at a later + // point in time (such as `checksums`) + '../product.json' + ] + } + } + ) )); const minifyTask = task.define(`minify-vscode-${type}`, task.series( optimizeTask, util.rimraf(`out-vscode-${type}-min`), - common.minifyTask(`out-vscode-${type}`, `https://ticino.blob.core.windows.net/sourcemaps/${commit}/core`) + optimize.minifyTask(`out-vscode-${type}`, `https://ticino.blob.core.windows.net/sourcemaps/${commit}/core`) )); gulp.task(minifyTask); diff --git a/build/gulpfile.vscode.js b/build/gulpfile.vscode.js index d371e6f3c25..cefb1f2ac98 100644 --- a/build/gulpfile.vscode.js +++ b/build/gulpfile.vscode.js @@ -20,7 +20,7 @@ const _ = require('underscore'); const util = require('./lib/util'); const task = require('./lib/task'); const buildfile = require('../src/buildfile'); -const common = require('./lib/optimize'); +const optimize = require('./lib/optimize'); const root = path.dirname(__dirname); const commit = util.getVersion(root); const packageJson = require('../package.json'); @@ -52,8 +52,6 @@ const vscodeEntryPoints = _.flatten([ ]); const vscodeResources = [ - 'out-build/main.js', - 'out-build/cli.js', 'out-build/bootstrap.js', 'out-build/bootstrap-fork.js', 'out-build/bootstrap-amd.js', @@ -63,12 +61,9 @@ const vscodeResources = [ '!out-build/vs/code/browser/**/*.html', '!out-build/vs/editor/standalone/**/*.svg', 'out-build/vs/base/common/performance.js', - 'out-build/vs/base/common/stripComments.js', - 'out-build/vs/base/node/languagePacks.js', 'out-build/vs/base/node/{stdForkStart.js,terminateProcess.sh,cpuUsage.sh,ps.sh}', 'out-build/vs/base/browser/ui/codicons/codicon/**', 'out-build/vs/base/parts/sandbox/electron-browser/preload.js', - 'out-build/vs/platform/environment/node/userDataPath.js', 'out-build/vs/workbench/browser/media/*-theme.css', 'out-build/vs/workbench/contrib/debug/**/*.json', 'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt', @@ -90,14 +85,34 @@ const vscodeResources = [ const optimizeVSCodeTask = task.define('optimize-vscode', task.series( util.rimraf('out-vscode'), - common.optimizeTask({ - src: 'out-build', - entryPoints: vscodeEntryPoints, - resources: vscodeResources, - loaderConfig: common.loaderConfig(), - out: 'out-vscode', - bundleInfo: undefined - }) + optimize.optimizeTask( + { + out: 'out-vscode', + amd: { + src: 'out-build', + entryPoints: vscodeEntryPoints, + resources: vscodeResources, + loaderConfig: optimize.loaderConfig(), + bundleInfo: undefined + }, + commonJS: { + src: 'out-build', + entryPoints: [ + 'out-build/main.js', + 'out-build/cli.js' + ], + platform: 'node', + external: [ + 'electron', + 'minimist', + // TODO: we cannot inline `product.json` because + // it is being changed during build time at a later + // point in time (such as `checksums`) + '../product.json' + ] + } + } + ) )); gulp.task(optimizeVSCodeTask); @@ -105,7 +120,7 @@ const sourceMappingURLBase = `https://ticino.blob.core.windows.net/sourcemaps/${ const minifyVSCodeTask = task.define('minify-vscode', task.series( optimizeVSCodeTask, util.rimraf('out-vscode-min'), - common.minifyTask('out-vscode', `${sourceMappingURLBase}/core`) + optimize.minifyTask('out-vscode', `${sourceMappingURLBase}/core`) )); gulp.task(minifyVSCodeTask); @@ -211,7 +226,7 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op .pipe(json(packageJsonUpdates)); const date = new Date().toISOString(); - const productJsonUpdate = { commit, date, checksums }; + const productJsonUpdate = { commit, date, checksums, version }; if (shouldSetupSettingsSearch()) { productJsonUpdate.settingsSearchBuildId = getSettingsSearchBuildId(packageJson); diff --git a/build/gulpfile.vscode.web.js b/build/gulpfile.vscode.web.js index 8e92d7717ab..c5b09393728 100644 --- a/build/gulpfile.vscode.web.js +++ b/build/gulpfile.vscode.web.js @@ -10,7 +10,7 @@ const path = require('path'); const es = require('event-stream'); const util = require('./lib/util'); const task = require('./lib/task'); -const common = require('./lib/optimize'); +const optimize = require('./lib/optimize'); const product = require('../product.json'); const rename = require('gulp-rename'); const filter = require('gulp-filter'); @@ -153,24 +153,28 @@ exports.createVSCodeWebFileContentMapper = createVSCodeWebFileContentMapper; const optimizeVSCodeWebTask = task.define('optimize-vscode-web', task.series( util.rimraf('out-vscode-web'), - common.optimizeTask({ - src: 'out-build', - entryPoints: _.flatten(vscodeWebEntryPoints), - otherSources: [], - resources: vscodeWebResources, - loaderConfig: common.loaderConfig(), - externalLoaderInfo: util.createExternalLoaderConfig(product.webEndpointUrl, commit, quality), - out: 'out-vscode-web', - inlineAmdImages: true, - bundleInfo: undefined, - fileContentMapper: createVSCodeWebFileContentMapper('.build/web/extensions', product) - }) + optimize.optimizeTask( + { + out: 'out-vscode-web', + amd: { + src: 'out-build', + entryPoints: _.flatten(vscodeWebEntryPoints), + otherSources: [], + resources: vscodeWebResources, + loaderConfig: optimize.loaderConfig(), + externalLoaderInfo: util.createExternalLoaderConfig(product.webEndpointUrl, commit, quality), + inlineAmdImages: true, + bundleInfo: undefined, + fileContentMapper: createVSCodeWebFileContentMapper('.build/web/extensions', product) + } + } + ) )); const minifyVSCodeWebTask = task.define('minify-vscode-web', task.series( optimizeVSCodeWebTask, util.rimraf('out-vscode-web-min'), - common.minifyTask('out-vscode-web', `https://ticino.blob.core.windows.net/sourcemaps/${commit}/core`) + optimize.minifyTask('out-vscode-web', `https://ticino.blob.core.windows.net/sourcemaps/${commit}/core`) )); gulp.task(minifyVSCodeWebTask); diff --git a/build/lib/optimize.js b/build/lib/optimize.js index 8333afc7184..564fa5ef89e 100644 --- a/build/lib/optimize.js +++ b/build/lib/optimize.js @@ -4,7 +4,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ Object.defineProperty(exports, "__esModule", { value: true }); -exports.minifyTask = exports.optimizeTask = exports.loaderConfig = void 0; +exports.minifyTask = exports.optimizeTask = exports.optimizeLoaderTask = exports.loaderConfig = void 0; const es = require("event-stream"); const gulp = require("gulp"); const concat = require("gulp-concat"); @@ -135,56 +135,83 @@ const DEFAULT_FILE_HEADER = [ ' * Copyright (C) Microsoft Corporation. All rights reserved.', ' *--------------------------------------------------------*/' ].join('\n'); -function optimizeTask(opts) { +function optimizeAMDTask(opts) { const src = opts.src; const entryPoints = opts.entryPoints; const resources = opts.resources; const loaderConfig = opts.loaderConfig; const bundledFileHeader = opts.header || DEFAULT_FILE_HEADER; - const bundleLoader = (typeof opts.bundleLoader === 'undefined' ? true : opts.bundleLoader); - const out = opts.out; const fileContentMapper = opts.fileContentMapper || ((contents, _path) => contents); - return function () { - const sourcemaps = require('gulp-sourcemaps'); - const bundlesStream = es.through(); // this stream will contain the bundled files - const resourcesStream = es.through(); // this stream will contain the resources - const bundleInfoStream = es.through(); // this stream will contain bundleInfo.json - bundle.bundle(entryPoints, loaderConfig, function (err, result) { - if (err || !result) { - return bundlesStream.emit('error', JSON.stringify(err)); + const sourcemaps = require('gulp-sourcemaps'); + const bundlesStream = es.through(); // this stream will contain the bundled files + const resourcesStream = es.through(); // this stream will contain the resources + const bundleInfoStream = es.through(); // this stream will contain bundleInfo.json + bundle.bundle(entryPoints, loaderConfig, function (err, result) { + if (err || !result) { + return bundlesStream.emit('error', JSON.stringify(err)); + } + toBundleStream(src, bundledFileHeader, result.files, fileContentMapper).pipe(bundlesStream); + // Remove css inlined resources + const filteredResources = resources.slice(); + result.cssInlinedResources.forEach(function (resource) { + if (process.env['VSCODE_BUILD_VERBOSE']) { + log('optimizer', 'excluding inlined: ' + resource); } - toBundleStream(src, bundledFileHeader, result.files, fileContentMapper).pipe(bundlesStream); - // Remove css inlined resources - const filteredResources = resources.slice(); - result.cssInlinedResources.forEach(function (resource) { - if (process.env['VSCODE_BUILD_VERBOSE']) { - log('optimizer', 'excluding inlined: ' + resource); - } - filteredResources.push('!' + resource); - }); - gulp.src(filteredResources, { base: `${src}`, allowEmpty: true }).pipe(resourcesStream); - const bundleInfoArray = []; - if (opts.bundleInfo) { - bundleInfoArray.push(new VinylFile({ - path: 'bundleInfo.json', - base: '.', - contents: Buffer.from(JSON.stringify(result.bundleData, null, '\t')) - })); - } - es.readArray(bundleInfoArray).pipe(bundleInfoStream); + filteredResources.push('!' + resource); }); - const result = es.merge(loader(src, bundledFileHeader, bundleLoader, opts.externalLoaderInfo), bundlesStream, resourcesStream, bundleInfoStream); - return result - .pipe(sourcemaps.write('./', { - sourceRoot: undefined, - addComment: true, - includeContent: true - })) - .pipe(opts.languages && opts.languages.length ? (0, i18n_1.processNlsFiles)({ - fileHeader: bundledFileHeader, - languages: opts.languages - }) : es.through()) - .pipe(gulp.dest(out)); + gulp.src(filteredResources, { base: `${src}`, allowEmpty: true }).pipe(resourcesStream); + const bundleInfoArray = []; + if (opts.bundleInfo) { + bundleInfoArray.push(new VinylFile({ + path: 'bundleInfo.json', + base: '.', + contents: Buffer.from(JSON.stringify(result.bundleData, null, '\t')) + })); + } + es.readArray(bundleInfoArray).pipe(bundleInfoStream); + }); + const result = es.merge(loader(src, bundledFileHeader, false, opts.externalLoaderInfo), bundlesStream, resourcesStream, bundleInfoStream); + return result + .pipe(sourcemaps.write('./', { + sourceRoot: undefined, + addComment: true, + includeContent: true + })) + .pipe(opts.languages && opts.languages.length ? (0, i18n_1.processNlsFiles)({ + fileHeader: bundledFileHeader, + languages: opts.languages + }) : es.through()); +} +function optimizeCommonJSTask(opts) { + const esbuild = require('esbuild'); + const src = opts.src; + const entryPoints = opts.entryPoints; + return gulp.src(entryPoints, { base: `${src}`, allowEmpty: true }) + .pipe(es.map((f, cb) => { + esbuild.build({ + entryPoints: [f.path], + bundle: true, + platform: opts.platform, + write: false, + external: opts.external + }).then(res => { + const jsFile = res.outputFiles[0]; + f.contents = Buffer.from(jsFile.contents); + cb(undefined, f); + }); + })); +} +function optimizeLoaderTask(src, out, bundleLoader, bundledFileHeader = '', externalLoaderInfo) { + return () => loader(src, bundledFileHeader, bundleLoader, externalLoaderInfo).pipe(gulp.dest(out)); +} +exports.optimizeLoaderTask = optimizeLoaderTask; +function optimizeTask(opts) { + return function () { + const optimizers = [optimizeAMDTask(opts.amd)]; + if (opts.commonJS) { + optimizers.push(optimizeCommonJSTask(opts.commonJS)); + } + return es.merge(...optimizers).pipe(gulp.dest(opts.out)); }; } exports.optimizeTask = optimizeTask; diff --git a/build/lib/optimize.ts b/build/lib/optimize.ts index c7b1981a589..f3c7627d3a4 100644 --- a/build/lib/optimize.ts +++ b/build/lib/optimize.ts @@ -153,7 +153,7 @@ function toBundleStream(src: string, bundledFileHeader: string, bundles: bundle. })); } -export interface IOptimizeTaskOpts { +export interface IOptimizeAMDTaskOpts { /** * The folder to read files from. */ @@ -184,11 +184,7 @@ export interface IOptimizeTaskOpts { */ bundleInfo: boolean; /** - * (out folder name) - */ - out: string; - /** - * (out folder name) + * Language configuration. */ languages?: Language[]; /** @@ -205,67 +201,125 @@ const DEFAULT_FILE_HEADER = [ ' *--------------------------------------------------------*/' ].join('\n'); -export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStream { +function optimizeAMDTask(opts: IOptimizeAMDTaskOpts): NodeJS.ReadWriteStream { const src = opts.src; const entryPoints = opts.entryPoints; const resources = opts.resources; const loaderConfig = opts.loaderConfig; const bundledFileHeader = opts.header || DEFAULT_FILE_HEADER; - const bundleLoader = (typeof opts.bundleLoader === 'undefined' ? true : opts.bundleLoader); - const out = opts.out; const fileContentMapper = opts.fileContentMapper || ((contents: string, _path: string) => contents); - return function () { - const sourcemaps = require('gulp-sourcemaps') as typeof import('gulp-sourcemaps'); + const sourcemaps = require('gulp-sourcemaps') as typeof import('gulp-sourcemaps'); - const bundlesStream = es.through(); // this stream will contain the bundled files - const resourcesStream = es.through(); // this stream will contain the resources - const bundleInfoStream = es.through(); // this stream will contain bundleInfo.json + const bundlesStream = es.through(); // this stream will contain the bundled files + const resourcesStream = es.through(); // this stream will contain the resources + const bundleInfoStream = es.through(); // this stream will contain bundleInfo.json - bundle.bundle(entryPoints, loaderConfig, function (err, result) { - if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); } + bundle.bundle(entryPoints, loaderConfig, function (err, result) { + if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); } - toBundleStream(src, bundledFileHeader, result.files, fileContentMapper).pipe(bundlesStream); + toBundleStream(src, bundledFileHeader, result.files, fileContentMapper).pipe(bundlesStream); - // Remove css inlined resources - const filteredResources = resources.slice(); - result.cssInlinedResources.forEach(function (resource) { - if (process.env['VSCODE_BUILD_VERBOSE']) { - log('optimizer', 'excluding inlined: ' + resource); - } - filteredResources.push('!' + resource); - }); - gulp.src(filteredResources, { base: `${src}`, allowEmpty: true }).pipe(resourcesStream); - - const bundleInfoArray: VinylFile[] = []; - if (opts.bundleInfo) { - bundleInfoArray.push(new VinylFile({ - path: 'bundleInfo.json', - base: '.', - contents: Buffer.from(JSON.stringify(result.bundleData, null, '\t')) - })); + // Remove css inlined resources + const filteredResources = resources.slice(); + result.cssInlinedResources.forEach(function (resource) { + if (process.env['VSCODE_BUILD_VERBOSE']) { + log('optimizer', 'excluding inlined: ' + resource); } - es.readArray(bundleInfoArray).pipe(bundleInfoStream); + filteredResources.push('!' + resource); }); + gulp.src(filteredResources, { base: `${src}`, allowEmpty: true }).pipe(resourcesStream); - const result = es.merge( - loader(src, bundledFileHeader, bundleLoader, opts.externalLoaderInfo), - bundlesStream, - resourcesStream, - bundleInfoStream - ); + const bundleInfoArray: VinylFile[] = []; + if (opts.bundleInfo) { + bundleInfoArray.push(new VinylFile({ + path: 'bundleInfo.json', + base: '.', + contents: Buffer.from(JSON.stringify(result.bundleData, null, '\t')) + })); + } + es.readArray(bundleInfoArray).pipe(bundleInfoStream); + }); - return result - .pipe(sourcemaps.write('./', { - sourceRoot: undefined, - addComment: true, - includeContent: true - })) - .pipe(opts.languages && opts.languages.length ? processNlsFiles({ - fileHeader: bundledFileHeader, - languages: opts.languages - }) : es.through()) - .pipe(gulp.dest(out)); + const result = es.merge( + loader(src, bundledFileHeader, false, opts.externalLoaderInfo), + bundlesStream, + resourcesStream, + bundleInfoStream + ); + + return result + .pipe(sourcemaps.write('./', { + sourceRoot: undefined, + addComment: true, + includeContent: true + })) + .pipe(opts.languages && opts.languages.length ? processNlsFiles({ + fileHeader: bundledFileHeader, + languages: opts.languages + }) : es.through()); +} + +export interface IOptimizeCommonJSTaskOpts { + /** + * The paths to consider for optimizing. + */ + entryPoints: string[]; + /** + * The folder to read files from. + */ + src: string; + /** + * ESBuild `platform` option: https://esbuild.github.io/api/#platform + */ + platform: 'browser' | 'node' | 'neutral'; + /** + * ESBuild `external` option: https://esbuild.github.io/api/#external + */ + external: string[]; +} + +function optimizeCommonJSTask(opts: IOptimizeCommonJSTaskOpts): NodeJS.ReadWriteStream { + const esbuild = require('esbuild') as typeof import('esbuild'); + + const src = opts.src; + const entryPoints = opts.entryPoints; + + return gulp.src(entryPoints, { base: `${src}`, allowEmpty: true }) + .pipe(es.map((f: any, cb) => { + esbuild.build({ + entryPoints: [f.path], + bundle: true, + platform: opts.platform, + write: false, + external: opts.external + }).then(res => { + const jsFile = res.outputFiles[0]; + f.contents = Buffer.from(jsFile.contents); + + cb(undefined, f); + }); + })); +} + +export function optimizeLoaderTask(src: string, out: string, bundleLoader: boolean, bundledFileHeader = '', externalLoaderInfo?: any): () => NodeJS.ReadWriteStream { + return () => loader(src, bundledFileHeader, bundleLoader, externalLoaderInfo).pipe(gulp.dest(out)); +} + +export interface IOptimizeTaskOpts { + out: string; + amd: IOptimizeAMDTaskOpts; + commonJS?: IOptimizeCommonJSTaskOpts; +} + +export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStream { + return function () { + const optimizers = [optimizeAMDTask(opts.amd)]; + if (opts.commonJS) { + optimizers.push(optimizeCommonJSTask(opts.commonJS)); + } + + return es.merge(...optimizers).pipe(gulp.dest(opts.out)); }; } diff --git a/src/bootstrap-amd.js b/src/bootstrap-amd.js index 31e27ea7ed7..88747c29aaf 100644 --- a/src/bootstrap-amd.js +++ b/src/bootstrap-amd.js @@ -6,6 +6,11 @@ //@ts-check 'use strict'; +// Store the node.js require function in a variable +// before loading our AMD loader to avoid issues +// when this file is bundled with other files. +const nodeRequire = require; + const loader = require('./vs/loader'); const bootstrap = require('./bootstrap'); const performance = require('./vs/base/common/performance'); @@ -17,7 +22,7 @@ const nlsConfig = bootstrap.setupNLS(); loader.config({ baseUrl: bootstrap.fileUriFromPath(__dirname, { isWindows: process.platform === 'win32' }), catchError: true, - nodeRequire: require, + nodeRequire, 'vs/nls': nlsConfig, amdModulesPattern: /^vs\//, recordStats: true diff --git a/src/buildfile.js b/src/buildfile.js index b63d85617c3..24654c77abe 100644 --- a/src/buildfile.js +++ b/src/buildfile.js @@ -35,7 +35,6 @@ exports.base = [ exclude: ['vs/nls'], prepend: [ { path: 'vs/loader.js' }, - { path: 'vs/nls.js', amdModuleId: 'vs/nls' }, { path: 'vs/base/worker/workerMain.js' } ], dest: 'vs/base/worker/workerMain.js' diff --git a/src/main.js b/src/main.js index 884120e01b0..f7e6e49a967 100644 --- a/src/main.js +++ b/src/main.js @@ -34,7 +34,7 @@ bootstrap.enableASARSupport(); // Set userData path before app 'ready' event const args = parseCLIArgs(); -const userDataPath = getUserDataPath(args); +const userDataPath = getUserDataPath(args, product.nameShort ?? 'code-oss-dev'); app.setPath('userData', userDataPath); // Resolve code cache path diff --git a/src/vs/platform/environment/node/environmentService.ts b/src/vs/platform/environment/node/environmentService.ts index 26ef9dad17b..cf59e2f135a 100644 --- a/src/vs/platform/environment/node/environmentService.ts +++ b/src/vs/platform/environment/node/environmentService.ts @@ -15,7 +15,7 @@ export class NativeEnvironmentService extends AbstractNativeEnvironmentService { super(args, { homeDir: homedir(), tmpDir: tmpdir(), - userDataDir: getUserDataPath(args) + userDataDir: getUserDataPath(args, productService.nameShort) }, productService); } } diff --git a/src/vs/platform/environment/node/userDataPath.d.ts b/src/vs/platform/environment/node/userDataPath.d.ts index 4c9239fc953..c75b432c59c 100644 --- a/src/vs/platform/environment/node/userDataPath.d.ts +++ b/src/vs/platform/environment/node/userDataPath.d.ts @@ -11,4 +11,4 @@ import { NativeParsedArgs } from 'vs/platform/environment/common/argv'; * - respect VSCODE_APPDATA environment variable * - respect --user-data-dir CLI argument */ -export function getUserDataPath(args: NativeParsedArgs): string; +export function getUserDataPath(args: NativeParsedArgs, productName: string): string; diff --git a/src/vs/platform/environment/node/userDataPath.js b/src/vs/platform/environment/node/userDataPath.js index 1f7196c33e1..6076754a2fb 100644 --- a/src/vs/platform/environment/node/userDataPath.js +++ b/src/vs/platform/environment/node/userDataPath.js @@ -14,18 +14,18 @@ * * @param {typeof import('path')} path * @param {typeof import('os')} os - * @param {string} productName * @param {string} cwd */ - function factory(path, os, productName, cwd) { + function factory(path, os, cwd) { /** * @param {NativeParsedArgs} cliArgs + * @param {string} productName * * @returns {string} */ - function getUserDataPath(cliArgs) { - const userDataPath = doGetUserDataPath(cliArgs); + function getUserDataPath(cliArgs, productName) { + const userDataPath = doGetUserDataPath(cliArgs, productName); const pathsToResolve = [userDataPath]; // If the user-data-path is not absolute, make @@ -43,10 +43,11 @@ /** * @param {NativeParsedArgs} cliArgs + * @param {string} productName * * @returns {string} */ - function doGetUserDataPath(cliArgs) { + function doGetUserDataPath(cliArgs, productName) { // 1. Support portable mode const portablePath = process.env['VSCODE_PORTABLE']; @@ -101,25 +102,18 @@ } if (typeof define === 'function') { - define(['require', 'path', 'os', 'vs/base/common/network', 'vs/base/common/resources', 'vs/base/common/process'], function ( - require, + define(['path', 'os', 'vs/base/common/process'], function ( /** @type {typeof import('path')} */ path, /** @type {typeof import('os')} */ os, - /** @type {typeof import('../../../base/common/network')} */ network, - /** @type {typeof import("../../../base/common/resources")} */ resources, /** @type {typeof import("../../../base/common/process")} */ process ) { - const rootPath = resources.dirname(network.FileAccess.asFileUri('', require)); - const pkg = require.__$__nodeRequire(resources.joinPath(rootPath, 'package.json').fsPath); - - return factory(path, os, pkg.name, process.cwd()); - }); // amd + return factory(path, os, process.cwd()); // amd + }); } else if (typeof module === 'object' && typeof module.exports === 'object') { - const pkg = require('../../../../../package.json'); const path = require('path'); const os = require('os'); - module.exports = factory(path, os, pkg.name, process.env['VSCODE_CWD'] || process.cwd()); // commonjs + module.exports = factory(path, os, process.env['VSCODE_CWD'] || process.cwd()); // commonjs } else { throw new Error('Unknown context'); } diff --git a/src/vs/platform/environment/test/node/userDataPath.test.ts b/src/vs/platform/environment/test/node/userDataPath.test.ts index e0eb596af9f..f92f1808481 100644 --- a/src/vs/platform/environment/test/node/userDataPath.test.ts +++ b/src/vs/platform/environment/test/node/userDataPath.test.ts @@ -6,11 +6,12 @@ import * as assert from 'assert'; import { OPTIONS, parseArgs } from 'vs/platform/environment/node/argv'; import { getUserDataPath } from 'vs/platform/environment/node/userDataPath'; +import product from 'vs/platform/product/common/product'; suite('User data path', () => { test('getUserDataPath - default', () => { - const path = getUserDataPath(parseArgs(process.argv, OPTIONS)); + const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort); assert.ok(path.length > 0); }); @@ -20,7 +21,7 @@ suite('User data path', () => { const portableDir = 'portable-dir'; process.env['VSCODE_PORTABLE'] = portableDir; - const path = getUserDataPath(parseArgs(process.argv, OPTIONS)); + const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort); assert.ok(path.includes(portableDir)); } finally { if (typeof origPortable === 'string') { @@ -36,7 +37,7 @@ suite('User data path', () => { const args = parseArgs(process.argv, OPTIONS); args['user-data-dir'] = cliUserDataDir; - const path = getUserDataPath(args); + const path = getUserDataPath(args, product.nameShort); assert.ok(path.includes(cliUserDataDir)); }); @@ -46,7 +47,7 @@ suite('User data path', () => { const appDataDir = 'appdata-dir'; process.env['VSCODE_APPDATA'] = appDataDir; - const path = getUserDataPath(parseArgs(process.argv, OPTIONS)); + const path = getUserDataPath(parseArgs(process.argv, OPTIONS), product.nameShort); assert.ok(path.includes(appDataDir)); } finally { if (typeof origAppData === 'string') { diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts index f0808b12783..bceda016f20 100644 --- a/src/vs/platform/product/common/product.ts +++ b/src/vs/platform/product/common/product.ts @@ -32,7 +32,6 @@ else if (typeof require?.__$__nodeRequire === 'function') { const rootPath = dirname(FileAccess.asFileUri('', require)); product = require.__$__nodeRequire(joinPath(rootPath, 'product.json').fsPath); - const pkg = require.__$__nodeRequire(joinPath(rootPath, 'package.json').fsPath) as { version: string }; // Running out of sources if (env['VSCODE_DEV']) { @@ -44,9 +43,16 @@ else if (typeof require?.__$__nodeRequire === 'function') { }); } - Object.assign(product, { - version: pkg.version - }); + // Version is added during built time, but we still + // want to have it running out of sources so we + // read it from package.json only when we need it. + if (!product.version) { + const pkg = require.__$__nodeRequire(joinPath(rootPath, 'package.json').fsPath) as { version: string }; + + Object.assign(product, { + version: pkg.version + }); + } } // Web environment or unknown diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index 0c6d93f52bf..54b3254011d 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -84,7 +84,7 @@ export const TestNativeWindowConfiguration: INativeWindowConfiguration = { product, homeDir: homeDir, tmpDir: tmpdir(), - userDataDir: getUserDataPath(args), + userDataDir: getUserDataPath(args, product.nameShort), profiles: { profile: NULL_PROFILE, all: [NULL_PROFILE] }, ...args };