@rebasepro/cli 0.11.1-canary.gf410d03 → 0.11.1-canary.gfadf355

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/dist/bundle.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type NativeDependency, type RebaseBundleManifest, type RebaseBackendAppConfig } from "@rebasepro/types";
1
+ import { type DeclaredStorageSources, type NativeDependency, type RebaseBundleManifest, type RebaseBackendAppConfig } from "@rebasepro/types";
2
2
  export declare const DEFAULT_BUNDLE_DIR = "dist-bundle";
3
3
  export interface BuildBundleOptions {
4
4
  projectRoot: string;
@@ -8,6 +8,13 @@ export interface BuildBundleOptions {
8
8
  outDir?: string;
9
9
  /** Runtime range from the manifest, recorded for compatibility checks. */
10
10
  runtimeRange: string;
11
+ /**
12
+ * The `storage` block of `rebase.json` — which buckets this project uses.
13
+ *
14
+ * Passed in rather than re-read here so `rebase.json` is parsed and validated
15
+ * once, by the command that owns it.
16
+ */
17
+ storage?: DeclaredStorageSources;
11
18
  /** Skip type checking. Faster, and strictly worse — for iteration only. */
12
19
  skipTypeCheck?: boolean;
13
20
  /** Skip regenerating the Drizzle schema from the collections. */
@@ -37,7 +44,7 @@ export interface BuildBundleResult {
37
44
  * says exactly how to proceed, while a false positive would hand back the crash
38
45
  * loop this exists to prevent.
39
46
  */
40
- export declare function detectStorageAuthorize(compiledConfigDir: string): boolean;
47
+ export declare function detectStorageAuthorize(compiledConfigDir: string, depth?: number): boolean;
41
48
  /**
42
49
  * Detect native code in the dependency closure.
43
50
  *
@@ -1,4 +1,20 @@
1
1
  import type { PackageManager, PMCommands } from "../utils/package-manager";
2
+ /**
3
+ * Every scaffolded file that carries a `{{PLACEHOLDER}}`.
4
+ *
5
+ * Exported because it is the single source of truth: `init.test.ts` reads it and
6
+ * asserts that every template file containing `{{` appears here. It used to be a
7
+ * local, with the test harness keeping a *second* copy — so the two drifted, and
8
+ * a test built on the copy could not observe the production list at all.
9
+ *
10
+ * The drift shipped: `docker-compose.yml` arrived with the self-host work
11
+ * (26fd5259c) and was added to neither, so every scaffolded project got a literal
12
+ * `name: {{PROJECT_NAME}}`. In YAML `{{...}}` is a map, not a string, so the
13
+ * documented `docker compose up` path failed on the file before doing anything:
14
+ *
15
+ * yaml: unmarshal errors: line 28: cannot unmarshal !!map into string
16
+ */
17
+ export declare const TEMPLATE_PLACEHOLDER_FILES: string[];
2
18
  /** Returns an error message, or null when the name is a valid package name. */
3
19
  export declare function validateProjectName(name: string): string | null;
4
20
  export type TemplatePreset = "blog" | "ecommerce" | "blank";
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
@@ -840,6 +840,31 @@ function findParentDir(currentDir, targetName) {
840
840
  }
841
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";
@@ -1411,15 +1436,7 @@ function cleanupPresets(presetsDir) {
1411
1436
  });
1412
1437
  }
1413
1438
  async function replacePlaceholders(options) {
1414
- const filesToProcess = [
1415
- "package.json",
1416
- "frontend/package.json",
1417
- "backend/package.json",
1418
- "config/package.json",
1419
- "frontend/index.html",
1420
- "pnpm-workspace.yaml",
1421
- "README.md"
1422
- ];
1439
+ const filesToProcess = TEMPLATE_PLACEHOLDER_FILES;
1423
1440
  const packageJsonPath = path.resolve(cliRoot, "package.json");
1424
1441
  let cliVersion = "latest";
1425
1442
  if (fs.existsSync(packageJsonPath)) cliVersion = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")).version || "latest";
@@ -2321,17 +2338,90 @@ function validateManifest(raw) {
2321
2338
  }
2322
2339
  byPath.set(at, name);
2323
2340
  }
2341
+ const storage = validateStorageSources(raw.storage, issues);
2324
2342
  if (issues.length > 0) return { issues };
2325
2343
  return {
2326
2344
  manifest: {
2327
2345
  $schema: typeof raw.$schema === "string" ? raw.$schema : void 0,
2328
2346
  rebase: raw.rebase,
2329
- apps
2347
+ apps,
2348
+ ...storage ? { storage } : {}
2330
2349
  },
2331
2350
  issues
2332
2351
  };
2333
2352
  }
