@cbartens/bkit 5.0.0 → 5.0.2

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 (72) hide show
  1. package/.bkit/README.md +12 -16
  2. package/.bkit/core/.agents/rules.md +57 -57
  3. package/.bkit/core/.bkit/README.md +11 -15
  4. package/.bkit/core/.bkit/cloud.md +22 -30
  5. package/.bkit/core/.bkit/comparison.md +36 -28
  6. package/.bkit/core/.bkit/install.md +55 -150
  7. package/.bkit/core/.bkit/jsonl.md +5 -5
  8. package/.bkit/core/.bkit/providers.md +6 -3
  9. package/.bkit/core/.bkit/templates.md +9 -7
  10. package/.bkit/core/.bkit/trackers.md +1 -1
  11. package/.bkit/core/.bkit/workflows.md +7 -3
  12. package/.bkit/core/engine/checks/after/auth.ts +16 -114
  13. package/.bkit/core/engine/checks/after/ci-yml.ts +36 -74
  14. package/.bkit/core/engine/checks/after/github.ts +1 -1
  15. package/.bkit/core/engine/checks/after/index.ts +158 -184
  16. package/.bkit/core/engine/checks/after/suppression.ts +53 -0
  17. package/.bkit/core/engine/checks/before/env.ts +5 -19
  18. package/.bkit/core/engine/checks/before/files.ts +2 -0
  19. package/.bkit/core/engine/cli.ts +4 -8
  20. package/.bkit/core/engine/commands/install/doctor.ts +9 -2
  21. package/.bkit/core/engine/commands/install/install.ts +24 -2
  22. package/.bkit/core/engine/commands/install/uninstall.ts +56 -1
  23. package/.bkit/core/engine/commands/install/upgrade.ts +14 -3
  24. package/.bkit/core/engine/commands/lib.ts +4 -3
  25. package/.bkit/core/engine/install/cloud-env.ts +4 -2
  26. package/.bkit/core/engine/install/modules/cloud.ts +3 -4
  27. package/.bkit/core/engine/install/modules/core.ts +33 -13
  28. package/.bkit/core/engine/install/modules/opencode.ts +34 -13
  29. package/.bkit/core/engine/install/payload-links.ts +150 -0
  30. package/.bkit/core/engine/install/template-copies.ts +1 -1
  31. package/.bkit/core/engine/shared/egress.ts +1 -1
  32. package/.bkit/core/workflows/bkit-debug.md +19 -12
  33. package/.bkit/shared/.bkit/.env.example +43 -36
  34. package/.bkit/shared/.claude/bkit-cloud.md +1 -1
  35. package/.bkit/shared/.cursor/bkit-cloud.md +2 -2
  36. package/.bkit/shared/.opencode/opencode.json +3 -1
  37. package/.bkit/shared/docs/deployments.md +7 -10
  38. package/.bkit/shared/docs/security.md +1 -1
  39. package/.bkit/shared/gitignore +5 -0
  40. package/.bkit/templates/.claude/hooks/bkit-cloud-bootstrap.sh +0 -5
  41. package/.bkit/templates/.cursor/Dockerfile +1 -1
  42. package/.bkit/templates/.cursor/environment.json +1 -1
  43. package/.bkit/templates/.github/renovate.json5 +0 -15
  44. package/.bkit/templates/.github/workflows/bkit-ci.yml +7 -24
  45. package/.bkit/templates/.github/workflows/bkit-cloud.yml +0 -2
  46. package/.bkit/templates/.github/workflows/bkit-renovate.yml +7 -10
  47. package/.bkit/templates/scripts/secrets/bkit-secrets.mjs +125 -12
  48. package/CHANGELOG.md +37 -0
  49. package/README.md +96 -38
  50. package/dist/checks/after/auth.js +16 -108
  51. package/dist/checks/after/ci-yml.js +30 -67
  52. package/dist/checks/after/github.js +1 -1
  53. package/dist/checks/after/index.js +138 -154
  54. package/dist/checks/after/suppression.js +39 -0
  55. package/dist/checks/before/env.js +5 -15
  56. package/dist/checks/before/files.js +2 -0
  57. package/dist/cli.js +4 -8
  58. package/dist/commands/install/doctor.js +4 -2
  59. package/dist/commands/install/install.js +16 -2
  60. package/dist/commands/install/uninstall.js +45 -1
  61. package/dist/commands/install/upgrade.js +14 -3
  62. package/dist/commands/lib.js +4 -3
  63. package/dist/install/cloud-env.js +4 -2
  64. package/dist/install/modules/cloud.js +3 -4
  65. package/dist/install/modules/core.js +33 -13
  66. package/dist/install/modules/opencode.js +34 -14
  67. package/dist/install/payload-links.js +119 -0
  68. package/dist/install/template-copies.js +1 -1
  69. package/dist/shared/egress.js +1 -1
  70. package/package.json +25 -3
  71. package/.bkit/core/engine/checks/after/vercel.ts +0 -101
  72. package/dist/checks/after/vercel.js +0 -102
