Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

esm: addinitialize hook, integrate withregister#48842

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

izaakschroeder
Copy link
Contributor

@izaakschroederizaakschroeder commentedJul 19, 2023
edited
Loading

Follows@giltayar's proposed API:

register can pass any data it wants to the loader, which will be passed to the exportedinitialize function of the loader. Additionally, if the user ofregister wants to communicate with the loader, it can just create aMessageChannel and pass the port to the loader as data.

Theregister API is now:

interfaceOptions{parentUrl?:string;data?:any;transferList?:any[];}functionregister(loader:string,parentUrl?:string):any;functionregister(loader:string,options?:Options):any;

This API is backwards compatible with the old one (new arguments are optional and at the end) and allows for passing data into the newinitialize hook. If this hook returns data it is passed back toregister:

functioninitialize(data:any):Promise<any>;

NOTE: Currently there is no mechanism for a loader to exchange ownership of something back to the caller.

Refs:nodejs/loaders#147


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

shrujalshah28 reacted with thumbs up emojiJakobJingleheimer and GeoffreyBooth reacted with hooray emoji
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

@nodejs-github-botnodejs-github-bot added esmIssues and PRs related to the ECMAScript Modules implementation. needs-ciPRs that need a full CI run. labelsJul 19, 2023
@izaakschroederizaakschroeder marked this pull request as ready for reviewJuly 19, 2023 22:03
@izaakschroeder
Copy link
ContributorAuthor

/cc @@targos@giltayar

@GeoffreyBooth
Copy link
Member

This API is backwards compatible with the old one (new arguments are optional and at the end)

register hasn’t been released yet, so we don’t need to preserve any backward compatibility. That said, the proposed API seems fine. (Do we needparentURL? It seems like it’s already optional and set toprocess.cwd if undefined, so maybe we can do without it and users can pass as the first argument a path to the loader relative to CWD or an absolute URL to the loader.)

The docs need updating as part of this PR. That would help in reviews, as we can see the intended usage from the example in the new docs. Sinceregister should work in CommonJS too, it would be good to have both CommonJS and ESM versions of the examples.

@GeoffreyBoothGeoffreyBooth added the loadersIssues and PRs related to ES module loaders labelJul 20, 2023
@izaakschroeder
Copy link
ContributorAuthor

Thanks for all the feedback! Work is a bit busy, but I will get to this later tonight (Friday) 😄

@izaakschroeder
Copy link
ContributorAuthor

The docs need updating as part of this PR. That would help in reviews, as we can see the intended usage from the example in the new docs. Since register should work in CommonJS too, it would be good to have both CommonJS and ESM versions of the examples.

@GeoffreyBooth how/where do I update the docs?

@GeoffreyBooth
Copy link
Member

how/where do I update the docs?

Edit themodule.md file in the repo:https://github.com/nodejs/node/blob/main/doc/api/module.md#moduleregister

You’ll find loaders documented inesm.md:https://github.com/nodejs/node/blob/main/doc/api/esm.md#loaders

izaakschroeder reacted with heart emoji

@izaakschroeder
Copy link
ContributorAuthor

@GeoffreyBooth while I do up the docs, is the CJS test here sufficient or do you want to see something more?

@GeoffreyBooth
Copy link
Member

is the CJS test here sufficient or do you want to see something more?

We should add a test that specifically uses--require, not just--eval, as the former is a different code path that runs at a different point in startup. Basically, I expect some users to run commands likenode --require ts-node/register app.js and that should work as expected. Bonus points for setting up arequire.extensions hook that does something and it's coordinated with theload hook. That simulates the transpilation use case.

@izaakschroeder
Copy link
ContributorAuthor

@GeoffreyBooth I added two more tests but one of them is failing. I added{skip: ...} for now but I will have to do further investigation. Let me know if you have any ideas on the source of this failure 😄

JakobJingleheimer reacted with heart emoji

@GeoffreyBooth
Copy link
Member

Please don't addskip, we don't want to accidentally land a PR with failing tests. It's okay if CI fails while we're still working.

@izaakschroeder
Copy link
ContributorAuthor

Oh, sorry, removing skip 😅

Copy link
Member

@JakobJingleheimerJakobJingleheimer left a comment

Choose a reason for hiding this comment

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

This is looking good!

If you'd like help with anything, I have some time this weekend (and then I'm away starting Wednesday for ~2 weeks)

@JakobJingleheimer
Copy link
Member

Do we needparentURL?

@GeoffreyBooth yes: this addresses a specific need; I can't remember what it is, but I'm sure it was discussed. I can try to find it if you'd like.

aduh95 reacted with thumbs up emoji

@GeoffreyBooth
Copy link
Member

@GeoffreyBooth yes: this addresses a specific need; I can’t remember what it is, but I’m sure it was discussed. I can try to find it if you’d like.

Yes, if you can find the reason, I’d appreciate it. I assume it’s because we can’t figure out how to search forspecifier relative to the importing file. Assuming that’s the reason, I still think I’d like to removeparentUrl from the signature. It defaults toprocess.cwd, so I think we could eliminate it and anyone whowould have been passing it (becausespecifier is relative to some base other than CWD) can instead callregister(new URL(specifier, parentURL).href, data, transferList).