2334
2353
  /**
2354
+ * Validate the `storage` block — which buckets this project uses.
2355
+ *
2356
+ * Absent means one default source, so `undefined` is a valid answer and not an
2357
+ * issue. Everything else is checked strictly, because each key here becomes the
2358
+ * suffix of a set of environment variables: a key that cannot become a variable
2359
+ * name, or two keys that become the *same* one, are failures worth catching
2360
+ * while someone is looking at the file rather than at a tenant serving one
2361
+ * bucket's files with another's credentials.
2362
+ */
2363
+ function validateStorageSources(raw, issues) {
2364
+ if (raw === void 0) return void 0;
2365
+ if (!isRecord(raw)) {
2366
+ issues.push({
2367
+ path: "storage",
2368
+ message: "must be an object keyed by storage source name"
2369
+ });
2370
+ return;
2371
+ }
2372
+ const sources = {};
2373
+ for (const [key, value] of Object.entries(raw)) {
2374
+ if (!isRecord(value)) {
2375
+ issues.push({
2376
+ path: `storage.${key}`,
2377
+ message: "must be an object"
2378
+ });
2379
+ continue;
2380
+ }
2381
+ if (typeof value.engine !== "string" || value.engine.trim() === "") {
2382
+ issues.push({
2383
+ path: `storage.${key}.engine`,
2384
+ message: "is required, e.g. \"s3\", \"gcs\" or \"local\""
2385
+ });
2386
+ continue;
2387
+ }
2388
+ if (value.transport !== void 0 && value.transport !== "server" && value.transport !== "direct") {
2389
+ issues.push({
2390
+ path: `storage.${key}.transport`,
2391
+ message: "must be \"server\" or \"direct\""
2392
+ });
2393
+ continue;
2394
+ }
2395
+ if (value.label !== void 0 && typeof value.label !== "string") {
2396
+ issues.push({
2397
+ path: `storage.${key}.label`,
2398
+ message: "must be a string"
2399
+ });
2400
+ continue;
2401
+ }
2402
+ try {
2403
+ storageEnvSuffix(key);
2404
+ } catch {
2405
+ issues.push({
2406
+ path: `storage.${key}`,
2407
+ message: "name cannot become an environment variable suffix — use a name containing at least one letter or digit"
2408
+ });
2409
+ continue;
2410
+ }
2411
+ sources[key] = {
2412
+ engine: value.engine,
2413
+ ...value.transport !== void 0 ? { transport: value.transport } : {},
2414
+ ...value.label !== void 0 ? { label: value.label } : {}
2415
+ };
2416
+ }
2417
+ const collision = findStorageSuffixCollision(Object.keys(sources));
2418
+ if (collision) issues.push({
2419
+ path: `storage.${collision.b}`,
2420
+ 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`
2421
+ });
2422
+ return Object.keys(sources).length > 0 ? sources : void 0;
2423
+ }
2424
+ /**
2335
2425
  * Infer a manifest from a directory that does not have one.
2336
2426
  *
2337
2427
  * This mirrors exactly what the template scaffolds, which is what makes adopting
@@ -3168,16 +3258,27 @@ async function writeBundleTsconfig(projectRoot, outDir, includes, skipTypeCheck)
3168
3258
  * says exactly how to proceed, while a false positive would hand back the crash
3169
3259
  * loop this exists to prevent.
3170
3260
  */
3171
- function detectStorageAuthorize(compiledConfigDir) {
3261
+ function detectStorageAuthorize(compiledConfigDir, depth = 0) {
3172
3262
  const indexPath = [
3173
3263
  ".js",
3174
3264
  ".mjs",
3175
3265
  ".ts"
3176
3266
  ].map((ext) => path.join(compiledConfigDir, `index${ext}`)).find((candidate) => fs.existsSync(candidate));
3177
3267
  if (!indexPath) return false;
3268
+ return moduleExportsStorageAuthorize(indexPath, depth);
3269
+ }
3270
+ /**
3271
+ * Whether one compiled module re-exports or defines `storageAuthorize`.
3272
+ *
3273
+ * Split out from {@link detectStorageAuthorize} so a wildcard re-export can be
3274
+ * followed. `export * from "./storage.js"` is an ordinary way to write a config
3275
+ * barrel, and treating it as "no hook" rejected deploys that were correct — with
3276
+ * a message telling the developer to add a hook they had already written.
3277
+ */
3278
+ function moduleExportsStorageAuthorize(modulePath, depth) {
3178
3279
  let source;
3179
3280
  try {
3180
- source = fs.readFileSync(indexPath, "utf8");
3281
+ source = fs.readFileSync(modulePath, "utf8");
3181
3282
  } catch {
3182
3283
  return false;
3183
3284
  }
@@ -3186,9 +3287,48 @@ function detectStorageAuthorize(compiledConfigDir) {
3186
3287
  const parts = entry.split(/\bas\b/);
3187
3288
  return parts[parts.length - 1].trim();
3188
3289
  }).includes("storageAuthorize")) return true;
3290
+ if (depth < 3) for (const clause of source.matchAll(/\bexport\s*\*\s*from\s*["']([^"']+)["']/g)) {
3291
+ const specifier = clause[1];
3292
+ if (!specifier.startsWith(".")) continue;
3293
+ const resolved = resolveRelativeModule(path.dirname(modulePath), specifier);
3294
+ if (resolved && moduleExportsStorageAuthorize(resolved, depth + 1)) return true;
3295
+ }
3189
3296
  return false;
3190
3297
  }
3191
3298
  /**
3299
+ * Resolve a relative ESM specifier to a file on disk.
3300
+ *
3301
+ * Compiled output carries explicit `.js` extensions, but the same function reads
3302
+ * TypeScript sources during a source boot, where the specifier may be
3303
+ * extensionless or point at a directory index.
3304
+ */
3305
+ function resolveRelativeModule(fromDir, specifier) {
3306
+ const base = path.resolve(fromDir, specifier);
3307
+ const candidates = [
3308
+ base,
3309
+ `${base}.js`,
3310
+ `${base}.mjs`,
3311
+ `${base}.ts`,
3312
+ path.join(base, "index.js"),
3313
+ path.join(base, "index.mjs"),
3314
+ path.join(base, "index.ts")
3315
+ ];
3316
+ for (const candidate of candidates) try {
3317
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return candidate;
3318
+ } catch {
3319
+ continue;
3320
+ }
3321
+ if (/\.js$/.test(base)) {
3322
+ const asTs = base.replace(/\.js$/, ".ts");
3323
+ try {
3324
+ if (fs.existsSync(asTs) && fs.statSync(asTs).isFile()) return asTs;
3325
+ } catch {
3326
+ return null;
3327
+ }
3328
+ }
3329
+ return null;
3330
+ }
3331
+ /**
3192
3332
  * Detect native code in the dependency closure.
3193
3333
  *
3194
3334
  * Walks declared runtime dependencies breadth-first through `node_modules`,
@@ -3542,6 +3682,9 @@ async function buildBundle(options) {
3542
3682
  const declared = collectDeclaredDependencies(projectRoot);
3543
3683
  const nativeModules = detectNativeDependencies(projectRoot, declared);
3544
3684
  const declaresStorageAuthorize = detectStorageAuthorize(path.join(outDir, paths.config));
3685
+ const storageSources = normalizeStorageSources(options.storage, void 0);
3686
+ const collision = findStorageSuffixCollision(storageSources.map((s) => s.key));
3687
+ 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.`);
3545
3688
  const schemaOut = paths.schema.replace(/\.ts$/, ".js");
3546
3689
  const relative = (target) => fs.existsSync(path.join(outDir, target)) ? target : void 0;
3547
3690
  const manifest = {
@@ -3567,7 +3710,10 @@ async function buildBundle(options) {
3567
3710
  native: nativeModules.length > 0,
3568
3711
  nativeModules: nativeModules.length > 0 ? nativeModules : void 0
3569
3712
  },
3570
- storage: { authorize: declaresStorageAuthorize },
3713
+ storage: {
3714
+ authorize: declaresStorageAuthorize,
3715
+ ...storageSources.length > 0 ? { sources: storageSources } : {}
3716
+ },
3571
3717
  deps: { declared },
3572
3718
  build: {
3573
3719
  cli: resolveCliVersion(),
@@ -4023,6 +4169,7 @@ async function buildCommand(rawArgs = []) {
4023
4169
  app,
4024
4170
  outDir: args["--out"],
4025
4171
  runtimeRange: manifest.rebase,
4172
+ storage: manifest.storage,
4026
4173
  skipTypeCheck: args["--skip-type-check"],
4027
4174
  skipSchema: args["--skip-schema"]
4028
4175
  });
@@ -5959,6 +6106,7 @@ async function deployBundle(opts) {
5959
6106
  appName: backend.name,
5960
6107
  app: backend.app,
5961
6108
  runtimeRange: loaded.manifest.rebase,
6109
+ storage: loaded.manifest.storage,
5962
6110
  skipTypeCheck: opts.skipTypeCheck,
5963
6111
  log: (m) => console.log(chalk.gray(m))
5964
6112
  })).outDir;
@@ -9790,25 +9938,25 @@ ${chalk.green.bold("SDK")}
9790
9938
 
9791
9939
  ${chalk.green.bold("Auth")}
9792
9940
  ${chalk.blue.bold("auth reset-password")} Reset a user's password
9793
- ${chalk.blue.bold("auth")} ${chalk.gray("--help")} Show auth command help
9941
+ ${chalk.blue.bold("auth")} ${chalk.gray("--help")} Show auth command help
9794
9942
 
9795
9943
  ${chalk.green.bold("Diagnostics")}
9796
9944
  ${chalk.blue.bold("doctor")} Detect schema drift between collections, schema, and DB
9797
9945
 
9798
9946
  ${chalk.green.bold("AI Agent Skills")}
9799
- ${chalk.blue.bold("skills install")} Install Rebase agent skills for your AI coding assistant
9947
+ ${chalk.blue.bold("skills install")} Install Rebase agent skills for your AI coding assistant
9800
9948
 
9801
9949
  ${chalk.green.bold("API Keys")}
9802
- ${chalk.blue.bold("api-keys list")} List all service API keys
9803
- ${chalk.blue.bold("api-keys create")} Create a new scoped API key
9804
- ${chalk.blue.bold("api-keys revoke")} Revoke an existing API key
9805
- ${chalk.blue.bold("api-keys")} ${chalk.gray("--help")} Show API key command help
9950
+ ${chalk.blue.bold("api-keys list")} List all service API keys
9951
+ ${chalk.blue.bold("api-keys create")} Create a new scoped API key
9952
+ ${chalk.blue.bold("api-keys revoke")} Revoke an existing API key
9953
+ ${chalk.blue.bold("api-keys")} ${chalk.gray("--help")} Show API key command help
9806
9954
 
9807
9955
  ${chalk.green.bold("Rebase Cloud")}
9808
9956
  ${chalk.blue.bold("cloud login")} Sign in to the hosted control plane
9809
9957
  ${chalk.blue.bold("cloud link")} Link this directory to a cloud project
9810
9958
  ${chalk.blue.bold("cloud deploy")} Deploy the linked project + stream logs
9811
- ${chalk.blue.bold("cloud")} ${chalk.gray("--help")} Show all cloud commands
9959
+ ${chalk.blue.bold("cloud")} ${chalk.gray("--help")} Show all cloud commands
9812
9960
 
9813
9961
  ${chalk.green.bold("Options")}
9814
9962
  ${chalk.blue("--version, -v")} Show version number
@@ -9818,6 +9966,6 @@ ${chalk.gray("Documentation: https://rebase.pro/docs")}
9818
9966
  `);
9819
9967
  }
9820
9968
  //#endregion
9821
- 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, 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 };
9969
+ 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 };
9822
9970
 
9823
9971
  //# sourceMappingURL=index.es.js.map