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

module: support loading entrypoint as url #54933

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RedYetiDev
Copy link
Member

Ref: #49975
Fixes?: #46009
Fixes?: #49204

The original PR stalled, so I addressed the comments, and reimplemented it in a way that it works with the latest Node.js codebase.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. labels Sep 13, 2024
@RedYetiDev RedYetiDev added semver-minor PRs that contain new features and should be released in the next minor version. cli Issues and PRs related to the Node.js command line interface. and removed c++ Issues and PRs that require attention from people who are familiar with C++. labels Sep 13, 2024
Copy link

codecov bot commented Sep 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.06%. Comparing base (75e4d0d) to head (8233681).
Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54933      +/-   ##
==========================================
- Coverage   88.06%   88.06%   -0.01%     
==========================================
  Files         651      651              
  Lines      183451   183543      +92     
  Branches    35821    35863      +42     
==========================================
+ Hits       161564   161642      +78     
- Misses      15133    15138       +5     
- Partials     6754     6763       +9     
Files with missing lines Coverage Δ
lib/internal/main/run_main_module.js 100.00% <100.00%> (ø)
lib/internal/modules/run_main.js 97.23% <100.00%> (-0.05%) ⬇️
src/node_options.cc 88.04% <100.00%> (+0.01%) ⬆️
src/node_options.h 98.22% <100.00%> (+0.01%) ⬆️

... and 37 files with indirect coverage changes

Copy link
Contributor

@LiviaMedeiros LiviaMedeiros left a comment

Choose a reason for hiding this comment

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

The code LGTM.

Adding more tests (and maybe examples in the docs) would be appreciated, and i think it should be more clear that --entry-url is a binary flag that doesn't require --entry-url <URL> syntax, i.e. node --any-flags file:///file.mjs --any-flags --entry-url --any-flags also works.

Also, IIRC src subsystem exists mainly for generic changes (just like lib), so just module should be sufficient.

test/es-module/test-esm-loader-entry-url.mjs Outdated Show resolved Hide resolved
test/es-module/test-esm-loader-entry-url.mjs Outdated Show resolved Hide resolved
@RedYetiDev RedYetiDev changed the title module,src: support loading entrypoint as url module: support loading entrypoint as url Sep 14, 2024
if (mainURL === undefined) {
mainURL = pathToFileURL(mainPath).href;
}
const mainURL = getOptionValue('--entry-url') ? new URL(mainPath, getCWDURL()).href : pathToFileURL(mainPath).href;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can avoid repeating the .href here, and we should probably rename mainPath.

Suggested change
const mainURL = getOptionValue('--entry-url') ? new URL(mainPath, getCWDURL()).href : pathToFileURL(mainPath).href;
const mainURL = getOptionValue('--entry-url') ? new URL(mainPathOrURL, getCWDURL()) : pathToFileURL(mainPathOrURL);

}

assert.strictEqual(code, expected.code ?? 0);
assert.strictEqual(signal, expected.signal ?? signal);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert.strictEqual(signal, expected.signal ?? signal);
assert.strictEqual(signal, expected.signal ?? null);

{},
{
...experimentalFeatureWarning,
stdout: /data:text\/javascript,console\.log\(import\.meta\.url\)/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
stdout: /data:text\/javascript,console\.log\(import\.meta\.url\)/,
stdout: /^data:text\/javascript,console\.log\(import\.meta\.url\)\r?\n$/,

{ cwd: fixtures.fileURL('./') },
{
...experimentalFeatureWarning,
stdout: /print-entrypoint\.mjs\?key=value#hash/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
stdout: /print-entrypoint\.mjs\?key=value#hash/,
stdout: /print-entrypoint\.mjs\?key=value#hash\r?\n$/,

{},
{
...experimentalFeatureWarning,
stdout: /A/,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
stdout: /A/,
stdout: /^A\r?\n$/,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Issues and PRs related to the Node.js command line interface. module Issues and PRs related to the module subsystem. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants