@react-consulting/rc-kit 0.13.4 → 0.14.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.
- package/devkit/cli.ts +2 -1
- package/devkit/commands/build.ts +13 -0
- package/devkit/lib/kit-migrate.test.ts +53 -0
- package/devkit/lib/kit-migrate.ts +22 -3
- package/package.json +1 -1
- package/rules/observability.md +1 -1
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,
|
package/devkit/commands/build.ts
CHANGED
|
@@ -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,59 @@ function legacyProject(): string {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
describe("migrateToKitPackage", () => {
|
|
55
|
+
test("an app outside the workspaces is migrated without its own kit dependency", () => {
|
|
56
|
+
const root = writeTree(tempDir(), {
|
|
57
|
+
"package.json": {
|
|
58
|
+
name: "contoso-books",
|
|
59
|
+
devDependencies: { "@rc/kit": "link:../_rc-kit" },
|
|
60
|
+
},
|
|
61
|
+
"workers/jobs/package.json": {
|
|
62
|
+
name: "contoso-jobs",
|
|
63
|
+
scripts: {
|
|
64
|
+
"build:cloudflare":
|
|
65
|
+
"wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(bun ../../scripts/build-commit-sha.ts) && bun ../../scripts/upload-sourcemaps.ts --app jobs --directory dist",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
"rc.config.json":
|
|
69
|
+
'{ "project": "contoso-books", "kit": ">=0.10.0", "apps": { "web": { "path": "." }, "jobs": { "path": "workers/jobs" } } }\n',
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
migrateToKitPackage({ root, kitVersion: "0.13.0" })
|
|
73
|
+
|
|
74
|
+
const jobs = JSON.parse(
|
|
75
|
+
readFileSync(join(root, "workers/jobs/package.json"), "utf8")
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
expect(jobs.scripts["build:cloudflare"]).toBe(
|
|
79
|
+
"wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(rc build:sha) && rc sentry:sourcemaps --app jobs --directory dist"
|
|
80
|
+
)
|
|
81
|
+
expect(jobs.devDependencies).toBeUndefined()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test("a Wrangler build reads its commit from rc build:sha", () => {
|
|
85
|
+
const root = writeTree(tempDir(), {
|
|
86
|
+
"package.json": {
|
|
87
|
+
name: "contoso-api",
|
|
88
|
+
scripts: {
|
|
89
|
+
"build:cloudflare":
|
|
90
|
+
"wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(bun scripts/lib/build-commit-sha.ts)",
|
|
91
|
+
},
|
|
92
|
+
devDependencies: { "@rc/kit": "link:../_rc-kit" },
|
|
93
|
+
},
|
|
94
|
+
"rc.config.json": '{ "project": "contoso-api", "kit": ">=0.10.0" }\n',
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
migrateToKitPackage({ root, kitVersion: "0.13.0" })
|
|
98
|
+
|
|
99
|
+
const manifest = JSON.parse(
|
|
100
|
+
readFileSync(join(root, "package.json"), "utf8")
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
expect(manifest.scripts["build:cloudflare"]).toBe(
|
|
104
|
+
"wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(rc build:sha)"
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
|
|
55
108
|
test("moves a project from the sibling clone to the npm package", () => {
|
|
56
109
|
const root = legacyProject()
|
|
57
110
|
const result = migrateToKitPackage({ root, kitVersion: "0.13.0" })
|
|
@@ -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 =
|
|
@@ -307,10 +308,28 @@ function appsByPath(root: string): Map<string, string> {
|
|
|
307
308
|
)
|
|
308
309
|
}
|
|
309
310
|
|
|
311
|
+
type ManifestDir = { dir: string; rel: string; installed: boolean }
|
|
312
|
+
|
|
313
|
+
// An app of rc.config.json outside the workspaces (a second Worker of a single-package project) runs from the root's install.
|
|
314
|
+
function manifestDirs(root: string): ManifestDir[] {
|
|
315
|
+
const workspaces = listWorkspaces(root).map((workspace) => ({
|
|
316
|
+
dir: workspace.dir,
|
|
317
|
+
rel: workspace.rel,
|
|
318
|
+
installed: true,
|
|
319
|
+
}))
|
|
320
|
+
const known = new Set(workspaces.map((workspace) => workspace.rel))
|
|
321
|
+
const outsideApps = [...appsByPath(root).keys()]
|
|
322
|
+
.filter((rel) => !known.has(rel) && rel !== "")
|
|
323
|
+
.map((rel) => ({ dir: join(root, rel), rel, installed: false }))
|
|
324
|
+
.filter((app) => existsSync(join(app.dir, "package.json")))
|
|
325
|
+
|
|
326
|
+
return [...workspaces, ...outsideApps]
|
|
327
|
+
}
|
|
328
|
+
|
|
310
329
|
function migrateManifests(migration: Migration, spec: string): void {
|
|
311
330
|
const apps = appsByPath(migration.root)
|
|
312
331
|
|
|
313
|
-
for (const workspace of
|
|
332
|
+
for (const workspace of manifestDirs(migration.root)) {
|
|
314
333
|
const file = join(workspace.dir, "package.json")
|
|
315
334
|
const before = readFileSync(file, "utf8")
|
|
316
335
|
const pkg = JSON.parse(before) as Manifest
|
|
@@ -329,7 +348,7 @@ function migrateManifests(migration: Migration, spec: string): void {
|
|
|
329
348
|
const dependencyNotes = rewriteDependencies(
|
|
330
349
|
pkg,
|
|
331
350
|
spec,
|
|
332
|
-
workspace.rel !== "." && usesRc(pkg)
|
|
351
|
+
workspace.installed && workspace.rel !== "." && usesRc(pkg)
|
|
333
352
|
)
|
|
334
353
|
const notes = [...dependencyNotes, ...catalogNotes, ...scriptNotes]
|
|
335
354
|
|
|
@@ -507,7 +526,7 @@ function migratedText(file: string): string {
|
|
|
507
526
|
function referencingFiles(root: string): string[] {
|
|
508
527
|
return [
|
|
509
528
|
...sourceFiles(root),
|
|
510
|
-
...
|
|
529
|
+
...manifestDirs(root).map((workspace) =>
|
|
511
530
|
join(workspace.dir, "package.json")
|
|
512
531
|
),
|
|
513
532
|
]
|
package/package.json
CHANGED
package/rules/observability.md
CHANGED
|
@@ -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.
|