Skip to content

Commit

Permalink
esm - provide a bridge to AMD world (#227361)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Sep 2, 2024
1 parent a5fbd74 commit 21135c8
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 216 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/~"
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion build/buildfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
];
};

Expand Down
2 changes: 1 addition & 1 deletion build/gulpfile.reh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 19 additions & 4 deletions build/gulpfile.vscode.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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' })
Expand Down
2 changes: 1 addition & 1 deletion build/lib/optimize.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/lib/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`),
Expand Down
10 changes: 10 additions & 0 deletions build/loader.min

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/vs/code/browser/workbench/workbench.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@
<script src="{{WORKBENCH_NLS_FALLBACK_URL}}"></script>
<!-- attempt to load NLS messages in case non-english -->
<script src="{{WORKBENCH_NLS_URL}}"></script>
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.js"></script>
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.internal.js"></script>
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/code/browser/workbench/workbench.js"></script>
</html>
2 changes: 1 addition & 1 deletion src/vs/code/browser/workbench/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
Expand Down
240 changes: 240 additions & 0 deletions src/vs/workbench/workbench.web.main.internal.ts
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 21135c8

Please sign in to comment.