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

Create README.md #13

Merged
merged 2 commits into from Oct 18, 2022
Merged

Create README.md #13

merged 2 commits into from Oct 18, 2022

Conversation

dfabulich
Copy link
Contributor

Copied and pasted from the old documentation for --experimental-specifier-resolution

Copied and pasted from the old documentation for `--experimental-specifier-resolution`
@dfabulich
Copy link
Contributor Author

@GeoffreyBooth

@GeoffreyBooth
Copy link
Member

GeoffreyBooth commented Oct 18, 2022

Does that example actually work? I think the loader covers specifiers within code, like import statements in your file, not the argument passed to the node binary on the command line.

(I know that that was the example in the old docs but I think it was either wrong or misstated the intent of the flag.)

Regardless, the example should show an import statement like import foo from './foo'; // fails without this loader.

@dfabulich
Copy link
Contributor Author

I have no idea!

I started pulling on this thread by reading https://nodejs.org/en/blog/announcements/v19-release-announce/#custom-esm-resolution-adjustments

Then I read nodejs/node#44859 which also told me nothing about what this custom loader does.

I was about to file an issue that said "what does this custom loader actually do? It's not documented at all"

But then I thought, "oh, I know, I'll just read the docs of the old thing that it got rid of," and I just assumed that this thing did the same as the old thing.

If it doesn't do the same thing as the old thing, then I really have no idea what this loader does. I thought I understood --experimental-specifier-resolution=node, but if its documentation was wrong, then I'm totally at sea here, and, I'm sure, so will all other users who try to read the ESM docs and figure this out.

@dfabulich
Copy link
Contributor Author

dfabulich commented Oct 18, 2022

FWIW, I cloned the repository, and did this:

$ cd /tmp/loaders-test/commonjs-extension-resolution-loader
$ npm i
$ echo "await 1; console.log('hi');" > index.mjs
$ node --version
19.0.0
$ node --loader=./loader.js index
(node:5170) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
hi
$ mkdir subdir
$ echo "await 1; console.log('hi');" > subdir/index.mjs
$ node --loader=./loader.js subdir
(node:5200) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
hi

Sooo I claim that the old documentation is at least kinda sorta applicable? And the README I'm proposing isn't entirely wrong.

But, just to be sure, what do you think this loader does???

@GeoffreyBooth
Copy link
Member

See also https://nodejs.org/api/cli.html#ecmascript-modules-loader-entry-point-caveat.

The intent of this loader is to enable import specifiers like this:

import foo from './foo'; // Where './foo' is ./foo.js or ./foo/index.js etc.

Instead of needing to write './foo.js' or './foo/index.js' or whatever the explicit path and filename is.

@dfabulich
Copy link
Contributor Author

👍 Done. I think this is ready to merge.

@GeoffreyBooth GeoffreyBooth merged commit 391b65f into nodejs:main Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants