esm-resolve
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -76,2 +76,6 @@ /* | ||
// This is always an array, but the arg might not be. | ||
/** @type {string[]} */ | ||
#constraints; | ||
/** | ||
@@ -83,2 +87,3 @@ * @param {string} importer | ||
this.#options = Object.assign({}, defaults, options); | ||
this.#constraints = [this.#options.constraints].flat(); | ||
@@ -215,3 +220,3 @@ // Importers are actually the same for every file in a directory. Remove the last part. | ||
const matched = matchModuleNode(self.info.imports ?? {}, importee, this.#options.constraints); | ||
const matched = matchModuleNode(self.info.imports ?? {}, importee, this.#constraints); | ||
if (!matched) { | ||
@@ -245,3 +250,3 @@ return; | ||
if (pkg.info.exports) { | ||
const matched = matchModuleNode(pkg.info.exports, rest, this.#options.constraints); | ||
const matched = matchModuleNode(pkg.info.exports, rest, this.#constraints); | ||
if (matched && isLocal(matched)) { | ||
@@ -248,0 +253,0 @@ return `file://${path.join(pkg.resolved, matched)}`; |
{ | ||
"name": "esm-resolve", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Resolves ESM imports in JS", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"test": "ava", | ||
"prepublishOnly": "esbuild index.js --bundle --platform=node --target=es2015 --outfile=bundle.cjs" | ||
"prepublishOnly": "esbuild index.js --bundle --platform=node --target=node12 --outfile=bundle.cjs" | ||
}, | ||
@@ -20,0 +20,0 @@ "author": "Sam Thorogood <sam.thorogood@gmail.com>", |
@@ -17,4 +17,4 @@ [![Tests](https://github.com/samthor/esm-resolve/workflows/Tests/badge.svg)](https://github.com/samthor/esm-resolve/actions) | ||
r('./relative'); // e.g., './relative.js' | ||
r('foo-test-package-name'); // e.g., './node_modules/foo-test-package-name/index.js' | ||
r('./relative'); // './relative.js' | ||
r('foo-test-package-name'); // './node_modules/foo-test-package-name/index.js' | ||
``` | ||
@@ -32,2 +32,16 @@ | ||
You can [configure all these options](./types/external.d.ts) via the resolver's second argument. | ||
You can [configure all these options](./types/external.d.ts) via the resolver's second argument, e.g.: | ||
```js | ||
// Resolves for Node, and allows .mjs files. | ||
const r = buildResolver('./path/to/js/file.js', { | ||
constraints: 'node', | ||
matchNakedMjs: true, | ||
}); | ||
// If there's a file "foo.mjs", this will now work: | ||
r('./foo'); // './foo.mjs' | ||
// Or if we're importing package with a node constraint: | ||
r('node-only'); // './node-modules/node-only/build-for-node.js' | ||
``` |
@@ -27,3 +27,3 @@ /* | ||
*/ | ||
constraints: string[], | ||
constraints: string[] | string, | ||
@@ -72,4 +72,4 @@ /** | ||
/** | ||
* Whether to search for a match suffixed with '.mjs' when a naked resolution is found. Defaults | ||
* to false. | ||
* Whether to search for a match suffixed with '.mjs' when a naked resolution is found, without | ||
* a suffix. Defaults to false: normally, we just match '.js' files. | ||
* | ||
@@ -76,0 +76,0 @@ * @default false |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43322
884
45