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

Remove __$__nodeRequire usages #166686

Merged
merged 11 commits into from
Nov 21, 2022
Merged

Remove __$__nodeRequire usages #166686

merged 11 commits into from
Nov 21, 2022

Conversation

jrieken
Copy link
Member

@jrieken jrieken commented Nov 18, 2022

helps with #160416

@jrieken jrieken self-assigned this Nov 18, 2022
@jrieken jrieken marked this pull request as ready for review November 18, 2022 16:29
@jrieken
Copy link
Member Author

jrieken commented Nov 18, 2022

@vscodenpa vscodenpa added this to the November 2022 milestone Nov 18, 2022
mjbvz
mjbvz previously approved these changes Nov 18, 2022
src/main.js Show resolved Hide resolved
@@ -47,7 +41,7 @@ else if (typeof require?.__$__nodeRequire === 'function') {
// want to have it running out of sources so we
// read it from package.json only when we need it.
if (!product.version) {
const pkg = require.__$__nodeRequire(joinPath(rootPath, 'package.json').fsPath) as { version: string };
const pkg = globalThis._VSCODE_PACKAGE_JSON as { version: string };
Copy link
Member

@bpasero bpasero Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is lazy to avoid a require(package.json) when running because a built time we add version to the product.json. The only exception is running out of sources for why this is called here. Would be nice for startup perf to avoid the package.json lookup.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ESM future there will be no more way to synchronously load anything. So, the only way forward will be something like _VSCODE_PRODUCT where the bootstrapper or embedder does these conditional loads. I suggest that we merge this with the vscode.context merging effort

globalThis._VSCODE_NODE_MODULES = new Proxy(Object.create(null), { get: (_target, mod) => nodeRequire(String(mod)) });

// VSCODE_GLOBALS: package/product.json
globalThis._VSCODE_PRODUCT_JSON = require('../product.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason product/package.json cannot go through the same proxy above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, _VSCODE_NODE_MODULES is debt and must eventually disappear whereas the _VSCODE_PRODUCT_JSON and _VSCODE_PACKAGE_JSON globals are likely staying (being merged with vscode.context...)

Copy link
Member

@bpasero bpasero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned in chat before: when I worked on using esbuild to bundle CommonJS, I noticed that it would inline every require call it finds. We cannot inline product.json though (because some properties are added after the build) and that is why the IOptimizeCommonJSTaskOpts have an array of external to explicitly exclude modules from getting inlined. We just have to make sure that this change preserves it. The bundler for CommonJS is configured from here:

commonJS?: IOptimizeCommonJSTaskOpts;

@jrieken
Copy link
Member Author

jrieken commented Nov 21, 2022

We just have to make sure that this change preserves it.

I am confident. These are either dynamic (cannot be inlined) or are explicitly spelled out as require calls with the same path. There is also https://builds.code.visualstudio.com/builds/insider which I gave a quick test and I didn't see any errors. @bpasero what else needed to test this?

@jrieken jrieken merged commit f08feed into main Nov 21, 2022
@jrieken jrieken deleted the joh/middle-jellyfish branch November 21, 2022 10:50
forivall added a commit to forivall/monkey-patch that referenced this pull request Dec 11, 2022
forivall added a commit to forivall/monkey-patch that referenced this pull request Dec 11, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants