-
-
Notifications
You must be signed in to change notification settings - Fork 36.4k
process: add process.entrypoint
#64800
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
Open
avivkeller
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
avivkeller:process.entrypoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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,5 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('node:assert'); | ||
|
|
||
| assert.strictEqual(process.entrypoint, process.env.NODE_TEST_ENTRYPOINT); |
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,4 @@ | ||
| import assert from 'node:assert'; | ||
| import { entrypoint } from 'node:process'; | ||
|
|
||
| assert.strictEqual(entrypoint, process.env.NODE_TEST_ENTRYPOINT); |
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 @@ | ||
| console.log(process.entrypoint); |
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,4 @@ | ||
| import assert from 'node:assert'; | ||
| import { entrypoint } from 'node:process'; | ||
|
|
||
| assert.strictEqual(entrypoint, process.env.NODE_TEST_ENTRYPOINT); |
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 @@ | ||
| console.log(process.entrypoint); |
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,9 @@ | ||
| 'use strict'; | ||
|
|
||
| const { isMainThread, workerData, Worker } = require('node:worker_threads'); | ||
|
|
||
| if (isMainThread || workerData === 'nested') { | ||
| new Worker(__filename, { workerData: isMainThread ? 'nested' : 'leaf' }); | ||
| } else { | ||
| console.log(process.entrypoint); | ||
| } |
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,118 @@ | ||
| 'use strict'; | ||
|
|
||
| const { spawnPromisified } = require('../common'); | ||
| const fixtures = require('../common/fixtures'); | ||
|
|
||
| const assert = require('node:assert'); | ||
| const { execPath } = require('node:process'); | ||
| const { describe, it } = require('node:test'); | ||
|
|
||
| const cjsFixture = fixtures.path('entrypoint', 'commonjs.cjs'); | ||
| const cjsFixtureURL = fixtures.fileURL('entrypoint', 'commonjs.cjs').href; | ||
|
|
||
| const mjsFixture = fixtures.path('entrypoint', 'module.mjs'); | ||
| const mjsFixtureURL = fixtures.fileURL('entrypoint', 'module.mjs').href; | ||
|
|
||
| const workerFixture = fixtures.path('entrypoint', 'worker.cjs'); | ||
| const workerFixtureURL = fixtures.fileURL('entrypoint', 'worker.cjs').href; | ||
|
|
||
| const cjsPreload = fixtures.path('entrypoint', 'check-commonjs.cjs'); | ||
| const esmPreload = fixtures.fileURL('entrypoint', 'check-module.mjs').href; | ||
| const loader = fixtures.fileURL('entrypoint', 'loader.mjs').href; | ||
|
|
||
| const printEntrypoint = 'console.log(process.entrypoint)'; | ||
|
|
||
| async function getEntrypoint(args, options, expected) { | ||
| const { code, signal, stderr, stdout } = await spawnPromisified( | ||
| execPath, | ||
| args, | ||
| { | ||
| ...options, | ||
| env: { | ||
| ...process.env, | ||
| NODE_TEST_ENTRYPOINT: expected, | ||
| }, | ||
| }, | ||
| ); | ||
| assert.strictEqual(code, 0, stderr); | ||
| assert.strictEqual(signal, null); | ||
|
|
||
| return stdout.trim(); | ||
| } | ||
|
|
||
| const testCases = [ | ||
| { | ||
| name: 'is the file URL of a CommonJS entry point', | ||
| args: [cjsFixture], | ||
| expected: cjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'is the file URL of an ES module entry point', | ||
| args: [mjsFixture], | ||
| expected: mjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'is absolute when passed a relative path', | ||
| args: ['./commonjs.cjs'], | ||
| options: { cwd: fixtures.path('entrypoint') }, | ||
| expected: cjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'stays correct when using --require', | ||
| args: ['--require', cjsPreload, cjsFixture], | ||
| expected: cjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'stays correct when using --import', | ||
| args: ['--import', esmPreload, cjsFixture], | ||
| expected: cjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'stays correct when using --loader', | ||
| args: ['--loader', loader, cjsFixture], | ||
| expected: cjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'stays correct when combining preloads and loaders', | ||
| args: [ | ||
| '--require', cjsPreload, | ||
| '--import', esmPreload, | ||
| '--loader', loader, | ||
| mjsFixture, | ||
| ], | ||
| expected: mjsFixtureURL, | ||
| }, | ||
| { | ||
| name: 'is inherited by worker threads and their preloads and loaders', | ||
| args: [ | ||
| '--require', cjsPreload, | ||
| '--import', esmPreload, | ||
| '--loader', loader, | ||
| workerFixture, | ||
| ], | ||
| expected: workerFixtureURL, | ||
| }, | ||
| { | ||
| name: 'supports non-file --entry-url entry points', | ||
| args: ['--entry-url', `data:text/javascript,${printEntrypoint}`], | ||
| expected: `data:text/javascript,${printEntrypoint}`, | ||
| }, | ||
| { | ||
| name: 'is undefined when evaluating CommonJS without an entry point', | ||
| args: ['--eval', printEntrypoint], | ||
| expected: 'undefined', | ||
| }, | ||
| { | ||
| name: 'is undefined when evaluating an ES module without an entry point', | ||
| args: ['--input-type=module', '--eval', printEntrypoint], | ||
| expected: 'undefined', | ||
| }, | ||
| ]; | ||
|
|
||
| describe('process.entrypoint', { concurrency: true }, () => { | ||
| for (const { name, args, options, expected } of testCases) { | ||
| it(name, async () => { | ||
| assert.strictEqual(await getEntrypoint(args, options, expected), expected); | ||
| }); | ||
| } | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.