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

feat(build): prevent submodules bundling their local dependencies #354

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

alienzhou
Copy link
Contributor

When importing a submodule, esm.sh tries to bundle all its local dependencies. If a local module has its 'inner state', it may occur some errors.


For example, here's a pkgA

 pkgA
   |-- lib
   |    |-- acc.js
   |    +-- print.js
   +-- index.js

The source code in lib/acc.js is something like

// lib/acc.js
let idx = 0;
export const acc = () => ++idx;

The source code in lib/print.js is something like

// lib/print.js
import { acc } from './acc.js';
export const print = () => console.log(acc())

So after building the lib/print.js submodule, the lib/acc.js's source code will be included.

When a third party package (pkgB) importing pkgA,

// pkgB
import { acc } 'pkgA/lib/acc.js';
import { print } 'pkgA/lib/print.js'

It actually uses two pkgA/lib/acc.js modules -- an original submodule and a copy in pkgA/lib/print.js. The idx variable is not shared.


the relative issue #353

@alienzhou alienzhou force-pushed the feat/prevent-bundle-submodule branch from 1de3dae to fb76f2a Compare June 28, 2022 07:45
Copy link
Member

@ije ije left a comment

Choose a reason for hiding this comment

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

LGTM! thanks

@ije ije merged commit 7afd9db into esm-dev:master Jun 29, 2022
austinhallock pushed a commit to trufflehq/esm.sh that referenced this pull request Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants