Skip to content

Commit 8d3dcad

Browse files
committed
chore: use vite-plus to eat dog food
1 parent 1c1bf07 commit 8d3dcad

19 files changed

Lines changed: 2566 additions & 1291 deletions

.github/workflows/test.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,30 @@ jobs:
6868
steps:
6969
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
7070

71-
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
72-
7371
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
7472
with:
7573
node-version: '22'
76-
cache: 'pnpm'
7774

78-
- name: Install dependencies
79-
run: pnpm install
75+
- name: Setup Vite+ with cache
76+
uses: ./
77+
id: setup
78+
with:
79+
registry: github
80+
github-token: ${{ secrets.VP_TOKEN }}
81+
cache: true
8082

8183
- name: Type check
82-
run: pnpm run typecheck
84+
run: vite run typecheck
85+
86+
- name: Format check
87+
run: vite run fmt:check
8388

8489
- name: Unit tests
85-
run: pnpm test
90+
run: vite run test
8691

8792
- name: Build
88-
run: pnpm run build
93+
run: vite run build
8994

9095
- name: Verify dist is up to date
9196
run: |
92-
git diff --exit-code dist/ || (echo "dist/ is out of date. Run 'pnpm run build' and commit." && exit 1)
97+
git diff --exit-code dist/ || (echo "dist/ is out of date. Run 'vite run build' and commit." && exit 1)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ jobs:
143143
cache: true
144144
run-install: true
145145
146-
- run: vite build
146+
- run: vite run build
147147
148-
- run: vite test
148+
- run: vite run test
149149
```
150150

151151
## License

dist/index.mjs

Lines changed: 21 additions & 21 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
"type": "module",
66
"packageManager": "pnpm@10.28.0",
77
"scripts": {
8-
"build": "tsdown",
8+
"lint": "vite lint",
9+
"lint:fix": "vite lint --fix",
10+
"build": "vite lib",
911
"typecheck": "tsc --noEmit",
10-
"test": "vitest run",
11-
"test:watch": "vitest"
12+
"test": "vite test run",
13+
"test:watch": "vite test -w",
14+
"fmt": "vite fmt",
15+
"fmt:check": "vite fmt --check"
1216
},
1317
"dependencies": {
1418
"@actions/cache": "^4.0.0",
@@ -20,8 +24,7 @@
2024
},
2125
"devDependencies": {
2226
"@types/node": "^22.0.0",
23-
"tsdown": "latest",
24-
"typescript": "^5.7.0",
25-
"vitest": "^4.0.17"
27+
"@voidzero-dev/vite-plus": "latest",
28+
"typescript": "^5.7.0"
2629
}
2730
}

pnpm-lock.yaml

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

src/cache-restore.ts

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,62 @@
1-
import { restoreCache as restoreCacheAction } from '@actions/cache'
2-
import { hashFiles } from '@actions/glob'
3-
import { warning, info, debug, saveState, setOutput } from '@actions/core'
4-
import { arch, platform } from 'node:os'
5-
import type { Inputs } from './types.js'
6-
import { State, Outputs } from './types.js'
7-
import { detectLockFile, getCacheDirectories } from './utils.js'
1+
import { restoreCache as restoreCacheAction } from "@actions/cache";
2+
import { hashFiles } from "@actions/glob";
3+
import { warning, info, debug, saveState, setOutput } from "@actions/core";
4+
import { arch, platform } from "node:os";
5+
import type { Inputs } from "./types.js";
6+
import { State, Outputs } from "./types.js";
7+
import { detectLockFile, getCacheDirectories } from "./utils.js";
88

99
export async function restoreCache(inputs: Inputs): Promise<void> {
1010
// Detect lock file
11-
const lockFile = detectLockFile(inputs.cacheDependencyPath)
11+
const lockFile = detectLockFile(inputs.cacheDependencyPath);
1212
if (!lockFile) {
13-
warning('No lock file found. Skipping cache restore.')
14-
setOutput(Outputs.CacheHit, false)
15-
return
13+
warning("No lock file found. Skipping cache restore.");
14+
setOutput(Outputs.CacheHit, false);
15+
return;
1616
}
1717

18-
info(`Using lock file: ${lockFile.path}`)
18+
info(`Using lock file: ${lockFile.path}`);
1919

2020
// Get cache directories based on lock file type
21-
const cachePaths = await getCacheDirectories(lockFile.type)
21+
const cachePaths = await getCacheDirectories(lockFile.type);
2222
if (!cachePaths.length) {
23-
warning('No cache directories found. Skipping cache restore.')
24-
setOutput(Outputs.CacheHit, false)
25-
return
23+
warning("No cache directories found. Skipping cache restore.");
24+
setOutput(Outputs.CacheHit, false);
25+
return;
2626
}
2727

28-
debug(`Cache paths: ${cachePaths.join(', ')}`)
29-
saveState(State.CachePaths, JSON.stringify(cachePaths))
28+
debug(`Cache paths: ${cachePaths.join(", ")}`);
29+
saveState(State.CachePaths, JSON.stringify(cachePaths));
3030

3131
// Generate cache key: vite-plus-{platform}-{arch}-{lockfile-type}-{hash}
32-
const runnerOS = process.env.RUNNER_OS || platform()
33-
const runnerArch = arch()
34-
const fileHash = await hashFiles(lockFile.path)
32+
const runnerOS = process.env.RUNNER_OS || platform();
33+
const runnerArch = arch();
34+
const fileHash = await hashFiles(lockFile.path);
3535

3636
if (!fileHash) {
37-
throw new Error(`Failed to generate hash for lock file: ${lockFile.path}`)
37+
throw new Error(`Failed to generate hash for lock file: ${lockFile.path}`);
3838
}
3939

40-
const primaryKey = `vite-plus-${runnerOS}-${runnerArch}-${lockFile.type}-${fileHash}`
40+
const primaryKey = `vite-plus-${runnerOS}-${runnerArch}-${lockFile.type}-${fileHash}`;
4141
const restoreKeys = [
4242
`vite-plus-${runnerOS}-${runnerArch}-${lockFile.type}-`,
4343
`vite-plus-${runnerOS}-${runnerArch}-`,
44-
]
44+
];
4545

46-
debug(`Primary key: ${primaryKey}`)
47-
debug(`Restore keys: ${restoreKeys.join(', ')}`)
46+
debug(`Primary key: ${primaryKey}`);
47+
debug(`Restore keys: ${restoreKeys.join(", ")}`);
4848

49-
saveState(State.CachePrimaryKey, primaryKey)
49+
saveState(State.CachePrimaryKey, primaryKey);
5050

5151
// Attempt to restore cache
52-
const matchedKey = await restoreCacheAction(
53-
cachePaths,
54-
primaryKey,
55-
restoreKeys
56-
)
52+
const matchedKey = await restoreCacheAction(cachePaths, primaryKey, restoreKeys);
5753

5854
if (matchedKey) {
59-
info(`Cache restored from key: ${matchedKey}`)
60-
saveState(State.CacheMatchedKey, matchedKey)
61-
setOutput(Outputs.CacheHit, true)
55+
info(`Cache restored from key: ${matchedKey}`);
56+
saveState(State.CacheMatchedKey, matchedKey);
57+
setOutput(Outputs.CacheHit, true);
6258
} else {
63-
info('Cache not found')
64-
setOutput(Outputs.CacheHit, false)
59+
info("Cache not found");
60+
setOutput(Outputs.CacheHit, false);
6561
}
6662
}

src/cache-save.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import { saveCache as saveCacheAction } from '@actions/cache'
2-
import { getState, info, warning } from '@actions/core'
3-
import { State } from './types.js'
1+
import { saveCache as saveCacheAction } from "@actions/cache";
2+
import { getState, info, warning } from "@actions/core";
3+
import { State } from "./types.js";
44

55
export async function saveCache(): Promise<void> {
6-
const primaryKey = getState(State.CachePrimaryKey)
7-
const matchedKey = getState(State.CacheMatchedKey)
8-
const cachePathsJson = getState(State.CachePaths)
6+
const primaryKey = getState(State.CachePrimaryKey);
7+
const matchedKey = getState(State.CacheMatchedKey);
8+
const cachePathsJson = getState(State.CachePaths);
99

1010
if (!primaryKey) {
11-
info('No cache key found. Skipping cache save.')
12-
return
11+
info("No cache key found. Skipping cache save.");
12+
return;
1313
}
1414

1515
if (!cachePathsJson) {
16-
info('No cache paths found. Skipping cache save.')
17-
return
16+
info("No cache paths found. Skipping cache save.");
17+
return;
1818
}
1919

2020
// Skip if cache hit on primary key (no changes)
2121
if (primaryKey === matchedKey) {
22-
info(`Cache hit on primary key "${primaryKey}". Skipping save.`)
23-
return
22+
info(`Cache hit on primary key "${primaryKey}". Skipping save.`);
23+
return;
2424
}
2525

26-
const cachePaths: string[] = JSON.parse(cachePathsJson) as string[]
26+
const cachePaths: string[] = JSON.parse(cachePathsJson) as string[];
2727

2828
if (!cachePaths.length) {
29-
info('Empty cache paths. Skipping cache save.')
30-
return
29+
info("Empty cache paths. Skipping cache save.");
30+
return;
3131
}
3232

3333
try {
34-
const cacheId = await saveCacheAction(cachePaths, primaryKey)
34+
const cacheId = await saveCacheAction(cachePaths, primaryKey);
3535
if (cacheId === -1) {
36-
warning('Cache save failed or was skipped.')
37-
return
36+
warning("Cache save failed or was skipped.");
37+
return;
3838
}
39-
info(`Cache saved with key: ${primaryKey}`)
39+
info(`Cache saved with key: ${primaryKey}`);
4040
} catch (error) {
4141
// Don't fail the action if cache save fails
42-
warning(`Failed to save cache: ${error}`)
42+
warning(`Failed to save cache: ${error}`);
4343
}
4444
}

src/index.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
import { saveState, getState, setFailed } from '@actions/core'
2-
import { getInputs } from './inputs.js'
3-
import { installVitePlus } from './install-viteplus.js'
4-
import { runViteInstall } from './run-install.js'
5-
import { restoreCache } from './cache-restore.js'
6-
import { saveCache } from './cache-save.js'
7-
import { State } from './types.js'
8-
import type { Inputs } from './types.js'
1+
import { saveState, getState, setFailed } from "@actions/core";
2+
import { getInputs } from "./inputs.js";
3+
import { installVitePlus } from "./install-viteplus.js";
4+
import { runViteInstall } from "./run-install.js";
5+
import { restoreCache } from "./cache-restore.js";
6+
import { saveCache } from "./cache-save.js";
7+
import { State } from "./types.js";
8+
import type { Inputs } from "./types.js";
99

1010
async function runMain(inputs: Inputs): Promise<void> {
1111
// Mark that post action should run
12-
saveState(State.IsPost, 'true')
12+
saveState(State.IsPost, "true");
1313

1414
// Step 1: Install @voidzero-dev/global
15-
await installVitePlus(inputs)
15+
await installVitePlus(inputs);
1616

1717
// Step 2: Restore cache if enabled
1818
if (inputs.cache) {
19-
await restoreCache(inputs)
19+
await restoreCache(inputs);
2020
}
2121

2222
// Step 3: Run vite install if requested
2323
if (inputs.runInstall.length > 0) {
24-
await runViteInstall(inputs)
24+
await runViteInstall(inputs);
2525
}
2626
}
2727

2828
async function runPost(inputs: Inputs): Promise<void> {
2929
// Save cache if enabled
3030
if (inputs.cache) {
31-
await saveCache()
31+
await saveCache();
3232
}
3333
}
3434

3535
async function main(): Promise<void> {
36-
const inputs = getInputs()
36+
const inputs = getInputs();
3737

38-
if (getState(State.IsPost) === 'true') {
39-
await runPost(inputs)
38+
if (getState(State.IsPost) === "true") {
39+
await runPost(inputs);
4040
} else {
41-
await runMain(inputs)
41+
await runMain(inputs);
4242
}
4343
}
4444

45-
main().catch(error => {
46-
console.error(error)
47-
setFailed(error instanceof Error ? error.message : String(error))
48-
})
45+
main().catch((error) => {
46+
console.error(error);
47+
setFailed(error instanceof Error ? error.message : String(error));
48+
});

0 commit comments

Comments
 (0)