Skip to content

Conversation

@aduh95
Copy link
Contributor

@aduh95 aduh95 commented Feb 12, 2022

No description provided.

@aduh95 aduh95 added experimental Issues and PRs related to experimental features. loaders Issues and PRs related to ES module loaders labels Feb 12, 2022
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/modules

@nodejs-github-bot nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Feb 12, 2022
@aduh95
Copy link
Contributor Author

aduh95 commented Feb 12, 2022

/cc @nodejs/loaders

Copy link
Member

@GeoffreyBooth GeoffreyBooth left a comment

Choose a reason for hiding this comment

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

FYI I think this conflicts with #41950; this seems much simpler, and I would recommend that this one land first. cc @benjamingr @JakobJingleheimer

@benjamingr
Copy link
Member

@GeoffreyBooth why would they conflict they change a different function don’t they?

Copy link
Member

@JakobJingleheimer JakobJingleheimer left a comment

Choose a reason for hiding this comment

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

Thanks for the improved test coverage! LGTM aside from a couple small non-blockers.

Comment on lines -266 to +267
let parent = parentURL;
const parentName = path.basename(parent.pathname);
if (
parentName === '[eval]' ||
parentName === '[stdin]'
) parent = 'command-line';
throw new ERR_NETWORK_IMPORT_DISALLOWED(
href,
parent,
parentURL,
Copy link
Member

@JakobJingleheimer JakobJingleheimer Feb 13, 2022

Choose a reason for hiding this comment

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

The reason I added this was because the output without it seemed likely to confuse (the file path is irrelevant and makes it took like it's coming from a file, but it's not). Aside from consistency with CJS, I think this is not an improvement (I don't feel strongly though).

Copy link
Contributor Author

@aduh95 aduh95 Feb 13, 2022

Choose a reason for hiding this comment

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

I added this was because the output without it seemed likely to confuse (the file path is irrelevant and makes it took like it's coming from a file, but it's not)

If the URL is confusing, we should fix the URL itself, not try to hide it in this specific error message imo. I disagree that command-line is less confusing – what if the user didn't start the process via the command-line?

I think this is not an improvement

Note that the condition can never be true: parentName is never equals to [eval] nor [stdin] (it could be [eval1] though, but we're not testing that).

Copy link
Member

Choose a reason for hiding this comment

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

If the URL is confusing, we should fix the URL itself, not try to hide it in this specific error message imo.

Sure! That works for me (and should also better support consistency).

what if the user didn't start the process via the command-line?

Is that possible?

Note that the condition can never be true: parentName is never equals to [eval] nor [stdin] (it could be [eval1] though, but we're not testing that).

If it doesn't now, it did at the time—I specifically tested CLI via -e …, which is how I found this in the first place 🙂 Is there a known related change that would explain why it's not now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is that possible?

Sure, why not? I don't have a deep enough knowledge of the various OSs Node.js supports to list them all, but I know that CLI is just an option among others (from the GUI, as a service, from a parent process, etc.).

If it doesn't now, it did at the time—I specifically tested CLI via -e …, which is how I found this in the first place 🙂 Is there a known related change that would explain why it's not now?

Maybe you forgot to add --input-type=module?

Copy link
Member

Choose a reason for hiding this comment

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

Is that possible?

Sure, why not? I don't have a deep enough knowledge of the various OSs Node.js supports to list them all, but I know that CLI is just an option among others (from the GUI, as a service, from a parent process, etc.).

No, I mean, is there a route that exists that leads to [eval*]/[stdin] that did not originate from CLI?

If it doesn't now, it did at the time—I specifically tested CLI via -e …, which is how I found this in the first place 🙂 Is there a known related change that would explain why it's not now?

Maybe you forgot to add --input-type=module?

I did not 🙂

// [ERR_NETWORK_IMPORT_DISALLOWED]: import of 'http://example.com/' by
// …/[eval1] is not supported: http can only be used to load local
// resources (use https instead).
match(stderr, /[ERR_NETWORK_IMPORT_DISALLOWED]/);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I prefer the err.code & err.message.includes() used in other ESM error tests. I think consistency would be favourable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have access to err.code not err.message, we're reading the stderr of a subprocess. FYI this test was inspired from

const child = spawn(execPath, [
path('es-modules', 'import-json-named-export.mjs'),
]);
let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => {
stderr += data;
});
child.on('close', mustCall((code, _signal) => {
notStrictEqual(code, 0);
// SyntaxError: The requested module '../experimental.json'
// does not provide an export named 'ofLife'
match(stderr, /SyntaxError:/);
match(stderr, /'\.\.\/experimental\.json'/);
match(stderr, /'ofLife'/);
}));

Copy link
Member

@JakobJingleheimer JakobJingleheimer Feb 15, 2022

Choose a reason for hiding this comment

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

gah, yes indeed (and aligns with #41352)

@GeoffreyBooth
Copy link
Member

@GeoffreyBooth why would they conflict they change a different function don’t they?

I thought they did, but if they don't then feel free to ignore me.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Feb 19, 2022
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 19, 2022
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@aduh95 aduh95 added the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 19, 2022
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 19, 2022
@nodejs-github-bot nodejs-github-bot merged commit 3a1a440 into nodejs:master Feb 19, 2022
@nodejs-github-bot
Copy link
Collaborator

Landed in 3a1a440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. esm Issues and PRs related to the ECMAScript Modules implementation. experimental Issues and PRs related to experimental features. loaders Issues and PRs related to ES module loaders needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants