tsdown-stale-guard 0.1.2 → 0.1.3
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.
- package/dist/cli.mjs +1 -1
- package/dist/{guard-CAD3_wn0.mjs → guard-CCIUAYhx.mjs} +35 -24
- package/dist/index.d.mts +16 -4
- package/dist/index.mjs +1 -1
- package/package.json +15 -15
package/dist/cli.mjs
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { dirname, relative, resolve } from "node:path";
|
|
3
3
|
import process from "node:process";
|
|
4
|
+
import { consoleReporter, createLogger, defineDiagnostics } from "logs-sdk";
|
|
4
5
|
import { createHash } from "node:crypto";
|
|
5
6
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
6
7
|
import { parse, stringify } from "yaml";
|
|
7
|
-
|
|
8
|
+
//#region src/diagnostics.ts
|
|
9
|
+
const diagnostics = defineDiagnostics({
|
|
10
|
+
docsBase: (code) => `https://github.com/antfu-collective/tsdown-stale-guard/blob/main/docs/errors/${code.toLowerCase()}.md`,
|
|
11
|
+
codes: {
|
|
12
|
+
TSDSG0001: {
|
|
13
|
+
message: "The `tsdownConfigResolved` hook was not called.",
|
|
14
|
+
why: "The `tsdownConfigResolved` hook is only available since `tsdown@0.21.9`. Your version of tsdown may not support it.",
|
|
15
|
+
fix: "Upgrade tsdown to `0.21.9` or later."
|
|
16
|
+
},
|
|
17
|
+
TSDSG0002: {
|
|
18
|
+
message: (p) => `Build is stale in \`${p.root}\`. ${p.changeCount} file${p.changeCount === 1 ? "" : "s"} changed since last build.`,
|
|
19
|
+
why: "Source files, config, or dependencies have changed since the last build.",
|
|
20
|
+
fix: "Run your build script (e.g. `npm run build`) or `tsdown` directly to rebuild the project."
|
|
21
|
+
},
|
|
22
|
+
TSDSG0003: {
|
|
23
|
+
message: (p) => `No build found in \`${p.root}\`. tsdown has not been run yet.`,
|
|
24
|
+
why: "The stale-guard hash file does not exist, which means `tsdown` (with the `StaleGuardRecorder` plugin) has never built this package, or its cache was cleared.",
|
|
25
|
+
fix: "Run your build script (e.g. `npm run build`) or `tsdown` directly to produce a build."
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const log = createLogger({
|
|
30
|
+
diagnostics: [diagnostics],
|
|
31
|
+
reporters: consoleReporter
|
|
32
|
+
});
|
|
33
|
+
//#endregion
|
|
8
34
|
//#region src/hash.ts
|
|
9
35
|
async function hashFile(path) {
|
|
10
36
|
const content = await readFile(path);
|
|
@@ -81,7 +107,10 @@ async function writeHashFile(path, data) {
|
|
|
81
107
|
const DEFAULT_HASH_FILE = "node_modules/.cache/tsdown-stale-guard/hash.yaml";
|
|
82
108
|
async function checkBuildState(options = {}) {
|
|
83
109
|
const root = options.root || process.cwd();
|
|
84
|
-
const data = await readHashFile(resolve(root, options.hashFile || DEFAULT_HASH_FILE))
|
|
110
|
+
const data = await readHashFile(resolve(root, options.hashFile || DEFAULT_HASH_FILE)).catch((error) => {
|
|
111
|
+
if (isEnoent(error)) log.TSDSG0003({ root }, { cause: error }).throw();
|
|
112
|
+
throw error;
|
|
113
|
+
});
|
|
85
114
|
const changes = [];
|
|
86
115
|
if (data.configs) for (const entry of data.configs) await checkEntry(entry, "config", root, changes);
|
|
87
116
|
if (data.lockfile) await checkEntry(data.lockfile, "lockfile", root, changes);
|
|
@@ -116,27 +145,9 @@ async function checkEntry(entry, category, root, changes) {
|
|
|
116
145
|
file: entry.file
|
|
117
146
|
});
|
|
118
147
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
docsBase: (code) => `https://github.com/antfu-collective/tsdown-stale-guard/blob/main/docs/errors/${code.toLowerCase()}.md`,
|
|
123
|
-
codes: {
|
|
124
|
-
TSDSG0001: {
|
|
125
|
-
message: "The `tsdownConfigResolved` hook was not called.",
|
|
126
|
-
why: "The `tsdownConfigResolved` hook is only available since `tsdown@0.21.9`. Your version of tsdown may not support it.",
|
|
127
|
-
fix: "Upgrade tsdown to `0.21.9` or later."
|
|
128
|
-
},
|
|
129
|
-
TSDSG0002: {
|
|
130
|
-
message: (p) => `Build is stale in \`${p.root}\`. ${p.changeCount} file${p.changeCount === 1 ? "" : "s"} changed since last build.`,
|
|
131
|
-
why: "Source files, config, or dependencies have changed since the last build.",
|
|
132
|
-
fix: "Run your build script (e.g. `npm run build`) or `tsdown` directly to rebuild the project."
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
const log = createLogger({
|
|
137
|
-
diagnostics: [diagnostics],
|
|
138
|
-
reporters: consoleReporter
|
|
139
|
-
});
|
|
148
|
+
function isEnoent(error) {
|
|
149
|
+
return error instanceof Error && error.code === "ENOENT";
|
|
150
|
+
}
|
|
140
151
|
//#endregion
|
|
141
152
|
//#region src/guard.ts
|
|
142
153
|
async function guardStaleBuild(options = {}) {
|
|
@@ -148,4 +159,4 @@ async function guardStaleBuild(options = {}) {
|
|
|
148
159
|
}).throw();
|
|
149
160
|
}
|
|
150
161
|
//#endregion
|
|
151
|
-
export {
|
|
162
|
+
export { serializeHashFile as a, hashFile as c, log as d, readHashFile as i, hashFiles as l, checkBuildState as n, writeHashFile as o, parseHashFile as r, computeCompositeHash as s, guardStaleBuild as t, diagnostics as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import * as _$logs_sdk0 from "logs-sdk";
|
|
2
1
|
import { TsdownPlugin } from "tsdown";
|
|
3
|
-
|
|
4
2
|
//#region src/types.d.ts
|
|
5
3
|
interface StaleGuardEntry {
|
|
6
4
|
file: string;
|
|
@@ -58,7 +56,7 @@ interface CheckOptions {
|
|
|
58
56
|
declare function checkBuildState(options?: CheckOptions): Promise<CheckResult>;
|
|
59
57
|
//#endregion
|
|
60
58
|
//#region src/diagnostics.d.ts
|
|
61
|
-
declare const diagnostics:
|
|
59
|
+
declare const diagnostics: import("logs-sdk").DiagnosticsResult<{
|
|
62
60
|
TSDSG0001: {
|
|
63
61
|
message: string;
|
|
64
62
|
why: string;
|
|
@@ -72,8 +70,15 @@ declare const diagnostics: _$logs_sdk0.DiagnosticsResult<{
|
|
|
72
70
|
why: string;
|
|
73
71
|
fix: string;
|
|
74
72
|
};
|
|
73
|
+
TSDSG0003: {
|
|
74
|
+
message: (p: {
|
|
75
|
+
root: string;
|
|
76
|
+
}) => string;
|
|
77
|
+
why: string;
|
|
78
|
+
fix: string;
|
|
79
|
+
};
|
|
75
80
|
}>;
|
|
76
|
-
declare const log:
|
|
81
|
+
declare const log: import("logs-sdk").Logger<[import("logs-sdk").DiagnosticsResult<{
|
|
77
82
|
TSDSG0001: {
|
|
78
83
|
message: string;
|
|
79
84
|
why: string;
|
|
@@ -87,6 +92,13 @@ declare const log: _$logs_sdk0.Logger<[_$logs_sdk0.DiagnosticsResult<{
|
|
|
87
92
|
why: string;
|
|
88
93
|
fix: string;
|
|
89
94
|
};
|
|
95
|
+
TSDSG0003: {
|
|
96
|
+
message: (p: {
|
|
97
|
+
root: string;
|
|
98
|
+
}) => string;
|
|
99
|
+
why: string;
|
|
100
|
+
fix: string;
|
|
101
|
+
};
|
|
90
102
|
}>]>;
|
|
91
103
|
//#endregion
|
|
92
104
|
//#region src/guard.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as serializeHashFile, c as hashFile, d as log, i as readHashFile, l as hashFiles, n as checkBuildState, o as writeHashFile, r as parseHashFile, s as computeCompositeHash, t as guardStaleBuild, u as diagnostics } from "./guard-CCIUAYhx.mjs";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { dirname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { readdir } from "node:fs/promises";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdown-stale-guard",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "Build freshness validation for tsdown",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -38,26 +38,26 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"cac": "^7.0.0",
|
|
40
40
|
"logs-sdk": "0.0.6",
|
|
41
|
-
"yaml": "^2.
|
|
41
|
+
"yaml": "^2.9.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@antfu/eslint-config": "^
|
|
45
|
-
"@antfu/ni": "^30.
|
|
44
|
+
"@antfu/eslint-config": "^9.1.0",
|
|
45
|
+
"@antfu/ni": "^30.2.0",
|
|
46
46
|
"@antfu/utils": "^9.3.0",
|
|
47
|
-
"@types/node": "^25.
|
|
47
|
+
"@types/node": "^25.9.5",
|
|
48
48
|
"bumpp": "^11.1.0",
|
|
49
|
-
"eslint": "^10.
|
|
50
|
-
"lint-staged": "^17.0.
|
|
51
|
-
"publint": "^0.3.
|
|
49
|
+
"eslint": "^10.6.0",
|
|
50
|
+
"lint-staged": "^17.0.8",
|
|
51
|
+
"publint": "^0.3.21",
|
|
52
52
|
"simple-git-hooks": "^2.13.1",
|
|
53
|
-
"skills-npm": "^1.
|
|
54
|
-
"tsdown": "^0.22.
|
|
55
|
-
"tsnapi": "^0.
|
|
56
|
-
"tsx": "^4.
|
|
53
|
+
"skills-npm": "^1.2.0",
|
|
54
|
+
"tsdown": "^0.22.4",
|
|
55
|
+
"tsnapi": "^1.0.0",
|
|
56
|
+
"tsx": "^4.23.0",
|
|
57
57
|
"typescript": "^6.0.3",
|
|
58
|
-
"unrun": "^0.3.
|
|
59
|
-
"vite": "^8.
|
|
60
|
-
"vitest": "^4.1.
|
|
58
|
+
"unrun": "^0.3.1",
|
|
59
|
+
"vite": "^8.1.3",
|
|
60
|
+
"vitest": "^4.1.10"
|
|
61
61
|
},
|
|
62
62
|
"simple-git-hooks": {
|
|
63
63
|
"pre-commit": "pnpm i --frozen-lockfile --ignore-scripts --offline && pnpm run build && npx lint-staged"
|