Skip to content

Commit

Permalink
fix: Configure Rollup's external to support subpaths too (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitdahan authored Oct 17, 2022
1 parent bb2309a commit 2f9d370
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ const getRollupConfig = async (
},
}),
].filter(Boolean),
external: [...deps, ...(options.external || [])],
external: [
// Exclude dependencies, e.g. `lodash`, `lodash/get`
...deps.map((dep) => new RegExp(`^${dep}($|\\/|\\\\)`)),
...(options.external || [])
],
},
outputConfig: {
dir: options.outDir || 'dist',
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ var input_default = foo_default;
"
`;

exports[`not bundle \`package/subpath\` in dts (resolve) 1`] = `
"import * as foo_bar from 'foo/bar';
declare const stuff: foo_bar.Foobar;
export { stuff };
"
`;

exports[`support baseUrl and paths in tsconfig.json 1`] = `
"var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
Expand Down
19 changes: 18 additions & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ test('bundle vue and ts-essentials with --dts --dts-resolve flag', async () => {
})

test('bundle @egoist/path-parser with --dts --dts-resolve flag', async () => {
const { getFileContent } = await run(
await run(
getTestName(),
{
'input.ts': `import { PathParser } from '@egoist/path-parser'
Expand All @@ -152,6 +152,23 @@ test('bundle @egoist/path-parser with --dts --dts-resolve flag', async () => {
)
})

test('not bundle `package/subpath` in dts (resolve)', async () => {
const { getFileContent } = await run(
getTestName(),
{
'package.json': `{ "dependencies": { "foo": "*" } }`,
'input.ts': `export const stuff: import('foo/bar').Foobar = { foo: 'foo', bar: 'bar' };`,
'node_modules/foo/bar.d.ts': `export type Foobar = { foo: 'foo', bar: 'bar' }`,
'node_modules/foo/package.json': `{ "name": "foo", "version": "0.0.0" }`,
},
{
flags: ['--dts', '--dts-resolve'],
}
)
const content = await getFileContent('dist/input.d.ts')
expect(content).toMatchSnapshot()
})

test('enable --dts-resolve for specific module', async () => {
const { getFileContent } = await run(getTestName(), {
'input.ts': `export * from 'vue'
Expand Down

0 comments on commit 2f9d370

Please sign in to comment.