Use esbuild to bundle some CommonJS main files (#160957)

* ensure node.js `require` is captured

* optimize `main.js` and `cli.js`

* cleanup

* leave out bundled files

* drop package.json from userdata paths

* fix web task

* fix editor distro

* inline version into `product.json`

* also bundle server

* t

* actually do server too

* Keep bundling nls in editor worker

Co-authored-by: Alex Dima <alexdima@microsoft.com>
This commit is contained in:
Benjamin Pasero 2022-09-16 05:24:23 -07:00 committed by GitHub
parent 694ecf5fd0
commit 2179e52fb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 318 additions and 195 deletions

View file

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

View file

@ -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({

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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'

View file

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

View file

@ -15,7 +15,7 @@ export class NativeEnvironmentService extends AbstractNativeEnvironmentService {
super(args, {
homeDir: homedir(),
tmpDir: tmpdir(),
userDataDir: getUserDataPath(args)
userDataDir: getUserDataPath(args, productService.nameShort)
}, productService);
}
}

View file

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

View file

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

View file

@ -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') {

View file

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

View file

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