| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Review requested:
|
Sorry, something went wrong.
|
This would need to be rebased now that the other PR has landed. Let me know if you need help with the process. |
Sorry, something went wrong.
|
How would this work with worker_thread? Can I set a loader specific to a given thread? |
Sorry, something went wrong.
I think the way this works is it would add loaders to the main loaders thread that applies to the main application thread and all worker threads. (And it would create that main loaders thread if it doesn’t already exist at startup time.) Any modules loaded prior to this registration would be unaffected, of course, so people would need to be careful if they want this to apply to their main app, like: import { registerLoader } from 'module'
await registerLoader('some-loader')
await import('app-entry.js')So long as there’s just one loaders thread that applies to both the main thread and worker threads, it’s all or nothing: registerLoader adds loaders to apply everywhere. |
Sorry, something went wrong.
|
That's perfect for me. |
Sorry, something went wrong.
|
Not something that needs to be done in this PR, but I think we should consider adding a few supporting APIs:
|
Sorry, something went wrong.
Arguably this should happen at this PR, so there isn’t a gap between being able to register loaders programmatically and preventing people from doing so. Or two PRs but this one is blocked from being released until the permission is added. The risk is relatively low though, because registerLoader only applies to modules imported after the registration call; which would be only dynamic import() and any resulting new downstream imports (static or dynamic).
I assume you mean loader/loaders here, not hooks? This API registers an entire loader, so presumably the complementary API would be deregisterLoader. Registering or deregistering individual hooks is an interesting idea, but I’m not sure what the use cases would be. A loader can always be broken apart into its component hooks, like you could create a new loader that consists of export { load } from './other-loader.js' to have a loader that’s just some other loader’s load hook, so I’m not sure we need our own API to provide an easier way. |
Sorry, something went wrong.
I did mean loaders instead of hooks here. I apologize for that. |
Sorry, something went wrong.
|
Okee, sorry for the dump, but I think this is too big to hide in a file comment: I think the tech design here needs to change quite a bit to actually work: esm/worker autonomously handles loader registration for loaders specified via CLI. it currently does not expose this; it would need to do. So what I think needs to happen is:
Perhaps module.registerLoader() should be "synchronous" like import.meta.resolve() because forgetting to await is quite a foot-gun that may be very difficult for a user to troubleshoot, and I believe there is no scenario where it would be desirable for the programme to continue before the registration has finished. If so, this is already possible, and CustomizedModuleLoader::register() would just need to call HooksProxy::makeSyncRequest() (instead of HooksProxy::makeAsyncRequest()); see CustomizedModuleLoader::resolve() and CustomizedModuleLoader::load() respectively). Footnotes:
|
Sorry, something went wrong.
|
Regarding making the API sync, I’ve been thinking about that and I’m having conflicting thoughts about it: while I 💯 agree that a sync API would produce fewer surprises, but on the same time we probably want the API to work from --require scripts, and there a sync API might cause problems because the ESM loader is not loaded yet. |
Sorry, something went wrong.
I always assumed it would be an async API; it’s essentially import()-ing a package from disk. I don’t think it would be too much of a footgun; if you do registerLoader('typescript'); import('./app.ts') the latter would immediately error. I feel like that would be the case for most loaders that users would register. And making it async from the start preserves the most flexibility.
If the user needs to pass --loader regardless of whether or not they’re going to use registerLoader, then there’s not much point to creating registerLoader. Maybe what we need is a way for DefaultModuleLoader to “convert” into CustomizedModuleLoader on demand when it’s told to register a loader. |
Sorry, something went wrong.
It loads it in a different thread, comparing it with import is not quite right IMO. Also it doesn't have to be from disk, it can be from the network or another loader.
If it's async, it would race, so sometimes error, sometimes succeeds. But that sounds like a terrible API 😅
Do you have a use case in mind that would require the loader registration to be async? 🤔
Maybe we should support it only in scripts loaded from --require on the main thread, before the ESM loader is initiated? We have to reduce its scope for the initial implementation somehow, it's not reasonable to try to address all at once IMO. |
Sorry, something went wrong.
Sure, but loading modules (whether from disk or network etc) is typically an async operation.
Okay, fair enough, but this is no different than any developer forgetting to await an async API. If the code somehow doesn’t error for them, hopefully their linter or typechecker warns them that they forgot an await. I don't think we should constrain our API because developers might forget to await a promise.
Because many loaders will presumably be written as ESM, and loading them means import()-ing them, which is async. I don’t necessarily want this API to be async; if it can be sync, great, do it that way. I just assumed that somewhere under the hood it would use the import() machinery and therefore would need to be async.
Needing this to happen from CommonJS and/or from --require really reduces a lot of the usefulness, to the point where we’ve defeated the purpose. The goal of creating this API is to not require flags, whether --require or --import or --loader. I think we just need to undo the separation of DefaultModuleLoader and CustomizedModuleLoader, where we merge them back together into one ModuleLoader that by default initializes like DefaultModuleLoader does today, and loaders get registered via a method rather than the constructor. And then only when a loader is registered does it create the loaders thread and so on. It would be a lot like the old ESMLoader used to be before the refactor (but let’s keep the name ModuleLoader so that eventually it can supplant the CommonJS loader). This is probably too much to expect a newcomer to the codebase to tackle, so we’ll need to do a lot of this work. |
Sorry, something went wrong.
But the "import" happens in a different thread, so there’s no reason we couldn’t make it sync, like we do for import.meta.resolve. |
Sorry, something went wrong.
PR-URL: nodejs#46826 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#46826 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: nodejs#46826 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: #46826 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Notable changes: doc: * add new TSC members (Michael Dawson) #48841 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 PR-URL: #49185
Notable changes: doc: * add new TSC members (Michael Dawson) #48841 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 PR-URL: #49185
Notable changes: doc: * add new TSC members (Michael Dawson) #48841 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 PR-URL: #49185
Notable changes: doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 PR-URL: #49185
Notable changes: deps: * V8: cherry-pick 93275031284c (Joyee Cheung) #48660 doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 PR-URL: #49185
Notable changes: deps: * V8: cherry-pick 93275031284c (Joyee Cheung) #48660 doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 * initialize cppgc (Daryl Haresign and Joyee Cheung) #48660 and #45704 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 PR-URL: #49185
Notable changes: deps: * V8: cherry-pick 93275031284c (Joyee Cheung) #48660 doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 * initialize cppgc (Daryl Haresign and Joyee Cheung) #48660 and #45704 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 PR-URL: #49185
Notable changes: deps: * V8: cherry-pick 93275031284c (Joyee Cheung) #48660 doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 * initialize cppgc (Daryl Haresign and Joyee Cheung) #48660 and #45704 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 PR-URL: #49185
Notable changes: deps: * V8: cherry-pick 93275031284c (Joyee Cheung) #48660 doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 * initialize cppgc (Daryl Haresign and Joyee Cheung) #48660 and #45704 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 PR-URL: #49185
Notable changes: deps: * V8: cherry-pick 93275031284c (Joyee Cheung) #48660 doc: * add new TSC members (Michael Dawson) #48841 * add rluvaton to collaborators (Raz Luvaton) #49215 esm: * unflag import.meta.resolve (Guy Bedford) #49028 * add `initialize` hook, integrate with `register` (Izaak Schroeder) #48842 * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder) #48559 inspector: * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow) #48765 module: * implement `register` utility (João Lenon) #46826 * make CJS load from ESM loader (Antoine du Hamel) #47999 src: * add built-in `.env` file support (Yagiz Nizipli) #48890 * initialize cppgc (Daryl Haresign and Joyee Cheung) #48660 and #45704 test_runner: * (SEMVER-MINOR) expose location of tests (Colin Ihrig) #48975 PR-URL: #49185
|
This does not land cleanly in v18.x-staging and will need manual backport in case you want it to land in v18. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
To-dos: