From 21135c81b538c0abaebf94c6c448ae4836fa3e38 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 2 Sep 2024 21:09:12 +0200 Subject: [PATCH] esm - provide a bridge to AMD world (#227361) --- .eslintrc.json | 27 ++ .vscode/settings.json | 3 +- build/buildfile.js | 2 +- build/gulpfile.reh.js | 2 +- build/gulpfile.vscode.web.js | 23 +- build/lib/optimize.js | 2 +- build/lib/optimize.ts | 2 +- build/loader.min | 10 + src/vs/code/browser/workbench/workbench.html | 2 +- src/vs/code/browser/workbench/workbench.ts | 2 +- .../workbench/workbench.web.main.internal.ts | 240 +++++++++++++++ src/vs/workbench/workbench.web.main.ts | 276 ++++++------------ 12 files changed, 388 insertions(+), 203 deletions(-) create mode 100644 build/loader.min create mode 100644 src/vs/workbench/workbench.web.main.internal.ts diff --git a/.eslintrc.json b/.eslintrc.json index 93564f5c0b1..68555ead5ad 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -943,6 +943,14 @@ "when": "hasBrowser", "pattern": "vs/workbench/workbench.web.main.js" }, + { + "when": "hasBrowser", + "pattern": "vs/workbench/workbench.web.main.internal" + }, + { + "when": "hasBrowser", + "pattern": "vs/workbench/workbench.web.main.internal.js" + }, { "when": "hasBrowser", "pattern": "vs/workbench/~" @@ -1011,6 +1019,25 @@ "vs/workbench/workbench.common.main.js" ] }, + { + "target": "src/vs/workbench/workbench.web.main.internal.ts", + "layer": "browser", + "restrictions": [ + "vs/base/~", + "vs/base/parts/*/~", + "vs/platform/*/~", + "vs/editor/~", + "vs/editor/contrib/*/~", + "vs/editor/editor.all", + "vs/editor/editor.all.js", + "vs/workbench/~", + "vs/workbench/api/~", + "vs/workbench/services/*/~", + "vs/workbench/contrib/*/~", + "vs/workbench/workbench.common.main", + "vs/workbench/workbench.common.main.js" + ] + }, { "target": "src/vs/workbench/workbench.desktop.main.ts", "layer": "electron-sandbox", diff --git a/.vscode/settings.json b/.vscode/settings.json index 6ddb8c1b9dc..9b1f61acd7d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,7 @@ "src/vs/workbench/api/test/browser/extHostDocumentData.test.perf-data.ts": true, "src/vs/base/test/node/uri.test.data.txt": true, "src/vs/editor/test/node/diffing/fixtures/**": true, + "build/loader.min": true }, "files.readonlyInclude": { "**/node_modules/**/*.*": true, @@ -162,7 +163,7 @@ "@xterm/headless", "node-pty", "vscode-notebook-renderer", - "src/vs/workbench/workbench.web.main.ts" + "src/vs/workbench/workbench.web.main.internal.ts" ], "[github-issues]": { "editor.wordWrap": "on" diff --git a/build/buildfile.js b/build/buildfile.js index 2ecda819e82..14eeb9c1187 100644 --- a/build/buildfile.js +++ b/build/buildfile.js @@ -95,7 +95,7 @@ exports.workbenchWeb = function () { ] : [ ...createEditorWorkerModuleDescription('vs/workbench/contrib/output/common/outputLinkComputer'), ...createEditorWorkerModuleDescription('vs/workbench/services/textMate/browser/backgroundTokenization/worker/textMateTokenizationWorker.worker'), - createModuleDescription('vs/code/browser/workbench/workbench', ['vs/workbench/workbench.web.main']) + createModuleDescription('vs/code/browser/workbench/workbench', ['vs/workbench/workbench.web.main.internal']) ]; }; diff --git a/build/gulpfile.reh.js b/build/gulpfile.reh.js index 409d89ed8d9..01ea17ee82f 100644 --- a/build/gulpfile.reh.js +++ b/build/gulpfile.reh.js @@ -142,7 +142,7 @@ const webEntryPoints = !isAMD() ? [ buildfile.keyboardMaps, buildfile.codeWeb ].flat() : [ - buildfile.entrypoint('vs/workbench/workbench.web.main'), + buildfile.entrypoint('vs/workbench/workbench.web.main.internal'), buildfile.base, buildfile.workerExtensionHost, buildfile.workerNotebook, diff --git a/build/gulpfile.vscode.web.js b/build/gulpfile.vscode.web.js index 085ed1e2b34..3eb25153de1 100644 --- a/build/gulpfile.vscode.web.js +++ b/build/gulpfile.vscode.web.js @@ -22,6 +22,7 @@ const packageJson = require('../package.json'); const { compileBuildTask } = require('./gulpfile.compile'); const extensions = require('./lib/extensions'); const { isAMD } = require('./lib/amd'); +const VinylFile = require('vinyl'); const REPO_ROOT = path.dirname(__dirname); const BUILD_ROOT = path.dirname(REPO_ROOT); @@ -105,9 +106,10 @@ const vscodeWebEntryPoints = !isAMD() ? [ buildfile.workerOutputLinks, buildfile.workerBackgroundTokenization, buildfile.keyboardMaps, - buildfile.workbenchWeb() + buildfile.workbenchWeb(), + buildfile.entrypoint('vs/workbench/workbench.web.main.internal') // TODO@esm remove line when we stop supporting web-amd-esm-bridge ].flat() : [ - buildfile.entrypoint('vs/workbench/workbench.web.main'), + buildfile.entrypoint('vs/workbench/workbench.web.main.internal'), buildfile.base, buildfile.workerExtensionHost, buildfile.workerNotebook, @@ -229,8 +231,21 @@ function packageTask(sourceFolderName, destinationFolderName) { const extensions = gulp.src('.build/web/extensions/**', { base: '.build/web', dot: true }); - const sources = es.merge(src, extensions) - .pipe(filter(['**', '!**/*.js.map'], { dot: true })); + 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(...(!isAMD() ? [src, extensions, loader] : [src, extensions])) + .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); + })); const name = product.nameShort; const packageJsonStream = gulp.src(['remote/web/package.json'], { base: 'remote/web' }) diff --git a/build/lib/optimize.js b/build/lib/optimize.js index 51cd2f25c59..7bc26570b45 100644 --- a/build/lib/optimize.js +++ b/build/lib/optimize.js @@ -255,7 +255,7 @@ function optimizeESMTask(opts, cjsOpts) { '.sh': 'file', }, assetNames: 'media/[name]', // moves media assets into a sub-folder "media" - banner, + banner: entryPoint.name === 'vs/workbench/workbench.web.main' ? undefined : banner, // TODO@esm remove line when we stop supporting web-amd-esm-bridge entryPoints: [ { in: path.join(REPO_ROOT_PATH, opts.src, `${entryPoint.name}.js`), diff --git a/build/lib/optimize.ts b/build/lib/optimize.ts index e57122731f8..f30f0d85b98 100644 --- a/build/lib/optimize.ts +++ b/build/lib/optimize.ts @@ -343,7 +343,7 @@ function optimizeESMTask(opts: IOptimizeAMDTaskOpts, cjsOpts?: IOptimizeCommonJS '.sh': 'file', }, assetNames: 'media/[name]', // moves media assets into a sub-folder "media" - banner, + banner: entryPoint.name === 'vs/workbench/workbench.web.main' ? undefined : banner, // TODO@esm remove line when we stop supporting web-amd-esm-bridge entryPoints: [ { in: path.join(REPO_ROOT_PATH, opts.src, `${entryPoint.name}.js`), diff --git a/build/loader.min b/build/loader.min new file mode 100644 index 00000000000..f9d21b58282 --- /dev/null +++ b/build/loader.min @@ -0,0 +1,10 @@ +/*--------------------------------------------------------------------------------------------- + * 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 _amdLoaderGlobal=this,_commonjsGlobal=typeof global=="object"?global:{};var AMDLoader;(function(d){d.global=_amdLoaderGlobal;class _{get isWindows(){return this._detect(),this._isWindows}get isNode(){return this._detect(),this._isNode}get isElectronRenderer(){return this._detect(),this._isElectronRenderer}get isWebWorker(){return this._detect(),this._isWebWorker}get isElectronNodeIntegrationWebWorker(){return this._detect(),this._isElectronNodeIntegrationWebWorker}constructor(){this._detected=!1,this._isWindows=!1,this._isNode=!1,this._isElectronRenderer=!1,this._isWebWorker=!1,this._isElectronNodeIntegrationWebWorker=!1}_detect(){this._detected||(this._detected=!0,this._isWindows=_._isWindows(),this._isNode=typeof module<"u"&&!!module.exports,this._isElectronRenderer=typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.electron<"u"&&process.type==="renderer",this._isWebWorker=typeof d.global.importScripts=="function",this._isElectronNodeIntegrationWebWorker=this._isWebWorker&&typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.electron<"u"&&process.type==="worker")}static _isWindows(){return typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.indexOf("Windows")>=0?!0:typeof process<"u"?process.platform==="win32":!1}}d.Environment=_})(AMDLoader||(AMDLoader={}));var AMDLoader;(function(d){class _{constructor(n,c,a){this.type=n,this.detail=c,this.timestamp=a}}d.LoaderEvent=_;class v{constructor(n){this._events=[new _(1,"",n)]}record(n,c){this._events.push(new _(n,c,d.Utilities.getHighPerformanceTimestamp()))}getEvents(){return this._events}}d.LoaderEventRecorder=v;class f{record(n,c){}getEvents(){return[]}}f.INSTANCE=new f,d.NullLoaderEventRecorder=f})(AMDLoader||(AMDLoader={}));var AMDLoader;(function(d){class _{static fileUriToFilePath(f,h){if(h=decodeURI(h).replace(/%23/g,"#"),f){if(/^file:\/\/\//.test(h))return h.substr(8);if(/^file:\/\//.test(h))return h.substr(5)}else if(/^file:\/\//.test(h))return h.substr(7);return h}static startsWith(f,h){return f.length>=h.length&&f.substr(0,h.length)===h}static endsWith(f,h){return f.length>=h.length&&f.substr(f.length-h.length)===h}static containsQueryString(f){return/^[^\#]*\?/gi.test(f)}static isAbsolutePath(f){return/^((http:\/\/)|(https:\/\/)|(file:\/\/)|(\/))/.test(f)}static forEachProperty(f,h){if(f){let n;for(n in f)f.hasOwnProperty(n)&&h(n,f[n])}}static isEmpty(f){let h=!0;return _.forEachProperty(f,()=>{h=!1}),h}static recursiveClone(f){if(!f||typeof f!="object"||f instanceof RegExp||!Array.isArray(f)&&Object.getPrototypeOf(f)!==Object.prototype)return f;let h=Array.isArray(f)?[]:{};return _.forEachProperty(f,(n,c)=>{c&&typeof c=="object"?h[n]=_.recursiveClone(c):h[n]=c}),h}static generateAnonymousModule(){return"===anonymous"+_.NEXT_ANONYMOUS_ID+++"==="}static isAnonymousModule(f){return _.startsWith(f,"===anonymous")}static getHighPerformanceTimestamp(){return this.PERFORMANCE_NOW_PROBED||(this.PERFORMANCE_NOW_PROBED=!0,this.HAS_PERFORMANCE_NOW=d.global.performance&&typeof d.global.performance.now=="function"),this.HAS_PERFORMANCE_NOW?d.global.performance.now():Date.now()}}_.NEXT_ANONYMOUS_ID=1,_.PERFORMANCE_NOW_PROBED=!1,_.HAS_PERFORMANCE_NOW=!1,d.Utilities=_})(AMDLoader||(AMDLoader={}));var AMDLoader;(function(d){function _(h){if(h instanceof Error)return h;const n=new Error(h.message||String(h)||"Unknown Error");return h.stack&&(n.stack=h.stack),n}d.ensureError=_;class v{static validateConfigurationOptions(n){function c(a){if(a.phase==="loading"){console.error('Loading "'+a.moduleId+'" failed'),console.error(a),console.error("Here are the modules that depend on it:"),console.error(a.neededBy);return}if(a.phase==="factory"){console.error('The factory function of "'+a.moduleId+'" has thrown an exception'),console.error(a),console.error("Here are the modules that depend on it:"),console.error(a.neededBy);return}}if(n=n||{},typeof n.baseUrl!="string"&&(n.baseUrl=""),typeof n.isBuild!="boolean"&&(n.isBuild=!1),typeof n.paths!="object"&&(n.paths={}),typeof n.config!="object"&&(n.config={}),typeof n.catchError>"u"&&(n.catchError=!1),typeof n.recordStats>"u"&&(n.recordStats=!1),typeof n.urlArgs!="string"&&(n.urlArgs=""),typeof n.onError!="function"&&(n.onError=c),Array.isArray(n.ignoreDuplicateModules)||(n.ignoreDuplicateModules=[]),n.baseUrl.length>0&&(d.Utilities.endsWith(n.baseUrl,"/")||(n.baseUrl+="/")),typeof n.cspNonce!="string"&&(n.cspNonce=""),typeof n.preferScriptTags>"u"&&(n.preferScriptTags=!1),n.nodeCachedData&&typeof n.nodeCachedData=="object"&&(typeof n.nodeCachedData.seed!="string"&&(n.nodeCachedData.seed="seed"),(typeof n.nodeCachedData.writeDelay!="number"||n.nodeCachedData.writeDelay<0)&&(n.nodeCachedData.writeDelay=1e3*7),!n.nodeCachedData.path||typeof n.nodeCachedData.path!="string")){const a=_(new Error("INVALID cached data configuration, 'path' MUST be set"));a.phase="configuration",n.onError(a),n.nodeCachedData=void 0}return n}static mergeConfigurationOptions(n=null,c=null){let a=d.Utilities.recursiveClone(c||{});return d.Utilities.forEachProperty(n,(t,e)=>{t==="ignoreDuplicateModules"&&typeof a.ignoreDuplicateModules<"u"?a.ignoreDuplicateModules=a.ignoreDuplicateModules.concat(e):t==="paths"&&typeof a.paths<"u"?d.Utilities.forEachProperty(e,(i,s)=>a.paths[i]=s):t==="config"&&typeof a.config<"u"?d.Utilities.forEachProperty(e,(i,s)=>a.config[i]=s):a[t]=d.Utilities.recursiveClone(e)}),v.validateConfigurationOptions(a)}}d.ConfigurationOptionsUtil=v;class f{constructor(n,c){if(this._env=n,this.options=v.mergeConfigurationOptions(c),this._createIgnoreDuplicateModulesMap(),this._createSortedPathsRules(),this.options.baseUrl===""&&this.options.nodeRequire&&this.options.nodeRequire.main&&this.options.nodeRequire.main.filename&&this._env.isNode){let a=this.options.nodeRequire.main.filename,t=Math.max(a.lastIndexOf("/"),a.lastIndexOf("\\"));this.options.baseUrl=a.substring(0,t+1)}}_createIgnoreDuplicateModulesMap(){this.ignoreDuplicateModulesMap={};for(let n=0;n{Array.isArray(c)?this.sortedPathsRules.push({from:n,to:c}):this.sortedPathsRules.push({from:n,to:[c]})}),this.sortedPathsRules.sort((n,c)=>c.from.length-n.from.length)}cloneAndMerge(n){return new f(this._env,v.mergeConfigurationOptions(n,this.options))}getOptionsLiteral(){return this.options}_applyPaths(n){let c;for(let a=0,t=this.sortedPathsRules.length;athis.triggerCallback(i),u=>this.triggerErrorback(i,u))}triggerCallback(e){let i=this._callbackMap[e];delete this._callbackMap[e];for(let s=0;s{e.removeEventListener("load",o),e.removeEventListener("error",u)},o=l=>{r(),i()},u=l=>{r(),s(l)};e.addEventListener("load",o),e.addEventListener("error",u)}load(e,i,s,r){if(/^node\|/.test(i)){let o=e.getConfig().getOptionsLiteral(),u=c(e.getRecorder(),o.nodeRequire||d.global.nodeRequire),l=i.split("|"),g=null;try{g=u(l[1])}catch(p){r(p);return}e.enqueueDefineAnonymousModule([],()=>g),s()}else{let o=document.createElement("script");o.setAttribute("async","async"),o.setAttribute("type","text/javascript"),this.attachListeners(o,s,r);const{trustedTypesPolicy:u}=e.getConfig().getOptionsLiteral();u&&(i=u.createScriptURL(i)),o.setAttribute("src",i);const{cspNonce:l}=e.getConfig().getOptionsLiteral();l&&o.setAttribute("nonce",l),document.getElementsByTagName("head")[0].appendChild(o)}}}function f(t){const{trustedTypesPolicy:e}=t.getConfig().getOptionsLiteral();try{return(e?self.eval(e.createScript("","true")):new Function("true")).call(self),!0}catch{return!1}}class h{constructor(){this._cachedCanUseEval=null}_canUseEval(e){return this._cachedCanUseEval===null&&(this._cachedCanUseEval=f(e)),this._cachedCanUseEval}load(e,i,s,r){if(/^node\|/.test(i)){const o=e.getConfig().getOptionsLiteral(),u=c(e.getRecorder(),o.nodeRequire||d.global.nodeRequire),l=i.split("|");let g=null;try{g=u(l[1])}catch(p){r(p);return}e.enqueueDefineAnonymousModule([],function(){return g}),s()}else{const{trustedTypesPolicy:o}=e.getConfig().getOptionsLiteral();if(!(/^((http:)|(https:)|(file:))/.test(i)&&i.substring(0,self.origin.length)!==self.origin)&&this._canUseEval(e)){fetch(i).then(l=>{if(l.status!==200)throw new Error(l.statusText);return l.text()}).then(l=>{l=`${l} +//# sourceURL=${i}`,(o?self.eval(o.createScript("",l)):new Function(l)).call(self),s()}).then(void 0,r);return}try{o&&(i=o.createScriptURL(i)),importScripts(i),s()}catch(l){r(l)}}}}class n{constructor(e){this._env=e,this._didInitialize=!1,this._didPatchNodeRequire=!1}_init(e){this._didInitialize||(this._didInitialize=!0,this._fs=e("fs"),this._vm=e("vm"),this._path=e("path"),this._crypto=e("crypto"))}_initNodeRequire(e,i){const{nodeCachedData:s}=i.getConfig().getOptionsLiteral();if(!s||this._didPatchNodeRequire)return;this._didPatchNodeRequire=!0;const r=this,o=e("module");function u(l){const g=l.constructor;let p=function(y){try{return l.require(y)}finally{}};return p.resolve=function(y,E){return g._resolveFilename(y,l,!1,E)},p.resolve.paths=function(y){return g._resolveLookupPaths(y,l)},p.main=process.mainModule,p.extensions=g._extensions,p.cache=g._cache,p}o.prototype._compile=function(l,g){const p=o.wrap(l.replace(/^#!.*/,"")),m=i.getRecorder(),y=r._getCachedDataPath(s,g),E={filename:g};let R;try{const x=r._fs.readFileSync(y);R=x.slice(0,16),E.cachedData=x.slice(16),m.record(60,y)}catch{m.record(61,y)}const C=new r._vm.Script(p,E),I=C.runInThisContext(E),w=r._path.dirname(g),b=u(this),U=[this.exports,b,this,g,w,process,_commonjsGlobal,Buffer],P=I.apply(this.exports,U);return r._handleCachedData(C,p,y,!E.cachedData,i),r._verifyCachedData(C,p,y,R,i),P}}load(e,i,s,r){const o=e.getConfig().getOptionsLiteral(),u=c(e.getRecorder(),o.nodeRequire||d.global.nodeRequire),l=o.nodeInstrumenter||function(p){return p};this._init(u),this._initNodeRequire(u,e);let g=e.getRecorder();if(/^node\|/.test(i)){let p=i.split("|"),m=null;try{m=u(p[1])}catch(y){r(y);return}e.enqueueDefineAnonymousModule([],()=>m),s()}else{i=d.Utilities.fileUriToFilePath(this._env.isWindows,i);const p=this._path.normalize(i),m=this._getElectronRendererScriptPathOrUri(p),y=!!o.nodeCachedData,E=y?this._getCachedDataPath(o.nodeCachedData,i):void 0;this._readSourceAndCachedData(p,E,g,(R,C,I,w)=>{if(R){r(R);return}let b;C.charCodeAt(0)===n._BOM?b=n._PREFIX+C.substring(1)+n._SUFFIX:b=n._PREFIX+C+n._SUFFIX,b=l(b,p);const U={filename:m,cachedData:I},P=this._createAndEvalScript(e,b,U,s,r);this._handleCachedData(P,b,E,y&&!I,e),this._verifyCachedData(P,b,E,w,e)})}}_createAndEvalScript(e,i,s,r,o){const u=e.getRecorder();u.record(31,s.filename);const l=new this._vm.Script(i,s),g=l.runInThisContext(s),p=e.getGlobalAMDDefineFunc();let m=!1;const y=function(){return m=!0,p.apply(null,arguments)};return y.amd=p.amd,g.call(d.global,e.getGlobalAMDRequireFunc(),y,s.filename,this._path.dirname(s.filename)),u.record(32,s.filename),m?r():o(new Error(`Didn't receive define call in ${s.filename}!`)),l}_getElectronRendererScriptPathOrUri(e){if(!this._env.isElectronRenderer)return e;let i=e.match(/^([a-z])\:(.*)/i);return i?`file:///${(i[1].toUpperCase()+":"+i[2]).replace(/\\/g,"/")}`:`file://${e}`}_getCachedDataPath(e,i){const s=this._crypto.createHash("md5").update(i,"utf8").update(e.seed,"utf8").update(process.arch,"").digest("hex"),r=this._path.basename(i).replace(/\.js$/,"");return this._path.join(e.path,`${r}-${s}.code`)}_handleCachedData(e,i,s,r,o){e.cachedDataRejected?this._fs.unlink(s,u=>{o.getRecorder().record(62,s),this._createAndWriteCachedData(e,i,s,o),u&&o.getConfig().onError(u)}):r&&this._createAndWriteCachedData(e,i,s,o)}_createAndWriteCachedData(e,i,s,r){let o=Math.ceil(r.getConfig().getOptionsLiteral().nodeCachedData.writeDelay*(1+Math.random())),u=-1,l=0,g;const p=()=>{setTimeout(()=>{g||(g=this._crypto.createHash("md5").update(i,"utf8").digest());const m=e.createCachedData();if(!(m.length===0||m.length===u||l>=5)){if(m.length{y&&r.getConfig().onError(y),r.getRecorder().record(63,s),p()})}},o*Math.pow(4,l++))};p()}_readSourceAndCachedData(e,i,s,r){if(!i)this._fs.readFile(e,{encoding:"utf8"},r);else{let o,u,l,g=2;const p=m=>{m?r(m):--g===0&&r(void 0,o,u,l)};this._fs.readFile(e,{encoding:"utf8"},(m,y)=>{o=y,p(m)}),this._fs.readFile(i,(m,y)=>{!m&&y&&y.length>0?(l=y.slice(0,16),u=y.slice(16),s.record(60,i)):s.record(61,i),p()})}}_verifyCachedData(e,i,s,r,o){r&&(e.cachedDataRejected||setTimeout(()=>{const u=this._crypto.createHash("md5").update(i,"utf8").digest();r.equals(u)||(o.getConfig().onError(new Error(`FAILED TO VERIFY CACHED DATA, deleting stale '${s}' now, but a RESTART IS REQUIRED`)),this._fs.unlink(s,l=>{l&&o.getConfig().onError(l)}))},Math.ceil(5e3*(1+Math.random()))))}}n._BOM=65279,n._PREFIX="(function (require, define, __filename, __dirname) { ",n._SUFFIX=` +});`;function c(t,e){if(e.__$__isRecorded)return e;const i=function(r){t.record(33,r);try{return e(r)}finally{t.record(34,r)}};return i.__$__isRecorded=!0,i}d.ensureRecordedNodeRequire=c;function a(t){return new _(t)}d.createScriptLoader=a})(AMDLoader||(AMDLoader={}));var AMDLoader;(function(d){class _{constructor(t){let e=t.lastIndexOf("/");e!==-1?this.fromModulePath=t.substr(0,e+1):this.fromModulePath=""}static _normalizeModuleId(t){let e=t,i;for(i=/\/\.\//;i.test(e);)e=e.replace(i,"/");for(e=e.replace(/^\.\//g,""),i=/\/(([^\/])|([^\/][^\/\.])|([^\/\.][^\/])|([^\/][^\/][^\/]+))\/\.\.\//;i.test(e);)e=e.replace(i,"/");return e=e.replace(/^(([^\/])|([^\/][^\/\.])|([^\/\.][^\/])|([^\/][^\/][^\/]+))\/\.\.\//,""),e}resolveModule(t){let e=t;return d.Utilities.isAbsolutePath(e)||(d.Utilities.startsWith(e,"./")||d.Utilities.startsWith(e,"../"))&&(e=_._normalizeModuleId(this.fromModulePath+e)),e}}_.ROOT=new _(""),d.ModuleIdResolver=_;class v{constructor(t,e,i,s,r,o){this.id=t,this.strId=e,this.dependencies=i,this._callback=s,this._errorback=r,this.moduleIdResolver=o,this.exports={},this.error=null,this.exportsPassedIn=!1,this.unresolvedDependenciesCount=this.dependencies.length,this._isComplete=!1}static _safeInvokeFunction(t,e){try{return{returnedValue:t.apply(d.global,e),producedError:null}}catch(i){return{returnedValue:null,producedError:i}}}static _invokeFactory(t,e,i,s){return t.shouldInvokeFactory(e)?t.shouldCatchError()?this._safeInvokeFunction(i,s):{returnedValue:i.apply(d.global,s),producedError:null}:{returnedValue:null,producedError:null}}complete(t,e,i,s){this._isComplete=!0;let r=null;if(this._callback)if(typeof this._callback=="function"){t.record(21,this.strId);let o=v._invokeFactory(e,this.strId,this._callback,i);r=o.producedError,t.record(22,this.strId),!r&&typeof o.returnedValue<"u"&&(!this.exportsPassedIn||d.Utilities.isEmpty(this.exports))&&(this.exports=o.returnedValue)}else this.exports=this._callback;if(r){let o=d.ensureError(r);o.phase="factory",o.moduleId=this.strId,o.neededBy=s(this.id),this.error=o,e.onError(o)}this.dependencies=null,this._callback=null,this._errorback=null,this.moduleIdResolver=null}onDependencyError(t){return this._isComplete=!0,this.error=t,this._errorback?(this._errorback(t),!0):!1}isComplete(){return this._isComplete}}d.Module=v;class f{constructor(){this._nextId=0,this._strModuleIdToIntModuleId=new Map,this._intModuleIdToStrModuleId=[],this.getModuleId("exports"),this.getModuleId("module"),this.getModuleId("require")}getMaxModuleId(){return this._nextId}getModuleId(t){let e=this._strModuleIdToIntModuleId.get(t);return typeof e>"u"&&(e=this._nextId++,this._strModuleIdToIntModuleId.set(t,e),this._intModuleIdToStrModuleId[e]=t),e}getStrModuleId(t){return this._intModuleIdToStrModuleId[t]}}class h{constructor(t){this.id=t}}h.EXPORTS=new h(0),h.MODULE=new h(1),h.REQUIRE=new h(2),d.RegularDependency=h;class n{constructor(t,e,i){this.id=t,this.pluginId=e,this.pluginParam=i}}d.PluginDependency=n;class c{constructor(t,e,i,s,r=0){this._env=t,this._scriptLoader=e,this._loaderAvailableTimestamp=r,this._defineFunc=i,this._requireFunc=s,this._moduleIdProvider=new f,this._config=new d.Configuration(this._env),this._hasDependencyCycle=!1,this._modules2=[],this._knownModules2=[],this._inverseDependencies2=[],this._inversePluginDependencies2=new Map,this._currentAnonymousDefineCall=null,this._recorder=null,this._buildInfoPath=[],this._buildInfoDefineStack=[],this._buildInfoDependencies=[],this._requireFunc.moduleManager=this}reset(){return new c(this._env,this._scriptLoader,this._defineFunc,this._requireFunc,this._loaderAvailableTimestamp)}getGlobalAMDDefineFunc(){return this._defineFunc}getGlobalAMDRequireFunc(){return this._requireFunc}static _findRelevantLocationInStack(t,e){let i=o=>o.replace(/\\/g,"/"),s=i(t),r=e.split(/\n/);for(let o=0;othis._moduleIdProvider.getStrModuleId(g.id))),this._resolve(l)}_normalizeDependency(t,e){if(t==="exports")return h.EXPORTS;if(t==="module")return h.MODULE;if(t==="require")return h.REQUIRE;let i=t.indexOf("!");if(i>=0){let s=e.resolveModule(t.substr(0,i)),r=e.resolveModule(t.substr(i+1)),o=this._moduleIdProvider.getModuleId(s+"!"+r),u=this._moduleIdProvider.getModuleId(s);return new n(o,u,r)}return new h(this._moduleIdProvider.getModuleId(e.resolveModule(t)))}_normalizeDependencies(t,e){let i=[],s=0;for(let r=0,o=t.length;rthis._moduleIdProvider.getStrModuleId(o));const r=d.ensureError(e);return r.phase="loading",r.moduleId=i,r.neededBy=s,r}_onLoadError(t,e){const i=this._createLoadError(t,e);this._modules2[t]||(this._modules2[t]=new v(t,this._moduleIdProvider.getStrModuleId(t),[],()=>{},null,null));let s=[];for(let u=0,l=this._moduleIdProvider.getMaxModuleId();u0;){let u=o.shift(),l=this._modules2[u];l&&(r=l.onDependencyError(i)||r);let g=this._inverseDependencies2[u];if(g)for(let p=0,m=g.length;p0;){let u=r.shift().dependencies;if(u)for(let l=0,g=u.length;lthis._relativeRequire(t,i,s,r);return e.toUrl=i=>this._config.requireToUrl(t.resolveModule(i)),e.getStats=()=>this.getLoaderEvents(),e.hasDependencyCycle=()=>this._hasDependencyCycle,e.config=(i,s=!1)=>{this.configure(i,s)},e.__$__nodeRequire=d.global.nodeRequire,e}_loadModule(t){if(this._modules2[t]||this._knownModules2[t])return;this._knownModules2[t]=!0;let e=this._moduleIdProvider.getStrModuleId(t),i=this._config.moduleIdToPaths(e),s=/^@[^\/]+\/[^\/]+$/;this._env.isNode&&(e.indexOf("/")===-1||s.test(e))&&i.push("node|"+e);let r=-1,o=u=>{if(r++,r>=i.length)this._onLoadError(t,u);else{let l=i[r],g=this.getRecorder();if(this._config.isBuild()&&l==="empty:"){this._buildInfoPath[t]=l,this.defineModule(this._moduleIdProvider.getStrModuleId(t),[],null,null,null),this._onLoad(t);return}g.record(10,l),this._scriptLoader.load(this,l,()=>{this._config.isBuild()&&(this._buildInfoPath[t]=l),g.record(11,l),this._onLoad(t)},p=>{g.record(12,l),o(p)})}};o(null)}_loadPluginDependency(t,e){if(this._modules2[e.id]||this._knownModules2[e.id])return;this._knownModules2[e.id]=!0;let i=s=>{this.defineModule(this._moduleIdProvider.getStrModuleId(e.id),[],s,null,null)};i.error=s=>{this._config.onError(this._createLoadError(e.id,s))},t.load(e.pluginParam,this._createRequire(_.ROOT),i,this._config.getOptionsLiteral())}_resolve(t){let e=t.dependencies;if(e)for(let i=0,s=e.length;ithis._moduleIdProvider.getStrModuleId(l)).join(` => +`)),t.unresolvedDependenciesCount--;continue}if(this._inverseDependencies2[r.id]=this._inverseDependencies2[r.id]||[],this._inverseDependencies2[r.id].push(t.id),r instanceof n){let u=this._modules2[r.pluginId];if(u&&u.isComplete()){this._loadPluginDependency(u.exports,r);continue}let l=this._inversePluginDependencies2.get(r.pluginId);l||(l=[],this._inversePluginDependencies2.set(r.pluginId,l)),l.push(r),this._loadModule(r.pluginId);continue}this._loadModule(r.id)}t.unresolvedDependenciesCount===0&&this._onModuleComplete(t)}_onModuleComplete(t){let e=this.getRecorder();if(t.isComplete())return;let i=t.dependencies,s=[];if(i)for(let l=0,g=i.length;lthis._config.getConfigForModule(t.strId)};continue}if(p===h.REQUIRE){s[l]=this._createRequire(t.moduleIdResolver);continue}let m=this._modules2[p.id];if(m){s[l]=m.exports;continue}s[l]=null}const r=l=>(this._inverseDependencies2[l]||[]).map(g=>this._moduleIdProvider.getStrModuleId(g));t.complete(e,this._config,s,r);let o=this._inverseDependencies2[t.id];if(this._inverseDependencies2[t.id]=null,o)for(let l=0,g=o.length;l"u"&&c())})(AMDLoader||(AMDLoader={})),define("vs/css",["require","exports"],function(d,_){"use strict";Object.defineProperty(_,"__esModule",{value:!0}),_.load=v;function v(a,t,e,i){if(i=i||{},(i["vs/css"]||{}).disabled){e({});return}const r=t.toUrl(a+".css");f(a,r,()=>{e({})},o=>{typeof e.error=="function"&&e.error("Could not find "+r+".")})}function f(a,t,e,i){if(h(a,t)){e();return}n(a,t,e,i)}function h(a,t){const e=window.document.getElementsByTagName("link");for(let i=0,s=e.length;i{t.removeEventListener("load",r),t.removeEventListener("error",o)},r=u=>{s(),e()},o=u=>{s(),i(u)};t.addEventListener("load",r),t.addEventListener("error",o)}}),function(){const d=require.getConfig().baseUrl||"https://main.vscode-cdn.net/insider/336db9ece67f682159078ea1b54212de7636d88a/out";require.config({baseUrl:d,recordStats:!0,paths:{"@microsoft/1ds-core-js":"../node_modules/@microsoft/1ds-core-js/dist/ms.core.min.js","@microsoft/1ds-post-js":"../node_modules/@microsoft/1ds-post-js/dist/ms.post.min.js","@vscode/iconv-lite-umd":"../node_modules/@vscode/iconv-lite-umd/lib/iconv-lite-umd.js","@vscode/tree-sitter-wasm":"../node_modules/@vscode/tree-sitter-wasm/wasm/tree-sitter.js","@vscode/vscode-languagedetection":"../node_modules/@vscode/vscode-languagedetection/dist/lib/index.js","@xterm/addon-clipboard":"../node_modules/@xterm/addon-clipboard/lib/addon-clipboard.js","@xterm/addon-image":"../node_modules/@xterm/addon-image/lib/addon-image.js","@xterm/addon-search":"../node_modules/@xterm/addon-search/lib/addon-search.js","@xterm/addon-serialize":"../node_modules/@xterm/addon-serialize/lib/addon-serialize.js","@xterm/addon-unicode11":"../node_modules/@xterm/addon-unicode11/lib/addon-unicode11.js","@xterm/addon-webgl":"../node_modules/@xterm/addon-webgl/lib/addon-webgl.js","@xterm/xterm":"../node_modules/@xterm/xterm/lib/xterm.js",jschardet:"../node_modules/jschardet/dist/jschardet.min.js","tas-client-umd":"../node_modules/tas-client-umd/lib/tas-client-umd.js","vscode-oniguruma":"../node_modules/vscode-oniguruma/release/main.js","vscode-textmate":"../node_modules/vscode-textmate/release/main.js","vscode-regexp-languagedetection":"../node_modules/vscode-regexp-languagedetection/dist/index.js",vsda:"../node_modules/vsda/rust/web/vsda.js","@microsoft/dynamicproto-js":"../node_modules/@microsoft/dynamicproto-js/lib/dist/umd/dynamicproto-js.min.js","@microsoft/applicationinsights-shims":"../node_modules/@microsoft/applicationinsights-shims/dist/umd/applicationinsights-shims.min.js","@microsoft/applicationinsights-core-js":"../node_modules/@microsoft/applicationinsights-core-js/browser/applicationinsights-core-js.min.js"}})}(); + +//# sourceMappingURL=https://main.vscode-cdn.net/sourcemaps/336db9ece67f682159078ea1b54212de7636d88a/core/vs/loader.js.map diff --git a/src/vs/code/browser/workbench/workbench.html b/src/vs/code/browser/workbench/workbench.html index 019f0b949f0..a4e95165cfb 100644 --- a/src/vs/code/browser/workbench/workbench.html +++ b/src/vs/code/browser/workbench/workbench.html @@ -65,6 +65,6 @@ - + diff --git a/src/vs/code/browser/workbench/workbench.ts b/src/vs/code/browser/workbench/workbench.ts index 62ecdb7f863..b98867e7ac3 100644 --- a/src/vs/code/browser/workbench/workbench.ts +++ b/src/vs/code/browser/workbench/workbench.ts @@ -20,7 +20,7 @@ import { isFolderToOpen, isWorkspaceToOpen } from '../../../platform/window/comm import type { IWorkbenchConstructionOptions, IWorkspace, IWorkspaceProvider } from '../../../workbench/browser/web.api.js'; import { AuthenticationSessionInfo } from '../../../workbench/services/authentication/browser/authenticationService.js'; import type { IURLCallbackProvider } from '../../../workbench/services/url/browser/urlService.js'; -import { create } from '../../../workbench/workbench.web.main.js'; +import { create } from '../../../workbench/workbench.web.main.internal.js'; interface ISecretStorageCrypto { seal(data: string): Promise; diff --git a/src/vs/workbench/workbench.web.main.internal.ts b/src/vs/workbench/workbench.web.main.internal.ts new file mode 100644 index 00000000000..402696a4a83 --- /dev/null +++ b/src/vs/workbench/workbench.web.main.internal.ts @@ -0,0 +1,240 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + + +// ####################################################################### +// ### ### +// ### !!! PLEASE ADD COMMON IMPORTS INTO WORKBENCH.COMMON.MAIN.TS !!! ### +// ### ### +// ####################################################################### + + +//#region --- workbench common + +import './workbench.common.main.js'; + +//#endregion + + +//#region --- workbench parts + +import './browser/parts/dialogs/dialog.web.contribution.js'; + +//#endregion + + +//#region --- workbench (web main) + +import './browser/web.main.js'; + +//#endregion + + +//#region --- workbench services + +import './services/integrity/browser/integrityService.js'; +import './services/search/browser/searchService.js'; +import './services/textfile/browser/browserTextFileService.js'; +import './services/keybinding/browser/keyboardLayoutService.js'; +import './services/extensions/browser/extensionService.js'; +import './services/extensionManagement/browser/extensionsProfileScannerService.js'; +import './services/extensions/browser/extensionsScannerService.js'; +import './services/extensionManagement/browser/webExtensionsScannerService.js'; +import './services/extensionManagement/common/extensionManagementServerService.js'; +import './services/telemetry/browser/telemetryService.js'; +import './services/url/browser/urlService.js'; +import './services/update/browser/updateService.js'; +import './services/workspaces/browser/workspacesService.js'; +import './services/workspaces/browser/workspaceEditingService.js'; +import './services/dialogs/browser/fileDialogService.js'; +import './services/host/browser/browserHostService.js'; +import './services/lifecycle/browser/lifecycleService.js'; +import './services/clipboard/browser/clipboardService.js'; +import './services/localization/browser/localeService.js'; +import './services/path/browser/pathService.js'; +import './services/themes/browser/browserHostColorSchemeService.js'; +import './services/encryption/browser/encryptionService.js'; +import './services/secrets/browser/secretStorageService.js'; +import './services/workingCopy/browser/workingCopyBackupService.js'; +import './services/tunnel/browser/tunnelService.js'; +import './services/files/browser/elevatedFileService.js'; +import './services/workingCopy/browser/workingCopyHistoryService.js'; +import './services/userDataSync/browser/webUserDataSyncEnablementService.js'; +import './services/userDataProfile/browser/userDataProfileStorageService.js'; +import './services/configurationResolver/browser/configurationResolverService.js'; +import '../platform/extensionResourceLoader/browser/extensionResourceLoaderService.js'; +import './services/auxiliaryWindow/browser/auxiliaryWindowService.js'; + +import { InstantiationType, registerSingleton } from '../platform/instantiation/common/extensions.js'; +import { IAccessibilityService } from '../platform/accessibility/common/accessibility.js'; +import { IContextMenuService } from '../platform/contextview/browser/contextView.js'; +import { ContextMenuService } from '../platform/contextview/browser/contextMenuService.js'; +import { IExtensionTipsService } from '../platform/extensionManagement/common/extensionManagement.js'; +import { ExtensionTipsService } from '../platform/extensionManagement/common/extensionTipsService.js'; +import { IWorkbenchExtensionManagementService } from './services/extensionManagement/common/extensionManagement.js'; +import { ExtensionManagementService } from './services/extensionManagement/common/extensionManagementService.js'; +import { LogLevel } from '../platform/log/common/log.js'; +import { UserDataSyncMachinesService, IUserDataSyncMachinesService } from '../platform/userDataSync/common/userDataSyncMachines.js'; +import { IUserDataSyncStoreService, IUserDataSyncService, IUserDataAutoSyncService, IUserDataSyncLocalStoreService, IUserDataSyncResourceProviderService } from '../platform/userDataSync/common/userDataSync.js'; +import { UserDataSyncStoreService } from '../platform/userDataSync/common/userDataSyncStoreService.js'; +import { UserDataSyncLocalStoreService } from '../platform/userDataSync/common/userDataSyncLocalStoreService.js'; +import { UserDataSyncService } from '../platform/userDataSync/common/userDataSyncService.js'; +import { IUserDataSyncAccountService, UserDataSyncAccountService } from '../platform/userDataSync/common/userDataSyncAccount.js'; +import { UserDataAutoSyncService } from '../platform/userDataSync/common/userDataAutoSyncService.js'; +import { AccessibilityService } from '../platform/accessibility/browser/accessibilityService.js'; +import { ICustomEndpointTelemetryService } from '../platform/telemetry/common/telemetry.js'; +import { NullEndpointTelemetryService } from '../platform/telemetry/common/telemetryUtils.js'; +import { ITitleService } from './services/title/browser/titleService.js'; +import { BrowserTitleService } from './browser/parts/titlebar/titlebarPart.js'; +import { ITimerService, TimerService } from './services/timer/browser/timerService.js'; +import { IDiagnosticsService, NullDiagnosticsService } from '../platform/diagnostics/common/diagnostics.js'; +import { ILanguagePackService } from '../platform/languagePacks/common/languagePacks.js'; +import { WebLanguagePacksService } from '../platform/languagePacks/browser/languagePacks.js'; + +registerSingleton(IWorkbenchExtensionManagementService, ExtensionManagementService, InstantiationType.Delayed); +registerSingleton(IAccessibilityService, AccessibilityService, InstantiationType.Delayed); +registerSingleton(IContextMenuService, ContextMenuService, InstantiationType.Delayed); +registerSingleton(IUserDataSyncStoreService, UserDataSyncStoreService, InstantiationType.Delayed); +registerSingleton(IUserDataSyncMachinesService, UserDataSyncMachinesService, InstantiationType.Delayed); +registerSingleton(IUserDataSyncLocalStoreService, UserDataSyncLocalStoreService, InstantiationType.Delayed); +registerSingleton(IUserDataSyncAccountService, UserDataSyncAccountService, InstantiationType.Delayed); +registerSingleton(IUserDataSyncService, UserDataSyncService, InstantiationType.Delayed); +registerSingleton(IUserDataSyncResourceProviderService, UserDataSyncResourceProviderService, InstantiationType.Delayed); +registerSingleton(IUserDataAutoSyncService, UserDataAutoSyncService, InstantiationType.Eager /* Eager to start auto sync */); +registerSingleton(ITitleService, BrowserTitleService, InstantiationType.Eager); +registerSingleton(IExtensionTipsService, ExtensionTipsService, InstantiationType.Delayed); +registerSingleton(ITimerService, TimerService, InstantiationType.Delayed); +registerSingleton(ICustomEndpointTelemetryService, NullEndpointTelemetryService, InstantiationType.Delayed); +registerSingleton(IDiagnosticsService, NullDiagnosticsService, InstantiationType.Delayed); +registerSingleton(ILanguagePackService, WebLanguagePacksService, InstantiationType.Delayed); + +//#endregion + + +//#region --- workbench contributions + +// Logs +import './contrib/logs/browser/logs.contribution.js'; + +// Localization +import './contrib/localization/browser/localization.contribution.js'; + +// Performance +import './contrib/performance/browser/performance.web.contribution.js'; + +// Preferences +import './contrib/preferences/browser/keyboardLayoutPicker.js'; + +// Debug +import './contrib/debug/browser/extensionHostDebugService.js'; + +// Welcome Banner +import './contrib/welcomeBanner/browser/welcomeBanner.contribution.js'; + +// Welcome Dialog +import './contrib/welcomeDialog/browser/welcomeDialog.contribution.js'; + +// Webview +import './contrib/webview/browser/webview.web.contribution.js'; + +// Extensions Management +import './contrib/extensions/browser/extensions.web.contribution.js'; + +// Terminal +import './contrib/terminal/browser/terminal.web.contribution.js'; +import './contrib/externalTerminal/browser/externalTerminal.contribution.js'; +import './contrib/terminal/browser/terminalInstanceService.js'; + +// Tasks +import './contrib/tasks/browser/taskService.js'; + +// Tags +import './contrib/tags/browser/workspaceTagsService.js'; + +// Issues +import './contrib/issue/browser/issue.contribution.js'; + +// Splash +import './contrib/splash/browser/splash.contribution.js'; + +// Remote Start Entry for the Web +import './contrib/remote/browser/remoteStartEntry.contribution.js'; + +//#endregion + + +//#region --- export workbench factory + +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +// +// Do NOT change these exports in a way that something is removed unless +// intentional. These exports are used by web embedders and thus require +// an adoption when something changes. +// +// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +import { create, commands, env, window, workspace, logger } from './browser/web.factory.js'; +import { Menu } from './browser/web.api.js'; +import { URI } from '../base/common/uri.js'; +import { Event, Emitter } from '../base/common/event.js'; +import { Disposable } from '../base/common/lifecycle.js'; +import { GroupOrientation } from './services/editor/common/editorGroupsService.js'; +import { UserDataSyncResourceProviderService } from '../platform/userDataSync/common/userDataSyncResourceProvider.js'; +import { RemoteAuthorityResolverError, RemoteAuthorityResolverErrorCode } from '../platform/remote/common/remoteAuthorityResolver.js'; + +// TODO@esm remove me once we stop supporting our web-esm-bridge +if ((globalThis as any).__VSCODE_WEB_ESM_PROMISE) { + const exports = { + + // Factory + create: create, + + // Basic Types + URI: URI, + Event: Event, + Emitter: Emitter, + Disposable: Disposable, + // GroupOrientation, + LogLevel: LogLevel, + RemoteAuthorityResolverError: RemoteAuthorityResolverError, + RemoteAuthorityResolverErrorCode: RemoteAuthorityResolverErrorCode, + + // Facade API + env: env, + window: window, + workspace: workspace, + commands: commands, + logger: logger, + Menu: Menu + }; + (globalThis as any).__VSCODE_WEB_ESM_PROMISE(exports); + delete (globalThis as any).__VSCODE_WEB_ESM_PROMISE; +} + +export { + + // Factory + create, + + // Basic Types + URI, + Event, + Emitter, + Disposable, + GroupOrientation, + LogLevel, + RemoteAuthorityResolverError, + RemoteAuthorityResolverErrorCode, + + // Facade API + env, + window, + workspace, + commands, + logger, + Menu +}; + +//#endregion diff --git a/src/vs/workbench/workbench.web.main.ts b/src/vs/workbench/workbench.web.main.ts index af4cc20d087..aec1e18c4e3 100644 --- a/src/vs/workbench/workbench.web.main.ts +++ b/src/vs/workbench/workbench.web.main.ts @@ -4,208 +4,100 @@ *--------------------------------------------------------------------------------------------*/ -// ####################################################################### -// ### ### -// ### !!! PLEASE ADD COMMON IMPORTS INTO WORKBENCH.COMMON.MAIN.TS !!! ### -// ### ### -// ####################################################################### +// #################################### +// ### ### +// ### !!! PLEASE DO NOT MODIFY !!! ### +// ### ### +// #################################### +// TODO@esm remove me once we stop supporting our web-esm-bridge -//#region --- workbench common +(function () { -import './workbench.common.main.js'; + // #region Types + type IGlobalDefine = { + (moduleName: string, dependencies: string[], callback: (...args: any[]) => any): any; + (moduleName: string, dependencies: string[], definition: any): any; + (moduleName: string, callback: (...args: any[]) => any): any; + (moduleName: string, definition: any): any; + (dependencies: string[], callback: (...args: any[]) => any): any; + (dependencies: string[], definition: any): any; + }; -//#endregion + interface ILoaderPlugin { + load: (pluginParam: string, parentRequire: IRelativeRequire, loadCallback: IPluginLoadCallback, options: IConfigurationOptions) => void; + write?: (pluginName: string, moduleName: string, write: IPluginWriteCallback) => void; + writeFile?: (pluginName: string, moduleName: string, req: IRelativeRequire, write: IPluginWriteFileCallback, config: IConfigurationOptions) => void; + finishBuild?: (write: (filename: string, contents: string) => void) => void; + } + interface IRelativeRequire { + (dependencies: string[], callback: Function, errorback?: (error: Error) => void): void; + toUrl(id: string): string; + } + interface IPluginLoadCallback { + (value: any): void; + error(err: any): void; + } + interface IConfigurationOptions { + isBuild: boolean | undefined; + [key: string]: any; + } + interface IPluginWriteCallback { + (contents: string): void; + getEntryPoint(): string; + asModule(moduleId: string, contents: string): void; + } + interface IPluginWriteFileCallback { + (filename: string, contents: string): void; + getEntryPoint(): string; + asModule(moduleId: string, contents: string): void; + } + //#endregion -//#region --- workbench parts + const define: IGlobalDefine = (globalThis as any).define; + const require: { getConfig?(): any } | undefined = (globalThis as any).require; -import './browser/parts/dialogs/dialog.web.contribution.js'; + if (!define || !require || typeof require.getConfig !== 'function') { + throw new Error('Expected global define() and require() functions. Please only load this module in an AMD context!'); + } -//#endregion + let baseUrl = require?.getConfig().baseUrl; + if (!baseUrl) { + throw new Error('Failed to determine baseUrl for loading AMD modules (tried require.getConfig().baseUrl)'); + } + if (!baseUrl.endsWith('/')) { + baseUrl = baseUrl + '/'; + } + globalThis._VSCODE_FILE_ROOT = baseUrl; + const trustedTypesPolicy: Pick, 'name' | 'createScriptURL'> | undefined = require.getConfig().trustedTypesPolicy; + if (trustedTypesPolicy) { + globalThis._VSCODE_WEB_PACKAGE_TTP = trustedTypesPolicy; + } -//#region --- workbench (web main) + const promise = new Promise(resolve => { + (globalThis as any).__VSCODE_WEB_ESM_PROMISE = resolve; + }); -import './browser/web.main.js'; + define('vs/web-api', [], () => { + return { + load: (_name, _req, _load, _config) => { + const script: any = document.createElement('script'); + script.type = 'module'; + script.src = trustedTypesPolicy ? trustedTypesPolicy.createScriptURL(`${baseUrl}vs/workbench/workbench.web.main.internal.js`) as any as string : `${baseUrl}vs/workbench/workbench.web.main.internal.js`; + document.head.appendChild(script); -//#endregion + return promise.then(mod => _load(mod)); + } + } as ILoaderPlugin; + }); - -//#region --- workbench services - -import './services/integrity/browser/integrityService.js'; -import './services/search/browser/searchService.js'; -import './services/textfile/browser/browserTextFileService.js'; -import './services/keybinding/browser/keyboardLayoutService.js'; -import './services/extensions/browser/extensionService.js'; -import './services/extensionManagement/browser/extensionsProfileScannerService.js'; -import './services/extensions/browser/extensionsScannerService.js'; -import './services/extensionManagement/browser/webExtensionsScannerService.js'; -import './services/extensionManagement/common/extensionManagementServerService.js'; -import './services/telemetry/browser/telemetryService.js'; -import './services/url/browser/urlService.js'; -import './services/update/browser/updateService.js'; -import './services/workspaces/browser/workspacesService.js'; -import './services/workspaces/browser/workspaceEditingService.js'; -import './services/dialogs/browser/fileDialogService.js'; -import './services/host/browser/browserHostService.js'; -import './services/lifecycle/browser/lifecycleService.js'; -import './services/clipboard/browser/clipboardService.js'; -import './services/localization/browser/localeService.js'; -import './services/path/browser/pathService.js'; -import './services/themes/browser/browserHostColorSchemeService.js'; -import './services/encryption/browser/encryptionService.js'; -import './services/secrets/browser/secretStorageService.js'; -import './services/workingCopy/browser/workingCopyBackupService.js'; -import './services/tunnel/browser/tunnelService.js'; -import './services/files/browser/elevatedFileService.js'; -import './services/workingCopy/browser/workingCopyHistoryService.js'; -import './services/userDataSync/browser/webUserDataSyncEnablementService.js'; -import './services/userDataProfile/browser/userDataProfileStorageService.js'; -import './services/configurationResolver/browser/configurationResolverService.js'; -import '../platform/extensionResourceLoader/browser/extensionResourceLoaderService.js'; -import './services/auxiliaryWindow/browser/auxiliaryWindowService.js'; - -import { InstantiationType, registerSingleton } from '../platform/instantiation/common/extensions.js'; -import { IAccessibilityService } from '../platform/accessibility/common/accessibility.js'; -import { IContextMenuService } from '../platform/contextview/browser/contextView.js'; -import { ContextMenuService } from '../platform/contextview/browser/contextMenuService.js'; -import { IExtensionTipsService } from '../platform/extensionManagement/common/extensionManagement.js'; -import { ExtensionTipsService } from '../platform/extensionManagement/common/extensionTipsService.js'; -import { IWorkbenchExtensionManagementService } from './services/extensionManagement/common/extensionManagement.js'; -import { ExtensionManagementService } from './services/extensionManagement/common/extensionManagementService.js'; -import { LogLevel } from '../platform/log/common/log.js'; -import { UserDataSyncMachinesService, IUserDataSyncMachinesService } from '../platform/userDataSync/common/userDataSyncMachines.js'; -import { IUserDataSyncStoreService, IUserDataSyncService, IUserDataAutoSyncService, IUserDataSyncLocalStoreService, IUserDataSyncResourceProviderService } from '../platform/userDataSync/common/userDataSync.js'; -import { UserDataSyncStoreService } from '../platform/userDataSync/common/userDataSyncStoreService.js'; -import { UserDataSyncLocalStoreService } from '../platform/userDataSync/common/userDataSyncLocalStoreService.js'; -import { UserDataSyncService } from '../platform/userDataSync/common/userDataSyncService.js'; -import { IUserDataSyncAccountService, UserDataSyncAccountService } from '../platform/userDataSync/common/userDataSyncAccount.js'; -import { UserDataAutoSyncService } from '../platform/userDataSync/common/userDataAutoSyncService.js'; -import { AccessibilityService } from '../platform/accessibility/browser/accessibilityService.js'; -import { ICustomEndpointTelemetryService } from '../platform/telemetry/common/telemetry.js'; -import { NullEndpointTelemetryService } from '../platform/telemetry/common/telemetryUtils.js'; -import { ITitleService } from './services/title/browser/titleService.js'; -import { BrowserTitleService } from './browser/parts/titlebar/titlebarPart.js'; -import { ITimerService, TimerService } from './services/timer/browser/timerService.js'; -import { IDiagnosticsService, NullDiagnosticsService } from '../platform/diagnostics/common/diagnostics.js'; -import { ILanguagePackService } from '../platform/languagePacks/common/languagePacks.js'; -import { WebLanguagePacksService } from '../platform/languagePacks/browser/languagePacks.js'; - -registerSingleton(IWorkbenchExtensionManagementService, ExtensionManagementService, InstantiationType.Delayed); -registerSingleton(IAccessibilityService, AccessibilityService, InstantiationType.Delayed); -registerSingleton(IContextMenuService, ContextMenuService, InstantiationType.Delayed); -registerSingleton(IUserDataSyncStoreService, UserDataSyncStoreService, InstantiationType.Delayed); -registerSingleton(IUserDataSyncMachinesService, UserDataSyncMachinesService, InstantiationType.Delayed); -registerSingleton(IUserDataSyncLocalStoreService, UserDataSyncLocalStoreService, InstantiationType.Delayed); -registerSingleton(IUserDataSyncAccountService, UserDataSyncAccountService, InstantiationType.Delayed); -registerSingleton(IUserDataSyncService, UserDataSyncService, InstantiationType.Delayed); -registerSingleton(IUserDataSyncResourceProviderService, UserDataSyncResourceProviderService, InstantiationType.Delayed); -registerSingleton(IUserDataAutoSyncService, UserDataAutoSyncService, InstantiationType.Eager /* Eager to start auto sync */); -registerSingleton(ITitleService, BrowserTitleService, InstantiationType.Eager); -registerSingleton(IExtensionTipsService, ExtensionTipsService, InstantiationType.Delayed); -registerSingleton(ITimerService, TimerService, InstantiationType.Delayed); -registerSingleton(ICustomEndpointTelemetryService, NullEndpointTelemetryService, InstantiationType.Delayed); -registerSingleton(IDiagnosticsService, NullDiagnosticsService, InstantiationType.Delayed); -registerSingleton(ILanguagePackService, WebLanguagePacksService, InstantiationType.Delayed); - -//#endregion - - -//#region --- workbench contributions - -// Logs -import './contrib/logs/browser/logs.contribution.js'; - -// Localization -import './contrib/localization/browser/localization.contribution.js'; - -// Performance -import './contrib/performance/browser/performance.web.contribution.js'; - -// Preferences -import './contrib/preferences/browser/keyboardLayoutPicker.js'; - -// Debug -import './contrib/debug/browser/extensionHostDebugService.js'; - -// Welcome Banner -import './contrib/welcomeBanner/browser/welcomeBanner.contribution.js'; - -// Welcome Dialog -import './contrib/welcomeDialog/browser/welcomeDialog.contribution.js'; - -// Webview -import './contrib/webview/browser/webview.web.contribution.js'; - -// Extensions Management -import './contrib/extensions/browser/extensions.web.contribution.js'; - -// Terminal -import './contrib/terminal/browser/terminal.web.contribution.js'; -import './contrib/externalTerminal/browser/externalTerminal.contribution.js'; -import './contrib/terminal/browser/terminalInstanceService.js'; - -// Tasks -import './contrib/tasks/browser/taskService.js'; - -// Tags -import './contrib/tags/browser/workspaceTagsService.js'; - -// Issues -import './contrib/issue/browser/issue.contribution.js'; - -// Splash -import './contrib/splash/browser/splash.contribution.js'; - -// Remote Start Entry for the Web -import './contrib/remote/browser/remoteStartEntry.contribution.js'; - -//#endregion - - -//#region --- export workbench factory - -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -// -// Do NOT change these exports in a way that something is removed unless -// intentional. These exports are used by web embedders and thus require -// an adoption when something changes. -// -// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -import { create, commands, env, window, workspace, logger } from './browser/web.factory.js'; -import { Menu } from './browser/web.api.js'; -import { URI } from '../base/common/uri.js'; -import { Event, Emitter } from '../base/common/event.js'; -import { Disposable } from '../base/common/lifecycle.js'; -import { GroupOrientation } from './services/editor/common/editorGroupsService.js'; -import { UserDataSyncResourceProviderService } from '../platform/userDataSync/common/userDataSyncResourceProvider.js'; -import { RemoteAuthorityResolverError, RemoteAuthorityResolverErrorCode } from '../platform/remote/common/remoteAuthorityResolver.js'; - -export { - - // Factory - create, - - // Basic Types - URI, - Event, - Emitter, - Disposable, - GroupOrientation, - LogLevel, - RemoteAuthorityResolverError, - RemoteAuthorityResolverErrorCode, - - // Facade API - env, - window, - workspace, - commands, - logger, - Menu -}; - -//#endregion + define( + 'vs/workbench/workbench.web.main', + ['require', 'exports', 'vs/web-api!'], + function (_require, exports, webApi) { + Object.assign(exports, webApi); + } + ); +})();