Skip to content

Commit

Permalink
Handle ERR_PACKAGE_PATH_NOT_EXPORTED gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
ctavan committed May 19, 2020
1 parent e18e8ae commit 9da2f9c
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
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
Empty file.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
8 changes: 8 additions & 0 deletions test/node_modules/esm-widget/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/node_modules/esm-widget/src/Widget.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
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 9da2f9c

Please sign in to comment.