Skip to content

Commit

Permalink
fix: resolve symlinks in d.ts imports (#71)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <[email protected]>
  • Loading branch information
jrson83 and privatenumber authored Jul 19, 2024
1 parent 2b61d12 commit ef6265c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/utils/get-rollup-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const getConfig = {
options: Options,
tsconfig: TsConfigResult | null,
) => {
const dts = await import('rollup-plugin-dts');

const [dts, ts] = await Promise.all([
import('rollup-plugin-dts'),
import('typescript'),

Check warning on line 48 in src/utils/get-rollup-configs.ts

View workflow job for this annotation

GitHub Actions / Release

Maximum number of dependencies (15) exceeded
]);
return {
input: [] as string[],
preserveEntrySignatures: 'strict' as const,
Expand Down Expand Up @@ -72,7 +74,11 @@ const getConfig = {
* One concern here is that this overwrites the compilerOptions. According to
* the rollup-plugin-dts docs, it reads from baseUrl and paths.
*/
compilerOptions: { composite: false },
compilerOptions: {
composite: false,
preserveSymlinks: false,
moduleResolution: ts.default.ModuleResolutionKind.Bundler,
},
}) as Plugin,
],
output: [] as unknown as Output,
Expand Down
40 changes: 40 additions & 0 deletions tests/specs/builds/output-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,45 @@ export default testSuite(({ describe }, nodePath: string) => {
const contentTwo = await fixture.readFile('packages/two/dist/index.mjs', 'utf8');
expect(contentTwo).toMatch('export { sayHello };');
});

test('symlinks', async () => {
await using fixture = await createFixture({
...installTypeScript,
'package.json': createPackageJson({
types: './dist/index.d.ts',
peerDependencies: {
'dep-a': '*',
},
}),
'src/index.ts': `
import { fn } from 'dep-a';
export default fn({ value: 1 });
`,
node_modules: {
'dep-a/index.d.ts': ({ symlink }) => symlink('../../store/dep-a/index.d.ts'),
},
store: {
'dep-a': {
'node_modules/dep-b/index.d.ts': `
type data = {
value: number;
};
export declare function fn(a: data): data;
`,
'index.d.ts': 'export * from \'dep-b\';',
},
},
});

const pkgrollOne = await pkgroll([], {
cwd: fixture.path,
nodePath,
});
expect(pkgrollOne.stderr).toBe('');

const types = await fixture.readFile('dist/index.d.ts', 'utf8');
expect(types).toMatch('\'dep-a\'');
expect(types).toMatch('.data');
});
});
});

0 comments on commit ef6265c

Please sign in to comment.