Skip to content

Commit 5937e58

Browse files
committed
chore: update
1 parent 1f9ad44 commit 5937e58

File tree

9 files changed

+410
-358
lines changed

9 files changed

+410
-358
lines changed

packages/plugin-dts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ To enable this option, you need to:
304304
npm add @typescript/native-preview -D
305305
```
306306

307+
> `@typescript/native-preview` requires Node.js 20.6.0 or higher.
308+
307309
2. Set `experiments.tsgo` to `true`.
308310

309311
```js

packages/plugin-dts/src/tsgo.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ const generateTsgoArgs = (
5555
args.push('--emitDeclarationOnly');
5656

5757
if (isWatch) {
58-
// rebuild when watch since watch mode is proof-of-concept only currently in tsgo
58+
// TODO: Enable watch mode when tsgo's watch support is ready.
59+
// Currently, watch mode is proof-of-concept only.
5960
// args.push('--watch');
6061
}
6162

@@ -155,7 +156,7 @@ export async function emitDtsTsgo(
155156
tsgoBinFile,
156157
[
157158
...args,
158-
/* Required parameter, use it stdout have color */
159+
// Required parameter to enable colored stdout
159160
'--pretty',
160161
],
161162
{
@@ -221,7 +222,7 @@ export async function emitDtsTsgo(
221222

222223
resolve(hasErrors);
223224
} catch (error) {
224-
reject(error);
225+
reject(error instanceof Error ? error : new Error(String(error)));
225226
}
226227
});
227228
});

tests/integration/dts-tsgo/build.test.ts

Lines changed: 138 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,73 @@ import { join } from 'node:path';
44
import { describe, expect, test } from '@rstest/core';
55
import { buildAndGetResults, createTempFiles, queryContent } from 'test-helper';
66

