Build: bundle / concat entry points (#161161)

* perf - concatenate windows main files

* Revert "Revert "Use `esbuild` to bundle some CommonJS main files (#160957)" (#161118)"

This reverts commit 84c46b71a5.

* build - exclude server main files

* build - make concat a task that runs like the others

* some renames

* Avoid overwriting the nodejs closure require

* Revert "build - exclude server main files"

This reverts commit 736516624e.

Co-authored-by: Alex Dima <alexdima@microsoft.com>
This commit is contained in:
Benjamin Pasero 2022-09-21 00:38:44 -07:00 committed by GitHub
parent d4a02ffb61
commit 9db57e76e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 487 additions and 243 deletions

4
.vscode/launch.json vendored
View File

@ -29,7 +29,7 @@
"name": "Attach to Shared Process",
"timeout": 30000,
"port": 9222,
"urlFilter": "*sharedProcess.html*",
"urlFilter": "*sharedProcess*.html*",
"presentation": {
"hidden": true
}
@ -236,7 +236,7 @@
"VSCODE_SKIP_PRELAUNCH": "1"
},
"cleanUp": "wholeBrowser",
"urlFilter": "*workbench.html*",
"urlFilter": "*workbench*.html*",
"runtimeArgs": [
"--inspect-brk=5875",
"--no-cached-data",

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',
@ -81,23 +76,58 @@ const vscodeResources = [
'out-build/vs/workbench/contrib/tasks/**/*.json',
'out-build/vs/platform/files/**/*.exe',
'out-build/vs/platform/files/**/*.md',
'out-build/vs/code/electron-sandbox/workbench/**',
'out-build/vs/code/electron-browser/sharedProcess/sharedProcess.js',
'out-build/vs/code/electron-sandbox/issue/issueReporter.js',
'out-build/vs/code/electron-sandbox/processExplorer/processExplorer.js',
'!**/test/**'
];
// Do not change the order of these files! They will
// be inlined into the target window file in this order
// and they depend on each other in this way.
const windowBootstrapFiles = [
'out-build/bootstrap.js',
'out-build/vs/loader.js',
'out-build/bootstrap-window.js'
];
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: bundles source files automatically based on
// AMD and CommonJS import statements based on the passed
// in entry points. In addition, concat window related
// bootstrap files into a single file.
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'
]
},
manual: [
{ src: [...windowBootstrapFiles, 'out-build/vs/code/electron-sandbox/workbench/workbench.js'], out: 'vs/code/electron-sandbox/workbench/workbench.js' },
{ src: [...windowBootstrapFiles, 'out-build/vs/code/electron-sandbox/issue/issueReporter.js'], out: 'vs/code/electron-sandbox/issue/issueReporter.js' },
{ src: [...windowBootstrapFiles, 'out-build/vs/code/electron-sandbox/processExplorer/processExplorer.js'], out: 'vs/code/electron-sandbox/processExplorer/processExplorer.js' },
{ src: [...windowBootstrapFiles, 'out-build/vs/code/electron-browser/sharedProcess/sharedProcess.js'], out: 'vs/code/electron-browser/sharedProcess/sharedProcess.js' }
]
}
)
));
gulp.task(optimizeVSCodeTask);
@ -105,7 +135,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 +241,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,94 @@ 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 optimizeManualTask(options) {
const concatenations = options.map(opt => {
return gulp
.src(opt.src)
.pipe(concat(opt.out));
});
return es.merge(...concatenations);
}
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));
}
if (opts.manual) {
optimizers.push(optimizeManualTask(opts.manual));
}
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,164 @@ 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 interface IOptimizeManualTaskOpts {
/**
* The paths to consider for concatenation. The entries
* will be concatenated in the order they are provided.
*/
src: string[];
/**
* Destination target to concatenate the entryPoints into.
*/
out: string;
}
function optimizeManualTask(options: IOptimizeManualTaskOpts[]): NodeJS.ReadWriteStream {
const concatenations = options.map(opt => {
return gulp
.src(opt.src)
.pipe(concat(opt.out));
});
return es.merge(...concatenations);
}
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 {
/**
* Destination folder for the optimized files.
*/
out: string;
/**
* Optimize AMD modules (using our AMD loader).
*/
amd: IOptimizeAMDTaskOpts;
/**
* Optimize CommonJS modules (using esbuild).
*/
commonJS?: IOptimizeCommonJSTaskOpts;
/**
* Optimize manually by concatenating files.
*/
manual?: IOptimizeManualTaskOpts[];
}
export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStream {
return function () {
const optimizers = [optimizeAMDTask(opts.amd)];
if (opts.commonJS) {
optimizers.push(optimizeCommonJSTask(opts.commonJS));
}
if (opts.manual) {
optimizers.push(optimizeManualTask(opts.manual));
}
return es.merge(...optimizers).pipe(gulp.dest(opts.out));
};
}

View File

@ -460,4 +460,3 @@ export function buildWebNodePaths(outDir: string) {
result.taskName = 'build-web-node-paths';
return result;
}

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

@ -0,0 +1,18 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; connect-src 'self' https:;">
</head>
<body aria-label="">
Shared Process
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="sharedProcess.js"></script>
</html>

View File

@ -1,22 +1,15 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; connect-src 'self' https:;">
</head>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; connect-src 'self' https:;">
</head>
<body aria-label="">
Shared Process
</body>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<!-- Startup via sharedProcess.js -->
<script src="sharedProcess.js"></script>
<body aria-label="">
Shared Process
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="sharedProcess.js"></script>
</html>

View File

@ -0,0 +1,22 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
<style>
body {
display: none
}
</style>
</head>
<body aria-label="">
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="issueReporter.js"></script>
</html>

