@rebasepro/cli 0.30.1 → 0.31.0-canary.g902a0ce
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 +8 -7
- package/dist/{agent-setup-0uyfC7VX.js → agent-setup-DqAcoDcn.js} +10 -5
- package/dist/{agent-setup-0uyfC7VX.js.map → agent-setup-DqAcoDcn.js.map} +1 -1
- package/dist/{api-keys-Dfw5-9s1.js → api-keys-eIUjMqWn.js} +8 -7
- package/dist/api-keys-eIUjMqWn.js.map +1 -0
- package/dist/{apps-MKQbgDtN.js → apps-DExO4PEl.js} +8 -7
- package/dist/apps-DExO4PEl.js.map +1 -0
- package/dist/{project-CasK56vN.js → args-CaCcrYE1.js} +2 -351
- package/dist/args-CaCcrYE1.js.map +1 -0
- package/dist/{atlas-dev-database-BODqdCWt.js → atlas-dev-database-DOCKk6ht.js} +2 -2
- package/dist/{atlas-dev-database-BODqdCWt.js.map → atlas-dev-database-DOCKk6ht.js.map} +1 -1
- package/dist/{auth-Bv0rTbQX.js → auth-CyADghFQ.js} +7 -6
- package/dist/{auth-Bv0rTbQX.js.map → auth-CyADghFQ.js.map} +1 -1
- package/dist/backend-guard-C0mVkXBw.js +162 -0
- package/dist/backend-guard-C0mVkXBw.js.map +1 -0
- package/dist/{branch-pointer-BQUF6lYa.js → branch-pointer-DMPyvZoK.js} +1 -1
- package/dist/{build-BuKTnec8.js → build-CA5R07tw.js} +29 -9
- package/dist/build-CA5R07tw.js.map +1 -0
- package/dist/{bundle-BAH4FCju.js → bundle-DgILeA5b.js} +112 -138
- package/dist/bundle-DgILeA5b.js.map +1 -0
- package/dist/bundle.d.ts +35 -12
- package/dist/cli.d.ts +2 -2
- package/dist/{cloud-DtADfWwn.js → cloud-CYMk92iG.js} +72 -71
- package/dist/cloud-CYMk92iG.js.map +1 -0
- package/dist/cms-directories-BK3vcswg.js +33 -0
- package/dist/cms-directories-BK3vcswg.js.map +1 -0
- package/dist/codemod/collections-to-tables/ast.d.ts +135 -0
- package/dist/codemod/collections-to-tables/backend.d.ts +38 -0
- package/dist/codemod/collections-to-tables/command.d.ts +35 -0
- package/dist/codemod/collections-to-tables/comments.d.ts +45 -0
- package/dist/codemod/collections-to-tables/customization.d.ts +47 -0
- package/dist/codemod/collections-to-tables/dynamic-props.d.ts +34 -0
- package/dist/codemod/collections-to-tables/export-changes.d.ts +83 -0
- package/dist/codemod/collections-to-tables/firestore.d.ts +11 -0
- package/dist/codemod/collections-to-tables/helper-hooks.d.ts +41 -0
- package/dist/codemod/collections-to-tables/hooks.d.ts +44 -0
- package/dist/codemod/collections-to-tables/journal.d.ts +10 -0
- package/dist/codemod/collections-to-tables/legacy-shims.d.ts +52 -0
- package/dist/codemod/collections-to-tables/load-legacy.d.ts +81 -0
- package/dist/codemod/collections-to-tables/migrate.d.ts +20 -0
- package/dist/codemod/collections-to-tables/modules.d.ts +127 -0
- package/dist/codemod/collections-to-tables/moved-imports.d.ts +70 -0
- package/dist/codemod/collections-to-tables/moved-symbols.generated.d.ts +12 -0
- package/dist/codemod/collections-to-tables/own.d.ts +10 -0
- package/dist/codemod/collections-to-tables/path-aliases.d.ts +26 -0
- package/dist/codemod/collections-to-tables/plan-context.d.ts +49 -0
- package/dist/codemod/collections-to-tables/print-js.d.ts +44 -0
- package/dist/codemod/collections-to-tables/project-files.d.ts +144 -0
- package/dist/codemod/collections-to-tables/repoint.d.ts +50 -0
- package/dist/codemod/collections-to-tables/row-hands.d.ts +7 -0
- package/dist/codemod/collections-to-tables/sdk-calls.d.ts +88 -0
- package/dist/codemod/collections-to-tables/skills-step.d.ts +13 -0
- package/dist/codemod/collections-to-tables/split-constants.d.ts +42 -0
- package/dist/codemod/collections-to-tables/storage-paths.d.ts +28 -0
- package/dist/codemod/collections-to-tables/types.d.ts +164 -0
- package/dist/codemod/collections-to-tables/verify.d.ts +27 -0
- package/dist/codemod/collections-to-tables/vocabulary.d.ts +40 -0
- package/dist/command-D5lhW_-B.js +9984 -0
- package/dist/command-D5lhW_-B.js.map +1 -0
- package/dist/commands/agent-setup.d.ts +6 -2
- package/dist/commands/cloud/context.d.ts +1 -1
- package/dist/commands/cloud/init.d.ts +2 -2
- package/dist/commands/console.d.ts +1 -2
- package/dist/commands/db.d.ts +5 -6
- package/dist/commands/dev.d.ts +18 -17
- package/dist/commands/doctor.d.ts +4 -5
- package/dist/commands/eject.d.ts +17 -13
- package/dist/commands/generate-view.d.ts +20 -9
- package/dist/commands/generate_sdk.d.ts +27 -27
- package/dist/commands/init.d.ts +21 -8
- package/dist/commands/migrate.d.ts +24 -0
- package/dist/commands/schema-reconcile.d.ts +1 -1
- package/dist/commands/skills.d.ts +8 -0
- package/dist/commands/verify-cms.d.ts +28 -0
- package/dist/commands/verify.d.ts +14 -9
- package/dist/{consent-BD7F29T3.js → consent-BXLIrMl8.js} +2 -2
- package/dist/{consent-BD7F29T3.js.map → consent-BXLIrMl8.js.map} +1 -1
- package/dist/{console-CdwIYOMV.js → console-CMjhgMUE.js} +14 -14
- package/dist/console-CMjhgMUE.js.map +1 -0
- package/dist/{context-AXdAh-q8.js → context--JwaHaZp.js} +6 -5
- package/dist/context--JwaHaZp.js.map +1 -0
- package/dist/{daemon-Cp7oNXth.js → daemon-w30PsdwV.js} +2 -2
- package/dist/{daemon-Cp7oNXth.js.map → daemon-w30PsdwV.js.map} +1 -1
- package/dist/{db-DBbKpjYX.js → db-A7XDCIIO.js} +51 -51
- package/dist/db-A7XDCIIO.js.map +1 -0
- package/dist/{derive-ae9UOoOB.js → derive-C3ezmY-p.js} +105 -133
- package/dist/derive-C3ezmY-p.js.map +1 -0
- package/dist/dev-db/attver.d.ts +11 -0
- package/dist/{dev-preflight-Cxv3TiD1.js → dev-preflight-DjvcV6SK.js} +5 -5
- package/dist/dev-preflight-DjvcV6SK.js.map +1 -0
- package/dist/{dev-server-OJsUGZEB.js → dev-server-BLxCbQEP.js} +2 -2
- package/dist/{dev-server-OJsUGZEB.js.map → dev-server-BLxCbQEP.js.map} +1 -1
- package/dist/{dev-C93d4QIv.js → dev-tWwPyWkQ.js} +142 -84
- package/dist/dev-tWwPyWkQ.js.map +1 -0
- package/dist/{doctor-BBPQUO2g.js → doctor-BBM0dWvZ.js} +39 -62
- package/dist/doctor-BBM0dWvZ.js.map +1 -0
- package/dist/doctor-environment.d.ts +6 -6
- package/dist/{eject-DABcDnPN.js → eject-Bhzd6hgb.js} +25 -16
- package/dist/eject-Bhzd6hgb.js.map +1 -0
- package/dist/{fold-static-BWzxNn06.js → fold-static-CKewnAPX.js} +5 -3
- package/dist/fold-static-CKewnAPX.js.map +1 -0
- package/dist/{generate-view-IFwCADvb.js → generate-view-CTOluXvH.js} +160 -89
- package/dist/generate-view-CTOluXvH.js.map +1 -0
- package/dist/{generate_sdk-DNmNuFuW.js → generate_sdk-De-aLC1L.js} +120 -137
- package/dist/generate_sdk-De-aLC1L.js.map +1 -0
- package/dist/import-schema-module-Df67TIWj.js +51 -0
- package/dist/import-schema-module-Df67TIWj.js.map +1 -0
- package/dist/index.es.js +64 -51
- package/dist/index.es.js.map +1 -1
- package/dist/{init-vL1DWOeC.js → init-Dtl-IcXf.js} +83 -80
- package/dist/init-Dtl-IcXf.js.map +1 -0
- package/dist/last-dev-database-Dc8cP01o.js +2 -0
- package/dist/{manifest-BtzDy7KQ.js → manifest-C3uLDrrJ.js} +115 -40
- package/dist/manifest-C3uLDrrJ.js.map +1 -0
- package/dist/manifest.d.ts +79 -24
- package/dist/migrate-VrKoi3nB.js +138 -0
- package/dist/migrate-VrKoi3nB.js.map +1 -0
- package/dist/{normalize-imports-Bd5Y4yLp.js → normalize-imports-DwxqEMYq.js} +3 -3
- package/dist/{normalize-imports-Bd5Y4yLp.js.map → normalize-imports-DwxqEMYq.js.map} +1 -1
- package/dist/path-flags-7O5uPBcQ.js +139 -0
- package/dist/path-flags-7O5uPBcQ.js.map +1 -0
- package/dist/{prepare-CTw9NEkh.js → prepare-Ccxspoj-.js} +4 -4
- package/dist/{prepare-CTw9NEkh.js.map → prepare-Ccxspoj-.js.map} +1 -1
- package/dist/project-CLcF5i8c.js +360 -0
- package/dist/project-CLcF5i8c.js.map +1 -0
- package/dist/project-schema-CsSOG2gE.js +30 -0
- package/dist/project-schema-CsSOG2gE.js.map +1 -0
- package/dist/{pull-DDMpsZ5r.js → pull-D9WvpDYY.js} +189 -1
- package/dist/pull-D9WvpDYY.js.map +1 -0
- package/dist/resolve-BY7bSFRT.js +2 -0
- package/dist/resources/derive.d.ts +19 -13
- package/dist/{resources-CPSC5Kcu.js → resources-Dpfs2y8P.js} +5 -4
- package/dist/{resources-CPSC5Kcu.js.map → resources-Dpfs2y8P.js.map} +1 -1
- package/dist/{schema-DtLPsXbT.js → schema-DwFDI1iU.js} +41 -39
- package/dist/schema-DwFDI1iU.js.map +1 -0
- package/dist/schema-dir-Cd1kvYbf.js +98 -0
- package/dist/schema-dir-Cd1kvYbf.js.map +1 -0
- package/dist/schema-reconcile-Tto54Qbv.js +2 -0
- package/dist/schema-text-CpNrsuMe.js +73 -0
- package/dist/schema-text-CpNrsuMe.js.map +1 -0
- package/dist/{skills-CbwV6vw_.js → skills-CXjA9TWw.js} +54 -10
- package/dist/skills-CXjA9TWw.js.map +1 -0
- package/dist/{start-YOr3X5Zm.js → start-Bwbtt2W5.js} +7 -10
- package/dist/{start-YOr3X5Zm.js.map → start-Bwbtt2W5.js.map} +1 -1
- package/dist/{status-BREvtzJm.js → status-DQ_PPz4C.js} +12 -12
- package/dist/status-DQ_PPz4C.js.map +1 -0
- package/dist/{storage-CO9ouK76.js → storage-iTqj5-Av.js} +12 -11
- package/dist/storage-iTqj5-Av.js.map +1 -0
- package/dist/{telemetry-DwK5RQJl.js → telemetry-BP_1Cl9r.js} +4 -4
- package/dist/{telemetry-DwK5RQJl.js.map → telemetry-BP_1Cl9r.js.map} +1 -1
- package/dist/{telemetry-CgwJPVMO.js → telemetry-M3HjlyhZ.js} +2 -2
- package/dist/{telemetry-CgwJPVMO.js.map → telemetry-M3HjlyhZ.js.map} +1 -1
- package/dist/{upgrade-B7sVwL8S.js → upgrade-oZzJ13jM.js} +5 -4
- package/dist/{upgrade-B7sVwL8S.js.map → upgrade-oZzJ13jM.js.map} +1 -1
- package/dist/utils/backend-guard.d.ts +47 -0
- package/dist/utils/cms-directories.d.ts +6 -0
- package/dist/utils/dev-preflight.d.ts +2 -2
- package/dist/utils/import-schema-module.d.ts +16 -0
- package/dist/utils/path-flags.d.ts +35 -16
- package/dist/utils/project-schema.d.ts +40 -0
- package/dist/utils/project.d.ts +8 -2
- package/dist/utils/schema-dir.d.ts +32 -0
- package/dist/utils/schema-drift.d.ts +6 -0
- package/dist/utils/schema-text.d.ts +24 -0
- package/dist/verify-DkJqhYPI.js +1160 -0
- package/dist/verify-DkJqhYPI.js.map +1 -0
- package/package.json +11 -8
- package/runtime/dev-server.mjs +5 -1
- package/templates/eject/Dockerfile +1 -4
- package/templates/eject/backend/src/env.ts +1 -1
- package/templates/eject/backend/src/index.ts +53 -40
- package/templates/eject/docker-compose.custom.yml +1 -1
- package/templates/overlays/baas/README.md +39 -12
- package/templates/overlays/baas/ai-instructions.md +8 -8
- package/templates/overlays/baas/{config → backend}/storage.ts +3 -4
- package/templates/overlays/baas/backend/tsconfig.json +10 -12
- package/templates/overlays/baas/package.json +1 -2
- package/templates/overlays/baas/pnpm-workspace.yaml +0 -1
- package/templates/presets/blank/backend/schema/index.ts +19 -0
- package/templates/presets/blank/frontend/src/App.tsx +56 -0
- package/templates/presets/ecommerce/backend/schema/categories.ts +12 -0
- package/templates/presets/ecommerce/backend/schema/index.ts +23 -0
- package/templates/presets/ecommerce/backend/schema/orders.ts +13 -0
- package/templates/presets/ecommerce/backend/schema/products.ts +18 -0
- package/templates/presets/ecommerce/frontend/src/App.tsx +59 -0
- package/templates/presets/ecommerce/frontend/src/cms/categories.tsx +12 -0
- package/templates/presets/ecommerce/frontend/src/cms/orders.tsx +38 -0
- package/templates/presets/ecommerce/frontend/src/cms/products.tsx +27 -0
- package/templates/resource-graphs/blank.json +2 -2
- package/templates/resource-graphs/blog.json +5 -5
- package/templates/resource-graphs/ecommerce.json +5 -5
- package/templates/resource-graphs/headless.json +1 -1
- package/templates/template/.claude/hooks/post-edit-collection.sh +27 -23
- package/templates/template/.cursorrules +2 -2
- package/templates/template/.env.example +6 -17
- package/templates/template/.github/copilot-instructions.md +2 -2
- package/templates/template/.windsurfrules +2 -2
- package/templates/template/AGENTS.md +2 -2
- package/templates/template/CLAUDE.md +2 -2
- package/templates/template/README.md +47 -13
- package/templates/template/ai-instructions.md +15 -14
- package/templates/template/backend/functions/hello.ts +1 -1
- package/templates/template/backend/package.json +0 -2
- package/templates/template/{config → backend}/resources.ts +3 -3
- package/templates/template/backend/schema/authors.ts +11 -0
- package/templates/template/backend/schema/index.ts +29 -0
- package/templates/template/backend/schema/posts.ts +29 -0
- package/templates/template/backend/schema/tags.ts +9 -0
- package/templates/template/backend/schema/users.ts +32 -0
- package/templates/template/{config → backend}/storage.ts +4 -4
- package/templates/template/backend/tsconfig.json +15 -20
- package/templates/template/docker-compose.yml +3 -3
- package/templates/template/frontend/package.json +0 -2
- package/templates/template/frontend/src/App.tsx +10 -4
- package/templates/template/frontend/src/cms/authors.tsx +7 -0
- package/templates/template/frontend/src/cms/posts.tsx +27 -0
- package/templates/template/frontend/src/cms/tags.tsx +11 -0
- package/templates/template/frontend/src/cms/ui-config.json +3 -0
- package/templates/template/frontend/src/cms/users.tsx +54 -0
- package/templates/template/frontend/src/{virtual.d.ts → vite-env.d.ts} +0 -4
- package/templates/template/frontend/vite.config.ts +6 -2
- package/templates/template/gitignore +1 -1
- package/templates/template/package.json +1 -2
- package/templates/template/pnpm-workspace.yaml +0 -1
- package/templates/template/scripts/example.ts +3 -3
- package/templates/template/tsconfig.json +1 -1
- package/templates/views/AppView.tsx.tmpl +4 -4
- package/templates/views/EntityView.tsx.tmpl +3 -4
- package/dist/api-keys-Dfw5-9s1.js.map +0 -1
- package/dist/apps-MKQbgDtN.js.map +0 -1
- package/dist/build-BuKTnec8.js.map +0 -1
- package/dist/bundle-BAH4FCju.js.map +0 -1
- package/dist/cloud-DtADfWwn.js.map +0 -1
- package/dist/collection-drift-BKj_BoMq.js +0 -106
- package/dist/collection-drift-BKj_BoMq.js.map +0 -1
- package/dist/collections-dir-DlvDhime.js +0 -69
- package/dist/collections-dir-DlvDhime.js.map +0 -1
- package/dist/console-CdwIYOMV.js.map +0 -1
- package/dist/context-AXdAh-q8.js.map +0 -1
- package/dist/db-DBbKpjYX.js.map +0 -1
- package/dist/derive-ae9UOoOB.js.map +0 -1
- package/dist/dev-C93d4QIv.js.map +0 -1
- package/dist/dev-preflight-Cxv3TiD1.js.map +0 -1
- package/dist/doctor-BBPQUO2g.js.map +0 -1
- package/dist/eject-DABcDnPN.js.map +0 -1
- package/dist/fold-static-BWzxNn06.js.map +0 -1
- package/dist/generate-view-IFwCADvb.js.map +0 -1
- package/dist/generate_sdk-DNmNuFuW.js.map +0 -1
- package/dist/init-vL1DWOeC.js.map +0 -1
- package/dist/last-dev-database-DpW5dfoX.js +0 -2
- package/dist/manifest-BtzDy7KQ.js.map +0 -1
- package/dist/path-flags-DNvtEi2-.js +0 -92
- package/dist/path-flags-DNvtEi2-.js.map +0 -1
- package/dist/project-CasK56vN.js.map +0 -1
- package/dist/pull-DDMpsZ5r.js.map +0 -1
- package/dist/resolve-D647F1LA.js +0 -2
- package/dist/schema-DtLPsXbT.js.map +0 -1
- package/dist/schema-reconcile-DkArN9jF.js +0 -2
- package/dist/skills-CbwV6vw_.js.map +0 -1
- package/dist/status-BREvtzJm.js.map +0 -1
- package/dist/storage-CO9ouK76.js.map +0 -1
- package/dist/utils/collection-drift.d.ts +0 -27
- package/dist/utils/collections-dir.d.ts +0 -14
- package/dist/verify-Y3rWSgfA.js +0 -730
- package/dist/verify-Y3rWSgfA.js.map +0 -1
- package/templates/overlays/baas/config/index.ts +0 -24
- package/templates/overlays/baas/config/package.json +0 -30
- package/templates/template/config/cms.d.ts +0 -15
- package/templates/template/config/collections/authors.ts +0 -47
- package/templates/template/config/collections/index.ts +0 -44
- package/templates/template/config/collections/posts.ts +0 -94
- package/templates/template/config/collections/presets/blank/index.ts +0 -5
- package/templates/template/config/collections/presets/ecommerce/categories.ts +0 -42
- package/templates/template/config/collections/presets/ecommerce/index.ts +0 -31
- package/templates/template/config/collections/presets/ecommerce/orders.ts +0 -78
- package/templates/template/config/collections/presets/ecommerce/products.ts +0 -73
- package/templates/template/config/collections/tags.ts +0 -27
- package/templates/template/config/collections/users.ts +0 -149
- package/templates/template/config/frontend-assets.d.ts +0 -17
- package/templates/template/config/index.ts +0 -12
- package/templates/template/config/package.json +0 -30
- package/templates/template/config/tsconfig.json +0 -35
- /package/templates/eject/{config → backend}/resources.ts +0 -0
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { n as getPMCommands, t as detectPackageManager } from "./package-manager-DSEOwTqM.js";
|
|
3
|
+
import { i as switchOn } from "./args-CaCcrYE1.js";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { pathToFileURL } from "url";
|
|
8
|
+
import { createRequire } from "module";
|
|
9
|
+
import { execSync } from "child_process";
|
|
10
|
+
import dotenv from "dotenv";
|
|
11
|
+
//#region src/utils/project.ts
|
|
12
|
+
/**
|
|
13
|
+
* Project discovery utilities for the Rebase CLI.
|
|
14
|
+
*
|
|
15
|
+
* These helpers locate the project root, backend directory, .env file,
|
|
16
|
+
* and local binaries — used by all CLI command modules.
|
|
17
|
+
*/
|
|
18
|
+
var project_exports = /* @__PURE__ */ __exportAll({
|
|
19
|
+
MANIFEST_FILENAME: () => MANIFEST_FILENAME,
|
|
20
|
+
dependenciesNotInstalled: () => dependenciesNotInstalled,
|
|
21
|
+
exitDependenciesNotInstalled: () => exitDependenciesNotInstalled,
|
|
22
|
+
failAsJson: () => failAsJson,
|
|
23
|
+
findBackendDir: () => findBackendDir,
|
|
24
|
+
findEnvFile: () => findEnvFile,
|
|
25
|
+
findFrontendDir: () => findFrontendDir,
|
|
26
|
+
findProjectRoot: () => findProjectRoot,
|
|
27
|
+
getActiveBackendPlugin: () => getActiveBackendPlugin,
|
|
28
|
+
readEnvFile: () => readEnvFile,
|
|
29
|
+
requireBackendDir: () => requireBackendDir,
|
|
30
|
+
requireProjectRoot: () => requireProjectRoot,
|
|
31
|
+
resolveLocalBin: () => resolveLocalBin,
|
|
32
|
+
resolvePluginCliScript: () => resolvePluginCliScript,
|
|
33
|
+
resolveTsx: () => resolveTsx,
|
|
34
|
+
resolveTsxLoader: () => resolveTsxLoader,
|
|
35
|
+
validateTsxInstallation: () => validateTsxInstallation,
|
|
36
|
+
wantsJsonOutput: () => wantsJsonOutput
|
|
37
|
+
});
|
|
38
|
+
/** The authored project manifest. Its presence alone marks a project root. */
|
|
39
|
+
var MANIFEST_FILENAME = "rebase.json";
|
|
40
|
+
/**
|
|
41
|
+
* Walk up from `startDir` to find the Rebase project root.
|
|
42
|
+
*
|
|
43
|
+
* A directory is the root when it holds a `rebase.json`, or when it holds a
|
|
44
|
+
* `package.json` that either lists `backend` as a workspace or sits beside a
|
|
45
|
+
* `backend/` directory.
|
|
46
|
+
*
|
|
47
|
+
* There is no `config/` requirement any more: the config package is gone (its
|
|
48
|
+
* collections became `backend/schema`, the rest moved into `backend/`), and a
|
|
49
|
+
* BaaS project is a `backend/` and nothing else. The `package.json` is still
|
|
50
|
+
* required beside it, so a stray `backend/` folder deep inside some unrelated
|
|
51
|
+
* tree does not make its parent a project.
|
|
52
|
+
*
|
|
53
|
+
* `rebase.json` is checked first and needs no `package.json` beside it, because
|
|
54
|
+
* the conventions below all describe a repository that *contains the backend*.
|
|
55
|
+
* A repository holding only a frontend — the normal shape once a project's apps
|
|
56
|
+
* live in separate repositories — matches none of them, so without this the
|
|
57
|
+
* tooling could not run there at all.
|
|
58
|
+
*/
|
|
59
|
+
function findProjectRoot(startDir = process.cwd()) {
|
|
60
|
+
let dir = path.resolve(startDir);
|
|
61
|
+
const root = path.parse(dir).root;
|
|
62
|
+
while (dir !== root) {
|
|
63
|
+
if (fs.existsSync(path.join(dir, "rebase.json"))) return dir;
|
|
64
|
+
const pkgPath = path.join(dir, "package.json");
|
|
65
|
+
if (fs.existsSync(pkgPath)) {
|
|
66
|
+
try {
|
|
67
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
68
|
+
if (pkg.workspaces && Array.isArray(pkg.workspaces)) {
|
|
69
|
+
if (pkg.workspaces.some((w) => w === "backend")) return dir;
|
|
70
|
+
}
|
|
71
|
+
} catch {}
|
|
72
|
+
if (fs.existsSync(path.join(dir, "backend"))) return dir;
|
|
73
|
+
}
|
|
74
|
+
dir = path.dirname(dir);
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Locate the backend directory within the project root.
|
|
80
|
+
*/
|
|
81
|
+
function findBackendDir(projectRoot) {
|
|
82
|
+
const backendDir = path.join(projectRoot, "backend");
|
|
83
|
+
return fs.existsSync(backendDir) ? backendDir : null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Detect the active backend plugin (e.g. @rebasepro/server-postgres) from the backend's package.json.
|
|
87
|
+
*/
|
|
88
|
+
function getActiveBackendPlugin(backendDir) {
|
|
89
|
+
const pkgPath = path.join(backendDir, "package.json");
|
|
90
|
+
if (!fs.existsSync(pkgPath)) return null;
|
|
91
|
+
try {
|
|
92
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
93
|
+
const deps = {
|
|
94
|
+
...pkg.dependencies,
|
|
95
|
+
...pkg.devDependencies
|
|
96
|
+
};
|
|
97
|
+
const candidates = Object.keys(deps).filter((dep) => dep.startsWith("@rebasepro/server-") && dep !== "@rebasepro/server");
|
|
98
|
+
if (candidates.length === 0) return null;
|
|
99
|
+
if (candidates.includes("@rebasepro/server-postgres")) return "@rebasepro/server-postgres";
|
|
100
|
+
for (const candidate of candidates) if (resolvePluginCliScript(backendDir, candidate)) return candidate;
|
|
101
|
+
return candidates[0];
|
|
102
|
+
} catch {}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Resolve the active plugin's CLI script.
|
|
107
|
+
*/
|
|
108
|
+
function resolvePluginCliScript(backendDir, pluginName) {
|
|
109
|
+
const candidates = [];
|
|
110
|
+
let dir = path.resolve(backendDir);
|
|
111
|
+
const fsRoot = path.parse(dir).root;
|
|
112
|
+
while (dir !== fsRoot) {
|
|
113
|
+
candidates.push(path.join(dir, "node_modules", pluginName, "src", "cli.ts"), path.join(dir, "node_modules", pluginName, "dist", "cli.js"));
|
|
114
|
+
dir = path.dirname(dir);
|
|
115
|
+
}
|
|
116
|
+
candidates.push(path.resolve(backendDir, "..", "..", "..", "packages", pluginName.replace("@rebasepro/", ""), "src", "cli.ts"), path.resolve(backendDir, "..", "..", "packages", pluginName.replace("@rebasepro/", ""), "src", "cli.ts"), path.resolve(backendDir, "..", "packages", pluginName.replace("@rebasepro/", ""), "src", "cli.ts"));
|
|
117
|
+
for (const candidate of candidates) if (fs.existsSync(candidate)) return candidate;
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Locate the frontend directory within the project root.
|
|
122
|
+
*/
|
|
123
|
+
function findFrontendDir(projectRoot) {
|
|
124
|
+
const frontendDir = path.join(projectRoot, "frontend");
|
|
125
|
+
return fs.existsSync(frontendDir) ? frontendDir : null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Find the .env file. Checks the project root first, then backend.
|
|
129
|
+
*/
|
|
130
|
+
function findEnvFile(projectRoot) {
|
|
131
|
+
const candidates = [path.join(projectRoot, ".env"), path.join(projectRoot, "backend", ".env")];
|
|
132
|
+
for (const candidate of candidates) if (fs.existsSync(candidate)) return candidate;
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Read the project's `.env` into a plain object.
|
|
137
|
+
*
|
|
138
|
+
* One reader, because there were four: `dotenv` in `start`, a hand-rolled
|
|
139
|
+
* `indexOf("=")` loop in `api-keys`, a single-key regex in `auth`, and its own
|
|
140
|
+
* splitting in `cloud env`. `dotenv` is a declared dependency of this package,
|
|
141
|
+
* so the other three existed for no reason and disagreed with the correct one
|
|
142
|
+
* on the two things people actually write in a `.env`:
|
|
143
|
+
*
|
|
144
|
+
* - `export KEY=value`, which the hand-rolled parser keyed as
|
|
145
|
+
* `export KEY` — so the command reported the key as unset while it was
|
|
146
|
+
* right there in the file;
|
|
147
|
+
* - `KEY=value # comment`, whose comment travelled into the value and then
|
|
148
|
+
* into an `Authorization` header, coming back as a 401 with nothing
|
|
149
|
+
* pointing at the cause.
|
|
150
|
+
*
|
|
151
|
+
* Returns `{}` when the project has no `.env`, so callers can treat "absent"
|
|
152
|
+
* and "empty" alike.
|
|
153
|
+
*/
|
|
154
|
+
function readEnvFile(projectRoot) {
|
|
155
|
+
const envFile = findEnvFile(projectRoot);
|
|
156
|
+
if (!envFile || !fs.existsSync(envFile)) return {};
|
|
157
|
+
try {
|
|
158
|
+
return dotenv.parse(fs.readFileSync(envFile, "utf-8"));
|
|
159
|
+
} catch {
|
|
160
|
+
return {};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Resolve a binary from the project's node_modules/.bin.
|
|
165
|
+
* Checks backend, root, parent monorepo root, then falls back to PATH.
|
|
166
|
+
*/
|
|
167
|
+
function resolveLocalBin(projectRoot, binName) {
|
|
168
|
+
const candidates = [path.join(projectRoot, "backend", "node_modules", ".bin", binName), path.join(projectRoot, "node_modules", ".bin", binName)];
|
|
169
|
+
let parent = path.dirname(projectRoot);
|
|
170
|
+
const rootDir = path.parse(parent).root;
|
|
171
|
+
while (parent !== rootDir) {
|
|
172
|
+
candidates.push(path.join(parent, "node_modules", ".bin", binName));
|
|
173
|
+
parent = path.dirname(parent);
|
|
174
|
+
}
|
|
175
|
+
for (const candidate of candidates) if (fs.existsSync(candidate)) return candidate;
|
|
176
|
+
try {
|
|
177
|
+
const globalPath = execSync(`which ${binName}`, { encoding: "utf-8" }).trim();
|
|
178
|
+
if (globalPath && fs.existsSync(globalPath)) return globalPath;
|
|
179
|
+
} catch {}
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Resolve the tsx binary. Checks backend node_modules first, then root.
|
|
184
|
+
*/
|
|
185
|
+
function resolveTsx(projectRoot) {
|
|
186
|
+
return resolveLocalBin(projectRoot, "tsx");
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* tsx's loader, as the URL `node --import` takes, or null when none resolves.
|
|
190
|
+
*
|
|
191
|
+
* For running a TypeScript entry in one Node process. The `tsx` binary is a
|
|
192
|
+
* relay — pnpm's `.bin/tsx` shell shim, then tsx's CLI in one Node, which
|
|
193
|
+
* spawns a second Node with this same loader to run the script — so spawning
|
|
194
|
+
* through it costs a shell and a Node start (~50–100 ms) on every hop, and
|
|
195
|
+
* `rebase dev` pays a hop on every start and every collection save.
|
|
196
|
+
*
|
|
197
|
+
* Resolved the way Node resolves the package, from the project first — the
|
|
198
|
+
* backend, where a scaffold declares tsx, then the root and everything above it
|
|
199
|
+
* — so the tsx used is the one {@link resolveTsx} would have found; then from
|
|
200
|
+
* this package, as the repository's own tests resolve `tsx/cli`. A URL rather
|
|
201
|
+
* than a path: a Windows path is not a valid `--import` specifier.
|
|
202
|
+
*/
|
|
203
|
+
function resolveTsxLoader(projectRoot) {
|
|
204
|
+
const bases = [
|
|
205
|
+
path.join(projectRoot, "backend", "noop.js"),
|
|
206
|
+
path.join(projectRoot, "noop.js"),
|
|
207
|
+
import.meta.url
|
|
208
|
+
];
|
|
209
|
+
for (const base of bases) try {
|
|
210
|
+
return pathToFileURL(createRequire(base).resolve("tsx")).href;
|
|
211
|
+
} catch {}
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Validate that a resolved tsx binary actually has an intact installation.
|
|
216
|
+
*
|
|
217
|
+
* `resolveLocalBin` only checks whether `node_modules/.bin/tsx` (a symlink)
|
|
218
|
+
* exists. If the pnpm content-addressable store was cleaned or a previous
|
|
219
|
+
* install was interrupted, the symlink can exist while critical files inside
|
|
220
|
+
* the tsx package (e.g. `dist/preflight.cjs`) are missing — causing a
|
|
221
|
+
* confusing MODULE_NOT_FOUND error at runtime.
|
|
222
|
+
*
|
|
223
|
+
* This function follows the symlink, walks up to find the tsx package root
|
|
224
|
+
* (`package.json` with `name: "tsx"`), and verifies that `dist/preflight.cjs`
|
|
225
|
+
* is present. Returns `null` when the installation looks healthy, or an
|
|
226
|
+
* error description string when it appears corrupted.
|
|
227
|
+
*/
|
|
228
|
+
function validateTsxInstallation(tsxBinPath) {
|
|
229
|
+
try {
|
|
230
|
+
const realPath = fs.realpathSync(tsxBinPath);
|
|
231
|
+
let dir = path.dirname(realPath);
|
|
232
|
+
const fsRoot = path.parse(dir).root;
|
|
233
|
+
for (let depth = 0; depth < 10 && dir !== fsRoot; depth++) {
|
|
234
|
+
const pkgPath = path.join(dir, "package.json");
|
|
235
|
+
if (fs.existsSync(pkgPath)) try {
|
|
236
|
+
if (JSON.parse(fs.readFileSync(pkgPath, "utf-8")).name === "tsx") {
|
|
237
|
+
const preflightPath = path.join(dir, "dist", "preflight.cjs");
|
|
238
|
+
if (!fs.existsSync(preflightPath)) return `tsx package at ${dir} is missing dist/preflight.cjs`;
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
} catch {}
|
|
242
|
+
dir = path.dirname(dir);
|
|
243
|
+
}
|
|
244
|
+
return null;
|
|
245
|
+
} catch (err) {
|
|
246
|
+
return `tsx binary symlink is broken: ${err instanceof Error ? err.message : String(err)}`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The one sentence a command says when the project's dependencies are missing.
|
|
251
|
+
*
|
|
252
|
+
* Six commands each had their own wording for the same state, and none of them
|
|
253
|
+
* named the remedy:
|
|
254
|
+
*
|
|
255
|
+
* ✗ Could not find CLI entry point for @rebasepro/server-postgres.
|
|
256
|
+
* ✗ Could not find tsx binary.
|
|
257
|
+
* ✗ Could not find tsx binary for backend.
|
|
258
|
+
*
|
|
259
|
+
* All three mean "you have not installed yet" — `getActiveBackendPlugin` has
|
|
260
|
+
* already read the driver out of `backend/package.json` by the time the first
|
|
261
|
+
* one fires, so the package is declared and simply not on disk, and `tsx` is a
|
|
262
|
+
* devDependency of every scaffold. But they read as *Rebase* being broken, and
|
|
263
|
+
* they name an internal path or a binary the developer never asked for rather
|
|
264
|
+
* than the command that fixes it. That is the whole of the failure someone sees
|
|
265
|
+
* on a fresh clone, where `node_modules/` is the one thing a checkout does not
|
|
266
|
+
* carry.
|
|
267
|
+
*
|
|
268
|
+
* So: one sentence, naming the package manager this project uses and the
|
|
269
|
+
* directory to run it in — the working directory is usually neither.
|
|
270
|
+
*/
|
|
271
|
+
function dependenciesNotInstalled(projectRoot) {
|
|
272
|
+
return `Dependencies are not installed — run \`${getPMCommands(detectPackageManager(projectRoot)).install.join(" ")}\` in ${projectRoot}`;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Print {@link dependenciesNotInstalled} and exit 1.
|
|
276
|
+
*
|
|
277
|
+
* For the five commands that report and stop. `db.ts` throws instead, because
|
|
278
|
+
* its caller adds the `✗` and the exit itself.
|
|
279
|
+
*/
|
|
280
|
+
function exitDependenciesNotInstalled(projectRoot) {
|
|
281
|
+
console.error(chalk.red(`✗ ${dependenciesNotInstalled(projectRoot)}`));
|
|
282
|
+
process.exit(1);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* The refusal envelope, for a caller that asked for JSON.
|
|
286
|
+
*
|
|
287
|
+
* Same shape as the cloud family's `fail()` — `{ error: { message, code, hint } }`
|
|
288
|
+
* — because there is one CLI and a caller should not have to know which half of
|
|
289
|
+
* it answered. `code` is what a caller branches on and is never absent; the
|
|
290
|
+
* cloud family's reasoning about that applies here unchanged. `issues` carries
|
|
291
|
+
* the per-problem detail a human reader gets as a bullet list, because a
|
|
292
|
+
* refusal that says "2 problem(s)" and does not say which two is not
|
|
293
|
+
* machine-readable in any useful sense.
|
|
294
|
+
*
|
|
295
|
+
* On **stdout**, like every other `--json` result: the contract those commands
|
|
296
|
+
* make is that stdout holds one JSON value, and a caller that pipes stdout to a
|
|
297
|
+
* parser must get a parseable refusal rather than an empty stream and a
|
|
298
|
+
* human sentence it never sees. That contract used to hold for exactly one
|
|
299
|
+
* failure of each command — the one that goes through `requireProjectRoot` —
|
|
300
|
+
* while every other exit of the *same* command wrote human text to stderr and
|
|
301
|
+
* left stdout empty. So `rebase status --json` was parseable outside a project
|
|
302
|
+
* and unparseable inside a broken one, which is the case a caller actually has
|
|
303
|
+
* to handle.
|
|
304
|
+
*
|
|
305
|
+
* The flag is read off `process.argv` because the failure happens inside a
|
|
306
|
+
* helper the command calls before it has parsed anything. Coarse — a literal
|
|
307
|
+
* `--json` as some other flag's value would count — and worth it: the failure
|
|
308
|
+
* mode of being coarse is a JSON error where a human one was wanted, and the
|
|
309
|
+
* failure mode of not doing it is an unparseable stream.
|
|
310
|
+
*/
|
|
311
|
+
function failAsJson(message, code, hint, issues) {
|
|
312
|
+
const error = {
|
|
313
|
+
message,
|
|
314
|
+
code
|
|
315
|
+
};
|
|
316
|
+
if (hint !== void 0) error.hint = hint;
|
|
317
|
+
if (issues !== void 0) error.issues = issues;
|
|
318
|
+
console.log(JSON.stringify({ error }, null, 2));
|
|
319
|
+
process.exit(1);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Did the command line ask for machine-readable output? Read as the parser
|
|
323
|
+
* reads a switch: `--json`, `--json=true` and `--json=1` ask for it,
|
|
324
|
+
* `--json=false` and `--json=0` do not.
|
|
325
|
+
*/
|
|
326
|
+
function wantsJsonOutput(argv = process.argv) {
|
|
327
|
+
return switchOn(argv, "--json");
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Require the project root or exit with a helpful error.
|
|
331
|
+
*/
|
|
332
|
+
function requireProjectRoot() {
|
|
333
|
+
const root = findProjectRoot();
|
|
334
|
+
if (!root) {
|
|
335
|
+
if (wantsJsonOutput()) failAsJson("Could not find a Rebase project root.", "no_project_root", `Looked in this directory and every parent for a ${MANIFEST_FILENAME}, a package.json with a "backend" workspace, or a package.json next to a backend/.`);
|
|
336
|
+
console.error(chalk.red("✗ Could not find a Rebase project root."));
|
|
337
|
+
console.error(chalk.gray(` Looked in this directory and every parent for a ${MANIFEST_FILENAME},`));
|
|
338
|
+
console.error(chalk.gray(" a package.json with a \"backend\" workspace, or a package.json next to a backend/."));
|
|
339
|
+
console.error(chalk.gray(" Run this from inside a project, or create one with `rebase init`."));
|
|
340
|
+
process.exit(1);
|
|
341
|
+
}
|
|
342
|
+
return root;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Require the backend directory or exit with a helpful error.
|
|
346
|
+
*/
|
|
347
|
+
function requireBackendDir(projectRoot) {
|
|
348
|
+
const backendDir = findBackendDir(projectRoot);
|
|
349
|
+
if (!backendDir) {
|
|
350
|
+
if (wantsJsonOutput()) failAsJson("Could not find a backend/ directory.", "no_backend_dir", `Expected at: ${path.join(projectRoot, "backend")}`);
|
|
351
|
+
console.error(chalk.red("✗ Could not find a backend/ directory."));
|
|
352
|
+
console.error(chalk.gray(` Expected at: ${path.join(projectRoot, "backend")}`));
|
|
353
|
+
process.exit(1);
|
|
354
|
+
}
|
|
355
|
+
return backendDir;
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
export { resolveTsxLoader as _, findBackendDir as a, findProjectRoot as c, readEnvFile as d, requireBackendDir as f, resolveTsx as g, resolvePluginCliScript as h, failAsJson as i, getActiveBackendPlugin as l, resolveLocalBin as m, dependenciesNotInstalled as n, findEnvFile as o, requireProjectRoot as p, exitDependenciesNotInstalled as r, findFrontendDir as s, MANIFEST_FILENAME as t, project_exports as u, validateTsxInstallation as v, wantsJsonOutput as y };
|
|
359
|
+
|
|
360
|
+
//# sourceMappingURL=project-CLcF5i8c.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-CLcF5i8c.js","names":[],"sources":["../src/utils/project.ts"],"sourcesContent":["/**\n * Project discovery utilities for the Rebase CLI.\n *\n * These helpers locate the project root, backend directory, .env file,\n * and local binaries — used by all CLI command modules.\n */\nimport fs from \"fs\";\nimport { createRequire } from \"module\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport { execSync } from \"child_process\";\nimport dotenv from \"dotenv\";\nimport chalk from \"chalk\";\nimport { detectPackageManager, getPMCommands } from \"./package-manager\";\nimport { switchOn } from \"./args\";\n\n/** The authored project manifest. Its presence alone marks a project root. */\nexport const MANIFEST_FILENAME = \"rebase.json\";\n\n/**\n * Walk up from `startDir` to find the Rebase project root.\n *\n * A directory is the root when it holds a `rebase.json`, or when it holds a\n * `package.json` that either lists `backend` as a workspace or sits beside a\n * `backend/` directory.\n *\n * There is no `config/` requirement any more: the config package is gone (its\n * collections became `backend/schema`, the rest moved into `backend/`), and a\n * BaaS project is a `backend/` and nothing else. The `package.json` is still\n * required beside it, so a stray `backend/` folder deep inside some unrelated\n * tree does not make its parent a project.\n *\n * `rebase.json` is checked first and needs no `package.json` beside it, because\n * the conventions below all describe a repository that *contains the backend*.\n * A repository holding only a frontend — the normal shape once a project's apps\n * live in separate repositories — matches none of them, so without this the\n * tooling could not run there at all.\n */\nexport function findProjectRoot(startDir: string = process.cwd()): string | null {\n let dir = path.resolve(startDir);\n const root = path.parse(dir).root;\n\n while (dir !== root) {\n if (fs.existsSync(path.join(dir, MANIFEST_FILENAME))) {\n return dir;\n }\n\n const pkgPath = path.join(dir, \"package.json\");\n\n if (fs.existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n // Check for workspace-based project (monorepo root)\n if (pkg.workspaces && Array.isArray(pkg.workspaces)) {\n const hasBackend = pkg.workspaces.some((w: string) =>\n w === \"backend\"\n );\n if (hasBackend) return dir;\n }\n } catch {\n // ignore parse errors\n }\n\n // A package beside a backend directory.\n if (fs.existsSync(path.join(dir, \"backend\"))) {\n return dir;\n }\n }\n\n dir = path.dirname(dir);\n }\n\n return null;\n}\n\n/**\n * Locate the backend directory within the project root.\n */\nexport function findBackendDir(projectRoot: string): string | null {\n const backendDir = path.join(projectRoot, \"backend\");\n return fs.existsSync(backendDir) ? backendDir : null;\n}\n\n/**\n * Detect the active backend plugin (e.g. @rebasepro/server-postgres) from the backend's package.json.\n */\nexport function getActiveBackendPlugin(backendDir: string): string | null {\n const pkgPath = path.join(backendDir, \"package.json\");\n if (!fs.existsSync(pkgPath)) return null;\n\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n const deps = { ...pkg.dependencies,\n...pkg.devDependencies };\n\n // Collect all @rebasepro/server-* driver plugins (exclude server itself)\n const candidates = Object.keys(deps).filter(\n dep => dep.startsWith(\"@rebasepro/server-\") && dep !== \"@rebasepro/server\"\n );\n\n if (candidates.length === 0) return null;\n\n // Prefer server-postgres — it's the primary supported driver\n if (candidates.includes(\"@rebasepro/server-postgres\")) {\n return \"@rebasepro/server-postgres\";\n }\n\n // Fallback: return the first candidate that actually has a CLI entry point\n for (const candidate of candidates) {\n if (resolvePluginCliScript(backendDir, candidate)) {\n return candidate;\n }\n }\n\n // Last resort: return whatever we found\n return candidates[0];\n } catch {\n // Ignore parse errors\n }\n return null;\n}\n\n/**\n * Resolve the active plugin's CLI script.\n */\nexport function resolvePluginCliScript(backendDir: string, pluginName: string): string | null {\n const candidates: string[] = [];\n\n // Walk up from the backend dir: pnpm links the plugin into\n // backend/node_modules, while npm workspaces hoist it to the project (or an\n // enclosing monorepo) root.\n let dir = path.resolve(backendDir);\n const fsRoot = path.parse(dir).root;\n while (dir !== fsRoot) {\n candidates.push(\n path.join(dir, \"node_modules\", pluginName, \"src\", \"cli.ts\"),\n path.join(dir, \"node_modules\", pluginName, \"dist\", \"cli.js\")\n );\n dir = path.dirname(dir);\n }\n\n candidates.push(\n // For monorepo dev mode:\n path.resolve(backendDir, \"..\", \"..\", \"..\", \"packages\", pluginName.replace(\"@rebasepro/\", \"\"), \"src\", \"cli.ts\"),\n path.resolve(backendDir, \"..\", \"..\", \"packages\", pluginName.replace(\"@rebasepro/\", \"\"), \"src\", \"cli.ts\"),\n path.resolve(backendDir, \"..\", \"packages\", pluginName.replace(\"@rebasepro/\", \"\"), \"src\", \"cli.ts\")\n );\n\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) return candidate;\n }\n return null;\n}\n\n/**\n * Locate the frontend directory within the project root.\n */\nexport function findFrontendDir(projectRoot: string): string | null {\n const frontendDir = path.join(projectRoot, \"frontend\");\n return fs.existsSync(frontendDir) ? frontendDir : null;\n}\n\n/**\n * Find the .env file. Checks the project root first, then backend.\n */\nexport function findEnvFile(projectRoot: string): string | null {\n const candidates = [\n path.join(projectRoot, \".env\"),\n path.join(projectRoot, \"backend\", \".env\")\n ];\n\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) return candidate;\n }\n\n return null;\n}\n\n/**\n * Read the project's `.env` into a plain object.\n *\n * One reader, because there were four: `dotenv` in `start`, a hand-rolled\n * `indexOf(\"=\")` loop in `api-keys`, a single-key regex in `auth`, and its own\n * splitting in `cloud env`. `dotenv` is a declared dependency of this package,\n * so the other three existed for no reason and disagreed with the correct one\n * on the two things people actually write in a `.env`:\n *\n * - `export KEY=value`, which the hand-rolled parser keyed as\n * `export KEY` — so the command reported the key as unset while it was\n * right there in the file;\n * - `KEY=value # comment`, whose comment travelled into the value and then\n * into an `Authorization` header, coming back as a 401 with nothing\n * pointing at the cause.\n *\n * Returns `{}` when the project has no `.env`, so callers can treat \"absent\"\n * and \"empty\" alike.\n */\nexport function readEnvFile(projectRoot: string): Record<string, string> {\n const envFile = findEnvFile(projectRoot);\n if (!envFile || !fs.existsSync(envFile)) return {};\n try {\n return dotenv.parse(fs.readFileSync(envFile, \"utf-8\"));\n } catch {\n // An unreadable or malformed file is not worth failing a command over;\n // the caller reports the missing value it was looking for.\n return {};\n }\n}\n\n/**\n * Resolve a binary from the project's node_modules/.bin.\n * Checks backend, root, parent monorepo root, then falls back to PATH.\n */\nexport function resolveLocalBin(projectRoot: string, binName: string): string | null {\n const candidates = [\n path.join(projectRoot, \"backend\", \"node_modules\", \".bin\", binName),\n path.join(projectRoot, \"node_modules\", \".bin\", binName)\n ];\n\n // Also check parent directories (for monorepo setups where app/ is nested)\n let parent = path.dirname(projectRoot);\n const rootDir = path.parse(parent).root;\n while (parent !== rootDir) {\n candidates.push(path.join(parent, \"node_modules\", \".bin\", binName));\n parent = path.dirname(parent);\n }\n\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) return candidate;\n }\n\n // Fall back to globally installed binary via which\n try {\n const globalPath = execSync(`which ${binName}`, { encoding: \"utf-8\" }).trim();\n if (globalPath && fs.existsSync(globalPath)) return globalPath;\n } catch {\n // not found globally\n }\n\n return null;\n}\n\n/**\n * Resolve the tsx binary. Checks backend node_modules first, then root.\n */\nexport function resolveTsx(projectRoot: string): string | null {\n return resolveLocalBin(projectRoot, \"tsx\");\n}\n\n/**\n * tsx's loader, as the URL `node --import` takes, or null when none resolves.\n *\n * For running a TypeScript entry in one Node process. The `tsx` binary is a\n * relay — pnpm's `.bin/tsx` shell shim, then tsx's CLI in one Node, which\n * spawns a second Node with this same loader to run the script — so spawning\n * through it costs a shell and a Node start (~50–100 ms) on every hop, and\n * `rebase dev` pays a hop on every start and every collection save.\n *\n * Resolved the way Node resolves the package, from the project first — the\n * backend, where a scaffold declares tsx, then the root and everything above it\n * — so the tsx used is the one {@link resolveTsx} would have found; then from\n * this package, as the repository's own tests resolve `tsx/cli`. A URL rather\n * than a path: a Windows path is not a valid `--import` specifier.\n */\nexport function resolveTsxLoader(projectRoot: string): string | null {\n const bases = [\n path.join(projectRoot, \"backend\", \"noop.js\"),\n path.join(projectRoot, \"noop.js\"),\n import.meta.url\n ];\n for (const base of bases) {\n try {\n return pathToFileURL(createRequire(base).resolve(\"tsx\")).href;\n } catch {\n // Not resolvable from here; try the next base.\n }\n }\n return null;\n}\n\n/**\n * Validate that a resolved tsx binary actually has an intact installation.\n *\n * `resolveLocalBin` only checks whether `node_modules/.bin/tsx` (a symlink)\n * exists. If the pnpm content-addressable store was cleaned or a previous\n * install was interrupted, the symlink can exist while critical files inside\n * the tsx package (e.g. `dist/preflight.cjs`) are missing — causing a\n * confusing MODULE_NOT_FOUND error at runtime.\n *\n * This function follows the symlink, walks up to find the tsx package root\n * (`package.json` with `name: \"tsx\"`), and verifies that `dist/preflight.cjs`\n * is present. Returns `null` when the installation looks healthy, or an\n * error description string when it appears corrupted.\n */\nexport function validateTsxInstallation(tsxBinPath: string): string | null {\n try {\n // Follow the symlink chain to the real tsx entry script\n const realPath = fs.realpathSync(tsxBinPath);\n\n // Walk up from the real binary to locate the tsx package root\n let dir = path.dirname(realPath);\n const fsRoot = path.parse(dir).root;\n for (let depth = 0; depth < 10 && dir !== fsRoot; depth++) {\n const pkgPath = path.join(dir, \"package.json\");\n if (fs.existsSync(pkgPath)) {\n try {\n const pkg = JSON.parse(fs.readFileSync(pkgPath, \"utf-8\"));\n if (pkg.name === \"tsx\") {\n // Found the tsx package root — verify critical preload file\n const preflightPath = path.join(dir, \"dist\", \"preflight.cjs\");\n if (!fs.existsSync(preflightPath)) {\n return `tsx package at ${dir} is missing dist/preflight.cjs`;\n }\n return null; // Installation looks healthy\n }\n } catch {\n // Malformed package.json — keep walking\n }\n }\n dir = path.dirname(dir);\n }\n\n // Could not determine tsx root — don't block, assume valid\n return null;\n } catch (err) {\n // realpathSync throws if the symlink target is completely gone\n return `tsx binary symlink is broken: ${err instanceof Error ? err.message : String(err)}`;\n }\n}\n\n/**\n * The one sentence a command says when the project's dependencies are missing.\n *\n * Six commands each had their own wording for the same state, and none of them\n * named the remedy:\n *\n * ✗ Could not find CLI entry point for @rebasepro/server-postgres.\n * ✗ Could not find tsx binary.\n * ✗ Could not find tsx binary for backend.\n *\n * All three mean \"you have not installed yet\" — `getActiveBackendPlugin` has\n * already read the driver out of `backend/package.json` by the time the first\n * one fires, so the package is declared and simply not on disk, and `tsx` is a\n * devDependency of every scaffold. But they read as *Rebase* being broken, and\n * they name an internal path or a binary the developer never asked for rather\n * than the command that fixes it. That is the whole of the failure someone sees\n * on a fresh clone, where `node_modules/` is the one thing a checkout does not\n * carry.\n *\n * So: one sentence, naming the package manager this project uses and the\n * directory to run it in — the working directory is usually neither.\n */\nexport function dependenciesNotInstalled(projectRoot: string): string {\n const install = getPMCommands(detectPackageManager(projectRoot)).install.join(\" \");\n return `Dependencies are not installed — run \\`${install}\\` in ${projectRoot}`;\n}\n\n/**\n * Print {@link dependenciesNotInstalled} and exit 1.\n *\n * For the five commands that report and stop. `db.ts` throws instead, because\n * its caller adds the `✗` and the exit itself.\n */\nexport function exitDependenciesNotInstalled(projectRoot: string): never {\n console.error(chalk.red(`✗ ${dependenciesNotInstalled(projectRoot)}`));\n process.exit(1);\n}\n\n/** One problem inside a refusal, when the command found several. */\nexport interface JsonFailureIssue {\n /** Where it is — a config path, a manifest key, a file. */\n path?: string;\n message: string;\n}\n\n/**\n * The refusal envelope, for a caller that asked for JSON.\n *\n * Same shape as the cloud family's `fail()` — `{ error: { message, code, hint } }`\n * — because there is one CLI and a caller should not have to know which half of\n * it answered. `code` is what a caller branches on and is never absent; the\n * cloud family's reasoning about that applies here unchanged. `issues` carries\n * the per-problem detail a human reader gets as a bullet list, because a\n * refusal that says \"2 problem(s)\" and does not say which two is not\n * machine-readable in any useful sense.\n *\n * On **stdout**, like every other `--json` result: the contract those commands\n * make is that stdout holds one JSON value, and a caller that pipes stdout to a\n * parser must get a parseable refusal rather than an empty stream and a\n * human sentence it never sees. That contract used to hold for exactly one\n * failure of each command — the one that goes through `requireProjectRoot` —\n * while every other exit of the *same* command wrote human text to stderr and\n * left stdout empty. So `rebase status --json` was parseable outside a project\n * and unparseable inside a broken one, which is the case a caller actually has\n * to handle.\n *\n * The flag is read off `process.argv` because the failure happens inside a\n * helper the command calls before it has parsed anything. Coarse — a literal\n * `--json` as some other flag's value would count — and worth it: the failure\n * mode of being coarse is a JSON error where a human one was wanted, and the\n * failure mode of not doing it is an unparseable stream.\n */\nexport function failAsJson(\n message: string,\n code: string,\n hint?: string,\n issues?: JsonFailureIssue[]\n): never {\n const error: Record<string, unknown> = { message, code };\n if (hint !== undefined) error.hint = hint;\n if (issues !== undefined) error.issues = issues;\n console.log(JSON.stringify({ error }, null, 2));\n process.exit(1);\n}\n\n/**\n * Did the command line ask for machine-readable output? Read as the parser\n * reads a switch: `--json`, `--json=true` and `--json=1` ask for it,\n * `--json=false` and `--json=0` do not.\n */\nexport function wantsJsonOutput(argv: readonly string[] = process.argv): boolean {\n return switchOn(argv, \"--json\");\n}\n\n/**\n * Require the project root or exit with a helpful error.\n */\nexport function requireProjectRoot(): string {\n const root = findProjectRoot();\n if (!root) {\n if (wantsJsonOutput()) {\n // `rebase status --json` outside a project wrote four grey lines to\n // stderr and nothing at all to stdout, so the agent or CI step that\n // asked for JSON got an empty parse and no reason.\n failAsJson(\n \"Could not find a Rebase project root.\",\n \"no_project_root\",\n `Looked in this directory and every parent for a ${MANIFEST_FILENAME}, `\n + \"a package.json with a \\\"backend\\\" workspace, or a package.json next to a backend/.\"\n );\n }\n // Name what is actually looked for, in the order `findProjectRoot`\n // looks for it. The old wording (\"backend/, frontend/, and config/\")\n // described neither the manifest — which is the primary marker and the\n // only one `rebase init` writes — nor a `--headless` project, which has\n // no frontend at all and would read this as \"you are in the wrong\n // place\" while standing in the right one.\n console.error(chalk.red(\"✗ Could not find a Rebase project root.\"));\n console.error(chalk.gray(` Looked in this directory and every parent for a ${MANIFEST_FILENAME},`));\n console.error(chalk.gray(\" a package.json with a \\\"backend\\\" workspace, or a package.json next to a backend/.\"));\n console.error(chalk.gray(\" Run this from inside a project, or create one with `rebase init`.\"));\n process.exit(1);\n }\n return root;\n}\n\n/**\n * Require the backend directory or exit with a helpful error.\n */\nexport function requireBackendDir(projectRoot: string): string {\n const backendDir = findBackendDir(projectRoot);\n if (!backendDir) {\n if (wantsJsonOutput()) {\n failAsJson(\n \"Could not find a backend/ directory.\",\n \"no_backend_dir\",\n `Expected at: ${path.join(projectRoot, \"backend\")}`\n );\n }\n console.error(chalk.red(\"✗ Could not find a backend/ directory.\"));\n console.error(chalk.gray(` Expected at: ${path.join(projectRoot, \"backend\")}`));\n process.exit(1);\n }\n return backendDir;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAa,oBAAoB;;;;;;;;;;;;;;;;;;;;AAqBjC,SAAgB,gBAAgB,WAAmB,QAAQ,IAAI,GAAkB;CAC7E,IAAI,MAAM,KAAK,QAAQ,QAAQ;CAC/B,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC;CAE7B,OAAO,QAAQ,MAAM;EACjB,IAAI,GAAG,WAAW,KAAK,KAAK,KAAA,aAAsB,CAAC,GAC/C,OAAO;EAGX,MAAM,UAAU,KAAK,KAAK,KAAK,cAAc;EAE7C,IAAI,GAAG,WAAW,OAAO,GAAG;GACxB,IAAI;IACA,MAAM,MAAM,KAAK,MAAM,GAAG,aAAa,SAAS,OAAO,CAAC;IAExD,IAAI,IAAI,cAAc,MAAM,QAAQ,IAAI,UAAU;SAC3B,IAAI,WAAW,MAAM,MACpC,MAAM,SAEN,GAAY,OAAO;IAAA;GAE/B,QAAQ,CAER;GAGA,IAAI,GAAG,WAAW,KAAK,KAAK,KAAK,SAAS,CAAC,GACvC,OAAO;EAEf;EAEA,MAAM,KAAK,QAAQ,GAAG;CAC1B;CAEA,OAAO;AACX;;;;AAKA,SAAgB,eAAe,aAAoC;CAC/D,MAAM,aAAa,KAAK,KAAK,aAAa,SAAS;CACnD,OAAO,GAAG,WA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;EAC/E,QAAQ,KAAK,CAAC;CAClB;CACA,OAAO;AACX"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { t as createSchemaModuleImporter } from "./import-schema-module-Df67TIWj.js";
|
|
2
|
+
//#region src/utils/project-schema.ts
|
|
3
|
+
/**
|
|
4
|
+
* Import and compile a project's schema directory.
|
|
5
|
+
*
|
|
6
|
+
* Throws what the loader throws: `SchemaLoadError` (a module that does not
|
|
7
|
+
* import, the legacy layout, a definition the index does not export) or
|
|
8
|
+
* `SchemaDefinitionError` from `@rebasepro/common` (every problem with every
|
|
9
|
+
* definition, one per line). A directory that does not exist, or has no
|
|
10
|
+
* index, declares no tables: `descriptors` is empty.
|
|
11
|
+
*
|
|
12
|
+
* @param projectRoot the project root — where a leftover legacy collections
|
|
13
|
+
* directory would be, and what the importer is rooted at.
|
|
14
|
+
* @param schemaDir the schema directory, absolute.
|
|
15
|
+
*/
|
|
16
|
+
async function loadProjectSchema(projectRoot, schemaDir, aliases = {}) {
|
|
17
|
+
const { loadBackendSchema, compileLoadedSchema } = await import("@rebasepro/server");
|
|
18
|
+
const loaded = await loadBackendSchema(schemaDir, {
|
|
19
|
+
projectRoot,
|
|
20
|
+
importModule: await createSchemaModuleImporter(projectRoot, aliases)
|
|
21
|
+
});
|
|
22
|
+
return {
|
|
23
|
+
loaded,
|
|
24
|
+
compiled: compileLoadedSchema(loaded)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { loadProjectSchema as t };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=project-schema-CsSOG2gE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-schema-CsSOG2gE.js","names":[],"sources":["../src/utils/project-schema.ts"],"sourcesContent":["/**\n * The project's `backend/schema`, imported in this process — for the commands\n * that read the tables themselves rather than through the driver: `rebase\n * verify`, `rebase build`, `rebase resources`, `rebase generate-sdk`.\n *\n * Through `loadBackendSchema` from `@rebasepro/server`, the one definition of\n * \"the tables\" that boot, the runtime and the driver also read, so a command\n * here can never accept a schema the server refuses (or the reverse): a table\n * with no `rls`, an index that does not export a sibling's table, a project\n * still on the collections layout — each is the loader's error, word for word.\n * Modules are imported with the CLI's one importer\n * (`createSchemaModuleImporter`), so a file written earlier in the same\n * process is read as it is now.\n */\nimport type { CompiledSchema, LoadedSchema } from \"@rebasepro/server\";\nimport { createSchemaModuleImporter } from \"./import-schema-module\";\n\n/** The project's schema, as the loader read it and as it compiles. */\nexport interface ProjectSchema {\n loaded: LoadedSchema;\n compiled: CompiledSchema;\n}\n\n/**\n * Module specifiers mapped to files, for the importer. A user's project\n * resolves through its own `node_modules` and passes none; tests and in-repo\n * runs point `@rebasepro/*` at the workspace's source.\n */\nexport type ModuleAliases = Record<string, string>;\n\n/**\n * Import and compile a project's schema directory.\n *\n * Throws what the loader throws: `SchemaLoadError` (a module that does not\n * import, the legacy layout, a definition the index does not export) or\n * `SchemaDefinitionError` from `@rebasepro/common` (every problem with every\n * definition, one per line). A directory that does not exist, or has no\n * index, declares no tables: `descriptors` is empty.\n *\n * @param projectRoot the project root — where a leftover legacy collections\n * directory would be, and what the importer is rooted at.\n * @param schemaDir the schema directory, absolute.\n */\nexport async function loadProjectSchema(\n projectRoot: string,\n schemaDir: string,\n aliases: ModuleAliases = {}\n): Promise<ProjectSchema> {\n const { loadBackendSchema, compileLoadedSchema } = await import(\"@rebasepro/server\");\n const importModule = await createSchemaModuleImporter(projectRoot, aliases);\n const loaded = await loadBackendSchema(schemaDir, { projectRoot, importModule });\n return { loaded, compiled: compileLoadedSchema(loaded) };\n}\n"],"mappings":";;;;;;;;;;;;;;;AA2CA,eAAsB,kBAClB,aACA,WACA,UAAyB,CAAC,GACJ;CACtB,MAAM,EAAE,mBAAmB,wBAAwB,MAAM,OAAO;CAEhE,MAAM,SAAS,MAAM,kBAAkB,WAAW;EAAE;EAAa,cAAA,MADtC,2BAA2B,aAAa,OAAO;CACI,CAAC;CAC/E,OAAO;EAAE;EAAQ,UAAU,oBAAoB,MAAM;CAAE;AAC3D"}
|
|
@@ -2,6 +2,193 @@ import { r as PGLITE_EXTENSIONS } from "./constraints-CtiylsGf.js";
|
|
|
2
2
|
import { i as hostOf, n as connectionErrorText, t as banner } from "./connection-banner-DbLJzWf4.js";
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
import { execa } from "execa";
|
|
5
|
+
//#region src/dev-db/attver.ts
|
|
6
|
+
/**
|
|
7
|
+
* `pg_attver` in a dump, and taking it out before a restore.
|
|
8
|
+
*
|
|
9
|
+
* The November 2026 PostgreSQL minor releases (every branch from 14 up;
|
|
10
|
+
* upstream commit c23382f0a8, "Introduce attribute versioning to prevent
|
|
11
|
+
* unsafe deforming") keep a per-column version as an attribute option: a
|
|
12
|
+
* `pg_attver` key in `pg_attribute.attoptions`, set on every column created or
|
|
13
|
+
* altered. A `pg_dump` from before that release, pointed at a server from
|
|
14
|
+
* after it, dumps the key like any other attribute option:
|
|
15
|
+
*
|
|
16
|
+
* ALTER TABLE ONLY public.authors ALTER COLUMN id SET (pg_attver=33846480);
|
|
17
|
+
*
|
|
18
|
+
* and every server without the change — PGlite, which the managed development
|
|
19
|
+
* database runs on, and a local Postgres on an older minor — refuses it with
|
|
20
|
+
* `unrecognized parameter "pg_attver"`. The statement sits in the same archive
|
|
21
|
+
* entry as the table's `CREATE TABLE`, so that entry fails whole: no table,
|
|
22
|
+
* and every row, index and constraint of it after. A server with the change
|
|
23
|
+
* ignores the key on input, so it carries nothing a restore needs.
|
|
24
|
+
*
|
|
25
|
+
* pg_dump's own fix leaves the key out, but a pull should not depend on the
|
|
26
|
+
* local client being newer than the source server. So the dump is edited in
|
|
27
|
+
* place before pg_restore reads it: in each TOC entry's definition, the key is
|
|
28
|
+
* overwritten with spaces — the whole statement when it is the only option,
|
|
29
|
+
* the key and its comma when there are others. Byte for byte the same length,
|
|
30
|
+
* because the TOC records the file offset of every data block after it.
|
|
31
|
+
*/
|
|
32
|
+
var ATTVER_ONLY = /^(ALTER (?:FOREIGN )?TABLE (?:ONLY )?.* ALTER COLUMN .* SET )\(pg_attver=\d+\);$/gm;
|
|
33
|
+
var ATTVER_FIRST = /(?<=^ALTER (?:FOREIGN )?TABLE (?:ONLY )?.* ALTER COLUMN .* SET \()pg_attver=\d+, (?=.*\);$)/gm;
|
|
34
|
+
var ATTVER_LATER = /(?<=^ALTER (?:FOREIGN )?TABLE (?:ONLY )?.* ALTER COLUMN .* SET \(.*), pg_attver=\d+(?=.*\);$)/gm;
|
|
35
|
+
function spaces(text) {
|
|
36
|
+
return " ".repeat(Buffer.byteLength(text, "utf8"));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A TOC entry's definition without its `pg_attver` options, as the same
|
|
40
|
+
* number of UTF-8 bytes: what was taken out is spaces.
|
|
41
|
+
*/
|
|
42
|
+
function blankAttverOptions(definition) {
|
|
43
|
+
if (!definition.includes("pg_attver=")) return definition;
|
|
44
|
+
return definition.replace(ATTVER_ONLY, (statement) => spaces(statement)).replace(ATTVER_FIRST, (option) => spaces(option)).replace(ATTVER_LATER, (option) => spaces(option));
|
|
45
|
+
}
|
|
46
|
+
/** `K_VERS_1_12`…`K_VERS_1_16`: the custom-format archives pg_dump 11 to 18 write. */
|
|
47
|
+
var OLDEST = archiveVersion(1, 12, 0);
|
|
48
|
+
var NEWEST = archiveVersion(1, 16, 0);
|
|
49
|
+
var V1_14 = archiveVersion(1, 14, 0);
|
|
50
|
+
var V1_15 = archiveVersion(1, 15, 0);
|
|
51
|
+
var V1_16 = archiveVersion(1, 16, 0);
|
|
52
|
+
/** `archCustom` in pg_backup.h. */
|
|
53
|
+
var CUSTOM_FORMAT = 1;
|
|
54
|
+
/** `K_OFFSET_POS_SET` in pg_backup_custom.c: the entry's data block is at the offset that follows. */
|
|
55
|
+
var OFFSET_SET = 2;
|
|
56
|
+
function archiveVersion(major, minor, revision) {
|
|
57
|
+
return major << 16 | minor << 8 | revision;
|
|
58
|
+
}
|
|
59
|
+
/** Reads a custom-format archive's header and TOC straight from the file, without loading its data. */
|
|
60
|
+
var ArchiveReader = class {
|
|
61
|
+
fd;
|
|
62
|
+
size;
|
|
63
|
+
position = 0;
|
|
64
|
+
intSize = 4;
|
|
65
|
+
offSize = 8;
|
|
66
|
+
constructor(fd, size) {
|
|
67
|
+
this.fd = fd;
|
|
68
|
+
this.size = size;
|
|
69
|
+
}
|
|
70
|
+
bytes(length) {
|
|
71
|
+
if (length < 0 || this.position + length > this.size) throw new RangeError("past the end of the archive");
|
|
72
|
+
const buffer = Buffer.alloc(length);
|
|
73
|
+
let read = 0;
|
|
74
|
+
while (read < length) {
|
|
75
|
+
const n = fs.readSync(this.fd, buffer, read, length - read, this.position + read);
|
|
76
|
+
if (n === 0) throw new RangeError("past the end of the archive");
|
|
77
|
+
read += n;
|
|
78
|
+
}
|
|
79
|
+
this.position += length;
|
|
80
|
+
return buffer;
|
|
81
|
+
}
|
|
82
|
+
byte() {
|
|
83
|
+
return this.bytes(1)[0] ?? 0;
|
|
84
|
+
}
|
|
85
|
+
/** `ReadInt`: a sign byte, then `intSize` bytes, least significant first. */
|
|
86
|
+
int() {
|
|
87
|
+
const negative = this.byte() !== 0;
|
|
88
|
+
const digits = this.bytes(this.intSize);
|
|
89
|
+
let value = 0;
|
|
90
|
+
for (let i = digits.length - 1; i >= 0; i--) value = value * 256 + (digits[i] ?? 0);
|
|
91
|
+
return negative ? -value : value;
|
|
92
|
+
}
|
|
93
|
+
/** `ReadStr`: a length, then that many bytes; a negative length is NULL. Returns where the bytes are. */
|
|
94
|
+
str() {
|
|
95
|
+
const length = this.int();
|
|
96
|
+
if (length < 0) return null;
|
|
97
|
+
return {
|
|
98
|
+
at: this.position,
|
|
99
|
+
text: this.bytes(length).toString("utf8")
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** `ReadOffset`: a flag byte, then `offSize` bytes, least significant first. */
|
|
103
|
+
offset() {
|
|
104
|
+
const flag = this.byte();
|
|
105
|
+
const digits = this.bytes(this.offSize);
|
|
106
|
+
let value = 0;
|
|
107
|
+
for (let i = digits.length - 1; i >= 0; i--) value = value * 256 + (digits[i] ?? 0);
|
|
108
|
+
return {
|
|
109
|
+
set: flag === OFFSET_SET,
|
|
110
|
+
value
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
/** The edits that blank `pg_attver` in an archive's TOC, or `null` when the file is not one this can read. */
|
|
115
|
+
function planPatches(fd, size) {
|
|
116
|
+
const reader = new ArchiveReader(fd, size);
|
|
117
|
+
if (reader.bytes(5).toString("latin1") !== "PGDMP") return null;
|
|
118
|
+
const version = archiveVersion(reader.byte(), reader.byte(), reader.byte());
|
|
119
|
+
if (version < OLDEST || version > NEWEST) return null;
|
|
120
|
+
reader.intSize = reader.byte();
|
|
121
|
+
reader.offSize = reader.byte();
|
|
122
|
+
if (reader.intSize < 1 || reader.intSize > 8 || reader.offSize < 1 || reader.offSize > 8) return null;
|
|
123
|
+
if (reader.byte() !== CUSTOM_FORMAT) return null;
|
|
124
|
+
if (version >= V1_15) reader.byte();
|
|
125
|
+
else reader.int();
|
|
126
|
+
for (let i = 0; i < 7; i++) reader.int();
|
|
127
|
+
reader.str();
|
|
128
|
+
reader.str();
|
|
129
|
+
reader.str();
|
|
130
|
+
const patches = [];
|
|
131
|
+
let firstData = Number.POSITIVE_INFINITY;
|
|
132
|
+
const entries = reader.int();
|
|
133
|
+
if (entries < 0) return null;
|
|
134
|
+
for (let i = 0; i < entries; i++) {
|
|
135
|
+
reader.int();
|
|
136
|
+
reader.int();
|
|
137
|
+
reader.str();
|
|
138
|
+
reader.str();
|
|
139
|
+
reader.str();
|
|
140
|
+
reader.str();
|
|
141
|
+
reader.int();
|
|
142
|
+
const definition = reader.str();
|
|
143
|
+
reader.str();
|
|
144
|
+
reader.str();
|
|
145
|
+
reader.str();
|
|
146
|
+
reader.str();
|
|
147
|
+
if (version >= V1_14) reader.str();
|
|
148
|
+
if (version >= V1_16) reader.int();
|
|
149
|
+
reader.str();
|
|
150
|
+
reader.str();
|
|
151
|
+
while (reader.str() !== null);
|
|
152
|
+
const data = reader.offset();
|
|
153
|
+
if (data.set) firstData = Math.min(firstData, data.value);
|
|
154
|
+
if (definition) {
|
|
155
|
+
const blanked = blankAttverOptions(definition.text);
|
|
156
|
+
if (blanked !== definition.text) {
|
|
157
|
+
const bytes = Buffer.from(blanked, "utf8");
|
|
158
|
+
if (bytes.length !== Buffer.byteLength(definition.text, "utf8")) return null;
|
|
159
|
+
patches.push({
|
|
160
|
+
at: definition.at,
|
|
161
|
+
bytes
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (reader.position > firstData) return null;
|
|
167
|
+
return patches;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Blank every `pg_attver` attribute option in a custom-format dump, in place.
|
|
171
|
+
* Returns how many TOC entries were changed; 0 also for a file this does not
|
|
172
|
+
* recognise, which pg_restore then reads as it is.
|
|
173
|
+
*/
|
|
174
|
+
function stripAttverFromArchive(dumpFile) {
|
|
175
|
+
const fd = fs.openSync(dumpFile, "r+");
|
|
176
|
+
try {
|
|
177
|
+
let patches;
|
|
178
|
+
try {
|
|
179
|
+
patches = planPatches(fd, fs.fstatSync(fd).size);
|
|
180
|
+
} catch (error) {
|
|
181
|
+
if (error instanceof RangeError) return 0;
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
if (!patches) return 0;
|
|
185
|
+
for (const patch of patches) fs.writeSync(fd, patch.bytes, 0, patch.bytes.length, patch.at);
|
|
186
|
+
return patches.length;
|
|
187
|
+
} finally {
|
|
188
|
+
fs.closeSync(fd);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
5
192
|
//#region src/dev-db/pull.ts
|
|
6
193
|
/**
|
|
7
194
|
* `rebase db pull` — copy a database's contents into local development.
|
|
@@ -781,6 +968,7 @@ async function restoreCopy(plan, dumpFile) {
|
|
|
781
968
|
} finally {
|
|
782
969
|
await client.end().catch(() => void 0);
|
|
783
970
|
}
|
|
971
|
+
stripAttverFromArchive(dumpFile);
|
|
784
972
|
const run = await execa("pg_restore", restoreArgs(plan, dumpFile), {
|
|
785
973
|
env: restoreEnv(plan),
|
|
786
974
|
stdin: "ignore",
|
|
@@ -834,4 +1022,4 @@ function describeRestoreFailure(outcome, source) {
|
|
|
834
1022
|
//#endregion
|
|
835
1023
|
export { anonymizeCopy, describeRestoreFailure, describeTarget, dumpSource, findPgTool, provisionableSchemas, restoreCopy, sourceProblem };
|
|
836
1024
|
|
|
837
|
-
//# sourceMappingURL=pull-
|
|
1025
|
+
//# sourceMappingURL=pull-D9WvpDYY.js.map
|