Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Configure Rollup's external to support subpaths too #722

Merged
merged 1 commit into from Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/rollup.ts
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
Expand Up @@ -199,6 +199,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
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