npm.io
2.0.0 • Published 5d ago

node-imports-info

Licence
MIT
Version
2.0.0
Deps
1
Size
18 kB
Vulns
0
Weekly
121

node-imports-info Version Badge

github actions coverage License Downloads

npm badge

Info about node imports field support: version ranges, categories, etc.

The imports field (subpath imports, with specifiers prefixed by #) shares most of its resolution behavior with the exports field, but its features arrived on a different timeline. This package tracks imports-specific syntax support; for exports, see node-exports-info.

imports resolution also uses conditions (node, node-addons, require, import, module-sync, default); these are field-agnostic, so getConditionsForCategory/getCategoryInfo share their implementation (in node-package-field-info) with node-exports-info.

Categories

  • pre-imports: versions that do not support the imports field (< 12.19 || 13 - 14.5). The field was added in 14.6.0 and backported to 12.19.0, so the 13.x line and 14.0 - 14.5 never received it, despite being newer than 12.19
  • imports: the first versions to support the imports field, including conditions and trailing-slash folder mappings, but not * patterns (~12.19 || 14.6 - 14.12)
  • patterns: support for * subpath patterns was added in these versions (^12.20 || 14.13 - 14.18 || 15.x || 16.0 - 16.9)
  • pattern-trailers: support for “pattern trailers” (a suffix after the *) was added in these versions (^14.19 || 16.10 - 16)
  • pattern-trailers-no-dir-slash: support for trailing-slash folder mappings (ending in /) was removed for these versions (17 - 20.18 || ^21 || 22.0 - 22.11)
  • pattern-trailers-no-dir-slash+module-sync: same syntax support, but the module-sync condition was added in these versions (^20.19 || 22.12 - 24.13 || 25 - 25.3)
  • subpath-imports-slash: these versions support subpath imports keys starting with #/, e.g. "#/*": "./src/*.js" (^24.14 || >= 25.4)

Entry points

  • node-imports-info/getCategoriesForRange: takes a node semver version range; returns an array of categories that overlap it
  • node-imports-info/getCategory: takes an optional node semver version (defaults to the current node version); returns the latest category that matches it
  • node-imports-info/getCategoryFlags: takes a category; returns an object with boolean flags { patterns, patternTrailers, dirSlash, subpathSlash } indicating which imports features are supported
  • node-imports-info/getConditionsForCategory: takes a category and an optional moduleSystem ('require' or 'import'); returns the array of supported conditions, or null if the imports field is unsupported
  • node-imports-info/getCategoryInfo: takes a category and an optional moduleSystem; returns an object with conditions and flags
  • node-imports-info/getRange: takes a category; returns the node semver version range that matches it
  • node-imports-info/getRangePairs: returns an array of entries - each a tuple of “semver range” and “category”
  • node-imports-info/isCategory: takes a category; returns true if it’s a known category

Tests

Simply clone the repo, npm install, and run npm test

Keywords