@adamhl8/configs 4.1.0 → 4.1.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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prepareDependencyReport } from "../dep-report/dep-report.js";
|
|
2
2
|
import { resolveProjectTailwind } from "../utils.js";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { list, task } from "@adamhl8/bask";
|
|
@@ -26,16 +26,16 @@ const prepare = task(async ({ sh }) => {
|
|
|
26
26
|
await sh`oxfmt bunfig.toml`;
|
|
27
27
|
if (await canRunTofu()) await sh`tofu init -upgrade`;
|
|
28
28
|
});
|
|
29
|
-
let
|
|
29
|
+
let reportDependencyChanges;
|
|
30
30
|
const bumpDeps = task(async ({ sh }) => {
|
|
31
31
|
await sh`bunx npm-check-updates --upgrade --format group`;
|
|
32
32
|
await sh`rm -f bun.lock`;
|
|
33
33
|
await sh`rm -rf node_modules/`;
|
|
34
34
|
await sh`bun install --no-summary --no-cache`;
|
|
35
|
-
|
|
35
|
+
await reportDependencyChanges?.();
|
|
36
36
|
});
|
|
37
|
-
bumpDeps.before(() => {
|
|
38
|
-
|
|
37
|
+
bumpDeps.before(async () => {
|
|
38
|
+
if (!inCi) reportDependencyChanges = await prepareDependencyReport();
|
|
39
39
|
});
|
|
40
40
|
const test = task(async ({ sh }) => {
|
|
41
41
|
await sh`bun test --pass-with-no-tests`.echo(false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bask.base.js","names":[],"sources":["../../src/configs/bask.base.ts"],"sourcesContent":["import { existsSync } from \"node:fs\"\n\nimport { list, task } from \"@adamhl8/bask\"\nimport bun, { $, Glob } from \"bun\"\n\nimport {
|
|
1
|
+
{"version":3,"file":"bask.base.js","names":[],"sources":["../../src/configs/bask.base.ts"],"sourcesContent":["import { existsSync } from \"node:fs\"\n\nimport { list, task } from \"@adamhl8/bask\"\nimport bun, { $, Glob } from \"bun\"\n\nimport { prepareDependencyReport } from \"#dep-report/dep-report.ts\"\nimport { resolveProjectTailwind } from \"#utils.ts\"\n\nconst inCi = Boolean(process.env[\"CI\"])\n\n/** Lists tracked and untracked files matching the pathspecs, skipping gitignored ones. */\nconst lsFiles = async (pathspecs: string[]) => {\n const output = await $`git ls-files -z --cached --others --exclude-standard -- ${pathspecs}`.quiet().text()\n return output.split(\"\\0\").filter(Boolean)\n}\n\n/** Checks that we're not in CI, the repo has a root tofu module, and the aws profile exists on this machine. */\nconst canRunTofu = async () => {\n if (inCi) return false\n const tofuFiles = await Array.fromAsync(new Glob(\"*.tofu\").scan())\n if (tofuFiles.length === 0) return false\n const profiles = await $`aws configure list-profiles`.nothrow().quiet().text()\n return profiles.split(\"\\n\").includes(\"adamhl8\")\n}\n\nexport const tofuCheck = task(async ({ sh }) => {\n if (await canRunTofu()) await sh`tofu plan -detailed-exitcode -concise -compact-warnings`\n})\n\nexport const prepare = task(async ({ sh }) => {\n // Skip `lefthook install` in CI so commits made by the workflows don't run the hooks.\n if (!inCi) await sh`lefthook install`\n await sh`adamhl8-gitignore`\n await sh`adamhl8-bunfig`\n await sh`adamhl8-tsconfig`\n await sh`oxfmt bunfig.toml`\n if (await canRunTofu()) await sh`tofu init -upgrade`\n})\n\nlet reportDependencyChanges: (() => Promise<void>) | undefined\n\nexport const bumpDeps = task(async ({ sh }) => {\n await sh`bunx npm-check-updates --upgrade --format group`\n await sh`rm -f bun.lock`\n await sh`rm -rf node_modules/`\n await sh`bun install --no-summary --no-cache`\n await reportDependencyChanges?.()\n})\n\n// Register the snapshot here so it runs before a project's own `before` hooks, which can bump ranges too.\nbumpDeps.before(async () => {\n if (!inCi) reportDependencyChanges = await prepareDependencyReport()\n})\n\nexport const test = task(async ({ sh }) => {\n await sh`bun test --pass-with-no-tests`.echo(false)\n})\n\nexport const lint = task(async ({ sh }) => {\n await sh`markdown-toc -i --bullets - --maxdepth 3 ./README.md`\n await sh`oxlint --fix --fix-suggestions --fix-dangerously`\n await sh`oxfmt`\n\n if (resolveProjectTailwind()) {\n // Check for `.astro` files first so projects without them don't need tailwint installed.\n const astroFiles = await lsFiles([\":(glob)**/*.astro\"])\n // Skip `--fix` because tailwint resolves a class conflict by deleting a class by position, not by which one wins.\n if (astroFiles.length > 0) await sh`tailwint \"**/*.astro\"`\n }\n\n const tofuFiles = await lsFiles([\n \":(glob)**/*.tf\",\n \":(glob)**/*.tofu\",\n \":(glob)**/*.tfvars\",\n \":(glob)**/*.tftest.hcl\",\n \":(glob)**/*.tofutest.hcl\",\n ])\n if (tofuFiles.length > 0) await sh`tofu fmt ${tofuFiles}`\n\n await sh`tsc`\n await sh`knip-bun`\n await sh`knip-bun --production`\n if (existsSync(\".github/workflows\")) await sh`actionlint`\n await test()\n})\n\nexport const build = task(async ({ sh }) => {\n await lint()\n if (await bun.file(\"tsdown.config.ts\").exists()) await sh`tsdown`\n // Fail in CI if the build changed or created any files, because lint fixes and formatting are applied in place.\n // `--intent-to-add` makes untracked files show up in the diff.\n if (inCi) {\n await sh`git add --intent-to-add --all`\n await sh`git diff --exit-code`\n }\n await tofuCheck()\n})\n\nexport const release = task(async ({ sh }) => {\n await sh`gh workflow run release.yml`\n})\n\nexport const releaseRun = task({ hidden: true }, async ({ sh }) => {\n await sh`release-it -VV --ci`\n})\n\nexport const commitTypes = task(async ({ sh }) => {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion - trust the shape that `commitlint --print-config json` prints\n const config = (await sh`commitlint --print-config json`.echo(false).json()) as {\n rules: { \"type-enum\": [number, string, string[]] }\n }\n const { 2: types } = config.rules[\"type-enum\"]\n console.log(`Commit types:\\n ${types.join(\"\\n \")}`)\n})\n\nlist.after(async () => {\n console.log()\n await commitTypes()\n})\n"],"mappings":";;;;;;AAQA,MAAM,OAAO,QAAQ,QAAQ,IAAI,KAAK;;AAGtC,MAAM,UAAU,OAAO,cAAwB;CAE7C,QAAO,MADc,CAAC,2DAA2D,YAAY,MAAM,CA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ACA;EACA;EACA;EACA;CACF,CAAC;CACD,IAAI,UAAU,SAAS,GAAG,MAAM,EAAE,YAAY;CAE9C,MAAM,EAAE;CACR,MAAM,EAAE;CACR,MAAM,EAAE;CACR,IAAI,WAAW,mBAAmB,GAAG,MAAM,EAAE;CAC7C,MAAM,KAAK;AACb,CAAC;AAED,MAAa,QAAQ,KAAK,OAAO,EAAE,SAAS;CAC1C,MAAM,KAAK;CACX,IAAI,MAAM,IAAI,KAAK,kBAAkB,CAAC,CAAC,OAAO,GAAG,MAAM,EAAE;CAGzD,IAAI,MAAM;EACR,MAAM,EAAE;EACR,MAAM,EAAE;CACV;CACA,MAAM,UAAU;AAClB,CAAC;AAED,MAAa,UAAU,KAAK,OAAO,EAAE,SAAS;CAC5C,MAAM,EAAE;AACV,CAAC;AAED,MAAa,aAAa,KAAK,EAAE,QAAQ,KAAK,GAAG,OAAO,EAAE,SAAS;CACjE,MAAM,EAAE;AACV,CAAC;AAED,MAAa,cAAc,KAAK,OAAO,EAAE,SAAS;CAKhD,MAAM,EAAE,GAAG,WAAU,MAHC,EAAE,iCAAiC,KAAK,KAAK,CAAC,CAAC,KAAK,EAAA,CAG9C,MAAM;CAClC,QAAQ,IAAI,sBAAsB,MAAM,KAAK,QAAQ,GAAG;AAC1D,CAAC;AAED,KAAK,MAAM,YAAY;CACrB,QAAQ,IAAI;CACZ,MAAM,YAAY;AACpB,CAAC"}
|
|
@@ -39,28 +39,33 @@ const listRangeChanges = (before, after) => {
|
|
|
39
39
|
return [.../* @__PURE__ */ new Set([...before.keys(), ...after.keys()])].filter((key) => before.get(key) !== after.get(key) && !isPatchOnlyChange(before.get(key), after.get(key))).map((key) => `${key}: ${before.get(key) ?? "(none)"} -> ${after.get(key) ?? "(none)"}`);
|
|
40
40
|
};
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* Snapshots the project's dependency ranges and loads the prompt. Returns a function that asks Claude Code to research
|
|
43
|
+
* the ranges that changed since the snapshot and prints its report. That function skips the report when nothing changed
|
|
44
|
+
* or `claude` isn't installed.
|
|
44
45
|
*/
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
46
|
+
const prepareDependencyReport = async () => {
|
|
47
|
+
const rangesBefore = readDependencyRanges();
|
|
48
|
+
const instructions = await Bun.file(fileURLToPath(new URL("prompt.md", import.meta.url))).text();
|
|
49
|
+
return async () => {
|
|
50
|
+
const changes = listRangeChanges(rangesBefore, readDependencyRanges());
|
|
51
|
+
if (changes.length === 0) return;
|
|
52
|
+
if (!Bun.which("claude")) {
|
|
53
|
+
console.log("\nSkipping the dependency report because `claude` isn't installed.");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
console.log("\nAsking Claude to review the dependency changes. This takes a few minutes.");
|
|
57
|
+
const prompt = `${instructions}\n${changes.join("\n")}\n`;
|
|
58
|
+
const output = await $`claude -p ${prompt} --output-format json --permission-mode auto --disallowedTools Edit,Write,NotebookEdit --name ${"bump-deps report"}`.nothrow().quiet();
|
|
59
|
+
const parsed = output.exitCode === 0 ? output.json() : void 0;
|
|
60
|
+
if (!parsed || parsed.is_error) {
|
|
61
|
+
console.log(`\nThe dependency report failed:\n${output.stderr.toString() || output.stdout.toString()}`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
console.log(`\n${parsed.result}`);
|
|
65
|
+
const cost = parsed.total_cost_usd === void 0 ? "" : ` (cost: $${parsed.total_cost_usd.toFixed(2)})`;
|
|
66
|
+
console.log(`\nFollow up with: claude --resume ${parsed.session_id}${cost}`);
|
|
67
|
+
};
|
|
63
68
|
};
|
|
64
|
-
export {
|
|
69
|
+
export { prepareDependencyReport };
|
|
65
70
|
|
|
66
71
|
//# sourceMappingURL=dep-report.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dep-report.js","names":[],"sources":["../../src/dep-report/dep-report.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\"\nimport { fileURLToPath } from \"node:url\"\n\nimport { $ } from \"bun\"\nimport { isPlainObject } from \"es-toolkit/predicate\"\nimport { difference, findMinimumForRange, tryParseRange } from \"verkit\"\n\nconst DEPENDENCY_FIELDS = [\"dependencies\", \"devDependencies\", \"peerDependencies\", \"optionalDependencies\"] as const\n\n/** Reads every dependency range in the project's `package.json`, keyed by `<field> <name>`. */\
|
|
1
|
+
{"version":3,"file":"dep-report.js","names":[],"sources":["../../src/dep-report/dep-report.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\"\nimport { fileURLToPath } from \"node:url\"\n\nimport { $ } from \"bun\"\nimport { isPlainObject } from \"es-toolkit/predicate\"\nimport { difference, findMinimumForRange, tryParseRange } from \"verkit\"\n\nconst DEPENDENCY_FIELDS = [\"dependencies\", \"devDependencies\", \"peerDependencies\", \"optionalDependencies\"] as const\n\n/** Reads every dependency range in the project's `package.json`, keyed by `<field> <name>`. */\nconst readDependencyRanges = () => {\n const packageJson: unknown = JSON.parse(readFileSync(\"package.json\", \"utf8\"))\n const fields = isPlainObject(packageJson) ? packageJson : {}\n\n const ranges = new Map<string, string>()\n for (const field of DEPENDENCY_FIELDS) {\n const dependencies: unknown = fields[field]\n if (!isPlainObject(dependencies)) continue\n for (const [name, range] of Object.entries(dependencies))\n if (typeof range === \"string\") ranges.set(`${field} ${name}`, range)\n }\n return ranges\n}\n\n/** Returns the lowest version a range allows, or nothing for a missing or non-semver range like `workspace:*`. */\nconst lowestVersion = (range: string | undefined) => {\n const parsedRange = range === undefined ? undefined : tryParseRange(range)\n return parsedRange ? findMinimumForRange(parsedRange) : undefined\n}\n\n/** Checks whether a range change only bumps the patch version of a 1.0+ package. */\nconst isPatchOnlyChange = (oldRange: string | undefined, newRange: string | undefined) => {\n const oldVersion = lowestVersion(oldRange)\n const newVersion = lowestVersion(newRange)\n if (!oldVersion || !newVersion) return false\n // Keep 0.x patch bumps because a 0.x patch release can add features or break things.\n return oldVersion.major > 0 && difference(oldVersion, newVersion) === \"patch\"\n}\n\n/** Lists each range that changed by more than a patch as `<field> <name>: <old> -> <new>`. */\nconst listRangeChanges = (before: ReadonlyMap<string, string>, after: ReadonlyMap<string, string>) => {\n const keys = new Set([...before.keys(), ...after.keys()])\n return [...keys]\n .filter((key) => before.get(key) !== after.get(key) && !isPatchOnlyChange(before.get(key), after.get(key)))\n .map((key) => `${key}: ${before.get(key) ?? \"(none)\"} -> ${after.get(key) ?? \"(none)\"}`)\n}\n\ninterface ClaudeResult {\n is_error: boolean\n result: string\n session_id: string\n total_cost_usd?: number\n}\n\n/**\n * Snapshots the project's dependency ranges and loads the prompt. Returns a function that asks Claude Code to research\n * the ranges that changed since the snapshot and prints its report. That function skips the report when nothing changed\n * or `claude` isn't installed.\n */\nexport const prepareDependencyReport = async () => {\n const rangesBefore = readDependencyRanges()\n // Read the prompt now because the reinstall can move this package to a new folder and delete the old one.\n const instructions = await Bun.file(fileURLToPath(new URL(\"prompt.md\", import.meta.url))).text()\n\n return async () => {\n const changes = listRangeChanges(rangesBefore, readDependencyRanges())\n if (changes.length === 0) return\n if (!Bun.which(\"claude\")) {\n console.log(\"\\nSkipping the dependency report because `claude` isn't installed.\")\n return\n }\n\n console.log(\"\\nAsking Claude to review the dependency changes. This takes a few minutes.\")\n const prompt = `${instructions}\\n${changes.join(\"\\n\")}\\n`\n\n // Use `auto` because the research runs commands that an allowlist can't predict.\n // Deny the file tools because the report must not change the project.\n const output =\n await $`claude -p ${prompt} --output-format json --permission-mode auto --disallowedTools Edit,Write,NotebookEdit --name ${\"bump-deps report\"}`\n .nothrow()\n .quiet()\n\n // Report a failure without throwing because the dependencies are already bumped.\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion - trust the shape that `claude --output-format json` prints\n const parsed = output.exitCode === 0 ? (output.json() as ClaudeResult) : undefined\n if (!parsed || parsed.is_error) {\n console.log(`\\nThe dependency report failed:\\n${output.stderr.toString() || output.stdout.toString()}`)\n return\n }\n\n console.log(`\\n${parsed.result}`)\n const cost = parsed.total_cost_usd === undefined ? \"\" : ` (cost: $${parsed.total_cost_usd.toFixed(2)})`\n console.log(`\\nFollow up with: claude --resume ${parsed.session_id}${cost}`)\n }\n}\n"],"mappings":";;;;;;AAOA,MAAM,oBAAoB;CAAC;CAAgB;CAAmB;CAAoB;AAAsB;;AAGxG,MAAM,6BAA6B;CACjC,MAAM,cAAuB,KAAK,MAAM,aAAa,gBAAgB,MAAM,CAAC;CAC5E,MAAM,SAAS,cAAc,WAAW,IAAI,cAAc,CAAC;CAE3D,MAAM,yBAAS,IAAI,IAAoB;CACvC,KAAK,MAAM,SAAS,mBAAmB;EACrC,MAAM,eAAwB,OAAO;EACrC,IAAI,CAAC,cAAc,YAAY,GAAG;EAClC,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,YAAY,GACrD,IAAI,OAAO,UAAU,UAAU,OAAO,IAAI,GAAG,MAAM,GAAG,QAAQ,KAAK;CACvE;CACA,OAAO;AACT;;AAGA,MAAM,iBAAiB,UAA8B;CACnD,MAAM,cAAc,UAAU,KAAA,IAAY,KAAA,IAAY,cAAc,KAAK;CACzE,OAAO,cAAc,oBAAoB,WAAW,IAAI,KAAA;AAC1D;;AAGA,MAAM,qBAAqB,UAA8B,aAAiC;CACxF,MAAM,aAAa,cAAc,QAAQ;CACzC,MAAM,aAAa,cAAc,QAAQ;CACzC,IAAI,CAAC,cAAc,CAAC,YAAY,OAAO;CAEvC,OAAO,WAAW,QAAQ,KAAK,WAAW,YAAY,UAAU,MAAM;AACxE;;AAGA,MAAM,oBAAoB,QAAqC,UAAuC;CAEpG,OAAO,CAAC,mBAAG,IADM,IAAI,CAAC,GAAG,OAAO,KAAK,GAAG,GAAG,MAAM,KAAK,CAAC,CACzC,CAAC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