From 36b52aa938cad53d2883f3fd5280794ea910d266 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 30 Sep 2024 22:13:42 +0200 Subject: [PATCH] esm - inline `minimist` (#230155) * esm - inline `minimist` * . * . * . --- build/lib/optimize.js | 12 +++++++++++- build/lib/optimize.ts | 13 ++++++++++++- .../test/node/nativeModules.integrationTest.ts | 5 ----- src/vs/platform/files/node/watcher/baseWatcher.ts | 3 ++- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/build/lib/optimize.js b/build/lib/optimize.js index f04709fa49d..2bc923ba636 100644 --- a/build/lib/optimize.js +++ b/build/lib/optimize.js @@ -64,6 +64,16 @@ function optimizeESMTask(opts) { }); } }; + const overrideExternalPlugin = { + name: 'override-external', + setup(build) { + // We inline selected modules that are we depend on on startup without + // a conditional `await import(...)` by hooking into the resolution. + build.onResolve({ filter: /^minimist$/ }, () => { + return { path: path.join(REPO_ROOT_PATH, 'node_modules', 'minimist', 'index.js'), external: false }; + }); + }, + }; const task = esbuild.build({ bundle: true, external: entryPoint.exclude, @@ -71,7 +81,7 @@ function optimizeESMTask(opts) { platform: 'neutral', // makes esm format: 'esm', sourcemap: 'external', - plugins: [boilerplateTrimmer], + plugins: [boilerplateTrimmer, overrideExternalPlugin], target: ['es2022'], loader: { '.ttf': 'file', diff --git a/build/lib/optimize.ts b/build/lib/optimize.ts index 60318c277ba..fc7a547ad71 100644 --- a/build/lib/optimize.ts +++ b/build/lib/optimize.ts @@ -96,6 +96,17 @@ function optimizeESMTask(opts: IOptimizeESMTaskOpts): NodeJS.ReadWriteStream { } }; + const overrideExternalPlugin: esbuild.Plugin = { + name: 'override-external', + setup(build) { + // We inline selected modules that are we depend on on startup without + // a conditional `await import(...)` by hooking into the resolution. + build.onResolve({ filter: /^minimist$/ }, () => { + return { path: path.join(REPO_ROOT_PATH, 'node_modules', 'minimist', 'index.js'), external: false }; + }); + }, + }; + const task = esbuild.build({ bundle: true, external: entryPoint.exclude, @@ -103,7 +114,7 @@ function optimizeESMTask(opts: IOptimizeESMTaskOpts): NodeJS.ReadWriteStream { platform: 'neutral', // makes esm format: 'esm', sourcemap: 'external', - plugins: [boilerplateTrimmer], + plugins: [boilerplateTrimmer, overrideExternalPlugin], target: ['es2022'], loader: { '.ttf': 'file', diff --git a/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts b/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts index 3b08a22c1d0..e0b99f38093 100644 --- a/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts +++ b/src/vs/platform/environment/test/node/nativeModules.integrationTest.ts @@ -18,11 +18,6 @@ flakySuite('Native Modules (all platforms)', () => { assert.ok(typeof kerberos.initializeClient === 'function', testErrorMessage('kerberos')); }); - test('minimist', async () => { - const { default: minimist } = await import('minimist'); - assert.ok(typeof minimist === 'function', testErrorMessage('minimist')); - }); - test('yauzl', async () => { const { default: yauzl } = await import('yauzl'); assert.ok(typeof yauzl.ZipFile === 'function', testErrorMessage('yauzl')); diff --git a/src/vs/platform/files/node/watcher/baseWatcher.ts b/src/vs/platform/files/node/watcher/baseWatcher.ts index 749f9fc8503..b1e83957900 100644 --- a/src/vs/platform/files/node/watcher/baseWatcher.ts +++ b/src/vs/platform/files/node/watcher/baseWatcher.ts @@ -11,6 +11,7 @@ import { FileChangeType, IFileChange } from '../../common/files.js'; import { URI } from '../../../../base/common/uri.js'; import { DeferredPromise, ThrottledDelayer } from '../../../../base/common/async.js'; import { hash } from '../../../../base/common/hash.js'; +import { onUnexpectedError } from '../../../../base/common/errors.js'; interface ISuspendedWatchRequest { readonly id: number; @@ -107,7 +108,7 @@ export abstract class BaseWatcher extends Disposable implements IWatcher { } } - return this.updateWatchersDelayer.trigger(() => this.doWatch(nonSuspendedRequests), delayed ? this.getUpdateWatchersDelay() : 0); + return this.updateWatchersDelayer.trigger(() => this.doWatch(nonSuspendedRequests), delayed ? this.getUpdateWatchersDelay() : 0).catch(error => onUnexpectedError(error)); } protected getUpdateWatchersDelay(): number {