@@ -1,102 +0,0 @@
1
- // checks/after/vercel.ts — the Vercel project link, env and install command auth.
2
- import * as fs from "node:fs";
3
- import * as path from "node:path";
4
- import { execFileSync } from "node:child_process";
5
- /**
6
- * Detect whether a Vercel project exists in the consumer's repo.
7
- * Heuristic: presence of vercel.json at root or under apps/<name>/.
8
- */
9
- export function detectVercelProject(cwd) {
10
- if (fs.existsSync(path.join(cwd, "vercel.json")))
11
- return true;
12
- const appsDir = path.join(cwd, "apps");
13
- if (!fs.existsSync(appsDir) || !fs.statSync(appsDir).isDirectory())
14
- return false;
15
- for (const entry of fs.readdirSync(appsDir, { withFileTypes: true })) {
16
- if (!entry.isDirectory())
17
- continue;
18
- if (fs.existsSync(path.join(appsDir, entry.name, "vercel.json")))
19
- return true;
20
- }
21
- return false;
22
- }
23
- /**
24
- * Detect whether BKIT_GH_TOKEN_INSTALL is present in a Vercel environment.
25
- *
26
- * B3 Vercel CLI hang guard: pre-checks `.vercel/project.json` and SKIPS `vercel env ls`
27
- * when the file is absent. Does NOT shell out unless the project file exists — this
28
- * avoids the CLI login prompt / TTY hang in non-interactive CI environments.
29
- *
30
- * Fallback: if detectVercelProject finds vercel.json but .vercel/project.json is absent,
31
- * the project is not yet linked to a Vercel deployment — skip CLI call.
32
- */
33
- export function detectVercelEnv(env, cwd = process.cwd()) {
34
- if (!detectVercelProject(cwd))
35
- return "unknown";
36
- // Runtime guard: reject unexpected env values even though TypeScript narrows them.
37
- if (env !== "preview" && env !== "production")
38
- return "unknown";
39
- // B3: Guard against `vercel env ls` hanging when the project is not linked.
40
- // `.vercel/project.json` is written by `vercel link` — absent means not linked.
41
- // Without this guard, `vercel env ls` blocks on a TTY login prompt in CI.
42
- const vercelProjectFile = path.join(cwd, ".vercel", "project.json");
43
- if (!fs.existsSync(vercelProjectFile))
44
- return "unknown";
45
- try {
46
- const out = execFileSync("vercel", ["env", "ls", env], {
47
- encoding: "utf-8",
48
- stdio: ["ignore", "pipe", "ignore"],
49
- timeout: 10000,
50
- });
51
- return out.includes("BKIT_GH_TOKEN_INSTALL") ? "present" : "missing";
52
- }
53
- catch {
54
- return "unknown";
55
- }
56
- }
57
- /**
58
- * Detect Vercel projects whose `vercel.json` does not authenticate to GH Packages in its
59
- * install step. Vercel runs `pnpm install` in a fresh container with no pre-install shell
60
- * hook, so the token must be written by an `installCommand` that runs
61
- * `pnpm config set "//npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL"` before install — the
62
- * registry-only project .npmrc carries no token on pnpm >=10.34.3. A vercel.json with no
63
- * installCommand (or one whose installCommand lacks that `pnpm config set`) 401s on the
64
- * @cbartens/bkit download even when BKIT_GH_TOKEN_INSTALL is present in the Vercel env.
65
- *
66
- * Uses a raw-content regex (like detectCiYmlMissingTokenEnv), not JSON.parse, so a
67
- * non-standard-but-valid vercel.json still matches.
68
- *
69
- * Returns the offending vercel.json paths (relative to cwd); empty when all authenticate.
70
- */
71
- export function detectVercelInstallCommandMissingAuth(cwd) {
72
- // `\\?["']?` tolerates the JSON-escaped (`\"//npm…`), plain-quoted, and unquoted forms
73
- // an installCommand string may take inside vercel.json.
74
- const authPattern = /pnpm\s+config\s+set\s+\\?["']?\/\/npm\.pkg\.github\.com\/:_authToken=/;
75
- const offenders = [];
76
- const check = (file) => {
77
- if (!fs.existsSync(file))
78
- return;
79
- if (!authPattern.test(fs.readFileSync(file, "utf-8")))
80
- offenders.push(path.relative(cwd, file));
81
- };
82
- check(path.join(cwd, "vercel.json"));
83
- const appsDir = path.join(cwd, "apps");
84
- if (fs.existsSync(appsDir)) {
85
- for (const entry of fs.readdirSync(appsDir, { withFileTypes: true })) {
86
- if (entry.isDirectory())
87
- check(path.join(appsDir, entry.name, "vercel.json"));
88
- }
89
- }
90
- return offenders;
91
- }
92
- export const VERCEL_MISSING_ACTION = "Add the @cbartens registry mapping to .npmrc at the repo root (the token is NOT stored here):\n\n" +
93
- " @cbartens:registry=https://npm.pkg.github.com\n\n" +
94
- "Commit this .npmrc — Vercel reads it during its build.\n\n" +
95
- "Vercel runs pnpm install in a fresh container and cannot run a pre-install shell step, so write the auth token via an installCommand in vercel.json:\n\n" +
96
- ' "installCommand": "pnpm config set //npm.pkg.github.com/:_authToken=$BKIT_GH_TOKEN_INSTALL && pnpm install"\n\n' +
97
- "Set BKIT_GH_TOKEN_INSTALL as a Vercel environment variable for each environment:\n\n" +
98
- " vercel env add BKIT_GH_TOKEN_INSTALL preview\n" +
99
- " vercel env add BKIT_GH_TOKEN_INSTALL production\n\n" +
100
- "Or via web: Vercel project → Settings → Environment Variables.\n" +
101
- "The token must be a GitHub PAT with read:packages scope (classic) or Packages: read permission (fine-grained).\n\n" +
102
- "Why the installCommand: pnpm >=10.34.3 does not authenticate a project-.npmrc ${BKIT_GH_TOKEN_INSTALL} env-substitution (it 401s on download), so the token must reach pnpm's user-level config via `pnpm config set` before install.";