Skip to content

nodejs/loaders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 

Loaders Team

Purpose

The Node.js Loaders Team maintains and actively develops the ECMAScript Modules Loaders implementation in Node.js core.

History

This team is spun off from the Modules team. We aim to implement the use cases that went unfulfilled by the initial ES modules implementation that can be achieved via loaders.

Project

Status

  • Finish nodejs/node#37468 / nodejs/node#35524, simplifying the hooks to resolve, load and globalPreloadCode.

  • Refactor the internal Node ESMLoader hooks into resolve and load. Node’s internal loader already has no-ops for transformSource and getGlobalPreloadCode, so all this really entails is wrapping the internal getFormat and getSource with one function load (getFormat is used internally outside ESMLoader, so they cannot merely be merged). nodejs/node#37468

  • Refactor Node’s internal ESM loader to move its exception on unknown file types from within resolve (on detection of unknown extensions) to within load (if the resolved extension has no defined translator). nodejs/node#37468

  • Implement chaining as described in the design, where the default<hookName> becomes next and references the next registered hook in the chain. nodejs/node#42623

  • Move loaders off thread

  • Add helper/utility functions to the module module

    • Start with the functions that make up the ESM resolution algorithm as defined in the spec. Create helper functions for each of the functions defined in that psuedocode: esmResolve, packageImportsResolve, packageResolve, esmFileFormat, packageSelfResolve, readPackageJson, packageExportsResolve, lookupPackageScope, packageTargetResolve, packageImportsExportsResolve, patternKeyCompare. (Not necessarily all with these exact names, but corresponding to these functions from the spec.)

    • Follow up with similar helper functions that make up what happens within Node’s internal load. (Definitions to come.)

  • Support loading source when the return value of load has format: 'commonjs'. See nodejs/node#34753 (comment) and https://github.com/nodejs/loaders-test/blob/835506a638c6002c1b2d42ab7137db3e7eda53fa/coffeescript-loader/loader.js#L45-L50.

  • First-class support for import maps that doesn’t require a custom loader.

We hope that moving loaders off thread will allow us to preserve an async resolve hook while supporting the sync import.meta.resolve API. If that turns out to be unachievable, however, then:

  • Convert resolve from async to sync nodejs/node#43363

    • Add an async resolve to module module

    • Consider an API for async operations before resolution begins, such as preImport #89

After this, we should get user feedback regarding the developer experience; for example, is too much boilerplate required? Should we have a separate transform hook? And so on. We should also investigate and potentially implement the technical improvements on our to-do list.

About

ECMAScript Modules Loaders

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 16