Skip to content

esm: unflag Module.register and allow nested loader import()#48559

Merged
nodejs-github-bot merged 1 commit intonodejs:mainfrom
izaakschroeder:support-nested-loader-chains
Jul 19, 2023
Merged

esm: unflag Module.register and allow nested loader import()#48559
nodejs-github-bot merged 1 commit intonodejs:mainfrom
izaakschroeder:support-nested-loader-chains

Conversation

@izaakschroeder
Copy link
Copy Markdown
Contributor

@izaakschroeder izaakschroeder commented Jun 26, 2023

Overview

Major functional changes:

  • Allow import() to work within loaders that require other loaders,
  • Unflag the use of Module.register.

A new interface Customizations has been created in order to unify ModuleLoader (previously DefaultModuleLoader), Hooks and CustomizedModuleLoader all of which now implement it:

interface LoadResult {
  format: ModuleFormat;
  source: ModuleSource;
}

interface ResolveResult {
  format: string;
  url: URL['href'];
}

interface Customizations {
  allowImportMetaResolve: boolean;
  load(url: string, context: object): Promise<LoadResult>
  resolve(
    originalSpecifier:
    string, parentURL: string,
    importAssertions: Record<string, string>
  ): Promise<ResolveResult>
  resolveSync(
    originalSpecifier:
    string, parentURL: string,
    importAssertions: Record<string, string>
  ) ResolveResult;
  register(specifier: string, parentUrl: string): any;
  forceLoadHooks(): void;
}

The ModuleLoader class now has setCustomizations which takes an object of this shape and delegates its responsibilities to this object if present.

Note that two properties allowImportMetaResolve and resolveSync exist now as a mechanism for import.meta.resolve – since Hooks does not implement resolveSync other loaders cannot use import.meta.resolve; allowImportMetaResolve is a way of checking for that case instead of invoking resolveSync and erroring.


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.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants