Skip to content

Commit ae9d35e

Browse files
committed
feat(tools): ignore pnpm install unstable ouutput
and ignore cwd too
1 parent 83bd01e commit ae9d35e

11 files changed

Lines changed: 155 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,12 @@ jobs:
119119
- name: Build CLI
120120
run: pnpm run bootstrap-cli
121121

122+
- name: Run CLI lint
123+
run: pnpm lint
124+
122125
- name: Run CLI E2E tests
123126
run: |
124-
pnpm run --filter=@voidzero-dev/vite-plus --filter=@voidzero-dev/global test
127+
pnpm test
125128
git diff --exit-code
126129
127130
install-e2e-test:

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"install-global-cli": "npm install -g ./packages/global",
1111
"typecheck": "tsc -b tsconfig.json",
1212
"lint": "vite lint",
13-
"test": "pnpm -r test",
13+
"test": "vite test && pnpm -r snap-test",
1414
"prepare": "husky"
1515
},
1616
"devDependencies": {
@@ -22,7 +22,8 @@
2222
"lint-staged": "^16.1.6",
2323
"oxfmt": "catalog:",
2424
"oxlint": "catalog:",
25-
"typescript": "catalog:"
25+
"typescript": "catalog:",
26+
"vitest": "catalog:"
2627
},
2728
"lint-staged": {
2829
"*.@(js|ts|tsx|yml|yaml|md|json|html|toml)": [

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"scripts": {
2222
"build": "oxnode ./build.ts",
23-
"test": "snap-test"
23+
"snap-test": "snap-test"
2424
},
2525
"files": [
2626
"bin",

packages/global/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"scripts": {
2020
"build": "rolldown -c rolldown.config.ts",
21-
"test": "snap-test"
21+
"snap-test": "snap-test"
2222
},
2323
"dependencies": {
2424
"oxlint": "catalog:",
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`replaceUnstableOutput > replace unstable cwd 1`] = `"<cwd>/foo.txt"`;
4+
5+
exports[`replaceUnstableOutput > replace unstable pnpm install output 1`] = `
6+
"Scope: all <variable> workspace projects
7+
Packages: +<variable>
8+
+<repeat>
9+
Progress: resolved <variable>, reused <variable>, downloaded <variable>, added <variable>, done
10+
11+
devDependencies:
12+
+ @voidzero-dev/vite-plus <semver>
13+
+ vitest <semver>"
14+
`;
15+
16+
exports[`replaceUnstableOutput > replace unstable pnpm install output 2`] = `
17+
"Scope: all <variable> workspace projects
18+
Lockfile is up to date, resolution step is skipped
19+
Already up to date
20+
21+
╭ Warning ───────────────────────────────────────────────────────────────────────────────────╮
22+
│ │
23+
│ Ignored build scripts: esbuild. │
24+
│ Run "pnpm approve-builds" to pick which dependencies should be allowed to run scripts. │
25+
│ │
26+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
27+
28+
Done in <variable>ms using pnpm v<semver>"
29+
`;
30+
31+
exports[`replaceUnstableOutput > replace unstable semver version 1`] = `
32+
"v1.0.0
33+
v1.0.0-beta.1
34+
v1.0.0-beta.1+build.1
35+
1.0.0
36+
1.0.0-beta.1
37+
1.0.0-beta.1+build.1"
38+
`;
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { tmpdir } from 'node:os';
2+
3+
import { describe, expect, test } from 'vitest';
4+
5+
import { replaceUnstableOutput } from '../utils.ts';
6+
7+
describe('replaceUnstableOutput', () => {
8+
test('replace unstable semver version', () => {
9+
const output = `
10+
v1.0.0
11+
v1.0.0-beta.1
12+
v1.0.0-beta.1+build.1
13+
1.0.0
14+
1.0.0-beta.1
15+
1.0.0-beta.1+build.1
16+
`;
17+
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
18+
});
19+
20+
test('replace unstable pnpm install output', () => {
21+
const outputs = [
22+
`
23+
Scope: all 6 workspace projects
24+
Packages: +312
25+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26+
Progress: resolved 1, reused 0, downloaded 0, added 0
27+
Progress: resolved 316, reused 316, downloaded 0, added 315
28+
WARN  Skip adding vite to the default catalog because it already exists as npm:@voidzero-dev/vite-plus. Please use \`pnpm update\` to update the catalogs.
29+
WARN  Skip adding vitest to the default catalog because it already exists as beta. Please use \`pnpm update\` to update the catalogs.
30+
Progress: resolved 316, reused 316, downloaded 0, added 316, done
31+
32+
devDependencies:
33+
+ @voidzero-dev/vite-plus 0.0.0-8a4f4936e0eca32dd57e1a503c2b09745953344d
34+
+ vitest 3.2.4
35+
`,
36+
`
37+
Scope: all 2 workspace projects
38+
Lockfile is up to date, resolution step is skipped
39+
Already up to date
40+
41+
╭ Warning ───────────────────────────────────────────────────────────────────────────────────╮
42+
│ │
43+
│ Ignored build scripts: esbuild. │
44+
│ Run "pnpm approve-builds" to pick which dependencies should be allowed to run scripts. │
45+
│ │
46+
╰────────────────────────────────────────────────────────────────────────────────────────────╯
47+
48+
Done in 171ms using pnpm v10.16.1
49+
`,
50+
];
51+
for (const output of outputs) {
52+
expect(replaceUnstableOutput(output.trim())).toMatchSnapshot();
53+
}
54+
});
55+
56+
test('replace unstable cwd', () => {
57+
const cwd = tmpdir();
58+
const output = `${cwd}/foo.txt`;
59+
expect(replaceUnstableOutput(output.trim(), cwd)).toMatchSnapshot();
60+
});
61+
});

packages/tools/src/snap-test.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { promisify } from 'node:util';
1010

1111
const exec = promisify(cp.exec);
1212

13+
import { replaceUnstableOutput } from './utils.ts';
14+
1315
// Create a unique temporary directory for testing
1416
const tempTmpDir = `${tmpdir()}/vite-plus-test-${randomUUID()}`;
1517
fs.mkdirSync(tempTmpDir, { recursive: true });
@@ -65,19 +67,19 @@ async function runTestCase(name: string) {
6567
const { stdout, stderr } = await exec(command, { env, cwd: caseTmpDir, encoding: 'utf-8' });
6668
newSnap.push(`> ${command}`);
6769
if (stdout) {
68-
newSnap.push(replaceUnstableOutput(stdout));
70+
newSnap.push(replaceUnstableOutput(stdout, caseTmpDir));
6971
}
7072
if (stderr) {
71-
newSnap.push(replaceUnstableOutput(stderr));
73+
newSnap.push(replaceUnstableOutput(stderr, caseTmpDir));
7274
}
7375
} catch (error) {
7476
// add error exit code to the command
7577
newSnap.push(`[${error.code}]> ${command}`);
7678
if (error.stdout) {
77-
newSnap.push(replaceUnstableOutput(error.stdout));
79+
newSnap.push(replaceUnstableOutput(error.stdout, caseTmpDir));
7880
}
7981
if (error.stderr) {
80-
newSnap.push(replaceUnstableOutput(error.stderr));
82+
newSnap.push(replaceUnstableOutput(error.stderr, caseTmpDir));
8183
}
8284
}
8385
}
@@ -86,9 +88,3 @@ async function runTestCase(name: string) {
8688
await fsPromises.writeFile(`${casesDir}/${name}/snap.txt`, newSnapContent);
8789
console.log('%s finished', name);
8890
}
89-
90-
function replaceUnstableOutput(output: string) {
91-
return output.replaceAll(/\d+(?:\.\d+)?s|\d+ms/g, '<variable>ms')
92-
.replaceAll(/with \d+ rules/g, 'with <variable> rules')
93-
.replaceAll(/using \d+ threads/g, 'using <variable> threads');
94-
}

packages/tools/src/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export function replaceUnstableOutput(output: string, cwd?: string) {
2+
if (cwd) {
3+
output = output.replaceAll(cwd, '<cwd>');
4+
}
5+
return output
6+
// semver version
7+
.replaceAll(/ (v)?\d+\.\d+\.\d+(?:-.*)?/g, ' $1<semver>')
8+
// oxlint
9+
.replaceAll(/\d+(?:\.\d+)?s|\d+ms/g, '<variable>ms')
10+
.replaceAll(/with \d+ rules/g, 'with <variable> rules')
11+
.replaceAll(/using \d+ threads/g, 'using <variable> threads')
12+
// pnpm
13+
.replaceAll(/Packages: \+\d+/g, 'Packages: +<variable>')
14+
// only keep done
15+
.replaceAll(
16+
/Progress: resolved \d+, reused \d+, downloaded \d+, added \d+, done/g,
17+
'Progress: resolved <variable>, reused <variable>, downloaded <variable>, added <variable>, done',
18+
)
19+
// ignore pnpm progress
20+
.replaceAll(/Progress: resolved \d+, reused \d+, downloaded \d+, added \d+\n/g, '')
21+
// ignore pnpm warn
22+
.replaceAll(/WARN\s+Skip\s+adding .+?\n/g, '')
23+
.replaceAll(/Scope: all \d+ workspace projects/g, 'Scope: all <variable> workspace projects')
24+
.replaceAll(/\++\n/g, '+<repeat>\n');
25+
}

pnpm-lock.yaml

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

vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from '@voidzero-dev/vite-plus';
33
export default defineConfig({
44
lint: {
55
rules: {
6-
'no-console': 'error',
6+
'no-console': 'warn',
77
},
88
},
99
});

0 commit comments

Comments
 (0)