vscode/build/gulpfile.vscode.web.js

231 lines
8.4 KiB
JavaScript
Raw Normal View History

2019-07-14 19:12:54 +08:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const gulp = require('gulp');
2021-10-21 00:42:13 +08:00
const path = require('path');
const es = require('event-stream');
const util = require('./lib/util');
2022-10-06 01:05:40 +08:00
const { getVersion } = require('./lib/getVersion');
2021-10-21 00:42:13 +08:00
const task = require('./lib/task');
const optimize = require('./lib/optimize');
const { readISODate } = require('./lib/date');
2021-10-21 00:42:13 +08:00
const product = require('../product.json');
const rename = require('gulp-rename');
const filter = require('gulp-filter');
const { getProductionDependencies } = require('./lib/dependencies');
const vfs = require('vinyl-fs');
const packageJson = require('../package.json');
const { compileBuildTask } = require('./gulpfile.compile');
const extensions = require('./lib/extensions');
const VinylFile = require('vinyl');
2019-07-14 19:12:54 +08:00
2021-10-21 00:42:13 +08:00
const REPO_ROOT = path.dirname(__dirname);
const BUILD_ROOT = path.dirname(REPO_ROOT);
const WEB_FOLDER = path.join(REPO_ROOT, 'remote', 'web');
2019-07-14 19:12:54 +08:00
2022-10-06 01:05:40 +08:00
const commit = getVersion(REPO_ROOT);
2021-10-21 00:42:13 +08:00
const quality = product.quality;
const version = (quality && quality !== 'stable') ? `${packageJson.version}-${quality}` : packageJson.version;
const vscodeWebResourceIncludes = [
2024-08-19 22:54:29 +08:00
// NLS
'out-build/nls.messages.js',
// Accessibility Signals
'out-build/vs/platform/accessibilitySignal/browser/media/*.mp3',
// Welcome
'out-build/vs/workbench/contrib/welcomeGettingStarted/common/media/**/*.{svg,png}',
// Extensions
'out-build/vs/workbench/contrib/extensions/browser/media/{theme-icon.png,language-icon.svg}',
'out-build/vs/workbench/services/extensionManagement/common/media/*.{svg,png}',
// Webview
'out-build/vs/workbench/contrib/webview/browser/pre/*.{js,html}',
// Tree Sitter highlights
'out-build/vs/editor/common/languages/highlights/*.scm',
2024-08-19 22:54:29 +08:00
// Extension Host Worker
'out-build/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html',
2021-10-21 00:42:13 +08:00
];
exports.vscodeWebResourceIncludes = vscodeWebResourceIncludes;
const vscodeWebResources = [
// Includes
...vscodeWebResourceIncludes,
// Excludes
'!out-build/vs/**/{node,electron-sandbox,electron-main,electron-utility}/**',
2021-10-21 00:42:13 +08:00
'!out-build/vs/editor/standalone/**',
'!out-build/vs/workbench/**/*-tb.png',
'!out-build/vs/code/**/*-dev.html',
2021-10-21 00:42:13 +08:00
'!**/test/**'
];
const buildfile = require('./buildfile');
2021-10-21 00:42:13 +08:00
const vscodeWebEntryPoints = [
buildfile.workerEditor,
2024-08-19 22:54:29 +08:00
buildfile.workerExtensionHost,
buildfile.workerNotebook,
buildfile.workerLanguageDetection,
buildfile.workerLocalFileSearch,
buildfile.workerOutputLinks,
buildfile.workerBackgroundTokenization,
buildfile.keyboardMaps,
buildfile.workbenchWeb,
buildfile.entrypoint('vs/workbench/workbench.web.main.internal') // TODO@esm remove line when we stop supporting web-amd-esm-bridge
].flat();
2021-10-21 00:42:13 +08:00
/**
* @param extensionsRoot {string} The location where extension will be read from
* @param {object} product The parsed product.json file contents
*/
const createVSCodeWebFileContentMapper = (extensionsRoot, product) => {
return path => {
2021-10-21 00:42:13 +08:00
if (path.endsWith('vs/platform/product/common/product.js')) {
return content => {
const productConfiguration = JSON.stringify({
...product,
version,
commit,
date: readISODate('out-build')
});
return content.replace('/*BUILD->INSERT_PRODUCT_CONFIGURATION*/', () => productConfiguration.substr(1, productConfiguration.length - 2) /* without { and }*/);
};
} else if (path.endsWith('vs/workbench/services/extensionManagement/browser/builtinExtensionsScannerService.js')) {
return content => {
const builtinExtensions = JSON.stringify(extensions.scanBuiltinExtensions(extensionsRoot));
return content.replace('/*BUILD->INSERT_BUILTIN_EXTENSIONS*/', () => builtinExtensions.substr(1, builtinExtensions.length - 2) /* without [ and ]*/);
};
2021-10-21 00:42:13 +08:00
}
return undefined;
2021-10-21 00:42:13 +08:00
};
2022-02-03 22:02:33 +08:00
};
2021-10-21 00:42:13 +08:00
exports.createVSCodeWebFileContentMapper = createVSCodeWebFileContentMapper;
const bundleVSCodeWebTask = task.define('bundle-vscode-web', task.series(
2021-10-21 00:42:13 +08:00
util.rimraf('out-vscode-web'),
optimize.bundleTask(
{
out: 'out-vscode-web',
2024-09-27 14:05:06 +08:00
esm: {
src: 'out-build',
2024-09-27 14:05:06 +08:00
entryPoints: vscodeWebEntryPoints,
resources: vscodeWebResources,
fileContentMapper: createVSCodeWebFileContentMapper('.build/web/extensions', product)
}
}
)
2021-10-21 00:42:13 +08:00
));
const minifyVSCodeWebTask = task.define('minify-vscode-web', task.series(
bundleVSCodeWebTask,
2021-10-21 00:42:13 +08:00
util.rimraf('out-vscode-web-min'),
optimize.minifyTask('out-vscode-web', `https://main.vscode-cdn.net/sourcemaps/${commit}/core`)
2021-10-21 00:42:13 +08:00
));
gulp.task(minifyVSCodeWebTask);
function packageTask(sourceFolderName, destinationFolderName) {
const destination = path.join(BUILD_ROOT, destinationFolderName);
return () => {
const json = require('gulp-json-editor');
const src = gulp.src(sourceFolderName + '/**', { base: '.' })
.pipe(rename(function (path) { path.dirname = path.dirname.replace(new RegExp('^' + sourceFolderName), 'out'); }));
const extensions = gulp.src('.build/web/extensions/**', { base: '.build/web', dot: true });
2021-10-21 00:42:13 +08:00
const loader = gulp.src('build/loader.min', { base: 'build', dot: true }).pipe(rename('out/vs/loader.js')); // TODO@esm remove line when we stop supporting web-amd-esm-bridge
const sources = es.merge(src, extensions, loader)
.pipe(filter(['**', '!**/*.js.map'], { dot: true }))
// TODO@esm remove me once we stop supporting our web-esm-bridge
.pipe(es.through(function (file) {
if (file.relative === 'out/vs/workbench/workbench.web.main.internal.css') {
this.emit('data', new VinylFile({
contents: file.contents,
path: file.path.replace('workbench.web.main.internal.css', 'workbench.web.main.css'),
base: file.base
}));
}
this.emit('data', file);
}));
2021-10-21 00:42:13 +08:00
const name = product.nameShort;
const packageJsonStream = gulp.src(['remote/web/package.json'], { base: 'remote/web' })
.pipe(json({ name, version }));
const license = gulp.src(['remote/LICENSE'], { base: 'remote', allowEmpty: true });
2021-10-21 00:42:13 +08:00
const productionDependencies = getProductionDependencies(WEB_FOLDER);
feat: switch to npm as default package manager (#226927) * feat: move from yarn to npm * chore: skip yarn.lock files * fix: playwright download * chore: fix compile and hygiene * chore: bump vsce@2.17.0 Refs https://github.com/microsoft/vscode-vsce/commit/8b49e9dfdf909ad3af2b9ec9c825f5b501f6d75e * test: update results for bat and sh colorizer tests * fix: add missing lock files for windows * fix: switch to legacy-peer-deps * chore: update markdown-it@14.1.0 Refs https://github.com/markdown-it/markdown-it/commit/737c95a12976357df99652e4b51d831cac4a75aa esbuild step in extensions-ci-pr was previously using markdown-it from root which had userland punycode and was able to compile successfully. * ci: increase pr timeout for windows integration tests * chore: fix product build * build: ignore extension dev dependency for rcedit * build: fix working directory inside container * build: fix dependency generation * npm: update dependencies * ci: use global npmrc * ci: update cache * ci: setup global npmrc for private npm auth * build: fix extension bundling * chore: sync npm dependencies * ci: debug env variables for container * ci: fix win32 cli pipeline * build: fix npmrc config usage for build/ and remote/ dirs * fix: windows build * fix: container builds * fix: markdown-language-features tests and bundling ``` [03:58:22] Error: Command failed: /Users/demohan/.nvm/versions/node/v20.15.1/bin/node /Users/demohan/github/vscode/extensions/markdown-language-features/esbuild-notebook.js --outputRoot /Users/demohan/github/vscode/.build/extensions/markdown-language-features ✘ [ERROR] Could not resolve "punycode" extensions/markdown-language-features/node_modules/markdown-it/lib/index.js:14:27: 14 │ var punycode = require('punycode'); ╵ ~~~~~~~~~~ The package "punycode" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. ``` Adds userland package based on https://github.com/markdown-it/markdown-it/commit/beed9aee2c1b44819afc25d485e86a6c699b6ef0 * fix: container builds for distro * chore: update yarn occurrences * fixup! chore: bump vsce@2.17.0 Uses the closest version to `main` branch that does not include https://github.com/microsoft/vscode-vsce/commit/d3cc84cdec99b8e9f24be63d1a2a54abe908f68b while still having the fix https://github.com/microsoft/vscode-vsce/commit/8b49e9dfdf909ad3af2b9ec9c825f5b501f6d75e * chore: sync npm dependencies * chore: sync npm dependencies * chore: sync npm dependencies * chore: throw error when yarn is used for installation * chore: add review feedback * chore: switch exec => run where needed * chore: npm sync dependencies * fix: markdown-language-features bundling ``` ✘ [ERROR] Could not resolve "punycode" extensions/markdown-language-features/node_modules/markdown-it/lib/index.js:14:27: 14 │ var punycode = require('punycode'); ╵ ~~~~~~~~~~ The package "punycode" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error. ``` Adds missing userland package based on markdown-it/markdown-it@beed9ae, can be removed once we update markdown-it >= 14.1.0 * ci: rename no-yarn-lock-changes.yml * chore: sync npm dependencies * ci: restore no-yarn-lock-changes.yml We can disable it in a separate PR to keep the required checks happy and also need workflow edit perms. * chore: sync npm dependencies * ci: rebuild cache * ci: fix no-package-lock-changes.yml * chore: bump distro * chore: rm yarn.lock files * chore: rm yarn.lock files without dependencies * chore: add vscode-selfhost-import-aid to postinstall dirs * chore: bump distro
2024-09-06 21:18:02 +08:00
const dependenciesSrc = productionDependencies.map(d => path.relative(REPO_ROOT, d)).map(d => [`${d}/**`, `!${d}/**/{test,tests}/**`, `!${d}/.bin/**`]).flat();
2021-10-21 00:42:13 +08:00
const deps = gulp.src(dependenciesSrc, { base: 'remote/web', dot: true })
.pipe(filter(['**', '!**/package-lock.json']))
.pipe(util.cleanNodeModules(path.join(__dirname, '.webignore')));
const favicon = gulp.src('resources/server/favicon.ico', { base: 'resources/server' });
const manifest = gulp.src('resources/server/manifest.json', { base: 'resources/server' });
const pwaicons = es.merge(
gulp.src('resources/server/code-192.png', { base: 'resources/server' }),
gulp.src('resources/server/code-512.png', { base: 'resources/server' })
);
2022-06-08 23:49:21 +08:00
const all = es.merge(
2021-10-21 00:42:13 +08:00
packageJsonStream,
license,
sources,
deps,
favicon,
manifest,
2022-02-15 23:22:06 +08:00
pwaicons
2021-10-21 00:42:13 +08:00
);
2022-06-08 23:49:21 +08:00
const result = all
2021-10-21 00:42:13 +08:00
.pipe(util.skipDirectories())
.pipe(util.fixWin32DirectoryPermissions());
return result.pipe(vfs.dest(destination));
};
}
const compileWebExtensionsBuildTask = task.define('compile-web-extensions-build', task.series(
task.define('clean-web-extensions-build', util.rimraf('.build/web/extensions')),
Adopt the MSAL broker to talk to the OS for Microsoft auth (#233739) This adopts the `NativeBrokerPlugin` provided by `@azure/msal-node-extensions` to provide the ability to use auth state from the OS, and show native auth dialogs instead of going to the browser. This has several pieces: * The adoption of the broker in the microsoft-authentication extension: * Adding `NativeBrokerPlugin` to our PCAs * Using the proposed handle API to pass the native window handle down to MSAL calls (btw, this API will change in a follow up PR) * Adopting an AccountAccess layer to handle: * giving the user control of which accounts VS Code uses * an eventing layer so that auth state can be updated across multiple windows * Getting the extension to build properly and only build what it really needs. This required several package.json/webpack hacks: * Use a fake keytar since we don't use the feature in `@azure/msal-node-extensions` that uses keytar * Use a fake dpapi layer since we don't use the feature in `@azure/msal-node-extensions` that uses it * Ensure the msal runtime `.node` and `.dll` files are included in the bundle * Get the VS Code build to allow a native node module in an extension: by having a list of native extensions that will be built in the "ci" part of the build - in other words when VS Code is building on the target platform There are a couple of followups: * Refactor the `handle` API to handle (heh) Auxiliary Windows https://github.com/microsoft/vscode/issues/233106 * Separate the call to `acquireTokenSilent` and `acquireTokenInteractive` and all the usage of this native node module into a separate process or maybe in Core... we'll see. Something to experiment with after we have something working. NEEDS FOLLOW UP ISSUE Fixes https://github.com/microsoft/vscode/issues/229431
2024-11-15 19:53:28 +08:00
task.define('bundle-web-extensions-build', () => extensions.packageAllLocalExtensionsStream(true, false).pipe(gulp.dest('.build/web'))),
task.define('bundle-marketplace-web-extensions-build', () => extensions.packageMarketplaceExtensionsStream(true).pipe(gulp.dest('.build/web'))),
2021-10-21 00:42:13 +08:00
task.define('bundle-web-extension-media-build', () => extensions.buildExtensionMedia(false, '.build/web/extensions')),
));
gulp.task(compileWebExtensionsBuildTask);
2022-03-01 06:32:12 +08:00
const dashed = (/** @type {string} */ str) => (str ? `-${str}` : ``);
2021-10-21 00:42:13 +08:00
['', 'min'].forEach(minified => {
const sourceFolderName = `out-vscode-web${dashed(minified)}`;
const destinationFolderName = `vscode-web`;
const vscodeWebTaskCI = task.define(`vscode-web${dashed(minified)}-ci`, task.series(
compileWebExtensionsBuildTask,
minified ? minifyVSCodeWebTask : bundleVSCodeWebTask,
2021-10-21 00:42:13 +08:00
util.rimraf(path.join(BUILD_ROOT, destinationFolderName)),
packageTask(sourceFolderName, destinationFolderName)
));
gulp.task(vscodeWebTaskCI);
const vscodeWebTask = task.define(`vscode-web${dashed(minified)}`, task.series(
compileBuildTask,
vscodeWebTaskCI
));
gulp.task(vscodeWebTask);
});