@rebasepro/cli 0.23.0 → 0.24.1-canary.g56af4a4
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/README.md +19 -3
- package/bin/rebase.js +4 -1
- package/dist/agent-setup-B31F00DC.js +324 -0
- package/dist/agent-setup-B31F00DC.js.map +1 -0
- package/dist/api-keys-BPBi5nOF.js +524 -0
- package/dist/api-keys-BPBi5nOF.js.map +1 -0
- package/dist/apps-CPXNElX4.js +256 -0
- package/dist/apps-CPXNElX4.js.map +1 -0
- package/dist/args-BnmsEXvu.js +109 -0
- package/dist/args-BnmsEXvu.js.map +1 -0
- package/dist/atlas-dev-database-DTMuEScS.js +62 -0
- package/dist/atlas-dev-database-DTMuEScS.js.map +1 -0
- package/dist/auth-DvY94ZuL.js +395 -0
- package/dist/auth-DvY94ZuL.js.map +1 -0
- package/dist/branch-pointer-DIhKbQLp.js +2 -0
- package/dist/build-CFwUx-Ff.js +336 -0
- package/dist/build-CFwUx-Ff.js.map +1 -0
- package/dist/bundle-BQhP_xiA.js +1617 -0
- package/dist/bundle-BQhP_xiA.js.map +1 -0
- package/dist/bundle.d.ts +6 -2
- package/dist/cli.d.ts +23 -2
- package/dist/cloud-CkTr-yt0.js +9640 -0
- package/dist/cloud-CkTr-yt0.js.map +1 -0
- package/dist/collection-drift-BKj_BoMq.js +106 -0
- package/dist/collection-drift-BKj_BoMq.js.map +1 -0
- package/dist/commands/__test_support__/parser-specs.d.ts +13 -0
- package/dist/commands/agent-setup.d.ts +116 -0
- package/dist/commands/api-keys.d.ts +86 -23
- package/dist/commands/apps.d.ts +17 -0
- package/dist/commands/auth.d.ts +7 -0
- package/dist/commands/build.d.ts +5 -1
- package/dist/commands/cloud/auth.d.ts +4 -3
- package/dist/commands/cloud/bundle-deploy.d.ts +45 -0
- package/dist/commands/cloud/context.d.ts +44 -5
- package/dist/commands/cloud/cron.d.ts +53 -0
- package/dist/commands/cloud/debug.d.ts +134 -0
- package/dist/commands/cloud/index.d.ts +89 -12
- package/dist/commands/cloud/token-capabilities.d.ts +76 -0
- package/dist/commands/cloud/tokens.d.ts +23 -0
- package/dist/commands/db.d.ts +52 -25
- package/dist/commands/dev.d.ts +181 -7
- package/dist/commands/doctor.d.ts +5 -0
- package/dist/commands/generate_sdk.d.ts +29 -2
- package/dist/commands/init.d.ts +57 -14
- package/dist/commands/schema.d.ts +6 -0
- package/dist/commands/skills.d.ts +126 -7
- package/dist/commands/start.d.ts +29 -0
- package/dist/commands/storage.d.ts +46 -0
- package/dist/consent-BWHaYx5p.js +76 -0
- package/dist/consent-BWHaYx5p.js.map +1 -0
- package/dist/context-BqhRydBg.js +1234 -0
- package/dist/context-BqhRydBg.js.map +1 -0
- package/dist/daemon-DBn-shxX.js +2 -0
- package/dist/{daemon-entry-LTFKtpHy.js → daemon-entry-Da-D3rmH.js} +3 -4
- package/dist/daemon-entry-Da-D3rmH.js.map +1 -0
- package/dist/db-CMpBK3sv.js +1252 -0
- package/dist/db-CMpBK3sv.js.map +1 -0
- package/dist/derive-RPIsAVO4.js +474 -0
- package/dist/derive-RPIsAVO4.js.map +1 -0
- package/dist/dev-C9P5Yp9k.js +1593 -0
- package/dist/dev-C9P5Yp9k.js.map +1 -0
- package/dist/dev-db/atlas-dev-database.d.ts +32 -0
- package/dist/dev-db/daemon-entry.d.ts +13 -0
- package/dist/dev-db/daemon.d.ts +10 -0
- package/dist/dev-db/prepare.d.ts +10 -0
- package/dist/dev-preflight-N1evJL3S.js +2 -0
- package/dist/doctor-DYs-NqFI.js +771 -0
- package/dist/doctor-DYs-NqFI.js.map +1 -0
- package/dist/eject-BT6t37D0.js +335 -0
- package/dist/eject-BT6t37D0.js.map +1 -0
- package/dist/fold-static-C1EtHlfV.js +201 -0
- package/dist/fold-static-C1EtHlfV.js.map +1 -0
- package/dist/fold-static.d.ts +26 -3
- package/dist/function-portability-BIvlvR9q.js +265 -0
- package/dist/function-portability-BIvlvR9q.js.map +1 -0
- package/dist/generate_sdk-UV635zSe.js +477 -0
- package/dist/generate_sdk-UV635zSe.js.map +1 -0
- package/dist/index.es.js +189 -22095
- package/dist/index.es.js.map +1 -1
- package/dist/init-fXeBcxuN.js +1042 -0
- package/dist/init-fXeBcxuN.js.map +1 -0
- package/dist/manifest-DzlC60WX.js +871 -0
- package/dist/manifest-DzlC60WX.js.map +1 -0
- package/dist/manifest.d.ts +41 -1
- package/dist/normalize-imports-CmVdE9iZ.js +100 -0
- package/dist/normalize-imports-CmVdE9iZ.js.map +1 -0
- package/dist/package-manager-DSEOwTqM.js +193 -0
- package/dist/package-manager-DSEOwTqM.js.map +1 -0
- package/dist/path-flags-DUBuI2i1.js +77 -0
- package/dist/path-flags-DUBuI2i1.js.map +1 -0
- package/dist/precompress.d.ts +17 -0
- package/dist/prepare-Btn9Ewbn.js +1052 -0
- package/dist/prepare-Btn9Ewbn.js.map +1 -0
- package/dist/{project-3WCbrrfW.js → project-Wp2zoyeN.js} +34 -184
- package/dist/project-Wp2zoyeN.js.map +1 -0
- package/dist/resolve-CJLkfFV0.js +2 -0
- package/dist/resources-DT1COn_6.js +161 -0
- package/dist/resources-DT1COn_6.js.map +1 -0
- package/dist/schema-BDBWvCHu.js +125 -0
- package/dist/schema-BDBWvCHu.js.map +1 -0
- package/dist/skills-DTFibT1m.js +642 -0
- package/dist/skills-DTFibT1m.js.map +1 -0
- package/dist/start-rU2e3Kp5.js +228 -0
- package/dist/start-rU2e3Kp5.js.map +1 -0
- package/dist/{state-C59Elrnt.js → state-Do7ZJYkF.js} +49 -4
- package/dist/state-Do7ZJYkF.js.map +1 -0
- package/dist/status-BR9oyi-y.js +351 -0
- package/dist/status-BR9oyi-y.js.map +1 -0
- package/dist/storage-DyvrSTH3.js +303 -0
- package/dist/storage-DyvrSTH3.js.map +1 -0
- package/dist/telemetry-CAWNCugs.js +338 -0
- package/dist/telemetry-CAWNCugs.js.map +1 -0
- package/dist/telemetry-DbLqGIBW.js +129 -0
- package/dist/telemetry-DbLqGIBW.js.map +1 -0
- package/dist/unknown-command-DNwDcX3w.js +98 -0
- package/dist/unknown-command-DNwDcX3w.js.map +1 -0
- package/dist/upgrade-D-5-Od96.js +1265 -0
- package/dist/upgrade-D-5-Od96.js.map +1 -0
- package/dist/upgrade.d.ts +14 -2
- package/dist/utils/path-flags.d.ts +18 -0
- package/dist/utils/project.d.ts +16 -0
- package/dist/version-Buyyo1ut.js +58 -0
- package/dist/version-Buyyo1ut.js.map +1 -0
- package/package.json +7 -7
- package/templates/eject/backend/src/env.ts +1 -1
- package/templates/eject/backend/src/index.ts +23 -2
- package/templates/overlays/baas/ai-instructions.md +1 -1
- package/templates/overlays/baas/config/storage.ts +5 -3
- package/templates/template/.cursorrules +1 -1
- package/templates/template/.env.example +10 -6
- package/templates/template/.github/copilot-instructions.md +1 -1
- package/templates/template/.mcp.json +2 -2
- package/templates/template/.windsurfrules +1 -1
- package/templates/template/AGENTS.md +1 -1
- package/templates/template/CLAUDE.md +1 -1
- package/templates/template/README.md +11 -12
- package/templates/template/ai-instructions.md +5 -4
- package/templates/template/backend/functions/hello.ts +8 -0
- package/templates/template/backend/package.json +1 -1
- package/templates/template/config/storage.ts +5 -3
- package/templates/template/docker-compose.yml +6 -6
- package/templates/template/frontend/vite.config.ts +11 -3
- package/templates/template/gitignore +6 -1
- package/templates/template/package.json +4 -3
- package/templates/template/scripts/example.ts +6 -4
- package/dist/branch-pointer-dBiClJ0p.js +0 -111
- package/dist/branch-pointer-dBiClJ0p.js.map +0 -1
- package/dist/constraints-DKGbNfUW.js +0 -48
- package/dist/constraints-DKGbNfUW.js.map +0 -1
- package/dist/daemon-DR9Tk0La.js +0 -355
- package/dist/daemon-DR9Tk0La.js.map +0 -1
- package/dist/daemon-entry-LTFKtpHy.js.map +0 -1
- package/dist/dev-preflight-CNLl4rdo.js +0 -367
- package/dist/dev-preflight-CNLl4rdo.js.map +0 -1
- package/dist/project-3WCbrrfW.js.map +0 -1
- package/dist/resolve-BAeRUBhg.js +0 -74
- package/dist/resolve-BAeRUBhg.js.map +0 -1
- package/dist/state-C59Elrnt.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-DzlC60WX.js","names":[],"sources":["../src/manifest.ts"],"sourcesContent":["/**\n * Loading, validating and synthesizing `rebase.json`.\n *\n * The manifest declares *topology*: which runtime major a project targets and\n * which apps this repository contributes. It is deliberately small — schema,\n * security rules, hooks and functions stay in TypeScript, where a type system\n * can check them.\n *\n * Two properties matter more than the file format itself:\n *\n * - **A missing manifest is never an error.** Every project that exists today\n * predates this file. One is synthesized from the conventions the template\n * already follows, so nothing breaks and nobody is forced to migrate.\n * - **Validation reports every problem at once**, with the path to each. A\n * config file that surfaces its mistakes one run at a time is a bad config\n * file.\n */\nimport fs from \"fs\";\nimport path from \"path\";\nimport {\n findStorageSuffixCollision,\n parseAppAddress,\n reservedPrefixFor,\n type AppAddress,\n type ManagedCompatibility,\n type RebaseAppConfig,\n type RebaseBackendAppConfig,\n type RebaseProjectManifest,\n type RebaseStaticAppConfig\n} from \"@rebasepro/types\";\nimport { MANIFEST_FILENAME } from \"./utils/project\";\n\n/** Runtime range written into new manifests. */\nexport const CURRENT_RUNTIME_RANGE = \"^1\";\n\n/** Conventional locations, matching what `rebase init` scaffolds. */\nexport const DEFAULT_CONFIG_DIR = \"config\";\nexport const DEFAULT_FUNCTIONS_DIR = \"backend/functions\";\nexport const DEFAULT_CRONS_DIR = \"backend/crons\";\nexport const DEFAULT_SCHEMA_FILE = \"backend/src/schema.generated.ts\";\n\nexport interface ManifestValidationIssue {\n /** Dotted path to the offending value, e.g. `apps.web.output`. */\n path: string;\n message: string;\n}\n\nexport interface LoadedManifest {\n manifest: RebaseProjectManifest;\n /** Where it came from — a real file, or inferred from the directory layout. */\n source: \"file\" | \"synthesized\";\n /** Absolute path to `rebase.json`, when one exists. */\n filePath?: string;\n}\n\nexport class ManifestError extends Error {\n constructor(message: string, readonly issues: ManifestValidationIssue[] = []) {\n super(message);\n this.name = \"ManifestError\";\n }\n}\n\nconst APP_TYPES = [\"backend\", \"static\"] as const;\n\n/**\n * App types that used to exist, and what replaced each one.\n *\n * Kept so a manifest written against the old vocabulary fails with the fix in\n * hand rather than with `must be one of: backend, static`, which tells a reader\n * what is wrong but not what to write instead.\n */\nconst REMOVED_APP_TYPES: Record<string, string> = {\n admin:\n \"the admin panel is an ordinary static app now — declare it as \" +\n '{ \"type\": \"static\", \"root\": \"frontend\", \"output\": \"frontend/dist\", \"path\": \"/admin\" }',\n custom:\n \"who owns the server is a property of the backend now — declare \" +\n '{ \"type\": \"backend\", \"runtime\": \"custom\" } instead of a separate app',\n mobile:\n \"mobile apps are no longer declared in the manifest — nothing consumed this type. \" +\n \"Remove the entry\"\n};\n\n/** Reserved because they name things in URLs and CLI output. */\nconst RESERVED_APP_NAMES = new Set([\"api\", \"health\", \"metrics\", \"livez\", \"_rebase\"]);\n\n/**\n * Validate a URL path an app is served at: a static app's `path`, or the path\n * part of it when `path` is a URL, and `cms`.\n *\n * Normalizes to \"no trailing slash, except for the root\" so that mounting and\n * the `REBASE_APP_BASE` build variable have one shape to reason about.\n *\n * `origin` is `https://<host>` when the path came out of a URL, and is only\n * used to phrase the fix in the form the author wrote: telling someone who\n * wrote `\"https://admin.example.com/cms/\"` to write `\"/cms\"` would be telling\n * them to drop the hostname.\n */\nfunction checkAppPath(\n value: unknown,\n fieldPath: string,\n issues: ManifestValidationIssue[],\n origin = \"\"\n): string | undefined {\n if (value === undefined) return undefined;\n if (typeof value !== \"string\" || !value.startsWith(\"/\")) {\n issues.push({\n path: fieldPath,\n message: 'must be an absolute path like \"/admin\"'\n });\n return undefined;\n }\n // Before the `..` and empty-segment rules, which it would otherwise trip\n // with a message about paths. `//admin.example.com` is a URL with the\n // scheme left off, and mounting it as a path is not what was meant.\n if (!origin && value.startsWith(\"//\")) {\n issues.push({\n path: fieldPath,\n message: `looks like a URL without its scheme — write \"https:${value}\" to give this app its own hostname`\n });\n return undefined;\n }\n if (value.includes(\"..\") || value.includes(\"//\")) {\n issues.push({\n path: fieldPath,\n message: origin\n ? `must have a plain path after the hostname, with no \"..\" and no empty segment — like \"${origin}/admin\"`\n : 'must be an absolute path like \"/admin\", with no \"..\" and no empty segment'\n });\n return undefined;\n }\n if (value !== \"/\" && value.endsWith(\"/\")) {\n issues.push({\n path: fieldPath,\n message: `must not end with a slash — write \"${origin}${value.slice(0, -1)}\", not \"${origin}${value}\"`\n });\n return undefined;\n }\n // Mounting is longest-path-first, so an app at `/api` outranks the API and\n // every request to it is answered with that app's index.html — a 200 of HTML\n // where the caller wanted JSON, from a deployment that looks healthy. A\n // hostname does not change that: the backend's routes are registered before\n // any app's, on every hostname the project answers on.\n const reserved = reservedPrefixFor(value);\n if (reserved) {\n issues.push({\n path: fieldPath,\n message: `cannot be \"${reserved}\" or nest under it — the backend serves that path` +\n (origin ? \" on every hostname, this one included\" : \"\") +\n \", and an app mounted there would answer the API's requests with its own index.html\"\n });\n return undefined;\n }\n return value;\n}\n\n/**\n * Validate a static app's `path`, which is either a path or an https URL that\n * also gives the app a hostname of its own.\n *\n * The split is {@link parseAppAddress}, shared with the control plane and the\n * runtime so that all three read one value the same way. What it leaves to the\n * caller — the path rules — are {@link checkAppPath}'s, applied to the path\n * part of either form.\n */\nfunction checkAppAddress(\n value: unknown,\n fieldPath: string,\n issues: ManifestValidationIssue[]\n): AppAddress | undefined {\n if (value === undefined) return undefined;\n if (typeof value !== \"string\") {\n issues.push({\n path: fieldPath,\n message: 'must be an absolute path like \"/admin\", or a URL like \"https://admin.example.com\"'\n });\n return undefined;\n }\n const parsed = parseAppAddress(value);\n if (!parsed.ok) {\n issues.push({ path: fieldPath, message: parsed.reason });\n return undefined;\n }\n const { host } = parsed.address;\n const appPath = checkAppPath(parsed.address.path, fieldPath, issues, host ? `https://${host}` : \"\");\n if (appPath === undefined) return undefined;\n return host ? { host, path: appPath } : { path: appPath };\n}\n\n/**\n * Where a validated static app answers: its hostname, if its `path` names one,\n * and the path under it.\n *\n * The manifest keeps `path` as it was written, URL and all, because it is also\n * what `writeManifest` puts back: storing the split pieces instead would have\n * `rebase eject` rewrite `\"https://admin.example.com\"` to `\"/\"` and drop the\n * hostname from a file the developer never asked it to touch. Everything that\n * mounts, builds or prints an app reads it through here instead, so there is\n * one reading of the field.\n *\n * Throws on a value `validateManifest` would have refused. Every caller holds a\n * manifest that came through it, so reaching the throw means one did not — and\n * guessing an address for it would build or mount the app somewhere it was\n * never declared.\n */\nexport function staticAppAddress(name: string, app: { path?: string }): AppAddress {\n if (app.path === undefined) return { path: \"/\" };\n const parsed = parseAppAddress(app.path);\n if (!parsed.ok) {\n throw new ManifestError(`apps.${name}.path ${parsed.reason}`, [{ path: `apps.${name}.path`, message: parsed.reason }]);\n }\n return parsed.address;\n}\n\n/**\n * An address as a developer would type it: the path alone for an app on every\n * hostname, the https URL for one on its own. The root of a hostname prints as\n * the bare origin — `https://admin.example.com`, which is how it is declared.\n */\nexport function formatAppAddress(address: AppAddress): string {\n if (!address.host) return address.path;\n return `https://${address.host}${address.path === \"/\" ? \"\" : address.path}`;\n}\n\n/**\n * The order static apps are mounted in, and the order a bundle lists them.\n *\n * Longest path first, so an app at `/` is registered after the apps beneath it\n * and its catch-all cannot claim their URLs. At an equal path, the app bound to\n * a hostname goes first: on that hostname it is the one that answers, and the\n * app on every hostname answers the rest. That is the runtime's matching rule,\n * restated as a sort so a bundle reads in the order it is served.\n */\nexport function compareMountOrder(a: AppAddress, b: AppAddress): number {\n if (a.path.length !== b.path.length) return b.path.length - a.path.length;\n return (a.host ? 0 : 1) - (b.host ? 0 : 1);\n}\n\n/**\n * Is `candidate` the path `parent`, or something beneath it?\n *\n * Segment-aware for the same reason `isForbiddenStaticPath` is: a plain\n * `startsWith` reads `/admin` as living under `/adm`.\n */\nfunction isUnderPath(candidate: string, parent: string): boolean {\n if (parent === \"/\") return true;\n return candidate === parent || candidate.startsWith(`${parent}/`);\n}\n\n/**\n * Validate where an app says it mounts the Rebase CMS.\n *\n * The same shape as {@link checkAppPath} — it is a URL path and ends up in the\n * same places — plus one rule of its own: it has to be inside the app declaring\n * it. The app's SPA fallback is what answers that URL, so a `cms` outside its\n * `path` names an address this app will never serve. That is a link the console\n * would then offer to a 404, which is worse than the missing link it replaces.\n *\n * Always a path, even on an app whose `path` is a URL. The app's address\n * already says which hostname it answers on, and a second hostname here could\n * only disagree with it; `cms` says where on that hostname the CMS is.\n */\nfunction checkCmsPath(\n value: unknown,\n app: AppAddress,\n fieldPath: string,\n issues: ManifestValidationIssue[]\n): string | undefined {\n if (value === undefined) return undefined;\n if (typeof value === \"string\" && (/^[a-z][a-z0-9+.-]*:/i.test(value) || value.startsWith(\"//\"))) {\n const parsed = parseAppAddress(value.startsWith(\"//\") ? `https:${value}` : value);\n issues.push({\n path: fieldPath,\n message: \"must be a path, not a URL — the CMS is a route of this app, which is served where its \" +\n \"`path` says\" + (parsed.ok ? `. Write \"${parsed.address.path}\"` : \"\")\n });\n return undefined;\n }\n const cms = checkAppPath(value, fieldPath, issues);\n if (cms === undefined) return undefined;\n if (!isUnderPath(cms, app.path)) {\n issues.push({\n path: fieldPath,\n message: `must be inside this app's path — it is at \"${formatAppAddress(app)}\", so it cannot serve \"${cms}\". ` +\n \"The CMS is a route of this app, not a separate deployment; if it really lives elsewhere, \" +\n \"declare that app and put `cms` on it instead\"\n });\n return undefined;\n }\n return cms;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Reject paths that escape the repository.\n *\n * A manifest is committed and reviewed, so this is not a security boundary so\n * much as a guard against `../../` typos that would otherwise have `rebase build`\n * writing outside the project.\n *\n * `mayEscape` is for `context`, and only for `context`. Every other path here\n * names something Rebase *reads* — collections, functions, the generated\n * schema, the built assets to serve — and those have to be inside the project\n * or the bundle cannot carry them. A Docker build context is the one field that\n * names something Rebase never opens: it is handed to `docker build`, and in\n * any workspace repository the thing it has to name is the workspace root,\n * above the app. That is not exotic. It is what pnpm, turbo and nx layouts all\n * look like, and it is what this repository's own reference project needs — its\n * Dockerfile's first instruction copies `pnpm-lock.yaml`, which does not exist\n * beside `rebase.json` and never will.\n *\n * Refusing it did not prevent the escape; it only stopped anyone declaring it.\n * `app/rebase.json` built from the monorepo root the whole time — via\n * `infra/cloudbuild.yaml`, which says `-f app/backend/Dockerfile .` — while the\n * manifest said the context was `app/` and `rebase build` printed a command\n * that dies on its first `COPY`.\n */\nfunction checkRelativePath(\n value: unknown,\n fieldPath: string,\n issues: ManifestValidationIssue[],\n { required, mayEscape = false }: { required: boolean; mayEscape?: boolean }\n): string | undefined {\n if (value === undefined) {\n if (required) issues.push({ path: fieldPath,\nmessage: \"is required\" });\n return undefined;\n }\n if (typeof value !== \"string\" || value.trim() === \"\") {\n issues.push({ path: fieldPath,\nmessage: \"must be a non-empty string\" });\n return undefined;\n }\n if (path.isAbsolute(value)) {\n issues.push({ path: fieldPath,\nmessage: \"must be a relative path, not absolute\" });\n return undefined;\n }\n const normalized = path.normalize(value);\n if (!mayEscape && (normalized === \"..\" || normalized.startsWith(`..${path.sep}`))) {\n issues.push({ path: fieldPath,\nmessage: \"must stay inside the project directory\" });\n return undefined;\n }\n return value;\n}\n\n/** Fields each app type understands. Anything else is a typo or a newer CLI. */\nconst KNOWN_APP_FIELDS: Record<string, readonly string[]> = {\n backend: [\"type\", \"runtime\", \"config\", \"functions\", \"crons\", \"schema\",\n \"usersCollection\", \"registerDatabase\", \"dockerfile\", \"context\", \"port\"],\n static: [\"type\", \"root\", \"build\", \"output\", \"path\", \"spa\", \"cms\"]\n};\n\n/**\n * Fields people reach for to give a static app a hostname, which is spelled as\n * a URL in `path` instead. Named so the warning says that, rather than \"your\n * CLI may be older than this manifest\" — which is false here and sends the\n * reader to upgrade a CLI that already does what they wanted.\n */\nconst HOSTNAME_FIELDS = new Set([\"host\", \"hostname\", \"domain\"]);\n\n/**\n * Report a field this CLI does not recognise.\n *\n * A warning rather than an error, and the distinction matters in both\n * directions. `\"pathh\": \"/admin\"` is a typo that would otherwise be silently\n * dropped — the app builds for `/`, mounts at `/`, and the only symptom is that\n * it is not where you put it. But an unknown field is also what an *older* CLI\n * sees when it opens a manifest written for a newer one, and refusing to build\n * over a field that is simply from the future would make every manifest addition\n * a breaking change.\n *\n * So: name it, suggest the near-miss, and carry on.\n */\nfunction warnUnknownFields(name: string, raw: Record<string, unknown>, type: string): void {\n const known = KNOWN_APP_FIELDS[type];\n if (!known) return;\n\n for (const field of Object.keys(raw)) {\n if (known.includes(field)) continue;\n if (type === \"static\" && HOSTNAME_FIELDS.has(field)) {\n const value = raw[field];\n const host = typeof value === \"string\" && value.trim() !== \"\"\n ? value.trim().replace(/^[a-z]+:\\/\\//i, \"\").replace(/\\/+$/, \"\")\n : \"admin.example.com\";\n const under = typeof raw.path === \"string\" && raw.path.startsWith(\"/\") && raw.path !== \"/\" ? raw.path : \"\";\n console.warn(\n `⚠ rebase.json: apps.${name}.${field} is not a field — it is ignored. To serve this app on its ` +\n `own hostname, write its path as a URL: \"path\": \"https://${host}${under}\"`\n );\n continue;\n }\n const suggestion = known.find(candidate => isNearMiss(candidate, field));\n console.warn(\n `⚠ rebase.json: apps.${name}.${field} is not a field this CLI knows.` +\n (suggestion ? ` Did you mean \"${suggestion}\"?` : \" It is ignored — your CLI may be older than this manifest.\")\n );\n }\n}\n\n/**\n * One edit apart, ignoring case: enough for a typo, tight enough to stay quiet.\n *\n * The same rule as `isNearMiss` in `@rebasepro/utils`, which the collection\n * validator uses for unknown `admin` keys. It is a copy rather than an import\n * because the CLI does not depend on `@rebasepro/utils`, and adding the\n * dependency is a lockfile change; collapsing the two is worth doing the next\n * time this package's dependencies are touched.\n */\nfunction isNearMiss(a: string, b: string): boolean {\n const x = a.toLowerCase();\n const y = b.toLowerCase();\n if (x === y) return true;\n if (Math.abs(x.length - y.length) > 1) return false;\n\n const [shorter, longer] = x.length <= y.length ? [x, y] : [y, x];\n let i = 0;\n let j = 0;\n let edits = 0;\n while (i < shorter.length && j < longer.length) {\n if (shorter[i] === longer[j]) { i++; j++; continue; }\n if (++edits > 1) return false;\n if (shorter.length === longer.length) i++;\n j++;\n }\n return edits + (longer.length - j) + (shorter.length - i) <= 1;\n}\n\nfunction validateApp(\n name: string,\n raw: unknown,\n issues: ManifestValidationIssue[]\n): RebaseAppConfig | undefined {\n const base = `apps.${name}`;\n\n if (!isRecord(raw)) {\n issues.push({ path: base,\nmessage: \"must be an object\" });\n return undefined;\n }\n\n const type = raw.type;\n if (typeof type === \"string\" && REMOVED_APP_TYPES[type]) {\n issues.push({ path: `${base}.type`,\nmessage: `\"${type}\" is no longer an app type — ${REMOVED_APP_TYPES[type]}` });\n return undefined;\n }\n if (typeof type !== \"string\" || !(APP_TYPES as readonly string[]).includes(type)) {\n issues.push({\n path: `${base}.type`,\n message: `must be one of: ${APP_TYPES.join(\", \")}`\n });\n return undefined;\n }\n\n warnUnknownFields(name, raw, type);\n\n switch (type) {\n case \"backend\": {\n checkRelativePath(raw.config, `${base}.config`, issues, { required: false });\n checkRelativePath(raw.functions, `${base}.functions`, issues, { required: false });\n checkRelativePath(raw.crons, `${base}.crons`, issues, { required: false });\n checkRelativePath(raw.schema, `${base}.schema`, issues, { required: false });\n checkRelativePath(raw.usersCollection, `${base}.usersCollection`, issues, { required: false });\n\n if (raw.mode !== undefined) {\n issues.push({\n path: `${base}.mode`,\n message:\n \"is no longer a field — collections come from the config directory when \" +\n \"it exists, and are introspected from the database when it does not\"\n });\n }\n\n const custom = raw.runtime === \"custom\";\n if (raw.runtime !== \"managed\" && !custom) {\n issues.push({\n path: `${base}.runtime`,\n message: 'is required, and must be \"managed\" or \"custom\"'\n });\n }\n\n // The image fields describe an image this repository builds. Under a\n // managed backend there is no such image, so accepting them silently\n // would be accepting a Dockerfile that never gets built.\n for (const field of [\"dockerfile\", \"context\", \"port\"] as const) {\n if (raw[field] !== undefined && !custom) {\n issues.push({\n path: `${base}.${field}`,\n message: 'only applies to a custom runtime — set \"runtime\": \"custom\" to build your own image'\n });\n }\n }\n checkRelativePath(raw.dockerfile, `${base}.dockerfile`, issues, { required: false });\n // `dockerfile` stays project-relative even when the context is\n // above the project: it names a file in THIS repository, and moving\n // the context should not rewrite it. `rebase build` re-expresses it\n // against the context when it prints the command.\n checkRelativePath(raw.context, `${base}.context`, issues, { required: false, mayEscape: true });\n if (raw.port !== undefined && (typeof raw.port !== \"number\" || !Number.isInteger(raw.port))) {\n issues.push({ path: `${base}.port`,\nmessage: \"must be an integer\" });\n }\n if (raw.registerDatabase !== undefined && typeof raw.registerDatabase !== \"boolean\") {\n issues.push({ path: `${base}.registerDatabase`,\nmessage: \"must be a boolean\" });\n }\n // Constructed, not asserted. Everything above pushes an issue for a\n // field it does not like and then leaves the field alone, so\n // `raw as unknown as RebaseAppConfig` handed the caller the *whole\n // parsed object* under a type describing only these fields — an\n // unknown key that `warnUnknownFields` merely warned about travelled\n // on as if it were part of the config, and a field that failed its\n // check above travelled on with the type saying it had passed.\n // Naming them is also what keeps this list and the interface in step:\n // a field added to `RebaseBackendAppConfig` and not validated here\n // now fails to compile instead of silently arriving unchecked.\n return {\n type: \"backend\",\n runtime: custom ? \"custom\" : \"managed\",\n config: raw.config as string | undefined,\n functions: raw.functions as string | undefined,\n crons: raw.crons as string | undefined,\n schema: raw.schema as string | undefined,\n usersCollection: raw.usersCollection as string | undefined,\n registerDatabase: raw.registerDatabase as boolean | undefined,\n dockerfile: raw.dockerfile as string | undefined,\n context: raw.context as string | undefined,\n port: raw.port as number | undefined\n };\n }\n case \"static\": {\n checkRelativePath(raw.root, `${base}.root`, issues, { required: true });\n checkRelativePath(raw.output, `${base}.output`, issues, { required: true });\n if (raw.build !== undefined && typeof raw.build !== \"string\") {\n issues.push({ path: `${base}.build`,\nmessage: \"must be a string command\" });\n }\n if (raw.spa !== undefined && typeof raw.spa !== \"boolean\") {\n issues.push({ path: `${base}.spa`,\nmessage: \"must be a boolean\" });\n }\n const address = checkAppAddress(raw.path, `${base}.path`, issues);\n checkCmsPath(raw.cms, address ?? { path: \"/\" }, `${base}.cms`, issues);\n // See the backend branch: constructed for the same reasons. `path`\n // is kept as written — see `staticAppAddress` for why the split\n // pieces are not what the manifest stores.\n return {\n type: \"static\",\n root: raw.root as string,\n build: raw.build as string | undefined,\n output: raw.output as string,\n path: address ? raw.path as string : undefined,\n spa: raw.spa as boolean | undefined,\n cms: raw.cms as string | undefined\n };\n }\n default:\n return undefined;\n }\n}\n\n/**\n * Validate a parsed manifest, collecting every problem.\n */\nexport function validateManifest(raw: unknown): {\n manifest?: RebaseProjectManifest;\n issues: ManifestValidationIssue[];\n} {\n const issues: ManifestValidationIssue[] = [];\n\n if (!isRecord(raw)) {\n return { issues: [{ path: \"\",\nmessage: `${MANIFEST_FILENAME} must contain a JSON object` }] };\n }\n\n if (typeof raw.rebase !== \"string\" || raw.rebase.trim() === \"\") {\n // `runtime` used to be this key. It now means who owns the backend\n // process, so a manifest still using it at the top level is naming the\n // wrong thing rather than merely missing a field.\n const message = typeof raw.runtime === \"string\"\n ? `is required, e.g. \"${CURRENT_RUNTIME_RANGE}\" — this is the top-level \"runtime\" key renamed, ` +\n 'because \"runtime\" now means \"managed\" or \"custom\" on the backend app'\n : `is required, e.g. \"${CURRENT_RUNTIME_RANGE}\"`;\n issues.push({ path: \"rebase\",\nmessage });\n }\n\n if (!isRecord(raw.apps)) {\n issues.push({ path: \"apps\",\nmessage: \"is required and must be an object\" });\n return { issues };\n }\n\n const apps: Record<string, RebaseAppConfig> = {};\n let backendCount = 0;\n\n for (const [name, value] of Object.entries(raw.apps)) {\n if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {\n issues.push({\n path: `apps.${name}`,\n message: \"name must be lowercase alphanumeric with dashes (it appears in URLs)\"\n });\n continue;\n }\n if (RESERVED_APP_NAMES.has(name)) {\n issues.push({ path: `apps.${name}`,\nmessage: \"name is reserved\" });\n continue;\n }\n\n const app = validateApp(name, value, issues);\n if (!app) continue;\n if (app.type === \"backend\") backendCount++;\n apps[name] = app;\n }\n\n // One backend per *project*. A repository declaring two would have two sets\n // of collections claiming the same database and the same API surface.\n if (backendCount > 1) {\n issues.push({\n path: \"apps\",\n message: \"a project may declare at most one backend app\"\n });\n }\n\n // Two apps at one address is not a preference conflict — the first one\n // mounted swallows the other's URLs, and the loser looks like it deployed\n // fine. The address is the hostname and the path together: an app at \"/\" on\n // admin.example.com and one at \"/\" everywhere else are two different\n // addresses, and that pair is the point of giving an app a hostname. An app\n // with no hostname is its own value here, not a wildcard that collides with\n // every hostname — at an equal path the one naming the hostname wins there.\n const byAddress = new Map<string, string>();\n for (const [name, app] of Object.entries(apps)) {\n if (app.type !== \"static\") continue;\n const address = staticAppAddress(name, app);\n const key = `${address.host ?? \"\"} ${address.path}`;\n const owner = byAddress.get(key);\n if (owner) {\n issues.push({\n path: `apps.${name}.path`,\n message: `two apps cannot serve the same path — \"${owner}\" is already at \"${formatAppAddress(address)}\"`\n });\n continue;\n }\n byAddress.set(key, name);\n }\n\n // One CMS per project. Not a taste ruling: everything downstream — the\n // console's button, `rebase apps list`, the app row that records it — talks\n // about \"the project's CMS\", and two of them would make every one of those\n // pick arbitrarily. A repository that genuinely wants a second admin surface\n // has two apps and can say so by name.\n const withCms = Object.entries(apps).filter(\n ([, app]) => app.type === \"static\" && typeof app.cms === \"string\"\n );\n if (withCms.length > 1) {\n for (const [name] of withCms.slice(1)) {\n issues.push({\n path: `apps.${name}.cms`,\n message: `a project has one CMS — \"${withCms[0][0]}\" already declares one`\n });\n }\n }\n\n refuseStorageBlock(raw.storage, issues);\n\n // Carried rather than dropped. This key is the only repository-wide privacy\n // control the CLI honours, and a key that does not survive a parse does not\n // survive a rewrite either: `writeManifest` builds its output from what this\n // returned, so `rebase eject` deleted a committed `\"telemetry\": false` and\n // every developer who had ever opted in silently resumed sending events.\n //\n // Only a boolean is a value here — `true` is ignored elsewhere, loudly, but\n // it is still valid. A string `\"false\"` is the mistake that would leave\n // sharing on while looking like it was off, so it is named rather than\n // quietly discarded.\n let telemetry: boolean | undefined;\n if (raw.telemetry !== undefined) {\n if (typeof raw.telemetry === \"boolean\") {\n telemetry = raw.telemetry;\n } else {\n issues.push({\n path: \"telemetry\",\n message: \"must be a boolean — only `false` does anything, and it opts this repository out of usage sharing\"\n });\n }\n }\n\n if (issues.length > 0) return { issues };\n\n return {\n manifest: {\n $schema: typeof raw.$schema === \"string\" ? raw.$schema : undefined,\n rebase: raw.rebase as string,\n apps,\n ...(telemetry !== undefined ? { telemetry } : {})\n },\n issues\n };\n}\n\n/**\n * Refuse a hand-written `storage` block.\n *\n * Buckets are declared in config code now — `bucket(\"media\")` — and the graph\n * is generated from those declarations into `rebase.resources.json`. Two homes\n * for one concept is what this replaced, and the reason it had to go is that\n * the runtime *merged* them: a bucket declared in both had one engine kept and\n * the other silently discarded.\n *\n * Refused rather than ignored. A key that still parses and no longer does\n * anything is the same failure wearing a nicer hat — the author sees valid\n * JSON, the platform sees a bucket, and the runtime has neither.\n */\nfunction refuseStorageBlock(raw: unknown, issues: ManifestValidationIssue[]): undefined {\n if (raw === undefined) return undefined;\n issues.push({\n path: \"storage\",\n message:\n \"is no longer read. Declare each bucket in your config's resources.ts — \" +\n 'bucket(\"media\", { engine: \"s3\" }) — then run `rebase resources --write`, ' +\n \"which generates rebase.resources.json. Refused rather than ignored: this \" +\n \"block used to be merged with the code's declarations and silently win.\"\n });\n return undefined;\n}\n\n/**\n * Infer a manifest from a directory that does not have one.\n *\n * This mirrors exactly what the template scaffolds, which is what makes adopting\n * the manifest a no-op for existing projects: the synthesized result is what\n * they would have written by hand.\n *\n * The backend's `runtime` is inferred from whether the repository declares a\n * **Dockerfile** — the thing that actually builds an image — and from nothing\n * else. It used to be inferred from the presence of `backend/src/index.ts`,\n * which every scaffolded project had whether or not it wanted its own server, so\n * projects predating the manifest silently landed on the custom runtime and paid\n * for it.\n */\nexport function synthesizeManifest(projectRoot: string): RebaseProjectManifest {\n const exists = (relative: string): boolean => fs.existsSync(path.join(projectRoot, relative));\n const apps: Record<string, RebaseAppConfig> = {};\n\n const hasConfig = exists(DEFAULT_CONFIG_DIR);\n const hasBackend = exists(\"backend\");\n const dockerfile = [\"Dockerfile\", \"backend/Dockerfile\"].find(exists);\n\n if (hasBackend || hasConfig) {\n const backend: RebaseBackendAppConfig = dockerfile\n ? { type: \"backend\",\nruntime: \"custom\",\ndockerfile,\ncontext: \".\" }\n : { type: \"backend\",\nruntime: \"managed\" };\n if (exists(DEFAULT_FUNCTIONS_DIR)) backend.functions = DEFAULT_FUNCTIONS_DIR;\n if (exists(DEFAULT_CRONS_DIR)) backend.crons = DEFAULT_CRONS_DIR;\n apps.backend = backend;\n\n // Say it out loud. The file looks exactly like the server and is never\n // loaded, which used to be discovered only after a deploy answered 404\n // on every route defined in it.\n if (!dockerfile && exists(\"backend/src/index.ts\")) {\n console.warn(\n \"⚠ backend/src/index.ts exists but this project's backend is managed — it is\\n\" +\n \" never loaded. Delete it, or move it aside and run `rebase eject`, which\\n\" +\n \" writes an entrypoint of its own and owns the image. Eject does not adopt\\n\" +\n \" this file: it refuses to replace it unless you pass --force.\"\n );\n }\n }\n\n if (exists(\"frontend\")) {\n apps.web = {\n type: \"static\",\n root: \"frontend\",\n build: \"npm run build --workspace frontend\",\n output: \"frontend/dist\",\n path: \"/\",\n spa: true\n };\n }\n\n return { rebase: CURRENT_RUNTIME_RANGE,\napps };\n}\n\nexport function manifestPath(projectRoot: string): string {\n return path.join(projectRoot, MANIFEST_FILENAME);\n}\n\nexport function manifestExists(projectRoot: string): boolean {\n return fs.existsSync(manifestPath(projectRoot));\n}\n\n/**\n * Read the manifest, falling back to a synthesized one.\n *\n * A malformed manifest throws — unlike a missing one. Silently ignoring a file\n * the developer wrote, and building something else instead, is the worst\n * available behaviour.\n */\nexport function loadManifest(projectRoot: string): LoadedManifest {\n const filePath = manifestPath(projectRoot);\n\n if (!fs.existsSync(filePath)) {\n return { manifest: synthesizeManifest(projectRoot),\nsource: \"synthesized\" };\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(fs.readFileSync(filePath, \"utf8\"));\n } catch (err) {\n throw new ManifestError(\n `${MANIFEST_FILENAME} is not valid JSON: ${err instanceof Error ? err.message : String(err)}`\n );\n }\n\n const { manifest, issues } = validateManifest(parsed);\n if (!manifest) {\n throw new ManifestError(`${MANIFEST_FILENAME} is invalid`, issues);\n }\n\n return { manifest,\nsource: \"file\",\nfilePath };\n}\n\n/** The keys `writeManifest` knows how to write. Everything else is carried through. */\nconst MODELLED_MANIFEST_KEYS = [\"$schema\", \"rebase\", \"apps\", \"storage\", \"telemetry\"];\n\n/**\n * What is on disk right now, or `{}` — this is a *rewrite*, so the file that is\n * about to be replaced is the only record of the keys the caller did not model.\n * Unparseable is treated as absent: `loadManifest` refuses malformed JSON long\n * before anything gets here, and a writer is not the place to fail on it.\n */\nfunction readManifestObject(filePath: string): Record<string, unknown> {\n try {\n const parsed: unknown = JSON.parse(fs.readFileSync(filePath, \"utf8\"));\n return isRecord(parsed) ? parsed : {};\n } catch {\n return {};\n }\n}\n\n/**\n * Write a manifest, with a trailing newline so it plays well with other tools.\n *\n * **Every key on disk survives.** This used to emit exactly `$schema`, `rebase`\n * and `apps`, so a rewrite deleted the rest of the file — and two commands with\n * no visible relationship to either key rewrite it: `rebase eject` and\n * `rebase apps init --force`. A repository that had committed\n * `\"telemetry\": false` lost its opt-out, and a multi-bucket project lost its\n * whole `storage` block, in a commit whose stated change was `runtime: custom`.\n *\n * So: the caller's manifest wins for what it models, the file supplies the rest.\n * `storage` and `telemetry` fall back to the file because the callers that\n * synthesize a manifest (`apps init --force`) cannot know them — they are\n * authored, not inferred — and unknown top-level keys are copied verbatim\n * rather than listed, since a hand-listed set loses the next key too.\n */\nexport function writeManifest(projectRoot: string, manifest: RebaseProjectManifest): string {\n const filePath = manifestPath(projectRoot);\n const existing = readManifestObject(filePath);\n\n const carried: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(existing)) {\n if (!MODELLED_MANIFEST_KEYS.includes(key)) carried[key] = value;\n }\n\n const schema = manifest.$schema\n ?? (typeof existing.$schema === \"string\" ? existing.$schema : undefined)\n ?? \"https://rebase.pro/schemas/rebase.json\";\n const telemetry = manifest.telemetry ?? (typeof existing.telemetry === \"boolean\" ? existing.telemetry : undefined);\n\n const ordered = {\n $schema: schema,\n rebase: manifest.rebase,\n apps: manifest.apps,\n ...(telemetry !== undefined ? { telemetry } : {}),\n ...carried\n };\n fs.writeFileSync(filePath, `${JSON.stringify(ordered, null, 4)}\\n`, \"utf8\");\n return filePath;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Queries\n// ─────────────────────────────────────────────────────────────────────────────\n\n/** Find the single backend app, if this repository declares one. */\nexport function findBackendApp(\n manifest: RebaseProjectManifest\n): { name: string; app: RebaseBackendAppConfig } | undefined {\n for (const [name, app] of Object.entries(manifest.apps)) {\n if (app.type === \"backend\") return { name,\napp: app as RebaseBackendAppConfig };\n }\n return undefined;\n}\n\n/**\n * Where this project mounts the Rebase CMS, if it says.\n *\n * The CMS is a component inside a developer's own app, so its address is a\n * client-side route: no build artifact, no running server and no control plane\n * can observe it. {@link RebaseStaticAppConfig.cms} is the only place that fact\n * is ever written down, and this is the one reader of it — so that \"the\n * project's CMS\" means the same thing to `rebase dev`, `rebase apps list`, the\n * bundle it builds and the console that shows it.\n *\n * Returns the *serving* app alongside the path, because a caller with a base URL\n * needs to know which app answers there — and because the path alone cannot say\n * whether the CMS is the whole of an app or one route of it.\n *\n * `path` is always a path. `host` is the serving app's hostname, when its `path`\n * gives it one: the CMS is then at `https://<host><path>` and nowhere else, and\n * a caller holding a local or project base URL must not put the path on that.\n */\nexport function cmsMountOf(\n manifest: RebaseProjectManifest\n): { appName: string; app: RebaseStaticAppConfig; path: string; host?: string } | undefined {\n for (const [name, app] of Object.entries(manifest.apps)) {\n if (app.type !== \"static\" || typeof app.cms !== \"string\") continue;\n const { host } = staticAppAddress(name, app);\n return { appName: name, app: app as RebaseStaticAppConfig, path: app.cms, ...(host ? { host } : {}) };\n }\n return undefined;\n}\n\n/**\n * The app a deploy targets: the one named, or the obvious one.\n *\n * A repository declares apps; a project owns them. So \"which app\" is a question\n * a multi-repo setup asks routinely and a single-app repository should never\n * have to answer — hence the fallbacks, in the order that makes each of them\n * unambiguous:\n *\n * - A name, when one is given. Wrong names fail loudly, listing what is there;\n * guessing past a typo would deploy the wrong app to a live project.\n * - The backend, when this repository declares one. It is the app whose deploy\n * people mean when they do not say, and it is what every existing invocation\n * already did.\n * - The only app, when there is exactly one. This is what makes a static-only\n * repository — an admin panel, a marketing site — deploy with no argument.\n * - Otherwise a refusal that lists the choices. A repository with two static\n * apps and no backend has no obvious default, and picking one would publish\n * somebody's admin panel at their marketing domain.\n */\nexport function selectDeployApp(\n manifest: RebaseProjectManifest,\n requested?: string\n): { name: string; app: RebaseAppConfig } {\n const entries = Object.entries(manifest.apps).map(([name, app]) => ({ name,\napp }));\n\n if (requested) {\n const match = entries.find(entry => entry.name === requested);\n if (!match) {\n const known = entries.map(e => e.name).join(\", \") || \"none\";\n throw new ManifestError(\n `This repository declares no app named \"${requested}\". It declares: ${known}.`\n );\n }\n return match;\n }\n\n const backend = findBackendApp(manifest);\n if (backend) return { name: backend.name,\napp: backend.app };\n\n if (entries.length === 1) return entries[0];\n\n if (entries.length === 0) {\n throw new ManifestError(\n `${MANIFEST_FILENAME} declares no apps, so there is nothing to deploy.`\n );\n }\n\n throw new ManifestError(\n \"This repository declares several apps and no backend, so there is no obvious one to deploy. \" +\n `Name one: ${entries.map(e => e.name).join(\", \")}.`\n );\n}\n\n/** Apps that produce build output, in the order they should be built. */\nexport function buildableApps(\n manifest: RebaseProjectManifest\n): { name: string; app: RebaseAppConfig }[] {\n // Backend first: a static app's build may consume an SDK generated from the\n // backend's collections, so building it second is the order that works.\n const entries = Object.entries(manifest.apps).map(([name, app]) => ({ name,\napp }));\n const rank = (app: RebaseAppConfig): number => (app.type === \"backend\" ? 0 : 1);\n return entries.sort((a, b) => rank(a.app) - rank(b.app));\n}\n\n/**\n * Decide whether a project can run on the managed runtime, and say why not.\n *\n * \"Not eligible\" is never a dead end — it selects the custom-runtime path, which\n * still deploys. The reasons exist so the answer is actionable rather than a\n * verdict.\n */\nexport function assessManagedCompatibility(\n manifest: RebaseProjectManifest\n): ManagedCompatibility {\n const backend = findBackendApp(manifest);\n\n if (!backend) {\n return {\n eligible: false,\n reasons: [\n \"No backend app is declared in this repository. Only the repository that \" +\n \"declares the backend selects the runtime.\"\n ]\n };\n }\n\n // Declared, not deduced. A project on the custom runtime is there because\n // somebody wrote it down, which is the whole point of the field.\n if (backend.app.runtime === \"custom\") {\n return {\n eligible: false,\n reasons: [\n `App \"${backend.name}\" declares runtime: \"custom\", so it builds and runs its ` +\n \"own image. The managed runtime boots the platform image with your bundle; \" +\n \"the custom runtime deploys exactly the same way, from your Dockerfile.\"\n ]\n };\n }\n\n return { eligible: true,\nreasons: [] };\n}\n\n/**\n * Resolve a backend app's directories against the conventions it omits.\n *\n * `hasCollections` replaces the old `mode: \"cms\" | \"baas\"` field. Where the\n * collections come from was never an independent choice: either they are\n * declared in code and the bundle ships them, or they are not and the runtime\n * introspects the live database at boot. Declaring it separately only created\n * the contradictory state — code-first declared, no collections anywhere.\n *\n * `hasConfig` is deliberately a **separate** question. A headless project has no\n * `config/collections`, but it may still ship a config package — that is where\n * the `storageAuthorize` hook lives, and storage is not under row-level\n * security, so without one the server refuses to boot with storage enabled.\n * Collapsing the two would leave a headless project nowhere to put it.\n */\nexport function resolveBackendPaths(\n app: RebaseBackendAppConfig,\n projectRoot: string\n): {\n config: string;\n functions: string;\n crons: string;\n schema: string;\n usersCollection: string;\n /** Whether a config package exists — hooks, storage authorization. */\n hasConfig: boolean;\n /** Whether collections are declared in code, under `<config>/collections`. */\n hasCollections: boolean;\n} {\n const config = app.config ?? DEFAULT_CONFIG_DIR;\n return {\n config,\n functions: app.functions ?? DEFAULT_FUNCTIONS_DIR,\n crons: app.crons ?? DEFAULT_CRONS_DIR,\n schema: app.schema ?? DEFAULT_SCHEMA_FILE,\n usersCollection: app.usersCollection ?? \"collections/users\",\n hasConfig: fs.existsSync(path.join(projectRoot, config)),\n hasCollections: fs.existsSync(path.join(projectRoot, config, \"collections\"))\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,wBAAwB;;AAGrC,IAAa,qBAAqB;AAClC,IAAa,wBAAwB;AACrC,IAAa,oBAAoB;AACjC,IAAa,sBAAsB;AAgBnC,IAAa,gBAAb,cAAmC,MAAM;CACC;CAAtC,YAAY,SAAiB,SAA6C,CAAC,GAAG;EAC1E,MAAM,OAAO;EADqB,KAAA,SAAA;EAElC,KAAK,OAAO;CAChB;AACJ;AAEA,IAAM,YAAY,CAAC,WAAW,QAAQ;;;;;;;;AAStC,IAAM,oBAA4C;CAC9C,OACI;CAEJ,QACI;CAEJ,QACI;AAER;;AAGA,IAAM,qCAAqB,IAAI,IAAI;CAAC;CAAO;CAAU;CAAW;CAAS;AAAS,CAAC;;;;;;;;;;;;;AAcnF,SAAS,aACL,OACA,WACA,QACA,SAAS,IACS;CAClB,IAAI,UAAU,KAAA,GAAW,OAAO,KAAA;CAChC,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,WAAW,GAAG,GAAG;EACrD,OAAO,KAAK;GACR,MAAM;GACN,SAAS;EACb,CAAC;EACD;CACJ;CAIA,IAAI,CAAC,UAAU,MAAM,WAAW,IAAI,GAAG;EACnC,OAAO,KAAK;GACR,MAAM;GACN,SAAS,sDAAsD,MAAM;EACzE,CAAC;EACD;CACJ;CACA,IAAI,MAAM,SAAS,IAAI,KAAK,MAAM,SAAS,IAAI,GAAG;EAC9C,OAAO,KAAK;GACR,MAAM;GACN,SAAS,SACH,wFAAwF,OAAO,WAC/F;EACV,CAAC;EACD;CACJ;CACA,IAAI,UAAU,OAAO,MAAM,SAAS,GAAG,GAAG;EACtC,OAAO,KAAK;GACR,MAAM;GACN,SAAS,sCAAsC,SAAS,MAAM,MAAM,GAAG,EAAE,EAAE,UAAU,S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CACJ;CAGJ,OAAO;EAAE,UAAU;EACvB,SAAS,CAAC;CAAE;AACZ;;;;;;;;;;;;;;;;AAiBA,SAAgB,oBACZ,KACA,aAWF;CACE,MAAM,SAAS,IAAI,UAAA;CACnB,OAAO;EACH;EACA,WAAW,IAAI,aAAA;EACf,OAAO,IAAI,SAAA;EACX,QAAQ,IAAI,UAAA;EACZ,iBAAiB,IAAI,mBAAmB;EACxC,WAAW,GAAG,WAAW,KAAK,KAAK,aAAa,MAAM,CAAC;EACvD,gBAAgB,GAAG,WAAW,KAAK,KAAK,aAAa,QAAQ,aAAa,CAAC;CAC/E;AACJ"}
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ManagedCompatibility, type RebaseAppConfig, type RebaseBackendAppConfig, type RebaseProjectManifest, type RebaseStaticAppConfig } from "@rebasepro/types";
|
|
1
|
+
import { type AppAddress, type ManagedCompatibility, type RebaseAppConfig, type RebaseBackendAppConfig, type RebaseProjectManifest, type RebaseStaticAppConfig } from "@rebasepro/types";
|
|
2
2
|
/** Runtime range written into new manifests. */
|
|
3
3
|
export declare const CURRENT_RUNTIME_RANGE = "^1";
|
|
4
4
|
/** Conventional locations, matching what `rebase init` scaffolds. */
|
|
@@ -22,6 +22,41 @@ export declare class ManifestError extends Error {
|
|
|
22
22
|
readonly issues: ManifestValidationIssue[];
|
|
23
23
|
constructor(message: string, issues?: ManifestValidationIssue[]);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Where a validated static app answers: its hostname, if its `path` names one,
|
|
27
|
+
* and the path under it.
|
|
28
|
+
*
|
|
29
|
+
* The manifest keeps `path` as it was written, URL and all, because it is also
|
|
30
|
+
* what `writeManifest` puts back: storing the split pieces instead would have
|
|
31
|
+
* `rebase eject` rewrite `"https://admin.example.com"` to `"/"` and drop the
|
|
32
|
+
* hostname from a file the developer never asked it to touch. Everything that
|
|
33
|
+
* mounts, builds or prints an app reads it through here instead, so there is
|
|
34
|
+
* one reading of the field.
|
|
35
|
+
*
|
|
36
|
+
* Throws on a value `validateManifest` would have refused. Every caller holds a
|
|
37
|
+
* manifest that came through it, so reaching the throw means one did not — and
|
|
38
|
+
* guessing an address for it would build or mount the app somewhere it was
|
|
39
|
+
* never declared.
|
|
40
|
+
*/
|
|
41
|
+
export declare function staticAppAddress(name: string, app: {
|
|
42
|
+
path?: string;
|
|
43
|
+
}): AppAddress;
|
|
44
|
+
/**
|
|
45
|
+
* An address as a developer would type it: the path alone for an app on every
|
|
46
|
+
* hostname, the https URL for one on its own. The root of a hostname prints as
|
|
47
|
+
* the bare origin — `https://admin.example.com`, which is how it is declared.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatAppAddress(address: AppAddress): string;
|
|
50
|
+
/**
|
|
51
|
+
* The order static apps are mounted in, and the order a bundle lists them.
|
|
52
|
+
*
|
|
53
|
+
* Longest path first, so an app at `/` is registered after the apps beneath it
|
|
54
|
+
* and its catch-all cannot claim their URLs. At an equal path, the app bound to
|
|
55
|
+
* a hostname goes first: on that hostname it is the one that answers, and the
|
|
56
|
+
* app on every hostname answers the rest. That is the runtime's matching rule,
|
|
57
|
+
* restated as a sort so a bundle reads in the order it is served.
|
|
58
|
+
*/
|
|
59
|
+
export declare function compareMountOrder(a: AppAddress, b: AppAddress): number;
|
|
25
60
|
/**
|
|
26
61
|
* Validate a parsed manifest, collecting every problem.
|
|
27
62
|
*/
|
|
@@ -89,11 +124,16 @@ export declare function findBackendApp(manifest: RebaseProjectManifest): {
|
|
|
89
124
|
* Returns the *serving* app alongside the path, because a caller with a base URL
|
|
90
125
|
* needs to know which app answers there — and because the path alone cannot say
|
|
91
126
|
* whether the CMS is the whole of an app or one route of it.
|
|
127
|
+
*
|
|
128
|
+
* `path` is always a path. `host` is the serving app's hostname, when its `path`
|
|
129
|
+
* gives it one: the CMS is then at `https://<host><path>` and nowhere else, and
|
|
130
|
+
* a caller holding a local or project base URL must not put the path on that.
|
|
92
131
|
*/
|
|
93
132
|
export declare function cmsMountOf(manifest: RebaseProjectManifest): {
|
|
94
133
|
appName: string;
|
|
95
134
|
app: RebaseStaticAppConfig;
|
|
96
135
|
path: string;
|
|
136
|
+
host?: string;
|
|
97
137
|
} | undefined;
|
|
98
138
|
/**
|
|
99
139
|
* The app a deploy targets: the one named, or the obvious one.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { n as parseCommandArgs } from "./args-BnmsEXvu.js";
|
|
2
|
+
import { v as normalizeEsmSpecifiers } from "./bundle-BQhP_xiA.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import path from "path";
|
|
6
|
+
//#region src/commands/normalize-imports.ts
|
|
7
|
+
/**
|
|
8
|
+
* Give compiled output the relative-import extensions Node's ESM loader needs.
|
|
9
|
+
*
|
|
10
|
+
* ## Why a project needs this at all
|
|
11
|
+
*
|
|
12
|
+
* TypeScript does not rewrite module specifiers, deliberately and by long-stated
|
|
13
|
+
* policy: what you write is what it emits. Node's ESM loader, equally
|
|
14
|
+
* deliberately, resolves no extensions — `./authors` is not a module, only
|
|
15
|
+
* `./authors.js` is. Between those two positions sits every project that writes
|
|
16
|
+
* extensionless relative imports, which is most of them, and which
|
|
17
|
+
* `moduleResolution: "bundler"` — what this scaffold ships — is designed for.
|
|
18
|
+
*
|
|
19
|
+
* The usual escape is to write the *output* extension in the *source*:
|
|
20
|
+
* `import x from "./authors.js"` in a file called `authors.ts`. It works, and it
|
|
21
|
+
* is a tax on every import in the project to satisfy a step the toolchain could
|
|
22
|
+
* take itself. This is that step.
|
|
23
|
+
*
|
|
24
|
+
* ## Why it is a command
|
|
25
|
+
*
|
|
26
|
+
* `rebase build` has always done this to its own bundle — the specifiers in
|
|
27
|
+
* `dist-bundle` are complete because {@link normalizeEsmSpecifiers} completes
|
|
28
|
+
* them. Nothing did it for the plain `tsc` output that `rebase eject` runs
|
|
29
|
+
* (`node dist/backend/src/index.js`) or that a self-hoster runs after
|
|
30
|
+
* `pnpm build`. So the templates wrote `.js` in source, which is the tax, and
|
|
31
|
+
* removing it silently broke eject at `pnpm start` while `check:eject` — which
|
|
32
|
+
* typechecks with `noEmit` — stayed green.
|
|
33
|
+
*
|
|
34
|
+
* One implementation, on both paths, callable from a package.json script.
|
|
35
|
+
*
|
|
36
|
+
* Mechanical and verifiable: only relative specifiers are touched, and only when
|
|
37
|
+
* the target resolves to a file that exists. Idempotent, so a build that runs it
|
|
38
|
+
* twice is a build that runs it once.
|
|
39
|
+
*/
|
|
40
|
+
var NORMALIZE_IMPORTS_FLAGS = {
|
|
41
|
+
/** Report what would change without writing anything. */
|
|
42
|
+
"--check": Boolean };
|
|
43
|
+
var HELP = `
|
|
44
|
+
${chalk.bold("rebase normalize-imports")} — complete the relative imports in compiled output
|
|
45
|
+
|
|
46
|
+
${chalk.green.bold("Usage")}
|
|
47
|
+
rebase normalize-imports ${chalk.blue("<dir>")} [--check]
|
|
48
|
+
|
|
49
|
+
${chalk.green.bold("What it does")}
|
|
50
|
+
TypeScript emits your module specifiers verbatim, and Node's ESM loader does
|
|
51
|
+
not guess extensions — so \`./authors\` compiles fine and fails at run time.
|
|
52
|
+
This rewrites each relative specifier in the emitted JavaScript to the file it
|
|
53
|
+
actually resolves to, so your source can stay extensionless.
|
|
54
|
+
|
|
55
|
+
Only relative specifiers, only when the target exists on disk, and idempotent.
|
|
56
|
+
|
|
57
|
+
${chalk.green.bold("Arguments")}
|
|
58
|
+
${chalk.blue("<dir>")} The directory tsc emitted into, e.g. ${chalk.cyan("dist")}
|
|
59
|
+
|
|
60
|
+
${chalk.green.bold("Options")}
|
|
61
|
+
${chalk.blue("--check")} Report what would change and exit 1 if anything would
|
|
62
|
+
${chalk.gray("(for CI — the build itself should just run the rewrite)")}
|
|
63
|
+
|
|
64
|
+
${chalk.green.bold("Where it runs")}
|
|
65
|
+
The scaffold's ${chalk.cyan("config")} and ${chalk.cyan("backend")} build scripts, after ${chalk.cyan("tsc")}.
|
|
66
|
+
${chalk.cyan("rebase build")} already does the same to the bundle it writes.
|
|
67
|
+
`;
|
|
68
|
+
async function normalizeImportsCommand(rawArgs) {
|
|
69
|
+
const { flags, positionals, help } = parseCommandArgs({
|
|
70
|
+
spec: NORMALIZE_IMPORTS_FLAGS,
|
|
71
|
+
rawArgs,
|
|
72
|
+
commandWords: 1,
|
|
73
|
+
command: "normalize-imports",
|
|
74
|
+
maxPositionals: 1
|
|
75
|
+
});
|
|
76
|
+
if (help) {
|
|
77
|
+
console.log(HELP);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const target = positionals[0] ?? "dist";
|
|
81
|
+
const outDir = path.resolve(process.cwd(), target);
|
|
82
|
+
if (!fs.existsSync(outDir)) throw new Error(`${target} does not exist — run your build first. This step rewrites what the compiler emitted; it does not compile.`);
|
|
83
|
+
const { rewritten, unresolved } = normalizeEsmSpecifiers(outDir);
|
|
84
|
+
if (unresolved.length > 0) {
|
|
85
|
+
console.log(chalk.yellow(` ⚠ ${unresolved.length} relative import(s) resolve to no file:`));
|
|
86
|
+
for (const specifier of unresolved.slice(0, 10)) console.log(chalk.dim(` ${specifier}`));
|
|
87
|
+
if (unresolved.length > 10) console.log(chalk.dim(` …and ${unresolved.length - 10} more`));
|
|
88
|
+
console.log(chalk.dim(" These will throw ERR_MODULE_NOT_FOUND at run time."));
|
|
89
|
+
}
|
|
90
|
+
if (flags["--check"]) {
|
|
91
|
+
if (rewritten > 0 || unresolved.length > 0) throw new Error(`${rewritten} import(s) are incomplete for Node ESM. Run \`rebase normalize-imports ${target}\` as part of the build.`);
|
|
92
|
+
console.log(chalk.green(`✓ every relative import in ${target} is complete`));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
console.log(rewritten > 0 ? chalk.dim(` completed ${rewritten} relative import(s) in ${target}/ for Node ESM`) : chalk.dim(` ${target}/ — every relative import was already complete`));
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { normalizeImportsCommand };
|
|
99
|
+
|
|
100
|
+
//# sourceMappingURL=normalize-imports-CmVdE9iZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-imports-CmVdE9iZ.js","names":[],"sources":["../src/commands/normalize-imports.ts"],"sourcesContent":["import path from \"path\";\nimport fs from \"fs\";\n\nimport chalk from \"chalk\";\n\nimport { normalizeEsmSpecifiers } from \"../bundle\";\nimport { parseCommandArgs } from \"../utils/args\";\n\n/**\n * Give compiled output the relative-import extensions Node's ESM loader needs.\n *\n * ## Why a project needs this at all\n *\n * TypeScript does not rewrite module specifiers, deliberately and by long-stated\n * policy: what you write is what it emits. Node's ESM loader, equally\n * deliberately, resolves no extensions — `./authors` is not a module, only\n * `./authors.js` is. Between those two positions sits every project that writes\n * extensionless relative imports, which is most of them, and which\n * `moduleResolution: \"bundler\"` — what this scaffold ships — is designed for.\n *\n * The usual escape is to write the *output* extension in the *source*:\n * `import x from \"./authors.js\"` in a file called `authors.ts`. It works, and it\n * is a tax on every import in the project to satisfy a step the toolchain could\n * take itself. This is that step.\n *\n * ## Why it is a command\n *\n * `rebase build` has always done this to its own bundle — the specifiers in\n * `dist-bundle` are complete because {@link normalizeEsmSpecifiers} completes\n * them. Nothing did it for the plain `tsc` output that `rebase eject` runs\n * (`node dist/backend/src/index.js`) or that a self-hoster runs after\n * `pnpm build`. So the templates wrote `.js` in source, which is the tax, and\n * removing it silently broke eject at `pnpm start` while `check:eject` — which\n * typechecks with `noEmit` — stayed green.\n *\n * One implementation, on both paths, callable from a package.json script.\n *\n * Mechanical and verifiable: only relative specifiers are touched, and only when\n * the target resolves to a file that exists. Idempotent, so a build that runs it\n * twice is a build that runs it once.\n */\nexport const NORMALIZE_IMPORTS_FLAGS = {\n /** Report what would change without writing anything. */\n \"--check\": Boolean\n} as const;\n\nconst HELP = `\n${chalk.bold(\"rebase normalize-imports\")} — complete the relative imports in compiled output\n\n${chalk.green.bold(\"Usage\")}\n rebase normalize-imports ${chalk.blue(\"<dir>\")} [--check]\n\n${chalk.green.bold(\"What it does\")}\n TypeScript emits your module specifiers verbatim, and Node's ESM loader does\n not guess extensions — so \\`./authors\\` compiles fine and fails at run time.\n This rewrites each relative specifier in the emitted JavaScript to the file it\n actually resolves to, so your source can stay extensionless.\n\n Only relative specifiers, only when the target exists on disk, and idempotent.\n\n${chalk.green.bold(\"Arguments\")}\n ${chalk.blue(\"<dir>\")} The directory tsc emitted into, e.g. ${chalk.cyan(\"dist\")}\n\n${chalk.green.bold(\"Options\")}\n ${chalk.blue(\"--check\")} Report what would change and exit 1 if anything would\n ${chalk.gray(\"(for CI — the build itself should just run the rewrite)\")}\n\n${chalk.green.bold(\"Where it runs\")}\n The scaffold's ${chalk.cyan(\"config\")} and ${chalk.cyan(\"backend\")} build scripts, after ${chalk.cyan(\"tsc\")}.\n ${chalk.cyan(\"rebase build\")} already does the same to the bundle it writes.\n`;\n\nexport async function normalizeImportsCommand(rawArgs: string[]): Promise<void> {\n const { flags, positionals, help } = parseCommandArgs({\n spec: NORMALIZE_IMPORTS_FLAGS,\n rawArgs,\n commandWords: 1,\n command: \"normalize-imports\",\n maxPositionals: 1\n });\n\n if (help) {\n console.log(HELP);\n return;\n }\n\n const target = positionals[0] ?? \"dist\";\n const outDir = path.resolve(process.cwd(), target);\n\n // A missing directory is the common shape of \"tsc did not run\", and saying\n // so beats a rewrite that reports zero changes and looks like success.\n if (!fs.existsSync(outDir)) {\n throw new Error(\n `${target} does not exist — run your build first. `\n + \"This step rewrites what the compiler emitted; it does not compile.\"\n );\n }\n\n const { rewritten, unresolved } = normalizeEsmSpecifiers(outDir);\n\n if (unresolved.length > 0) {\n console.log(chalk.yellow(` ⚠ ${unresolved.length} relative import(s) resolve to no file:`));\n for (const specifier of unresolved.slice(0, 10)) {\n console.log(chalk.dim(` ${specifier}`));\n }\n if (unresolved.length > 10) {\n console.log(chalk.dim(` …and ${unresolved.length - 10} more`));\n }\n console.log(chalk.dim(\" These will throw ERR_MODULE_NOT_FOUND at run time.\"));\n }\n\n if (flags[\"--check\"]) {\n if (rewritten > 0 || unresolved.length > 0) {\n throw new Error(\n `${rewritten} import(s) are incomplete for Node ESM. `\n + `Run \\`rebase normalize-imports ${target}\\` as part of the build.`\n );\n }\n console.log(chalk.green(`✓ every relative import in ${target} is complete`));\n return;\n }\n\n console.log(\n rewritten > 0\n ? chalk.dim(` completed ${rewritten} relative import(s) in ${target}/ for Node ESM`)\n : chalk.dim(` ${target}/ — every relative import was already complete`)\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,0BAA0B;;AAEnC,WAAW,QACf;AAEA,IAAM,OAAO;EACX,MAAM,KAAK,0BAA0B,EAAE;;EAEvC,MAAM,MAAM,KAAK,OAAO,EAAE;6BACC,MAAM,KAAK,OAAO,EAAE;;EAE/C,MAAM,MAAM,KAAK,cAAc,EAAE;;;;;;;;EAQjC,MAAM,MAAM,KAAK,WAAW,EAAE;IAC5B,MAAM,KAAK,OAAO,EAAE,0DAA0D,MAAM,KAAK,MAAM,EAAE;;EAEnG,MAAM,MAAM,KAAK,SAAS,EAAE;IAC1B,MAAM,KAAK,SAAS,EAAE;4BACE,MAAM,KAAK,yDAAyD,EAAE;;EAEhG,MAAM,MAAM,KAAK,eAAe,EAAE;mBACjB,MAAM,KAAK,QAAQ,EAAE,OAAO,MAAM,KAAK,SAAS,EAAE,wBAAwB,MAAM,KAAK,KAAK,EAAE;IAC3G,MAAM,KAAK,cAAc,EAAE;;AAG/B,eAAsB,wBAAwB,SAAkC;CAC5E,MAAM,EAAE,OAAO,aAAa,SAAS,iBAAiB;EAClD,MAAM;EACN;EACA,cAAc;EACd,SAAS;EACT,gBAAgB;CACpB,CAAC;CAED,IAAI,MAAM;EACN,QAAQ,IAAI,IAAI;EAChB;CACJ;CAEA,MAAM,SAAS,YAAY,MAAM;CACjC,MAAM,SAAS,KAAK,QAAQ,QAAQ,IAAI,GAAG,MAAM;CAIjD,IAAI,CAAC,GAAG,WAAW,MAAM,GACrB,MAAM,IAAI,MACN,GAAG,OAAO,2GAEd;CAGJ,MAAM,EAAE,WAAW,eAAe,uBAAuB,MAAM;CAE/D,IAAI,WAAW,SAAS,GAAG;EACvB,QAAQ,IAAI,MAAM,OAAO,OAAO,WAAW,OAAO,wCAAwC,CAAC;EAC3F,KAAK,MAAM,aAAa,WAAW,MAAM,GAAG,EAAE,GAC1C,QAAQ,IAAI,MAAM,IAAI,SAAS,WAAW,CAAC;EAE/C,IAAI,WAAW,SAAS,IACpB,QAAQ,IAAI,MAAM,IAAI,cAAc,WAAW,SAAS,GAAG,MAAM,CAAC;EAEtE,QAAQ,IAAI,MAAM,IAAI,wDAAwD,CAAC;CACnF;CAEA,IAAI,MAAM,YAAY;EAClB,IAAI,YAAY,KAAK,WAAW,SAAS,GACrC,MAAM,IAAI,MACN,GAAG,UAAU,yEACuB,OAAO,yBAC/C;EAEJ,QAAQ,IAAI,MAAM,MAAM,8BAA8B,OAAO,aAAa,CAAC;EAC3E;CACJ;CAEA,QAAQ,IACJ,YAAY,IACN,MAAM,IAAI,eAAe,UAAU,yBAAyB,OAAO,eAAe,IAClF,MAAM,IAAI,KAAK,OAAO,+CAA+C,CAC/E;AACJ"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { spawnSync } from "child_process";
|
|
5
|
+
//#region src/utils/package-manager.ts
|
|
6
|
+
/**
|
|
7
|
+
* Package manager detection and command abstraction.
|
|
8
|
+
*
|
|
9
|
+
* Detects whether the user is running pnpm or npm and provides
|
|
10
|
+
* a unified interface for common package-manager operations so
|
|
11
|
+
* the rest of the CLI never has to hardcode a specific PM.
|
|
12
|
+
*/
|
|
13
|
+
var package_manager_exports = /* @__PURE__ */ __exportAll({
|
|
14
|
+
detectPackageManager: () => detectPackageManager,
|
|
15
|
+
getPMCommands: () => getPMCommands,
|
|
16
|
+
isPnpmAvailable: () => isPnpmAvailable,
|
|
17
|
+
pnpmAvailabilityFromProbe: () => pnpmAvailabilityFromProbe
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* How long to wait for `pnpm --version` before giving up on the probe.
|
|
21
|
+
*
|
|
22
|
+
* `pnpm --version` is a cold Node start, and on a machine that is busy — a
|
|
23
|
+
* parallel install, a full test run — it routinely takes seconds. Measured at
|
|
24
|
+
* 630ms, 990ms and 4293ms on three consecutive runs of one developer laptop
|
|
25
|
+
* under load, so the previous 3s budget was inside the normal spread rather
|
|
26
|
+
* than safely outside it.
|
|
27
|
+
*/
|
|
28
|
+
var PNPM_PROBE_TIMEOUT_MS = 5e3;
|
|
29
|
+
/** Memoised result of the probe. pnpm cannot appear or vanish mid-process. */
|
|
30
|
+
var cachedPnpmAvailable;
|
|
31
|
+
/**
|
|
32
|
+
* Decide availability from a `spawnSync` outcome.
|
|
33
|
+
*
|
|
34
|
+
* Split out from the spawn itself so the decision is testable without starting
|
|
35
|
+
* a process — which is what made the old test load-sensitive and occasionally
|
|
36
|
+
* red for reasons that had nothing to do with the code under test.
|
|
37
|
+
*
|
|
38
|
+
* The three outcomes are distinguishable, and the old code conflated two of
|
|
39
|
+
* them by asking only `status === 0`:
|
|
40
|
+
*
|
|
41
|
+
* not installed status null, signal null, error.code ENOENT
|
|
42
|
+
* timed out status null, signal SIGTERM, error.code ETIMEDOUT
|
|
43
|
+
* broken install status non-zero, no error
|
|
44
|
+
*/
|
|
45
|
+
function pnpmAvailabilityFromProbe(res) {
|
|
46
|
+
const code = res.error?.code;
|
|
47
|
+
if (code === "ENOENT") return false;
|
|
48
|
+
if (code === "ETIMEDOUT" || res.signal) return true;
|
|
49
|
+
if (res.error) return false;
|
|
50
|
+
return res.status === 0;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether pnpm is runnable on this machine.
|
|
54
|
+
*
|
|
55
|
+
* Used to decide whether a fresh project can be scaffolded with pnpm. Kept
|
|
56
|
+
* cheap and non-interactive (bounded timeout, output discarded) so it never
|
|
57
|
+
* hangs detection if a corepack shim misbehaves, and memoised so that repeated
|
|
58
|
+
* detection in one CLI run costs one process rather than one per call.
|
|
59
|
+
*/
|
|
60
|
+
function isPnpmAvailable() {
|
|
61
|
+
if (cachedPnpmAvailable !== void 0) return cachedPnpmAvailable;
|
|
62
|
+
try {
|
|
63
|
+
cachedPnpmAvailable = pnpmAvailabilityFromProbe(spawnSync("pnpm", ["--version"], {
|
|
64
|
+
stdio: "ignore",
|
|
65
|
+
timeout: PNPM_PROBE_TIMEOUT_MS
|
|
66
|
+
}));
|
|
67
|
+
} catch {
|
|
68
|
+
cachedPnpmAvailable = false;
|
|
69
|
+
}
|
|
70
|
+
return cachedPnpmAvailable;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Detect the package manager for a Rebase project.
|
|
74
|
+
*
|
|
75
|
+
* Rebase recommends pnpm, so detection prefers it. Crucially, *how the CLI was
|
|
76
|
+
* invoked* (`npx` vs `pnpm dlx`, i.e. `npm_config_user_agent`) is deliberately
|
|
77
|
+
* ignored: running `npx @rebasepro/cli init` says nothing about how the user
|
|
78
|
+
* wants to manage the project they're creating, and letting it pin the scaffold
|
|
79
|
+
* to npm is what made every `npx`-invoked project an npm project.
|
|
80
|
+
*
|
|
81
|
+
* Detection order:
|
|
82
|
+
* 1. An existing lock file — an explicit choice we always respect
|
|
83
|
+
* (`pnpm-lock.yaml` wins over `package-lock.json` when both are present).
|
|
84
|
+
* 2. pnpm, whenever it is installed.
|
|
85
|
+
* 3. npm, only as a fallback when pnpm is genuinely unavailable.
|
|
86
|
+
*/
|
|
87
|
+
function detectPackageManager(targetDir) {
|
|
88
|
+
const dirs = [targetDir, process.cwd()].filter((d) => !!d);
|
|
89
|
+
for (const dir of dirs) {
|
|
90
|
+
if (fs.existsSync(path.join(dir, "pnpm-lock.yaml"))) return "pnpm";
|
|
91
|
+
if (fs.existsSync(path.join(dir, "package-lock.json"))) return "npm";
|
|
92
|
+
for (const [lock, name] of [
|
|
93
|
+
["yarn.lock", "yarn"],
|
|
94
|
+
["bun.lockb", "bun"],
|
|
95
|
+
["bun.lock", "bun"]
|
|
96
|
+
]) {
|
|
97
|
+
if (!fs.existsSync(path.join(dir, lock))) continue;
|
|
98
|
+
console.warn(`[rebase] Found ${lock}, but Rebase scaffolds pnpm or npm workspaces only — ${name} is not supported yet. Continuing with ${isPnpmAvailable() ? "pnpm" : "npm"}.`);
|
|
99
|
+
return isPnpmAvailable() ? "pnpm" : "npm";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (isPnpmAvailable()) return "pnpm";
|
|
103
|
+
return "npm";
|
|
104
|
+
}
|
|
105
|
+
/** Build the command helpers for a given package manager. */
|
|
106
|
+
function getPMCommands(pm) {
|
|
107
|
+
if (pm === "npm") return {
|
|
108
|
+
name: "npm",
|
|
109
|
+
install: ["npm", "install"],
|
|
110
|
+
run: (script) => [
|
|
111
|
+
"npm",
|
|
112
|
+
"run",
|
|
113
|
+
script
|
|
114
|
+
],
|
|
115
|
+
exec: (bin, args) => [
|
|
116
|
+
"npx",
|
|
117
|
+
bin,
|
|
118
|
+
...args
|
|
119
|
+
],
|
|
120
|
+
view: (pkg, field) => [
|
|
121
|
+
"npm",
|
|
122
|
+
"view",
|
|
123
|
+
pkg,
|
|
124
|
+
field
|
|
125
|
+
],
|
|
126
|
+
runAll: (script) => [
|
|
127
|
+
"npm",
|
|
128
|
+
"run",
|
|
129
|
+
script,
|
|
130
|
+
"--workspaces",
|
|
131
|
+
"--if-present"
|
|
132
|
+
],
|
|
133
|
+
runWorkspace: (workspace, script) => [
|
|
134
|
+
"npm",
|
|
135
|
+
"run",
|
|
136
|
+
script,
|
|
137
|
+
"-w",
|
|
138
|
+
workspace
|
|
139
|
+
],
|
|
140
|
+
dlx: (pkg, args) => [
|
|
141
|
+
"npx",
|
|
142
|
+
"-y",
|
|
143
|
+
pkg,
|
|
144
|
+
...args
|
|
145
|
+
],
|
|
146
|
+
workspaceProtocol: "*"
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
name: "pnpm",
|
|
150
|
+
install: ["pnpm", "install"],
|
|
151
|
+
run: (script) => [
|
|
152
|
+
"pnpm",
|
|
153
|
+
"run",
|
|
154
|
+
script
|
|
155
|
+
],
|
|
156
|
+
exec: (bin, args) => [
|
|
157
|
+
"pnpm",
|
|
158
|
+
"exec",
|
|
159
|
+
bin,
|
|
160
|
+
...args
|
|
161
|
+
],
|
|
162
|
+
view: (pkg, field) => [
|
|
163
|
+
"pnpm",
|
|
164
|
+
"view",
|
|
165
|
+
pkg,
|
|
166
|
+
field
|
|
167
|
+
],
|
|
168
|
+
runAll: (script) => [
|
|
169
|
+
"pnpm",
|
|
170
|
+
"-r",
|
|
171
|
+
"run",
|
|
172
|
+
script
|
|
173
|
+
],
|
|
174
|
+
runWorkspace: (workspace, script) => [
|
|
175
|
+
"pnpm",
|
|
176
|
+
"--filter",
|
|
177
|
+
`./${workspace}`,
|
|
178
|
+
"run",
|
|
179
|
+
script
|
|
180
|
+
],
|
|
181
|
+
dlx: (pkg, args) => [
|
|
182
|
+
"pnpm",
|
|
183
|
+
"dlx",
|
|
184
|
+
pkg,
|
|
185
|
+
...args
|
|
186
|
+
],
|
|
187
|
+
workspaceProtocol: "workspace:*"
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
export { getPMCommands as n, package_manager_exports as r, detectPackageManager as t };
|
|
192
|
+
|
|
193
|
+
//# sourceMappingURL=package-manager-DSEOwTqM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package-manager-DSEOwTqM.js","names":[],"sources":["../src/utils/package-manager.ts"],"sourcesContent":["/**\n * Package manager detection and command abstraction.\n *\n * Detects whether the user is running pnpm or npm and provides\n * a unified interface for common package-manager operations so\n * the rest of the CLI never has to hardcode a specific PM.\n */\nimport fs from \"fs\";\nimport path from \"path\";\nimport { spawnSync } from \"child_process\";\n\n/**\n * The two package managers the CLI can scaffold for.\n *\n * Yarn and bun are deliberately absent, and this is the note that says so\n * rather than leaving it to be discovered. A yarn or bun user gets an npm\n * project: `detectPackageManager` finds no `pnpm-lock.yaml` and no\n * `package-lock.json`, falls through to the pnpm probe, and lands on npm —\n * silently, and with a `yarn.lock` or `bun.lockb` sitting right there in the\n * directory it was asked about.\n *\n * The reason is not indifference. Every generated project is a workspace, and\n * the scaffold writes one protocol for the workspace links —\n * `workspaceProtocol` below is `\"workspace:*\"` or `\"*\"`. Yarn understands\n * `workspace:*` and bun does not; the two also disagree with pnpm about where\n * `node_modules` goes, which is what `rebase dev` walks to find the backend.\n * Supporting them means a fourth and fifth scaffold shape, each needing its own\n * end-to-end test, and neither exists.\n *\n * So the honest position is: pnpm (recommended) or npm. A yarn or bun user is\n * better served knowing they will get an npm workspace than finding out from\n * the lockfile that appears after their first install. See\n * {@link detectPackageManager}, which now says so out loud.\n */\nexport type PackageManager = \"pnpm\" | \"npm\";\n\nexport interface PMCommands {\n /** The binary name (\"pnpm\" | \"npm\"). */\n name: PackageManager;\n /** Install all dependencies — e.g. `pnpm install` / `npm install`. */\n install: string[];\n /** Run a script — e.g. `pnpm run dev` / `npm run dev`. */\n run: (script: string) => string[];\n /** Execute a local bin — e.g. `pnpm exec rebase ...` / `npx rebase ...`. */\n exec: (bin: string, args: string[]) => string[];\n /** Query the registry — e.g. `pnpm view <pkg> version` / `npm view <pkg> version`. */\n view: (pkg: string, field: string) => string[];\n /** Run all workspace scripts — e.g. `pnpm -r run build` / `npm run build --workspaces`. */\n runAll: (script: string) => string[];\n /** Run a script in a specific workspace — e.g. `pnpm --filter \"*-backend\" start` / `npm run start -w backend`. */\n runWorkspace: (workspace: string, script: string) => string[];\n /** Execute a one-off package — e.g. `pnpm dlx skills ...` / `npx -y skills ...`. */\n dlx: (pkg: string, args: string[]) => string[];\n /** The workspace dependency protocol: `\"workspace:*\"` for pnpm, `\"*\"` for npm. */\n workspaceProtocol: string;\n}\n\n/**\n * How long to wait for `pnpm --version` before giving up on the probe.\n *\n * `pnpm --version` is a cold Node start, and on a machine that is busy — a\n * parallel install, a full test run — it routinely takes seconds. Measured at\n * 630ms, 990ms and 4293ms on three consecutive runs of one developer laptop\n * under load, so the previous 3s budget was inside the normal spread rather\n * than safely outside it.\n */\nconst PNPM_PROBE_TIMEOUT_MS = 5000;\n\n/** Memoised result of the probe. pnpm cannot appear or vanish mid-process. */\nlet cachedPnpmAvailable: boolean | undefined;\n\n/**\n * Decide availability from a `spawnSync` outcome.\n *\n * Split out from the spawn itself so the decision is testable without starting\n * a process — which is what made the old test load-sensitive and occasionally\n * red for reasons that had nothing to do with the code under test.\n *\n * The three outcomes are distinguishable, and the old code conflated two of\n * them by asking only `status === 0`:\n *\n * not installed status null, signal null, error.code ENOENT\n * timed out status null, signal SIGTERM, error.code ETIMEDOUT\n * broken install status non-zero, no error\n */\nexport function pnpmAvailabilityFromProbe(res: {\n status: number | null;\n signal?: NodeJS.Signals | null;\n error?: { code?: string } | Error;\n}): boolean {\n const code = (res.error as { code?: string } | undefined)?.code;\n\n // The binary is not on PATH. Genuinely absent.\n if (code === \"ENOENT\") return false;\n\n // We killed it for taking too long. That means it WAS found and did start,\n // so pnpm is installed — it was merely slow, which on a loaded machine is\n // routine rather than exceptional. Reporting \"absent\" here is what silently\n // scaffolded npm projects for developers who had pnpm all along.\n //\n // The trade-off, stated plainly: a pnpm that hangs forever (a misbehaving\n // corepack shim) now resolves to pnpm instead of falling back to npm. That\n // is the rarer and more visible failure — the user sees their next command\n // hang — whereas the case this fixes was silent and produced a project\n // pinned to the wrong package manager. The timeout still bounds how long\n // detection itself waits, which was always its real job.\n if (code === \"ETIMEDOUT\" || res.signal) return true;\n\n // Any other spawn error: treat as unavailable rather than guess.\n if (res.error) return false;\n\n return res.status === 0;\n}\n\n/**\n * Whether pnpm is runnable on this machine.\n *\n * Used to decide whether a fresh project can be scaffolded with pnpm. Kept\n * cheap and non-interactive (bounded timeout, output discarded) so it never\n * hangs detection if a corepack shim misbehaves, and memoised so that repeated\n * detection in one CLI run costs one process rather than one per call.\n */\nexport function isPnpmAvailable(): boolean {\n if (cachedPnpmAvailable !== undefined) return cachedPnpmAvailable;\n try {\n const res = spawnSync(\"pnpm\", [\"--version\"], {\n stdio: \"ignore\",\n timeout: PNPM_PROBE_TIMEOUT_MS\n });\n cachedPnpmAvailable = pnpmAvailabilityFromProbe(res);\n } catch {\n cachedPnpmAvailable = false;\n }\n return cachedPnpmAvailable;\n}\n\n/** Forget the memoised probe. For tests; nothing in a CLI run needs it. */\nexport function resetPnpmAvailabilityCache(): void {\n cachedPnpmAvailable = undefined;\n}\n\n/**\n * Detect the package manager for a Rebase project.\n *\n * Rebase recommends pnpm, so detection prefers it. Crucially, *how the CLI was\n * invoked* (`npx` vs `pnpm dlx`, i.e. `npm_config_user_agent`) is deliberately\n * ignored: running `npx @rebasepro/cli init` says nothing about how the user\n * wants to manage the project they're creating, and letting it pin the scaffold\n * to npm is what made every `npx`-invoked project an npm project.\n *\n * Detection order:\n * 1. An existing lock file — an explicit choice we always respect\n * (`pnpm-lock.yaml` wins over `package-lock.json` when both are present).\n * 2. pnpm, whenever it is installed.\n * 3. npm, only as a fallback when pnpm is genuinely unavailable.\n */\nexport function detectPackageManager(targetDir?: string): PackageManager {\n // 1. Respect an existing project's lock file.\n const dirs = [targetDir, process.cwd()].filter((d): d is string => !!d);\n for (const dir of dirs) {\n if (fs.existsSync(path.join(dir, \"pnpm-lock.yaml\"))) return \"pnpm\";\n if (fs.existsSync(path.join(dir, \"package-lock.json\"))) return \"npm\";\n\n // A yarn or bun lockfile is a stated choice this CLI cannot honour —\n // see the note on `PackageManager`. Say so once, here, rather than\n // scaffolding an npm workspace beside their lockfile without comment.\n for (const [lock, name] of [[\"yarn.lock\", \"yarn\"], [\"bun.lockb\", \"bun\"], [\"bun.lock\", \"bun\"]] as const) {\n if (!fs.existsSync(path.join(dir, lock))) continue;\n console.warn(\n `[rebase] Found ${lock}, but Rebase scaffolds pnpm or npm workspaces only — ` +\n `${name} is not supported yet. Continuing with ` +\n `${isPnpmAvailable() ? \"pnpm\" : \"npm\"}.`\n );\n return isPnpmAvailable() ? \"pnpm\" : \"npm\";\n }\n }\n\n // 2. Prefer pnpm whenever it's installed.\n if (isPnpmAvailable()) return \"pnpm\";\n\n // 3. Fall back to npm only when pnpm is genuinely unavailable.\n return \"npm\";\n}\n\n/** Build the command helpers for a given package manager. */\nexport function getPMCommands(pm: PackageManager): PMCommands {\n if (pm === \"npm\") {\n return {\n name: \"npm\",\n install: [\"npm\", \"install\"],\n run: (script) => [\"npm\", \"run\", script],\n exec: (bin, args) => [\"npx\", bin, ...args],\n view: (pkg, field) => [\"npm\", \"view\", pkg, field],\n runAll: (script) => [\"npm\", \"run\", script, \"--workspaces\", \"--if-present\"],\n runWorkspace: (workspace, script) => [\"npm\", \"run\", script, \"-w\", workspace],\n dlx: (pkg, args) => [\"npx\", \"-y\", pkg, ...args],\n workspaceProtocol: \"*\"\n };\n }\n\n return {\n name: \"pnpm\",\n install: [\"pnpm\", \"install\"],\n run: (script) => [\"pnpm\", \"run\", script],\n exec: (bin, args) => [\"pnpm\", \"exec\", bin, ...args],\n view: (pkg, field) => [\"pnpm\", \"view\", pkg, field],\n runAll: (script) => [\"pnpm\", \"-r\", \"run\", script],\n // Filter by directory (`./backend`), not name: pnpm's `--filter` matches\n // the package *name* (e.g. `my-app-backend`), so a bare `backend` matches\n // nothing. npm's `-w` is path-based, which is why this only bites pnpm.\n runWorkspace: (workspace, script) => [\"pnpm\", \"--filter\", `./${workspace}`, \"run\", script],\n dlx: (pkg, args) => [\"pnpm\", \"dlx\", pkg, ...args],\n workspaceProtocol: \"workspace:*\"\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,IAAM,wBAAwB;;AAG9B,IAAI;;;;;;;;;;;;;;;AAgBJ,SAAgB,0BAA0B,KAI9B;CACR,MAAM,OAAQ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GAAO;GAAK,GAAG;EAAI;EACzC,OAAO,KAAK,UAAU;GAAC;GAAO;GAAQ;GAAK;EAAK;EAChD,SAAS,WAAW;GAAC;GAAO;GAAO;GAAQ;GAAgB;EAAc;EACzE,eAAe,WAAW,WAAW;GAAC;GAAO;GAAO;GAAQ;GAAM;EAAS;EAC3E,MAAM,KAAK,SAAS;GAAC;GAAO;GAAM;GAAK,GAAG;EAAI;EAC9C,mBAAmB;CACvB;CAGJ,OAAO;EACH,MAAM;EACN,SAAS,CAAC,QAAQ,SAAS;EAC3B,MAAM,WAAW;GAAC;GAAQ;GAAO;EAAM;EACvC,OAAO,KAAK,SAAS;GAAC;GAAQ;GAAQ;GAAK,GAAG;EAAI;EAClD,OAAO,KAAK,UAAU;GAAC;GAAQ;GAAQ;GAAK;EAAK;EACjD,SAAS,WAAW;GAAC;GAAQ;GAAM;GAAO;EAAM;EAIhD,eAAe,WAAW,WAAW;GAAC;GAAQ;GAAY,KAAK;GAAa;GAAO;EAAM;EACzF,MAAM,KAAK,SAAS;GAAC;GAAQ;GAAO;GAAK,GAAG;EAAI;EAChD,mBAAmB;CACvB;AACJ"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
//#region src/utils/path-flags.ts
|
|
5
|
+
/**
|
|
6
|
+
* Where a path typed on a `rebase` command line resolves: one rule, one sentence.
|
|
7
|
+
*
|
|
8
|
+
* The driver CLI runs with `cwd: backend/` — that is where it and its
|
|
9
|
+
* dependencies resolve from — while people type commands from the project root
|
|
10
|
+
* (or anywhere else in it). So every relative path on the line is resolved by
|
|
11
|
+
* the CLI, from the directory the command was run in, before the driver is
|
|
12
|
+
* handed a different one (`absolutizeLocalPathArgs` in `commands/db.ts`).
|
|
13
|
+
* `generate-sdk` and `db backup --out` already worked that way; `--collections`
|
|
14
|
+
* was resolved from `backend/` and was the odd one out.
|
|
15
|
+
*
|
|
16
|
+
* The sentence below is printed by every help page that takes `--collections`,
|
|
17
|
+
* and by the refusal when the path is not there, so the rule is stated in one
|
|
18
|
+
* set of words wherever a reader meets it.
|
|
19
|
+
*/
|
|
20
|
+
/** The rule, as every help page and error states it. */
|
|
21
|
+
var COLLECTIONS_PATH_RULE = "relative paths are resolved from where you run the command";
|
|
22
|
+
/** The `--collections` line of a help page. */
|
|
23
|
+
var COLLECTIONS_FLAG_HELP = `Collections directory (default: config/collections); ${COLLECTIONS_PATH_RULE}`;
|
|
24
|
+
/** The flags that carry a collections path, in every spelling the driver accepts. */
|
|
25
|
+
var COLLECTIONS_FLAGS = ["--collections", "-c"];
|
|
26
|
+
/** The `--collections` value on a line, as typed, or `null` when there is none. */
|
|
27
|
+
function typedCollectionsPath(args) {
|
|
28
|
+
for (let i = 0; i < args.length; i++) {
|
|
29
|
+
const token = args[i];
|
|
30
|
+
const eq = token.indexOf("=");
|
|
31
|
+
if (eq > 0 && COLLECTIONS_FLAGS.includes(token.slice(0, eq))) return token.slice(eq + 1) || null;
|
|
32
|
+
if (COLLECTIONS_FLAGS.includes(token)) {
|
|
33
|
+
const value = args[i + 1];
|
|
34
|
+
return value && !value.startsWith("-") ? value : null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The refusal for a `--collections` path that does not exist, or `null`.
|
|
41
|
+
*
|
|
42
|
+
* Checked by the CLI, in the reader's terms, before the driver is spawned: the
|
|
43
|
+
* driver's own check runs in `backend/` and can only describe the path it was
|
|
44
|
+
* handed. A generator pointed at a directory that is not there writes an empty
|
|
45
|
+
* schema, and a push of an empty schema drops every table — so nothing runs.
|
|
46
|
+
*
|
|
47
|
+
* Scripts written for the old rule (`--collections ../config/collections`,
|
|
48
|
+
* run from the root) land here, and the message says exactly what to change.
|
|
49
|
+
*/
|
|
50
|
+
function missingCollectionsPath(args, cwd, backendDir) {
|
|
51
|
+
const typed = typedCollectionsPath(args);
|
|
52
|
+
if (typed === null) return null;
|
|
53
|
+
const resolved = path.resolve(cwd, typed);
|
|
54
|
+
if (fs.existsSync(resolved)) return null;
|
|
55
|
+
const lines = [
|
|
56
|
+
chalk.red(`✗ Collections path not found: "${typed}"`),
|
|
57
|
+
chalk.gray(` Resolved to: ${resolved}`),
|
|
58
|
+
chalk.gray(` (${COLLECTIONS_PATH_RULE}: ${cwd})`)
|
|
59
|
+
];
|
|
60
|
+
const fromBackend = path.resolve(backendDir, typed);
|
|
61
|
+
if (!path.isAbsolute(typed) && fs.existsSync(fromBackend)) lines.push("", chalk.yellow(` From backend/ it would be ${fromBackend} — the driver used to resolve paths from there.`), chalk.yellow(` Leave the flag out (config/collections is the default), or write it from here: ${path.relative(cwd, fromBackend) || "."}`));
|
|
62
|
+
lines.push("", chalk.gray(" Nothing was generated and nothing was applied — a schema generated from a"), chalk.gray(" directory that is not there is an empty one, and applying it would drop"), chalk.gray(" every table it does not describe."));
|
|
63
|
+
return lines;
|
|
64
|
+
}
|
|
65
|
+
/** Print {@link missingCollectionsPath}'s refusal and exit 1, or return. */
|
|
66
|
+
function refuseMissingCollectionsPath(args, cwd, backendDir) {
|
|
67
|
+
const lines = missingCollectionsPath(args, cwd, backendDir);
|
|
68
|
+
if (!lines) return;
|
|
69
|
+
console.error("");
|
|
70
|
+
for (const line of lines) console.error(line);
|
|
71
|
+
console.error("");
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { COLLECTIONS_PATH_RULE as n, refuseMissingCollectionsPath as r, COLLECTIONS_FLAG_HELP as t };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=path-flags-DUBuI2i1.js.map
|