And ifspecifier cannot be found, the error message should say something about Node searching for itrelative to the current working directory, rather than relative to the importing file. I think we should probably add this extra error text regardless of whether or notparentUrl stays or goes, as I think this “relative to CWD” behavior is atypical for Node and potentially surprising.

How do others feel about this?

@targos
Copy link
Member

I would prefer the signature to beloader, options?.

@aduh95
Copy link
Contributor

aduh95 commentedJul 22, 2023
edited
Loading

can instead callregister(new URL(specifier, parentURL).href, data, transferList).

You would not get the expected result if you try to register anode_module package.

becausespecifier is relative to some base other than CWD

Note that's almost certainly the case, the only case I can think of where resolving relative to the CWD makes sense is to parse a relative path passed as CLI argument, I expect this will not be the case for the vast majority ofregister calls.

@GeoffreyBooth
Copy link
Member

You would not get the expected result if you try to register anode_module package.

For a package you would just pass the specifier, e.g.register('ts-node'). My example was only for custom loaders, likeregister(new URL('./my-custom-loader.js', import.meta.url).href).

the only case I can think of where resolving relative to the CWD makes sense is to parse a relative path passed as CLI argument

Yes, except that’s howregister currently works as far as I know. I assume we all agree that it would be nice if it worked relative to the current file, like howimport() works, if anyone can figure out how to make that happen.

UlisesGascon added a commit that referenced this pull requestAug 18, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 22, 2023
deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 22, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 22, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 22, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 22, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 22, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 24, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 29, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestAug 31, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
UlisesGascon added a commit that referenced this pull requestSep 1, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
juanarbol pushed a commit that referenced this pull requestSep 4, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)#48660doc:  * add new TSC members (Michael Dawson)#48841  * add rluvaton to collaborators (Raz Luvaton)#49215esm:  * 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)#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)#48765module:  * implement `register` utility (João Lenon)#46826  * make CJS load from ESM loader (Antoine du Hamel)#47999src:  * add built-in `.env` file support (Yagiz Nizipli)#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)#48660 and#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)#48975PR-URL:#49185
@ruyadorno
Copy link
Member

Based on the note from@GeoffreyBooth on#46826 (comment) I'm going ahead and adding a backport-requested label to this PR too. Ideally you can organize it so that it can be a single backport PR containing all the required commits 😊

