1.0.0 • Published 5 months ago

get-conditions v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

get-conditions Latest version npm downloads

Get Node import conditions at runtime

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).

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