Skip to content

Commit

Permalink
[New] add check for exports field
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 2, 2023
1 parent 98fe5ef commit f6f7920
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var existsSync = path.existsSync || fs.existsSync;
var spawn = require('child_process').spawn;

var flatMap = require('array.prototype.flatmap');
var keys = require('object-keys');
var includes = require('array-includes');

var args = process.argv.slice(2); // remove node, and script name

Expand Down Expand Up @@ -162,6 +164,23 @@ var validateModule = function validateAPIModule(t, nameOrFilePaths) {
name = nameOrFilePaths[0];
packageDir = nameOrFilePaths[1];
}

t.test('`exports` field', { skip: !('exports' in pkg) }, function (st) {
var expectedKeys = ['.', './auto', './polyfill', './implementation', './shim', './package.json'];
var keysToCheck = keys(pkg.exports).filter(function (key) {
return includes(expectedKeys, key);
});
st.deepEqual(keysToCheck, expectedKeys, 'expected entrypoints are present in the proper order');

keysToCheck.forEach(function (key) {
st.ok(fs.existsSync(pkg.exports[key]), 'entrypoint "' + key + '" points to "' + pkg.exports[key] + '" which exists');
});

st.equal(pkg.exports['./package.json'], './package.json', 'package.json is exposed');

st.end();
});

if (isMulti) {
var subPackages = requireOrEvalError(name);
if (subPackages instanceof EvalError) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
"ES2016"
],
"dependencies": {
"array-includes": "^3.1.6",
"array.prototype.flatmap": "^1.3.1",
"object-keys": "^1.1.1",
"tape": "^5.6.3"
},
"devDependencies": {
Expand Down

0 comments on commit f6f7920

Please sign in to comment.