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

make managerEntries be loaded as ESM, for improved tree-shaking #20070

Merged
merged 5 commits into from
Dec 3, 2022

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Dec 2, 2022

Issue:

I noticed that the whole preview-api is bundled into every manager entry (manager.mjs).
I was able to assert that this is because the core-server resolves the entry fully. (to prevent pnp issues).
But by resolving it, it resolves the cjs entry.

What I did

I changed the code in core-server so it removes the file extension.
Then I configured the manager-builder to try adding .mjs to the path.
This is not a perfect solution.
A better solution would be to somehow use the exportsMap.

I also configured esbuild to optimize the code.

before:
Screenshot 2022-12-02 at 20 20 00

after:
Screenshot 2022-12-02 at 19 38 54

@ndelangen ndelangen self-assigned this Dec 2, 2022
@ndelangen ndelangen added the maintenance User-facing maintenance tasks label Dec 2, 2022
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -113,11 +119,19 @@ export const resolveAddonName = (
const managerEntries = [];

if (managerFile) {
managerEntries.push(managerFile);
// we remove the extension
// this is a bit of a hack to try en be able to find .mjs files
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// this is a bit of a hack to try en be able to find .mjs files
// this is a bit of a hack to try to find .mjs files

}
// register file is the old way of registering addons
if (!managerFile && registerFile && !presetFile) {
managerEntries.push(registerFile);
// we remove the extension
// this is a bit of a hack to try en be able to find .mjs files
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// this is a bit of a hack to try en be able to find .mjs files
// this is a bit of a hack to try to find .mjs files

return {
type: 'virtual',
name,
managerEntries: [resolved],
// we remove the extension
// this is a bit of a hack to try en be able to find .mjs files
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// this is a bit of a hack to try en be able to find .mjs files
// this is a bit of a hack to try to find .mjs files

@ndelangen ndelangen merged commit 986dd2f into next Dec 3, 2022
@ndelangen ndelangen deleted the tech/improve-perf-by-using-mjs branch December 3, 2022 19:53
@ndelangen
Copy link
Member Author

arg, github only showed me your review comments after I merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants