-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
sea: support code cache for ESM entrypoint in SEA #62158
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
sea: support code cache for ESM entrypoint in SEA
The initial support for ESM entrypoint in SEA didn't support code cache. This patch implements that by following a path similar to how code cache in CJS SEA entrypoint is supported: at build time we generate the code cache from C++ and put it into the sea blob, and at runtime we consume it via a special case in compilation routines - for CJS this was CompileFunctionForCJSLoader, in the case of SourceTextModule, it's in Module::New.
- Loading branch information
commit 57e7b9f802e651fe6f176c11f39e20cd1f3d42e5
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "main": "sea.mjs", | ||
| "output": "sea", | ||
| "mainFormat": "module", | ||
| "useCodeCache": true, | ||
| "disableExperimentalSEAWarning": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import assert from 'node:assert'; | ||
| import { createRequire } from 'node:module'; | ||
| import { pathToFileURL } from 'node:url'; | ||
| import { dirname } from 'node:path'; | ||
|
|
||
| // Test createRequire with process.execPath. | ||
| const assert2 = createRequire(process.execPath)('node:assert'); | ||
| assert.strictEqual(assert2.strict, assert.strict); | ||
|
|
||
| // Test import.meta properties. | ||
| assert.strictEqual(import.meta.url, pathToFileURL(process.execPath).href); | ||
| assert.strictEqual(import.meta.filename, process.execPath); | ||
| assert.strictEqual(import.meta.dirname, dirname(process.execPath)); | ||
| assert.strictEqual(import.meta.main, true); | ||
|
|
||
| // Test import() with a built-in module. | ||
| const { strict } = await import('node:assert'); | ||
| assert.strictEqual(strict, assert.strict); | ||
|
|
||
| console.log('ESM SEA with code cache executed successfully'); |
34 changes: 34 additions & 0 deletions
34
test/sea/test-single-executable-application-esm-code-cache.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| 'use strict'; | ||
|
|
||
| // This tests the creation of a single executable application with an ESM | ||
| // entry point using "mainFormat": "module" and "useCodeCache": true. | ||
|
|
||
| require('../common'); | ||
|
|
||
| const { | ||
| buildSEA, | ||
| skipIfBuildSEAIsNotSupported, | ||
| } = require('../common/sea'); | ||
|
|
||
| skipIfBuildSEAIsNotSupported(); | ||
|
|
||
| const tmpdir = require('../common/tmpdir'); | ||
| const fixtures = require('../common/fixtures'); | ||
| const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
|
|
||
| tmpdir.refresh(); | ||
|
|
||
| const outputFile = buildSEA(fixtures.path('sea', 'esm-code-cache')); | ||
|
|
||
| spawnSyncAndExitWithoutError( | ||
| outputFile, | ||
| { | ||
| env: { | ||
| NODE_DEBUG_NATIVE: 'SEA', | ||
| ...process.env, | ||
| }, | ||
| }, | ||
| { | ||
| stdout: /ESM SEA with code cache executed successfully/, | ||
| stderr: /SEA module code cache accepted/, | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that this should already be fixed - and locally it works. But since it was talking about the CommonJS case I think it's out of scope of this PR, so I only left a TODO.