@react-consulting/rc-kit 0.0.0-stage → 0.13.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/LICENSE +21 -0
- package/README.md +93 -2
- package/devkit/README.md +301 -0
- package/devkit/cli.test.ts +211 -0
- package/devkit/cli.ts +120 -0
- package/devkit/commands/build.ts +127 -0
- package/devkit/commands/checks.ts +123 -0
- package/devkit/commands/context.ts +47 -0
- package/devkit/commands/db.ts +154 -0
- package/devkit/commands/deploy.ts +46 -0
- package/devkit/commands/dev.ts +191 -0
- package/devkit/commands/doctor.ts +25 -0
- package/devkit/commands/kit.ts +45 -0
- package/devkit/commands/new.ts +81 -0
- package/devkit/commands/registry.ts +20 -0
- package/devkit/commands/secrets.ts +254 -0
- package/devkit/lib/args.ts +65 -0
- package/devkit/lib/audit.test.ts +405 -0
- package/devkit/lib/audit.ts +813 -0
- package/devkit/lib/config.test.ts +203 -0
- package/devkit/lib/config.ts +417 -0
- package/devkit/lib/database/index.test.ts +223 -0
- package/devkit/lib/database/index.ts +314 -0
- package/devkit/lib/database/neon.test.ts +233 -0
- package/devkit/lib/database/neon.ts +357 -0
- package/devkit/lib/database/prepare.ts +54 -0
- package/devkit/lib/deploy-config.test.ts +217 -0
- package/devkit/lib/deploy-config.ts +133 -0
- package/devkit/lib/deploy.test.ts +275 -0
- package/devkit/lib/deploy.ts +177 -0
- package/devkit/lib/dev-gateway.test.ts +128 -0
- package/devkit/lib/dev-gateway.ts +162 -0
- package/devkit/lib/dev-menu.test.ts +114 -0
- package/devkit/lib/dev-menu.ts +332 -0
- package/devkit/lib/dev-secrets.test.ts +156 -0
- package/devkit/lib/dev-secrets.ts +97 -0
- package/devkit/lib/dev.test.ts +194 -0
- package/devkit/lib/dev.ts +119 -0
- package/devkit/lib/doctor.test.ts +144 -0
- package/devkit/lib/doctor.ts +264 -0
- package/devkit/lib/env-file.test.ts +102 -0
- package/devkit/lib/env-file.ts +96 -0
- package/devkit/lib/glob.ts +31 -0
- package/devkit/lib/infisical.test.ts +208 -0
- package/devkit/lib/infisical.ts +139 -0
- package/devkit/lib/json-schema.ts +220 -0
- package/devkit/lib/jsonc.test.ts +53 -0
- package/devkit/lib/jsonc.ts +93 -0
- package/devkit/lib/kit-migrate.test.ts +215 -0
- package/devkit/lib/kit-migrate.ts +624 -0
- package/devkit/lib/kit-package.test.ts +83 -0
- package/devkit/lib/kit-package.ts +57 -0
- package/devkit/lib/kit-version.ts +22 -0
- package/devkit/lib/naming.test.ts +547 -0
- package/devkit/lib/naming.ts +796 -0
- package/devkit/lib/paths.ts +7 -0
- package/devkit/lib/process.ts +78 -0
- package/devkit/lib/project-checks.ts +86 -0
- package/devkit/lib/scaffold.test.ts +302 -0
- package/devkit/lib/scaffold.ts +315 -0
- package/devkit/lib/secrets.test.ts +101 -0
- package/devkit/lib/secrets.ts +125 -0
- package/devkit/lib/sourcemaps.test.ts +86 -0
- package/devkit/lib/sourcemaps.ts +98 -0
- package/devkit/lib/test-utils.ts +68 -0
- package/devkit/lib/workspace.ts +87 -0
- package/devkit/lib/wrangler.ts +231 -0
- package/docs/rc-config.md +93 -0
- package/package.json +86 -4
- package/presets/build.d.ts +15 -0
- package/presets/build.js +53 -0
- package/presets/vite-plus.d.ts +28 -0
- package/presets/vite-plus.js +153 -0
- package/registry/README.md +294 -0
- package/registry/public/r/avatar-stack.json +18 -0
- package/registry/public/r/avatar.json +20 -0
- package/registry/public/r/back-link.json +21 -0
- package/registry/public/r/badge.json +17 -0
- package/registry/public/r/button.json +18 -0
- package/registry/public/r/calendar-days.json +14 -0
- package/registry/public/r/calendar-popover.json +24 -0
- package/registry/public/r/calendar.json +23 -0
- package/registry/public/r/callout.json +20 -0
- package/registry/public/r/card.json +18 -0
- package/registry/public/r/character-counter.json +17 -0
- package/registry/public/r/checkbox.json +22 -0
- package/registry/public/r/choice-cards.json +22 -0
- package/registry/public/r/color-tag.json +17 -0
- package/registry/public/r/combobox.json +24 -0
- package/registry/public/r/confirm-button.json +24 -0
- package/registry/public/r/confirm-dialog.json +23 -0
- package/registry/public/r/copy-button.json +24 -0
- package/registry/public/r/date-picker.json +24 -0
- package/registry/public/r/date-range-picker.json +28 -0
- package/registry/public/r/detail-header.json +17 -0
- package/registry/public/r/detail-row.json +17 -0
- package/registry/public/r/dev-inbox-api.json +33 -0
- package/registry/public/r/dev-toolbar.json +109 -0
- package/registry/public/r/dev-tools-contract.json +15 -0
- package/registry/public/r/dialog.json +23 -0
- package/registry/public/r/empty-state.json +20 -0
- package/registry/public/r/error-state.json +23 -0
- package/registry/public/r/eyebrow.json +17 -0
- package/registry/public/r/fab.json +20 -0
- package/registry/public/r/field-error.json +17 -0
- package/registry/public/r/field-grid.json +17 -0
- package/registry/public/r/field.json +19 -0
- package/registry/public/r/file-picker.json +22 -0
- package/registry/public/r/filter-chips.json +17 -0
- package/registry/public/r/form-section.json +17 -0
- package/registry/public/r/form-sheet.json +22 -0
- package/registry/public/r/icon-button.json +23 -0
- package/registry/public/r/input.json +18 -0
- package/registry/public/r/label.json +18 -0
- package/registry/public/r/list-row.json +17 -0
- package/registry/public/r/loading-state.json +18 -0
- package/registry/public/r/localized-field.json +23 -0
- package/registry/public/r/markdown-text.json +17 -0
- package/registry/public/r/menu.json +21 -0
- package/registry/public/r/money-input.json +17 -0
- package/registry/public/r/month-day-select.json +18 -0
- package/registry/public/r/numbered-step.json +20 -0
- package/registry/public/r/page-actions.json +14 -0
- package/registry/public/r/page-header.json +17 -0
- package/registry/public/r/pending.json +17 -0
- package/registry/public/r/person-option.json +21 -0
- package/registry/public/r/popover.json +20 -0
- package/registry/public/r/progress-bar.json +17 -0
- package/registry/public/r/query-view.json +22 -0
- package/registry/public/r/registry.json +1352 -0
- package/registry/public/r/retry-button.json +21 -0
- package/registry/public/r/rich-text-editor.json +32 -0
- package/registry/public/r/save-bar.json +22 -0
- package/registry/public/r/search-input.json +23 -0
- package/registry/public/r/search-select.json +24 -0
- package/registry/public/r/section-tabs.json +17 -0
- package/registry/public/r/segmented.json +18 -0
- package/registry/public/r/select.json +23 -0
- package/registry/public/r/sheet.json +24 -0
- package/registry/public/r/skeleton.json +17 -0
- package/registry/public/r/spinner.json +20 -0
- package/registry/public/r/stale-notice.json +23 -0
- package/registry/public/r/stat-tile.json +23 -0
- package/registry/public/r/stepper.json +23 -0
- package/registry/public/r/suggestion-strip.json +21 -0
- package/registry/public/r/swatch-picker.json +22 -0
- package/registry/public/r/switch.json +21 -0
- package/registry/public/r/tabs.json +20 -0
- package/registry/public/r/textarea.json +18 -0
- package/registry/public/r/theme.json +15 -0
- package/registry/public/r/timezone-select.json +19 -0
- package/registry/public/r/toaster.json +21 -0
- package/registry/public/r/tooltip.json +17 -0
- package/registry/public/r/ui-labels.json +14 -0
- package/registry/public/r/use-copy-to-clipboard.json +20 -0
- package/registry/public/r/use-online.json +14 -0
- package/registry/public/r/use-stale-queries.json +17 -0
- package/registry/public/r/utils.json +18 -0
- package/registry/public/r/weekday-picker.json +19 -0
- package/registry/public/r/yes-no.json +20 -0
- package/registry/serve.ts +29 -0
- package/rules/architecture.md +47 -0
- package/rules/cloudflare.md +74 -0
- package/rules/code.md +12 -0
- package/rules/git.md +10 -0
- package/rules/index.md +14 -0
- package/rules/observability.md +13 -0
- package/rules/performance.md +39 -0
- package/rules/runtime.md +9 -0
- package/rules/secrets.md +11 -0
- package/rules/stack.md +33 -0
- package/rules/ui.md +23 -0
- package/runtime/ai.test.ts +106 -0
- package/runtime/ai.ts +125 -0
- package/runtime/observability/allowlists.ts +42 -0
- package/runtime/observability/anonymize.test.ts +111 -0
- package/runtime/observability/anonymize.ts +249 -0
- package/runtime/observability/browser.test.ts +46 -0
- package/runtime/observability/browser.ts +126 -0
- package/runtime/observability/server.test.ts +84 -0
- package/runtime/observability/server.ts +152 -0
- package/runtime/observability/tunnel.test.ts +276 -0
- package/runtime/observability/tunnel.ts +360 -0
- package/runtime/observability/user-agent.ts +51 -0
- package/schema/rc.config.schema.json +333 -0
- package/template/.gitattributes +1 -0
- package/template/.github/workflows/ci.yml +64 -0
- package/template/CLAUDE.md +48 -0
- package/template/README.md +50 -0
- package/template/apps/admin/.dev.vars.example +5 -0
- package/template/apps/admin/components.json +24 -0
- package/template/apps/admin/package.json +48 -0
- package/template/apps/admin/public/favicon.svg +1 -0
- package/template/apps/admin/src/components/app-shell.tsx +41 -0
- package/template/apps/admin/src/components/dev-sign-in-links.tsx +57 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-context.ts +13 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-environment-panel.tsx +105 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-list.tsx +54 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-message.tsx +104 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-inbox-panel.tsx +130 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-launcher.tsx +45 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-panel.tsx +90 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar-types.ts +11 -0
- package/template/apps/admin/src/components/dev-toolbar/dev-toolbar.tsx +61 -0
- package/template/apps/admin/src/components/dev-toolbar/development-devtools.tsx +32 -0
- package/template/apps/admin/src/components/login-form.tsx +115 -0
- package/template/apps/admin/src/components/login-sent.tsx +23 -0
- package/template/apps/admin/src/components/message-list.tsx +44 -0
- package/template/apps/admin/src/components/turnstile-challenge.tsx +140 -0
- package/template/apps/admin/src/components/ui/button.tsx +87 -0
- package/template/apps/admin/src/components/ui/callout.tsx +84 -0
- package/template/apps/admin/src/components/ui/card.tsx +48 -0
- package/template/apps/admin/src/components/ui/eyebrow.tsx +33 -0
- package/template/apps/admin/src/components/ui/field-error.tsx +24 -0
- package/template/apps/admin/src/components/ui/field.tsx +100 -0
- package/template/apps/admin/src/components/ui/input.tsx +73 -0
- package/template/apps/admin/src/components/ui/label.tsx +39 -0
- package/template/apps/admin/src/components/ui/skeleton.tsx +225 -0
- package/template/apps/admin/src/components/ui/spinner.tsx +12 -0
- package/template/apps/admin/src/components/ui/toaster.tsx +33 -0
- package/template/apps/admin/src/components/ui/tooltip.tsx +51 -0
- package/template/apps/admin/src/hooks/use-dev-inbox.ts +25 -0
- package/template/apps/admin/src/hooks/use-dev-toolbar-state.ts +48 -0
- package/template/apps/admin/src/lib/api.ts +39 -0
- package/template/apps/admin/src/lib/auth-client.ts +7 -0
- package/template/apps/admin/src/lib/dev-inbox-links.ts +66 -0
- package/template/apps/admin/src/lib/dev-tools-client.ts +54 -0
- package/template/apps/admin/src/lib/dev-tools-contract.ts +52 -0
- package/template/apps/admin/src/lib/messages.ts +5 -0
- package/template/apps/admin/src/lib/query-keys.ts +3 -0
- package/template/apps/admin/src/lib/security-headers.ts +18 -0
- package/template/apps/admin/src/lib/session.ts +27 -0
- package/template/apps/admin/src/lib/site-url.ts +7 -0
- package/template/apps/admin/src/lib/turnstile.ts +70 -0
- package/template/apps/admin/src/lib/ui-labels.tsx +182 -0
- package/template/apps/admin/src/lib/utils.ts +6 -0
- package/template/apps/admin/src/routeTree.gen.ts +109 -0
- package/template/apps/admin/src/router.tsx +29 -0
- package/template/apps/admin/src/routes/__root.tsx +56 -0
- package/template/apps/admin/src/routes/_app/index.tsx +38 -0
- package/template/apps/admin/src/routes/_app.tsx +26 -0
- package/template/apps/admin/src/routes/login.tsx +48 -0
- package/template/apps/admin/src/styles/app.css +11 -0
- package/template/apps/admin/src/worker.ts +88 -0
- package/template/apps/admin/tsconfig.json +19 -0
- package/template/apps/admin/vite.config.ts +69 -0
- package/template/apps/admin/wrangler.jsonc +92 -0
- package/template/apps/web/.env.example +1 -0
- package/template/apps/web/astro.config.ts +46 -0
- package/template/apps/web/package.json +33 -0
- package/template/apps/web/public/favicon.svg +1 -0
- package/template/apps/web/src/components/ContactForm.astro +78 -0
- package/template/apps/web/src/env.d.ts +11 -0
- package/template/apps/web/src/layouts/BaseLayout.astro +32 -0
- package/template/apps/web/src/lib/api.ts +8 -0
- package/template/apps/web/src/pages/api/messages.ts +32 -0
- package/template/apps/web/src/pages/index.astro +26 -0
- package/template/apps/web/src/pages/media/[...key].ts +4 -0
- package/template/apps/web/src/scripts/contact-form.ts +105 -0
- package/template/apps/web/src/scripts/error-reporting.ts +4 -0
- package/template/apps/web/src/scripts/turnstile.ts +177 -0
- package/template/apps/web/src/styles/global.css +11 -0
- package/template/apps/web/src/worker.ts +34 -0
- package/template/apps/web/tsconfig.json +11 -0
- package/template/apps/web/wrangler.jsonc +45 -0
- package/template/bun.lock +1925 -0
- package/template/bunfig.toml +2 -0
- package/template/gitignore +23 -0
- package/template/package.json +74 -0
- package/template/packages/api/components.json +21 -0
- package/template/packages/api/package.json +30 -0
- package/template/packages/api/src/client.ts +13 -0
- package/template/packages/api/src/cloudflare-env.d.ts +26 -0
- package/template/packages/api/src/emails/escape-html.ts +13 -0
- package/template/packages/api/src/emails/layout.ts +22 -0
- package/template/packages/api/src/emails/magic-link.ts +32 -0
- package/template/packages/api/src/emails/new-message.ts +32 -0
- package/template/packages/api/src/emails/send.ts +14 -0
- package/template/packages/api/src/lib/auth-guard.ts +16 -0
- package/template/packages/api/src/lib/auth.ts +108 -0
- package/template/packages/api/src/lib/context.ts +7 -0
- package/template/packages/api/src/lib/dev-inbox/routes.ts +77 -0
- package/template/packages/api/src/lib/dev-inbox/send.ts +57 -0
- package/template/packages/api/src/lib/dev-inbox/store.ts +185 -0
- package/template/packages/api/src/lib/dev-inbox.ts +6 -0
- package/template/packages/api/src/lib/dev-tools-contract.ts +52 -0
- package/template/packages/api/src/lib/environment.ts +17 -0
- package/template/packages/api/src/lib/turnstile.ts +33 -0
- package/template/packages/api/src/media.ts +45 -0
- package/template/packages/api/src/routes/admin-messages.ts +21 -0
- package/template/packages/api/src/routes/dev.ts +31 -0
- package/template/packages/api/src/routes/health.ts +7 -0
- package/template/packages/api/src/routes/messages.ts +58 -0
- package/template/packages/api/src/schemas.ts +18 -0
- package/template/packages/api/src/server.ts +29 -0
- package/template/packages/api/tsconfig.json +10 -0
- package/template/packages/db/migrations/0001_init.sql +79 -0
- package/template/packages/db/package.json +34 -0
- package/template/packages/db/prisma/schema.prisma +95 -0
- package/template/packages/db/prisma.config.ts +9 -0
- package/template/packages/db/scripts/migrate.ts +15 -0
- package/template/packages/db/scripts/new-migration.ts +185 -0
- package/template/packages/db/scripts/reset.ts +54 -0
- package/template/packages/db/scripts/seed.ts +44 -0
- package/template/packages/db/scripts/wrangler.ts +35 -0
- package/template/packages/db/src/d1.ts +7 -0
- package/template/packages/db/src/migration-guard.test.ts +43 -0
- package/template/packages/db/src/migration-guard.ts +51 -0
- package/template/packages/db/src/new-migration.test.ts +16 -0
- package/template/packages/db/src/scope.ts +38 -0
- package/template/packages/db/src/seed.ts +30 -0
- package/template/packages/db/src/sql.ts +42 -0
- package/template/packages/db/tsconfig.json +8 -0
- package/template/packages/shared/components.json +21 -0
- package/template/packages/shared/package.json +33 -0
- package/template/packages/shared/src/edge/origins.ts +20 -0
- package/template/packages/shared/src/edge/turnstile.ts +11 -0
- package/template/packages/shared/src/locales.ts +13 -0
- package/template/packages/shared/src/message-rules.ts +16 -0
- package/template/packages/shared/src/messages.test.ts +26 -0
- package/template/packages/shared/src/messages.ts +30 -0
- package/template/packages/shared/src/observability/build-release.ts +9 -0
- package/template/packages/shared/src/observability/error-reporting.ts +31 -0
- package/template/packages/shared/src/observability/error-tunnel.ts +20 -0
- package/template/packages/shared/src/observability/sentry-browser.ts +1 -0
- package/template/packages/shared/src/observability/server-errors.ts +74 -0
- package/template/packages/shared/src/project.ts +1 -0
- package/template/packages/shared/src/styles/rc-theme.css +138 -0
- package/template/packages/shared/src/styles/theme.css +9 -0
- package/template/packages/shared/tsconfig.json +10 -0
- package/template/rc.config.json +25 -0
- package/template/scripts/bootstrap-local.ts +42 -0
- package/template/tsconfig.base.json +20 -0
- package/template/tsconfig.json +8 -0
- package/template/tsconfig.worker.json +7 -0
- package/template/turbo.json +40 -0
- package/template/vite.config.ts +8 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
import {
|
|
2
|
+
existsSync,
|
|
3
|
+
readdirSync,
|
|
4
|
+
readFileSync,
|
|
5
|
+
rmSync,
|
|
6
|
+
statSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from "node:fs"
|
|
9
|
+
import { basename, join, relative } from "node:path"
|
|
10
|
+
|
|
11
|
+
import { parseJsonc } from "./jsonc"
|
|
12
|
+
import {
|
|
13
|
+
isPortableImport,
|
|
14
|
+
KIT_PACKAGE,
|
|
15
|
+
KIT_RULES_PATH,
|
|
16
|
+
KIT_SCHEMA_PATH,
|
|
17
|
+
LEGACY_KIT_PACKAGE,
|
|
18
|
+
RULES_IMPORT,
|
|
19
|
+
rulesImportsOf,
|
|
20
|
+
toPosixPath,
|
|
21
|
+
} from "./kit-package"
|
|
22
|
+
import { listWorkspaces } from "./workspace"
|
|
23
|
+
|
|
24
|
+
export interface MigrationChange {
|
|
25
|
+
file: string
|
|
26
|
+
action: "modifié" | "supprimé"
|
|
27
|
+
detail: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface MigrationResult {
|
|
31
|
+
changes: MigrationChange[]
|
|
32
|
+
manual: string[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface MigrationInput {
|
|
36
|
+
root: string
|
|
37
|
+
kitVersion: string
|
|
38
|
+
dryRun?: boolean
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const LEGACY_IMPORT_RE = /@rc\/kit(?![\w-])/g
|
|
42
|
+
const LEGACY_SCRIPTS = {
|
|
43
|
+
bootstrap: "scripts/ensure-rc-kit.ts",
|
|
44
|
+
ciOnly: "scripts/on-workers-ci.ts",
|
|
45
|
+
sourcemaps: "scripts/upload-sourcemaps.ts",
|
|
46
|
+
commitSha: "scripts/build-commit-sha.ts",
|
|
47
|
+
publicEnv: "scripts/deployed-public-env.ts",
|
|
48
|
+
}
|
|
49
|
+
const SCRIPT_REWRITES: [RegExp, string][] = [
|
|
50
|
+
[/bun (?:\.\.\/)*scripts\/on-workers-ci\.ts/g, "rc ci:only"],
|
|
51
|
+
[/bun (?:\.\.\/)*scripts\/upload-sourcemaps\.ts/g, "rc sentry:sourcemaps"],
|
|
52
|
+
[/\brc op:sync\b/g, "rc secrets:pull"],
|
|
53
|
+
]
|
|
54
|
+
const BUILD_IMPORT_RE =
|
|
55
|
+
/(["'])(?:\.\.?\/)+scripts\/(?:build-commit-sha|deployed-public-env)(?:\.ts)?\1/g
|
|
56
|
+
const SOURCE_EXTENSIONS = /\.(?:[cm]?[jt]sx?|astro|vue|svelte)$/
|
|
57
|
+
const DOC_EXTENSIONS = /\.mdx?$/
|
|
58
|
+
const STALE_DOC_RE =
|
|
59
|
+
/_rc-kit|@rc\/kit(?![\w-])|ensure-rc-kit|\bop:sync\b|upload-sourcemaps|on-workers-ci/
|
|
60
|
+
const SKIPPED_DIRS = new Set([
|
|
61
|
+
"node_modules",
|
|
62
|
+
".git",
|
|
63
|
+
".turbo",
|
|
64
|
+
".wrangler",
|
|
65
|
+
"dist",
|
|
66
|
+
".output",
|
|
67
|
+
".tanstack",
|
|
68
|
+
".astro",
|
|
69
|
+
"generated",
|
|
70
|
+
])
|
|
71
|
+
const DEPENDENCY_FIELDS = [
|
|
72
|
+
"dependencies",
|
|
73
|
+
"devDependencies",
|
|
74
|
+
"peerDependencies",
|
|
75
|
+
"optionalDependencies",
|
|
76
|
+
] as const
|
|
77
|
+
|
|
78
|
+
const LEGACY_SECRETS_SCRIPT = "op:sync"
|
|
79
|
+
const SECRETS_SCRIPT = "secrets:pull"
|
|
80
|
+
const SOURCEMAPS_PROJECT_RE = /rc sentry:sourcemaps --project (\S+)/g
|
|
81
|
+
const LEGACY_SENTRY_ORG_RE = /SENTRY_ORG\s*\?\?\s*["']([^"']+)["']/
|
|
82
|
+
|
|
83
|
+
type Manifest = Record<string, unknown> & {
|
|
84
|
+
scripts?: Record<string, string>
|
|
85
|
+
workspaces?: { catalog?: Record<string, string> } | string[]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
class Migration {
|
|
89
|
+
readonly changes: MigrationChange[] = []
|
|
90
|
+
readonly manual: string[] = []
|
|
91
|
+
readonly sentryProjects: Record<string, string> = {}
|
|
92
|
+
|
|
93
|
+
constructor(
|
|
94
|
+
readonly root: string,
|
|
95
|
+
readonly dryRun: boolean
|
|
96
|
+
) {}
|
|
97
|
+
|
|
98
|
+
rel(path: string): string {
|
|
99
|
+
return toPosixPath(relative(this.root, path)) || "."
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
write(path: string, text: string, detail: string): void {
|
|
103
|
+
if (!this.dryRun) {
|
|
104
|
+
writeFileSync(path, text)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.changes.push({ file: this.rel(path), action: "modifié", detail })
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
remove(path: string, detail: string): void {
|
|
111
|
+
if (!this.dryRun) {
|
|
112
|
+
rmSync(path, { force: true })
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.changes.push({ file: this.rel(path), action: "supprimé", detail })
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isNestedCheckout(path: string): boolean {
|
|
120
|
+
return existsSync(join(path, ".git"))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function sourceFiles(
|
|
124
|
+
dir: string,
|
|
125
|
+
extensions = SOURCE_EXTENSIONS,
|
|
126
|
+
files: string[] = []
|
|
127
|
+
): string[] {
|
|
128
|
+
for (const entry of readdirSync(dir)) {
|
|
129
|
+
if (SKIPPED_DIRS.has(entry)) {
|
|
130
|
+
continue
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const path = join(dir, entry)
|
|
134
|
+
|
|
135
|
+
if (statSync(path).isDirectory()) {
|
|
136
|
+
if (entry.startsWith(".") || isNestedCheckout(path)) {
|
|
137
|
+
continue
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
sourceFiles(path, extensions, files)
|
|
141
|
+
} else if (extensions.test(entry)) {
|
|
142
|
+
files.push(path)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return files
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function rewriteDependencies(
|
|
150
|
+
pkg: Manifest,
|
|
151
|
+
spec: string,
|
|
152
|
+
needsKit: boolean
|
|
153
|
+
): string[] {
|
|
154
|
+
const notes: string[] = []
|
|
155
|
+
|
|
156
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
157
|
+
const deps = pkg[field] as Record<string, string> | undefined
|
|
158
|
+
|
|
159
|
+
if (!deps) {
|
|
160
|
+
continue
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (Object.hasOwn(deps, LEGACY_KIT_PACKAGE)) {
|
|
164
|
+
delete deps[LEGACY_KIT_PACKAGE]
|
|
165
|
+
deps[KIT_PACKAGE] = spec
|
|
166
|
+
pkg[field] = Object.fromEntries(
|
|
167
|
+
Object.entries(deps).toSorted(([a], [b]) => a.localeCompare(b))
|
|
168
|
+
)
|
|
169
|
+
notes.push(`${LEGACY_KIT_PACKAGE} → ${KIT_PACKAGE}@${spec}`)
|
|
170
|
+
} else if (deps[KIT_PACKAGE]?.startsWith("link:")) {
|
|
171
|
+
deps[KIT_PACKAGE] = spec
|
|
172
|
+
notes.push(`${KIT_PACKAGE} : lien local → ${spec}`)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const declared = DEPENDENCY_FIELDS.some(
|
|
177
|
+
(field) => (pkg[field] as Record<string, string> | undefined)?.[KIT_PACKAGE]
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
if (needsKit && !declared) {
|
|
181
|
+
pkg.devDependencies = Object.fromEntries(
|
|
182
|
+
Object.entries({
|
|
183
|
+
...(pkg.devDependencies as Record<string, string> | undefined),
|
|
184
|
+
[KIT_PACKAGE]: spec,
|
|
185
|
+
}).toSorted(([a], [b]) => a.localeCompare(b))
|
|
186
|
+
)
|
|
187
|
+
notes.push(`${KIT_PACKAGE}@${spec} ajouté (installation filtrée)`)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return notes
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function renameSecretsScript(scripts: Record<string, string>): string[] {
|
|
194
|
+
if (!Object.hasOwn(scripts, LEGACY_SECRETS_SCRIPT)) {
|
|
195
|
+
return []
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const renamed = Object.fromEntries(
|
|
199
|
+
Object.entries(scripts).map(([name, command]) => [
|
|
200
|
+
name === LEGACY_SECRETS_SCRIPT && !Object.hasOwn(scripts, SECRETS_SCRIPT)
|
|
201
|
+
? SECRETS_SCRIPT
|
|
202
|
+
: name,
|
|
203
|
+
command.replaceAll(
|
|
204
|
+
`run ${LEGACY_SECRETS_SCRIPT}`,
|
|
205
|
+
`run ${SECRETS_SCRIPT}`
|
|
206
|
+
),
|
|
207
|
+
])
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
for (const name of Object.keys(scripts)) {
|
|
211
|
+
delete scripts[name]
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
Object.assign(scripts, renamed)
|
|
215
|
+
|
|
216
|
+
return [`script ${LEGACY_SECRETS_SCRIPT} → ${SECRETS_SCRIPT}`]
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function sentryProjectsToApps(
|
|
220
|
+
migration: Migration,
|
|
221
|
+
scripts: Record<string, string>,
|
|
222
|
+
app: string | undefined
|
|
223
|
+
): void {
|
|
224
|
+
for (const [name, command] of Object.entries(scripts)) {
|
|
225
|
+
scripts[name] = command.replace(SOURCEMAPS_PROJECT_RE, (match, slug) => {
|
|
226
|
+
if (!app) {
|
|
227
|
+
migration.manual.push(
|
|
228
|
+
`script ${name} : --project ${slug} garde son projet Sentry, mais aucune app de rc.config.json ne pointe sur ce dossier ; déclare-la et passe à --app.`
|
|
229
|
+
)
|
|
230
|
+
return match
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
migration.sentryProjects[app] = slug
|
|
234
|
+
return `rc sentry:sourcemaps --app ${app}`
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function rewriteScripts(
|
|
240
|
+
migration: Migration,
|
|
241
|
+
pkg: Manifest,
|
|
242
|
+
app: string | undefined
|
|
243
|
+
): string[] {
|
|
244
|
+
const notes: string[] = []
|
|
245
|
+
const scripts = pkg.scripts
|
|
246
|
+
|
|
247
|
+
if (!scripts) {
|
|
248
|
+
return notes
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
for (const hook of ["preinstall", "postinstall"]) {
|
|
252
|
+
if (scripts[hook]?.includes("ensure-rc-kit")) {
|
|
253
|
+
delete scripts[hook]
|
|
254
|
+
notes.push(`script ${hook} retiré`)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
for (const [name, command] of Object.entries(scripts)) {
|
|
259
|
+
let next = command
|
|
260
|
+
|
|
261
|
+
for (const [pattern, replacement] of SCRIPT_REWRITES) {
|
|
262
|
+
next = next.replace(pattern, replacement)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (next !== command) {
|
|
266
|
+
scripts[name] = next
|
|
267
|
+
notes.push(`script ${name}`)
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
sentryProjectsToApps(migration, scripts, app)
|
|
272
|
+
const renamed = renameSecretsScript(scripts)
|
|
273
|
+
|
|
274
|
+
if (renamed.length === 0) {
|
|
275
|
+
return notes
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return [
|
|
279
|
+
...notes.filter((note) => note !== `script ${LEGACY_SECRETS_SCRIPT}`),
|
|
280
|
+
...renamed,
|
|
281
|
+
]
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function usesRc(pkg: Manifest): boolean {
|
|
285
|
+
return Object.values(pkg.scripts ?? {}).some((command) =>
|
|
286
|
+
/(?:^|&&|\s)rc\s/.test(command)
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function appsByPath(root: string): Map<string, string> {
|
|
291
|
+
const file = join(root, "rc.config.json")
|
|
292
|
+
|
|
293
|
+
if (!existsSync(file)) {
|
|
294
|
+
return new Map()
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const config = parseJsonc<{ apps?: Record<string, { path?: string }> }>(
|
|
298
|
+
readFileSync(file, "utf8")
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
return new Map(
|
|
302
|
+
Object.entries(config.apps ?? {}).flatMap(([name, app]) =>
|
|
303
|
+
app.path ? [[toPosixPath(app.path).replace(/\/$/, ""), name]] : []
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function migrateManifests(migration: Migration, spec: string): void {
|
|
309
|
+
const apps = appsByPath(migration.root)
|
|
310
|
+
|
|
311
|
+
for (const workspace of listWorkspaces(migration.root)) {
|
|
312
|
+
const file = join(workspace.dir, "package.json")
|
|
313
|
+
const before = readFileSync(file, "utf8")
|
|
314
|
+
const pkg = JSON.parse(before) as Manifest
|
|
315
|
+
const scriptNotes = rewriteScripts(migration, pkg, apps.get(workspace.rel))
|
|
316
|
+
const catalog = Array.isArray(pkg.workspaces)
|
|
317
|
+
? undefined
|
|
318
|
+
: pkg.workspaces?.catalog
|
|
319
|
+
const catalogNotes: string[] = []
|
|
320
|
+
|
|
321
|
+
if (catalog && Object.hasOwn(catalog, LEGACY_KIT_PACKAGE)) {
|
|
322
|
+
delete catalog[LEGACY_KIT_PACKAGE]
|
|
323
|
+
catalog[KIT_PACKAGE] = spec
|
|
324
|
+
catalogNotes.push(`catalog : ${KIT_PACKAGE}@${spec}`)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const dependencyNotes = rewriteDependencies(
|
|
328
|
+
pkg,
|
|
329
|
+
spec,
|
|
330
|
+
workspace.rel !== "." && usesRc(pkg)
|
|
331
|
+
)
|
|
332
|
+
const notes = [...dependencyNotes, ...catalogNotes, ...scriptNotes]
|
|
333
|
+
|
|
334
|
+
if (notes.length > 0) {
|
|
335
|
+
migration.write(
|
|
336
|
+
file,
|
|
337
|
+
`${JSON.stringify(pkg, null, 2)}\n`,
|
|
338
|
+
notes.join(", ")
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function migrateSources(migration: Migration): void {
|
|
345
|
+
for (const file of sourceFiles(migration.root)) {
|
|
346
|
+
if (migration.rel(file) === LEGACY_SCRIPTS.bootstrap) {
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const text = readFileSync(file, "utf8")
|
|
351
|
+
const next = text
|
|
352
|
+
.replace(LEGACY_IMPORT_RE, KIT_PACKAGE)
|
|
353
|
+
.replace(BUILD_IMPORT_RE, `$1${KIT_PACKAGE}/build$1`)
|
|
354
|
+
|
|
355
|
+
if (next !== text) {
|
|
356
|
+
migration.write(file, next, `imports vers ${KIT_PACKAGE}`)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function migrateAgentFiles(migration: Migration): void {
|
|
362
|
+
for (const name of ["CLAUDE.md", "AGENTS.md"]) {
|
|
363
|
+
const file = join(migration.root, name)
|
|
364
|
+
|
|
365
|
+
if (!existsSync(file)) {
|
|
366
|
+
continue
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const text = readFileSync(file, "utf8")
|
|
370
|
+
const stale = rulesImportsOf(text).filter(
|
|
371
|
+
(spec) =>
|
|
372
|
+
spec !== KIT_RULES_PATH &&
|
|
373
|
+
(!isPortableImport(spec) || spec.endsWith("rules/index.md"))
|
|
374
|
+
)
|
|
375
|
+
let next = text
|
|
376
|
+
|
|
377
|
+
for (const spec of stale) {
|
|
378
|
+
next = next.replaceAll(`@${spec}`, RULES_IMPORT)
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
next = next.replace(LEGACY_IMPORT_RE, KIT_PACKAGE)
|
|
382
|
+
|
|
383
|
+
if (next !== text) {
|
|
384
|
+
migration.write(file, next, `règles importées par ${RULES_IMPORT}`)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function migrateRcConfig(migration: Migration, kitVersion: string): void {
|
|
390
|
+
const file = join(migration.root, "rc.config.json")
|
|
391
|
+
|
|
392
|
+
if (!existsSync(file)) {
|
|
393
|
+
migration.manual.push(
|
|
394
|
+
"rc.config.json absent : crée-le (docs/rc-config.md du kit) avant de relancer rc audit."
|
|
395
|
+
)
|
|
396
|
+
return
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const text = readFileSync(file, "utf8")
|
|
400
|
+
const config = parseJsonc<Record<string, unknown>>(text)
|
|
401
|
+
const range = `>=${kitVersion}`
|
|
402
|
+
let next = text.replace(
|
|
403
|
+
/("\$schema"\s*:\s*)"[^"]*"/,
|
|
404
|
+
`$1"${KIT_SCHEMA_PATH}"`
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
if (!("$schema" in config)) {
|
|
408
|
+
next = next.replace(/^\{/, `{\n "$schema": "${KIT_SCHEMA_PATH}",`)
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
next =
|
|
412
|
+
"kit" in config
|
|
413
|
+
? next.replace(/("kit"\s*:\s*)"[^"]*"/, `$1"${range}"`)
|
|
414
|
+
: next.replace(/("\$schema"\s*:\s*"[^"]*",)/, `$1\n "kit": "${range}",`)
|
|
415
|
+
|
|
416
|
+
const withSentry = withSentryProjects(migration, config, next)
|
|
417
|
+
const details = [`$schema du paquet, kit ${range}`]
|
|
418
|
+
|
|
419
|
+
if (withSentry !== next) {
|
|
420
|
+
details.push(
|
|
421
|
+
`sentry.projects ${Object.keys(migration.sentryProjects).join(", ")}`
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (withSentry !== text) {
|
|
426
|
+
migration.write(file, withSentry, details.join(", "))
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function legacySentryOrg(root: string): string | null {
|
|
431
|
+
const file = join(root, LEGACY_SCRIPTS.sourcemaps)
|
|
432
|
+
|
|
433
|
+
if (!existsSync(file)) {
|
|
434
|
+
return null
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return readFileSync(file, "utf8").match(LEGACY_SENTRY_ORG_RE)?.[1] ?? null
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function withSentryProjects(
|
|
441
|
+
migration: Migration,
|
|
442
|
+
config: Record<string, unknown>,
|
|
443
|
+
text: string
|
|
444
|
+
): string {
|
|
445
|
+
const projects = migration.sentryProjects
|
|
446
|
+
|
|
447
|
+
if (Object.keys(projects).length === 0) {
|
|
448
|
+
return text
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const sentry = config.sentry as
|
|
452
|
+
| { projects?: Record<string, string> }
|
|
453
|
+
| undefined
|
|
454
|
+
|
|
455
|
+
if (sentry) {
|
|
456
|
+
const missing = Object.entries(projects).filter(
|
|
457
|
+
([app, slug]) => sentry.projects?.[app] !== slug
|
|
458
|
+
)
|
|
459
|
+
|
|
460
|
+
if (missing.length > 0) {
|
|
461
|
+
migration.manual.push(
|
|
462
|
+
`rc.config.json : ajoute à sentry.projects ${missing.map(([app, slug]) => `"${app}": "${slug}"`).join(", ")}.`
|
|
463
|
+
)
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return text
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
const org = legacySentryOrg(migration.root)
|
|
470
|
+
|
|
471
|
+
if (!org) {
|
|
472
|
+
migration.manual.push(
|
|
473
|
+
`rc.config.json : ajoute "sentry": { "org": "<organisation>", "projects": ${JSON.stringify(projects)} }.`
|
|
474
|
+
)
|
|
475
|
+
return text
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
const block = JSON.stringify({ org, projects }, null, 2).replaceAll(
|
|
479
|
+
"\n",
|
|
480
|
+
"\n "
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
return text.replace(/\s*\}\s*$/, `,\n "sentry": ${block}\n}\n`)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function migratedText(file: string): string {
|
|
487
|
+
const text = readFileSync(file, "utf8")
|
|
488
|
+
|
|
489
|
+
if (file.endsWith("package.json")) {
|
|
490
|
+
return SCRIPT_REWRITES.reduce(
|
|
491
|
+
(next, [pattern, replacement]) => next.replace(pattern, replacement),
|
|
492
|
+
text
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
return text
|
|
497
|
+
.replace(LEGACY_IMPORT_RE, KIT_PACKAGE)
|
|
498
|
+
.replace(BUILD_IMPORT_RE, "")
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function referencingFiles(root: string): string[] {
|
|
502
|
+
return [
|
|
503
|
+
...sourceFiles(root),
|
|
504
|
+
...listWorkspaces(root).map((workspace) =>
|
|
505
|
+
join(workspace.dir, "package.json")
|
|
506
|
+
),
|
|
507
|
+
]
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function stillUsedScripts(
|
|
511
|
+
migration: Migration,
|
|
512
|
+
candidates: string[]
|
|
513
|
+
): Set<string> {
|
|
514
|
+
const texts = referencingFiles(migration.root).map((file) => ({
|
|
515
|
+
rel: migration.rel(file),
|
|
516
|
+
text: migratedText(file),
|
|
517
|
+
}))
|
|
518
|
+
const kept = new Set<string>()
|
|
519
|
+
let changed = true
|
|
520
|
+
|
|
521
|
+
while (changed) {
|
|
522
|
+
changed = false
|
|
523
|
+
|
|
524
|
+
for (const script of candidates) {
|
|
525
|
+
const name = basename(script, ".ts")
|
|
526
|
+
const used = texts.some(
|
|
527
|
+
({ rel, text }) =>
|
|
528
|
+
(!candidates.includes(rel) || kept.has(rel)) &&
|
|
529
|
+
(text.includes(`scripts/${name}`) ||
|
|
530
|
+
(rel.startsWith("scripts/") && text.includes(`./${name}`)))
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
if (used && !kept.has(script)) {
|
|
534
|
+
kept.add(script)
|
|
535
|
+
changed = true
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return kept
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function removeLegacyScripts(migration: Migration): void {
|
|
544
|
+
const bootstrap = join(migration.root, LEGACY_SCRIPTS.bootstrap)
|
|
545
|
+
|
|
546
|
+
if (existsSync(bootstrap)) {
|
|
547
|
+
migration.remove(bootstrap, "le kit vient du registre npm")
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const replaced: Record<string, string> = {
|
|
551
|
+
[LEGACY_SCRIPTS.ciOnly]: "remplacé par rc ci:only",
|
|
552
|
+
[LEGACY_SCRIPTS.sourcemaps]: "remplacé par rc sentry:sourcemaps",
|
|
553
|
+
[LEGACY_SCRIPTS.commitSha]: `remplacé par ${KIT_PACKAGE}/build`,
|
|
554
|
+
[LEGACY_SCRIPTS.publicEnv]: `remplacé par ${KIT_PACKAGE}/build`,
|
|
555
|
+
}
|
|
556
|
+
const candidates = Object.keys(replaced).filter((script) =>
|
|
557
|
+
existsSync(join(migration.root, script))
|
|
558
|
+
)
|
|
559
|
+
const kept = stillUsedScripts(migration, candidates)
|
|
560
|
+
|
|
561
|
+
for (const script of candidates) {
|
|
562
|
+
if (kept.has(script)) {
|
|
563
|
+
migration.manual.push(
|
|
564
|
+
`${script} est encore utilisé : remplace ses usages (${replaced[script]}), puis supprime-le.`
|
|
565
|
+
)
|
|
566
|
+
} else {
|
|
567
|
+
migration.remove(join(migration.root, script), replaced[script] ?? "")
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function reportDocs(migration: Migration): void {
|
|
573
|
+
const stale = sourceFiles(migration.root, DOC_EXTENSIONS)
|
|
574
|
+
.map((file) => migration.rel(file))
|
|
575
|
+
.filter(
|
|
576
|
+
(rel) =>
|
|
577
|
+
!["CLAUDE.md", "AGENTS.md"].includes(rel) &&
|
|
578
|
+
STALE_DOC_RE.test(readFileSync(join(migration.root, rel), "utf8"))
|
|
579
|
+
)
|
|
580
|
+
|
|
581
|
+
if (stale.length > 0) {
|
|
582
|
+
migration.manual.push(
|
|
583
|
+
`Documentation qui décrit encore le clone voisin, op:sync ou les anciens scripts : ${stale.join(", ")}.`
|
|
584
|
+
)
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function reportWorkflows(migration: Migration): void {
|
|
589
|
+
const dir = join(migration.root, ".github", "workflows")
|
|
590
|
+
|
|
591
|
+
if (!existsSync(dir)) {
|
|
592
|
+
return
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
for (const entry of readdirSync(dir)) {
|
|
596
|
+
const text = readFileSync(join(dir, entry), "utf8")
|
|
597
|
+
|
|
598
|
+
if (/_rc-kit|\.rc-kit|RC_KIT_TOKEN|repository:\s*\S+\/rc-kit/.test(text)) {
|
|
599
|
+
migration.manual.push(
|
|
600
|
+
`.github/workflows/${entry} : retire le checkout du kit, son déplacement et « bun install --cwd ../_rc-kit » ; reprends template/.github/workflows/ci.yml du kit.`
|
|
601
|
+
)
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
export function migrateToKitPackage(input: MigrationInput): MigrationResult {
|
|
607
|
+
const migration = new Migration(input.root, input.dryRun ?? false)
|
|
608
|
+
const spec = `^${input.kitVersion}`
|
|
609
|
+
|
|
610
|
+
migrateManifests(migration, spec)
|
|
611
|
+
migrateSources(migration)
|
|
612
|
+
migrateAgentFiles(migration)
|
|
613
|
+
migrateRcConfig(migration, input.kitVersion)
|
|
614
|
+
removeLegacyScripts(migration)
|
|
615
|
+
reportWorkflows(migration)
|
|
616
|
+
reportDocs(migration)
|
|
617
|
+
|
|
618
|
+
migration.manual.push(
|
|
619
|
+
"Workers Builds : retire RC_KIT_TOKEN des variables de build s'il y figure ; les commandes de build et de déploiement ne changent pas.",
|
|
620
|
+
"bun install, puis bun run lint:fix, bun run lint, bun run check:types, bun run test et rc audit."
|
|
621
|
+
)
|
|
622
|
+
|
|
623
|
+
return { changes: migration.changes, manual: migration.manual }
|
|
624
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { mkdirSync, symlinkSync } from "node:fs"
|
|
3
|
+
import { homedir } from "node:os"
|
|
4
|
+
import { join, resolve } from "node:path"
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
hasLfAttributes,
|
|
8
|
+
installedKitDir,
|
|
9
|
+
isLocalSpec,
|
|
10
|
+
isPortableImport,
|
|
11
|
+
linkedKitTarget,
|
|
12
|
+
RULES_IMPORT,
|
|
13
|
+
resolveImport,
|
|
14
|
+
rulesImportsOf,
|
|
15
|
+
toPosixPath,
|
|
16
|
+
} from "./kit-package"
|
|
17
|
+
import { tempDir } from "./test-utils"
|
|
18
|
+
|
|
19
|
+
describe("kit-package", () => {
|
|
20
|
+
test("imports the rules from the installed package", () => {
|
|
21
|
+
expect(RULES_IMPORT).toBe(
|
|
22
|
+
"@node_modules/@react-consulting/rc-kit/rules/index.md"
|
|
23
|
+
)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test("lists the rules imports of an instructions file", () => {
|
|
27
|
+
expect(
|
|
28
|
+
rulesImportsOf(
|
|
29
|
+
"@node_modules/@react-consulting/rc-kit/rules/index.md\n\n# Projet\n@~/code/kit/rules/index.md\nvoir @rules/index.md dans le texte\n"
|
|
30
|
+
)
|
|
31
|
+
).toEqual([
|
|
32
|
+
"node_modules/@react-consulting/rc-kit/rules/index.md",
|
|
33
|
+
"~/code/kit/rules/index.md",
|
|
34
|
+
])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test("accepts only relative imports", () => {
|
|
38
|
+
expect(
|
|
39
|
+
isPortableImport("node_modules/@react-consulting/rc-kit/rules/index.md")
|
|
40
|
+
).toBe(true)
|
|
41
|
+
expect(isPortableImport("~/code/kit/rules/index.md")).toBe(false)
|
|
42
|
+
expect(isPortableImport("/srv/kit/rules/index.md")).toBe(false)
|
|
43
|
+
expect(isPortableImport("C:/code/kit/rules/index.md")).toBe(false)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test("resolves an import from the project or the home directory", () => {
|
|
47
|
+
expect(resolveImport("node_modules/x/rules/index.md", "/p/app")).toBe(
|
|
48
|
+
resolve("/p/app", "node_modules/x/rules/index.md")
|
|
49
|
+
)
|
|
50
|
+
expect(resolveImport("~/x/rules/index.md", "/p/app")).toBe(
|
|
51
|
+
join(homedir(), "x/rules/index.md")
|
|
52
|
+
)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
test("detects LF line endings in .gitattributes", () => {
|
|
56
|
+
expect(hasLfAttributes("* text=auto eol=lf\n")).toBe(true)
|
|
57
|
+
expect(hasLfAttributes("*.png binary\n* text=auto eol=lf\n")).toBe(true)
|
|
58
|
+
expect(hasLfAttributes("* text=auto\n")).toBe(false)
|
|
59
|
+
expect(hasLfAttributes(null)).toBe(false)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
test("writes Windows paths with forward slashes", () => {
|
|
63
|
+
expect(toPosixPath("..\\kit")).toBe("../kit")
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test("tells a published version from a local spec", () => {
|
|
67
|
+
expect(isLocalSpec("^0.12.1")).toBe(false)
|
|
68
|
+
expect(isLocalSpec("link:../kit")).toBe(true)
|
|
69
|
+
expect(isLocalSpec("file:../kit")).toBe(true)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
test("finds the clone behind a bun link", () => {
|
|
73
|
+
const root = tempDir()
|
|
74
|
+
const clone = tempDir()
|
|
75
|
+
|
|
76
|
+
expect(linkedKitTarget(root)).toBeUndefined()
|
|
77
|
+
|
|
78
|
+
mkdirSync(join(installedKitDir(root), ".."), { recursive: true })
|
|
79
|
+
symlinkSync(clone, installedKitDir(root), "junction")
|
|
80
|
+
|
|
81
|
+
expect(linkedKitTarget(root)).toBe(resolve(clone))
|
|
82
|
+
})
|
|
83
|
+
})
|