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: fix specifier resolution algorithm #30574

Closed
wants to merge 1 commit into from
Closed

module: fix specifier resolution algorithm #30574

wants to merge 1 commit into from

Conversation

pd4d10
Copy link
Contributor

@pd4d10 pd4d10 commented Nov 21, 2019

Fixes: #30520

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@cjihrig
Copy link
Contributor

cjihrig commented Nov 21, 2019

Can you add tests?

@pd4d10
Copy link
Contributor Author

pd4d10 commented Nov 21, 2019

@cjihrig OK, I'll try to add some tests for this case.

@guybedford
Copy link
Contributor

I know I suggested this approach as a simple way to resolve the issue, but I don't think we should support .mjs searching in the CommonJS resolver, even under this flag.

The alternative would be to use the ESM resolver when this flag is set. That can be achieved by having the shouldUseESMLoader function in https:/nodejs/node/blob/master/lib/internal/modules/run_main.js#L23 return true whenever this flag is set.

@guybedford
Copy link
Contributor

And yes, tests very much necessary too.

@pd4d10
Copy link
Contributor Author

pd4d10 commented Nov 22, 2019

Hi @guybedford, I've updated the implementation and tests for this case.

Copy link
Contributor

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

Great work, thank you @pd4d10 for taking a look at this.

@@ -24,6 +24,10 @@ function shouldUseESMLoader(mainPath) {
const userLoader = getOptionValue('--experimental-loader');
if (userLoader)
return true;
const esModuleSpecifierResolution =
getOptionValue('--es-module-specifier-resolution');
Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect. One thing to note is that this flag is experimental. I just posted an issue about this here - #30600.

Since this is now the primary entry for this flag, we should probably move this check up to the top of the function, and also include a warning like:

process.emitWarning(
    'The --es-module-specifier-resolution flag is experimental.',
    'ExperimentalWarning', undefined);

Would help to add this stuff while we're working on this area anyway, but if you'd rather it be done separately that is fine too just thought I'd mention as it's important for users not to overlook that any of these flags might be removed in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation. I've noticed that #30600 is not only about specifier-resolution but also related to other experimental flags, so perhaps the fix about it should be raised in another PR rather than merged to this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I don't understand it wrong, I'll try to work on #30600 and create another PR to fix it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure if you're able to work on that it would be great, just mentioning as otherwise it can be useful to do these things while we're there.

Copy link
Contributor

@MylesBorins MylesBorins left a comment

Choose a reason for hiding this comment

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

LGTM

@nodejs-github-bot
Copy link
Collaborator

@MylesBorins MylesBorins added the esm Issues and PRs related to the ECMAScript Modules implementation. label Nov 27, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

nodejs-github-bot commented Nov 27, 2019

@nodejs-github-bot
Copy link
Collaborator

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Nov 28, 2019
@Trott
Copy link
Member

Trott commented Nov 28, 2019

Landed in f5ef7cd

@Trott Trott closed this Nov 28, 2019
Trott pushed a commit to Trott/io.js that referenced this pull request Nov 28, 2019
Fixes: nodejs#30520

PR-URL: nodejs#30574
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
@pd4d10 pd4d10 deleted the patch-1 branch November 29, 2019 02:43
addaleax pushed a commit that referenced this pull request Nov 30, 2019
Fixes: #30520

PR-URL: #30574
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Dec 3, 2019
MylesBorins pushed a commit that referenced this pull request Jan 12, 2020
Fixes: #30520

PR-URL: #30574
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
BethGriggs pushed a commit that referenced this pull request Feb 6, 2020
Fixes: #30520

PR-URL: #30574
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Myles Borins <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Feb 8, 2020
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

--es-module-specifier-resolution=node not working from v13.0.1
6 participants