View File

@ -10,14 +10,10 @@
}
</style>
</head>
<body aria-label="">
</body>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<!-- Startup via issueReporter.js -->
<!-- Startup (do not modify order of script tags!) -->
<script src="issueReporter.js"></script>
</html>

View File

@ -0,0 +1,18 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
</head>
<body aria-label="">
<div id="process-list"></div>
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="processExplorer.js"></script>
</html>

View File

@ -5,15 +5,11 @@
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data:; media-src 'none'; child-src 'self'; object-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; connect-src 'self' https:; font-src 'self' https:;">
</head>
<body aria-label="">
<div id="process-list"></div>
</body>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<!-- Startup via processExplorer.js -->
<!-- Startup (do not modify order of script tags!) -->
<script src="processExplorer.js"></script>
</html>

View File

@ -0,0 +1,18 @@
<!-- Copyright (C) Microsoft Corporation. All rights reserved. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data: blob: vscode-remote-resource:; media-src 'self'; frame-src 'self' vscode-webview:; object-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; connect-src 'self' https: ws:; font-src 'self' https: vscode-remote-resource:;">
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'; trusted-types amdLoader cellRendererEditorText defaultWorkerFactory diffEditorWidget stickyScrollViewLayer editorGhostText domLineBreaksComputer editorViewLayer diffReview dompurify notebookRenderer safeInnerHtml standaloneColorizer tokenizeToString;">
</head>
<body aria-label="">
</body>
<!-- Startup (do not modify order of script tags!) -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<script src="workbench.js"></script>
</html>

View File

@ -6,14 +6,10 @@
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self' https: data: blob: vscode-remote-resource:; media-src 'self'; frame-src 'self' vscode-webview:; object-src 'self'; script-src 'self' 'unsafe-eval' blob:; style-src 'self' 'unsafe-inline'; connect-src 'self' https: ws:; font-src 'self' https: vscode-remote-resource:;">
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'; trusted-types amdLoader cellRendererEditorText defaultWorkerFactory diffEditorWidget stickyScrollViewLayer editorGhostText domLineBreaksComputer editorViewLayer diffReview dompurify notebookRenderer safeInnerHtml standaloneColorizer tokenizeToString;">
</head>
<body aria-label="">
</body>
<!-- Init Bootstrap Helpers -->
<script src="../../../../bootstrap.js"></script>
<script src="../../../../vs/loader.js"></script>
<script src="../../../../bootstrap-window.js"></script>
<!-- Startup via workbench.js -->
<!-- Startup (do not modify order of script tags!) -->
<script src="workbench.js"></script>
</html>

View File

@ -334,7 +334,7 @@ export async function main(argv: string[]): Promise<any> {
return false;
}
if (target.type === 'page') {
return target.url.indexOf('workbench/workbench.html') > 0;
return target.url.indexOf('workbench/workbench.html') > 0 || target.url.indexOf('workbench/workbench-dev.html') > 0;
} else {
return true;
}

View File

@ -1926,7 +1926,7 @@ var AMDLoader;
}
if (env.isNode && !env.isElectronRenderer && !env.isElectronNodeIntegrationWebWorker) {
module.exports = RequireFunc;
require = RequireFunc;
// require = RequireFunc;
}
else {
if (!env.isElectronRenderer) {

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) {
// 0. Running out of sources has a fixed productName
if (process.env['VSCODE_DEV']) {
@ -106,25 +107,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

@ -228,7 +228,7 @@ export class IssueMainService implements IIssueMainService {
});
this.issueReporterWindow.loadURL(
FileAccess.asBrowserUri('vs/code/electron-sandbox/issue/issueReporter.html', require).toString(true)
FileAccess.asBrowserUri(`vs/code/electron-sandbox/issue/issueReporter${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true)
);
this.issueReporterWindow.on('close', () => {
@ -279,7 +279,7 @@ export class IssueMainService implements IIssueMainService {
});
this.processExplorerWindow.loadURL(
FileAccess.asBrowserUri('vs/code/electron-sandbox/processExplorer/processExplorer.html', require).toString(true)
FileAccess.asBrowserUri(`vs/code/electron-sandbox/processExplorer/processExplorer${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true)
);
this.processExplorerWindow.on('close', () => {

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

@ -96,7 +96,7 @@ export class ProtocolMainService extends Disposable implements IProtocolMainServ
let headers: Record<string, string> | undefined;
if (this.environmentService.crossOriginIsolated) {
if (path.endsWith('/workbench.html')) {
if (path.endsWith('/workbench.html') || path.endsWith('/workbench-dev.html')) {
headers = COI.CoopAndCoep;
} else {
headers = COI.getHeadersFromQuery(request.url);

View File

@ -250,7 +250,7 @@ export class SharedProcess extends Disposable implements ISharedProcess {
});
// Load with config
this.window.loadURL(FileAccess.asBrowserUri('vs/code/electron-browser/sharedProcess/sharedProcess.html', require).toString(true));
this.window.loadURL(FileAccess.asBrowserUri(`vs/code/electron-browser/sharedProcess/sharedProcess${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true));
}
private registerWindowListeners(): void {

View File

@ -877,7 +877,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
this.readyState = ReadyState.NAVIGATING;
// Load URL
this._win.loadURL(FileAccess.asBrowserUri('vs/code/electron-sandbox/workbench/workbench.html', require).toString(true));
this._win.loadURL(FileAccess.asBrowserUri(`vs/code/electron-sandbox/workbench/workbench${this.environmentMainService.isBuilt ? '' : '-dev'}.html`, require).toString(true));
// Remember that we did load
const wasLoaded = this.wasLoaded;

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