|
1 | | -import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' |
| 1 | +import { |
| 2 | + cp, |
| 3 | + mkdir, |
| 4 | + mkdtemp, |
| 5 | + readFile, |
| 6 | + realpath, |
| 7 | + rm, |
| 8 | + symlink, |
| 9 | + writeFile, |
| 10 | +} from 'node:fs/promises' |
2 | 11 | import os from 'node:os' |
3 | 12 | import path from 'node:path' |
4 | 13 | import { fileURLToPath } from 'node:url' |
5 | 14 | import { normalizePath, rolldownBuild } from '@sxzz/test-utils' |
6 | 15 | import { describe, expect, test, vi } from 'vitest' |
7 | | -import { dts, resolveOptions, type Generator } from '../src/index.ts' |
| 16 | +import { |
| 17 | + dts, |
| 18 | + resolveOptions, |
| 19 | + type Generator, |
| 20 | + type Options, |
| 21 | +} from '../src/index.ts' |
8 | 22 | import type { Plugin, TransformResult } from 'rolldown' |
9 | 23 |
|
10 | 24 | const dirname = path.dirname(fileURLToPath(import.meta.url)) |
@@ -95,6 +109,52 @@ describe('resolve paths', () => { |
95 | 109 | }) |
96 | 110 | }) |
97 | 111 |
|
| 112 | +test.each<[string, Options]>([ |
| 113 | + ['tsc', { generator: 'tsc', tsc: { newContext: true } }], |
| 114 | + ['tsc build', { generator: 'tsc', tsc: { build: true } }], |
| 115 | + [ |
| 116 | + 'tsgo', |
| 117 | + { |
| 118 | + generator: 'tsgo', |
| 119 | + tsgo: { moduleUrl: import.meta.resolve('typescript-next') }, |
| 120 | + }, |
| 121 | + ], |
| 122 | +])('%s: tsconfig in a symlinked directory', async (_, options) => { |
| 123 | + const dir = await realpath( |
| 124 | + await mkdtemp(path.join(os.tmpdir(), 'rolldown-plugin-dts-')), |
| 125 | + ) |
| 126 | + try { |
| 127 | + const project = path.join(dir, 'project') |
| 128 | + const alias = path.join(dir, 'alias') |
| 129 | + await mkdir(project) |
| 130 | + await writeFile( |
| 131 | + path.join(project, 'index.ts'), |
| 132 | + 'export const value: number = 1', |
| 133 | + ) |
| 134 | + // `files` must still resolve from `project`, not from the link target. |
| 135 | + await writeFile( |
| 136 | + path.join(dir, 'shared.json'), |
| 137 | + JSON.stringify({ files: ['index.ts'] }), |
| 138 | + ) |
| 139 | + await symlink( |
| 140 | + path.join(dir, 'shared.json'), |
| 141 | + path.join(project, 'tsconfig.json'), |
| 142 | + ) |
| 143 | + await symlink(project, alias, 'junction') |
| 144 | + |
| 145 | + const { snapshot } = await rolldownBuild(path.join(project, 'index.ts'), [ |
| 146 | + dts({ |
| 147 | + ...options, |
| 148 | + tsconfig: path.join(alias, 'tsconfig.json'), |
| 149 | + dtsOnly: true, |
| 150 | + }), |
| 151 | + ]) |
| 152 | + expect(snapshot).toContain('value: number') |
| 153 | + } finally { |
| 154 | + await rm(dir, { recursive: true, force: true }) |
| 155 | + } |
| 156 | +}) |
| 157 | + |
98 | 158 | // Test alias mapping based on rolldown input option |
99 | 159 | test('input alias', async () => { |
100 | 160 | const root = path.resolve(dirname, 'fixtures/alias') |
|
0 commit comments