Skip to content

Commit

Permalink
esm - more diff reduction (#225666)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero authored Aug 15, 2024
1 parent 27f650e commit bea40cd
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 130 deletions.
29 changes: 23 additions & 6 deletions build/gulpfile.reh.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const BUILD_TARGETS = [
{ platform: 'linux', arch: 'alpine' },
];

const serverResources = [
const serverResourceIncludes = [

// NLS
'out-build/nls.messages.json',
Expand All @@ -73,19 +73,36 @@ const serverResources = [
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-login.zsh',
'out-build/vs/workbench/contrib/terminal/browser/media/fish_xdg_data/fish/vendor_conf.d/shellIntegration.fish',
];

const serverResourceExcludes = [
'!out-build/vs/**/{electron-sandbox,electron-main}/**',
'!out-build/vs/editor/standalone/**',
'!out-build/vs/workbench/**/*-tb.png',
'!**/test/**'
];

const serverWithWebResources = [

// Include all of server...
...serverResources,
const serverResources = [
...serverResourceIncludes,
...serverResourceExcludes
];

// ...and all of web
const serverWithWebResourceIncludes = [
...serverResourceIncludes,
...vscodeWebResourceIncludes
];

const serverWithWebResourceExcludes = [
...serverResourceExcludes,
'!out-build/vs/code/**/*-dev.html',
'!out-build/vs/code/**/*-dev.esm.html',
];

const serverWithWebResources = [
...serverWithWebResourceIncludes,
...serverWithWebResourceExcludes
];

const serverEntryPoints = [
{
name: 'vs/server/node/server.main',
Expand Down
4 changes: 4 additions & 0 deletions scripts/code-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ async function main() {
openSystemBrowser = true;
}

if (fs.existsSync(path.join(APP_ROOT, 'src2')) || fs.existsSync(path.join(APP_ROOT, 'out-build', 'esm'))) {
serverArgs.push('--esm');
}

serverArgs.push('--sourcesPath', APP_ROOT);

serverArgs.push(...process.argv.slice(2).filter(v => !v.startsWith('--playground') && v !== '--no-playground'));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/parts/sandbox/common/sandboxTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ISandboxConfiguration {
};

/**
* DEV time only! All css-modules that we have.
* DEV time only: All CSS-modules that we have.
*/
cssModules?: string[];
}
5 changes: 5 additions & 0 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ import { Lazy } from 'vs/base/common/lazy';
import { IAuxiliaryWindowsMainService } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindows';
import { AuxiliaryWindowsMainService } from 'vs/platform/auxiliaryWindow/electron-main/auxiliaryWindowsMainService';
import { normalizeNFC } from 'vs/base/common/normalization';
import { ICSSDevelopmentService, CSSDevelopmentService } from 'vs/platform/cssDev/node/cssDevService';

/**
* The main VS Code application. There will only ever be one instance,
* even if the user starts many instances (e.g. from the command line).
Expand Down Expand Up @@ -1101,6 +1103,9 @@ export class CodeApplication extends Disposable {
// Proxy Auth
services.set(IProxyAuthService, new SyncDescriptor(ProxyAuthService));

// Dev Only: CSS service (for ESM)
services.set(ICSSDevelopmentService, new SyncDescriptor(CSSDevelopmentService, undefined, true));

// Init services that require it
await Promises.settled([
backupMainService.initialize(),
Expand Down
73 changes: 73 additions & 0 deletions src/vs/platform/cssDev/node/cssDevService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { spawn } from 'child_process';
import { relative } from 'path';
import { isESM } from 'vs/base/common/amd';
import { FileAccess } from 'vs/base/common/network';
import { StopWatch } from 'vs/base/common/stopwatch';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/platform/log/common/log';

export const ICSSDevelopmentService = createDecorator<ICSSDevelopmentService>('ICSSDevelopmentService');

export interface ICSSDevelopmentService {
_serviceBrand: undefined;
isEnabled: boolean;
getCssModules(): Promise<string[]>;
}

export class CSSDevelopmentService implements ICSSDevelopmentService {

declare _serviceBrand: undefined;

private _cssModules?: Promise<string[]>;

constructor(
@IEnvironmentService private readonly envService: IEnvironmentService,
@ILogService private readonly logService: ILogService
) { }

get isEnabled(): boolean {
return !this.envService.isBuilt && isESM;
}

getCssModules(): Promise<string[]> {
this._cssModules ??= this.computeCssModules();
return this._cssModules;
}

private async computeCssModules(): Promise<string[]> {
if (!this.isEnabled) {
return [];
}

const rg = await import('@vscode/ripgrep');
return await new Promise<string[]>((resolve) => {

const sw = StopWatch.create();

const chunks: string[][] = [];
const decoder = new TextDecoder();
const basePath = FileAccess.asFileUri('').fsPath;
const process = spawn(rg.rgPath, ['-g', '**/*.css', '--files', '--no-ignore', basePath], {});

process.stdout.on('data', data => {
const chunk = decoder.decode(data, { stream: true });
chunks.push(chunk.split('\n').filter(Boolean));
});
process.on('error', err => {
this.logService.error('[CSS_DEV] FAILED to compute CSS data', err);
resolve([]);
});
process.on('close', () => {
const result = chunks.flat().map(path => relative(basePath, path).replace(/\\/g, '/')).filter(Boolean).sort();
resolve(result);
this.logService.info(`[CSS_DEV] DONE, ${result.length} css modules (${Math.round(sw.elapsed())}ms)`);
});
});
}
}
73 changes: 0 additions & 73 deletions src/vs/platform/environment/test/common/amdX.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/vs/platform/environment/test/common/esmModule.test.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import assert from 'assert';
import { isWindows } from 'vs/base/common/platform';
import { isMacintosh, isWindows } from 'vs/base/common/platform';
import { flakySuite } from 'vs/base/test/common/testUtils';

function testErrorMessage(module: string): string {
Expand All @@ -13,7 +13,7 @@ function testErrorMessage(module: string): string {

flakySuite('Native Modules (all platforms)', () => {

test.skip('kerberos', async () => { // TODO fails on macOS ARM?
(isMacintosh ? test.skip : test)('kerberos', async () => { // Somehow fails on macOS ARM?
const { default: kerberos } = await import('kerberos');
assert.ok(typeof kerberos.initializeClient === 'function', testErrorMessage('kerberos'));
});
Expand Down Expand Up @@ -150,21 +150,6 @@ flakySuite('Native Modules (all platforms)', () => {
});
assert.ok(windowsCerts.length > 0, testErrorMessage('@vscode/proxy-agent'));
});

// These tests require certain modules from `vscode-distro` to work and are otherwise skipped.
// test('vsda', async function () {
// const vsda = await import('vsda');
// const signer = new vsda.signer();
// const signed = await signer.sign('value');
// assert.ok(typeof signed === 'string', testErrorMessage('vsda'));
// assert.ok(typeof (vsda as any).validator === 'function', testErrorMessage('vsda'));

// });

// test('@vscode/vsce-sign', async function () {
// const vsceSign = await import('@vscode/vsce-sign');
// assert.ok(typeof vsceSign.verify === 'function', testErrorMessage('@vscode/vsce-sign'));
// });
});

(!isWindows ? suite.skip : suite)('Native Modules (Windows)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class ExtensionSignatureVerificationService implements IExtensionSignatur

private async resolveVsceSign(): Promise<typeof vsceSign> {
// ESM-uncomment-begin
// if (importAMDNodeModule) { /* fixes unused import, remove me */}
// if (typeof importAMDNodeModule === 'function') { /* fixes unused import, remove me */}
// const mod = '@vscode/vsce-sign';
// return import(mod);
// ESM-uncomment-end
Expand Down
5 changes: 4 additions & 1 deletion src/vs/platform/issue/electron-main/issueMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { zoomLevelToZoomFactor } from 'vs/platform/window/common/window';
import { ICodeWindow, IWindowState } from 'vs/platform/window/electron-main/window';
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
import { isESM } from 'vs/base/common/amd';
import { ICSSDevelopmentService } from 'vs/platform/cssDev/node/cssDevService';

interface IBrowserWindowOptions {
backgroundColor: string | undefined;
Expand Down Expand Up @@ -50,6 +51,7 @@ export class IssueMainService implements IIssueMainService {
@INativeHostMainService private readonly nativeHostMainService: INativeHostMainService,
@IProtocolMainService private readonly protocolMainService: IProtocolMainService,
@IWindowsMainService private readonly windowsMainService: IWindowsMainService,
@ICSSDevelopmentService private readonly cssDevelopmentService: ICSSDevelopmentService,
) { }

//#region Used by renderer
Expand Down Expand Up @@ -86,7 +88,8 @@ export class IssueMainService implements IIssueMainService {
nls: {
messages: globalThis._VSCODE_NLS_MESSAGES,
language: globalThis._VSCODE_NLS_LANGUAGE
}
},
cssModules: this.cssDevelopmentService.isEnabled ? await this.cssDevelopmentService.getCssModules() : undefined
});

this.issueReporterWindow.loadURL(
Expand Down
5 changes: 4 additions & 1 deletion src/vs/platform/issue/electron-main/processMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { IDiagnosticsService, isRemoteDiagnosticError, PerformanceInfo, SystemIn
import { IDiagnosticsMainService } from 'vs/platform/diagnostics/electron-main/diagnosticsMainService';
import { IDialogMainService } from 'vs/platform/dialogs/electron-main/dialogMainService';
import { IEnvironmentMainService } from 'vs/platform/environment/electron-main/environmentMainService';
import { ICSSDevelopmentService } from 'vs/platform/cssDev/node/cssDevService';
import { IProcessMainService, ProcessExplorerData, ProcessExplorerWindowConfiguration } from 'vs/platform/issue/common/issue';
import { ILogService } from 'vs/platform/log/common/log';
import { INativeHostMainService } from 'vs/platform/native/electron-main/nativeHostMainService';
Expand Down Expand Up @@ -58,6 +59,7 @@ export class ProcessMainService implements IProcessMainService {
@IProtocolMainService private readonly protocolMainService: IProtocolMainService,
@IProductService private readonly productService: IProductService,
@IStateService private readonly stateService: IStateService,
@ICSSDevelopmentService private readonly cssDevelopmentService: ICSSDevelopmentService
) {
this.registerListeners();
}
Expand Down Expand Up @@ -158,7 +160,8 @@ export class ProcessMainService implements IProcessMainService {
nls: {
messages: globalThis._VSCODE_NLS_MESSAGES,
language: globalThis._VSCODE_NLS_LANGUAGE
}
},
cssModules: this.cssDevelopmentService.isEnabled ? await this.cssDevelopmentService.getCssModules() : undefined
});

this.processExplorerWindow.loadURL(
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/sign/node/signService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class SignService extends AbstractSignService implements ISignService {

private async vsda(): Promise<typeof vsda> {
// ESM-uncomment-begin
// if (importAMDNodeModule) { /* fixes unused import, remove me */}
// if (typeof importAMDNodeModule === 'function') { /* fixes unused import, remove me */}
// const mod = 'vsda';
// const { default: vsda } = await import(mod);
// return vsda;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/telemetry/common/1dsAppender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async function getClient(instrumentationKey: string, addInternalFlag?: boolean,
const postPlugin = await importAMDNodeModule<typeof import('@microsoft/1ds-post-js')>('@microsoft/1ds-post-js', 'dist/ms.post.js');
// ESM-comment-end
// ESM-uncomment-begin
// if (importAMDNodeModule) { /* fixes unused import, remove me */}
// if (typeof importAMDNodeModule === 'function') { /* fixes unused import, remove me */}
// // eslint-disable-next-line local/code-amd-node-module
// const oneDs = await import('@microsoft/1ds-core-js');
// // eslint-disable-next-line local/code-amd-node-module
Expand Down
Loading

0 comments on commit bea40cd

Please sign in to comment.