Skip to content

Commit d27bb53

Browse files
committed
chore: format
1 parent 566d998 commit d27bb53

2 files changed

Lines changed: 36 additions & 18 deletions

File tree

packages/cli/src/pack-bin.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
import { readFileSync } from 'node:fs';
32
import module from 'node:module';
43

54
import {
@@ -23,8 +22,7 @@ import { resolveViteConfig } from './resolve-vite-config.js';
2322
* Since .d.ts files contain only type information, all imports/exports are
2423
* inherently type-only, so this transformation is always safe.
2524
*/
26-
const EXTERNAL_DTS_INTERNAL_RE =
27-
/node_modules\/(postcss|lightningcss)\/.*\.d\.(ts|mts|cts)$/;
25+
const EXTERNAL_DTS_INTERNAL_RE = /node_modules\/(postcss|lightningcss)\/.*\.d\.(ts|mts|cts)$/;
2826
// Match consumer .d.ts files that import from postcss/lightningcss.
2927
// In CI (installed from tgz): node_modules/vite-plus-core/dist/...
3028
// In local development (symlinked workspace): packages/core/dist/...

packages/test/build.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,29 +2112,38 @@ async function patchModuleAugmentations() {
21122112
let content = await readFile(file, 'utf-8');
21132113
let modified = false;
21142114

2115-
for (const [bareSpecifier, { relativePath, targetFile }] of Object.entries(augmentationMappings)) {
2115+
for (const [bareSpecifier, { relativePath, targetFile }] of Object.entries(
2116+
augmentationMappings,
2117+
)) {
21162118
const oldPattern = `declare module "${bareSpecifier}"`;
21172119

2118-
if (!content.includes(oldPattern)) continue;
2120+
if (!content.includes(oldPattern)) {
2121+
continue;
2122+
}
21192123

21202124
// Extract the augmentation block content using brace matching
21212125
const startIdx = content.indexOf(oldPattern);
21222126
const braceStart = content.indexOf('{', startIdx);
2123-
if (braceStart === -1) continue;
2127+
if (braceStart === -1) {
2128+
continue;
2129+
}
21242130

21252131
let depth = 0;
21262132
let braceEnd = -1;
21272133
for (let i = braceStart; i < content.length; i++) {
2128-
if (content[i] === '{') depth++;
2129-
else if (content[i] === '}') {
2134+
if (content[i] === '{') {
2135+
depth++;
2136+
} else if (content[i] === '}') {
21302137
depth--;
21312138
if (depth === 0) {
21322139
braceEnd = i;
21332140
break;
21342141
}
21352142
}
21362143
}
2137-
if (braceEnd === -1) continue;
2144+
if (braceEnd === -1) {
2145+
continue;
2146+
}
21382147

21392148
const innerContent = content.slice(braceStart + 1, braceEnd).trim();
21402149

@@ -2155,9 +2164,12 @@ async function patchModuleAugmentations() {
21552164
// Check both direct declarations (interface Name) and re-exports (export type { Name }).
21562165
const hasDirectDecl = new RegExp(`\\binterface\\s+${name}\\b`).test(targetContent);
21572166
const exportTypeMatch = targetContent.match(/export\s+type\s*\{([^}]*)\}/);
2158-
const isReExported = exportTypeMatch != null && new RegExp(`\\b${name}\\b`).test(exportTypeMatch[1]);
2167+
const isReExported =
2168+
exportTypeMatch != null && new RegExp(`\\b${name}\\b`).test(exportTypeMatch[1]);
21592169
if (hasDirectDecl || isReExported) {
2160-
console.log(` Skipped existing interface "${name}" (already in ${basename(targetFile)})`);
2170+
console.log(
2171+
` Skipped existing interface "${name}" (already in ${basename(targetFile)})`,
2172+
);
21612173
continue;
21622174
}
21632175

@@ -2167,16 +2179,19 @@ async function patchModuleAugmentations() {
21672179
let ifaceDepth = 0;
21682180
let ifaceBraceEnd = -1;
21692181
for (let i = ifaceBraceStart; i < innerContent.length; i++) {
2170-
if (innerContent[i] === '{') ifaceDepth++;
2171-
else if (innerContent[i] === '}') {
2182+
if (innerContent[i] === '{') {
2183+
ifaceDepth++;
2184+
} else if (innerContent[i] === '}') {
21722185
ifaceDepth--;
21732186
if (ifaceDepth === 0) {
21742187
ifaceBraceEnd = i;
21752188
break;
21762189
}
21772190
}
21782191
}
2179-
if (ifaceBraceEnd === -1) continue;
2192+
if (ifaceBraceEnd === -1) {
2193+
continue;
2194+
}
21802195

21812196
let block = innerContent.slice(ifaceStart, ifaceBraceEnd + 1).trim();
21822197
if (!block.startsWith('export')) {
@@ -2208,7 +2223,10 @@ async function patchModuleAugmentations() {
22082223
const contextDtsPath = join(distDir, '@vitest/browser/context.d.ts');
22092224
if (existsSync(contextDtsPath)) {
22102225
let content = await readFile(contextDtsPath, 'utf-8');
2211-
if (content.includes('BrowserCommands') && !content.match(/export\s+(type\s+)?\{[^}]*BrowserCommands/)) {
2226+
if (
2227+
content.includes('BrowserCommands') &&
2228+
!content.match(/export\s+(type\s+)?\{[^}]*BrowserCommands/)
2229+
) {
22122230
content += '\nexport type { BrowserCommands };\n';
22132231
await writeFile(contextDtsPath, content, 'utf-8');
22142232
console.log(' Added BrowserCommands re-export to context.d.ts');
@@ -2218,7 +2236,9 @@ async function patchModuleAugmentations() {
22182236
// Validate: ensure no duplicate top-level interface declarations were introduced by merging.
22192237
// Only count interfaces at the module scope (not nested inside declare global, namespace, etc.)
22202238
for (const [bareSpecifier, { targetFile }] of Object.entries(augmentationMappings)) {
2221-
if (!existsSync(targetFile)) continue;
2239+
if (!existsSync(targetFile)) {
2240+
continue;
2241+
}
22222242
const finalContent = await readFile(targetFile, 'utf-8');
22232243

22242244
// Extract top-level interface names by tracking brace depth
@@ -2248,8 +2268,8 @@ async function patchModuleAugmentations() {
22482268
if (count > 1) {
22492269
throw new Error(
22502270
`Interface "${name}" is declared ${count} times at top level in ${basename(targetFile)}. ` +
2251-
`Module augmentation merge for "${bareSpecifier}" likely created a duplicate ` +
2252-
`declaration that will shadow extends clauses and break type signatures.`,
2271+
`Module augmentation merge for "${bareSpecifier}" likely created a duplicate ` +
2272+
`declaration that will shadow extends clauses and break type signatures.`,
22532273
);
22542274
}
22552275
}

0 commit comments

Comments
 (0)