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: Reimplement support for true ESM mode #48

Open
Chooks22 opened this issue Feb 28, 2022 · 1 comment
Open

feat: Reimplement support for true ESM mode #48

Chooks22 opened this issue Feb 28, 2022 · 1 comment
Assignees
Labels
dev server Issues concerning the Development Server enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@Chooks22
Copy link
Contributor

For the sake of the project's simplicity during the v2 rewrite, support for ES Modules have been temporarily dropped.

Major issues in supporting ESM is the lack of access to module cache (as opposed to CJS require.cache), so custom URL hashing, dependency chain tracking, and cache invalidation will all have to be developed (which is possible as seen in v1, but is extremely messy and still have disparities between the two modes).

In future versions, module loading could possibly be handled via messages in a client-server architecture, possibly unifying the handling for both CJS and ES modules and resulting in a clearer API.

Relevant links:

@Chooks22 Chooks22 added enhancement New feature or request help wanted Extra attention is needed dev server Issues concerning the Development Server labels Feb 28, 2022
@Chooks22
Copy link
Contributor Author

Chooks22 commented Jun 8, 2022

Update on this:

vm.Module from node:vm module looks promising. vm.SourceTextModule accepts a string as its first param as the code for the module, which is easily accessible for us since we compile the code using swc.

Issue is, it doesn't seem like the memory is freed once the reference to the module is gone. Even just a simple test of the ff. increases the heap size.

import { SourceTextModule } from 'node:vm'

for (let i = 0; i < 10_000; i++) {
  new SourceTextModule('')
}

console.log(process.memoryUsage().heapUsed)

@Chooks22 Chooks22 self-assigned this Jun 10, 2022
@Chooks22 Chooks22 added this to the v3.0.0 milestone Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev server Issues concerning the Development Server enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant