Skip to content

Commit 68e1d8b

Browse files
committed
test(e2e): verify local vite-plus install
1 parent 87ac05b commit 68e1d8b

1 file changed

Lines changed: 72 additions & 5 deletions

File tree

ecosystem-ci/verify-install.ts

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import { execFileSync } from 'node:child_process';
2+
import { readFileSync } from 'node:fs';
3+
import { mkdirSync, writeFileSync } from 'node:fs';
14
import { createRequire } from 'node:module';
5+
import path from 'node:path';
26

37
import cliPkg from '../packages/cli/package.json' with { type: 'json' };
48

@@ -7,13 +11,76 @@ const require = createRequire(`${process.cwd()}/`);
711
const expectedVersion = cliPkg.version;
812

913
try {
10-
const pkg = require('vite-plus/package.json') as { version: string; name: string };
14+
const pkgPath = require.resolve('vite-plus/package.json');
15+
const pkg = require(pkgPath) as {
16+
version: string;
17+
name: string;
18+
dependencies?: Record<string, string>;
19+
};
1120
if (pkg.version !== expectedVersion) {
12-
console.error(` vite-plus: expected version ${expectedVersion}, got ${pkg.version}`);
21+
console.error(`x vite-plus: expected version ${expectedVersion}, got ${pkg.version}`);
1322
process.exit(1);
1423
}
15-
console.log(`✓ vite-plus@${pkg.version}`);
16-
} catch {
17-
console.error('✗ vite-plus: not installed');
24+
25+
const projectPkg = JSON.parse(
26+
readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'),
27+
) as {
28+
dependencies?: Record<string, string>;
29+
devDependencies?: Record<string, string>;
30+
};
31+
const vitePlusSpec =
32+
projectPkg.dependencies?.['vite-plus'] ?? projectPkg.devDependencies?.['vite-plus'];
33+
34+
const isFileSpec = vitePlusSpec?.startsWith('file:') ?? false;
35+
const isPnpmFileInstall = `${path.sep}${pkgPath}`.includes(
36+
`${path.sep}.pnpm${path.sep}vite-plus@file+`,
37+
);
38+
if (!isFileSpec && !isPnpmFileInstall) {
39+
console.error(
40+
`x vite-plus: expected local file: install, got spec ${vitePlusSpec ?? '<missing>'}`,
41+
);
42+
console.error(` resolved to ${pkgPath}`);
43+
process.exit(1);
44+
}
45+
46+
const vitePlusRequire = createRequire(pkgPath);
47+
const oxlintPkgPath = vitePlusRequire.resolve('oxlint/package.json');
48+
const oxlintPkg = vitePlusRequire('oxlint/package.json') as { version: string };
49+
const expectedOxlint = pkg.dependencies?.oxlint?.replace(/^=/, '');
50+
if (expectedOxlint && oxlintPkg.version !== expectedOxlint) {
51+
console.error(`x oxlint: expected ${expectedOxlint}, got ${oxlintPkg.version}`);
52+
console.error(` resolved to ${oxlintPkgPath}`);
53+
process.exit(1);
54+
}
55+
56+
const oxlintBin = path.join(path.dirname(oxlintPkgPath), 'bin', 'oxlint');
57+
const probeDir = path.join(process.cwd(), '.vite-plus-local-oxlint-probe');
58+
mkdirSync(probeDir, { recursive: true });
59+
60+
const configPath = path.join(probeDir, 'vite.config.ts');
61+
const inputPath = path.join(probeDir, 'index.ts');
62+
writeFileSync(
63+
configPath,
64+
"import { defineConfig } from 'vite-plus';\n\nexport default defineConfig({ lint: {} });\n",
65+
);
66+
writeFileSync(inputPath, 'export const value = 1;\n');
67+
68+
execFileSync(process.execPath, [oxlintBin, '-c', configPath, inputPath], {
69+
cwd: probeDir,
70+
stdio: 'inherit',
71+
env: {
72+
...process.env,
73+
VP_VERSION: cliPkg.version,
74+
},
75+
});
76+
77+
console.log(`ok vite-plus@${pkg.version} (${vitePlusSpec ?? 'unknown spec'})`);
78+
console.log(`ok oxlint@${oxlintPkg.version} from vite-plus dependency tree`);
79+
console.log('ok oxlint loaded Vite+ config through local vite-plus');
80+
} catch (error) {
81+
console.error('x vite-plus: not installed or incomplete');
82+
if (error instanceof Error) {
83+
console.error(error.message);
84+
}
1885
process.exit(1);
1986
}

0 commit comments

Comments
 (0)