diff --git a/src/rollup.ts b/src/rollup.ts index 658b9381f..8fe4e022e 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -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', diff --git a/test/__snapshots__/index.test.ts.snap b/test/__snapshots__/index.test.ts.snap index e60dd5d47..5f76bbf56 100644 --- a/test/__snapshots__/index.test.ts.snap +++ b/test/__snapshots__/index.test.ts.snap @@ -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; diff --git a/test/index.test.ts b/test/index.test.ts index 038ea5693..663d789e8 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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' @@ -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'