Ajout de promotion et de commande
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [ljharb]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: npm/node-exports-info
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 85.93,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v1.6.0](https://github.com/inspect-js/node-exports-info/compare/v1.5.1...v1.6.0) - 2026-01-28
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add `getCategoryFlags` and `getCategoryInfo` APIs [`164024c`](https://github.com/inspect-js/node-exports-info/commit/164024c07e4612b8cfd470730b51f9ec78bdead2)
|
||||
- [readme] use curly quotes in prose [`945e57a`](https://github.com/inspect-js/node-exports-info/commit/945e57a650d7d0ae085c84e11e493d939e77d05f)
|
||||
|
||||
## [v1.5.1](https://github.com/inspect-js/node-exports-info/compare/v1.5.0...v1.5.1) - 2026-01-28
|
||||
|
||||
### Commits
|
||||
|
||||
- [Types] add missing types changes from 547f4ef3f62e05032cb7b4d7e4f541eea380fcbf [`ad98746`](https://github.com/inspect-js/node-exports-info/commit/ad98746dcae60360813ea7fce8955415529b5408)
|
||||
|
||||
## [v1.5.0](https://github.com/inspect-js/node-exports-info/compare/v1.4.0...v1.5.0) - 2026-01-16
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add `node-addons` condition support [`fd11809`](https://github.com/inspect-js/node-exports-info/commit/fd118093e55e8fcb1b3b1c90779e277a6806bc73)
|
||||
- [New] add `module-sync` condition support [`6cc5123`](https://github.com/inspect-js/node-exports-info/commit/6cc51230673a8846d5b1d2ec4124e35c9d6f077f)
|
||||
- [New] add `subpath-imports-slash` category for `#/` subpath imports [`547f4ef`](https://github.com/inspect-js/node-exports-info/commit/547f4ef3f62e05032cb7b4d7e4f541eea380fcbf)
|
||||
|
||||
## [v1.4.0](https://github.com/inspect-js/node-exports-info/compare/v1.3.1...v1.4.0) - 2026-01-12
|
||||
|
||||
### Commits
|
||||
|
||||
- [Refactor] use loops instead of `array.prototype.find` [`d58884b`](https://github.com/inspect-js/node-exports-info/commit/d58884b03ce0ac49ba74f0ac923d5388f468af7c)
|
||||
- [types] use shared config [`136778d`](https://github.com/inspect-js/node-exports-info/commit/136778db519a5b7e3b1ad13f40d71e4c05de196e)
|
||||
- [Dev Deps] update `eslint` [`616920c`](https://github.com/inspect-js/node-exports-info/commit/616920cc40f5be64eaca8f02626d3543ae4816d3)
|
||||
- [New] add type stripping, require(esm), JSON imports [`75b97f1`](https://github.com/inspect-js/node-exports-info/commit/75b97f1d7108207dadcfd3ab7010cd15ed2aebe1)
|
||||
- [actions] split out node 10-20, and 20+ [`7e992d2`](https://github.com/inspect-js/node-exports-info/commit/7e992d25b4d144405f9fcd51d2ef80f0cd614dd3)
|
||||
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@types/object-inspect`, `auto-changelog`, `es-value-fixtures`, `object-inspect`, `tape` [`417745a`](https://github.com/inspect-js/node-exports-info/commit/417745a3186a03b1b2ddb26aa7c0d16fd59edb91)
|
||||
- [Robustness] use `es-errors` [`c25eda7`](https://github.com/inspect-js/node-exports-info/commit/c25eda77ad517d7b01be662e1ce9b86974b49f87)
|
||||
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/tsconfig`, `@types/tape`, `es-value-fixtures`, `for-each`, `object-inspect` [`84c5d1b`](https://github.com/inspect-js/node-exports-info/commit/84c5d1b8eb670b985b1ae25a32b198a61383f34d)
|
||||
- [Fix] update the strips-types node ranges [`e6ef526`](https://github.com/inspect-js/node-exports-info/commit/e6ef52685f5d2c05b22e5bac03086b8a2b0836e0)
|
||||
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `eslint`, `npmignore` [`f10c9d8`](https://github.com/inspect-js/node-exports-info/commit/f10c9d8373c6876872144ed33a9abadcdbc3265a)
|
||||
- [readme] fix badges [`0dd9d62`](https://github.com/inspect-js/node-exports-info/commit/0dd9d624c17c135def20f0e43d095fd555640919)
|
||||
- [Deps] update `array.prototype.flatmap`, `object.entries` [`140b885`](https://github.com/inspect-js/node-exports-info/commit/140b8852614b64c23444109377df4cbb41638647)
|
||||
- [Deps] update `array.prototype.find`, `object.entries` [`0d87ad7`](https://github.com/inspect-js/node-exports-info/commit/0d87ad7fe6e58eda7424bffb311480b65e865af8)
|
||||
- [Tests] replace `aud` with `npm audit` [`5d03f96`](https://github.com/inspect-js/node-exports-info/commit/5d03f964dc4e48b02a2ae53e7376488568115a97)
|
||||
- [Tests] use `@arethetypeswrong/cli` [`5a2ef68`](https://github.com/inspect-js/node-exports-info/commit/5a2ef68cc53940701533240f2e251a502e00aaf1)
|
||||
- [Dev Deps] update `@arethetypeswrong/cli` [`0a430bc`](https://github.com/inspect-js/node-exports-info/commit/0a430bc15e029d115ee6d6562a7c835ca9623f90)
|
||||
|
||||
## [v1.3.1](https://github.com/inspect-js/node-exports-info/compare/v1.3.0...v1.3.1) - 2024-02-26
|
||||
|
||||
### Commits
|
||||
|
||||
- add types [`c3449ed`](https://github.com/inspect-js/node-exports-info/commit/c3449edd1e3c0e1dd019c3c5ef9f075305577372)
|
||||
- [actions] skip ls check on node < 10; remove redundant finisher [`8a88b7b`](https://github.com/inspect-js/node-exports-info/commit/8a88b7b82a05787540541bd40dd92c4d73083e19)
|
||||
- [actions] remove erroneous `none` permission [`9145df6`](https://github.com/inspect-js/node-exports-info/commit/9145df664d6ccbb49a812ccadb35ecad5957a6ba)
|
||||
- [Dev Deps] update `tape` [`ff1f4de`](https://github.com/inspect-js/node-exports-info/commit/ff1f4ded536ea936a96c1c01f026768abc41ac27)
|
||||
|
||||
## [v1.3.0](https://github.com/inspect-js/node-exports-info/compare/v1.2.1...v1.3.0) - 2023-12-15
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add `isCategory` [`13b0f5f`](https://github.com/inspect-js/node-exports-info/commit/13b0f5f1ae7db4ddbbcc8a25f4acf671fffaf622)
|
||||
|
||||
## [v1.2.1](https://github.com/inspect-js/node-exports-info/compare/v1.2.0...v1.2.1) - 2023-12-15
|
||||
|
||||
### Commits
|
||||
|
||||
- [meta] use `npmignore` to autogenerate an npmignore file [`e79731c`](https://github.com/inspect-js/node-exports-info/commit/e79731c10ea60ddd06cc5d8ffe0acd2ac5ca051a)
|
||||
- [actions] update rebase action to use reusable workflow [`20eab87`](https://github.com/inspect-js/node-exports-info/commit/20eab879a247e893c3566f5327a0e1b8978e0ccc)
|
||||
- [Deps] update `array.prototype.find`, `array.prototype.flatmap`, `object.entries`, `semver` [`7f3bf1b`](https://github.com/inspect-js/node-exports-info/commit/7f3bf1bce617bab72f5091f150549fc344beb0a0)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `npmignore`, `tape` [`a30b7b7`](https://github.com/inspect-js/node-exports-info/commit/a30b7b7880de4f2aa2f45537233bb5e30abc3169)
|
||||
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`1f262ad`](https://github.com/inspect-js/node-exports-info/commit/1f262ad99324825a8fd9b3ce5cf425f4a849a6c4)
|
||||
- [Deps] update `array.prototype.find`, `array.prototype.flatmap` [`660e637`](https://github.com/inspect-js/node-exports-info/commit/660e637bf7a5cfbdf90e5ad174a437cf381c5c3d)
|
||||
- [meta] add `safe-publish-latest` [`bcfb161`](https://github.com/inspect-js/node-exports-info/commit/bcfb161a37311a7791147addceda91ca9ef4a006)
|
||||
- [Robustness] `ranges`: make it a null object [`5a6d476`](https://github.com/inspect-js/node-exports-info/commit/5a6d47631a6491ec7517b8a2ce3a7ba9ccece461)
|
||||
|
||||
## [v1.2.0](https://github.com/inspect-js/node-exports-info/compare/v1.1.3...v1.2.0) - 2022-04-08
|
||||
|
||||
### Commits
|
||||
|
||||
- Revert "[Tests] temporarily use actions instead of composable workflows" [`1d12795`](https://github.com/inspect-js/node-exports-info/commit/1d1279531112e422d1b67cad2bc267684ec0ca81)
|
||||
- [New] `getConditionsForCategory`: add optional `moduleSystem` argument [`b4164bd`](https://github.com/inspect-js/node-exports-info/commit/b4164bde3658ec66c08319e411f01096939a734a)
|
||||
- [actions] restrict permissions [`d0f58ef`](https://github.com/inspect-js/node-exports-info/commit/d0f58ef3696498a3030eb378ce0c98d32e8c7bba)
|
||||
- [Dev Deps] update `tape` [`afaa392`](https://github.com/inspect-js/node-exports-info/commit/afaa3928208f93f308e1045eb9c5e8e50cea4e18)
|
||||
|
||||
## [v1.1.3](https://github.com/inspect-js/node-exports-info/compare/v1.1.2...v1.1.3) - 2022-03-24
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] `node v13.13 also has broken dir-slash [`cc9f891`](https://github.com/inspect-js/node-exports-info/commit/cc9f891f8679a1e4b1063d2d91546b72f82be011)
|
||||
- [meta] add missing `version` config [`6a7f8c6`](https://github.com/inspect-js/node-exports-info/commit/6a7f8c629d9fb41315c3cea2c514d0398c6be2c7)
|
||||
|
||||
## [v1.1.2](https://github.com/inspect-js/node-exports-info/compare/v1.1.1...v1.1.2) - 2022-03-22
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] turns out all `patterns` nodes have a broken dir-slash [`3e8310b`](https://github.com/inspect-js/node-exports-info/commit/3e8310b79496de9d177487c3b5d199cd66630d9d)
|
||||
|
||||
## [v1.1.1](https://github.com/inspect-js/node-exports-info/compare/v1.1.0...v1.1.1) - 2022-03-21
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] correct category version ranges [`e98260d`](https://github.com/inspect-js/node-exports-info/commit/e98260dc78a7e969c4fa0d868934066865f344e2)
|
||||
|
||||
## [v1.1.0](https://github.com/inspect-js/node-exports-info/compare/v1.0.2...v1.1.0) - 2022-03-21
|
||||
|
||||
### Commits
|
||||
|
||||
- [New] add three new categories: [`a549cb8`](https://github.com/inspect-js/node-exports-info/commit/a549cb884e8d6a990fdcdd5eb9b10e922a24c89c)
|
||||
|
||||
## [v1.0.2](https://github.com/inspect-js/node-exports-info/compare/v1.0.1...v1.0.2) - 2022-03-21
|
||||
|
||||
### Commits
|
||||
|
||||
- [Fix] fix sort ordering of range pairs [`48a6865`](https://github.com/inspect-js/node-exports-info/commit/48a68659e890d4331ede9c971709ca03e5ab3b9a)
|
||||
|
||||
## [v1.0.1](https://github.com/inspect-js/node-exports-info/compare/v1.0.0...v1.0.1) - 2022-03-21
|
||||
|
||||
### Commits
|
||||
|
||||
- [meta] do not publish workflow files [`44a1fe8`](https://github.com/inspect-js/node-exports-info/commit/44a1fe82cffc4453d8bc5171d70284b205db7bcc)
|
||||
- read me [`99e4edf`](https://github.com/inspect-js/node-exports-info/commit/99e4edf1b245b8c58b8854c7596da5007e3f887e)
|
||||
- [Test] add tests [`462bd2b`](https://github.com/inspect-js/node-exports-info/commit/462bd2b0a8e0147f308f93885f30e1d255e1746e)
|
||||
|
||||
## v1.0.0 - 2022-03-20
|
||||
|
||||
### Commits
|
||||
|
||||
- initial implementation and tests [`633f2bc`](https://github.com/inspect-js/node-exports-info/commit/633f2bcfc4a939c3095ea1c6cc08d426baa1c726)
|
||||
- Initial commit [`bef50ef`](https://github.com/inspect-js/node-exports-info/commit/bef50ef02aabd8a50d8841d665106aeb6097248f)
|
||||
- [Tests] temporarily use actions instead of composable workflows [`436fbbf`](https://github.com/inspect-js/node-exports-info/commit/436fbbf9612f0d661cc66b7a73247015eccbef13)
|
||||
- `npm init` [`0c85774`](https://github.com/inspect-js/node-exports-info/commit/0c8577490640779d2881dbd02d1a8dca7c9951a5)
|
||||
- Only apps should have lockfiles [`28d9d61`](https://github.com/inspect-js/node-exports-info/commit/28d9d6160d10855cbf29bb1e4751260b87735d34)
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Inspect JS
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
# node-exports-info <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||
|
||||
[![github actions][actions-image]][actions-url]
|
||||
[![coverage][codecov-image]][codecov-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
|
||||
[![npm badge][npm-badge-png]][package-url]
|
||||
|
||||
Info about node `exports` field support: version ranges, categories, etc.
|
||||
|
||||
## Categories
|
||||
- `pre-exports`: versions before node supported `exports` in any way (`< 12.17`)
|
||||
- `broken`: versions that have a broken `exports` implementation. These only support the string form, and array fallbacks. (`13.0 - 13.2`)
|
||||
- `experimental`: versions where `exports` support was experimental. These only support the “default” condition in the object form. (`13.3 - 13.6`)
|
||||
- `conditions`: the first versions where `exports` support was unflagged. (`13.7 - 13.12`)
|
||||
- `broken-dir-slash-conditions`: `conditions`, but directory exports (ending in `./`) are broken in these versions (`12.17 - 12.19 || ^13.13 || 14.0 - 14.12`)
|
||||
- `patterns`: support for “patterns” was added in these versions, and directory exports (ending in `./`) are broken (`^12.20 || 14.13 - 14.18 || 15.x || 16.0 - 16.8`)
|
||||
- `pattern-trailers`: support for “pattern trailers” was added in these versions (`^14.19 || 16.9 - 16.13`)
|
||||
- `pattern-trailers+json-imports`: `pattern-trailers`, and JSON can be `import`ed (`^16.14`)
|
||||
- `pattern-trailers-no-dir-slash`: support for directory exports (ending in `./`) was removed for these versions (`17.0`)
|
||||
- `pattern-trailers-no-dir-slash+json-imports`: `pattern-trailers-no-dir-slash`, and JSON can be `import`ed (`17.1 - 19 || 20 - 20.18 || ^21 || 22 - 22.11`)
|
||||
- `require-esm`: ESM files can be `require`d (`23 - 23.5 || 22.12 - 22.17 || ^20.19`)
|
||||
- `strips-types`: these versions also automatically strip types from typescript files, for both `require` and `import` (`23.6 - 25.3 || ^22.18`)
|
||||
- `subpath-imports-slash`: these versions support `#/` subpath imports patterns in the `imports` field, e.g. `"#/*": "./src/*.js"` (`>= 25.4`)
|
||||
|
||||
## Entry points
|
||||
- `node-exports-info/getCategoriesForRange`: takes a node semver version range; returns an array of categories that overlap it
|
||||
- `node-exports-info/getCategory`: takes an optional node semver version (defaults to the current node version); returns the latest category that matches it
|
||||
- `node-exports-info/getCategoryFlags`: takes a category; returns an object with boolean flags `{ patterns, patternTrailers, dirSlash }` indicating which `exports` features are supported
|
||||
- `node-exports-info/getCategoryInfo`: takes a category and an optional `moduleSystem` (`'require'` or `'import'`); returns an object with `conditions` (array or null) and `flags` (from `getCategoryFlags`)
|
||||
- `node-exports-info/getConditionsForCategory`: takes a category and an optional `moduleSystem` (`'require'` or `'import'`); returns an array of `exports` "conditions" that is supported, or `null` if `exports` itself is not supported
|
||||
- `node-exports-info/getRange`: takes a category; returns the node semver version range that matches it
|
||||
- `node-exports-info/getRangePairs`: returns an array of entries - each a tuple of “semver range” and “category”
|
||||
- `node-exports-info/isCategory`: takes a category; returns true if it’s a known category
|
||||
|
||||
## Related packages
|
||||
- [`has-package-exports`](https://www.npmjs.com/package/has-package-exports): feature-detect your node version’s `exports` support
|
||||
|
||||
## Tests
|
||||
Simply clone the repo, `npm install`, and run `npm test`
|
||||
|
||||
[package-url]: https://npmjs.org/package/node-exports-info
|
||||
[npm-version-svg]: https://versionbadg.es/inspect-js/node-exports-info.svg
|
||||
[deps-svg]: https://david-dm.org/inspect-js/node-exports-info.svg
|
||||
[deps-url]: https://david-dm.org/inspect-js/node-exports-info
|
||||
[dev-deps-svg]: https://david-dm.org/inspect-js/node-exports-info/dev-status.svg
|
||||
[dev-deps-url]: https://david-dm.org/inspect-js/node-exports-info#info=devDependencies
|
||||
[npm-badge-png]: https://nodei.co/npm/node-exports-info.png?downloads=true&stars=true
|
||||
[license-image]: https://img.shields.io/npm/l/node-exports-info.svg
|
||||
[license-url]: LICENSE
|
||||
[downloads-image]: https://img.shields.io/npm/dm/node-exports-info.svg
|
||||
[downloads-url]: https://npm-stat.com/charts.html?package=node-exports-info
|
||||
[codecov-image]: https://codecov.io/gh/inspect-js/node-exports-info/branch/main/graphs/badge.svg
|
||||
[codecov-url]: https://app.codecov.io/gh/inspect-js/node-exports-info/
|
||||
[actions-image]: https://img.shields.io/github/check-runs/inspect-js/node-exports-info/main
|
||||
[actions-url]: https://github.com/inspect-js/node-exports-info/actions
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import ljharbConfig from '@ljharb/eslint-config/flat';
|
||||
|
||||
export default [
|
||||
...ljharbConfig,
|
||||
{
|
||||
rules: {
|
||||
'func-name-matching': ['error', 'always'],
|
||||
'id-length': 'off',
|
||||
'multiline-comment-style': 'off',
|
||||
'no-magic-numbers': ['error', { ignore: [0, 1] }],
|
||||
'sort-keys': 'off',
|
||||
},
|
||||
},
|
||||
];
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { type Category } from './types';
|
||||
|
||||
declare function getCategoriesForRange(rangeA: string): Category[];
|
||||
|
||||
export = getCategoriesForRange;
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
var flatMap = require('array.prototype.flatmap');
|
||||
var entries = require('object.entries');
|
||||
var intersects = require('semver').intersects;
|
||||
|
||||
var ranges = require('./ranges');
|
||||
|
||||
/** @type {import('./getCategoriesForRange')} */
|
||||
module.exports = function getCategoriesForRange(rangeA) {
|
||||
return flatMap(
|
||||
entries(ranges),
|
||||
/** @type {(entry: import('./types').RangePair) => import('./types').Category[] | []} */
|
||||
function (entry) {
|
||||
var rangeB = entry[0];
|
||||
var category = entry[1];
|
||||
return intersects(rangeA, rangeB) ? [category] : [];
|
||||
}
|
||||
);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { Category } from './types';
|
||||
|
||||
declare function getCategory(nodeVersion?: string): Category;
|
||||
|
||||
export = getCategory;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
var entries = require('object.entries');
|
||||
var satisfies = require('semver').satisfies;
|
||||
|
||||
var ranges = require('./ranges');
|
||||
|
||||
/** @type {import('./getCategory')} */
|
||||
module.exports = function getCategory() {
|
||||
var version = arguments.length > 0 ? arguments[0] : process.version;
|
||||
var rangeEntries = entries(ranges);
|
||||
for (var i = 0; i < rangeEntries.length; i += 1) {
|
||||
var entry = rangeEntries[i];
|
||||
if (satisfies(version, entry[0])) {
|
||||
return entry[1];
|
||||
}
|
||||
}
|
||||
|
||||
throw new $RangeError('no category found for version ' + version);
|
||||
};
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
import type { Category } from './types';
|
||||
|
||||
declare namespace getCategoryFlags {
|
||||
interface CategoryFlags {
|
||||
patterns: boolean;
|
||||
patternTrailers: boolean;
|
||||
dirSlash: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare function getCategoryFlags(category: Category): getCategoryFlags.CategoryFlags;
|
||||
|
||||
export = getCategoryFlags;
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
|
||||
var isCategory = require('./isCategory');
|
||||
|
||||
// Categories that support patterns (wildcard *)
|
||||
/** @type {{ [k in import('./types').Category | '__proto__']?: k extends '__proto__' ? null : true }} */
|
||||
var patternsCategories = {
|
||||
__proto__: null,
|
||||
patterns: true,
|
||||
'pattern-trailers': true,
|
||||
'pattern-trailers+json-imports': true,
|
||||
'pattern-trailers-no-dir-slash': true,
|
||||
'pattern-trailers-no-dir-slash+json-imports': true,
|
||||
'require-esm': true,
|
||||
'strips-types': true,
|
||||
'subpath-imports-slash': true
|
||||
};
|
||||
|
||||
// Categories that support pattern trailers (suffix after *)
|
||||
/** @type {{ [k in import('./types').Category | '__proto__']?: k extends '__proto__' ? null : true }} */
|
||||
var patternTrailersCategories = {
|
||||
__proto__: null,
|
||||
'pattern-trailers': true,
|
||||
'pattern-trailers+json-imports': true,
|
||||
'pattern-trailers-no-dir-slash': true,
|
||||
'pattern-trailers-no-dir-slash+json-imports': true,
|
||||
'require-esm': true,
|
||||
'strips-types': true,
|
||||
'subpath-imports-slash': true
|
||||
};
|
||||
|
||||
// Categories that support directory slash exports (ending with /)
|
||||
/** @type {{ [k in import('./types').Category | '__proto__']?: k extends '__proto__' ? null : true }} */
|
||||
var dirSlashCategories = {
|
||||
__proto__: null,
|
||||
'broken-dir-slash-conditions': true,
|
||||
patterns: true,
|
||||
'pattern-trailers': true,
|
||||
'pattern-trailers+json-imports': true,
|
||||
'subpath-imports-slash': true
|
||||
};
|
||||
|
||||
/** @type {import('./getCategoryFlags')} */
|
||||
module.exports = function getCategoryFlags(category) {
|
||||
if (!isCategory(category)) {
|
||||
throw new $RangeError('invalid category ' + category);
|
||||
}
|
||||
|
||||
return {
|
||||
patterns: !!patternsCategories[category],
|
||||
patternTrailers: !!patternTrailersCategories[category],
|
||||
dirSlash: !!dirSlashCategories[category]
|
||||
};
|
||||
};
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import type { Category, Condition } from './types';
|
||||
import type getCategoryFlags from './getCategoryFlags';
|
||||
|
||||
declare namespace getCategoryInfo {
|
||||
interface CategoryInfo {
|
||||
conditions: Condition[] | null;
|
||||
flags: getCategoryFlags.CategoryFlags;
|
||||
}
|
||||
}
|
||||
|
||||
declare function getCategoryInfo(
|
||||
category: Category,
|
||||
moduleSystem?: 'import' | 'require'
|
||||
): getCategoryInfo.CategoryInfo;
|
||||
|
||||
export = getCategoryInfo;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
var getCategoryFlags = require('./getCategoryFlags');
|
||||
var getConditionsForCategory = require('./getConditionsForCategory');
|
||||
|
||||
/** @type {import('./getCategoryInfo')} */
|
||||
module.exports = function getCategoryInfo(category, moduleSystem) {
|
||||
var conditions = getConditionsForCategory(category, moduleSystem || 'require');
|
||||
var flags = getCategoryFlags(category);
|
||||
return { conditions: conditions, flags: flags };
|
||||
};
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import type { Category, Condition } from './types';
|
||||
|
||||
declare function getConditionsForCategory(
|
||||
category: Category,
|
||||
moduleSystem?: 'import' | 'require'
|
||||
): (
|
||||
| ['default']
|
||||
| ['import', 'node', 'default']
|
||||
| ['node', 'require', 'default']
|
||||
| ['import', 'node', 'require', 'default']
|
||||
| ['import', 'node-addons', 'node', 'default']
|
||||
| ['node-addons', 'node', 'require', 'default']
|
||||
| ['import', 'node-addons', 'node', 'require', 'default']
|
||||
| ['import', 'node-addons', 'node', 'module-sync', 'default']
|
||||
| ['node-addons', 'node', 'require', 'module-sync', 'default']
|
||||
| ['import', 'node-addons', 'node', 'require', 'module-sync', 'default']
|
||||
| null
|
||||
);
|
||||
|
||||
export = getConditionsForCategory;
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
var $TypeError = require('es-errors/type');
|
||||
|
||||
var isCategory = require('./isCategory');
|
||||
|
||||
// pre-computed condition sets
|
||||
/** @type {['import', 'node', 'require', 'default']} */
|
||||
var base = [
|
||||
'import',
|
||||
'node',
|
||||
'require',
|
||||
'default'
|
||||
];
|
||||
/** @type {['import', 'node', 'default']} */
|
||||
var baseImport = [
|
||||
'import',
|
||||
'node',
|
||||
'default'
|
||||
];
|
||||
/** @type {['node', 'require', 'default']} */
|
||||
var baseRequire = [
|
||||
'node',
|
||||
'require',
|
||||
'default'
|
||||
];
|
||||
/** @type {['import', 'node-addons', 'node', 'require', 'default']} */
|
||||
var withAddons = [
|
||||
'import',
|
||||
'node-addons',
|
||||
'node',
|
||||
'require',
|
||||
'default'
|
||||
];
|
||||
/** @type {['import', 'node-addons', 'node', 'default']} */
|
||||
var withAddonsImport = [
|
||||
'import',
|
||||
'node-addons',
|
||||
'node',
|
||||
'default'
|
||||
];
|
||||
/** @type {['node-addons', 'node', 'require', 'default']} */
|
||||
var withAddonsRequire = [
|
||||
'node-addons',
|
||||
'node',
|
||||
'require',
|
||||
'default'
|
||||
];
|
||||
/** @type {['import', 'node-addons', 'node', 'require', 'module-sync', 'default']} */
|
||||
var withAddonsModuleSync = [
|
||||
'import',
|
||||
'node-addons',
|
||||
'node',
|
||||
'require',
|
||||
'module-sync',
|
||||
'default'
|
||||
];
|
||||
/** @type {['import', 'node-addons', 'node', 'module-sync', 'default']} */
|
||||
var withAddonsModuleSyncImport = [
|
||||
'import',
|
||||
'node-addons',
|
||||
'node',
|
||||
'module-sync',
|
||||
'default'
|
||||
];
|
||||
/** @type {['node-addons', 'node', 'require', 'module-sync', 'default']} */
|
||||
var withAddonsModuleSyncRequire = [
|
||||
'node-addons',
|
||||
'node',
|
||||
'require',
|
||||
'module-sync',
|
||||
'default'
|
||||
];
|
||||
|
||||
// categories that support node-addons condition (added in v14.19/v16.10)
|
||||
/** @type {{ [k: string]: boolean | null | undefined }} */
|
||||
var nodeAddonsCategories = {
|
||||
__proto__: null,
|
||||
'pattern-trailers': true,
|
||||
'pattern-trailers+json-imports': true,
|
||||
'pattern-trailers-no-dir-slash': true,
|
||||
'pattern-trailers-no-dir-slash+json-imports': true,
|
||||
'require-esm': true,
|
||||
'strips-types': true,
|
||||
'subpath-imports-slash': true
|
||||
};
|
||||
|
||||
// categories that support module-sync condition (added in v22.12)
|
||||
/** @type {{ [k: string]: boolean | null | undefined }} */
|
||||
var moduleSyncCategories = {
|
||||
__proto__: null,
|
||||
'require-esm': true,
|
||||
'strips-types': true,
|
||||
'subpath-imports-slash': true
|
||||
};
|
||||
|
||||
/** @type {import('./getConditionsForCategory')} */
|
||||
module.exports = function getConditionsForCategory(category) {
|
||||
if (!isCategory(category)) {
|
||||
throw new $RangeError('invalid category ' + category);
|
||||
}
|
||||
|
||||
var moduleSystem = arguments.length > 1 ? arguments[1] : null;
|
||||
if (arguments.length > 1 && moduleSystem !== 'import' && moduleSystem !== 'require') {
|
||||
throw new $TypeError('invalid moduleSystem: must be `\'require\'` or `\'import\'` if provided, got' + moduleSystem);
|
||||
}
|
||||
|
||||
if (category === 'experimental') {
|
||||
return ['default'];
|
||||
}
|
||||
if (category === 'broken' || category === 'pre-exports') {
|
||||
return null;
|
||||
}
|
||||
|
||||
var hasAddons = !!nodeAddonsCategories[category];
|
||||
var hasModuleSync = !!moduleSyncCategories[category];
|
||||
|
||||
if (hasAddons && hasModuleSync) {
|
||||
return moduleSystem === 'import' ? withAddonsModuleSyncImport : moduleSystem === 'require' ? withAddonsModuleSyncRequire : withAddonsModuleSync;
|
||||
}
|
||||
if (hasAddons) {
|
||||
return moduleSystem === 'import' ? withAddonsImport : moduleSystem === 'require' ? withAddonsRequire : withAddons;
|
||||
}
|
||||
return moduleSystem === 'import' ? baseImport : moduleSystem === 'require' ? baseRequire : base;
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { Category, Range } from './types';
|
||||
|
||||
declare function getRange(category: Category): Range;
|
||||
|
||||
export = getRange;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
var $RangeError = require('es-errors/range');
|
||||
var entries = require('object.entries');
|
||||
|
||||
var ranges = require('./ranges');
|
||||
|
||||
/** @type {import('./getRange')} */
|
||||
module.exports = function getRange(category) {
|
||||
var rangeEntries = entries(ranges);
|
||||
for (var i = 0; i < rangeEntries.length; i += 1) {
|
||||
var entry = rangeEntries[i];
|
||||
if (entry[1] === category) {
|
||||
return entry[0];
|
||||
}
|
||||
}
|
||||
|
||||
throw new $RangeError('no version range found for category ' + category);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { Category, Range } from "./types";
|
||||
|
||||
declare function getRangePairs(): [Range, Category][];
|
||||
|
||||
export = getRangePairs;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
|
||||
var entries = require('object.entries');
|
||||
|
||||
var ranges = require('./ranges');
|
||||
|
||||
/** @type {import('./getRangePairs')} */
|
||||
module.exports = function getRangePairs() {
|
||||
return entries(ranges);
|
||||
};
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import type { Category } from './types';
|
||||
|
||||
declare function isCategory(category: unknown): category is Category;
|
||||
|
||||
export = isCategory;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
var getRangePairs = require('./getRangePairs');
|
||||
|
||||
/** @type {import('./isCategory')} */
|
||||
module.exports = function isCategory(category) {
|
||||
var all = getRangePairs();
|
||||
|
||||
for (var i = 0; i < all.length; i++) {
|
||||
if (all[i][1] === category) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
{
|
||||
"name": "node-exports-info",
|
||||
"version": "1.6.0",
|
||||
"description": "Info about node `exports` field support: version ranges, categories, etc.",
|
||||
"main": false,
|
||||
"exports": {
|
||||
"./getCategoriesForRange": "./getCategoriesForRange.js",
|
||||
"./getCategory": "./getCategory.js",
|
||||
"./getCategoryFlags": "./getCategoryFlags.js",
|
||||
"./getCategoryInfo": "./getCategoryInfo.js",
|
||||
"./getConditionsForCategory": "./getConditionsForCategory.js",
|
||||
"./getRange": "./getRange.js",
|
||||
"./getRangePairs": "./getRangePairs.js",
|
||||
"./isCategory": "./isCategory.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||
"prepublishOnly": "safe-publish-latest",
|
||||
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||
"lint": "eslint .",
|
||||
"postlint": "tsc && attw -P",
|
||||
"pretest": "npm run lint",
|
||||
"tests-only": "nyc tape 'test/**/*.js'",
|
||||
"test": "npm run tests-only",
|
||||
"posttest": "npx npm@'>=10.2' audit --production",
|
||||
"version": "auto-changelog && git add CHANGELOG.md",
|
||||
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/inspect-js/node-exports-info.git"
|
||||
},
|
||||
"keywords": [
|
||||
"node",
|
||||
"exports",
|
||||
"support",
|
||||
"info",
|
||||
"ranges",
|
||||
"categories",
|
||||
"conditions",
|
||||
"patterns",
|
||||
"pattern trailers",
|
||||
"experimental",
|
||||
"esm",
|
||||
"cjs",
|
||||
"require",
|
||||
"import"
|
||||
],
|
||||
"author": "Jordan Harband <ljharb@gmail.com>",
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
},
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/inspect-js/node-exports-info/issues"
|
||||
},
|
||||
"homepage": "https://github.com/inspect-js/node-exports-info#readme",
|
||||
"dependencies": {
|
||||
"array.prototype.flatmap": "^1.3.3",
|
||||
"es-errors": "^1.3.0",
|
||||
"object.entries": "^1.1.9",
|
||||
"semver": "^6.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@arethetypeswrong/cli": "^0.18.2",
|
||||
"@ljharb/eslint-config": "^22.1.3",
|
||||
"@ljharb/tsconfig": "^0.3.2",
|
||||
"@types/array.prototype.flatmap": "^1.2.6",
|
||||
"@types/for-each": "^0.3.3",
|
||||
"@types/object-inspect": "^1.13.0",
|
||||
"@types/object.entries": "^1.1.1",
|
||||
"@types/semver": "^6.2.7",
|
||||
"@types/tape": "^5.8.1",
|
||||
"auto-changelog": "^2.5.0",
|
||||
"es-value-fixtures": "^1.7.1",
|
||||
"eslint": "^9.39.2",
|
||||
"for-each": "^0.3.5",
|
||||
"in-publish": "^2.0.1",
|
||||
"jiti": "^0.0.0",
|
||||
"npmignore": "^0.3.5",
|
||||
"nyc": "^10.3.2",
|
||||
"object-inspect": "^1.13.4",
|
||||
"safe-publish-latest": "^2.0.0",
|
||||
"tape": "^5.9.0",
|
||||
"typescript": "next"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.4"
|
||||
},
|
||||
"auto-changelog": {
|
||||
"output": "CHANGELOG.md",
|
||||
"template": "keepachangelog",
|
||||
"unreleased": false,
|
||||
"commitLimit": false,
|
||||
"backfillLimit": false,
|
||||
"hideCredit": true
|
||||
},
|
||||
"publishConfig": {
|
||||
"ignore": [
|
||||
".github/workflows"
|
||||
]
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
declare const ranges: {
|
||||
__proto__: null;
|
||||
'>= 25.4': 'subpath-imports-slash';
|
||||
'23.6 - 25.3 || ^22.18': 'strips-types';
|
||||
'23 - 23.5 || 22.12 - 22.17 || ^20.19': 'require-esm';
|
||||
'17.1 - 19 || 20 - 20.18 || ^21 || 22 - 22.11': 'pattern-trailers-no-dir-slash+json-imports';
|
||||
'17.0': 'pattern-trailers-no-dir-slash';
|
||||
'^16.14': 'pattern-trailers+json-imports';
|
||||
'^14.19 || 16.9 - 16.13': 'pattern-trailers';
|
||||
'^12.20 || 14.13 - 14.18 || 15.x || 16.0 - 16.8': 'patterns';
|
||||
'12.17 - 12.19 || ^13.13 || 14.0 - 14.12': 'broken-dir-slash-conditions';
|
||||
'13.7 - 13.12': 'conditions';
|
||||
'13.3 - 13.6': 'experimental';
|
||||
'13.0 - 13.2': 'broken';
|
||||
'< 12.17': 'pre-exports';
|
||||
};
|
||||
|
||||
export = ranges;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('./ranges.d.ts')} */
|
||||
module.exports = {
|
||||
__proto__: null,
|
||||
'>= 25.4': 'subpath-imports-slash', // added in 25.4
|
||||
'23.6 - 25.3 || ^22.18': 'strips-types', // added in 23.6, backported to 22.18
|
||||
'23 - 23.5 || 22.12 - 22.17 || ^20.19': 'require-esm', // added in 23.0, 22.12, 20.19
|
||||
'17.1 - 19 || 20 - 20.18 || ^21 || 22 - 22.11': 'pattern-trailers-no-dir-slash+json-imports',
|
||||
'17.0': 'pattern-trailers-no-dir-slash',
|
||||
'^16.14': 'pattern-trailers+json-imports',
|
||||
'^14.19 || 16.9 - 16.13': 'pattern-trailers',
|
||||
'^12.20 || 14.13 - 14.18 || 15.x || 16.0 - 16.8': 'patterns',
|
||||
'12.17 - 12.19 || ^13.13 || 14.0 - 14.12': 'broken-dir-slash-conditions',
|
||||
'13.7 - 13.12': 'conditions',
|
||||
'13.3 - 13.6': 'experimental',
|
||||
'13.0 - 13.2': 'broken',
|
||||
'< 12.17': 'pre-exports'
|
||||
};
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
|
||||
var getCategoriesForRange = require('../getCategoriesForRange');
|
||||
var getCategory = require('../getCategory');
|
||||
|
||||
var boundaryVersions = require('./versions');
|
||||
|
||||
test('getCategoriesForRange', function (t) {
|
||||
t['throws'](
|
||||
function () { getCategoriesForRange('not a version'); },
|
||||
TypeError,
|
||||
'invalid version range throws'
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
getCategoriesForRange(process.version),
|
||||
[getCategory(process.version)],
|
||||
'exactly 1 category for the current version'
|
||||
);
|
||||
|
||||
forEach(boundaryVersions, function (version) {
|
||||
t.test('boundary version: ' + version, function (st) {
|
||||
var categories = getCategoriesForRange(version);
|
||||
|
||||
st.deepEqual(
|
||||
categories,
|
||||
[getCategory(version)],
|
||||
'exactly 1 category for a boundary version'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
var semver = require('semver');
|
||||
|
||||
var getCategory = require('../getCategory');
|
||||
var getRange = require('../getRange');
|
||||
|
||||
var boundaryVersions = require('./versions');
|
||||
|
||||
test('getCategory', function (t) {
|
||||
t['throws'](
|
||||
function () { getCategory('not a version'); },
|
||||
RangeError,
|
||||
'invalid version throws'
|
||||
);
|
||||
t['throws'](
|
||||
function () { getCategory('^1.2.3'); },
|
||||
RangeError,
|
||||
'semver range throws'
|
||||
);
|
||||
|
||||
t.doesNotThrow(
|
||||
function () { getCategory(process.version); },
|
||||
'current node version has a category'
|
||||
);
|
||||
|
||||
forEach(boundaryVersions, function (version) {
|
||||
t.test('boundary version: ' + version, function (st) {
|
||||
st.test('default version', function (s2t) {
|
||||
var origVersion = process.version;
|
||||
Object.defineProperty(process, 'version', { value: version });
|
||||
s2t.teardown(function () { Object.defineProperty(process, 'version', { value: origVersion }); });
|
||||
|
||||
s2t.equal(
|
||||
getCategory(),
|
||||
getCategory(version),
|
||||
'category with an explicit version matches the defaulted process.version'
|
||||
);
|
||||
|
||||
s2t.end();
|
||||
});
|
||||
|
||||
var range = getRange(getCategory(version));
|
||||
st.ok(
|
||||
semver.satisfies(version, range),
|
||||
'version ' + version + ' satisfies range ' + range
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
|
||||
var getCategoryFlags = require('../getCategoryFlags');
|
||||
var getRangePairs = require('../getRangePairs');
|
||||
|
||||
test('getCategoryFlags', function (t) {
|
||||
t['throws'](
|
||||
// @ts-expect-error
|
||||
function () { getCategoryFlags('not a category'); },
|
||||
RangeError,
|
||||
'invalid category throws'
|
||||
);
|
||||
|
||||
forEach(getRangePairs(), function (pair) {
|
||||
var category = pair[1];
|
||||
t.test('category: ' + category, function (st) {
|
||||
var flags = getCategoryFlags(category);
|
||||
|
||||
st.ok(
|
||||
flags && typeof flags === 'object',
|
||||
'returns an object'
|
||||
);
|
||||
st.ok(
|
||||
'patterns' in flags && typeof flags.patterns === 'boolean',
|
||||
'has boolean patterns flag'
|
||||
);
|
||||
st.ok(
|
||||
'patternTrailers' in flags && typeof flags.patternTrailers === 'boolean',
|
||||
'has boolean patternTrailers flag'
|
||||
);
|
||||
st.ok(
|
||||
'dirSlash' in flags && typeof flags.dirSlash === 'boolean',
|
||||
'has boolean dirSlash flag'
|
||||
);
|
||||
|
||||
// Verify flag consistency: patternTrailers implies patterns
|
||||
if (flags.patternTrailers) {
|
||||
st.ok(flags.patterns, 'patternTrailers implies patterns');
|
||||
}
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.test('specific category flags', function (st) {
|
||||
st.deepEqual(
|
||||
getCategoryFlags('pre-exports'),
|
||||
{ patterns: false, patternTrailers: false, dirSlash: false },
|
||||
'pre-exports has no flags'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('broken'),
|
||||
{ patterns: false, patternTrailers: false, dirSlash: false },
|
||||
'broken has no flags'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('experimental'),
|
||||
{ patterns: false, patternTrailers: false, dirSlash: false },
|
||||
'experimental has no flags'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('conditions'),
|
||||
{ patterns: false, patternTrailers: false, dirSlash: false },
|
||||
'conditions has no flags'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('broken-dir-slash-conditions'),
|
||||
{ patterns: false, patternTrailers: false, dirSlash: true },
|
||||
'broken-dir-slash-conditions has dirSlash'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('patterns'),
|
||||
{ patterns: true, patternTrailers: false, dirSlash: true },
|
||||
'patterns has patterns and dirSlash'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('pattern-trailers'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: true },
|
||||
'pattern-trailers has all flags'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('pattern-trailers+json-imports'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: true },
|
||||
'pattern-trailers+json-imports has all flags'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('pattern-trailers-no-dir-slash'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: false },
|
||||
'pattern-trailers-no-dir-slash has patterns and patternTrailers but not dirSlash'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('pattern-trailers-no-dir-slash+json-imports'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: false },
|
||||
'pattern-trailers-no-dir-slash+json-imports has patterns and patternTrailers but not dirSlash'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('require-esm'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: false },
|
||||
'require-esm has patterns and patternTrailers but not dirSlash'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('strips-types'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: false },
|
||||
'strips-types has patterns and patternTrailers but not dirSlash'
|
||||
);
|
||||
|
||||
st.deepEqual(
|
||||
getCategoryFlags('subpath-imports-slash'),
|
||||
{ patterns: true, patternTrailers: true, dirSlash: true },
|
||||
'subpath-imports-slash has all flags'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
|
||||
var getCategoryInfo = require('../getCategoryInfo');
|
||||
var getCategoryFlags = require('../getCategoryFlags');
|
||||
var getConditionsForCategory = require('../getConditionsForCategory');
|
||||
var getRangePairs = require('../getRangePairs');
|
||||
|
||||
test('getCategoryInfo', function (t) {
|
||||
t['throws'](
|
||||
// @ts-expect-error
|
||||
function () { getCategoryInfo('not a category'); },
|
||||
RangeError,
|
||||
'invalid category throws'
|
||||
);
|
||||
|
||||
forEach(getRangePairs(), function (pair) {
|
||||
var category = pair[1];
|
||||
t.test('category: ' + category, function (st) {
|
||||
var info = getCategoryInfo(category);
|
||||
|
||||
st.ok(
|
||||
info && typeof info === 'object',
|
||||
'returns an object'
|
||||
);
|
||||
st.ok(
|
||||
'conditions' in info,
|
||||
'has conditions property'
|
||||
);
|
||||
st.ok(
|
||||
'flags' in info && info.flags && typeof info.flags === 'object',
|
||||
'has flags object'
|
||||
);
|
||||
|
||||
// Verify it matches individual function results
|
||||
st.deepEqual(
|
||||
info.conditions,
|
||||
getConditionsForCategory(category, 'require'),
|
||||
'conditions match getConditionsForCategory with require'
|
||||
);
|
||||
st.deepEqual(
|
||||
info.flags,
|
||||
getCategoryFlags(category),
|
||||
'flags match getCategoryFlags'
|
||||
);
|
||||
|
||||
// Test with explicit moduleSystem
|
||||
var importInfo = getCategoryInfo(category, 'import');
|
||||
st.deepEqual(
|
||||
importInfo.conditions,
|
||||
getConditionsForCategory(category, 'import'),
|
||||
'import conditions match getConditionsForCategory with import'
|
||||
);
|
||||
|
||||
var requireInfo = getCategoryInfo(category, 'require');
|
||||
st.deepEqual(
|
||||
requireInfo.conditions,
|
||||
getConditionsForCategory(category, 'require'),
|
||||
'require conditions match getConditionsForCategory with require'
|
||||
);
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
|
||||
var getConditionsForCategory = require('../getConditionsForCategory');
|
||||
var getRangePairs = require('../getRangePairs');
|
||||
|
||||
test('getConditionsForCategory', function (t) {
|
||||
t['throws'](
|
||||
// @ts-expect-error
|
||||
function () { getConditionsForCategory('not a category'); },
|
||||
RangeError,
|
||||
'invalid category throws'
|
||||
);
|
||||
|
||||
forEach(getRangePairs(), function (pair) {
|
||||
var category = pair[1];
|
||||
t.test('category: ' + category, function (st) {
|
||||
if (category === 'broken' || category === 'pre-exports') {
|
||||
st.equal(
|
||||
getConditionsForCategory(category),
|
||||
null,
|
||||
'category that does not support conditions, yields null'
|
||||
);
|
||||
} else {
|
||||
var conditions = getConditionsForCategory(category);
|
||||
st.ok(Array.isArray(conditions), 'moduleSystem none: returns an array');
|
||||
|
||||
var requireConditions = getConditionsForCategory(category, 'require');
|
||||
st.ok(Array.isArray(requireConditions), 'moduleSystem require: returns an array');
|
||||
|
||||
var importConditions = getConditionsForCategory(category, 'import');
|
||||
st.ok(Array.isArray(importConditions), 'moduleSystem import: returns an array');
|
||||
|
||||
st['throws'](
|
||||
// @ts-expect-error
|
||||
function () { getConditionsForCategory(category, 'not a thing'); },
|
||||
TypeError,
|
||||
'invalid moduleSystem throws'
|
||||
);
|
||||
}
|
||||
|
||||
st.end();
|
||||
});
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
|
||||
var getRange = require('../getRange');
|
||||
var getRangePairs = require('../getRangePairs');
|
||||
|
||||
test('getRange', function (t) {
|
||||
t['throws'](
|
||||
// @ts-expect-error
|
||||
function () { getRange('not a category'); },
|
||||
RangeError,
|
||||
'invalid category throws'
|
||||
);
|
||||
|
||||
forEach(getRangePairs(), function (entry) {
|
||||
var range = entry[0];
|
||||
var category = entry[1];
|
||||
|
||||
var actualRange = getRange(category);
|
||||
t.equal(actualRange, range, 'yielded range for ' + category + ' is as expected');
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
var semver = require('semver');
|
||||
|
||||
var getRangePairs = require('../getRangePairs');
|
||||
var getConditionsForCategory = require('../getConditionsForCategory');
|
||||
|
||||
test('getRangePairs', function (t) {
|
||||
var pairs = getRangePairs();
|
||||
t.ok(Array.isArray(pairs), 'returns an array');
|
||||
|
||||
forEach(pairs, function (entry, i) {
|
||||
t.ok(Array.isArray(entry), 'entry ' + i + ' is an array');
|
||||
|
||||
var range = entry[0];
|
||||
var category = entry[1];
|
||||
|
||||
t.ok(semver.validRange(range), i + ': item 0 is a valid semver range');
|
||||
t.doesNotThrow(
|
||||
function () { getConditionsForCategory(category); },
|
||||
i + ': item 1 is a valid category'
|
||||
);
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var test = require('tape');
|
||||
var forEach = require('for-each');
|
||||
var v = require('es-value-fixtures');
|
||||
var inspect = require('object-inspect');
|
||||
|
||||
var getRange = require('../getRange');
|
||||
var getRangePairs = require('../getRangePairs');
|
||||
var isCategory = require('../isCategory');
|
||||
|
||||
test('isCategory', function (t) {
|
||||
forEach(v.nonStrings, function (nonString) {
|
||||
t.equal(isCategory(nonString), false, inspect(nonString) + ' is not a category');
|
||||
});
|
||||
|
||||
forEach(getRangePairs(), function (pair) {
|
||||
var category = pair[1];
|
||||
|
||||
t.equal(isCategory(category), true, inspect(category) + ' is a category');
|
||||
t.doesNotThrow(function () { getRange(category); }, 'getRange does not throw for ' + inspect(category));
|
||||
});
|
||||
|
||||
t.end();
|
||||
});
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = [
|
||||
'v12.16.999',
|
||||
'v12.17.0',
|
||||
'v12.19.999',
|
||||
'v12.20.0',
|
||||
'v12.999.0',
|
||||
'v13.0.0',
|
||||
'v13.2.999',
|
||||
'v13.3.0',
|
||||
'v13.6.999',
|
||||
'v13.7.0',
|
||||
'v13.13.999',
|
||||
'v13.14.0',
|
||||
'v13.999.999',
|
||||
'v14.0.0',
|
||||
'v14.12.999',
|
||||
'v14.13.0',
|
||||
'v14.18.999',
|
||||
'v14.19.0',
|
||||
'v16.8.999',
|
||||
'v16.9.0',
|
||||
'v16.13.999',
|
||||
'v16.14.0',
|
||||
'v16.999.999',
|
||||
'v17.0.0',
|
||||
'v17.0.999',
|
||||
'v17.1.0',
|
||||
'v20.18.999',
|
||||
'v20.19.0',
|
||||
'v22.11.999',
|
||||
'v22.12.0',
|
||||
'v22.17.999',
|
||||
'v22.18.0',
|
||||
'v22.999.999',
|
||||
'v23.0.0',
|
||||
'v23.5.999',
|
||||
'v23.6.0',
|
||||
'v25.3.999',
|
||||
'v25.4.0'
|
||||
];
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "@ljharb/tsconfig",
|
||||
"exclude": [
|
||||
"coverage",
|
||||
],
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import ranges from './ranges';
|
||||
|
||||
export type Category = typeof ranges[Exclude<keyof typeof ranges, '__proto__'>];
|
||||
|
||||
export type Range = Exclude<keyof typeof ranges, '__proto__'>;
|
||||
|
||||
export type RangePair = [Range, Category];
|
||||
|
||||
export type Condition = 'node' | 'node-addons' | 'import' | 'require' | 'module-sync' | 'default';
|
||||
Reference in New Issue
Block a user