@react-consulting/rc-kit 0.0.0-stage → 0.13.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/LICENSE +21 -0
- package/README.md +94 -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 +212 -0
- package/devkit/lib/kit-migrate.ts +617 -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,315 @@
|
|
|
1
|
+
import {
|
|
2
|
+
copyFileSync,
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readdirSync,
|
|
6
|
+
readFileSync,
|
|
7
|
+
statSync,
|
|
8
|
+
writeFileSync,
|
|
9
|
+
} from "node:fs"
|
|
10
|
+
import { basename, dirname, join, relative, resolve } from "node:path"
|
|
11
|
+
|
|
12
|
+
import { parseJsonc } from "./jsonc"
|
|
13
|
+
import { KIT_PACKAGE, KIT_SCHEMA_PATH, toPosixPath } from "./kit-package"
|
|
14
|
+
import { type Account, isAccount, isAccountId, isValidPrefix } from "./naming"
|
|
15
|
+
import type { Runner } from "./process"
|
|
16
|
+
|
|
17
|
+
export const TEMPLATE_TOKENS = {
|
|
18
|
+
prefix: "tpl",
|
|
19
|
+
scope: "@tpl/",
|
|
20
|
+
slug: "rc-template",
|
|
21
|
+
title: "RC Template",
|
|
22
|
+
account: "example",
|
|
23
|
+
accountId: "00000000000000000000000000000000",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const EXCLUDED_NAMES = new Set([
|
|
27
|
+
"node_modules",
|
|
28
|
+
".turbo",
|
|
29
|
+
".wrangler",
|
|
30
|
+
"dist",
|
|
31
|
+
".output",
|
|
32
|
+
".tanstack",
|
|
33
|
+
".astro",
|
|
34
|
+
"bun.lock",
|
|
35
|
+
".git",
|
|
36
|
+
".DS_Store",
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
// npm drops every .gitignore from a published package, so the template ships it without the dot.
|
|
40
|
+
const RENAMED_FILES: Record<string, string> = { gitignore: ".gitignore" }
|
|
41
|
+
// npm drops symlinks too: the template's AGENTS.md (a link to CLAUDE.md) is rebuilt as a copy.
|
|
42
|
+
const MIRRORED_FILES: Record<string, string> = { "AGENTS.md": "CLAUDE.md" }
|
|
43
|
+
|
|
44
|
+
const LOCAL_SECRET_RE = /^(?:\.dev\.vars|\.env)(?:\..+)?$/
|
|
45
|
+
const SLUG_RE = /^[a-z][a-z0-9-]*$/
|
|
46
|
+
const PREFIX_TOKEN_RE = /(?<![A-Za-z0-9_])tpl-(?=[a-z0-9])/g
|
|
47
|
+
const DEPENDENCY_FIELDS = [
|
|
48
|
+
"dependencies",
|
|
49
|
+
"devDependencies",
|
|
50
|
+
"peerDependencies",
|
|
51
|
+
"optionalDependencies",
|
|
52
|
+
] as const
|
|
53
|
+
|
|
54
|
+
export interface ScaffoldTokens {
|
|
55
|
+
prefix: string
|
|
56
|
+
slug: string
|
|
57
|
+
title: string
|
|
58
|
+
account: Account
|
|
59
|
+
accountId: string
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ScaffoldOptions extends ScaffoldTokens {
|
|
63
|
+
templateDir: string
|
|
64
|
+
targetDir: string
|
|
65
|
+
kitPath?: string
|
|
66
|
+
kitSpec?: string
|
|
67
|
+
kitVersion?: string
|
|
68
|
+
sentryOrg?: string
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function titleFromSlug(slug: string): string {
|
|
72
|
+
return slug
|
|
73
|
+
.split("-")
|
|
74
|
+
.filter(Boolean)
|
|
75
|
+
.map((word) => word[0]?.toUpperCase() + word.slice(1))
|
|
76
|
+
.join(" ")
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function isExcluded(name: string): boolean {
|
|
80
|
+
if (EXCLUDED_NAMES.has(name)) {
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return LOCAL_SECRET_RE.test(name) && !name.endsWith(".example")
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function replaceTokens(text: string, tokens: ScaffoldTokens): string {
|
|
88
|
+
return text
|
|
89
|
+
.replaceAll(TEMPLATE_TOKENS.scope, `@${tokens.slug}/`)
|
|
90
|
+
.replaceAll(TEMPLATE_TOKENS.slug, tokens.slug)
|
|
91
|
+
.replaceAll(TEMPLATE_TOKENS.title, tokens.title)
|
|
92
|
+
.replaceAll(TEMPLATE_TOKENS.accountId, tokens.accountId)
|
|
93
|
+
.replace(PREFIX_TOKEN_RE, `${tokens.prefix}-`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function validateScaffold(options: ScaffoldOptions): string[] {
|
|
97
|
+
const errors: string[] = []
|
|
98
|
+
|
|
99
|
+
if (!SLUG_RE.test(options.slug)) {
|
|
100
|
+
errors.push(
|
|
101
|
+
`--name « ${options.slug} » : slug en minuscules et tirets attendu (ex. contoso-mode).`
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!isValidPrefix(options.prefix)) {
|
|
106
|
+
errors.push(
|
|
107
|
+
`--prefix « ${options.prefix} » : trois lettres minuscules attendues.`
|
|
108
|
+
)
|
|
109
|
+
} else if (options.prefix === TEMPLATE_TOKENS.prefix) {
|
|
110
|
+
errors.push(`--prefix « tpl » est le jeton du modèle.`)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (!isAccount(options.account)) {
|
|
114
|
+
errors.push(
|
|
115
|
+
`--account « ${String(options.account)} » : clé de l'entité propriétaire attendue, en minuscules et tirets (la même que dans les autres projets de l'entité).`
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!(options.kitSpec || options.kitPath || options.kitVersion)) {
|
|
120
|
+
errors.push(
|
|
121
|
+
`Version de ${KIT_PACKAGE} inconnue : passe --kit-spec ou --kit-path.`
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (
|
|
126
|
+
!isAccountId(options.accountId) ||
|
|
127
|
+
options.accountId === TEMPLATE_TOKENS.accountId
|
|
128
|
+
) {
|
|
129
|
+
errors.push(
|
|
130
|
+
`--account-id « ${options.accountId} » : identifiant du compte Cloudflare attendu (32 caractères hexadécimaux, visible dans l'URL du tableau de bord).`
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (!existsSync(options.templateDir)) {
|
|
135
|
+
errors.push(`Modèle introuvable : ${options.templateDir}.`)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
existsSync(options.targetDir) &&
|
|
140
|
+
readdirSync(options.targetDir).length > 0
|
|
141
|
+
) {
|
|
142
|
+
errors.push(`${options.targetDir} existe déjà et n'est pas vide.`)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return errors
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function isBinary(buffer: Buffer): boolean {
|
|
149
|
+
return buffer.subarray(0, 8000).includes(0)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function kitSpecFor(dir: string, options: ScaffoldOptions): string {
|
|
153
|
+
if (options.kitSpec) {
|
|
154
|
+
return options.kitSpec
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (options.kitPath) {
|
|
158
|
+
return `link:${toPosixPath(relative(dir, resolve(options.kitPath))) || "."}`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return `^${options.kitVersion}`
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function rewriteKitDependency(file: string, options: ScaffoldOptions): void {
|
|
165
|
+
const pkg = JSON.parse(readFileSync(file, "utf8")) as Record<string, unknown>
|
|
166
|
+
let changed = false
|
|
167
|
+
|
|
168
|
+
for (const field of DEPENDENCY_FIELDS) {
|
|
169
|
+
const deps = pkg[field] as Record<string, string> | undefined
|
|
170
|
+
|
|
171
|
+
if (deps && Object.hasOwn(deps, KIT_PACKAGE)) {
|
|
172
|
+
deps[KIT_PACKAGE] = kitSpecFor(dirname(file), options)
|
|
173
|
+
changed = true
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (changed) {
|
|
178
|
+
writeFileSync(file, `${JSON.stringify(pkg, null, 2)}\n`)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function rewriteRcConfig(file: string, options: ScaffoldOptions): void {
|
|
183
|
+
const config = parseJsonc<Record<string, unknown>>(readFileSync(file, "utf8"))
|
|
184
|
+
|
|
185
|
+
config.$schema = KIT_SCHEMA_PATH
|
|
186
|
+
config.project = options.slug
|
|
187
|
+
config.prefix = options.prefix
|
|
188
|
+
config.account = options.account
|
|
189
|
+
|
|
190
|
+
if (options.kitVersion) {
|
|
191
|
+
config.kit = `>=${options.kitVersion}`
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (options.sentryOrg && config.sentry && typeof config.sentry === "object") {
|
|
195
|
+
config.sentry = { ...config.sentry, org: options.sentryOrg }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function copyTree(
|
|
202
|
+
source: string,
|
|
203
|
+
target: string,
|
|
204
|
+
options: ScaffoldOptions,
|
|
205
|
+
written: string[]
|
|
206
|
+
): void {
|
|
207
|
+
mkdirSync(target, { recursive: true })
|
|
208
|
+
|
|
209
|
+
for (const entry of readdirSync(source)) {
|
|
210
|
+
if (isExcluded(entry)) {
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const from = join(source, entry)
|
|
215
|
+
const to = join(
|
|
216
|
+
target,
|
|
217
|
+
RENAMED_FILES[entry] ?? replaceTokens(entry, options)
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
if (statSync(from).isDirectory()) {
|
|
221
|
+
copyTree(from, to, options, written)
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const buffer = readFileSync(from)
|
|
226
|
+
|
|
227
|
+
if (isBinary(buffer)) {
|
|
228
|
+
copyFileSync(from, to)
|
|
229
|
+
} else {
|
|
230
|
+
writeFileSync(to, replaceTokens(buffer.toString("utf8"), options))
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
written.push(to)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function restoreMirroredFiles(targetDir: string, written: string[]): void {
|
|
238
|
+
for (const [mirror, source] of Object.entries(MIRRORED_FILES)) {
|
|
239
|
+
const to = join(targetDir, mirror)
|
|
240
|
+
const from = join(targetDir, source)
|
|
241
|
+
|
|
242
|
+
if (existsSync(to) || !existsSync(from)) {
|
|
243
|
+
continue
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
copyFileSync(from, to)
|
|
247
|
+
written.push(to)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function scaffold(options: ScaffoldOptions): string[] {
|
|
252
|
+
const errors = validateScaffold(options)
|
|
253
|
+
|
|
254
|
+
if (errors.length > 0) {
|
|
255
|
+
throw new Error(errors.join("\n"))
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const written: string[] = []
|
|
259
|
+
|
|
260
|
+
copyTree(options.templateDir, options.targetDir, options, written)
|
|
261
|
+
restoreMirroredFiles(options.targetDir, written)
|
|
262
|
+
|
|
263
|
+
for (const file of written) {
|
|
264
|
+
if (basename(file) === "package.json") {
|
|
265
|
+
rewriteKitDependency(file, options)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const rcConfig = join(options.targetDir, "rc.config.json")
|
|
270
|
+
|
|
271
|
+
if (existsSync(rcConfig)) {
|
|
272
|
+
rewriteRcConfig(rcConfig, options)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return written
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export const FINISH_COMMANDS = [
|
|
279
|
+
["bun", "install"],
|
|
280
|
+
["bun", "run", "format"],
|
|
281
|
+
]
|
|
282
|
+
|
|
283
|
+
export interface FinishInput {
|
|
284
|
+
targetDir: string
|
|
285
|
+
install: boolean
|
|
286
|
+
runner: Runner
|
|
287
|
+
log?: (line: string) => void
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function finishProject(input: FinishInput): boolean {
|
|
291
|
+
const log = input.log ?? console.log
|
|
292
|
+
|
|
293
|
+
if (!input.install) {
|
|
294
|
+
log(
|
|
295
|
+
`À lancer dans ${input.targetDir} :\n${FINISH_COMMANDS.map((command) => ` ${command.join(" ")}`).join("\n")}`
|
|
296
|
+
)
|
|
297
|
+
return true
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
for (const command of FINISH_COMMANDS) {
|
|
301
|
+
log(`$ ${command.join(" ")}`)
|
|
302
|
+
|
|
303
|
+
if (
|
|
304
|
+
input.runner(command, { cwd: input.targetDir, inherit: true })
|
|
305
|
+
.exitCode !== 0
|
|
306
|
+
) {
|
|
307
|
+
log(
|
|
308
|
+
`\`${command.join(" ")}\` a échoué dans ${input.targetDir} : corrige puis relance-la.`
|
|
309
|
+
)
|
|
310
|
+
return false
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
return true
|
|
315
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
parseSecretList,
|
|
5
|
+
routeSecrets,
|
|
6
|
+
secretPayload,
|
|
7
|
+
unroutedFields,
|
|
8
|
+
wranglerTargetArgs,
|
|
9
|
+
} from "./secrets"
|
|
10
|
+
import type { Deployment } from "./wrangler"
|
|
11
|
+
|
|
12
|
+
const SECRETS = {
|
|
13
|
+
BETTER_AUTH_SECRET: "a",
|
|
14
|
+
TURNSTILE_SECRET_KEY: "b",
|
|
15
|
+
WHATSAPP_ACCESS_TOKEN: "c",
|
|
16
|
+
SITE_BUILD_API_TOKEN: "d",
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function deployment(required: string[], usesEnv = true): Deployment {
|
|
20
|
+
return {
|
|
21
|
+
environment: "production",
|
|
22
|
+
name: "adv-admin-prod",
|
|
23
|
+
usesEnv,
|
|
24
|
+
level: { name: "adv-admin-prod", secrets: { required } },
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe("routeSecrets", () => {
|
|
29
|
+
test("sends the required keys plus the optional ones Infisical fills", () => {
|
|
30
|
+
const route = routeSecrets({
|
|
31
|
+
app: "admin",
|
|
32
|
+
deployment: deployment(["BETTER_AUTH_SECRET", "TURNSTILE_SECRET_KEY"]),
|
|
33
|
+
optionalSecrets: ["WHATSAPP_ACCESS_TOKEN", "WHATSAPP_APP_SECRET"],
|
|
34
|
+
values: SECRETS,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
expect(route).toEqual({
|
|
38
|
+
app: "admin",
|
|
39
|
+
worker: "adv-admin-prod",
|
|
40
|
+
required: ["BETTER_AUTH_SECRET", "TURNSTILE_SECRET_KEY"],
|
|
41
|
+
optional: ["WHATSAPP_ACCESS_TOKEN"],
|
|
42
|
+
missing: [],
|
|
43
|
+
keys: [
|
|
44
|
+
"BETTER_AUTH_SECRET",
|
|
45
|
+
"TURNSTILE_SECRET_KEY",
|
|
46
|
+
"WHATSAPP_ACCESS_TOKEN",
|
|
47
|
+
],
|
|
48
|
+
})
|
|
49
|
+
expect(secretPayload(route, SECRETS, ["OLD_KEY"])).toEqual({
|
|
50
|
+
BETTER_AUTH_SECRET: "a",
|
|
51
|
+
TURNSTILE_SECRET_KEY: "b",
|
|
52
|
+
WHATSAPP_ACCESS_TOKEN: "c",
|
|
53
|
+
OLD_KEY: null,
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test("reports a required key Infisical leaves empty", () => {
|
|
58
|
+
const route = routeSecrets({
|
|
59
|
+
app: "admin",
|
|
60
|
+
deployment: deployment(["BETTER_AUTH_SECRET", "RESEND_KEY"]),
|
|
61
|
+
values: SECRETS,
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
expect(route.missing).toEqual(["RESEND_KEY"])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test("lists the Infisical secrets no Worker receives", () => {
|
|
68
|
+
const route = routeSecrets({
|
|
69
|
+
app: "admin",
|
|
70
|
+
deployment: deployment(["BETTER_AUTH_SECRET"]),
|
|
71
|
+
values: SECRETS,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
expect(unroutedFields(SECRETS, [route], ["WHATSAPP_ACCESS_TOKEN"])).toEqual(
|
|
75
|
+
["TURNSTILE_SECRET_KEY", "SITE_BUILD_API_TOKEN"]
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe("wrangler helpers", () => {
|
|
81
|
+
test("targets the source config, and the env when the Worker lives in one", () => {
|
|
82
|
+
expect(wranglerTargetArgs("/p/wrangler.jsonc", deployment([]))).toEqual([
|
|
83
|
+
"--config",
|
|
84
|
+
"/p/wrangler.jsonc",
|
|
85
|
+
"--env",
|
|
86
|
+
"production",
|
|
87
|
+
])
|
|
88
|
+
expect(
|
|
89
|
+
wranglerTargetArgs("/p/wrangler.jsonc", deployment([], false))
|
|
90
|
+
).toEqual(["--config", "/p/wrangler.jsonc"])
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
test("reads the JSON of wrangler secret list, banner included", () => {
|
|
94
|
+
expect(
|
|
95
|
+
parseSecretList(
|
|
96
|
+
'⛅️ wrangler 4.0\n[{"name":"A","type":"secret_text"},{"name":"B"}]'
|
|
97
|
+
)
|
|
98
|
+
).toEqual(["A", "B"])
|
|
99
|
+
expect(parseSecretList("not logged in")).toBeNull()
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { Runner } from "./process"
|
|
2
|
+
import type { Deployment } from "./wrangler"
|
|
3
|
+
import { requiredSecrets } from "./wrangler"
|
|
4
|
+
|
|
5
|
+
export interface SecretRoute {
|
|
6
|
+
app: string
|
|
7
|
+
worker: string
|
|
8
|
+
required: string[]
|
|
9
|
+
optional: string[]
|
|
10
|
+
missing: string[]
|
|
11
|
+
keys: string[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function routeSecrets(input: {
|
|
15
|
+
app: string
|
|
16
|
+
deployment: Deployment
|
|
17
|
+
optionalSecrets?: readonly string[]
|
|
18
|
+
values: Record<string, string>
|
|
19
|
+
}): SecretRoute {
|
|
20
|
+
const required = requiredSecrets(input.deployment.level)
|
|
21
|
+
const optional = (input.optionalSecrets ?? []).filter(
|
|
22
|
+
(key) => !required.includes(key) && Boolean(input.values[key])
|
|
23
|
+
)
|
|
24
|
+
const missing = required.filter((key) => !input.values[key])
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
app: input.app,
|
|
28
|
+
worker: input.deployment.name,
|
|
29
|
+
required,
|
|
30
|
+
optional,
|
|
31
|
+
missing,
|
|
32
|
+
keys: [...required.filter((key) => input.values[key]), ...optional],
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function unroutedFields(
|
|
37
|
+
values: Record<string, string>,
|
|
38
|
+
routes: SecretRoute[],
|
|
39
|
+
declaredOptional: readonly string[] = []
|
|
40
|
+
): string[] {
|
|
41
|
+
const routed = new Set([
|
|
42
|
+
...routes.flatMap((route) => [...route.required, ...route.keys]),
|
|
43
|
+
...declaredOptional,
|
|
44
|
+
])
|
|
45
|
+
|
|
46
|
+
return Object.keys(values).filter((key) => !routed.has(key))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function secretPayload(
|
|
50
|
+
route: SecretRoute,
|
|
51
|
+
values: Record<string, string>,
|
|
52
|
+
stale: string[] = []
|
|
53
|
+
): Record<string, string | null> {
|
|
54
|
+
return {
|
|
55
|
+
...Object.fromEntries(route.keys.map((key) => [key, values[key] ?? ""])),
|
|
56
|
+
...Object.fromEntries(stale.map((key) => [key, null])),
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function wranglerTargetArgs(
|
|
61
|
+
configPath: string,
|
|
62
|
+
deployment: Deployment
|
|
63
|
+
): string[] {
|
|
64
|
+
return [
|
|
65
|
+
"--config",
|
|
66
|
+
configPath,
|
|
67
|
+
...(deployment.usesEnv ? ["--env", deployment.environment] : []),
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function parseSecretList(stdout: string): string[] | null {
|
|
72
|
+
const trimmed = stdout.trim()
|
|
73
|
+
const start = trimmed.indexOf("[")
|
|
74
|
+
|
|
75
|
+
if (start === -1) {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
const rows = JSON.parse(trimmed.slice(start)) as { name?: unknown }[]
|
|
81
|
+
|
|
82
|
+
return rows
|
|
83
|
+
.map((row) => row.name)
|
|
84
|
+
.filter((name): name is string => typeof name === "string")
|
|
85
|
+
} catch {
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function listDeployedSecrets(input: {
|
|
91
|
+
appDir: string
|
|
92
|
+
configPath: string
|
|
93
|
+
deployment: Deployment
|
|
94
|
+
runner: Runner
|
|
95
|
+
}): string[] {
|
|
96
|
+
const result = input.runner(
|
|
97
|
+
[
|
|
98
|
+
"bun",
|
|
99
|
+
"x",
|
|
100
|
+
"wrangler",
|
|
101
|
+
"secret",
|
|
102
|
+
"list",
|
|
103
|
+
"--format",
|
|
104
|
+
"json",
|
|
105
|
+
...wranglerTargetArgs(input.configPath, input.deployment),
|
|
106
|
+
],
|
|
107
|
+
{ cwd: input.appDir }
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
if (result.exitCode !== 0) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`\`wrangler secret list\` a échoué pour ${input.deployment.name}.\n${(result.stderr || result.stdout).trim()}`
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const names = parseSecretList(result.stdout)
|
|
117
|
+
|
|
118
|
+
if (!names) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`Liste des secrets de ${input.deployment.name} illisible :\n${result.stdout.trim()}`
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return names
|
|
125
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { afterAll, describe, expect, test } from "bun:test"
|
|
2
|
+
import { existsSync } from "node:fs"
|
|
3
|
+
import { join } from "node:path"
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
planSourcemaps,
|
|
7
|
+
removeSourceMaps,
|
|
8
|
+
sentryCliCommands,
|
|
9
|
+
} from "./sourcemaps"
|
|
10
|
+
import { cleanupTempDirs, tempDir, writeTree } from "./test-utils"
|
|
11
|
+
|
|
12
|
+
afterAll(cleanupTempDirs)
|
|
13
|
+
|
|
14
|
+
const SENTRY = { org: "acme", projects: { admin: "gfa-admin" } }
|
|
15
|
+
|
|
16
|
+
describe("planSourcemaps", () => {
|
|
17
|
+
test("uploads under the build commit when a token is set", () => {
|
|
18
|
+
const plan = planSourcemaps({
|
|
19
|
+
sentry: SENTRY,
|
|
20
|
+
app: "admin",
|
|
21
|
+
release: "abc123",
|
|
22
|
+
env: { SENTRY_AUTH_TOKEN: "x" },
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
expect(plan).toEqual({
|
|
26
|
+
action: "upload",
|
|
27
|
+
project: "gfa-admin",
|
|
28
|
+
release: "abc123",
|
|
29
|
+
url: "https://de.sentry.io/",
|
|
30
|
+
})
|
|
31
|
+
expect(
|
|
32
|
+
plan.action === "upload" && sentryCliCommands(plan, "acme", ["dist"])
|
|
33
|
+
).toEqual([
|
|
34
|
+
["sourcemaps", "inject", "dist"],
|
|
35
|
+
[
|
|
36
|
+
"sourcemaps",
|
|
37
|
+
"upload",
|
|
38
|
+
"--org",
|
|
39
|
+
"acme",
|
|
40
|
+
"--project",
|
|
41
|
+
"gfa-admin",
|
|
42
|
+
"--release",
|
|
43
|
+
"abc123",
|
|
44
|
+
"dist",
|
|
45
|
+
],
|
|
46
|
+
])
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("skips locally and fails in Workers Builds without a token", () => {
|
|
50
|
+
const input = { sentry: SENTRY, app: "admin", release: "abc123" }
|
|
51
|
+
|
|
52
|
+
expect(planSourcemaps({ ...input, env: {} }).action).toBe("skip")
|
|
53
|
+
expect(planSourcemaps({ ...input, env: { WORKERS_CI: "1" } }).action).toBe(
|
|
54
|
+
"fail"
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test("fails for an app without a Sentry project or without a release", () => {
|
|
59
|
+
expect(
|
|
60
|
+
planSourcemaps({ sentry: SENTRY, app: "web", release: "a", env: {} })
|
|
61
|
+
.action
|
|
62
|
+
).toBe("fail")
|
|
63
|
+
expect(
|
|
64
|
+
planSourcemaps({
|
|
65
|
+
sentry: SENTRY,
|
|
66
|
+
app: "admin",
|
|
67
|
+
release: null,
|
|
68
|
+
env: { SENTRY_AUTH_TOKEN: "x" },
|
|
69
|
+
}).action
|
|
70
|
+
).toBe("fail")
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe("removeSourceMaps", () => {
|
|
75
|
+
test("deletes every .map file below the directory", () => {
|
|
76
|
+
const dir = writeTree(tempDir(), {
|
|
77
|
+
"a.js": "",
|
|
78
|
+
"a.js.map": "",
|
|
79
|
+
"assets/b.js.map": "",
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
expect(removeSourceMaps(dir)).toBe(2)
|
|
83
|
+
expect(existsSync(join(dir, "a.js"))).toBe(true)
|
|
84
|
+
expect(existsSync(join(dir, "assets/b.js.map"))).toBe(false)
|
|
85
|
+
})
|
|
86
|
+
})
|