wireit-cache-validate 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +10 -10
  2. package/src/index.mjs +36 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wireit-cache-validate",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "Validate if Wireit script is fully cached with subsequent runs.",
5
5
  "bin": {
6
6
  "wireit-cache-validate": "./src/index.mjs"
@@ -11,12 +11,6 @@
11
11
  "./README.md",
12
12
  "./LICENSE"
13
13
  ],
14
- "scripts": {
15
- "cache": "wireit",
16
- "cache:validate": "npm run cache && ./src/index.mjs npm run cache",
17
- "nocache": "wireit",
18
- "nocache:validate": "node ./src/test.mjs && ./src/index.mjs npm run nocache"
19
- },
20
14
  "keywords": [
21
15
  "wireit"
22
16
  ],
@@ -43,7 +37,13 @@
43
37
  }
44
38
  },
45
39
  "devDependencies": {
46
- "wireit": "^0.14.9"
40
+ "wireit": "^0.14.12"
41
+ },
42
+ "scripts": {
43
+ "test": "node --test test/**/*.test.mjs",
44
+ "cache": "wireit",
45
+ "cache:validate": "pnpm cache && ./src/index.mjs pnpm cache",
46
+ "nocache": "wireit",
47
+ "nocache:validate": "node ./src/test.mjs && ./src/index.mjs pnpm nocache"
47
48
  }
48
- }
49
-
49
+ }
package/src/index.mjs CHANGED
@@ -1,40 +1,62 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { exec } from 'child_process';
4
- import { readFileSync, rmSync } from 'fs';
4
+ import { readFileSync, rmSync, existsSync } from 'fs';
5
5
 
6
- const command = `WIREIT_DEBUG_LOG_FILE=.wireit-cache-validate WIREIT_LOGGER=metrics ${process.argv.slice(2).join(' ')}`;
6
+ const args = process.argv.slice(2).join(' ');
7
+ const logFile = '.wireit-cache-validate';
7
8
 
8
- function asyncChildProcess(child, options = { log: true }) {
9
+ function asyncChildProcess(child) {
9
10
  return new Promise((resolve, reject) => {
10
- child.addListener("error", reject);
11
- child.addListener("exit", resolve);
12
- if (options.log) {
13
- child.stdout.on('data', (data) => console.log(data.toString()));
14
- }
11
+ let stderr = '';
12
+ child.addListener("error", reject);
13
+ child.stderr.on('data', (data) => { stderr += data.toString(); });
14
+ child.addListener("exit", (code) => resolve({ code, stderr }));
15
15
  });
16
16
  }
17
17
 
18
- await asyncChildProcess(exec(command), { log: false });
18
+ const { code, stderr } = await asyncChildProcess(
19
+ exec(args, {
20
+ env: { ...process.env, WIREIT_DEBUG_LOG_FILE: logFile, WIREIT_LOGGER: 'metrics' }
21
+ })
22
+ );
23
+
24
+ if (code !== 0) {
25
+ console.error(`🚫 Command failed with exit code ${code}.`);
26
+ if (stderr) {
27
+ console.error(stderr);
28
+ }
29
+ process.exit(1);
30
+ }
31
+
32
+ if (!existsSync(logFile)) {
33
+ console.error('🚫 Cache validation log not found. Did the wireit command run successfully?');
34
+ process.exit(1);
35
+ }
19
36
 
20
- const log = readFileSync('.wireit-cache-validate', 'utf8').toString();
37
+ const log = readFileSync(logFile, 'utf8');
21
38
 
22
- if (log.includes('error') || log.includes('fail')) {
39
+ if (log.includes('<error>') || log.includes('<failure>')) {
23
40
  console.error('🚫 Cache validation failed. Verify all scripts pass without failure.');
24
41
  console.error(log);
25
42
  process.exit(1);
26
43
  }
27
44
 
45
+ // Statuses indicating a task was skipped or completed without needing re-execution.
46
+ // 'fresh': wireit determined the task fingerprint (inputs) is unchanged, no re-run needed.
47
+ // 'cached': wireit restored outputs from cache.
28
48
  const passingStatuses = ['analysis-started', 'analysis-completed', 'fresh', 'no-command', 'cached', 'exit-zero'];
29
49
 
30
- const statuses = log.split('\n').filter(line => line.includes('<success>') || line.includes('<info>')).map(line => line.split('> ')[1]).map(line => line.trim());
50
+ const statusLines = log.split('\n').filter(line => line.includes('<success>') || line.includes('<info>'));
51
+ const statuses = statusLines.map(line => line.split('> ')[1]).map(s => s.trim());
31
52
  const cacheFailures = statuses.filter(status => !passingStatuses.includes(status));
32
- const failedTasks = log.split('\n').filter(line => line.includes('🏃')).map(log => log.replace('🏃', '').trim())
53
+ const failedTasks = log.split('\n').filter(line => line.includes('🏃')).map(l => l.replace('🏃', '').trim());
54
+
33
55
  if (cacheFailures.length) {
34
56
  console.error(failedTasks.join('\n'));
35
57
  console.error('🚫 Cache validation failed. Check .wireit-cache-validate log to verify all scripts are cached correctly.\nhttps://github.com/google/wireit?tab=readme-ov-file#caching');
36
58
  process.exit(1);
37
59
  } else {
38
60
  console.log('✅ Cache validation passed.');
39
- rmSync('.wireit-cache-validate', { force: true });
61
+ rmSync(logFile, { force: true });
40
62
  }