@base44-preview/cli 0.2.2-pr.675.788aed1 → 0.2.2-pr.677.e0cc2a5

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/cli/index.js CHANGED
@@ -255336,7 +255336,6 @@ var deno2 = Object.freeze({
255336
255336
  });
255337
255337
  globalThis.Deno = deno2;
255338
255338
  globalThis.Buffer = Buffer2;
255339
- if (typeof process !== "undefined") process.version = "v22.23.4";
255340
255339
  try {
255341
255340
  new AsyncLocalStorage().enterWith(void 0);
255342
255341
  } catch {
@@ -262852,25 +262851,30 @@ var pipelineType = ZodPipeline.create;
262852
262851
  var fileMapSchema = recordType(stringType().min(1), stringType()).refine((files) => Object.keys(files).length > 0, {
262853
262852
  message: "must contain at least one file"
262854
262853
  });
262854
+ var entryPathSchema = stringType().min(1).max(200);
262855
262855
  var bundleRequestSchema = objectType({
262856
262856
  entry: stringType().min(1),
262857
262857
  files: fileMapSchema,
262858
+ entryPath: entryPathSchema.optional(),
262858
262859
  postResponseTelemetry: booleanType().optional(),
262859
- runtimeSecrets: booleanType().optional()
262860
+ runtimeSecrets: booleanType().optional(),
262861
+ sourceMap: booleanType().optional()
262860
262862
  }).refine((body) => (body.entry in body.files), {
262861
262863
  message: "`entry` must be a key in `files`"
262862
262864
  });
262863
262865
  var appFunctionSchema = objectType({
262864
262866
  name: stringType().min(1),
262865
262867
  entry: stringType().min(1),
262866
- files: fileMapSchema
262868
+ files: fileMapSchema,
262869
+ entryPath: entryPathSchema.optional()
262867
262870
  }).refine((fn) => (fn.entry in fn.files), {
262868
262871
  message: "`entry` must be a key in `files`"
262869
262872
  });
262870
262873
  var bundleAppRequestSchema = objectType({
262871
262874
  functions: arrayType(appFunctionSchema).min(1),
262872
262875
  postResponseTelemetry: booleanType().optional(),
262873
- runtimeSecrets: booleanType().optional()
262876
+ runtimeSecrets: booleanType().optional(),
262877
+ sourceMap: booleanType().optional()
262874
262878
  }).refine((body) => new Set(body.functions.map((fn) => fn.name)).size === body.functions.length, { message: "function names must be unique" });
262875
262879
  var ACTIVATION_MODE = "pull";
262876
262880
 
@@ -263435,7 +263439,8 @@ function wsNativeVirtualPlugin() {
263435
263439
  }
263436
263440
 
263437
263441
  // ../functions-compiler/src/deno-bundle.ts
263438
- async function bundleToModule(prepared, nodeModulesDir = "none") {
263442
+ var MAIN_MODULE = "_bundled.mjs";
263443
+ async function bundleToModule(prepared, nodeModulesDir = "none", sourceMap = false) {
263439
263444
  const dir = await mkdtemp(path21.join(tmpdir2(), "b44-bundle-"));
263440
263445
  try {
263441
263446
  await writeFile2(path21.join(dir, "deno.json"), JSON.stringify({ nodeModulesDir }));
@@ -263454,7 +263459,7 @@ async function bundleToModule(prepared, nodeModulesDir = "none") {
263454
263459
  define: { __dirname: '"/"', __filename: '"/index.js"' },
263455
263460
  minify: true,
263456
263461
  ...prepared.banner ? { banner: { js: prepared.banner } } : {},
263457
- sourcemap: false,
263462
+ ...sourceMap ? { sourcemap: "linked", sourcesContent: false, outfile: MAIN_MODULE } : { sourcemap: false },
263458
263463
  logLevel: "silent",
263459
263464
  plugins: [
263460
263465
  wsNativeVirtualPlugin(),
@@ -263473,14 +263478,19 @@ async function bundleToModule(prepared, nodeModulesDir = "none") {
263473
263478
  throw e;
263474
263479
  }
263475
263480
  const outputs = result.outputFiles ?? [];
263476
- if (outputs.length !== 1) {
263477
- throw new Error(`expected single-module output, got ${outputs.length} file(s)`);
263481
+ const warnings = result.warnings.map((w) => w.text);
263482
+ if (!sourceMap) {
263483
+ if (outputs.length !== 1) {
263484
+ throw new Error(`expected single-module output, got ${outputs.length} file(s)`);
263485
+ }
263486
+ return { ok: true, module: outputs[0].text, warnings };
263478
263487
  }
263479
- return {
263480
- ok: true,
263481
- module: outputs[0].text,
263482
- warnings: result.warnings.map((w) => w.text)
263483
- };
263488
+ const module = outputs.find((o) => o.path.endsWith(".mjs"));
263489
+ const map = outputs.find((o) => o.path.endsWith(".map"));
263490
+ if (outputs.length !== 2 || !module || !map) {
263491
+ throw new Error(`expected a module and its source map, got ${outputs.map((o) => path21.basename(o.path)).join(", ") || "no files"}`);
263492
+ }
263493
+ return { ok: true, module: module.text, map: map.text, warnings };
263484
263494
  } finally {
263485
263495
  await rm2(dir, { recursive: true, force: true });
263486
263496
  }
@@ -263526,6 +263536,36 @@ function relativizeFile(file, dir) {
263526
263536
  return file.startsWith(prefix) ? file.slice(prefix.length) : file;
263527
263537
  }
263528
263538
 
263539
+ // ../functions-compiler/src/source-map.ts
263540
+ var INTERNAL_SOURCE_PREFIX = "base44-internal:";
263541
+ var USER_PREFIX = `${USER_NAMESPACE}:`;
263542
+ var APP_FUNCTION_PATH = /^fn_(\d+)\/(.*)$/;
263543
+ function functionSourceMap(raw, fn) {
263544
+ return rewriteSources(raw, (key) => appPath(fn, key));
263545
+ }
263546
+ function appSourceMap(raw, functions) {
263547
+ return rewriteSources(raw, (key) => {
263548
+ const match = key.match(APP_FUNCTION_PATH);
263549
+ const fn = match ? functions[Number(match[1])] : undefined;
263550
+ return fn && match ? appPath(fn, match[2]) : undefined;
263551
+ });
263552
+ }
263553
+ function appPath(fn, key) {
263554
+ if (!Object.hasOwn(fn.files, key))
263555
+ return;
263556
+ return key === fn.entry && fn.entryPath ? fn.entryPath : key;
263557
+ }
263558
+ function rewriteSources(raw, appPathOf) {
263559
+ const map = JSON.parse(raw);
263560
+ map.sources = (map.sources ?? []).map((source) => {
263561
+ const app = source.startsWith(USER_PREFIX) ? appPathOf(source.slice(USER_PREFIX.length)) : undefined;
263562
+ return app ?? `${INTERNAL_SOURCE_PREFIX}${source}`;
263563
+ });
263564
+ delete map.sourceRoot;
263565
+ delete map.sourcesContent;
263566
+ return JSON.stringify(map);
263567
+ }
263568
+
263529
263569
  // ../functions-compiler/src/tracing.ts
263530
263570
  var noopTracer = {
263531
263571
  withSpan: (_name, fn) => fn(),
@@ -263540,7 +263580,6 @@ function setSpanTags(tags) {
263540
263580
  }
263541
263581
 
263542
263582
  // ../functions-compiler/src/bundler.ts
263543
- var NORMALIZED_MAIN_MODULE = "_bundled.mjs";
263544
263583
  var MAX_PARALLEL_COMPILES = 4;
263545
263584
  async function bundle(req) {
263546
263585
  let actor;
@@ -263561,7 +263600,7 @@ async function bundle(req) {
263561
263600
  return {
263562
263601
  ok: true,
263563
263602
  module: outcome.module,
263564
- main_module: NORMALIZED_MAIN_MODULE,
263603
+ main_module: MAIN_MODULE,
263565
263604
  warnings: outcome.warnings,
263566
263605
  handler_name: actor.handlerName,
263567
263606
  do_class_name: actor.doClassName
@@ -263575,12 +263614,13 @@ async function bundle(req) {
263575
263614
  } catch (e) {
263576
263615
  return denoCompatErrorOrThrow(e);
263577
263616
  }
263578
- const outcome = await installAndCompile(prepared);
263617
+ const outcome = await installAndCompile(prepared, req.sourceMap ?? false);
263579
263618
  if (outcome.ok) {
263580
263619
  return {
263581
263620
  ok: true,
263582
263621
  module: outcome.module,
263583
- main_module: NORMALIZED_MAIN_MODULE,
263622
+ ...outcome.map ? { source_map: functionSourceMap(outcome.map, req) } : {},
263623
+ main_module: MAIN_MODULE,
263584
263624
  warnings: outcome.warnings,
263585
263625
  ...activationField(req.runtimeSecrets ?? false)
263586
263626
  };
@@ -263595,26 +263635,29 @@ async function bundleApp(req) {
263595
263635
  return result.ok ? { ...result, ...activationField(req.runtimeSecrets ?? false) } : result;
263596
263636
  }
263597
263637
  async function assembleApp(req) {
263598
- const telemetry = req.postResponseTelemetry ?? false;
263599
- const runtimeSecrets = req.runtimeSecrets ?? false;
263638
+ const build = {
263639
+ telemetry: req.postResponseTelemetry ?? false,
263640
+ runtimeSecrets: req.runtimeSecrets ?? false,
263641
+ sourceMap: req.sourceMap ?? false
263642
+ };
263600
263643
  const entries = req.functions.map((fn, index) => ({
263601
263644
  index,
263602
263645
  fn
263603
263646
  }));
263604
263647
  let combined;
263605
263648
  try {
263606
- combined = await compileApp(entries, telemetry, runtimeSecrets);
263649
+ combined = await compileApp(entries, build);
263607
263650
  } catch (e) {
263608
263651
  if (e instanceof DenoCompatError)
263609
- return bundleAppPerFunction(entries, telemetry, runtimeSecrets);
263652
+ return bundleAppPerFunction(entries, build);
263610
263653
  throw e;
263611
263654
  }
263612
263655
  if (combined.ok) {
263613
- return appResponse(combined.module, allOk(entries));
263656
+ return appResponse(combined, allOk(entries));
263614
263657
  }
263615
263658
  const { byIndex, unattributable } = classifyAppErrors(combined.errors);
263616
263659
  if (unattributable.length > 0) {
263617
- return bundleAppPerFunction(entries, telemetry, runtimeSecrets);
263660
+ return bundleAppPerFunction(entries, build);
263618
263661
  }
263619
263662
  const functions = entries.map((e) => byIndex.has(e.index) ? { name: e.fn.name, ok: false, errors: byIndex.get(e.index) } : { name: e.fn.name, ok: true });
263620
263663
  const survivors = entries.filter((e) => !byIndex.has(e.index));
@@ -263623,25 +263666,42 @@ async function assembleApp(req) {
263623
263666
  }
263624
263667
  let rebuilt;
263625
263668
  try {
263626
- rebuilt = await compileApp(survivors, telemetry, runtimeSecrets);
263669
+ rebuilt = await compileApp(survivors, build);
263627
263670
  } catch (e) {
263628
263671
  if (e instanceof DenoCompatError)
263629
- return bundleAppPerFunction(entries, telemetry, runtimeSecrets);
263672
+ return bundleAppPerFunction(entries, build);
263630
263673
  throw e;
263631
263674
  }
263632
263675
  if (rebuilt.ok)
263633
- return appResponse(rebuilt.module, functions);
263634
- return bundleAppPerFunction(entries, telemetry, runtimeSecrets);
263635
- }
263636
- async function compileApp(entries, telemetry = false, runtimeSecrets = false) {
263637
- const outcome = await installAndCompile(prepareApp(entries, telemetry, runtimeSecrets));
263638
- return outcome.ok ? { ok: true, module: outcome.module } : { ok: false, errors: outcome.errors };
263676
+ return appResponse(rebuilt, functions);
263677
+ return bundleAppPerFunction(entries, build);
263678
+ }
263679
+ async function compileApp(entries, build) {
263680
+ const outcome = await installAndCompile(prepareApp(entries, build.telemetry, build.runtimeSecrets), build.sourceMap);
263681
+ if (!outcome.ok)
263682
+ return { ok: false, errors: outcome.errors };
263683
+ if (!outcome.map)
263684
+ return { ok: true, module: outcome.module };
263685
+ const functions = [];
263686
+ for (const { index, fn } of entries)
263687
+ functions[index] = fn;
263688
+ return {
263689
+ ok: true,
263690
+ module: outcome.module,
263691
+ map: appSourceMap(outcome.map, functions)
263692
+ };
263639
263693
  }
263640
263694
  function allOk(entries) {
263641
263695
  return entries.map((e) => ({ name: e.fn.name, ok: true }));
263642
263696
  }
263643
- function appResponse(module, functions) {
263644
- return { ok: true, module, main_module: NORMALIZED_MAIN_MODULE, functions };
263697
+ function appResponse(built, functions) {
263698
+ return {
263699
+ ok: true,
263700
+ module: built.module,
263701
+ ...built.map ? { source_map: built.map } : {},
263702
+ main_module: MAIN_MODULE,
263703
+ functions
263704
+ };
263645
263705
  }
263646
263706
  function classifyAppErrors(errors) {
263647
263707
  const byIndex = new Map;
@@ -263659,19 +263719,19 @@ function classifyAppErrors(errors) {
263659
263719
  }
263660
263720
  return { byIndex, unattributable };
263661
263721
  }
263662
- async function bundleAppPerFunction(entries, telemetry = false, runtimeSecrets = false) {
263663
- const probes = await mapWithConcurrency(entries, MAX_PARALLEL_COMPILES, (entry) => probeFunction(entry, runtimeSecrets));
263722
+ async function bundleAppPerFunction(entries, build) {
263723
+ const probes = await mapWithConcurrency(entries, MAX_PARALLEL_COMPILES, (entry) => probeFunction(entry, build.runtimeSecrets));
263664
263724
  const functions = probes.map((p) => p.ok ? { name: p.entry.fn.name, ok: true } : { name: p.entry.fn.name, ok: false, errors: p.errors });
263665
263725
  const survivors = probes.filter((p) => p.ok).map((p) => p.entry);
263666
263726
  if (survivors.length === 0) {
263667
263727
  return { ok: false, module: null, functions };
263668
263728
  }
263669
- const combined = await compileApp(survivors, telemetry, runtimeSecrets);
263729
+ const combined = await compileApp(survivors, build);
263670
263730
  if (combined.ok)
263671
- return appResponse(combined.module, functions);
263672
- return assembleWithoutConflicting(survivors, functions, combined.errors, telemetry, runtimeSecrets);
263731
+ return appResponse(combined, functions);
263732
+ return assembleWithoutConflicting(survivors, functions, combined.errors, build);
263673
263733
  }
263674
- async function assembleWithoutConflicting(survivors, functions, errors, telemetry, runtimeSecrets = false) {
263734
+ async function assembleWithoutConflicting(survivors, functions, errors, build) {
263675
263735
  const failWith = (entries, items) => {
263676
263736
  for (const e of entries) {
263677
263737
  functions[e.index] = { name: e.fn.name, ok: false, errors: items };
@@ -263686,10 +263746,10 @@ async function assembleWithoutConflicting(survivors, functions, errors, telemetr
263686
263746
  const blamed = survivors.filter((e) => importsConflictingPackage(e, errors));
263687
263747
  const rest = survivors.filter((e) => !blamed.includes(e));
263688
263748
  if (blamed.length > 0 && rest.length > 0) {
263689
- const rebuilt = await compileApp(rest, telemetry, runtimeSecrets);
263749
+ const rebuilt = await compileApp(rest, build);
263690
263750
  if (rebuilt.ok) {
263691
263751
  failWith(blamed, conflictErrors);
263692
- return appResponse(rebuilt.module, functions);
263752
+ return appResponse(rebuilt, functions);
263693
263753
  }
263694
263754
  failWith(blamed, conflictErrors);
263695
263755
  failWith(rest, [conflictErrors[0], ...rebuilt.errors]);
@@ -263726,7 +263786,11 @@ function escapeRegExp(s) {
263726
263786
  async function probeFunction(entry, runtimeSecrets = false) {
263727
263787
  let outcome;
263728
263788
  try {
263729
- outcome = await compileApp([entry], false, runtimeSecrets);
263789
+ outcome = await compileApp([entry], {
263790
+ telemetry: false,
263791
+ runtimeSecrets,
263792
+ sourceMap: false
263793
+ });
263730
263794
  } catch (e) {
263731
263795
  if (e instanceof DenoCompatError) {
263732
263796
  return { ok: false, entry, errors: [denoCompatErrorItem(e)] };
@@ -263756,20 +263820,25 @@ async function mapWithConcurrency(items, limit, fn) {
263756
263820
  return results;
263757
263821
  }
263758
263822
  var NODE_MODULES_FALLBACK = /ERR_MODULE_NOT_FOUND|Could not find referrer npm package/;
263759
- async function installAndCompile(prepared) {
263823
+ async function installAndCompile(prepared, sourceMap = false) {
263760
263824
  return withSpan("base44.bundler.compile", async () => {
263761
263825
  let mode = "none";
263762
- let result = await bundleToModule(prepared, mode);
263826
+ let result = await bundleToModule(prepared, mode, sourceMap);
263763
263827
  if (!result.ok && result.errors.some((e) => NODE_MODULES_FALLBACK.test(e.message))) {
263764
263828
  mode = "auto";
263765
- result = await bundleToModule(prepared, mode);
263829
+ result = await bundleToModule(prepared, mode, sourceMap);
263766
263830
  }
263767
263831
  await setSpanTags({
263768
263832
  node_modules_mode: mode,
263769
263833
  outcome: result.ok ? "ok" : "failed"
263770
263834
  });
263771
263835
  if (result.ok) {
263772
- return { ok: true, module: result.module, warnings: result.warnings };
263836
+ return {
263837
+ ok: true,
263838
+ module: result.module,
263839
+ ...result.map ? { map: result.map } : {},
263840
+ warnings: result.warnings
263841
+ };
263773
263842
  }
263774
263843
  return { ok: false, stage: "esbuild", errors: result.errors };
263775
263844
  });
@@ -273996,4 +274065,4 @@ export {
273996
274065
  runCLI
273997
274066
  };
273998
274067
 
273999
- //# debugId=7645CAD3637685AD64756E2164756E21
274068
+ //# debugId=3CA0B8062C899A1564756E2164756E21