Skip to content

Commit

Permalink
[New] add pattern-trailers detection
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 7, 2022
1 parent cbfec0f commit b36a91e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Require or import `has-package-exports/conditional` to determine if the current

Require or import `has-package-exports/pattern` to determine if the current environment supports exports patterns (as of this writing, node v12.20+ and v14.13+).

Require or import `has-package-exports/pattern-trailers` to determine if the current environment supports exports pattern trailers (as of this writing, node v14.19+ and v16.9+).

## Tests
Simply clone the repo, `npm install`, and run `npm test`

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"./no.js"
],
"./pattern": "./pattern.js"
"./pattern": "./pattern.js",
"./pattern-trailers": "./pattern-trailers.js"
},
"scripts": {
"prepublish": "!(type safe-publish-latest 2>&1 >/dev/null) || not-in-publish || npm run prepublishOnly",
Expand Down Expand Up @@ -58,7 +59,7 @@
},
"homepage": "https://github.com/inspect-js/has-package-exports#readme",
"dependencies": {
"@ljharb/has-package-exports-patterns": "0.0.1"
"@ljharb/has-package-exports-patterns": "^0.0.2"
},
"devDependencies": {
"@ljharb/eslint-config": "^20.2.3",
Expand Down
11 changes: 11 additions & 0 deletions pattern-trailers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

var supported;
try {
/* eslint global-require: 0 */
supported = require('@ljharb/has-package-exports-patterns/pattern-trailers/pattern')
&& require('@ljharb/has-package-exports-patterns/pattern-trailers/pattern.js');
} catch (e) {
supported = false;
}
module.exports = supported;
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var semver = require('semver');
var hasPackageExports = require('has-package-exports');
var hasConditionalPackageExports = require('has-package-exports/conditional');
var hasPackageExportPatterns = require('has-package-exports/pattern');
var hasPackageExportPatternTrailers = require('has-package-exports/pattern-trailers');
// eslint-disable-next-line global-require
var spawnSync = typeof window === 'undefined' && require('child_process').spawnSync;

Expand All @@ -31,5 +32,8 @@ test('has-package-exports', function (t) {
var expectedPattern = typeof window === 'undefined' ? semver.satisfies(process.version, '^12.20.0 || >= 14.13') : null;
t.equal(hasPackageExportPatterns, expectedPattern, './pattern entrypoint exports expected value: ' + expectedPattern);

var expectedPatternTrailers = typeof window === 'undefined' ? semver.satisfies(process.version, '^14.19 || >= 16.9') : null;
t.equal(hasPackageExportPatternTrailers, expectedPatternTrailers, './pattern-trailers entrypoint exports expected value: ' + expectedPatternTrailers);

t.end();
});

0 comments on commit b36a91e

Please sign in to comment.