Skip to content

Commit

Permalink
Handle ERR_PACKAGE_PATH_NOT_EXPORTED gracefully
Browse files Browse the repository at this point in the history
Fixes #104
Closes #108
  • Loading branch information
ctavan committed May 18, 2020
1 parent e18e8ae commit 22a941e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Expand Up @@ -50,6 +50,10 @@ function tryResolve(pkg, importer) {
return relative.resolve(pkg, importer);
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') return null;
if (err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
console.warn(`WARNING: Could not read svelte config from ${pkg}. Reason: ${err.message}`);
return null;
}
throw err;
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Expand Up @@ -33,6 +33,22 @@ describe('rollup-plugin-svelte', () => {
);
});

it('ignores esm module not exporting package.json', () => {
const { resolveId } = plugin();
assert.equal(
resolveId('esm-module-without-svelte-config', path.resolve('test/foo/main.js')),
null
);
});

it('resolves esm module exporting package.json', () => {
const { resolveId } = plugin();
assert.equal(
resolveId('esm-widget', path.resolve('test/foo/main.js')),
path.resolve('test/node_modules/esm-widget/src/Widget.html')
);
});

it('ignores virtual modules', () => {
const { resolveId } = plugin();
assert.equal(
Expand Down

0 comments on commit 22a941e

Please sign in to comment.