Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm - more cleanup of rules and files #230083

Merged
merged 11 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1133,8 +1133,18 @@
"restrictions": []
},
{
"target": "src/{bootstrap-cli.ts,bootstrap-esm.ts,bootstrap-fork.ts,bootstrap-node.ts,bootstrap-import.ts,bootstrap-meta.ts,bootstrap-window.ts,cli.ts,main.ts,server-cli.ts,server-main.ts,bootstrap-server.ts}",
"target": "src/bootstrap-window.ts",
"restrictions": []
},
{
"target": "src/{bootstrap-cli.ts,bootstrap-esm.ts,bootstrap-fork.ts,bootstrap-import.ts,bootstrap-meta.ts,bootstrap-node.ts,bootstrap-server.ts,cli.ts,main.ts,server-cli.ts,server-main.ts}",
"restrictions": [
"vs/**/common/*",
"vs/**/node/*",
"vs/nls.js",
"src/*.js",
"*" // node.js
]
}
]
}
Expand Down
21 changes: 9 additions & 12 deletions build/buildfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ function createModuleDescription(name, exclude) {
* @param {string} name
*/
function createEditorWorkerModuleDescription(name) {
const description = createModuleDescription(name, ['vs/base/common/worker/simpleWorker', 'vs/editor/common/services/editorSimpleWorker']);
description.name = `${description.name}.esm`;

return description;
return createModuleDescription(name, ['vs/base/common/worker/simpleWorker', 'vs/editor/common/services/editorSimpleWorker']);
}

exports.workerEditor = createEditorWorkerModuleDescription('vs/editor/common/services/editorSimpleWorker');
exports.workerExtensionHost = createEditorWorkerModuleDescription('vs/workbench/api/worker/extensionHostWorker');
exports.workerNotebook = createEditorWorkerModuleDescription('vs/workbench/contrib/notebook/common/services/notebookSimpleWorker');
exports.workerLanguageDetection = createEditorWorkerModuleDescription('vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker');
exports.workerLocalFileSearch = createEditorWorkerModuleDescription('vs/workbench/services/search/worker/localFileSearch');
exports.workerProfileAnalysis = createEditorWorkerModuleDescription('vs/platform/profiling/electron-sandbox/profileAnalysisWorker');
exports.workerOutputLinks = createEditorWorkerModuleDescription('vs/workbench/contrib/output/common/outputLinkComputer');
exports.workerBackgroundTokenization = createEditorWorkerModuleDescription('vs/workbench/services/textMate/browser/backgroundTokenization/worker/textMateTokenizationWorker.worker');
exports.workerEditor = createEditorWorkerModuleDescription('vs/editor/common/services/editorSimpleWorkerMain');
exports.workerExtensionHost = createEditorWorkerModuleDescription('vs/workbench/api/worker/extensionHostWorkerMain');
exports.workerNotebook = createEditorWorkerModuleDescription('vs/workbench/contrib/notebook/common/services/notebookSimpleWorkerMain');
exports.workerLanguageDetection = createEditorWorkerModuleDescription('vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorkerMain');
exports.workerLocalFileSearch = createEditorWorkerModuleDescription('vs/workbench/services/search/worker/localFileSearchMain');
exports.workerProfileAnalysis = createEditorWorkerModuleDescription('vs/platform/profiling/electron-sandbox/profileAnalysisWorkerMain');
exports.workerOutputLinks = createEditorWorkerModuleDescription('vs/workbench/contrib/output/common/outputLinkComputerMain');
exports.workerBackgroundTokenization = createEditorWorkerModuleDescription('vs/workbench/services/textMate/browser/backgroundTokenization/worker/textMateTokenizationWorker.workerMain');

exports.workbenchDesktop = [
createModuleDescription('vs/workbench/contrib/debug/node/telemetryApp'),
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import * as path from 'path';
import * as fs from 'fs';
import { fileURLToPath } from 'url';
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap-fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import * as performance from './vs/base/common/performance.js';
import { removeGlobalNodeJsModuleLookupPaths, devInjectNodeModuleLookupPath } from './bootstrap-node.js';
import { load } from './bootstrap-esm.js';
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

// *********************************************************************
// * *
// * We need this to redirect to node_modules from the remote-folder. *
Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import { createRequire } from 'node:module';
import type { IProductConfiguration } from './vs/base/common/product.js';

Expand Down
2 changes: 0 additions & 2 deletions src/bootstrap-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import * as path from 'path';
import * as fs from 'fs';
import { fileURLToPath } from 'url';
Expand Down
39 changes: 18 additions & 21 deletions src/bootstrap-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,27 @@
(function () {

type ISandboxConfiguration = import('vs/base/parts/sandbox/common/sandboxTypes.js').ISandboxConfiguration;
type ILoadResult<M, T extends ISandboxConfiguration> = import('vs/platform/window/electron-sandbox/window.js').ILoadResult<M, T>;
type ILoadOptions<T extends ISandboxConfiguration> = import('vs/platform/window/electron-sandbox/window.js').ILoadOptions<T>;
type IMainWindowSandboxGlobals = import('./vs/base/parts/sandbox/electron-sandbox/globals.js').IMainWindowSandboxGlobals;

const preloadGlobals: IMainWindowSandboxGlobals = (window as any).vscode; // defined by preload.ts
const safeProcess = preloadGlobals.process;

// increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
Error.stackTraceLimit = 100;

async function load<T extends ISandboxConfiguration>(esModule: string, resultCallback: (result: any, configuration: T) => Promise<unknown> | undefined, options: ILoadOptions<T>): Promise<void> {
async function load<M, T extends ISandboxConfiguration>(esModule: string, options: ILoadOptions<T>): Promise<ILoadResult<M, T>> {

// Window Configuration from Preload Script
const configuration = await resolveWindowConfiguration<T>();

// Signal can modify DOM
options?.canModifyDOM?.(configuration);
// Signal before import()
options?.beforeImport?.(configuration);

// Developer settings
const { enableDeveloperKeybindings, removeDeveloperKeybindingsAfterLoad, developerDeveloperKeybindingsDisposable } = setupDeveloperKeybindings(configuration, options);
const { enableDeveloperKeybindings, removeDeveloperKeybindingsAfterLoad, developerDeveloperKeybindingsDisposable, forceDisableShowDevtoolsOnError } = setupDeveloperKeybindings(configuration, options);

// NLS
setupNLS<T>(configuration);

// Signal before import()
options?.beforeImport?.(configuration);

// Compute base URL and set as global
const baseUrl = new URL(`${fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out/`);
globalThis._VSCODE_FILE_ROOT = baseUrl.toString();
Expand All @@ -45,16 +40,15 @@
try {
const result = await import(new URL(`${esModule}.js`, baseUrl).href);

const callbackResult = resultCallback(result, configuration);
if (callbackResult instanceof Promise) {
await callbackResult;

if (developerDeveloperKeybindingsDisposable && removeDeveloperKeybindingsAfterLoad) {
developerDeveloperKeybindingsDisposable();
}
if (developerDeveloperKeybindingsDisposable && removeDeveloperKeybindingsAfterLoad) {
developerDeveloperKeybindingsDisposable();
}

return { result, configuration };
} catch (error) {
onUnexpectedError(error, enableDeveloperKeybindings);
onUnexpectedError(error, enableDeveloperKeybindings && !forceDisableShowDevtoolsOnError);

throw error;
}
}

Expand All @@ -74,11 +68,13 @@
const {
forceEnableDeveloperKeybindings,
disallowReloadKeybinding,
removeDeveloperKeybindingsAfterLoad
removeDeveloperKeybindingsAfterLoad,
forceDisableShowDevtoolsOnError
} = typeof options?.configureDeveloperSettings === 'function' ? options.configureDeveloperSettings(configuration) : {
forceEnableDeveloperKeybindings: false,
disallowReloadKeybinding: false,
removeDeveloperKeybindingsAfterLoad: false
removeDeveloperKeybindingsAfterLoad: false,
forceDisableShowDevtoolsOnError: false
};

const isDev = !!safeProcess.env['VSCODE_DEV'];
Expand All @@ -91,7 +87,8 @@
return {
enableDeveloperKeybindings,
removeDeveloperKeybindingsAfterLoad,
developerDeveloperKeybindingsDisposable
developerDeveloperKeybindingsDisposable,
forceDisableShowDevtoolsOnError
};
}

Expand Down
2 changes: 0 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import './bootstrap-cli.js'; // this MUST come before other imports as it changes global state
import * as path from 'path';
import { fileURLToPath } from 'url';
Expand Down
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import * as path from 'path';
import * as fs from 'original-fs';
import * as os from 'os';
Expand Down
2 changes: 0 additions & 2 deletions src/server-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import './bootstrap-server.js'; // this MUST come before other imports as it changes global state
import * as path from 'path';
import { fileURLToPath } from 'url';
Expand Down
2 changes: 0 additions & 2 deletions src/server-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

/* eslint-disable local/code-import-patterns */

import './bootstrap-server.js'; // this MUST come before other imports as it changes global state
import * as path from 'path';
import * as http from 'http';
Expand Down
27 changes: 3 additions & 24 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,10 @@
]
},
"include": [
"./bootstrap-esm.ts",
"./bootstrap-cli.ts",
"./bootstrap-fork.ts",
"./bootstrap-import.ts",
"./bootstrap-meta.ts",
"./bootstrap-node.ts",
"./bootstrap-server.ts",
"./bootstrap-window.ts",
"./cli.ts",
"./main.ts",
"./server-main.ts",
"./server-cli.ts",
"./vs/base/common/jsonc.ts",
"./vs/base/common/performance.ts",
"./vs/base/node/unc.ts",
"./vs/base/node/nls.ts",
"./vs/platform/environment/node/userDataPath.ts",
"./vs/base/parts/sandbox/electron-sandbox/preload-aux.ts",
"./vs/base/parts/sandbox/electron-sandbox/preload.ts",
"./vs/code/electron-sandbox/processExplorer/processExplorer.ts",
"./vs/code/electron-sandbox/workbench/workbench.ts",
"./vs/workbench/contrib/issue/electron-sandbox/issueReporter.ts",
"./*.ts",
"./typings",
"./vs/**/*.ts",
"vscode-dts/vscode.proposed.*.d.ts",
"vscode-dts/vscode.d.ts"
"./vscode-dts/vscode.proposed.*.d.ts",
"./vscode-dts/vscode.d.ts"
]
}
12 changes: 6 additions & 6 deletions src/vs/base/browser/defaultWorkerFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class WebWorker extends Disposable implements IWorker {
private readonly label: string;
private worker: Promise<Worker> | null;

constructor(esmWorkerLocation: URI | undefined, amdModuleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
constructor(esmWorkerLocation: URI | undefined, moduleId: string, id: number, label: string, onMessageCallback: IWorkerCallback, onErrorCallback: (err: any) => void) {
super();
this.id = id;
this.label = label;
Expand All @@ -129,7 +129,7 @@ class WebWorker extends Disposable implements IWorker {
} else {
this.worker = Promise.resolve(workerOrPromise);
}
this.postMessage(amdModuleId, []);
this.postMessage(moduleId, []);
this.worker.then((w) => {
w.onmessage = function (ev) {
onMessageCallback(ev.data);
Expand Down Expand Up @@ -171,10 +171,10 @@ export class WorkerDescriptor implements IWorkerDescriptor {
public readonly esmModuleLocation: URI | undefined;

constructor(
public readonly amdModuleId: string,
public readonly moduleId: string,
readonly label: string | undefined,
) {
this.esmModuleLocation = FileAccess.asBrowserUri(`${amdModuleId}.esm.js` as AppResourcePath);
this.esmModuleLocation = FileAccess.asBrowserUri(`${moduleId}Main.js` as AppResourcePath);
}
}

Expand All @@ -194,15 +194,15 @@ class DefaultWorkerFactory implements IWorkerFactory {
throw this._webWorkerFailedBeforeError;
}

return new WebWorker(desc.esmModuleLocation, desc.amdModuleId, workerId, desc.label || 'anonymous' + workerId, onMessageCallback, (err) => {
return new WebWorker(desc.esmModuleLocation, desc.moduleId, workerId, desc.label || 'anonymous' + workerId, onMessageCallback, (err) => {
logOnceWebWorkerWarning(err);
this._webWorkerFailedBeforeError = err;
onErrorCallback(err);
});
}
}

export function createWebWorker<T extends object>(amdModuleId: string, label: string | undefined): IWorkerClient<T>;
export function createWebWorker<T extends object>(moduleId: string, label: string | undefined): IWorkerClient<T>;
export function createWebWorker<T extends object>(workerDescriptor: IWorkerDescriptor): IWorkerClient<T>;
export function createWebWorker<T extends object>(arg0: string | IWorkerDescriptor, arg1?: string | undefined): IWorkerClient<T> {
const workerDescriptor = (typeof arg0 === 'string' ? new WorkerDescriptor(arg0, arg1) : arg0);
Expand Down
8 changes: 4 additions & 4 deletions src/vs/base/common/worker/simpleWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IWorkerFactory {
}

export interface IWorkerDescriptor {
readonly amdModuleId: string;
readonly moduleId: string;
readonly esmModuleLocation: URI | undefined;
readonly label: string | undefined;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ export class SimpleWorkerClient<W extends object> extends Disposable implements

this._worker = this._register(workerFactory.create(
{
amdModuleId: 'vs/base/common/worker/simpleWorker',
moduleId: 'vs/base/common/worker/simpleWorker',
esmModuleLocation: workerDescriptor.esmModuleLocation,
label: workerDescriptor.label
},
Expand Down Expand Up @@ -375,12 +375,12 @@ export class SimpleWorkerClient<W extends object> extends Disposable implements
this._onModuleLoaded = this._protocol.sendMessage(DEFAULT_CHANNEL, INITIALIZE, [
this._worker.getId(),
JSON.parse(JSON.stringify(loaderConfiguration)),
workerDescriptor.amdModuleId,
workerDescriptor.moduleId,
]);

this.proxy = this._protocol.createProxyToRemoteChannel(DEFAULT_CHANNEL, async () => { await this._onModuleLoaded; });
this._onModuleLoaded.catch((e) => {
this._onError('Worker failed to load ' + workerDescriptor.amdModuleId, e);
this._onError('Worker failed to load ' + workerDescriptor.moduleId, e);
});
}

Expand Down
11 changes: 7 additions & 4 deletions src/vs/code/electron-sandbox/processExplorer/processExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@

/* eslint-disable no-restricted-globals */

(function () {
(async function () {

type IBootstrapWindow = import('vs/platform/window/electron-sandbox/window.js').IBootstrapWindow;
type IProcessExplorerMain = import('vs/code/electron-sandbox/processExplorer/processExplorerMain.js').IProcessExplorerMain;
type ProcessExplorerWindowConfiguration = import('vs/platform/issue/common/issue.js').ProcessExplorerWindowConfiguration;

const bootstrapWindow: IBootstrapWindow = (window as any).MonacoBootstrapWindow; // defined by bootstrap-window.ts

bootstrapWindow.load('vs/code/electron-sandbox/processExplorer/processExplorerMain', function (processExplorer, configuration) {
return processExplorer.startup(configuration);
}, {
const { result, configuration } = await bootstrapWindow.load<IProcessExplorerMain, ProcessExplorerWindowConfiguration>('vs/code/electron-sandbox/processExplorer/processExplorerMain', {
configureDeveloperSettings: function () {
return {
forceEnableDeveloperKeybindings: true
};
},
});

result.startup(configuration);
}());
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,10 @@ function createCodiconStyleSheet() {
delayer.schedule();
}

export interface IProcessExplorerMain {
startup(configuration: ProcessExplorerWindowConfiguration): void;
}

export function startup(configuration: ProcessExplorerWindowConfiguration): void {
const platformClass = configuration.data.platform === 'win32' ? 'windows' : configuration.data.platform === 'linux' ? 'linux' : 'mac';
mainWindow.document.body.classList.add(platformClass); // used by our fonts
Expand Down
Loading
Loading