@react-consulting/rc-kit 0.14.0 → 0.14.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.
|
@@ -52,6 +52,71 @@ function legacyProject(): string {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
describe("migrateToKitPackage", () => {
|
|
55
|
+
test("a script only named in ignore lists is removed, with its entries", () => {
|
|
56
|
+
const root = writeTree(tempDir(), {
|
|
57
|
+
"package.json": {
|
|
58
|
+
name: "contoso-site",
|
|
59
|
+
devDependencies: { "@rc/kit": "link:../_rc-kit" },
|
|
60
|
+
},
|
|
61
|
+
"biome.jsonc":
|
|
62
|
+
'{\n "files": {\n "includes": [\n "**",\n "!scripts/ensure-rc-kit.ts",\n "!scripts/on-workers-ci.ts"\n ]\n }\n}\n',
|
|
63
|
+
"tsconfig.json":
|
|
64
|
+
'{\n "exclude": [\n "dist",\n "scripts/upload-sourcemaps.ts"\n ]\n}\n',
|
|
65
|
+
"rc.config.json": '{ "project": "contoso-site", "kit": ">=0.10.0" }\n',
|
|
66
|
+
"scripts/ensure-rc-kit.ts": "",
|
|
67
|
+
"scripts/on-workers-ci.ts": "",
|
|
68
|
+
"scripts/upload-sourcemaps.ts":
|
|
69
|
+
'import { resolveBuildCommitSha } from "./build-commit-sha"\n',
|
|
70
|
+
"scripts/build-commit-sha.ts": "",
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
migrateToKitPackage({ root, kitVersion: "0.13.0" })
|
|
74
|
+
|
|
75
|
+
for (const script of [
|
|
76
|
+
"on-workers-ci",
|
|
77
|
+
"upload-sourcemaps",
|
|
78
|
+
"build-commit-sha",
|
|
79
|
+
]) {
|
|
80
|
+
expect(existsSync(join(root, `scripts/${script}.ts`))).toBe(false)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
expect(readFileSync(join(root, "biome.jsonc"), "utf8")).toBe(
|
|
84
|
+
'{\n "files": {\n "includes": [\n "**"\n ]\n }\n}\n'
|
|
85
|
+
)
|
|
86
|
+
expect(readFileSync(join(root, "tsconfig.json"), "utf8")).toBe(
|
|
87
|
+
'{\n "exclude": [\n "dist"\n ]\n}\n'
|
|
88
|
+
)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test("an app outside the workspaces is migrated without its own kit dependency", () => {
|
|
92
|
+
const root = writeTree(tempDir(), {
|
|
93
|
+
"package.json": {
|
|
94
|
+
name: "contoso-books",
|
|
95
|
+
devDependencies: { "@rc/kit": "link:../_rc-kit" },
|
|
96
|
+
},
|
|
97
|
+
"workers/jobs/package.json": {
|
|
98
|
+
name: "contoso-jobs",
|
|
99
|
+
scripts: {
|
|
100
|
+
"build:cloudflare":
|
|
101
|
+
"wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(bun ../../scripts/build-commit-sha.ts) && bun ../../scripts/upload-sourcemaps.ts --app jobs --directory dist",
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
"rc.config.json":
|
|
105
|
+
'{ "project": "contoso-books", "kit": ">=0.10.0", "apps": { "web": { "path": "." }, "jobs": { "path": "workers/jobs" } } }\n',
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
migrateToKitPackage({ root, kitVersion: "0.13.0" })
|
|
109
|
+
|
|
110
|
+
const jobs = JSON.parse(
|
|
111
|
+
readFileSync(join(root, "workers/jobs/package.json"), "utf8")
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
expect(jobs.scripts["build:cloudflare"]).toBe(
|
|
115
|
+
"wrangler deploy --dry-run --define __RC_BUILD_SHA__:$(rc build:sha) && rc sentry:sourcemaps --app jobs --directory dist"
|
|
116
|
+
)
|
|
117
|
+
expect(jobs.devDependencies).toBeUndefined()
|
|
118
|
+
})
|
|
119
|
+
|
|
55
120
|
test("a Wrangler build reads its commit from rc build:sha", () => {
|
|
56
121
|
const root = writeTree(tempDir(), {
|
|
57
122
|
"package.json": {
|
|
@@ -54,6 +54,8 @@ const SCRIPT_REWRITES: [RegExp, string][] = [
|
|
|
54
54
|
]
|
|
55
55
|
const BUILD_IMPORT_RE =
|
|
56
56
|
/(["'])(?:\.\.?\/)+scripts\/(?:build-commit-sha|deployed-public-env)(?:\.ts)?\1/g
|
|
57
|
+
const TOOL_CONFIGS = ["biome.json", "biome.jsonc", "tsconfig.json"]
|
|
58
|
+
const TOOL_IGNORE_ENTRY_RE = /"!(?:\.\/)?scripts\/[^"]+"/g
|
|
57
59
|
const SOURCE_EXTENSIONS = /\.(?:[cm]?[jt]sx?|astro|vue|svelte|jsonc)$/
|
|
58
60
|
const DOC_EXTENSIONS = /\.mdx?$|\.example$/
|
|
59
61
|
const STALE_DOC_RE =
|
|
@@ -308,10 +310,28 @@ function appsByPath(root: string): Map<string, string> {
|
|
|
308
310
|
)
|
|
309
311
|
}
|
|
310
312
|
|
|
313
|
+
type ManifestDir = { dir: string; rel: string; installed: boolean }
|
|
314
|
+
|
|
315
|
+
// An app of rc.config.json outside the workspaces (a second Worker of a single-package project) runs from the root's install.
|
|
316
|
+
function manifestDirs(root: string): ManifestDir[] {
|
|
317
|
+
const workspaces = listWorkspaces(root).map((workspace) => ({
|
|
318
|
+
dir: workspace.dir,
|
|
319
|
+
rel: workspace.rel,
|
|
320
|
+
installed: true,
|
|
321
|
+
}))
|
|
322
|
+
const known = new Set(workspaces.map((workspace) => workspace.rel))
|
|
323
|
+
const outsideApps = [...appsByPath(root).keys()]
|
|
324
|
+
.filter((rel) => !known.has(rel) && rel !== "")
|
|
325
|
+
.map((rel) => ({ dir: join(root, rel), rel, installed: false }))
|
|
326
|
+
.filter((app) => existsSync(join(app.dir, "package.json")))
|
|
327
|
+
|
|
328
|
+
return [...workspaces, ...outsideApps]
|
|
329
|
+
}
|
|
330
|
+
|
|
311
331
|
function migrateManifests(migration: Migration, spec: string): void {
|
|
312
332
|
const apps = appsByPath(migration.root)
|
|
313
333
|
|
|
314
|
-
for (const workspace of
|
|
334
|
+
for (const workspace of manifestDirs(migration.root)) {
|
|
315
335
|
const file = join(workspace.dir, "package.json")
|
|
316
336
|
const before = readFileSync(file, "utf8")
|
|
317
337
|
const pkg = JSON.parse(before) as Manifest
|
|
@@ -330,7 +350,7 @@ function migrateManifests(migration: Migration, spec: string): void {
|
|
|
330
350
|
const dependencyNotes = rewriteDependencies(
|
|
331
351
|
pkg,
|
|
332
352
|
spec,
|
|
333
|
-
workspace.rel !== "." && usesRc(pkg)
|
|
353
|
+
workspace.installed && workspace.rel !== "." && usesRc(pkg)
|
|
334
354
|
)
|
|
335
355
|
const notes = [...dependencyNotes, ...catalogNotes, ...scriptNotes]
|
|
336
356
|
|
|
@@ -508,7 +528,7 @@ function migratedText(file: string): string {
|
|
|
508
528
|
function referencingFiles(root: string): string[] {
|
|
509
529
|
return [
|
|
510
530
|
...sourceFiles(root),
|
|
511
|
-
...
|
|
531
|
+
...manifestDirs(root).map((workspace) =>
|
|
512
532
|
join(workspace.dir, "package.json")
|
|
513
533
|
),
|
|
514
534
|
]
|
|
@@ -520,7 +540,7 @@ function stillUsedScripts(
|
|
|
520
540
|
): Set<string> {
|
|
521
541
|
const texts = referencingFiles(migration.root).map((file) => ({
|
|
522
542
|
rel: migration.rel(file),
|
|
523
|
-
text: migratedText(file),
|
|
543
|
+
text: migratedText(file).replace(TOOL_IGNORE_ENTRY_RE, ""),
|
|
524
544
|
}))
|
|
525
545
|
const kept = new Set<string>()
|
|
526
546
|
let changed = true
|
|
@@ -574,6 +594,43 @@ function removeLegacyScripts(migration: Migration): void {
|
|
|
574
594
|
migration.remove(join(migration.root, script), replaced[script] ?? "")
|
|
575
595
|
}
|
|
576
596
|
}
|
|
597
|
+
|
|
598
|
+
const removed = [
|
|
599
|
+
LEGACY_SCRIPTS.bootstrap,
|
|
600
|
+
...candidates.filter((script) => !kept.has(script)),
|
|
601
|
+
]
|
|
602
|
+
|
|
603
|
+
dropToolEntries(migration, removed)
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// Lint and TypeScript configs list the old scripts in their ignore lists: an entry for a removed file is dropped.
|
|
607
|
+
function dropToolEntries(migration: Migration, scripts: string[]): void {
|
|
608
|
+
for (const name of TOOL_CONFIGS) {
|
|
609
|
+
const file = join(migration.root, name)
|
|
610
|
+
|
|
611
|
+
if (!existsSync(file)) {
|
|
612
|
+
continue
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const text = readFileSync(file, "utf8")
|
|
616
|
+
const next = text
|
|
617
|
+
.split("\n")
|
|
618
|
+
.filter((line) => {
|
|
619
|
+
const entry = line.trim().match(/^"!?(?:\.\/)?([^"]+)",?$/)?.[1]
|
|
620
|
+
|
|
621
|
+
return !entry || !scripts.includes(entry)
|
|
622
|
+
})
|
|
623
|
+
.join("\n")
|
|
624
|
+
.replace(/,(\s*\n\s*[\]}])/g, "$1")
|
|
625
|
+
|
|
626
|
+
if (next !== text) {
|
|
627
|
+
migration.write(
|
|
628
|
+
file,
|
|
629
|
+
next,
|
|
630
|
+
"anciens scripts retirés des listes d'exclusion"
|
|
631
|
+
)
|
|
632
|
+
}
|
|
633
|
+
}
|
|
577
634
|
}
|
|
578
635
|
|
|
579
636
|
function reportDocs(migration: Migration): void {
|