get-conditions
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

get-conditions Latest version npm downloads

Get Node import conditions at runtime


Premium sponsor banner

Install

npm install get-conditions

Why?

In Node.js, users can pass in custom import conditions via --conditions to influence which paths are used when export or import maps are resolved.

However, this information is not available at runtime. This makes it difficult when implementing custom resolvers (e.g. statically analyzing an import path).

Premium sponsor banner

API

getConditions()

Returns: string[]

Example: ['node', 'node-addons', 'foo', 'bar']

Gets the import conditions for the current Node.js process.

require and import are excluded as their existence varies by how the current module was resolved. But you can add require/import back depending on which resolution type you prefer, before passing in the array into a resolver.

Note, the order of this array does not matter to the resolution algorithm (the order of the condition keys in the map does).

Sponsors

Premium sponsor banner Premium sponsor banner

Package Sidebar

Install

npm i get-conditions

Weekly Downloads

251

Version

1.0.0

License

MIT

Unpacked Size

7.24 kB

Total Files

7

Last publish

Collaborators

  • hirokiosame