list-exports
Given a path to a package.json, what specifiers does it expose?
The package export defaults an async function
. It fulfills with an object with the following keys:
-
name
the package name -
version
: the package version -
engines
: the package'sengines
requirements -
binaries
: the files that are made available as executable programs -
errors
: any validation errors encountered during parsing. Note that these errors do not necessarily interfere with the listed entry points being accessible at runtime.
In addition to the required package.json path, it also takes a second argument, an options object. This object supports the following properties:
-
level
: must be'all'
(the default), or'without conditions'
-
'all'
means "supports everything latest node supports", which includes export conditions. (note: subpath patterns are not yet supported) -
'without conditions'
means "support what node v13.2 - v13.6 support", which in the "exports" field only allows the string form or an object with the "default" property set
-
For ESM-supporting node versions (at the time of this writing, ^12.17 || >= 13.2
):
-
require
: valid specifiers to pass intorequire
-
import
: valid specifiers to pass intoimport()
, or to use in a staticimport
statement -
files
: all files on the filesystem that are directly exposed by the above entry points -
tree
: a hierarchical object structure where each directory is represented as a key containing an object, and each file is represented as a key containing a list of the entry points that expose that file
For node versions prior to ESM support (at the time of this writing, < 12.17 || ~13.0 || ~13.1
):
-
require (pre-exports)
: valid specifiers to pass intorequire
-
files (pre-exports)
: all files on the filesystem that are directly exposed by the above entry points -
tree (pre-exports)
: a hierarchical object structure where each directory is represented as a key containing an object, and each file is represented as a key containing a list of the entry points that expose that file
Example
expected.json
:
{
"name": "list-exports",
"version": "1.0.0",
"engines": {
"node": ">= 10"
},
"binaries": [],
"require": [
"list-exports",
"list-exports/package.json"
],
"import": [
"list-exports",
"list-exports/package.json"
],
"files": [
"./index.js",
"./index.mjs",
"./package.json"
],
"tree": {
"list-exports": {
"index.js": [
"list-exports"
],
"index.mjs": [
"list-exports"
],
"package.json": [
"list-exports/package.json"
]
}
},
"require (pre-exports)": [
"list-exports",
"list-exports/",
"list-exports/index",
"list-exports/index.js",
"list-exports/package",
"list-exports/package.json"
],
"files (pre-exports)": [
"./index.js",
"./index.mjs",
"./package.json"
],
"tree (pre-exports)": {
"list-exports": {
"index.js": [
"list-exports",
"list-exports/",
"list-exports/index",
"list-exports/index.js"
],
"index.mjs": [
"list-exports/index.mjs"
],
"package.json": [
"list-exports/package",
"list-exports/package.json"
]
}
},
"errors": []
}
const assert = require('assert');
const listExports = require('list-exports');
const expected = require('./expected.json');
listExports('list-exports@1').then((data) => {
assert.deepEqual(data, expected);
}).catch((e) => {
console.error(e);
process.exit(1);
});