@rebasepro/cli 0.11.1-canary.gfd39654 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/rebase.js +21 -0
- package/dist/bundle.d.ts +24 -7
- package/dist/commands/eject.d.ts +1 -0
- package/dist/commands/init.d.ts +19 -15
- package/dist/fold-static.d.ts +41 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +894 -246
- package/dist/index.es.js.map +1 -1
- package/dist/manifest.d.ts +27 -8
- package/package.json +7 -7
- package/runtime/dev-server.mjs +0 -1
- package/templates/{template/backend → eject}/Dockerfile +16 -4
- package/templates/{template → eject}/backend/src/env.ts +0 -1
- package/templates/{template → eject}/backend/src/index.ts +41 -27
- package/templates/eject/docker-compose.custom.yml +71 -0
- package/templates/overlays/baas/backend/package.json +1 -4
- package/templates/overlays/baas/backend/tsconfig.json +8 -2
- package/templates/overlays/baas/config/index.ts +15 -0
- package/templates/overlays/baas/config/package.json +28 -0
- package/templates/overlays/baas/package.json +2 -1
- package/templates/overlays/baas/pnpm-workspace.yaml +1 -0
- package/templates/overlays/baas/rebase.json +2 -6
- package/templates/template/.env.example +15 -0
- package/templates/template/README.md +56 -22
- package/templates/template/ai-instructions.md +1 -0
- package/templates/template/backend/functions/hello.ts +45 -14
- package/templates/template/backend/package.json +1 -4
- package/templates/template/backend/tsconfig.json +23 -2
- package/templates/template/config/tsconfig.json +16 -1
- package/templates/template/docker-compose.yml +62 -38
- package/templates/template/frontend/src/main.tsx +8 -1
- package/templates/template/frontend/vite.config.ts +5 -0
- package/templates/template/rebase.json +5 -8
- package/templates/overlays/baas/backend/src/index.ts +0 -216
- package/templates/template/frontend/Dockerfile +0 -52
- package/templates/template/frontend/nginx.conf +0 -40
- /package/templates/overlays/baas/{backend/src → config}/storage.ts +0 -0
package/dist/index.es.js
CHANGED
|
@@ -12,7 +12,7 @@ import crypto from "crypto";
|
|
|
12
12
|
import { execSync, spawn, spawnSync } from "child_process";
|
|
13
13
|
import os from "os";
|
|
14
14
|
import { createRebaseClient } from "@rebasepro/client";
|
|
15
|
-
import { BUNDLE_FORMAT_VERSION, RUNTIME_CONTRACT_VERSION, computeSchemaVersion, deserializeCollections } from "@rebasepro/types";
|
|
15
|
+
import { BUNDLE_FORMAT_VERSION, RUNTIME_CONTRACT_VERSION, computeSchemaVersion, deserializeCollections, findStorageSuffixCollision, normalizeStorageSources, storageEnvSuffix } from "@rebasepro/types";
|
|
16
16
|
import { generateSDK } from "@rebasepro/codegen";
|
|
17
17
|
import { createRequire } from "module";
|
|
18
18
|
//#region src/utils/package-manager.ts
|
|
@@ -829,7 +829,7 @@ function openUrl(target, label = "Opening") {
|
|
|
829
829
|
//#region src/commands/init.ts
|
|
830
830
|
var access = promisify(fs.access);
|
|
831
831
|
var __filename$1 = fileURLToPath(import.meta.url);
|
|
832
|
-
var __dirname$
|
|
832
|
+
var __dirname$2 = path.dirname(__filename$1);
|
|
833
833
|
function findParentDir(currentDir, targetName) {
|
|
834
834
|
const root = path.parse(currentDir).root;
|
|
835
835
|
while (currentDir && currentDir !== root) {
|
|
@@ -838,22 +838,56 @@ function findParentDir(currentDir, targetName) {
|
|
|
838
838
|
}
|
|
839
839
|
return null;
|
|
840
840
|
}
|
|
841
|
-
var cliRoot = findParentDir(__dirname$
|
|
841
|
+
var cliRoot = findParentDir(__dirname$2, "cli");
|
|
842
842
|
var PROJECT_NAME_RE = /^[a-z0-9][a-z0-9._-]*$/;
|
|
843
|
+
/**
|
|
844
|
+
* Every scaffolded file that carries a `{{PLACEHOLDER}}`.
|
|
845
|
+
*
|
|
846
|
+
* Exported because it is the single source of truth: `init.test.ts` reads it and
|
|
847
|
+
* asserts that every template file containing `{{` appears here. It used to be a
|
|
848
|
+
* local, with the test harness keeping a *second* copy — so the two drifted, and
|
|
849
|
+
* a test built on the copy could not observe the production list at all.
|
|
850
|
+
*
|
|
851
|
+
* The drift shipped: `docker-compose.yml` arrived with the self-host work
|
|
852
|
+
* (26fd5259c) and was added to neither, so every scaffolded project got a literal
|
|
853
|
+
* `name: {{PROJECT_NAME}}`. In YAML `{{...}}` is a map, not a string, so the
|
|
854
|
+
* documented `docker compose up` path failed on the file before doing anything:
|
|
855
|
+
*
|
|
856
|
+
* yaml: unmarshal errors: line 28: cannot unmarshal !!map into string
|
|
857
|
+
*/
|
|
858
|
+
var TEMPLATE_PLACEHOLDER_FILES = [
|
|
859
|
+
"package.json",
|
|
860
|
+
"frontend/package.json",
|
|
861
|
+
"backend/package.json",
|
|
862
|
+
"config/package.json",
|
|
863
|
+
"frontend/index.html",
|
|
864
|
+
"pnpm-workspace.yaml",
|
|
865
|
+
"docker-compose.yml",
|
|
866
|
+
"README.md"
|
|
867
|
+
];
|
|
843
868
|
/** Returns an error message, or null when the name is a valid package name. */
|
|
844
869
|
function validateProjectName(name) {
|
|
845
870
|
if (!name.trim()) return "Project name is required";
|
|
846
871
|
if (!PROJECT_NAME_RE.test(name)) return "Project name must start with a lowercase letter or number and contain only lowercase letters, numbers, hyphens, dots, or underscores";
|
|
847
872
|
return null;
|
|
848
873
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
874
|
+
/**
|
|
875
|
+
* Whether to scaffold the admin panel alongside the backend.
|
|
876
|
+
*
|
|
877
|
+
* A boolean, not a named pair. It was `--flavor cms|baas`, and neither word
|
|
878
|
+
* survived what they described: "cms" is a product category rather than a thing
|
|
879
|
+
* this tool builds, and "baas" was the same value that used to appear as
|
|
880
|
+
* `backend.mode` — which is now derived from whether collections are declared.
|
|
881
|
+
* What is left is one question: does this project get an admin UI?
|
|
882
|
+
*/
|
|
883
|
+
var HEADLESS_CHOICES = [{
|
|
884
|
+
name: "Backend + admin — API plus an admin UI, driven by collections you define (like Payload/Directus)",
|
|
885
|
+
value: false,
|
|
886
|
+
short: "Backend + admin"
|
|
853
887
|
}, {
|
|
854
|
-
name: "
|
|
855
|
-
value:
|
|
856
|
-
short: "
|
|
888
|
+
name: "Backend only — headless API over your database. No collections, no UI (like Supabase)",
|
|
889
|
+
value: true,
|
|
890
|
+
short: "Backend only"
|
|
857
891
|
}];
|
|
858
892
|
var PRESET_CHOICES = [
|
|
859
893
|
{
|
|
@@ -878,7 +912,7 @@ var PRESET_CHOICES = [
|
|
|
878
912
|
* types registered by the installed version of inquirer.
|
|
879
913
|
*/
|
|
880
914
|
function buildInitQuestions(params) {
|
|
881
|
-
const { nameArg, templateArg,
|
|
915
|
+
const { nameArg, templateArg, headlessArg, hasGitFlag, hasInstallFlag, pm } = params;
|
|
882
916
|
const questions = [];
|
|
883
917
|
if (!nameArg) questions.push({
|
|
884
918
|
type: "input",
|
|
@@ -887,12 +921,12 @@ function buildInitQuestions(params) {
|
|
|
887
921
|
default: "my-rebase-app",
|
|
888
922
|
validate: (input) => validateProjectName(input) ?? true
|
|
889
923
|
});
|
|
890
|
-
if (
|
|
924
|
+
if (headlessArg === void 0) questions.push({
|
|
891
925
|
type: "select",
|
|
892
|
-
name: "
|
|
926
|
+
name: "headless",
|
|
893
927
|
message: "What do you want to build?",
|
|
894
|
-
choices:
|
|
895
|
-
default:
|
|
928
|
+
choices: HEADLESS_CHOICES,
|
|
929
|
+
default: false
|
|
896
930
|
});
|
|
897
931
|
if (!templateArg) questions.push({
|
|
898
932
|
type: "select",
|
|
@@ -900,7 +934,7 @@ function buildInitQuestions(params) {
|
|
|
900
934
|
message: "Choose a starter template:",
|
|
901
935
|
choices: PRESET_CHOICES,
|
|
902
936
|
default: "blog",
|
|
903
|
-
when: (answers) => (
|
|
937
|
+
when: (answers) => !(headlessArg ?? answers.headless)
|
|
904
938
|
});
|
|
905
939
|
if (!hasGitFlag) questions.push({
|
|
906
940
|
type: "confirm",
|
|
@@ -956,7 +990,7 @@ ${chalk.bold("Usage")}
|
|
|
956
990
|
|
|
957
991
|
${chalk.bold("Options")}
|
|
958
992
|
${chalk.blue("-t, --template")} ${chalk.gray("<preset>")} blog | ecommerce | blank ${chalk.gray("(default: blog)")}
|
|
959
|
-
${chalk.blue("
|
|
993
|
+
${chalk.blue("--headless")} Backend only — no admin panel, no collections
|
|
960
994
|
${chalk.blue("-y, --yes")} Accept defaults, never prompt ${chalk.gray("(required for CI / non-TTY)")}
|
|
961
995
|
${chalk.blue("-i, --install")} Install dependencies after scaffolding
|
|
962
996
|
${chalk.blue("-g, --git")} Initialize a git repository and make an initial commit
|
|
@@ -965,14 +999,14 @@ ${chalk.bold("Options")}
|
|
|
965
999
|
${chalk.blue("--project")} ${chalk.gray("<slug>")} Link the scaffold to a Rebase Cloud project
|
|
966
1000
|
${chalk.blue("--setup-key")} ${chalk.gray("<key>")} One-time key authenticating the cloud link ${chalk.gray("(use with --project)")}
|
|
967
1001
|
|
|
968
|
-
${chalk.bold("
|
|
969
|
-
${chalk.
|
|
970
|
-
${chalk.blue("
|
|
971
|
-
|
|
1002
|
+
${chalk.bold("What gets scaffolded")}
|
|
1003
|
+
${chalk.gray("default")} Backend + an admin UI, driven by collections you define ${chalk.gray("(like Payload/Directus)")}
|
|
1004
|
+
${chalk.blue("--headless")} Backend only, over your existing database ${chalk.gray("(like Supabase)")}
|
|
1005
|
+
${chalk.gray("--template has no effect: there are no collections to seed.")}
|
|
972
1006
|
|
|
973
1007
|
${chalk.bold("Examples")}
|
|
974
1008
|
${chalk.gray("$")} rebase init my-shop --template ecommerce --install
|
|
975
|
-
${chalk.gray("$")} rebase init my-api --
|
|
1009
|
+
${chalk.gray("$")} rebase init my-api --headless --yes
|
|
976
1010
|
${chalk.gray("$")} rebase init . --yes --git
|
|
977
1011
|
`);
|
|
978
1012
|
}
|
|
@@ -993,14 +1027,13 @@ async function promptForOptions(rawArgs, pm) {
|
|
|
993
1027
|
"--database-url": String,
|
|
994
1028
|
"--introspect": Boolean,
|
|
995
1029
|
"--template": String,
|
|
996
|
-
"--
|
|
1030
|
+
"--headless": Boolean,
|
|
997
1031
|
"--project": String,
|
|
998
1032
|
"--setup-key": String,
|
|
999
1033
|
"--yes": Boolean,
|
|
1000
1034
|
"-g": "--git",
|
|
1001
1035
|
"-i": "--install",
|
|
1002
1036
|
"-t": "--template",
|
|
1003
|
-
"-f": "--flavor",
|
|
1004
1037
|
"-y": "--yes"
|
|
1005
1038
|
}, {
|
|
1006
1039
|
argv: rawArgs.slice(3),
|
|
@@ -1021,11 +1054,7 @@ async function promptForOptions(rawArgs, pm) {
|
|
|
1021
1054
|
console.error(chalk.red(`Unknown template "${templateArg}". Available: ${PRESET_CHOICES.map((p) => p.value).join(", ")}`));
|
|
1022
1055
|
process.exit(1);
|
|
1023
1056
|
}
|
|
1024
|
-
const
|
|
1025
|
-
if (flavorArg && !FLAVOR_CHOICES.some((f) => f.value === flavorArg)) {
|
|
1026
|
-
console.error(chalk.red(`Unknown flavor "${flavorArg}". Available: ${FLAVOR_CHOICES.map((f) => f.value).join(", ")}`));
|
|
1027
|
-
process.exit(1);
|
|
1028
|
-
}
|
|
1057
|
+
const headlessArg = args["--headless"] === true ? true : void 0;
|
|
1029
1058
|
if (isNonInteractive) {
|
|
1030
1059
|
const projectName = nameArg || "my-rebase-app";
|
|
1031
1060
|
const targetDirectory = path.resolve(process.cwd(), projectName);
|
|
@@ -1041,7 +1070,7 @@ async function promptForOptions(rawArgs, pm) {
|
|
|
1041
1070
|
introspect: args["--introspect"] || false,
|
|
1042
1071
|
preset: templateArg || "blog",
|
|
1043
1072
|
explicitPreset: !!templateArg,
|
|
1044
|
-
|
|
1073
|
+
headless: headlessArg ?? false,
|
|
1045
1074
|
pm,
|
|
1046
1075
|
pmCommands,
|
|
1047
1076
|
cloudProject: args["--project"] || void 0,
|
|
@@ -1052,14 +1081,14 @@ async function promptForOptions(rawArgs, pm) {
|
|
|
1052
1081
|
if (!process.stdin.isTTY) {
|
|
1053
1082
|
console.error(chalk.red("Cannot prompt: this is a non-interactive terminal (no TTY)."));
|
|
1054
1083
|
console.error(chalk.yellow(" Re-run with --yes to accept defaults, passing any choices as flags, e.g.:"));
|
|
1055
|
-
console.error(chalk.yellow(` rebase init ${nameArg || "my-app"} --yes --template blog
|
|
1056
|
-
console.error(chalk.gray(" Options: --template <blog|ecommerce|blank> --
|
|
1084
|
+
console.error(chalk.yellow(` rebase init ${nameArg || "my-app"} --yes --template blog`));
|
|
1085
|
+
console.error(chalk.gray(" Options: --template <blog|ecommerce|blank> --headless --database-url <url> --install --git"));
|
|
1057
1086
|
process.exit(1);
|
|
1058
1087
|
}
|
|
1059
1088
|
const questions = buildInitQuestions({
|
|
1060
1089
|
nameArg,
|
|
1061
1090
|
templateArg,
|
|
1062
|
-
|
|
1091
|
+
headlessArg,
|
|
1063
1092
|
hasGitFlag: !!args["--git"],
|
|
1064
1093
|
hasInstallFlag: !!args["--install"],
|
|
1065
1094
|
pm
|
|
@@ -1079,7 +1108,7 @@ async function promptForOptions(rawArgs, pm) {
|
|
|
1079
1108
|
introspect: answers.introspect || false,
|
|
1080
1109
|
preset: templateArg || answers.preset || "blog",
|
|
1081
1110
|
explicitPreset: !!templateArg,
|
|
1082
|
-
|
|
1111
|
+
headless: headlessArg ?? Boolean(answers.headless),
|
|
1083
1112
|
pm,
|
|
1084
1113
|
pmCommands,
|
|
1085
1114
|
cloudProject: args["--project"] || void 0,
|
|
@@ -1163,12 +1192,12 @@ async function createProject$1(options) {
|
|
|
1163
1192
|
const shipped = path.join(options.targetDirectory, from);
|
|
1164
1193
|
if (fs.existsSync(shipped)) fs.renameSync(shipped, path.join(options.targetDirectory, to));
|
|
1165
1194
|
}
|
|
1166
|
-
if (options.
|
|
1167
|
-
if (options.
|
|
1195
|
+
if (options.headless && options.explicitPreset) console.log(chalk.yellow(` Ignoring --template ${options.preset}: a headless project declares no collections.`));
|
|
1196
|
+
if (!options.headless) {
|
|
1168
1197
|
if (options.introspect && options.preset !== "blank") console.log(chalk.gray(" Using the blank template: collections will come from your database."));
|
|
1169
1198
|
await applyPreset(options.targetDirectory, options.introspect ? "blank" : options.preset);
|
|
1170
1199
|
}
|
|
1171
|
-
await
|
|
1200
|
+
await applyHeadless(options.targetDirectory, options.headless);
|
|
1172
1201
|
await replacePlaceholders(options);
|
|
1173
1202
|
await configureEnvFile(options.targetDirectory, options.databaseUrl);
|
|
1174
1203
|
if (options.git) {
|
|
@@ -1266,7 +1295,7 @@ async function createProject$1(options) {
|
|
|
1266
1295
|
console.log("");
|
|
1267
1296
|
const runDev = pmCommands.run("dev");
|
|
1268
1297
|
const runDbPush = pmCommands.run("db:push");
|
|
1269
|
-
const isBaas = options.
|
|
1298
|
+
const isBaas = options.headless;
|
|
1270
1299
|
const cdTarget = formatCdTarget(process.cwd(), options.targetDirectory);
|
|
1271
1300
|
if (cdTarget) console.log(` ${chalk.cyan("cd")} ${cdTarget}`);
|
|
1272
1301
|
if (!options.installDeps) console.log(` ${chalk.cyan(installCmd.join(" "))}`);
|
|
@@ -1336,18 +1365,31 @@ async function createProject$1(options) {
|
|
|
1336
1365
|
* presets directory so the final project is clean.
|
|
1337
1366
|
*/
|
|
1338
1367
|
/**
|
|
1339
|
-
* Reduce the scaffolded project to the chosen
|
|
1368
|
+
* Reduce the scaffolded project to the chosen shape.
|
|
1369
|
+
*
|
|
1370
|
+
* The base template is the full triad. `--headless` drops the frontend and the
|
|
1371
|
+
* declared collections — there is nothing to define, since the server derives
|
|
1372
|
+
* its API from the database — and overlays the files that differ.
|
|
1340
1373
|
*
|
|
1341
|
-
* The
|
|
1342
|
-
*
|
|
1343
|
-
*
|
|
1374
|
+
* The config *package* stays, holding only `storageAuthorize`. Storage is not
|
|
1375
|
+
* under row-level security, so a deployment with file storage enabled and no
|
|
1376
|
+
* access model serves every user's files to every signed-in user; the server
|
|
1377
|
+
* refuses to boot in that state. Deleting the package outright would leave a
|
|
1378
|
+
* headless project with nowhere to put the hook, and the scaffold's own
|
|
1379
|
+
* docker-compose.yml enables storage — so the first `docker compose up` would
|
|
1380
|
+
* crash-loop.
|
|
1344
1381
|
*/
|
|
1345
|
-
async function
|
|
1346
|
-
if (
|
|
1347
|
-
|
|
1382
|
+
async function applyHeadless(targetDirectory, headless) {
|
|
1383
|
+
if (!headless) return;
|
|
1384
|
+
fs.rmSync(path.join(targetDirectory, "frontend"), {
|
|
1348
1385
|
recursive: true,
|
|
1349
1386
|
force: true
|
|
1350
1387
|
});
|
|
1388
|
+
fs.rmSync(path.join(targetDirectory, "config", "collections"), {
|
|
1389
|
+
recursive: true,
|
|
1390
|
+
force: true
|
|
1391
|
+
});
|
|
1392
|
+
for (const stray of ["admin.d.ts", "frontend-assets.d.ts"]) fs.rmSync(path.join(targetDirectory, "config", stray), { force: true });
|
|
1351
1393
|
fs.rmSync(path.join(targetDirectory, "backend", "src", "schema.generated.ts"), { force: true });
|
|
1352
1394
|
const overlayDir = path.resolve(cliRoot, "templates", "overlays", "baas");
|
|
1353
1395
|
if (!fs.existsSync(overlayDir)) {
|
|
@@ -1394,15 +1436,7 @@ function cleanupPresets(presetsDir) {
|
|
|
1394
1436
|
});
|
|
1395
1437
|
}
|
|
1396
1438
|
async function replacePlaceholders(options) {
|
|
1397
|
-
const filesToProcess =
|
|
1398
|
-
"package.json",
|
|
1399
|
-
"frontend/package.json",
|
|
1400
|
-
"backend/package.json",
|
|
1401
|
-
"config/package.json",
|
|
1402
|
-
"frontend/index.html",
|
|
1403
|
-
"pnpm-workspace.yaml",
|
|
1404
|
-
"README.md"
|
|
1405
|
-
];
|
|
1439
|
+
const filesToProcess = TEMPLATE_PLACEHOLDER_FILES;
|
|
1406
1440
|
const packageJsonPath = path.resolve(cliRoot, "package.json");
|
|
1407
1441
|
let cliVersion = "latest";
|
|
1408
1442
|
if (fs.existsSync(packageJsonPath)) cliVersion = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")).version || "latest";
|
|
@@ -1497,6 +1531,26 @@ async function findAvailablePort(startPort) {
|
|
|
1497
1531
|
while (!await isPortAvailable(port)) port++;
|
|
1498
1532
|
return port;
|
|
1499
1533
|
}
|
|
1534
|
+
/**
|
|
1535
|
+
* The CLI's own version, which is the runtime image tag a scaffolded project
|
|
1536
|
+
* pins. They move together: the CLI, the packages and the runtime image are cut
|
|
1537
|
+
* from one release, so the version that installed the project is the version
|
|
1538
|
+
* whose runtime can boot its bundle.
|
|
1539
|
+
*
|
|
1540
|
+
* Falls back to `latest` only when the CLI cannot read its own manifest — a
|
|
1541
|
+
* floating tag is worse than a pinned one, but better than a compose file that
|
|
1542
|
+
* names a version that was never published.
|
|
1543
|
+
*/
|
|
1544
|
+
function readCliVersion() {
|
|
1545
|
+
try {
|
|
1546
|
+
const manifest = path.resolve(cliRoot, "package.json");
|
|
1547
|
+
if (fs.existsSync(manifest)) {
|
|
1548
|
+
const pkg = JSON.parse(fs.readFileSync(manifest, "utf-8"));
|
|
1549
|
+
if (typeof pkg.version === "string" && pkg.version) return pkg.version;
|
|
1550
|
+
}
|
|
1551
|
+
} catch {}
|
|
1552
|
+
return "latest";
|
|
1553
|
+
}
|
|
1500
1554
|
async function configureEnvFile(targetDirectory, databaseUrl) {
|
|
1501
1555
|
const envExamplePath = path.join(targetDirectory, ".env.example");
|
|
1502
1556
|
const envPath = path.join(targetDirectory, ".env");
|
|
@@ -1508,6 +1562,8 @@ async function configureEnvFile(targetDirectory, databaseUrl) {
|
|
|
1508
1562
|
let envContent = fs.readFileSync(envPath, "utf-8");
|
|
1509
1563
|
envContent = envContent.replace(/^JWT_SECRET=.*$/m, `JWT_SECRET=${jwtSecret}`);
|
|
1510
1564
|
envContent = envContent.replace(/^#\s*REBASE_SERVICE_KEY=.*$/m, `REBASE_SERVICE_KEY=${serviceKey}`);
|
|
1565
|
+
const runtimeVersion = readCliVersion();
|
|
1566
|
+
envContent = /^#?\s*REBASE_VERSION=.*$/m.test(envContent) ? envContent.replace(/^#?\s*REBASE_VERSION=.*$/m, `REBASE_VERSION=${runtimeVersion}`) : `${envContent.trimEnd()}\n\n# The Rebase runtime image tag docker-compose.yml pulls.\n# Change this and restart to upgrade; your project bundle is untouched.\nREBASE_VERSION=${runtimeVersion}\n`;
|
|
1511
1567
|
if (databaseUrl) {
|
|
1512
1568
|
if (/[\r\n]/.test(databaseUrl)) throw new Error("Invalid DATABASE_URL: multiline values are not allowed.");
|
|
1513
1569
|
envContent = envContent.replace(/^DATABASE_URL=.*$/m, `DATABASE_URL=${databaseUrl}\nDATABASE_PASSWORD=${dbPassword}`);
|
|
@@ -2014,13 +2070,19 @@ var ManifestError = class extends Error {
|
|
|
2014
2070
|
this.name = "ManifestError";
|
|
2015
2071
|
}
|
|
2016
2072
|
};
|
|
2017
|
-
var APP_TYPES = [
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2073
|
+
var APP_TYPES = ["backend", "static"];
|
|
2074
|
+
/**
|
|
2075
|
+
* App types that used to exist, and what replaced each one.
|
|
2076
|
+
*
|
|
2077
|
+
* Kept so a manifest written against the old vocabulary fails with the fix in
|
|
2078
|
+
* hand rather than with `must be one of: backend, static`, which tells a reader
|
|
2079
|
+
* what is wrong but not what to write instead.
|
|
2080
|
+
*/
|
|
2081
|
+
var REMOVED_APP_TYPES = {
|
|
2082
|
+
admin: "the admin panel is an ordinary static app now — declare it as { \"type\": \"static\", \"root\": \"frontend\", \"output\": \"frontend/dist\", \"path\": \"/admin\" }",
|
|
2083
|
+
custom: "who owns the server is a property of the backend now — declare { \"type\": \"backend\", \"runtime\": \"custom\" } instead of a separate app",
|
|
2084
|
+
mobile: "mobile apps are no longer declared in the manifest — nothing consumed this type. Remove the entry"
|
|
2085
|
+
};
|
|
2024
2086
|
/** Reserved because they name things in URLs and CLI output. */
|
|
2025
2087
|
var RESERVED_APP_NAMES = new Set([
|
|
2026
2088
|
"api",
|
|
@@ -2029,6 +2091,30 @@ var RESERVED_APP_NAMES = new Set([
|
|
|
2029
2091
|
"livez",
|
|
2030
2092
|
"_rebase"
|
|
2031
2093
|
]);
|
|
2094
|
+
/**
|
|
2095
|
+
* Validate a static app's public base path.
|
|
2096
|
+
*
|
|
2097
|
+
* Normalizes to "no trailing slash, except for the root" so that mounting and
|
|
2098
|
+
* the `REBASE_APP_BASE` build variable have one shape to reason about.
|
|
2099
|
+
*/
|
|
2100
|
+
function checkAppPath(value, fieldPath, issues) {
|
|
2101
|
+
if (value === void 0) return void 0;
|
|
2102
|
+
if (typeof value !== "string" || !value.startsWith("/") || value.includes("..")) {
|
|
2103
|
+
issues.push({
|
|
2104
|
+
path: fieldPath,
|
|
2105
|
+
message: "must be an absolute path like \"/admin\""
|
|
2106
|
+
});
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
if (value !== "/" && value.endsWith("/")) {
|
|
2110
|
+
issues.push({
|
|
2111
|
+
path: fieldPath,
|
|
2112
|
+
message: "must not end with a slash — write \"/admin\", not \"/admin/\""
|
|
2113
|
+
});
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
return value;
|
|
2117
|
+
}
|
|
2032
2118
|
function isRecord(value) {
|
|
2033
2119
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2034
2120
|
}
|
|
@@ -2071,6 +2157,73 @@ function checkRelativePath(value, fieldPath, issues, { required }) {
|
|
|
2071
2157
|
}
|
|
2072
2158
|
return value;
|
|
2073
2159
|
}
|
|
2160
|
+
/** Fields each app type understands. Anything else is a typo or a newer CLI. */
|
|
2161
|
+
var KNOWN_APP_FIELDS = {
|
|
2162
|
+
backend: [
|
|
2163
|
+
"type",
|
|
2164
|
+
"runtime",
|
|
2165
|
+
"config",
|
|
2166
|
+
"functions",
|
|
2167
|
+
"crons",
|
|
2168
|
+
"schema",
|
|
2169
|
+
"usersCollection",
|
|
2170
|
+
"dockerfile",
|
|
2171
|
+
"context",
|
|
2172
|
+
"port"
|
|
2173
|
+
],
|
|
2174
|
+
static: [
|
|
2175
|
+
"type",
|
|
2176
|
+
"root",
|
|
2177
|
+
"build",
|
|
2178
|
+
"output",
|
|
2179
|
+
"path",
|
|
2180
|
+
"spa"
|
|
2181
|
+
]
|
|
2182
|
+
};
|
|
2183
|
+
/**
|
|
2184
|
+
* Report a field this CLI does not recognise.
|
|
2185
|
+
*
|
|
2186
|
+
* A warning rather than an error, and the distinction matters in both
|
|
2187
|
+
* directions. `"pathh": "/admin"` is a typo that would otherwise be silently
|
|
2188
|
+
* dropped — the app builds for `/`, mounts at `/`, and the only symptom is that
|
|
2189
|
+
* it is not where you put it. But an unknown field is also what an *older* CLI
|
|
2190
|
+
* sees when it opens a manifest written for a newer one, and refusing to build
|
|
2191
|
+
* over a field that is simply from the future would make every manifest addition
|
|
2192
|
+
* a breaking change.
|
|
2193
|
+
*
|
|
2194
|
+
* So: name it, suggest the near-miss, and carry on.
|
|
2195
|
+
*/
|
|
2196
|
+
function warnUnknownFields(name, raw, type) {
|
|
2197
|
+
const known = KNOWN_APP_FIELDS[type];
|
|
2198
|
+
if (!known) return;
|
|
2199
|
+
for (const field of Object.keys(raw)) {
|
|
2200
|
+
if (known.includes(field)) continue;
|
|
2201
|
+
const suggestion = known.find((candidate) => isNearMiss(candidate, field));
|
|
2202
|
+
console.warn(`⚠ rebase.json: apps.${name}.${field} is not a field this CLI knows.` + (suggestion ? ` Did you mean "${suggestion}"?` : " It is ignored — your CLI may be older than this manifest."));
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
/** One edit apart, ignoring case: enough for a typo, tight enough to stay quiet. */
|
|
2206
|
+
function isNearMiss(a, b) {
|
|
2207
|
+
const x = a.toLowerCase();
|
|
2208
|
+
const y = b.toLowerCase();
|
|
2209
|
+
if (x === y) return true;
|
|
2210
|
+
if (Math.abs(x.length - y.length) > 1) return false;
|
|
2211
|
+
const [shorter, longer] = x.length <= y.length ? [x, y] : [y, x];
|
|
2212
|
+
let i = 0;
|
|
2213
|
+
let j = 0;
|
|
2214
|
+
let edits = 0;
|
|
2215
|
+
while (i < shorter.length && j < longer.length) {
|
|
2216
|
+
if (shorter[i] === longer[j]) {
|
|
2217
|
+
i++;
|
|
2218
|
+
j++;
|
|
2219
|
+
continue;
|
|
2220
|
+
}
|
|
2221
|
+
if (++edits > 1) return false;
|
|
2222
|
+
if (shorter.length === longer.length) i++;
|
|
2223
|
+
j++;
|
|
2224
|
+
}
|
|
2225
|
+
return edits + (longer.length - j) + (shorter.length - i) <= 1;
|
|
2226
|
+
}
|
|
2074
2227
|
function validateApp(name, raw, issues) {
|
|
2075
2228
|
const base = `apps.${name}`;
|
|
2076
2229
|
if (!isRecord(raw)) {
|
|
@@ -2081,6 +2234,13 @@ function validateApp(name, raw, issues) {
|
|
|
2081
2234
|
return;
|
|
2082
2235
|
}
|
|
2083
2236
|
const type = raw.type;
|
|
2237
|
+
if (typeof type === "string" && REMOVED_APP_TYPES[type]) {
|
|
2238
|
+
issues.push({
|
|
2239
|
+
path: `${base}.type`,
|
|
2240
|
+
message: `"${type}" is no longer an app type — ${REMOVED_APP_TYPES[type]}`
|
|
2241
|
+
});
|
|
2242
|
+
return;
|
|
2243
|
+
}
|
|
2084
2244
|
if (typeof type !== "string" || !APP_TYPES.includes(type)) {
|
|
2085
2245
|
issues.push({
|
|
2086
2246
|
path: `${base}.type`,
|
|
@@ -2088,18 +2248,39 @@ function validateApp(name, raw, issues) {
|
|
|
2088
2248
|
});
|
|
2089
2249
|
return;
|
|
2090
2250
|
}
|
|
2251
|
+
warnUnknownFields(name, raw, type);
|
|
2091
2252
|
switch (type) {
|
|
2092
|
-
case "backend":
|
|
2253
|
+
case "backend": {
|
|
2093
2254
|
checkRelativePath(raw.config, `${base}.config`, issues, { required: false });
|
|
2094
2255
|
checkRelativePath(raw.functions, `${base}.functions`, issues, { required: false });
|
|
2095
2256
|
checkRelativePath(raw.crons, `${base}.crons`, issues, { required: false });
|
|
2096
2257
|
checkRelativePath(raw.schema, `${base}.schema`, issues, { required: false });
|
|
2097
2258
|
checkRelativePath(raw.usersCollection, `${base}.usersCollection`, issues, { required: false });
|
|
2098
|
-
if (raw.mode !== void 0
|
|
2259
|
+
if (raw.mode !== void 0) issues.push({
|
|
2099
2260
|
path: `${base}.mode`,
|
|
2100
|
-
message: "
|
|
2261
|
+
message: "is no longer a field — collections come from the config directory when it exists, and are introspected from the database when it does not"
|
|
2262
|
+
});
|
|
2263
|
+
const custom = raw.runtime === "custom";
|
|
2264
|
+
if (raw.runtime !== "managed" && !custom) issues.push({
|
|
2265
|
+
path: `${base}.runtime`,
|
|
2266
|
+
message: "is required, and must be \"managed\" or \"custom\""
|
|
2267
|
+
});
|
|
2268
|
+
for (const field of [
|
|
2269
|
+
"dockerfile",
|
|
2270
|
+
"context",
|
|
2271
|
+
"port"
|
|
2272
|
+
]) if (raw[field] !== void 0 && !custom) issues.push({
|
|
2273
|
+
path: `${base}.${field}`,
|
|
2274
|
+
message: "only applies to a custom runtime — set \"runtime\": \"custom\" to build your own image"
|
|
2275
|
+
});
|
|
2276
|
+
checkRelativePath(raw.dockerfile, `${base}.dockerfile`, issues, { required: false });
|
|
2277
|
+
checkRelativePath(raw.context, `${base}.context`, issues, { required: false });
|
|
2278
|
+
if (raw.port !== void 0 && (typeof raw.port !== "number" || !Number.isInteger(raw.port))) issues.push({
|
|
2279
|
+
path: `${base}.port`,
|
|
2280
|
+
message: "must be an integer"
|
|
2101
2281
|
});
|
|
2102
2282
|
return raw;
|
|
2283
|
+
}
|
|
2103
2284
|
case "static":
|
|
2104
2285
|
checkRelativePath(raw.root, `${base}.root`, issues, { required: true });
|
|
2105
2286
|
checkRelativePath(raw.output, `${base}.output`, issues, { required: true });
|
|
@@ -2111,37 +2292,7 @@ function validateApp(name, raw, issues) {
|
|
|
2111
2292
|
path: `${base}.spa`,
|
|
2112
2293
|
message: "must be a boolean"
|
|
2113
2294
|
});
|
|
2114
|
-
|
|
2115
|
-
case "admin": {
|
|
2116
|
-
const mode = raw.mode ?? "hosted";
|
|
2117
|
-
if (mode !== "hosted" && mode !== "bundled") {
|
|
2118
|
-
issues.push({
|
|
2119
|
-
path: `${base}.mode`,
|
|
2120
|
-
message: "must be \"hosted\" or \"bundled\""
|
|
2121
|
-
});
|
|
2122
|
-
return;
|
|
2123
|
-
}
|
|
2124
|
-
if (mode === "bundled") {
|
|
2125
|
-
checkRelativePath(raw.root, `${base}.root`, issues, { required: true });
|
|
2126
|
-
checkRelativePath(raw.output, `${base}.output`, issues, { required: true });
|
|
2127
|
-
}
|
|
2128
|
-
return raw;
|
|
2129
|
-
}
|
|
2130
|
-
case "mobile": {
|
|
2131
|
-
const platform = raw.platform;
|
|
2132
|
-
if (platform !== "ios" && platform !== "android" && platform !== "other") issues.push({
|
|
2133
|
-
path: `${base}.platform`,
|
|
2134
|
-
message: "must be \"ios\", \"android\" or \"other\""
|
|
2135
|
-
});
|
|
2136
|
-
return raw;
|
|
2137
|
-
}
|
|
2138
|
-
case "custom":
|
|
2139
|
-
checkRelativePath(raw.dockerfile, `${base}.dockerfile`, issues, { required: false });
|
|
2140
|
-
checkRelativePath(raw.context, `${base}.context`, issues, { required: false });
|
|
2141
|
-
if (raw.port !== void 0 && (typeof raw.port !== "number" || !Number.isInteger(raw.port))) issues.push({
|
|
2142
|
-
path: `${base}.port`,
|
|
2143
|
-
message: "must be an integer"
|
|
2144
|
-
});
|
|
2295
|
+
checkAppPath(raw.path, `${base}.path`, issues);
|
|
2145
2296
|
return raw;
|
|
2146
2297
|
default: return;
|
|
2147
2298
|
}
|
|
@@ -2155,10 +2306,13 @@ function validateManifest(raw) {
|
|
|
2155
2306
|
path: "",
|
|
2156
2307
|
message: `${MANIFEST_FILENAME} must contain a JSON object`
|
|
2157
2308
|
}] };
|
|
2158
|
-
if (typeof raw.
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2309
|
+
if (typeof raw.rebase !== "string" || raw.rebase.trim() === "") {
|
|
2310
|
+
const message = typeof raw.runtime === "string" ? `is required, e.g. "^1" — this is the top-level "runtime" key renamed, because "runtime" now means "managed" or "custom" on the backend app` : `is required, e.g. "^1"`;
|
|
2311
|
+
issues.push({
|
|
2312
|
+
path: "rebase",
|
|
2313
|
+
message
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2162
2316
|
if (!isRecord(raw.apps)) {
|
|
2163
2317
|
issues.push({
|
|
2164
2318
|
path: "apps",
|
|
@@ -2192,55 +2346,148 @@ function validateManifest(raw) {
|
|
|
2192
2346
|
path: "apps",
|
|
2193
2347
|
message: "a project may declare at most one backend app"
|
|
2194
2348
|
});
|
|
2349
|
+
const byPath = /* @__PURE__ */ new Map();
|
|
2350
|
+
for (const [name, app] of Object.entries(apps)) {
|
|
2351
|
+
if (app.type !== "static") continue;
|
|
2352
|
+
const at = app.path ?? "/";
|
|
2353
|
+
const owner = byPath.get(at);
|
|
2354
|
+
if (owner) {
|
|
2355
|
+
issues.push({
|
|
2356
|
+
path: `apps.${name}.path`,
|
|
2357
|
+
message: `two apps cannot serve the same path — "${owner}" is already at "${at}"`
|
|
2358
|
+
});
|
|
2359
|
+
continue;
|
|
2360
|
+
}
|
|
2361
|
+
byPath.set(at, name);
|
|
2362
|
+
}
|
|
2363
|
+
const storage = validateStorageSources(raw.storage, issues);
|
|
2195
2364
|
if (issues.length > 0) return { issues };
|
|
2196
2365
|
return {
|
|
2197
2366
|
manifest: {
|
|
2198
2367
|
$schema: typeof raw.$schema === "string" ? raw.$schema : void 0,
|
|
2199
|
-
|
|
2200
|
-
apps
|
|
2368
|
+
rebase: raw.rebase,
|
|
2369
|
+
apps,
|
|
2370
|
+
...storage ? { storage } : {}
|
|
2201
2371
|
},
|
|
2202
2372
|
issues
|
|
2203
2373
|
};
|
|
2204
2374
|
}
|
|
2205
2375
|
/**
|
|
2376
|
+
* Validate the `storage` block — which buckets this project uses.
|
|
2377
|
+
*
|
|
2378
|
+
* Absent means one default source, so `undefined` is a valid answer and not an
|
|
2379
|
+
* issue. Everything else is checked strictly, because each key here becomes the
|
|
2380
|
+
* suffix of a set of environment variables: a key that cannot become a variable
|
|
2381
|
+
* name, or two keys that become the *same* one, are failures worth catching
|
|
2382
|
+
* while someone is looking at the file rather than at a tenant serving one
|
|
2383
|
+
* bucket's files with another's credentials.
|
|
2384
|
+
*/
|
|
2385
|
+
function validateStorageSources(raw, issues) {
|
|
2386
|
+
if (raw === void 0) return void 0;
|
|
2387
|
+
if (!isRecord(raw)) {
|
|
2388
|
+
issues.push({
|
|
2389
|
+
path: "storage",
|
|
2390
|
+
message: "must be an object keyed by storage source name"
|
|
2391
|
+
});
|
|
2392
|
+
return;
|
|
2393
|
+
}
|
|
2394
|
+
const sources = {};
|
|
2395
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
2396
|
+
if (!isRecord(value)) {
|
|
2397
|
+
issues.push({
|
|
2398
|
+
path: `storage.${key}`,
|
|
2399
|
+
message: "must be an object"
|
|
2400
|
+
});
|
|
2401
|
+
continue;
|
|
2402
|
+
}
|
|
2403
|
+
if (typeof value.engine !== "string" || value.engine.trim() === "") {
|
|
2404
|
+
issues.push({
|
|
2405
|
+
path: `storage.${key}.engine`,
|
|
2406
|
+
message: "is required, e.g. \"s3\", \"gcs\" or \"local\""
|
|
2407
|
+
});
|
|
2408
|
+
continue;
|
|
2409
|
+
}
|
|
2410
|
+
if (value.transport !== void 0 && value.transport !== "server" && value.transport !== "direct") {
|
|
2411
|
+
issues.push({
|
|
2412
|
+
path: `storage.${key}.transport`,
|
|
2413
|
+
message: "must be \"server\" or \"direct\""
|
|
2414
|
+
});
|
|
2415
|
+
continue;
|
|
2416
|
+
}
|
|
2417
|
+
if (value.label !== void 0 && typeof value.label !== "string") {
|
|
2418
|
+
issues.push({
|
|
2419
|
+
path: `storage.${key}.label`,
|
|
2420
|
+
message: "must be a string"
|
|
2421
|
+
});
|
|
2422
|
+
continue;
|
|
2423
|
+
}
|
|
2424
|
+
try {
|
|
2425
|
+
storageEnvSuffix(key);
|
|
2426
|
+
} catch {
|
|
2427
|
+
issues.push({
|
|
2428
|
+
path: `storage.${key}`,
|
|
2429
|
+
message: "name cannot become an environment variable suffix — use a name containing at least one letter or digit"
|
|
2430
|
+
});
|
|
2431
|
+
continue;
|
|
2432
|
+
}
|
|
2433
|
+
sources[key] = {
|
|
2434
|
+
engine: value.engine,
|
|
2435
|
+
...value.transport !== void 0 ? { transport: value.transport } : {},
|
|
2436
|
+
...value.label !== void 0 ? { label: value.label } : {}
|
|
2437
|
+
};
|
|
2438
|
+
}
|
|
2439
|
+
const collision = findStorageSuffixCollision(Object.keys(sources));
|
|
2440
|
+
if (collision) issues.push({
|
|
2441
|
+
path: `storage.${collision.b}`,
|
|
2442
|
+
message: `maps to the same environment variable suffix ("${collision.suffix || "(none)"}") as "${collision.a}", so the two would read each other's configuration — rename one of them`
|
|
2443
|
+
});
|
|
2444
|
+
return Object.keys(sources).length > 0 ? sources : void 0;
|
|
2445
|
+
}
|
|
2446
|
+
/**
|
|
2206
2447
|
* Infer a manifest from a directory that does not have one.
|
|
2207
2448
|
*
|
|
2208
2449
|
* This mirrors exactly what the template scaffolds, which is what makes adopting
|
|
2209
2450
|
* the manifest a no-op for existing projects: the synthesized result is what
|
|
2210
2451
|
* they would have written by hand.
|
|
2211
2452
|
*
|
|
2212
|
-
*
|
|
2213
|
-
*
|
|
2214
|
-
*
|
|
2215
|
-
*
|
|
2453
|
+
* The backend's `runtime` is inferred from whether the repository declares a
|
|
2454
|
+
* **Dockerfile** — the thing that actually builds an image — and from nothing
|
|
2455
|
+
* else. It used to be inferred from the presence of `backend/src/index.ts`,
|
|
2456
|
+
* which every scaffolded project had whether or not it wanted its own server, so
|
|
2457
|
+
* projects predating the manifest silently landed on the custom runtime and paid
|
|
2458
|
+
* for it (see `docs/cloud-deploy-workspace-vendoring.md`).
|
|
2216
2459
|
*/
|
|
2217
2460
|
function synthesizeManifest(projectRoot) {
|
|
2218
2461
|
const exists = (relative) => fs.existsSync(path.join(projectRoot, relative));
|
|
2219
2462
|
const apps = {};
|
|
2220
2463
|
const hasConfig = exists(DEFAULT_CONFIG_DIR);
|
|
2221
2464
|
const hasBackend = exists("backend");
|
|
2222
|
-
const
|
|
2223
|
-
if (hasBackend
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2465
|
+
const dockerfile = ["Dockerfile", "backend/Dockerfile"].find(exists);
|
|
2466
|
+
if (hasBackend || hasConfig) {
|
|
2467
|
+
const backend = dockerfile ? {
|
|
2468
|
+
type: "backend",
|
|
2469
|
+
runtime: "custom",
|
|
2470
|
+
dockerfile,
|
|
2471
|
+
context: "."
|
|
2472
|
+
} : {
|
|
2473
|
+
type: "backend",
|
|
2474
|
+
runtime: "managed"
|
|
2475
|
+
};
|
|
2231
2476
|
if (exists("backend/functions")) backend.functions = DEFAULT_FUNCTIONS_DIR;
|
|
2232
2477
|
if (exists("backend/crons")) backend.crons = DEFAULT_CRONS_DIR;
|
|
2233
2478
|
apps.backend = backend;
|
|
2479
|
+
if (!dockerfile && exists("backend/src/index.ts")) console.warn("⚠ backend/src/index.ts exists but this project's backend is managed — it is\n never loaded. Delete it, or run `rebase eject` to make it the entrypoint.");
|
|
2234
2480
|
}
|
|
2235
2481
|
if (exists("frontend")) apps.web = {
|
|
2236
2482
|
type: "static",
|
|
2237
2483
|
root: "frontend",
|
|
2238
2484
|
build: "npm run build --workspace frontend",
|
|
2239
2485
|
output: "frontend/dist",
|
|
2486
|
+
path: "/",
|
|
2240
2487
|
spa: true
|
|
2241
2488
|
};
|
|
2242
2489
|
return {
|
|
2243
|
-
|
|
2490
|
+
rebase: "^1",
|
|
2244
2491
|
apps
|
|
2245
2492
|
};
|
|
2246
2493
|
}
|
|
@@ -2282,7 +2529,7 @@ function writeManifest(projectRoot, manifest) {
|
|
|
2282
2529
|
const filePath = manifestPath(projectRoot);
|
|
2283
2530
|
const ordered = {
|
|
2284
2531
|
$schema: manifest.$schema ?? "https://rebase.pro/schemas/rebase.json",
|
|
2285
|
-
|
|
2532
|
+
rebase: manifest.rebase,
|
|
2286
2533
|
apps: manifest.apps
|
|
2287
2534
|
};
|
|
2288
2535
|
fs.writeFileSync(filePath, `${JSON.stringify(ordered, null, 4)}\n`, "utf8");
|
|
@@ -2301,13 +2548,8 @@ function buildableApps(manifest) {
|
|
|
2301
2548
|
name,
|
|
2302
2549
|
app
|
|
2303
2550
|
}));
|
|
2304
|
-
const rank = (app) =>
|
|
2305
|
-
|
|
2306
|
-
if (app.type === "admin") return 1;
|
|
2307
|
-
if (app.type === "static") return 2;
|
|
2308
|
-
return 3;
|
|
2309
|
-
};
|
|
2310
|
-
return entries.filter(({ app }) => app.type !== "mobile").sort((a, b) => rank(a.app) - rank(b.app));
|
|
2551
|
+
const rank = (app) => app.type === "backend" ? 0 : 1;
|
|
2552
|
+
return entries.sort((a, b) => rank(a.app) - rank(b.app));
|
|
2311
2553
|
}
|
|
2312
2554
|
/**
|
|
2313
2555
|
* Decide whether a project can run on the managed runtime, and say why not.
|
|
@@ -2317,28 +2559,45 @@ function buildableApps(manifest) {
|
|
|
2317
2559
|
* verdict.
|
|
2318
2560
|
*/
|
|
2319
2561
|
function assessManagedCompatibility(manifest) {
|
|
2320
|
-
const reasons = [];
|
|
2321
2562
|
const backend = findBackendApp(manifest);
|
|
2322
|
-
if (!backend) {
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2563
|
+
if (!backend) return {
|
|
2564
|
+
eligible: false,
|
|
2565
|
+
reasons: ["No backend app is declared in this repository. Only the repository that declares the backend selects the runtime."]
|
|
2566
|
+
};
|
|
2567
|
+
if (backend.app.runtime === "custom") return {
|
|
2568
|
+
eligible: false,
|
|
2569
|
+
reasons: [`App "${backend.name}" declares runtime: "custom", so it builds and runs its own image. The managed runtime boots the platform image with your bundle; the custom runtime deploys exactly the same way, from your Dockerfile.`]
|
|
2570
|
+
};
|
|
2328
2571
|
return {
|
|
2329
|
-
eligible:
|
|
2330
|
-
reasons
|
|
2572
|
+
eligible: true,
|
|
2573
|
+
reasons: []
|
|
2331
2574
|
};
|
|
2332
2575
|
}
|
|
2333
|
-
/**
|
|
2334
|
-
|
|
2576
|
+
/**
|
|
2577
|
+
* Resolve a backend app's directories against the conventions it omits.
|
|
2578
|
+
*
|
|
2579
|
+
* `hasCollections` replaces the old `mode: "cms" | "baas"` field. Where the
|
|
2580
|
+
* collections come from was never an independent choice: either they are
|
|
2581
|
+
* declared in code and the bundle ships them, or they are not and the runtime
|
|
2582
|
+
* introspects the live database at boot. Declaring it separately only created
|
|
2583
|
+
* the contradictory state — code-first declared, no collections anywhere.
|
|
2584
|
+
*
|
|
2585
|
+
* `hasConfig` is deliberately a **separate** question. A headless project has no
|
|
2586
|
+
* `config/collections`, but it may still ship a config package — that is where
|
|
2587
|
+
* the `storageAuthorize` hook lives, and storage is not under row-level
|
|
2588
|
+
* security, so without one the server refuses to boot with storage enabled.
|
|
2589
|
+
* Collapsing the two would leave a headless project nowhere to put it.
|
|
2590
|
+
*/
|
|
2591
|
+
function resolveBackendPaths(app, projectRoot) {
|
|
2592
|
+
const config = app.config ?? "config";
|
|
2335
2593
|
return {
|
|
2336
|
-
config
|
|
2594
|
+
config,
|
|
2337
2595
|
functions: app.functions ?? "backend/functions",
|
|
2338
2596
|
crons: app.crons ?? "backend/crons",
|
|
2339
2597
|
schema: app.schema ?? "backend/src/schema.generated.ts",
|
|
2340
2598
|
usersCollection: app.usersCollection ?? "collections/users",
|
|
2341
|
-
|
|
2599
|
+
hasConfig: fs.existsSync(path.join(projectRoot, config)),
|
|
2600
|
+
hasCollections: fs.existsSync(path.join(projectRoot, config, "collections"))
|
|
2342
2601
|
};
|
|
2343
2602
|
}
|
|
2344
2603
|
//#endregion
|
|
@@ -2401,22 +2660,19 @@ function devRuntimeEnv(projectRoot) {
|
|
|
2401
2660
|
REBASE_DEV_CONFIG: "config",
|
|
2402
2661
|
REBASE_DEV_FUNCTIONS: "backend/functions",
|
|
2403
2662
|
REBASE_DEV_CRONS: "backend/crons",
|
|
2404
|
-
REBASE_DEV_SCHEMA: "backend/src/schema.generated.ts"
|
|
2405
|
-
REBASE_DEV_MODE: "cms"
|
|
2663
|
+
REBASE_DEV_SCHEMA: "backend/src/schema.generated.ts"
|
|
2406
2664
|
};
|
|
2407
2665
|
try {
|
|
2408
2666
|
const backend = findBackendApp(loadManifest(projectRoot).manifest);
|
|
2409
2667
|
if (backend) {
|
|
2410
|
-
const paths = resolveBackendPaths(backend.app);
|
|
2668
|
+
const paths = resolveBackendPaths(backend.app, projectRoot);
|
|
2411
2669
|
result.REBASE_DEV_CONFIG = paths.config;
|
|
2412
2670
|
result.REBASE_DEV_FUNCTIONS = paths.functions;
|
|
2413
2671
|
result.REBASE_DEV_CRONS = paths.crons;
|
|
2414
2672
|
result.REBASE_DEV_SCHEMA = paths.schema;
|
|
2415
|
-
result.REBASE_DEV_MODE = paths.mode;
|
|
2416
2673
|
result.REBASE_DEV_APP = backend.name;
|
|
2417
2674
|
}
|
|
2418
2675
|
} catch {}
|
|
2419
|
-
if (!fs.existsSync(path.join(projectRoot, result.REBASE_DEV_CONFIG))) result.REBASE_DEV_MODE = "baas";
|
|
2420
2676
|
return result;
|
|
2421
2677
|
}
|
|
2422
2678
|
/** Well-known filename the backend writes its actual port to. */
|
|
@@ -3024,16 +3280,27 @@ async function writeBundleTsconfig(projectRoot, outDir, includes, skipTypeCheck)
|
|
|
3024
3280
|
* says exactly how to proceed, while a false positive would hand back the crash
|
|
3025
3281
|
* loop this exists to prevent.
|
|
3026
3282
|
*/
|
|
3027
|
-
function detectStorageAuthorize(compiledConfigDir) {
|
|
3283
|
+
function detectStorageAuthorize(compiledConfigDir, depth = 0) {
|
|
3028
3284
|
const indexPath = [
|
|
3029
3285
|
".js",
|
|
3030
3286
|
".mjs",
|
|
3031
3287
|
".ts"
|
|
3032
3288
|
].map((ext) => path.join(compiledConfigDir, `index${ext}`)).find((candidate) => fs.existsSync(candidate));
|
|
3033
3289
|
if (!indexPath) return false;
|
|
3290
|
+
return moduleExportsStorageAuthorize(indexPath, depth);
|
|
3291
|
+
}
|
|
3292
|
+
/**
|
|
3293
|
+
* Whether one compiled module re-exports or defines `storageAuthorize`.
|
|
3294
|
+
*
|
|
3295
|
+
* Split out from {@link detectStorageAuthorize} so a wildcard re-export can be
|
|
3296
|
+
* followed. `export * from "./storage.js"` is an ordinary way to write a config
|
|
3297
|
+
* barrel, and treating it as "no hook" rejected deploys that were correct — with
|
|
3298
|
+
* a message telling the developer to add a hook they had already written.
|
|
3299
|
+
*/
|
|
3300
|
+
function moduleExportsStorageAuthorize(modulePath, depth) {
|
|
3034
3301
|
let source;
|
|
3035
3302
|
try {
|
|
3036
|
-
source = fs.readFileSync(
|
|
3303
|
+
source = fs.readFileSync(modulePath, "utf8");
|
|
3037
3304
|
} catch {
|
|
3038
3305
|
return false;
|
|
3039
3306
|
}
|
|
@@ -3042,9 +3309,48 @@ function detectStorageAuthorize(compiledConfigDir) {
|
|
|
3042
3309
|
const parts = entry.split(/\bas\b/);
|
|
3043
3310
|
return parts[parts.length - 1].trim();
|
|
3044
3311
|
}).includes("storageAuthorize")) return true;
|
|
3312
|
+
if (depth < 3) for (const clause of source.matchAll(/\bexport\s*\*\s*from\s*["']([^"']+)["']/g)) {
|
|
3313
|
+
const specifier = clause[1];
|
|
3314
|
+
if (!specifier.startsWith(".")) continue;
|
|
3315
|
+
const resolved = resolveRelativeModule(path.dirname(modulePath), specifier);
|
|
3316
|
+
if (resolved && moduleExportsStorageAuthorize(resolved, depth + 1)) return true;
|
|
3317
|
+
}
|
|
3045
3318
|
return false;
|
|
3046
3319
|
}
|
|
3047
3320
|
/**
|
|
3321
|
+
* Resolve a relative ESM specifier to a file on disk.
|
|
3322
|
+
*
|
|
3323
|
+
* Compiled output carries explicit `.js` extensions, but the same function reads
|
|
3324
|
+
* TypeScript sources during a source boot, where the specifier may be
|
|
3325
|
+
* extensionless or point at a directory index.
|
|
3326
|
+
*/
|
|
3327
|
+
function resolveRelativeModule(fromDir, specifier) {
|
|
3328
|
+
const base = path.resolve(fromDir, specifier);
|
|
3329
|
+
const candidates = [
|
|
3330
|
+
base,
|
|
3331
|
+
`${base}.js`,
|
|
3332
|
+
`${base}.mjs`,
|
|
3333
|
+
`${base}.ts`,
|
|
3334
|
+
path.join(base, "index.js"),
|
|
3335
|
+
path.join(base, "index.mjs"),
|
|
3336
|
+
path.join(base, "index.ts")
|
|
3337
|
+
];
|
|
3338
|
+
for (const candidate of candidates) try {
|
|
3339
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return candidate;
|
|
3340
|
+
} catch {
|
|
3341
|
+
continue;
|
|
3342
|
+
}
|
|
3343
|
+
if (/\.js$/.test(base)) {
|
|
3344
|
+
const asTs = base.replace(/\.js$/, ".ts");
|
|
3345
|
+
try {
|
|
3346
|
+
if (fs.existsSync(asTs) && fs.statSync(asTs).isFile()) return asTs;
|
|
3347
|
+
} catch {
|
|
3348
|
+
return null;
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
return null;
|
|
3352
|
+
}
|
|
3353
|
+
/**
|
|
3048
3354
|
* Detect native code in the dependency closure.
|
|
3049
3355
|
*
|
|
3050
3356
|
* Walks declared runtime dependencies breadth-first through `node_modules`,
|
|
@@ -3328,11 +3634,10 @@ async function regenerateSchema(projectRoot, configDir, options) {
|
|
|
3328
3634
|
* deployed green, and answered 404 on every one of them, with the file still
|
|
3329
3635
|
* sitting in the repository looking exactly like the server.
|
|
3330
3636
|
*
|
|
3331
|
-
* A project that means to keep its own entrypoint
|
|
3332
|
-
*
|
|
3333
|
-
*
|
|
3334
|
-
*
|
|
3335
|
-
* a mistake.
|
|
3637
|
+
* A project that means to keep its own entrypoint runs `rebase eject`, which
|
|
3638
|
+
* writes the entrypoint, a Dockerfile and a compose file together and flips the
|
|
3639
|
+
* backend to `runtime: "custom"`. The warning names that route rather than
|
|
3640
|
+
* implying the file is a mistake.
|
|
3336
3641
|
*/
|
|
3337
3642
|
function findUnusedServerEntry(projectRoot, functionsDir) {
|
|
3338
3643
|
const found = [path.join("backend", "src", "index.ts"), path.join(path.dirname(functionsDir), "src", "index.ts")].find((candidate) => fs.existsSync(path.join(projectRoot, candidate)));
|
|
@@ -3343,22 +3648,22 @@ function findUnusedServerEntry(projectRoot, functionsDir) {
|
|
|
3343
3648
|
*/
|
|
3344
3649
|
async function buildBundle(options) {
|
|
3345
3650
|
const { projectRoot, app, appName } = options;
|
|
3346
|
-
const paths = resolveBackendPaths(app);
|
|
3651
|
+
const paths = resolveBackendPaths(app, projectRoot);
|
|
3347
3652
|
const outDir = path.resolve(projectRoot, options.outDir ?? "dist-bundle");
|
|
3348
3653
|
const includes = [];
|
|
3349
3654
|
const addIfExists = (relative, pattern) => {
|
|
3350
3655
|
if (fs.existsSync(path.join(projectRoot, relative))) includes.push(pattern);
|
|
3351
3656
|
};
|
|
3352
|
-
if (paths.
|
|
3657
|
+
if (paths.hasConfig) addIfExists(paths.config, `${paths.config}/**/*.ts`);
|
|
3353
3658
|
addIfExists(paths.functions, `${paths.functions}/**/*.ts`);
|
|
3354
3659
|
addIfExists(paths.crons, `${paths.crons}/**/*.ts`);
|
|
3355
3660
|
if (fs.existsSync(path.join(projectRoot, paths.schema))) includes.push(paths.schema);
|
|
3356
3661
|
if (includes.length === 0) throw new Error(`Nothing to build for app "${appName}". Expected a config directory at "${paths.config}" or functions at "${paths.functions}".`);
|
|
3357
|
-
if (paths.
|
|
3662
|
+
if (paths.hasCollections && options.skipSchema !== true) await regenerateSchema(projectRoot, paths.config, options);
|
|
3358
3663
|
const unusedEntry = findUnusedServerEntry(projectRoot, paths.functions);
|
|
3359
3664
|
if (unusedEntry) {
|
|
3360
3665
|
const parts = [
|
|
3361
|
-
...paths.
|
|
3666
|
+
...paths.hasCollections ? [`${paths.config}/`] : [],
|
|
3362
3667
|
`${paths.functions}/`,
|
|
3363
3668
|
"the schema"
|
|
3364
3669
|
];
|
|
@@ -3366,7 +3671,7 @@ async function buildBundle(options) {
|
|
|
3366
3671
|
console.log(chalk.yellow(` ⚠ ${unusedEntry} is not the bundle's entry point — it is not compiled or shipped.`));
|
|
3367
3672
|
console.log(chalk.dim(` The runtime boots the bundle itself and mounts ${compiled}.`));
|
|
3368
3673
|
console.log(chalk.dim(` Routes defined there will not exist once deployed: move them to ${paths.functions}/,`));
|
|
3369
|
-
console.log(chalk.dim(` or
|
|
3674
|
+
console.log(chalk.dim(` or run \`rebase eject\` to make this file the entrypoint and own the image.`));
|
|
3370
3675
|
}
|
|
3371
3676
|
log(options, chalk.dim(` compiling ${includes.length} source group(s) → ${path.relative(projectRoot, outDir)}/`));
|
|
3372
3677
|
cleanOutDir(projectRoot, outDir);
|
|
@@ -3391,14 +3696,17 @@ async function buildBundle(options) {
|
|
|
3391
3696
|
const compiledConfigDir = path.join(outDir, paths.config);
|
|
3392
3697
|
const compiledCollectionsDir = path.join(compiledConfigDir, "collections");
|
|
3393
3698
|
let collections = [];
|
|
3394
|
-
if (paths.
|
|
3699
|
+
if (paths.hasCollections) {
|
|
3395
3700
|
collections = await loadSourceCollections(path.join(projectRoot, paths.config, "collections"));
|
|
3396
|
-
if (collections.length === 0) throw new Error(`No collections were found in ${path.join(paths.config, "collections")}.
|
|
3701
|
+
if (collections.length === 0) throw new Error(`No collections were found in ${path.join(paths.config, "collections")}. Define at least one collection there, or remove the directory to have the runtime introspect collections from the live database instead.`);
|
|
3397
3702
|
if (!fs.existsSync(compiledCollectionsDir)) throw new Error(`Compilation produced no collections directory at ${path.relative(projectRoot, compiledCollectionsDir)}.`);
|
|
3398
3703
|
}
|
|
3399
3704
|
const declared = collectDeclaredDependencies(projectRoot);
|
|
3400
3705
|
const nativeModules = detectNativeDependencies(projectRoot, declared);
|
|
3401
3706
|
const declaresStorageAuthorize = detectStorageAuthorize(path.join(outDir, paths.config));
|
|
3707
|
+
const storageSources = normalizeStorageSources(options.storage, void 0);
|
|
3708
|
+
const collision = findStorageSuffixCollision(storageSources.map((s) => s.key));
|
|
3709
|
+
if (collision) throw new Error(`Storage sources "${collision.a}" and "${collision.b}" in rebase.json both map to the environment variable suffix "${collision.suffix || "(none)"}", so they would read each other's configuration. Rename one of them.`);
|
|
3402
3710
|
const schemaOut = paths.schema.replace(/\.ts$/, ".js");
|
|
3403
3711
|
const relative = (target) => fs.existsSync(path.join(outDir, target)) ? target : void 0;
|
|
3404
3712
|
const manifest = {
|
|
@@ -3408,23 +3716,26 @@ async function buildBundle(options) {
|
|
|
3408
3716
|
builtAgainst: resolveServerVersion(projectRoot),
|
|
3409
3717
|
contract: RUNTIME_CONTRACT_VERSION
|
|
3410
3718
|
},
|
|
3411
|
-
schemaVersion: paths.
|
|
3719
|
+
schemaVersion: paths.hasCollections ? computeSchemaVersion(collections) : "",
|
|
3412
3720
|
app: appName,
|
|
3413
|
-
|
|
3721
|
+
kind: "backend",
|
|
3414
3722
|
entry: {
|
|
3415
|
-
config: paths.
|
|
3416
|
-
collections: paths.
|
|
3723
|
+
config: paths.hasConfig ? relative(paths.config) : void 0,
|
|
3724
|
+
collections: paths.hasCollections ? relative(path.join(paths.config, "collections")) : void 0,
|
|
3417
3725
|
functions: relative(paths.functions),
|
|
3418
3726
|
crons: relative(paths.crons),
|
|
3419
3727
|
schema: relative(schemaOut),
|
|
3420
|
-
usersCollection: paths.
|
|
3728
|
+
usersCollection: paths.hasCollections ? relative(path.join(paths.config, `${paths.usersCollection}.js`)) : void 0
|
|
3421
3729
|
},
|
|
3422
3730
|
collections: collections.map((collection) => collection.slug).filter((slug) => Boolean(slug)).sort(),
|
|
3423
3731
|
hooks: {
|
|
3424
3732
|
native: nativeModules.length > 0,
|
|
3425
3733
|
nativeModules: nativeModules.length > 0 ? nativeModules : void 0
|
|
3426
3734
|
},
|
|
3427
|
-
storage: {
|
|
3735
|
+
storage: {
|
|
3736
|
+
authorize: declaresStorageAuthorize,
|
|
3737
|
+
...storageSources.length > 0 ? { sources: storageSources } : {}
|
|
3738
|
+
},
|
|
3428
3739
|
deps: { declared },
|
|
3429
3740
|
build: {
|
|
3430
3741
|
cli: resolveCliVersion(),
|
|
@@ -3487,11 +3798,12 @@ async function buildBundle(options) {
|
|
|
3487
3798
|
* in one image already, that is exactly what it had.
|
|
3488
3799
|
*/
|
|
3489
3800
|
function foldStaticIntoBundle(options) {
|
|
3490
|
-
const { bundleDir, assetsDir } = options;
|
|
3801
|
+
const { bundleDir, assetsDir, appName, path: basePath, spa } = options;
|
|
3491
3802
|
const manifestPath = path.join(bundleDir, "manifest.json");
|
|
3492
3803
|
if (!fs.existsSync(manifestPath)) throw new Error(`No manifest at ${manifestPath} — build the backend bundle first.`);
|
|
3493
3804
|
if (!fs.existsSync(assetsDir)) throw new Error(`No built assets at ${assetsDir}.`);
|
|
3494
|
-
const
|
|
3805
|
+
const dir = path.posix.join("static", appName);
|
|
3806
|
+
const staticOut = path.join(bundleDir, "static", appName);
|
|
3495
3807
|
fs.rmSync(staticOut, {
|
|
3496
3808
|
recursive: true,
|
|
3497
3809
|
force: true
|
|
@@ -3499,21 +3811,30 @@ function foldStaticIntoBundle(options) {
|
|
|
3499
3811
|
fs.mkdirSync(staticOut, { recursive: true });
|
|
3500
3812
|
fs.cpSync(assetsDir, staticOut, { recursive: true });
|
|
3501
3813
|
let fileCount = 0;
|
|
3502
|
-
const count = (
|
|
3503
|
-
for (const entry of fs.readdirSync(
|
|
3814
|
+
const count = (target) => {
|
|
3815
|
+
for (const entry of fs.readdirSync(target, { withFileTypes: true })) if (entry.isDirectory()) count(path.join(target, entry.name));
|
|
3504
3816
|
else fileCount++;
|
|
3505
3817
|
};
|
|
3506
3818
|
count(staticOut);
|
|
3507
3819
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
3820
|
+
const existing = (manifest.entry?.static ?? []).filter((entry) => entry.dir !== dir);
|
|
3508
3821
|
manifest.entry = {
|
|
3509
3822
|
...manifest.entry,
|
|
3510
|
-
static:
|
|
3823
|
+
static: [...existing, {
|
|
3824
|
+
path: basePath,
|
|
3825
|
+
dir,
|
|
3826
|
+
spa
|
|
3827
|
+
}]
|
|
3511
3828
|
};
|
|
3512
3829
|
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
3513
|
-
return {
|
|
3830
|
+
return {
|
|
3831
|
+
fileCount,
|
|
3832
|
+
dir
|
|
3833
|
+
};
|
|
3514
3834
|
}
|
|
3515
3835
|
function buildStaticBundle(options) {
|
|
3516
3836
|
const { projectRoot, appName, assetsDir, outDir, runtimeRange } = options;
|
|
3837
|
+
const basePath = options.path ?? "/";
|
|
3517
3838
|
cleanOutDir(projectRoot, outDir);
|
|
3518
3839
|
const staticOut = path.join(outDir, "static");
|
|
3519
3840
|
fs.mkdirSync(staticOut, { recursive: true });
|
|
@@ -3533,8 +3854,12 @@ function buildStaticBundle(options) {
|
|
|
3533
3854
|
},
|
|
3534
3855
|
schemaVersion: "",
|
|
3535
3856
|
app: appName,
|
|
3536
|
-
|
|
3537
|
-
entry: { static:
|
|
3857
|
+
kind: "static",
|
|
3858
|
+
entry: { static: [{
|
|
3859
|
+
path: basePath,
|
|
3860
|
+
dir: "static",
|
|
3861
|
+
spa: options.spa ?? true
|
|
3862
|
+
}] },
|
|
3538
3863
|
hooks: { native: false },
|
|
3539
3864
|
deps: { declared: {} },
|
|
3540
3865
|
build: {
|
|
@@ -3636,7 +3961,7 @@ function resolveCliVersion() {
|
|
|
3636
3961
|
//#endregion
|
|
3637
3962
|
//#region src/fold-static.ts
|
|
3638
3963
|
/**
|
|
3639
|
-
* Folding a project's
|
|
3964
|
+
* Folding a project's static apps into its backend bundle.
|
|
3640
3965
|
*
|
|
3641
3966
|
* Shared by `rebase build` and `rebase cloud deploy` deliberately. It lived in
|
|
3642
3967
|
* the build *command* first, and `deploy` rebuilds the bundle itself — so a
|
|
@@ -3645,34 +3970,77 @@ function resolveCliVersion() {
|
|
|
3645
3970
|
* folding had never been written. Two callers building the same artefact must
|
|
3646
3971
|
* share the step that completes it.
|
|
3647
3972
|
*
|
|
3648
|
-
* Why fold at all: `bootFromBundle`
|
|
3973
|
+
* Why fold at all: `bootFromBundle` serves static apps from `entry.static`
|
|
3649
3974
|
* behind `REBASE_SERVE_STATIC` (default on). A managed tenant runs one pod, so
|
|
3650
|
-
* putting the built
|
|
3651
|
-
* already had — site at `/`, API at `/api` — which is the
|
|
3652
|
-
* for calling the managed runtime a drop-in replacement.
|
|
3975
|
+
* putting the built assets in the bundle gives it the shape a custom container
|
|
3976
|
+
* already had — site at `/`, admin at `/admin`, API at `/api` — which is the
|
|
3977
|
+
* only honest baseline for calling the managed runtime a drop-in replacement.
|
|
3978
|
+
*
|
|
3979
|
+
* **Every** static app is folded, each at its declared path. Folding used to
|
|
3980
|
+
* pick exactly one and refuse when it found two, which meant a project with a
|
|
3981
|
+
* site and an admin panel deployed with neither.
|
|
3653
3982
|
*/
|
|
3654
3983
|
/**
|
|
3655
|
-
*
|
|
3984
|
+
* Every static app in the manifest, in mount order.
|
|
3656
3985
|
*
|
|
3657
|
-
*
|
|
3658
|
-
*
|
|
3659
|
-
*
|
|
3660
|
-
* filesystem.
|
|
3986
|
+
* Longest path first, so the `/`-rooted app is registered last — its catch-all
|
|
3987
|
+
* would otherwise claim its siblings' URLs. Pure, so the ordering is testable
|
|
3988
|
+
* without a filesystem.
|
|
3661
3989
|
*/
|
|
3662
|
-
function
|
|
3663
|
-
const
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3990
|
+
function foldableApps(manifest) {
|
|
3991
|
+
const apps = [];
|
|
3992
|
+
const skipped = [];
|
|
3993
|
+
for (const [name, app] of Object.entries(manifest.apps ?? {})) {
|
|
3994
|
+
if (app?.type !== "static") continue;
|
|
3995
|
+
if (!app.output) {
|
|
3996
|
+
skipped.push({
|
|
3997
|
+
name,
|
|
3998
|
+
reason: `"${name}" declares no output directory — not folded in.`
|
|
3999
|
+
});
|
|
4000
|
+
continue;
|
|
4001
|
+
}
|
|
4002
|
+
apps.push({
|
|
4003
|
+
name,
|
|
4004
|
+
build: app.build,
|
|
4005
|
+
output: app.output,
|
|
4006
|
+
path: app.path ?? "/",
|
|
4007
|
+
spa: app.spa ?? true
|
|
4008
|
+
});
|
|
4009
|
+
}
|
|
4010
|
+
apps.sort((a, b) => b.path.length - a.path.length);
|
|
4011
|
+
return {
|
|
4012
|
+
apps,
|
|
4013
|
+
skipped
|
|
4014
|
+
};
|
|
4015
|
+
}
|
|
4016
|
+
/**
|
|
4017
|
+
* Assert a built app's assets are actually rooted at the path it is served from.
|
|
4018
|
+
*
|
|
4019
|
+
* An app mounted at `/admin` but built with Vite's default `base: "/"` emits
|
|
4020
|
+
* `<script src="/assets/index-a1b2.js">`. The server serves `index.html` fine
|
|
4021
|
+
* and 404s every asset: a blank page, no server error, nothing in the logs. It
|
|
4022
|
+
* is the single most expensive silent failure in this design, so it is a build
|
|
4023
|
+
* error rather than a runtime surprise.
|
|
4024
|
+
*
|
|
4025
|
+
* Only `<script src>` and `<link href>` are inspected — those are what a bundler
|
|
4026
|
+
* rewrites through `base`. Author-written anchors and canonical URLs are not
|
|
4027
|
+
* evidence of a misbuild.
|
|
4028
|
+
*/
|
|
4029
|
+
function assertBuiltForPath(indexHtml, basePath, appName) {
|
|
4030
|
+
if (basePath === "/") return;
|
|
4031
|
+
const offenders = [];
|
|
4032
|
+
for (const match of indexHtml.matchAll(/<(?:script|link)\b[^>]*?\b(?:src|href)\s*=\s*["']([^"']+)["']/gi)) {
|
|
4033
|
+
const ref = match[1];
|
|
4034
|
+
if (!ref.startsWith("/")) continue;
|
|
4035
|
+
if (ref === `${basePath}` || ref.startsWith(`${basePath}/`)) continue;
|
|
4036
|
+
offenders.push(ref);
|
|
4037
|
+
}
|
|
4038
|
+
if (offenders.length === 0) return;
|
|
4039
|
+
throw new Error(`"${appName}" is declared at ${basePath} but its build emitted assets rooted at /.\n index.html references: ${offenders.slice(0, 3).join(", ")}\n The app would load a blank page. Set \`base\` from REBASE_APP_BASE in its
|
|
4040
|
+
build config — see docs/apps-and-runtimes.md §4.2.`);
|
|
3673
4041
|
}
|
|
3674
4042
|
/**
|
|
3675
|
-
* Build the project's
|
|
4043
|
+
* Build the project's static apps and fold them into the backend bundle.
|
|
3676
4044
|
*
|
|
3677
4045
|
* Throws rather than exiting, so the caller decides whether a missing frontend
|
|
3678
4046
|
* should fail its command — a `build` may reasonably want to stop, and so should
|
|
@@ -3681,27 +4049,39 @@ function selectFoldableApp(manifest) {
|
|
|
3681
4049
|
async function foldFrontendIntoBundle(options) {
|
|
3682
4050
|
const { projectRoot, manifest, bundleDir, skipBuild } = options;
|
|
3683
4051
|
const log = options.log ?? ((m) => console.log(m));
|
|
3684
|
-
const {
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
4052
|
+
const { apps, skipped } = foldableApps(manifest);
|
|
4053
|
+
for (const { reason } of skipped) log(chalk.yellow(` ⚠ ${reason}`));
|
|
4054
|
+
if (apps.length === 0) return [];
|
|
4055
|
+
const outcomes = [];
|
|
4056
|
+
for (const app of apps) {
|
|
4057
|
+
if (app.build && !skipBuild) await execa(app.build, {
|
|
4058
|
+
cwd: projectRoot,
|
|
4059
|
+
stdio: "inherit",
|
|
4060
|
+
shell: true,
|
|
4061
|
+
env: {
|
|
4062
|
+
REBASE_APP_PATH: app.path,
|
|
4063
|
+
REBASE_APP_BASE: app.path === "/" ? "/" : `${app.path}/`,
|
|
4064
|
+
REBASE_APP_NAME: app.name
|
|
4065
|
+
}
|
|
4066
|
+
});
|
|
4067
|
+
const assetsDir = path.join(projectRoot, app.output);
|
|
4068
|
+
if (!fs.existsSync(assetsDir)) throw new Error(`"${app.name}" declared output "${app.output}" does not exist after building — the bundle would ship without a frontend.`);
|
|
4069
|
+
const indexHtml = path.join(assetsDir, "index.html");
|
|
4070
|
+
if (fs.existsSync(indexHtml)) assertBuiltForPath(fs.readFileSync(indexHtml, "utf8"), app.path, app.name);
|
|
4071
|
+
const { fileCount } = foldStaticIntoBundle({
|
|
4072
|
+
bundleDir,
|
|
4073
|
+
assetsDir,
|
|
4074
|
+
appName: app.name,
|
|
4075
|
+
path: app.path,
|
|
4076
|
+
spa: app.spa
|
|
4077
|
+
});
|
|
4078
|
+
outcomes.push({
|
|
4079
|
+
appName: app.name,
|
|
4080
|
+
fileCount,
|
|
4081
|
+
path: app.path
|
|
4082
|
+
});
|
|
3688
4083
|
}
|
|
3689
|
-
|
|
3690
|
-
if (app.build && !skipBuild) await execa(app.build, {
|
|
3691
|
-
cwd: projectRoot,
|
|
3692
|
-
stdio: "inherit",
|
|
3693
|
-
shell: true
|
|
3694
|
-
});
|
|
3695
|
-
const assetsDir = path.join(projectRoot, app.output);
|
|
3696
|
-
if (!fs.existsSync(assetsDir)) throw new Error(`"${app.name}" declared output "${app.output}" does not exist after building — the bundle would ship without a frontend.`);
|
|
3697
|
-
const { fileCount } = foldStaticIntoBundle({
|
|
3698
|
-
bundleDir,
|
|
3699
|
-
assetsDir
|
|
3700
|
-
});
|
|
3701
|
-
return {
|
|
3702
|
-
appName: app.name,
|
|
3703
|
-
fileCount
|
|
3704
|
-
};
|
|
4084
|
+
return outcomes;
|
|
3705
4085
|
}
|
|
3706
4086
|
//#endregion
|
|
3707
4087
|
//#region src/commands/build.ts
|
|
@@ -3719,7 +4099,7 @@ async function foldFrontendIntoBundle(options) {
|
|
|
3719
4099
|
* entrypoint, falls back to the previous behaviour: run every workspace's own
|
|
3720
4100
|
* `build` script. Nothing that built before stops building.
|
|
3721
4101
|
*/
|
|
3722
|
-
function printHelp$
|
|
4102
|
+
function printHelp$4() {
|
|
3723
4103
|
console.log(`
|
|
3724
4104
|
${chalk.bold("rebase build")} — build the apps declared in rebase.json
|
|
3725
4105
|
|
|
@@ -3754,7 +4134,7 @@ async function buildCommand(rawArgs = []) {
|
|
|
3754
4134
|
permissive: true
|
|
3755
4135
|
});
|
|
3756
4136
|
if (args["--help"]) {
|
|
3757
|
-
printHelp$
|
|
4137
|
+
printHelp$4();
|
|
3758
4138
|
return;
|
|
3759
4139
|
}
|
|
3760
4140
|
const projectRoot = requireProjectRoot();
|
|
@@ -3798,13 +4178,20 @@ async function buildCommand(rawArgs = []) {
|
|
|
3798
4178
|
console.log(`${chalk.bold("Rebase")} — building ${targets.length} app(s)\n`);
|
|
3799
4179
|
for (const { name, app } of targets) {
|
|
3800
4180
|
console.log(chalk.cyan(`▸ ${name}`) + chalk.dim(` (${app.type})`));
|
|
4181
|
+
if (app.type === "backend" && app.runtime === "custom") {
|
|
4182
|
+
console.log(chalk.dim(" custom runtime — this project builds its own image, not a bundle"));
|
|
4183
|
+
console.log(chalk.dim(` ${chalk.cyan(`npm run build --workspace ${name}`)} then ${chalk.cyan(`docker build -f ${app.dockerfile ?? "Dockerfile"} .`)}`));
|
|
4184
|
+
console.log("");
|
|
4185
|
+
continue;
|
|
4186
|
+
}
|
|
3801
4187
|
if (app.type === "backend") {
|
|
3802
4188
|
const result = await buildBundle({
|
|
3803
4189
|
projectRoot,
|
|
3804
4190
|
appName: name,
|
|
3805
4191
|
app,
|
|
3806
4192
|
outDir: args["--out"],
|
|
3807
|
-
runtimeRange: manifest.
|
|
4193
|
+
runtimeRange: manifest.rebase,
|
|
4194
|
+
storage: manifest.storage,
|
|
3808
4195
|
skipTypeCheck: args["--skip-type-check"],
|
|
3809
4196
|
skipSchema: args["--skip-schema"]
|
|
3810
4197
|
});
|
|
@@ -3827,28 +4214,24 @@ async function buildCommand(rawArgs = []) {
|
|
|
3827
4214
|
console.error(chalk.red(` ✗ ${err instanceof Error ? err.message : String(err)}`));
|
|
3828
4215
|
process.exit(1);
|
|
3829
4216
|
});
|
|
3830
|
-
|
|
4217
|
+
for (const outcome of folded ?? []) console.log(chalk.green(` ✓ ${outcome.appName} folded in`) + chalk.dim(` (${outcome.fileCount} file(s) → served at ${outcome.path})`));
|
|
3831
4218
|
}
|
|
3832
|
-
} else if (app.type === "static"
|
|
3833
|
-
else if (app.type === "custom") console.log(chalk.dim(" custom container — built at deploy time from its Dockerfile"));
|
|
4219
|
+
} else if (app.type === "static") await buildAssetApp(projectRoot, name, app, manifest.rebase, args["--out"]);
|
|
3834
4220
|
console.log("");
|
|
3835
4221
|
}
|
|
3836
4222
|
console.log(chalk.green("✓ Build complete."));
|
|
3837
4223
|
}
|
|
3838
4224
|
/**
|
|
3839
|
-
* Build a static
|
|
4225
|
+
* Build a static app and package it into a static bundle.
|
|
3840
4226
|
*
|
|
3841
4227
|
* Runs the app's own build command, checks it produced the declared output, then
|
|
3842
|
-
* packages that output into a `static`-
|
|
4228
|
+
* packages that output into a `static`-kind bundle — the same deployable shape as
|
|
3843
4229
|
* a backend bundle, so a frontend or admin app deploys through the identical
|
|
3844
4230
|
* path and runs on the identical image, just serving files instead of an API.
|
|
3845
4231
|
*/
|
|
3846
4232
|
async function buildAssetApp(projectRoot, name, app, runtimeRange, outOverride) {
|
|
3847
4233
|
const asset = app;
|
|
3848
|
-
|
|
3849
|
-
console.log(chalk.dim(" hosted admin panel — nothing to build"));
|
|
3850
|
-
return;
|
|
3851
|
-
}
|
|
4234
|
+
const basePath = asset.path ?? "/";
|
|
3852
4235
|
if (!asset.build) {
|
|
3853
4236
|
console.log(chalk.dim(" no build command declared — skipping"));
|
|
3854
4237
|
return;
|
|
@@ -3857,7 +4240,12 @@ async function buildAssetApp(projectRoot, name, app, runtimeRange, outOverride)
|
|
|
3857
4240
|
await execa(asset.build, {
|
|
3858
4241
|
cwd: projectRoot,
|
|
3859
4242
|
stdio: "inherit",
|
|
3860
|
-
shell: true
|
|
4243
|
+
shell: true,
|
|
4244
|
+
env: {
|
|
4245
|
+
REBASE_APP_PATH: basePath,
|
|
4246
|
+
REBASE_APP_BASE: basePath === "/" ? "/" : `${basePath}/`,
|
|
4247
|
+
REBASE_APP_NAME: name
|
|
4248
|
+
}
|
|
3861
4249
|
});
|
|
3862
4250
|
} catch {
|
|
3863
4251
|
console.error(chalk.red(` ✗ build command failed for "${name}"`));
|
|
@@ -3872,15 +4260,24 @@ async function buildAssetApp(projectRoot, name, app, runtimeRange, outOverride)
|
|
|
3872
4260
|
console.error(chalk.red(` ✗ declared output "${asset.output}" does not exist after building`));
|
|
3873
4261
|
process.exit(1);
|
|
3874
4262
|
}
|
|
4263
|
+
const indexHtml = path.join(outputPath, "index.html");
|
|
4264
|
+
if (fs.existsSync(indexHtml)) try {
|
|
4265
|
+
assertBuiltForPath(fs.readFileSync(indexHtml, "utf8"), basePath, name);
|
|
4266
|
+
} catch (err) {
|
|
4267
|
+
console.error(chalk.red(` ✗ ${err instanceof Error ? err.message : String(err)}`));
|
|
4268
|
+
process.exit(1);
|
|
4269
|
+
}
|
|
3875
4270
|
const result = buildStaticBundle({
|
|
3876
4271
|
projectRoot,
|
|
3877
4272
|
appName: name,
|
|
3878
4273
|
assetsDir: outputPath,
|
|
3879
4274
|
outDir: outOverride ? path.resolve(process.cwd(), outOverride) : path.join(projectRoot, `dist-bundle-${name}`),
|
|
3880
|
-
runtimeRange
|
|
4275
|
+
runtimeRange,
|
|
4276
|
+
path: basePath,
|
|
4277
|
+
spa: asset.spa ?? true
|
|
3881
4278
|
});
|
|
3882
4279
|
const rel = path.relative(projectRoot, result.outDir);
|
|
3883
|
-
console.log(chalk.green(` ✓ static bundle → ${rel}/`) + chalk.dim(` (${result.fileCount} file(s))`));
|
|
4280
|
+
console.log(chalk.green(` ✓ static bundle → ${rel}/`) + chalk.dim(` (${result.fileCount} file(s) → served at ${basePath})`));
|
|
3884
4281
|
}
|
|
3885
4282
|
/** The pre-manifest behaviour: build every workspace package. */
|
|
3886
4283
|
async function runWorkspaceBuilds(projectRoot) {
|
|
@@ -3898,6 +4295,234 @@ async function runWorkspaceBuilds(projectRoot) {
|
|
|
3898
4295
|
}
|
|
3899
4296
|
}
|
|
3900
4297
|
//#endregion
|
|
4298
|
+
//#region src/commands/eject.ts
|
|
4299
|
+
/**
|
|
4300
|
+
* CLI command: rebase eject
|
|
4301
|
+
*
|
|
4302
|
+
* The supported route from the managed runtime to a custom one.
|
|
4303
|
+
*
|
|
4304
|
+
* Without it, `runtime: "custom"` is a mode a user can only reach by
|
|
4305
|
+
* hand-writing an entrypoint they have never seen. The template used to solve
|
|
4306
|
+
* that by scaffolding `backend/src/index.ts` into every project — ~190 lines
|
|
4307
|
+
* configuring CORS, auth, cookies, storage and history, which the managed
|
|
4308
|
+
* runtime never loads. It was the most important-looking file in a new project
|
|
4309
|
+
* and editing it did nothing.
|
|
4310
|
+
*
|
|
4311
|
+
* So the file moved here. A managed project does not carry it; a project that
|
|
4312
|
+
* asks for it gets it together with the Dockerfile and the manifest change that
|
|
4313
|
+
* make it actually run.
|
|
4314
|
+
*
|
|
4315
|
+
* There is deliberately no `rebase uneject`. Going back is deleting two files
|
|
4316
|
+
* and editing one line, and a command that silently discarded a user's server
|
|
4317
|
+
* code would be worse than its absence.
|
|
4318
|
+
*/
|
|
4319
|
+
var __dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
4320
|
+
/** Walk up to the package root, which holds `templates/`. */
|
|
4321
|
+
function findCliRoot(from) {
|
|
4322
|
+
const root = path.parse(from).root;
|
|
4323
|
+
let dir = from;
|
|
4324
|
+
while (dir && dir !== root) {
|
|
4325
|
+
if (fs.existsSync(path.join(dir, "templates", "eject"))) return dir;
|
|
4326
|
+
dir = path.dirname(dir);
|
|
4327
|
+
}
|
|
4328
|
+
return null;
|
|
4329
|
+
}
|
|
4330
|
+
/** Files the eject payload contributes, as `<source> → <destination>`. */
|
|
4331
|
+
var PAYLOAD = [
|
|
4332
|
+
{
|
|
4333
|
+
from: "backend/src/index.ts",
|
|
4334
|
+
to: "backend/src/index.ts",
|
|
4335
|
+
overwrite: true
|
|
4336
|
+
},
|
|
4337
|
+
{
|
|
4338
|
+
from: "backend/src/env.ts",
|
|
4339
|
+
to: "backend/src/env.ts",
|
|
4340
|
+
overwrite: true
|
|
4341
|
+
},
|
|
4342
|
+
{
|
|
4343
|
+
from: "Dockerfile",
|
|
4344
|
+
to: "Dockerfile",
|
|
4345
|
+
overwrite: false
|
|
4346
|
+
},
|
|
4347
|
+
{
|
|
4348
|
+
from: "docker-compose.custom.yml",
|
|
4349
|
+
to: "docker-compose.custom.yml",
|
|
4350
|
+
overwrite: false
|
|
4351
|
+
}
|
|
4352
|
+
];
|
|
4353
|
+
/**
|
|
4354
|
+
* The project's name, for the `{{PROJECT_NAME}}` the payload carries.
|
|
4355
|
+
*
|
|
4356
|
+
* Falls back to the directory name — a compose project name is cosmetic, and a
|
|
4357
|
+
* missing or unreadable package.json is not a reason to refuse to eject.
|
|
4358
|
+
*/
|
|
4359
|
+
function projectNameOf(projectRoot) {
|
|
4360
|
+
try {
|
|
4361
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf8"));
|
|
4362
|
+
if (typeof pkg.name === "string" && pkg.name.trim()) return pkg.name.trim();
|
|
4363
|
+
} catch {}
|
|
4364
|
+
return path.basename(projectRoot);
|
|
4365
|
+
}
|
|
4366
|
+
function printHelp$3() {
|
|
4367
|
+
console.log(`
|
|
4368
|
+
${chalk.bold("rebase eject")} — take ownership of the server process
|
|
4369
|
+
|
|
4370
|
+
Writes the backend entrypoint and a Dockerfile into this project, and flips its
|
|
4371
|
+
backend to ${chalk.cyan("runtime: \"custom\"")}. From then on this repository builds its own
|
|
4372
|
+
image: platform runtime upgrades no longer reach it, and CORS, auth wiring,
|
|
4373
|
+
storage and shutdown become yours to configure.
|
|
4374
|
+
|
|
4375
|
+
${chalk.bold("Usage")}
|
|
4376
|
+
rebase eject [app]
|
|
4377
|
+
|
|
4378
|
+
${chalk.bold("Options")}
|
|
4379
|
+
--dry-run List what would change, and change nothing
|
|
4380
|
+
-h, --help Show this help
|
|
4381
|
+
`.trim());
|
|
4382
|
+
}
|
|
4383
|
+
async function ejectCommand(rawArgs = []) {
|
|
4384
|
+
const args = arg({
|
|
4385
|
+
"--dry-run": Boolean,
|
|
4386
|
+
"--help": Boolean,
|
|
4387
|
+
"-h": "--help"
|
|
4388
|
+
}, {
|
|
4389
|
+
argv: rawArgs.slice(2),
|
|
4390
|
+
permissive: true
|
|
4391
|
+
});
|
|
4392
|
+
if (args["--help"]) {
|
|
4393
|
+
printHelp$3();
|
|
4394
|
+
return;
|
|
4395
|
+
}
|
|
4396
|
+
const projectRoot = requireProjectRoot();
|
|
4397
|
+
const dryRun = Boolean(args["--dry-run"]);
|
|
4398
|
+
const requested = args._.slice(1).find((value) => !value.startsWith("-"));
|
|
4399
|
+
let loaded;
|
|
4400
|
+
try {
|
|
4401
|
+
loaded = loadManifest(projectRoot);
|
|
4402
|
+
} catch (err) {
|
|
4403
|
+
if (err instanceof ManifestError) {
|
|
4404
|
+
console.error(chalk.red(`✗ ${err.message}`));
|
|
4405
|
+
for (const issue of err.issues) console.error(chalk.dim(` ${issue.path}: ${issue.message}`));
|
|
4406
|
+
process.exit(1);
|
|
4407
|
+
}
|
|
4408
|
+
throw err;
|
|
4409
|
+
}
|
|
4410
|
+
const { manifest } = loaded;
|
|
4411
|
+
let appName;
|
|
4412
|
+
let app;
|
|
4413
|
+
if (requested) {
|
|
4414
|
+
const declared = manifest.apps[requested];
|
|
4415
|
+
if (!declared) {
|
|
4416
|
+
console.error(chalk.red(`✗ No app named "${requested}" in rebase.json.`));
|
|
4417
|
+
console.error(chalk.dim(` Declared: ${Object.keys(manifest.apps).join(", ") || "(none)"}`));
|
|
4418
|
+
process.exit(1);
|
|
4419
|
+
}
|
|
4420
|
+
if (declared.type !== "backend") {
|
|
4421
|
+
console.error(chalk.red(`✗ "${requested}" is a ${declared.type} app — only a backend can be ejected.`));
|
|
4422
|
+
process.exit(1);
|
|
4423
|
+
}
|
|
4424
|
+
appName = requested;
|
|
4425
|
+
app = declared;
|
|
4426
|
+
} else {
|
|
4427
|
+
const backend = findBackendApp(manifest);
|
|
4428
|
+
if (!backend) {
|
|
4429
|
+
console.error(chalk.red("✗ This repository declares no backend app."));
|
|
4430
|
+
console.error(chalk.dim(" Only the repository that declares the backend chooses its runtime."));
|
|
4431
|
+
process.exit(1);
|
|
4432
|
+
}
|
|
4433
|
+
appName = backend.name;
|
|
4434
|
+
app = backend.app;
|
|
4435
|
+
}
|
|
4436
|
+
if (app.runtime === "custom") {
|
|
4437
|
+
console.error(chalk.red(`✗ "${appName}" is already ejected — it declares runtime: "custom".`));
|
|
4438
|
+
console.error(chalk.dim(` Its entrypoint is ${app.dockerfile ?? "Dockerfile"} and backend/src/index.ts.`));
|
|
4439
|
+
process.exit(1);
|
|
4440
|
+
}
|
|
4441
|
+
const cliRoot = findCliRoot(__dirname$1);
|
|
4442
|
+
if (!cliRoot) {
|
|
4443
|
+
console.error(chalk.red("✗ Could not locate the eject templates. Reinstall @rebasepro/cli."));
|
|
4444
|
+
process.exit(1);
|
|
4445
|
+
}
|
|
4446
|
+
const payloadDir = path.join(cliRoot, "templates", "eject");
|
|
4447
|
+
const planned = [];
|
|
4448
|
+
for (const file of PAYLOAD) {
|
|
4449
|
+
const source = path.join(payloadDir, file.from);
|
|
4450
|
+
if (!fs.existsSync(source)) {
|
|
4451
|
+
console.error(chalk.red(`✗ The eject template is missing ${file.from}. Reinstall @rebasepro/cli.`));
|
|
4452
|
+
process.exit(1);
|
|
4453
|
+
}
|
|
4454
|
+
const exists = fs.existsSync(path.join(projectRoot, file.to));
|
|
4455
|
+
planned.push({
|
|
4456
|
+
to: file.to,
|
|
4457
|
+
action: exists && !file.overwrite ? "keep" : "write"
|
|
4458
|
+
});
|
|
4459
|
+
}
|
|
4460
|
+
if (dryRun) {
|
|
4461
|
+
console.log(chalk.bold(`Would eject "${appName}" to a custom runtime:`));
|
|
4462
|
+
console.log("");
|
|
4463
|
+
for (const item of planned) console.log(item.action === "write" ? ` ${chalk.green("write")} ${item.to}` : ` ${chalk.dim("keep")} ${item.to} ${chalk.dim("(already exists)")}`);
|
|
4464
|
+
console.log(` ${chalk.green("write")} rebase.json ${chalk.dim("(runtime: \"custom\")")}`);
|
|
4465
|
+
console.log("");
|
|
4466
|
+
console.log(chalk.dim("Nothing was changed."));
|
|
4467
|
+
return;
|
|
4468
|
+
}
|
|
4469
|
+
const projectName = projectNameOf(projectRoot);
|
|
4470
|
+
for (const [index, file] of PAYLOAD.entries()) {
|
|
4471
|
+
if (planned[index].action === "keep") continue;
|
|
4472
|
+
const destination = path.join(projectRoot, file.to);
|
|
4473
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
4474
|
+
const contents = fs.readFileSync(path.join(payloadDir, file.from), "utf8").replace(/\{\{PROJECT_NAME\}\}/g, projectName);
|
|
4475
|
+
fs.writeFileSync(destination, contents, "utf8");
|
|
4476
|
+
}
|
|
4477
|
+
const dockerfile = app.dockerfile ?? "Dockerfile";
|
|
4478
|
+
manifest.apps[appName] = {
|
|
4479
|
+
...app,
|
|
4480
|
+
runtime: "custom",
|
|
4481
|
+
dockerfile,
|
|
4482
|
+
port: app.port ?? 8080
|
|
4483
|
+
};
|
|
4484
|
+
writeManifest(projectRoot, manifest);
|
|
4485
|
+
restoreBackendScripts(projectRoot);
|
|
4486
|
+
console.log("");
|
|
4487
|
+
console.log(chalk.green(`✓ Ejected "${appName}" to a custom runtime.`));
|
|
4488
|
+
console.log("");
|
|
4489
|
+
console.log(` ${chalk.cyan("backend/src/index.ts".padEnd(26))} your entrypoint — the runtime no longer boots the bundle`);
|
|
4490
|
+
console.log(` ${chalk.cyan("backend/src/env.ts".padEnd(26))} the environment it reads`);
|
|
4491
|
+
console.log(` ${chalk.cyan(dockerfile.padEnd(26))} your image`);
|
|
4492
|
+
console.log(` ${chalk.cyan("docker-compose.custom.yml".padEnd(26))} runs it`);
|
|
4493
|
+
console.log(` ${chalk.cyan("rebase.json".padEnd(26))} runtime: custom`);
|
|
4494
|
+
console.log("");
|
|
4495
|
+
console.log(chalk.yellow(" You now own CORS, auth wiring, storage and shutdown. Platform runtime"));
|
|
4496
|
+
console.log(chalk.yellow(" upgrades no longer reach this project."));
|
|
4497
|
+
console.log("");
|
|
4498
|
+
console.log(chalk.dim(` ${chalk.cyan("docker compose -f docker-compose.custom.yml up --build")}`));
|
|
4499
|
+
console.log(chalk.dim(" docker-compose.yml is untouched — it still runs the managed shape if you go back."));
|
|
4500
|
+
console.log("");
|
|
4501
|
+
}
|
|
4502
|
+
/**
|
|
4503
|
+
* Point the backend workspace's scripts at the entrypoint that now exists.
|
|
4504
|
+
*
|
|
4505
|
+
* A managed project's backend package deliberately declares no `main` and no
|
|
4506
|
+
* `start`: there is no entrypoint to name. Ejecting creates one.
|
|
4507
|
+
*/
|
|
4508
|
+
function restoreBackendScripts(projectRoot) {
|
|
4509
|
+
const packagePath = path.join(projectRoot, "backend", "package.json");
|
|
4510
|
+
if (!fs.existsSync(packagePath)) return;
|
|
4511
|
+
let parsed;
|
|
4512
|
+
try {
|
|
4513
|
+
parsed = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
|
4514
|
+
} catch {
|
|
4515
|
+
console.log(chalk.yellow(" ⚠ backend/package.json is not valid JSON — its scripts were left alone."));
|
|
4516
|
+
return;
|
|
4517
|
+
}
|
|
4518
|
+
const scripts = parsed.scripts ?? {};
|
|
4519
|
+
parsed.main ??= "src/index.ts";
|
|
4520
|
+
scripts.dev ??= "tsx watch --include=\"../config/**/*\" --include=\"./functions/**/*\" src/index.ts";
|
|
4521
|
+
scripts.start ??= "node dist/backend/src/index.js";
|
|
4522
|
+
parsed.scripts = scripts;
|
|
4523
|
+
fs.writeFileSync(packagePath, `${JSON.stringify(parsed, null, 4)}\n`, "utf8");
|
|
4524
|
+
}
|
|
4525
|
+
//#endregion
|
|
3901
4526
|
//#region src/commands/start.ts
|
|
3902
4527
|
/**
|
|
3903
4528
|
* CLI command: rebase start
|
|
@@ -5345,7 +5970,7 @@ function declaredAppsFrom(manifest) {
|
|
|
5345
5970
|
if (!apps || typeof apps !== "object") return [];
|
|
5346
5971
|
return Object.entries(apps).filter(([name]) => name.trim().length > 0).map(([name, value]) => ({
|
|
5347
5972
|
name,
|
|
5348
|
-
type:
|
|
5973
|
+
type: value?.type === "backend" ? "backend" : "static"
|
|
5349
5974
|
}));
|
|
5350
5975
|
}
|
|
5351
5976
|
/** Upload a bundle archive; returns the control-plane bundle id. */
|
|
@@ -5502,7 +6127,8 @@ async function deployBundle(opts) {
|
|
|
5502
6127
|
projectRoot,
|
|
5503
6128
|
appName: backend.name,
|
|
5504
6129
|
app: backend.app,
|
|
5505
|
-
runtimeRange: loaded.manifest.
|
|
6130
|
+
runtimeRange: loaded.manifest.rebase,
|
|
6131
|
+
storage: loaded.manifest.storage,
|
|
5506
6132
|
skipTypeCheck: opts.skipTypeCheck,
|
|
5507
6133
|
log: (m) => console.log(chalk.gray(m))
|
|
5508
6134
|
})).outDir;
|
|
@@ -5513,7 +6139,7 @@ async function deployBundle(opts) {
|
|
|
5513
6139
|
bundleDir,
|
|
5514
6140
|
log: (m) => console.log(m)
|
|
5515
6141
|
});
|
|
5516
|
-
|
|
6142
|
+
for (const outcome of folded) console.log(chalk.gray(` folded ${outcome.appName} in (${outcome.fileCount} file(s), served at ${outcome.path})`));
|
|
5517
6143
|
} catch (err) {
|
|
5518
6144
|
fail(err instanceof Error ? err.message : String(err), "Fix the frontend build, or pass --no-static to deploy the API alone.");
|
|
5519
6145
|
}
|
|
@@ -5650,6 +6276,23 @@ async function readDeployContext(client, projectId) {
|
|
|
5650
6276
|
return {};
|
|
5651
6277
|
}
|
|
5652
6278
|
}
|
|
6279
|
+
/**
|
|
6280
|
+
* Whether this repository's backend declares the managed runtime.
|
|
6281
|
+
*
|
|
6282
|
+
* Deliberately quiet: a directory that is not a Rebase project, or whose
|
|
6283
|
+
* manifest does not parse, simply does not route this way — `rebase build` is
|
|
6284
|
+
* where a broken manifest gets reported, and a deploy refusing on one before it
|
|
6285
|
+
* has even said what it is doing would be the wrong place to find out.
|
|
6286
|
+
*/
|
|
6287
|
+
function declaresManagedRuntime() {
|
|
6288
|
+
try {
|
|
6289
|
+
const projectRoot = findProjectRoot();
|
|
6290
|
+
if (!projectRoot) return false;
|
|
6291
|
+
return findBackendApp(loadManifest(projectRoot).manifest)?.app.runtime === "managed";
|
|
6292
|
+
} catch {
|
|
6293
|
+
return false;
|
|
6294
|
+
}
|
|
6295
|
+
}
|
|
5653
6296
|
async function deployCommand(rawArgs, projectRef) {
|
|
5654
6297
|
const args = arg({
|
|
5655
6298
|
"--no-follow": Boolean,
|
|
@@ -5666,8 +6309,10 @@ async function deployCommand(rawArgs, projectRef) {
|
|
|
5666
6309
|
});
|
|
5667
6310
|
const { client, url } = await requireClient(rawArgs);
|
|
5668
6311
|
const projectId = await resolveProjectRef(projectRef, client);
|
|
5669
|
-
|
|
5670
|
-
|
|
6312
|
+
const declaredManaged = !args["--source"] && !args["--bundle"] && declaresManagedRuntime();
|
|
6313
|
+
if (args["--bundle"] || declaredManaged) {
|
|
6314
|
+
if (args["--bundle"] && args["--source"]) fail("--bundle and --source cannot be combined: one is a managed bundle, the other a source build.");
|
|
6315
|
+
if (declaredManaged && !isJsonMode()) console.log(chalk.gray(" rebase.json declares runtime: managed — deploying a bundle."));
|
|
5671
6316
|
await deployBundle({
|
|
5672
6317
|
client,
|
|
5673
6318
|
url,
|
|
@@ -9039,11 +9684,8 @@ async function appsCommand(subcommand, rawArgs = []) {
|
|
|
9039
9684
|
}
|
|
9040
9685
|
function describeApp(app) {
|
|
9041
9686
|
switch (app.type) {
|
|
9042
|
-
case "backend": return `
|
|
9043
|
-
case "static": return `${app.root} → ${app.output}`;
|
|
9044
|
-
case "admin": return app.mode === "bundled" ? `bundled → ${app.output ?? "?"}` : "hosted by the platform";
|
|
9045
|
-
case "mobile": return app.platform;
|
|
9046
|
-
case "custom": return app.dockerfile ?? "Dockerfile";
|
|
9687
|
+
case "backend": return app.runtime === "custom" ? `custom runtime — ${app.dockerfile ?? "Dockerfile"}` : `managed runtime, config: ${app.config ?? "config"}`;
|
|
9688
|
+
case "static": return `${app.root} → ${app.output} @ ${app.path ?? "/"}`;
|
|
9047
9689
|
default: return "";
|
|
9048
9690
|
}
|
|
9049
9691
|
}
|
|
@@ -9053,7 +9695,7 @@ async function listApps(asJson) {
|
|
|
9053
9695
|
if (asJson) {
|
|
9054
9696
|
console.log(JSON.stringify({
|
|
9055
9697
|
source: loaded.source,
|
|
9056
|
-
|
|
9698
|
+
rebase: loaded.manifest.rebase,
|
|
9057
9699
|
apps: loaded.manifest.apps,
|
|
9058
9700
|
managed: compatibility
|
|
9059
9701
|
}, null, 2));
|
|
@@ -9063,7 +9705,7 @@ async function listApps(asJson) {
|
|
|
9063
9705
|
console.log(chalk.dim("No rebase.json — showing the layout inferred from this project."));
|
|
9064
9706
|
console.log(chalk.dim(`Run ${chalk.cyan("rebase apps init")} to write it down.\n`));
|
|
9065
9707
|
}
|
|
9066
|
-
console.log(chalk.bold(`
|
|
9708
|
+
console.log(chalk.bold(`Rebase ${loaded.manifest.rebase}`));
|
|
9067
9709
|
console.log("");
|
|
9068
9710
|
const entries = Object.entries(loaded.manifest.apps);
|
|
9069
9711
|
if (entries.length === 0) {
|
|
@@ -9209,6 +9851,7 @@ async function entry(args) {
|
|
|
9209
9851
|
"api-keys",
|
|
9210
9852
|
"cloud",
|
|
9211
9853
|
"apps",
|
|
9854
|
+
"eject",
|
|
9212
9855
|
"generate-sdk"
|
|
9213
9856
|
].includes(command)) {
|
|
9214
9857
|
printHelp();
|
|
@@ -9261,6 +9904,9 @@ async function entry(args) {
|
|
|
9261
9904
|
case "apps":
|
|
9262
9905
|
await appsCommand(effectiveSubcommand, args);
|
|
9263
9906
|
break;
|
|
9907
|
+
case "eject":
|
|
9908
|
+
await ejectCommand(args);
|
|
9909
|
+
break;
|
|
9264
9910
|
case "auth":
|
|
9265
9911
|
await authCommand(effectiveSubcommand, args);
|
|
9266
9912
|
break;
|
|
@@ -9295,6 +9941,8 @@ ${chalk.green.bold("Commands")}
|
|
|
9295
9941
|
${chalk.blue.bold("dev")} Start the development server
|
|
9296
9942
|
${chalk.blue.bold("build")} Build all workspace packages
|
|
9297
9943
|
${chalk.blue.bold("start")} Start the backend server ${chalk.gray("(production)")}
|
|
9944
|
+
${chalk.blue.bold("apps list")} Show the apps this repository declares
|
|
9945
|
+
${chalk.blue.bold("eject")} Take ownership of the server process and image
|
|
9298
9946
|
|
|
9299
9947
|
${chalk.green.bold("Schema")}
|
|
9300
9948
|
${chalk.blue.bold("schema generate")} Generate Drizzle schema from collections
|
|
@@ -9312,25 +9960,25 @@ ${chalk.green.bold("SDK")}
|
|
|
9312
9960
|
|
|
9313
9961
|
${chalk.green.bold("Auth")}
|
|
9314
9962
|
${chalk.blue.bold("auth reset-password")} Reset a user's password
|
|
9315
|
-
${chalk.blue.bold("auth")} ${chalk.gray("--help")}
|
|
9963
|
+
${chalk.blue.bold("auth")} ${chalk.gray("--help")} Show auth command help
|
|
9316
9964
|
|
|
9317
9965
|
${chalk.green.bold("Diagnostics")}
|
|
9318
9966
|
${chalk.blue.bold("doctor")} Detect schema drift between collections, schema, and DB
|
|
9319
9967
|
|
|
9320
9968
|
${chalk.green.bold("AI Agent Skills")}
|
|
9321
|
-
${chalk.blue.bold("skills install")}
|
|
9969
|
+
${chalk.blue.bold("skills install")} Install Rebase agent skills for your AI coding assistant
|
|
9322
9970
|
|
|
9323
9971
|
${chalk.green.bold("API Keys")}
|
|
9324
|
-
${chalk.blue.bold("api-keys list")}
|
|
9325
|
-
${chalk.blue.bold("api-keys create")}
|
|
9326
|
-
${chalk.blue.bold("api-keys revoke")}
|
|
9327
|
-
${chalk.blue.bold("api-keys")} ${chalk.gray("--help")}
|
|
9972
|
+
${chalk.blue.bold("api-keys list")} List all service API keys
|
|
9973
|
+
${chalk.blue.bold("api-keys create")} Create a new scoped API key
|
|
9974
|
+
${chalk.blue.bold("api-keys revoke")} Revoke an existing API key
|
|
9975
|
+
${chalk.blue.bold("api-keys")} ${chalk.gray("--help")} Show API key command help
|
|
9328
9976
|
|
|
9329
9977
|
${chalk.green.bold("Rebase Cloud")}
|
|
9330
9978
|
${chalk.blue.bold("cloud login")} Sign in to the hosted control plane
|
|
9331
9979
|
${chalk.blue.bold("cloud link")} Link this directory to a cloud project
|
|
9332
9980
|
${chalk.blue.bold("cloud deploy")} Deploy the linked project + stream logs
|
|
9333
|
-
${chalk.blue.bold("cloud")} ${chalk.gray("--help")}
|
|
9981
|
+
${chalk.blue.bold("cloud")} ${chalk.gray("--help")} Show all cloud commands
|
|
9334
9982
|
|
|
9335
9983
|
${chalk.green.bold("Options")}
|
|
9336
9984
|
${chalk.blue("--version, -v")} Show version number
|
|
@@ -9340,6 +9988,6 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
|
|
|
9340
9988
|
`);
|
|
9341
9989
|
}
|
|
9342
9990
|
//#endregion
|
|
9343
|
-
export { CURRENT_RUNTIME_RANGE, DEFAULT_BUNDLE_DIR, DEFAULT_CONFIG_DIR, DEFAULT_CRONS_DIR, DEFAULT_FUNCTIONS_DIR, DEFAULT_SCHEMA_FILE, MANIFEST_FILENAME, ManifestError, appsCommand, assessManagedCompatibility, authCommand, buildBundle, buildCommand, buildInitQuestions, buildStaticBundle, buildableApps, cloudCommand, collectDeclaredDependencies, configureEnvFile, createRebaseApp, dbCommand, detectNativeDependencies, detectPackageManager, detectStorageAuthorize, devCommand, doctorCommand, entry, findBackendApp, findBackendDir, findEnvFile, findFrontendDir, findProjectRoot, findUnusedServerEntry, foldStaticIntoBundle, formatCdTarget, generateSdkCommand, getActiveBackendPlugin, getPMCommands, isIdentifierLike, isPnpmAvailable, loadManifest, manifestExists, manifestPath, normalizeEsmSpecifiers, pnpmAvailabilityFromProbe, printInitHelp, requireBackendDir, requireProjectRoot, resetPnpmAvailabilityCache, resolveBackendPaths, resolveExampleBaseUrl, resolveLocalBin, resolvePluginCliScript, resolveTsx, schemaCommand, startCommand, synthesizeManifest, validateManifest, validateProjectName, validateTsxInstallation, writeManifest };
|
|
9991
|
+
export { CURRENT_RUNTIME_RANGE, DEFAULT_BUNDLE_DIR, DEFAULT_CONFIG_DIR, DEFAULT_CRONS_DIR, DEFAULT_FUNCTIONS_DIR, DEFAULT_SCHEMA_FILE, MANIFEST_FILENAME, ManifestError, TEMPLATE_PLACEHOLDER_FILES, appsCommand, assessManagedCompatibility, authCommand, buildBundle, buildCommand, buildInitQuestions, buildStaticBundle, buildableApps, cloudCommand, collectDeclaredDependencies, configureEnvFile, createRebaseApp, dbCommand, detectNativeDependencies, detectPackageManager, detectStorageAuthorize, devCommand, doctorCommand, ejectCommand, entry, findBackendApp, findBackendDir, findEnvFile, findFrontendDir, findProjectRoot, findUnusedServerEntry, foldStaticIntoBundle, formatCdTarget, generateSdkCommand, getActiveBackendPlugin, getPMCommands, isIdentifierLike, isPnpmAvailable, loadManifest, manifestExists, manifestPath, normalizeEsmSpecifiers, pnpmAvailabilityFromProbe, printInitHelp, requireBackendDir, requireProjectRoot, resetPnpmAvailabilityCache, resolveBackendPaths, resolveExampleBaseUrl, resolveLocalBin, resolvePluginCliScript, resolveTsx, schemaCommand, startCommand, synthesizeManifest, validateManifest, validateProjectName, validateTsxInstallation, writeManifest };
|
|
9344
9992
|
|
|
9345
9993
|
//# sourceMappingURL=index.es.js.map
|