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' ) ;
2022-09-21 15:38:44 +08:00
const optimize = require ( './lib/optimize' ) ;
2024-07-06 02:06:43 +08:00
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' ) ;
2024-09-03 03:09:12 +08:00
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 ;
2024-09-27 14:04:00 +08:00
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}' ,
2024-08-20 23:06:21 +08:00
// Tree Sitter highlights
'out-build/vs/editor/common/languages/highlights/*.scm' ,
2024-08-19 22:54:29 +08:00
// Extension Host Worker
2024-09-27 14:04:16 +08:00
'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
2024-09-05 15:49:23 +08:00
'!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' ,
2024-08-15 02:48:27 +08:00
'!out-build/vs/code/**/*-dev.html' ,
2021-10-21 00:42:13 +08:00
'!**/test/**'
] ;
2024-08-23 18:18:26 +08:00
const buildfile = require ( './buildfile' ) ;
2021-10-21 00:42:13 +08:00
2024-09-27 14:04:00 +08:00
const vscodeWebEntryPoints = [
2024-09-27 14:04:34 +08:00
buildfile . workerEditor ,
2024-08-19 22:54:29 +08:00
buildfile . workerExtensionHost ,
buildfile . workerNotebook ,
buildfile . workerLanguageDetection ,
buildfile . workerLocalFileSearch ,
buildfile . workerOutputLinks ,
buildfile . workerBackgroundTokenization ,
buildfile . keyboardMaps ,
2024-09-27 14:04:00 +08:00
buildfile . workbenchWeb ,
2024-09-03 03:09:12 +08:00
buildfile . entrypoint ( 'vs/workbench/workbench.web.main.internal' ) // TODO@esm remove line when we stop supporting web-amd-esm-bridge
2023-02-03 19:47:51 +08:00
] . flat ( ) ;
2021-10-21 00:42:13 +08:00
2022-02-04 02:27:53 +08:00
/ * *
2024-10-04 21:34:21 +08:00
* @ param extensionsRoot { string } The location where extension will be read from
2022-02-04 02:27:53 +08:00
* @ param { object } product The parsed product . json file contents
* /
2024-10-04 21:34:21 +08:00
const createVSCodeWebFileContentMapper = ( extensionsRoot , product ) => {
return path => {
2021-10-21 00:42:13 +08:00
if ( path . endsWith ( 'vs/platform/product/common/product.js' ) ) {
2024-10-04 21:34:21 +08:00
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
}
2024-10-04 21:34:21 +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 ;
2024-10-06 20:12:20 +08:00
const bundleVSCodeWebTask = task . define ( 'bundle-vscode-web' , task . series (
2021-10-21 00:42:13 +08:00
util . rimraf ( 'out-vscode-web' ) ,
2024-10-06 20:12:20 +08:00
optimize . bundleTask (
2022-09-21 15:38:44 +08:00
{
out : 'out-vscode-web' ,
2024-09-27 14:05:06 +08:00
esm : {
2022-09-21 15:38:44 +08:00
src : 'out-build' ,
2024-09-27 14:05:06 +08:00
entryPoints : vscodeWebEntryPoints ,
2022-09-21 15:38:44 +08:00
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 (
2024-10-06 20:12:20 +08:00
bundleVSCodeWebTask ,
2021-10-21 00:42:13 +08:00
util . rimraf ( 'out-vscode-web-min' ) ,
2024-06-03 22:10:01 +08:00
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' ) ; } ) ) ;
2024-08-28 20:24:52 +08:00
const extensions = gulp . src ( '.build/web/extensions/**' , { base : '.build/web' , dot : true } ) ;
2021-10-21 00:42:13 +08:00
2024-09-03 03:09:12 +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
2024-09-27 14:04:00 +08:00
const sources = es . merge ( src , extensions , loader )
2024-09-03 03:09:12 +08:00
. 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 } ) ) ;
2021-10-21 21:28:37 +08:00
const license = gulp . src ( [ 'remote/LICENSE' ] , { base : 'remote' , allowEmpty : true } ) ;
2021-10-21 00:42:13 +08:00
const productionDependencies = getProductionDependencies ( WEB _FOLDER ) ;
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' ) ) ,
2024-11-15 19:53:28 +08:00
task . define ( 'bundle-web-extensions-build' , ( ) => extensions . packageAllLocalExtensionsStream ( true , false ) . pipe ( gulp . dest ( '.build/web' ) ) ) ,
2022-08-03 06:27:16 +08:00
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 ,
2024-10-06 20:12:20 +08:00
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 ) ;
} ) ;