@react-consulting/rc-kit 0.13.3 → 0.14.0

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/devkit/cli.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
2
  import { resolve } from "node:path"
3
3
 
4
- import { ciOnly, sentrySourcemaps } from "./commands/build"
4
+ import { buildSha, ciOnly, sentrySourcemaps } from "./commands/build"
5
5
  import { audit, checkDeployConfig, checkNaming } from "./commands/checks"
6
6
  import type { Command } from "./commands/context"
7
7
  import { dbBranch, dbEnv, dbGuard, dbMigrate, dbSeed } from "./commands/db"
@@ -25,6 +25,7 @@ const COMMANDS: Record<string, Command> = {
25
25
  "db:guard": dbGuard,
26
26
  "db:branch": dbBranch,
27
27
  deploy,
28
+ "build:sha": buildSha,
28
29
  "ci:only": ciOnly,
29
30
  "sentry:sourcemaps": sentrySourcemaps,
30
31
  dev,
@@ -20,6 +20,19 @@ function sentryCli(root: string): string | null {
20
20
  return Bun.which("sentry-cli", { PATH: bins.join(delimiter) })
21
21
  }
22
22
 
23
+ export const buildSha: Command = {
24
+ usage: "rc build:sha",
25
+ summary:
26
+ "écrit le commit du build en JSON, pour --define d'un build Wrangler",
27
+ details:
28
+ "Écrit WORKERS_CI_COMMIT_SHA, sinon le commit git du dossier courant, en littéral JSON (null hors dépôt). Usage : wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(rc build:sha). Un build Vite lit plutôt resolveBuildCommitSha() de @react-consulting/rc-kit/build.",
29
+ cwdRoot: true,
30
+ run() {
31
+ process.stdout.write(JSON.stringify(resolveBuildCommitSha()))
32
+ return 0
33
+ },
34
+ }
35
+
23
36
  export const ciOnly: Command = {
24
37
  usage: "rc ci:only <script> [arguments…]",
25
38
  summary: "lance un script du package.json seulement dans Workers Builds",
@@ -52,6 +52,30 @@ function legacyProject(): string {
52
52
  }
53
53
 
54
54
  describe("migrateToKitPackage", () => {
55
+ test("a Wrangler build reads its commit from rc build:sha", () => {
56
+ const root = writeTree(tempDir(), {
57
+ "package.json": {
58
+ name: "contoso-api",
59
+ scripts: {
60
+ "build:cloudflare":
61
+ "wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(bun scripts/lib/build-commit-sha.ts)",
62
+ },
63
+ devDependencies: { "@rc/kit": "link:../_rc-kit" },
64
+ },
65
+ "rc.config.json": '{ "project": "contoso-api", "kit": ">=0.10.0" }\n',
66
+ })
67
+
68
+ migrateToKitPackage({ root, kitVersion: "0.13.0" })
69
+
70
+ const manifest = JSON.parse(
71
+ readFileSync(join(root, "package.json"), "utf8")
72
+ )
73
+
74
+ expect(manifest.scripts["build:cloudflare"]).toBe(
75
+ "wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(rc build:sha)"
76
+ )
77
+ })
78
+
55
79
  test("moves a project from the sibling clone to the npm package", () => {
56
80
  const root = legacyProject()
57
81
  const result = migrateToKitPackage({ root, kitVersion: "0.13.0" })
@@ -181,7 +205,7 @@ describe("migrateToKitPackage", () => {
181
205
  ".github/actions/setup/action.yml": " path: .rc-kit\n",
182
206
  ".env.example": "# secrets lus par rc op:sync\n",
183
207
  "scripts/dev/boot.ts":
184
- 'spawnSync(rc, ["op:sync"])\nconsole.warn("rc op:sync a échoué")\n',
208
+ 'spawnSync(rc, ["op:sync"])\nconsole.warn("rc op:sync a échoué")\nthrow new Error("lance `bun run op:sync`")\n',
185
209
  "vendor/other/.git": "gitdir: elsewhere\n",
186
210
  "vendor/other/b.ts": 'import "@rc/kit"\n',
187
211
  "CLAUDE.md": "bun dev # rc op:sync puis turbo\n",
@@ -226,7 +250,7 @@ describe("migrateToKitPackage", () => {
226
250
  readFileSync(join(root, "apps/api/wrangler.jsonc"), "utf8")
227
251
  ).toContain("`rc secrets:pull`")
228
252
  expect(readFileSync(join(root, "scripts/dev/boot.ts"), "utf8")).toBe(
229
- 'spawnSync(rc, ["secrets:pull"])\nconsole.warn("rc secrets:pull a échoué")\n'
253
+ 'spawnSync(rc, ["secrets:pull"])\nconsole.warn("rc secrets:pull a échoué")\nthrow new Error("lance `bun run secrets:pull`")\n'
230
254
  )
231
255
  expect(result.changes.map((change) => change.file)).not.toContain(
232
256
  ".worktrees/kit/src/a.ts"
@@ -49,6 +49,7 @@ const LEGACY_SCRIPTS = {
49
49
  const SCRIPT_REWRITES: [RegExp, string][] = [
50
50
  [/bun (?:\.\.\/)*scripts\/on-workers-ci\.ts/g, "rc ci:only"],
51
51
  [/bun (?:\.\.\/)*scripts\/upload-sourcemaps\.ts/g, "rc sentry:sourcemaps"],
52
+ [/bun (?:\.\.\/)*scripts\/(?:lib\/)?build-commit-sha\.ts/g, "rc build:sha"],
52
53
  [/\brc op:sync\b/g, "rc secrets:pull"],
53
54
  ]
54
55
  const BUILD_IMPORT_RE =
@@ -78,7 +79,7 @@ const DEPENDENCY_FIELDS = [
78
79
  const LEGACY_SECRETS_SCRIPT = "op:sync"
79
80
  const SECRETS_SCRIPT = "secrets:pull"
80
81
  const LEGACY_SECRETS_LITERAL_RE = /(["'`])op:sync\1/g
81
- const LEGACY_SECRETS_COMMAND_RE = /\brc op:sync\b/g
82
+ const LEGACY_SECRETS_COMMAND_RE = /\b(rc|run) op:sync\b/g
82
83
  const SOURCEMAPS_PROJECT_RE = /rc sentry:sourcemaps --project (\S+)/g
83
84
  const LEGACY_SENTRY_ORG_RE = /SENTRY_ORG\s*\?\?\s*["']([^"']+)["']/
84
85
 
@@ -354,7 +355,7 @@ function migrateSources(migration: Migration): void {
354
355
  .replace(LEGACY_IMPORT_RE, KIT_PACKAGE)
355
356
  .replace(BUILD_IMPORT_RE, `$1${KIT_PACKAGE}/build$1`)
356
357
  .replace(LEGACY_SECRETS_LITERAL_RE, `$1${SECRETS_SCRIPT}$1`)
357
- .replace(LEGACY_SECRETS_COMMAND_RE, `rc ${SECRETS_SCRIPT}`)
358
+ .replace(LEGACY_SECRETS_COMMAND_RE, `$1 ${SECRETS_SCRIPT}`)
358
359
 
359
360
  if (next !== text) {
360
361
  migration.write(file, next, `imports et appels vers ${KIT_PACKAGE}`)
@@ -384,7 +385,7 @@ function migrateAgentFiles(migration: Migration): void {
384
385
 
385
386
  next = next
386
387
  .replace(LEGACY_IMPORT_RE, KIT_PACKAGE)
387
- .replace(LEGACY_SECRETS_COMMAND_RE, `rc ${SECRETS_SCRIPT}`)
388
+ .replace(LEGACY_SECRETS_COMMAND_RE, `$1 ${SECRETS_SCRIPT}`)
388
389
 
389
390
  if (next !== text) {
390
391
  migration.write(file, next, `règles importées par ${RULES_IMPORT}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-consulting/rc-kit",
3
- "version": "0.13.3",
3
+ "version": "0.14.0",
4
4
  "description": "Règles, composants, CLI rc et modèle de départ pour des projets Cloudflare Workers en Bun",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -8,6 +8,6 @@
8
8
  - `anonymize` : rien d'identifiant ne part (compte, e-mail, IP, URL brute, query string, fil d'Ariane). Tags et contexte passent par liste blanche ; un projet l'étend par `allowlists`, jamais avec un identifiant.
9
9
  - Le projet garde une couche mince : `packages/shared/src/observability/server-errors.ts` (`withErrorTracking(service, handler)`, `reportServerError(error, context)`) et un `initErrorReporting({ dsn, front })` côté navigateur.
10
10
  - Variables publiques, dans les `vars` de `env.production` (vides au niveau local) : `SENTRY_DSN` (Worker), `SENTRY_TUNNEL_DSNS` (DSN de son front), `PUBLIC_SENTRY_DSN` (Astro) ou `VITE_SENTRY_DSN` (TanStack Start), injectées dans le bundle navigateur au build par `readDeployedPublicEnv` de `@react-consulting/rc-kit/build`, qui lit les `vars` de l'environnement Wrangler construit.
11
- - Release = commit du build : `resolveBuildCommitSha()` de `@react-consulting/rc-kit/build` (`WORKERS_CI_COMMIT_SHA`, sinon git) injecté en `__RC_BUILD_SHA__` (`define` Vite ou `--define` Wrangler).
11
+ - Release = commit du build : `resolveBuildCommitSha()` de `@react-consulting/rc-kit/build` (`WORKERS_CI_COMMIT_SHA`, sinon git) injecté en `__RC_BUILD_SHA__` (`define` Vite) ou `--define __RC_BUILD_SHA__:$(rc build:sha)` pour un build Wrangler ; aucun script local de commit.
12
12
  - Source maps : build en `sourcemap: "hidden"`, puis `rc sentry:sourcemaps --app <app> --directory <sortie> [--delete-maps]` à la fin de `build:cloudflare` (`--delete-maps` sur les assets publics). La commande lit `sentry` de `rc.config.json` ; dans Workers Builds elle échoue sans `SENTRY_AUTH_TOKEN` (voir `secrets.md`), en local elle saute l'envoi.
13
13
  - Alertes, membres et règles de regroupement se règlent dans Sentry, pas dans le dépôt.