7-
describe('dts with tsgo when build: true', () => {
8-
test('basic', async () => {
9-
const fixturePath = join(__dirname, 'build', 'basic');
10-
const { files } = await buildAndGetResults({
11-
fixturePath,
12-
type: 'dts',
13-
});
14-
15-
expect(files.esm).toMatchInlineSnapshot(`
7+
describe.skipIf(process.version.startsWith('v18'))(
8+
'dts with tsgo when build: true',
9+
() => {
10+
test('basic', async () => {
11+
const fixturePath = join(__dirname, 'build', 'basic');
12+
const { files } = await buildAndGetResults({
13+
fixturePath,
14+
type: 'dts',
15+
});
16+
17+
expect(files.esm).toMatchInlineSnapshot(`
1618
[
1719
"<ROOT>/tests/integration/dts-tsgo/build/basic/dist/esm/index.d.ts",
1820
"<ROOT>/tests/integration/dts-tsgo/build/basic/dist/esm/sum.d.ts",
1921
]
2022
`);
2123

22-
const referenceDistPath = join(
23-
fixturePath,
24-
'../__references__/dist/index.d.ts',
25-
);
26-
expect(existsSync(referenceDistPath)).toBeTruthy();
27-
28-
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
29-
expect(existsSync(buildInfoPath)).toBeTruthy();
30-
});
31-
32-
test('distPath', async () => {
33-
const fixturePath = join(__dirname, 'build', 'dist-path');
34-
const { files } = await buildAndGetResults({
35-
fixturePath,
36-
type: 'dts',
24+
const referenceDistPath = join(
25+
fixturePath,
26+
'../__references__/dist/index.d.ts',
27+
);
28+
expect(existsSync(referenceDistPath)).toBeTruthy();
29+
30+
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
31+
expect(existsSync(buildInfoPath)).toBeTruthy();
3732
});
3833

39-
expect(files.esm).toMatchInlineSnapshot(`
34+
test('distPath', async () => {
35+
const fixturePath = join(__dirname, 'build', 'dist-path');
36+
const { files } = await buildAndGetResults({
37+
fixturePath,
38+
type: 'dts',
39+
});
40+
41+
expect(files.esm).toMatchInlineSnapshot(`
4042
[
4143
"<ROOT>/tests/integration/dts-tsgo/build/dist-path/dist/custom/index.d.ts",
4244
]
4345
`);
4446

45-
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
46-
expect(existsSync(buildInfoPath)).toBeTruthy();
47-
});
47+
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
48+
expect(existsSync(buildInfoPath)).toBeTruthy();
49+
});
4850

49-
test('autoExtension: true', async () => {
50-
const fixturePath = join(__dirname, 'build', 'auto-extension');
51-
const { files } = await buildAndGetResults({ fixturePath, type: 'dts' });
51+
test('autoExtension: true', async () => {
52+
const fixturePath = join(__dirname, 'build', 'auto-extension');
53+
const { files } = await buildAndGetResults({ fixturePath, type: 'dts' });
5254

53-
expect(files.cjs).toMatchInlineSnapshot(`
55+
expect(files.cjs).toMatchInlineSnapshot(`
5456
[
5557
"<ROOT>/tests/integration/dts-tsgo/build/auto-extension/dist/types/index.d.cts",
5658
"<ROOT>/tests/integration/dts-tsgo/build/auto-extension/dist/types/sum.d.cts",
5759
]
5860
`);
5961

60-
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
61-
expect(existsSync(buildInfoPath)).toBeTruthy();
62-
});
63-
64-
test('process files - auto extension and banner / footer', async () => {
65-
const fixturePath = join(__dirname, 'build', 'process-files');
66-
const { contents } = await buildAndGetResults({
67-
fixturePath,
68-
type: 'dts',
62+
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
63+
expect(existsSync(buildInfoPath)).toBeTruthy();
6964
});
7065

71-
expect(contents.esm).toMatchInlineSnapshot(`
66+
test('process files - auto extension and banner / footer', async () => {
67+
const fixturePath = join(__dirname, 'build', 'process-files');
68+
const { contents } = await buildAndGetResults({
69+
fixturePath,
70+
type: 'dts',
71+
});
72+
73+
expect(contents.esm).toMatchInlineSnapshot(`
7274
{
7375
"<ROOT>/tests/integration/dts-tsgo/build/process-files/dist/esm/index.d.mts": "/*! hello banner dts build*/
7476
export declare const num1 = 1;
@@ -78,126 +80,135 @@ describe('dts with tsgo when build: true', () => {
7880
}
7981
`);
8082

81-
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
82-
expect(existsSync(buildInfoPath)).toBeTruthy();
83-
});
83+
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
84+
expect(existsSync(buildInfoPath)).toBeTruthy();
85+
});
8486

85-
test('abortOnError: false', async () => {
86-
const fixturePath = join(__dirname, 'build', 'abort-on-error');
87+
test('abortOnError: false', async () => {
88+
const fixturePath = join(__dirname, 'build', 'abort-on-error');
8789

88-
const result = spawnSync('npx', ['rslib', 'build'], {
89-
cwd: fixturePath,
90-
// do not show output in test console
91-
stdio: 'ignore',
92-
shell: true,
93-
});
90+
const result = spawnSync('npx', ['rslib', 'build'], {
91+
cwd: fixturePath,
92+
// do not show output in test console
93+
stdio: 'ignore',
94+
shell: true,
95+
});
9496

95-
expect(result.status).toBe(0);
97+
expect(result.status).toBe(0);
9698

97-
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
98-
expect(existsSync(buildInfoPath)).toBeTruthy();
99-
});
99+
const buildInfoPath = join(fixturePath, 'tsconfig.tsbuildinfo');
100+
expect(existsSync(buildInfoPath)).toBeTruthy();
101+
});
100102

101-
test('should clean dts dist files', async () => {
102-
const fixturePath = join(__dirname, 'build', 'clean');
103+
test('should clean dts dist files', async () => {
104+
const fixturePath = join(__dirname, 'build', 'clean');
103105

104-
const checkFiles = await createTempFiles(fixturePath, false);
106+
const checkFiles = await createTempFiles(fixturePath, false);
105107

106-
const { files } = await buildAndGetResults({ fixturePath, type: 'dts' });
108+
const { files } = await buildAndGetResults({ fixturePath, type: 'dts' });
107109

108-
for (const file of checkFiles) {
109-
expect(existsSync(file)).toBe(false);
110-
}
110+
for (const file of checkFiles) {
111+
expect(existsSync(file)).toBe(false);
112+
}
111113

112-
expect(files.esm).toMatchInlineSnapshot(`
114+
expect(files.esm).toMatchInlineSnapshot(`
113115
[
114116
"<ROOT>/tests/integration/dts-tsgo/build/clean/dist-types/esm/index.d.ts",
115117
"<ROOT>/tests/integration/dts-tsgo/build/clean/dist-types/esm/sum.d.ts",
116118
]
117119
`);
118120

119-
expect(files.cjs).toMatchInlineSnapshot(`
121+
expect(files.cjs).toMatchInlineSnapshot(`
120122
[
121123
"<ROOT>/tests/integration/dts-tsgo/build/clean/dist-types/cjs/index.d.ts",
122124
"<ROOT>/tests/integration/dts-tsgo/build/clean/dist-types/cjs/sum.d.ts",
123125
]
124126
`);
125127

126-
const referenceDistPath = join(
127-
fixturePath,
128-
'../__references__/dist/index.d.ts',
129-
);
130-
expect(existsSync(referenceDistPath)).toBeTruthy();
131-
132-
const cjsBuildInfoPath = join(fixturePath, 'tsconfig.cjs.tsbuildinfo');
133-
expect(existsSync(cjsBuildInfoPath)).toBeTruthy();
128+
const referenceDistPath = join(
129+
fixturePath,
130+
'../__references__/dist/index.d.ts',
131+
);
132+
expect(existsSync(referenceDistPath)).toBeTruthy();
134133

135-
const esmBuildInfoPath = join(fixturePath, 'tsconfig.esm.tsbuildinfo');
136-
expect(existsSync(esmBuildInfoPath)).toBeTruthy();
137-
});
134+
const cjsBuildInfoPath = join(fixturePath, 'tsconfig.cjs.tsbuildinfo');
135+
expect(existsSync(cjsBuildInfoPath)).toBeTruthy();
138136

139-
test('declarationMap', async () => {
140-
const fixturePath = join(__dirname, 'build', 'declaration-map');
141-
const { files, contents } = await buildAndGetResults({
142-
fixturePath,
143-
type: 'dts',
137+
const esmBuildInfoPath = join(fixturePath, 'tsconfig.esm.tsbuildinfo');
138+
expect(existsSync(esmBuildInfoPath)).toBeTruthy();
144139
});
145140

146-
expect(files.esm).toMatchInlineSnapshot(`
141+
test('declarationMap', async () => {
142+
const fixturePath = join(__dirname, 'build', 'declaration-map');
143+
const { files, contents } = await buildAndGetResults({
144+
fixturePath,
145+
type: 'dts',
146+
});
147+
148+
expect(files.esm).toMatchInlineSnapshot(`
147149
[
148150
"<ROOT>/tests/integration/dts-tsgo/build/declaration-map/dist/esm/index.d.ts",
149151
"<ROOT>/tests/integration/dts-tsgo/build/declaration-map/dist/esm/index.d.ts.map",
150152
]
151153
`);
152154

153-
expect(files.cjs).toMatchInlineSnapshot(`
155+
expect(files.cjs).toMatchInlineSnapshot(`
154156
[
155157
"<ROOT>/tests/integration/dts-tsgo/build/declaration-map/dist/cjs/index.d.cts",
156158
"<ROOT>/tests/integration/dts-tsgo/build/declaration-map/dist/cjs/index.d.cts.map",
157159
]
158160
`);
159161

160-
const { content: indexDtsEsm } = queryContent(contents.esm, 'index.d.ts', {
161-
basename: true,
162-
});
163-
const { content: indexDtsCjs } = queryContent(contents.cjs, 'index.d.cts', {
164-
basename: true,
162+
const { content: indexDtsEsm } = queryContent(
163+
contents.esm,
164+
'index.d.ts',
165+
{
166+
basename: true,
167+
},
168+
);
169+
const { content: indexDtsCjs } = queryContent(
170+
contents.cjs,
171+
'index.d.cts',
172+
{
173+
basename: true,
174+
},
175+
);
176+
const { content: indexMapEsm } = queryContent(
177+
contents.esm,
178+
'index.d.ts.map',
179+
{
180+
basename: true,
181+
},
182+
);
183+
const { content: indexMapCjs } = queryContent(
184+
contents.cjs,
185+
'index.d.cts.map',
186+
{
187+
basename: true,
188+
},
189+
);
190+
expect(indexDtsEsm).toContain('//# sourceMappingURL=index.d.ts.map');
191+
expect(indexDtsCjs).toContain('//# sourceMappingURL=index.d.cts.map');
192+
expect(indexMapEsm).toContain('"file":"index.d.ts"');
193+
expect(indexMapCjs).toContain('"file":"index.d.cts"');
194+
195+
const referenceEsmDistPath = join(
196+
fixturePath,
197+
'../__references__/dist/index.d.ts',
198+
);
199+
expect(existsSync(referenceEsmDistPath)).toBeTruthy();
200+
201+
// TODO: can not rename dts files in reference yet
202+
// const referenceCjsDistPath = join(
203+
// fixturePath,
204+
// '../__references__/dist/index.d.cts',
205+
// );
206+
// expect(existsSync(referenceCjsDistPath)).toBeTruthy();
207+
208+
const esmBuildInfoPath = join(fixturePath, 'tsconfig.esm.tsbuildinfo');
209+
const cjsBuildInfoPath = join(fixturePath, 'tsconfig.cjs.tsbuildinfo');
210+
expect(existsSync(esmBuildInfoPath)).toBeTruthy();
211+
expect(existsSync(cjsBuildInfoPath)).toBeTruthy();
165212
});
166-
const { content: indexMapEsm } = queryContent(
167-
contents.esm,
168-
'index.d.ts.map',
169-
{
170-
basename: true,
171-
},
172-
);
173-
const { content: indexMapCjs } = queryContent(
174-
contents.cjs,
175-
'index.d.cts.map',
176-
{
177-
basename: true,
178-
},
179-
);
180-
expect(indexDtsEsm).toContain('//# sourceMappingURL=index.d.ts.map');
181-
expect(indexDtsCjs).toContain('//# sourceMappingURL=index.d.cts.map');
182-
expect(indexMapEsm).toContain('"file":"index.d.ts"');
183-
expect(indexMapCjs).toContain('"file":"index.d.cts"');
184-
185-
const referenceEsmDistPath = join(
186-
fixturePath,
187-
'../__references__/dist/index.d.ts',
188-
);
189-
expect(existsSync(referenceEsmDistPath)).toBeTruthy();
190-
191-
// TODO: can not rename dts files in reference yet
192-
// const referenceCjsDistPath = join(
193-
// fixturePath,
194-
// '../__references__/dist/index.d.cts',
195-
// );
196-
// expect(existsSync(referenceCjsDistPath)).toBeTruthy();
197-
198-
const esmBuildInfoPath = join(fixturePath, 'tsconfig.esm.tsbuildinfo');
199-
const cjsBuildInfoPath = join(fixturePath, 'tsconfig.cjs.tsbuildinfo');
200-
expect(existsSync(esmBuildInfoPath)).toBeTruthy();
201-
expect(existsSync(cjsBuildInfoPath)).toBeTruthy();
202-
});
203-
});
213+
},
214+
);

0 commit comments

Comments
 (0)