-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
doc: fix transpiler loader hooks documentation #57037
Conversation
Review requested:
|
It should be fine as long as there is a resolve hook for it. I do this a bunch in https://www.github.com/nodejs-loaders/nodejs-loaders
That is not (or at least should not) be true: Node supplies You only need to provide |
I don't think it does? Adding a resolve hook that merely passes on the result of the nextResolve does not make the ERR_UNKNOWN_FILE_EXTENSION go away, and code-wise from |
I see, then it's probably just the synchrnous hooks that is missing this - though this feels rather surprising to me, considering the return values are mandatory and does not accept merges, yet the context parameter is optional and can be merged... |
The reason for it was because I thought it was silly to require a hook to pass the thing just handed it by node back to node, the vast majority of the time totally unchanged. Or when it is changed, only 10% different (which would necessitate everyone doing the same thing, so I figured build that into node). |
I think the more surprising part is that this is not enforced consistently between return value and parameters - the return values might also be unchanged most of the time or only changed for a specific subset of modules. But yeah that's a bit off topic for this PR. |
I think I figured out why it seems to work in your examples - you likely always have an explicit known format (either in package.json, or extension, or the |
48e5811
to
b0daac3
Compare
Updated the PR to fix the incorrect package type implementation (it was returning false in the absence of explicit type) and warn about the format issue. @JakobJingleheimer can you take a look? |
b0daac3
to
7192b2c
Compare
Yes, exactly: I wouldn't say "evades" (although I certainly see where you're coming from) as much as "gets out of the way": The design rationale here was intending to avoid "but it already knows!?" frustrations.
If I understand what you're saying, I think that is not correct: omitting |
For the sake of running the example, add a `package.json` file containing the | ||
module type of the CoffeeScript files. | ||
|
||
```json | ||
{ | ||
"type": "module" | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ovflowd in the incoming new API docs, will we have access to the awesome multi-file (tabbed) code samples like we do in Learn articles?
What I meant is, because |
Ahhhh, gotcha. Perhaps we should call that out in the doc? |
It is already, from L1484 |
I did not get that from L1484; I point I got from it is related specifically to the sample code (also important). I would explicitly say something like:
|
I don't think the resolve hook matters in this case. The problem comes from the |
Hmm, perhaps not in this case. I think it's a good idea since you pointed out there is some arcana to this that even you did not get (maybe I'm the only person aware of this?). I'm happy to add it subsequently :) |
2118907
to
0e4f364
Compare
Updated the docs to point out context.format is mandatory if there's no explicit module type information. |
The loader hooks examples have been broken for a while: 1. The nextLoad() hook cannot be used on a .coffee file that ends up going to the default load step without an explict format, which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention adding a package.json with a type field to work around it in the example. 2. Pass the context parameter to the nextLoad() invocation and document that context.format is mandatory when module type is not explicitly inferrable from the module. 3. Correct the getPackageType() implementation which returns false instead of undefined in the absence of an explict format, which is not a valid type for format.
0e4f364
to
b5a6385
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ 🙌
Landed in e892e79 |
The loader hooks examples have been broken for a while: 1. The nextLoad() hook cannot be used on a .coffee file that ends up going to the default load step without an explict format, which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention adding a package.json with a type field to work around it in the example. 2. Pass the context parameter to the nextLoad() invocation and document that context.format is mandatory when module type is not explicitly inferrable from the module. 3. Correct the getPackageType() implementation which returns false instead of undefined in the absence of an explict format, which is not a valid type for format. PR-URL: #57037 Refs: #57030 Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
The loader hooks examples have been broken for a while: 1. The nextLoad() hook cannot be used on a .coffee file that ends up going to the default load step without an explict format, which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention adding a package.json with a type field to work around it in the example. 2. Pass the context parameter to the nextLoad() invocation and document that context.format is mandatory when module type is not explicitly inferrable from the module. 3. Correct the getPackageType() implementation which returns false instead of undefined in the absence of an explict format, which is not a valid type for format. PR-URL: nodejs#57037 Refs: nodejs#57030 Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
The loader hooks examples have been broken for a while:
up going to the default load step without an explict format,
which would cause a ERR_UNKNOWN_FILE_EXTENSION. Mention
adding a package.json with a type field to work around it
in the example.
document that context.format is mandatory when module type
is not explicitly inferrable from the module.
false instead of undefined in the absence of an explict format,
which is not a valid type for format.
I still feel that moving the examples to a proper repository that have the examples actually tested in a workflow is the right way to go, which was why I left the TODO in L1348 instead of fixing the examples in any way some time ago. But until we do that, it's not good to have broken examples in the docs, so this just fixes it to be a working version without actually making it perfect in any way.
Also I feel that the current API is a bit awkward to use even for these examples:
These should probably be addressed in other PRs since they'll require changes to the API.
Refs: #57030