-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: add support for nodeEntryPointConfig.loaders
in package.json
#43973
Conversation
Review requested:
|
Thanks for picking this problem up. Agreed having it not apply to I do still think there might be confusion in the Another possibility could be a special comment in the entry point file only. Similarly to what we have in the test files. That would then also solve the issue of standalone executions. That Node.js itself needs it for tests demonstrates it's a relatively useful feature. |
Yes I think we need to change this. I assume the prior behavior was for performance? Doing a single stat (or stat lookup chain) for the entrypoint seems like a very minor hit.
Not opposed, but what made this necessary? This makes me think we should land the “move off thread” PR before we tackle this part.
I feel like we should support all of Node’s configuration (or at least, as much of it as possible) rather than just a field for loaders. Within the configuration file we also need a way to define different configurations per environment, like production vs development configuration (perhaps aligning with |
Note that the
One reason to use
That's smart, that would not work for entry point files that do not follow the same comment convention as JS though (e.g. a WASM file).
To be clear, that's very much not a goal for this PR, I intend to focus on resolving the loaders use-case only. Adding gradually more options should be possible though, and can happen in follow up PRs.
It's already possible to do the following: {
"name": "pkg",
"imports": {
"#loader": {
"development": "typescript-loader/with-type-checks",
"default": "typescript-loader/no-type-checks"
}
},
"nodeEntryPointConfig": {
"loaders": ["#loader"]
}
} I'm tempted to say it's good enough, wdyt?
It's more than a stat, we also have to parse that JSON, so the time it takes depends on the size of the |
No, that only works for I think this API needs to be designed to eventually support all of Node’s config options (or at least, all the ones that make sense to define in a config file; probably all the ones supported by I think this should also be an experimental API, possibly even needing its own flag to enable. There’s no versioning in I also think that we need to look at what flags get parsed by C++ on startup, long before we get to module loading. I think users will consider this feature broken if it doesn’t support most of the options they expect (such as everything in |
I'm -1 on the specific name This seems to be a part of a bigger/longer-term trend of Node.js begnning to use package.json for configuration more. If we're going down that path I'd strongly prefer we do something like |
i wonder what number of people would expect, based on one or more of those names, that this configuration object would support nested configurations like |
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.
Thanks for getting this moving!
Seconding Tierney: I think we should create a top-level field in package.json such as node
and nest this and others within it following the same environment conditional conventions as packageJSON.exports
:
{
"node": {
"development": {
"entryPoint¹": {
"loaders": ["…"]
},
"//eventually": "others like below",
"imports": ["…"],
"policy": "./policy.dev.json",
"//policy": {
"integrity": "…",
"manifest": "./policy.dev.json"
}
}
}
}
This is already supported by many, many packages, and I find it works very well. So if it ain't broke.
Also, yes: we decided to "wait and see" about converting resolve
to sync until after loaders are moved off-thread. So if that's needed, I think this should be blocked from landing til then.
--
¹ not sure whether entrypoint
or entryPoint
is more common/correct
I'm not sure what to do with this, I'm not happy with the solution I came up, and it doesn't look like any other solution make consensus so far. Also, I feel trying to come up with a JSON representation that pleases everyone of any value that could configure Node.js is a doomed project, it doesn't seem realistic to set this goal. I'm thinking a better approach would be to use Anyway closing this for now, if someone else to give it a shot, you'll be very welcome. If you are looking for a solution to do that and don't care about Windows support, create your own executable: #!/bin/sh
exec node --loader '#ts-loader' "${@}" |
I’m leaning toward this as well. For comparison, Bun supports this approach:
In our case, a We can always support |
I mean, if |
Currently, starting a
.mjs
or.cjs
file allow to skip the lookup and the parsing of apackage.json
file, I'm reluctant to change that but I'm curious what others think.I had to make the default
resolve
function sync – but we don't use anything async inside anyway, I assume it's fine. If we move the loaders off-thread (or even to make the loading of loaders itself go through non-default loaders), we might need to think of an async way of resolving those loaders, not sure.Opening as draft because it's just at the PoC stage, and I would like to get some feedback on the initial implementation before going further.
/cc @nodejs/loaders