nodejs-github-bot pushed a commit that referenced this pull requestSep 7, 2023
PR-URL:#49530Refs:#48842Refs:#47999Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>Reviewed-By: Jacob Smith <jacob@frende.me>
ruyadorno pushed a commit that referenced this pull requestSep 28, 2023
PR-URL:#49530Refs:#48842Refs:#47999Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>Reviewed-By: Jacob Smith <jacob@frende.me>
alexfernandez pushed a commit to alexfernandez/node that referenced this pull requestNov 1, 2023
Notable changes:deps:  * V8: cherry-pick 93275031284c (Joyee Cheung)nodejs#48660doc:  * add new TSC members (Michael Dawson)nodejs#48841  * add rluvaton to collaborators (Raz Luvaton)nodejs#49215esm:  * unflag import.meta.resolve (Guy Bedford)nodejs#49028  * add `initialize` hook, integrate with `register` (Izaak Schroeder)nodejs#48842  * unflag `Module.register` and allow nested loader `import()` (Izaak Schroeder)nodejs#48559inspector:  * (SEMVER-MINOR) open add `SymbolDispose` (Chemi Atlow)nodejs#48765module:  * implement `register` utility (João Lenon)nodejs#46826  * make CJS load from ESM loader (Antoine du Hamel)nodejs#47999src:  * add built-in `.env` file support (Yagiz Nizipli)nodejs#48890  * initialize cppgc (Daryl Haresign and Joyee Cheung)nodejs#48660 andnodejs#45704test_runner:  * (SEMVER-MINOR) expose location of tests (Colin Ihrig)nodejs#48975PR-URL:nodejs#49185
alexfernandez pushed a commit to alexfernandez/node that referenced this pull requestNov 1, 2023
PR-URL:nodejs#49530Refs:nodejs#48842Refs:nodejs#47999Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com>Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>Reviewed-By: Jacob Smith <jacob@frende.me>
targos pushed a commit to targos/node that referenced this pull requestNov 11, 2023
Follows@giltayar's proposed API:> `register` can pass any data it wants to the loader, which will bepassed to the exported `initialize` function of the loader.Additionally, if the user of `register` wants to communicate with theloader, it can just create a `MessageChannel` and pass the port to theloader as data.The `register` API is now:```tsinterface Options {  parentUrl?: string;  data?: any;  transferList?: any[];}function register(loader: string, parentUrl?: string): any;function register(loader: string, options?: Options): any;```This API is backwards compatible with the old one (new arguments areoptional and at the end) and allows for passing data into the new`initialize` hook. If this hook returns data it is passed back to`register`:```tsfunction initialize(data: any): Promise<any>;```**NOTE**: Currently there is no mechanism for a loader to exchangeownership of something back to the caller.Refs:nodejs/loaders#147PR-URL:nodejs#48842Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
arcanis pushed a commit to yarnpkg/berry that referenced this pull requestNov 14, 2023
…5961)**What's the problem this PR addresses?**nodejs/node#48842 changed it so that our fspatch is loaded after the internal translators so ESM importing namedCJS exports in loaders doesn't work.Fixes#5951**How did you fix it?**Updated our ESM loader patching to target the `fs` bindings usedinternally.**Checklist**- [x] I have read the [ContributingGuide](https://yarnpkg.com/advanced/contributing).- [x] I have set the packages that need to be released for my changes tobe effective.- [x] I will check that all automated PR checks pass before the PR getsreviewed.
merceyz added a commit to yarnpkg/berry that referenced this pull requestNov 14, 2023
…5961)**What's the problem this PR addresses?**nodejs/node#48842 changed it so that our fspatch is loaded after the internal translators so ESM importing namedCJS exports in loaders doesn't work.Fixes#5951**How did you fix it?**Updated our ESM loader patching to target the `fs` bindings usedinternally.**Checklist**- [x] I have read the [ContributingGuide](https://yarnpkg.com/advanced/contributing).- [x] I have set the packages that need to be released for my changes tobe effective.- [x] I will check that all automated PR checks pass before the PR getsreviewed.(cherry picked from commit6e920f9)
targos pushed a commit that referenced this pull requestNov 23, 2023
Follows@giltayar's proposed API:> `register` can pass any data it wants to the loader, which will bepassed to the exported `initialize` function of the loader.Additionally, if the user of `register` wants to communicate with theloader, it can just create a `MessageChannel` and pass the port to theloader as data.The `register` API is now:```tsinterface Options {  parentUrl?: string;  data?: any;  transferList?: any[];}function register(loader: string, parentUrl?: string): any;function register(loader: string, options?: Options): any;```This API is backwards compatible with the old one (new arguments areoptional and at the end) and allows for passing data into the new`initialize` hook. If this hook returns data it is passed back to`register`:```tsfunction initialize(data: any): Promise<any>;```**NOTE**: Currently there is no mechanism for a loader to exchangeownership of something back to the caller.Refs:nodejs/loaders#147PR-URL:#48842Backport-PR-URL:#50669Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
@targostargos mentioned this pull requestNov 28, 2023
sercher added a commit to sercher/graaljs that referenced this pull requestApr 25, 2024
Follows@giltayar's proposed API:> `register` can pass any data it wants to the loader, which will bepassed to the exported `initialize` function of the loader.Additionally, if the user of `register` wants to communicate with theloader, it can just create a `MessageChannel` and pass the port to theloader as data.The `register` API is now:```tsinterface Options {  parentUrl?: string;  data?: any;  transferList?: any[];}function register(loader: string, parentUrl?: string): any;function register(loader: string, options?: Options): any;```This API is backwards compatible with the old one (new arguments areoptional and at the end) and allows for passing data into the new`initialize` hook. If this hook returns data it is passed back to`register`:```tsfunction initialize(data: any): Promise<any>;```**NOTE**: Currently there is no mechanism for a loader to exchangeownership of something back to the caller.Refs:nodejs/loaders#147PR-URL:nodejs/node#48842Backport-PR-URL:nodejs/node#50669Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
sercher added a commit to sercher/graaljs that referenced this pull requestApr 25, 2024
Follows@giltayar's proposed API:> `register` can pass any data it wants to the loader, which will bepassed to the exported `initialize` function of the loader.Additionally, if the user of `register` wants to communicate with theloader, it can just create a `MessageChannel` and pass the port to theloader as data.The `register` API is now:```tsinterface Options {  parentUrl?: string;  data?: any;  transferList?: any[];}function register(loader: string, parentUrl?: string): any;function register(loader: string, options?: Options): any;```This API is backwards compatible with the old one (new arguments areoptional and at the end) and allows for passing data into the new`initialize` hook. If this hook returns data it is passed back to`register`:```tsfunction initialize(data: any): Promise<any>;```**NOTE**: Currently there is no mechanism for a loader to exchangeownership of something back to the caller.Refs:nodejs/loaders#147PR-URL:nodejs/node#48842Backport-PR-URL:nodejs/node#50669Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@targostargostargos left review comments

@mcollinamcollinamcollina approved these changes

@GeoffreyBoothGeoffreyBoothGeoffreyBooth approved these changes

@aduh95aduh95aduh95 approved these changes

@ljharbljharbAwaiting requested review from ljharb

@JakobJingleheimerJakobJingleheimerAwaiting requested review from JakobJingleheimer

@anonriganonrigAwaiting requested review from anonrig

Assignees
No one assigned
Labels
author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loaders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

11 participants
@izaakschroeder@nodejs-github-bot@GeoffreyBooth@JakobJingleheimer@targos@aduh95@giltayar@ruyadorno@ljharb@mcollina@anonrig

[8]ページ先頭

©2009-2025 Movatter.jp