Skip to content

Commit e5c0779

Browse files
committed
fix(test): bundle the deps .d.ts file
1 parent 1c97751 commit e5c0779

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

packages/test/build.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { fileURLToPath } from 'node:url';
5252

5353
import { parseSync } from 'oxc-parser';
5454
import { build } from 'rolldown';
55+
import { dts } from 'rolldown-plugin-dts';
5556

5657
import pkg from './package.json' with { type: 'json' };
5758

@@ -413,6 +414,7 @@ async function bundleVitest() {
413414
.replaceAll(`import 'vite';`, `import '${CORE_PACKAGE_NAME}';`)
414415
.replaceAll(`'vite/module-runner'`, `'${CORE_PACKAGE_NAME}/module-runner'`)
415416
.replaceAll(`declare module "vite"`, `declare module "${CORE_PACKAGE_NAME}"`);
417+
console.log(`Replaced vite imports in ${destPath}`);
416418
await writeFile(destPath, content, 'utf-8');
417419
} else {
418420
await copyFile(file, destPath);
@@ -659,6 +661,36 @@ async function bundleLeafDeps(leafDeps: Set<string>): Promise<Map<string, string
659661
logLevel: 'warn',
660662
});
661663

664+
const dtsInput = { ...input };
665+
666+
for (const name of Object.keys(dtsInput)) {
667+
const vendorDtsPath = join(vendorDir, `vendor_${name}.d.ts`);
668+
dtsInput[name] = vendorDtsPath;
669+
await writeFile(vendorDtsPath, `export * from '${name}';`, 'utf-8');
670+
}
671+
672+
await build({
673+
input: dtsInput,
674+
output: {
675+
dir: vendorDir,
676+
format: 'esm',
677+
entryFileNames: '[name].mts',
678+
},
679+
plugins: [
680+
dts({
681+
dtsInput: true,
682+
oxc: true,
683+
resolve: true,
684+
emitDtsOnly: true,
685+
tsconfig: false,
686+
}),
687+
],
688+
});
689+
690+
for (const p of Object.values(dtsInput)) {
691+
await rm(p);
692+
}
693+
662694
// Register all specifiers
663695
for (const dep of leafDeps) {
664696
const safeName = safeFileName(dep);

packages/test/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@
289289
"@types/chai": "^5.2.2",
290290
"@voidzero-dev/vite-plus-core": "workspace:*",
291291
"es-module-lexer": "^1.7.0",
292-
"expect-type": "^1.2.2",
293292
"obug": "^2.1.1",
294293
"picomatch": "^4.0.3",
295294
"pixelmatch": "^7.1.0",
@@ -317,10 +316,12 @@
317316
"@vitest/utils": "4.0.16",
318317
"chai": "^6.2.1",
319318
"estree-walker": "^3.0.3",
319+
"expect-type": "^1.2.2",
320320
"magic-string": "^0.30.21",
321321
"oxc-parser": "catalog:",
322322
"pathe": "^2.0.3",
323323
"rolldown": "workspace:*",
324+
"rolldown-plugin-dts": "catalog:",
324325
"tinyrainbow": "^3.0.3",
325326
"vitest-dev": "^4.0.16",
326327
"why-is-node-running": "^2.3.0"

packages/test/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"experimentalDecorators": true,
1313
"customConditions": ["dev"]
1414
},
15+
"include": ["build.ts", "package.json"],
1516
"exclude": ["node_modules", "dist/**/*"]
1617
}

pnpm-lock.yaml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)