GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — RFC: Per Package Loader Hooks · Issue #18233 · nodejs/node Closed Labels esmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure. DescriptionPer-package loader hooksThis proposal seeks strong support for per-package loader hooks. ProblemIndividual application and packages have loading considerations that vary. The ability to globally mutate the Node module system is problematic and causes packages to alter each other's behavior implicitly. CommonJS had various abilities to mutate the CJS loader with Various workarounds to these use cases do exist but do not apply to all code using these patterns. Example Use Cases
ProposalScope of hooksHooks must be confined to a well defined subsection of the URL space ( This proposal will define the boundaries of subsections to be:
Given the // /foo/bar/example.mjs import '../' // does not cross boundary by resolving to `/foo` import '../..' // does cross boundary by resolving outside of `/foo` to `/` // /a/a.mjs import '../foo' // does cross boundary by resolving out of `/a` import '../foo' // does cross boundary by resolving to `/foo` Consumer and Author negotiation
In order to avoid recursive boundary crossing in one step, all paths will be resolved in two phases. This is similar to
// /a/a.mjs import('/foo'); // 1. fires /a 's package scope loader hooks, seeing `/a/a.mjs` as source and `/foo` as specifier // lets assume it resolves to /foo // 2. fires /foos 's package scope loader hooks, seeing `/foo` as source and `./` as specifier Declaration of hooksPer package loader hooks can be declared in a { "name": "foo", "loader": "../path-searching-loader" } This also allows the hooks to exist outside of package boundaries. This file when loaded as a loader will be in a separate Module Map space from userland and only has the globally defined resolution algorithm. Types of hooks
On the nature of static resolutionESM is able to link statically and there should be a path to allow static / ahead of time usage of per package hooks ideally. By only having a single This is problematic however, since I recommend a combination of V8's SnapshotCreator when possible, and a flag to allow rewriting Problem, multiple boundary crossingIf This is seen as a suitable limitation since CompositionHooks should have a means by which to achieve composition. This is needed for cases of multiple transformations. A package might seek to call a Loaders therefore need to have a concept of a parent loader hooks to defer to, or to ignore. Changing hook allocation to be done using #! node --loader module.exports = class LogImports { constructor(parent) { this.parent = parent; } async resolve(specifier, referrer) { debugger; const ret = await this.parent.resolve(specifier, referrer); console.log(url, 'became', ret); return ret; } } Example use cases for composition
IsolationHooks that are composed still are isolated by per-package boundaries. Nested packages will not fire the Passing arbitrary data between instances can be problematic for both isolation and threading. Therefore the only data passed between instances of loaders will be transferables (including structured clone algorithm) or primitives. The Per-package compositionCan be achieved by manually constructing the chain inside their per-package hook code. Global compositionCan be achieved by providing multiple npm start # => node hasErrors.mjs # aborts export NODE_OPTIONS='--loader DebugImports' npm start # will log imports if HasErrors defers to the parent loader Ignoring parentsIn certain scenarios a package may need to ignore the parent loader. In those situations the hooks will be unable to defer to the default global behavior of the process, which may provide debugging behavior such as logging/code coverage/linting/etc. For now escape hatches are punted on this design space to userland, but it is recommended that when using Code signing invariant implicationsMutating the code loaded in a code signed bundle is problematic. Integrity checks of unexpectedly mutated imports should fail. This area needs more research. Use of any sort of in-source translation should be avoided. Future researchGiven the problems of ignoring scripts and code signing being unable to easily defer to parent loaders more design needs to be done around development workflows. Inspector tooling is the recommended approach. This may mean adding special hooks to inject loader hooks during development via a flag such as This design also does not instrument CJS as loaders currently are not able to instrument CJS. It is not a design goal of this specification to add CJS support to ESM loaders; however, any design for CJS loaders that is presented should and will be considered for compatibility reasons. Reacted by snek, rektide, Marvin Hagemeister, Matteo Collina, Charles Samborski and Salvatore Previti Activity
MetadataMetadataAssigneesLabelsesmIssues and PRs related to the ECMAScript Modules implementation.feature requestIssues requesting new Node.js features.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure. TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |