clawfire 0.6.16 → 0.6.18

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.js CHANGED
@@ -269,7 +269,7 @@ async function runDevServer() {
269
269
  const port = portArg ? parseInt(portArg.split("=")[1], 10) : 3e3;
270
270
  const apiPort = apiPortArg ? parseInt(apiPortArg.split("=")[1], 10) : 3456;
271
271
  const noHotReload = args.includes("--no-hot-reload");
272
- const { startDevServer } = await import("./dev-server-FYHT3WN5.js");
272
+ const { startDevServer } = await import("./dev-server-54RXFRNZ.js");
273
273
  await startDevServer({
274
274
  projectDir,
275
275
  port,
@@ -2682,7 +2682,7 @@ function generateDashboardHtml(options) {
2682
2682
 
2683
2683
  // src/dev/firebase-setup.ts
2684
2684
  import { execFile as execFile2, spawn } from "child_process";
2685
- import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
2685
+ import { existsSync as existsSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync3, rmSync } from "fs";
2686
2686
  import { resolve as resolve4, join as join3 } from "path";
2687
2687
  import { tmpdir, platform, homedir } from "os";
2688
2688
  var FirebaseSetup = class {
@@ -3158,6 +3158,15 @@ var FirebaseSetup = class {
3158
3158
  if (!existsSync5(pkgPath)) {
3159
3159
  return { success: false, message: "functions/package.json not found." };
3160
3160
  }
3161
+ this.ensureFunctionsCJS(functionsDir);
3162
+ const distDir = resolve4(functionsDir, "dist");
3163
+ if (existsSync5(distDir)) {
3164
+ try {
3165
+ rmSync(distDir, { recursive: true, force: true });
3166
+ console.log(" \x1B[32m\u2713\x1B[0m Cleaned functions/dist/");
3167
+ } catch {
3168
+ }
3169
+ }
3161
3170
  try {
3162
3171
  await this.execTimeout("npm", ["install"], 12e4, functionsDir);
3163
3172
  } catch (err) {
@@ -3174,11 +3183,80 @@ var FirebaseSetup = class {
3174
3183
  await this.execTimeout("npx", ["tsc"], 6e4, functionsDir);
3175
3184
  }
3176
3185
  }
3177
- return { success: true, message: "Functions built successfully." };
3178
3186
  } catch (err) {
3179
3187
  const msg = err instanceof Error ? err.message : "Unknown error";
3180
3188
  return { success: false, message: `Functions build failed: ${msg}` };
3181
3189
  }
3190
+ const mainEntry = resolve4(functionsDir, "dist/index.js");
3191
+ if (!existsSync5(mainEntry)) {
3192
+ return { success: false, message: "Build produced no output (dist/index.js not found)." };
3193
+ }
3194
+ try {
3195
+ const firstLine = readFileSync4(mainEntry, "utf-8").split("\n")[0];
3196
+ const isESM = firstLine.startsWith("import ") || firstLine.startsWith("export ");
3197
+ if (isESM) {
3198
+ console.log(" \x1B[33m\u26A0\x1B[0m Warning: dist/index.js appears to be ESM, not CJS");
3199
+ } else {
3200
+ console.log(" \x1B[32m\u2713\x1B[0m Build output verified (CJS)");
3201
+ }
3202
+ } catch {
3203
+ }
3204
+ try {
3205
+ const verifyScript = [
3206
+ 'process.env.FIREBASE_CONFIG=JSON.stringify({projectId:"verify"});',
3207
+ 'process.env.GCLOUD_PROJECT="verify";',
3208
+ 'try{require("./dist/index.js");console.log("OK")}',
3209
+ 'catch(e){console.error("LOAD_ERROR:"+e.message);process.exit(1)}'
3210
+ ].join("");
3211
+ await this.execTimeout("node", ["-e", verifyScript], 15e3, functionsDir);
3212
+ console.log(" \x1B[32m\u2713\x1B[0m Module load verification passed");
3213
+ } catch (verifyErr) {
3214
+ const msg = verifyErr instanceof Error ? verifyErr.message : "Unknown";
3215
+ const match = msg.match(/LOAD_ERROR:(.+?)(\n|$)/);
3216
+ const detail = match ? match[1].trim() : msg.substring(0, 300);
3217
+ console.log(` \x1B[31m\u2717\x1B[0m Module load failed: ${detail}`);
3218
+ return { success: false, message: `Functions built but failed to load: ${detail}` };
3219
+ }
3220
+ return { success: true, message: "Functions built successfully." };
3221
+ }
3222
+ /**
3223
+ * Ensure functions/ uses CommonJS for Firebase Functions compatibility.
3224
+ * ESM + Firebase CLI analysis often fails. Auto-fix if needed.
3225
+ */
3226
+ ensureFunctionsCJS(functionsDir) {
3227
+ const pkgPath = resolve4(functionsDir, "package.json");
3228
+ try {
3229
+ const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
3230
+ if (pkg.type === "module") {
3231
+ delete pkg.type;
3232
+ writeFileSync3(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
3233
+ console.log(' \x1B[32m\u2713\x1B[0m Auto-fixed: removed "type": "module" from functions/package.json');
3234
+ }
3235
+ } catch {
3236
+ }
3237
+ const tsconfigPath = resolve4(functionsDir, "tsconfig.json");
3238
+ try {
3239
+ if (existsSync5(tsconfigPath)) {
3240
+ let content = readFileSync4(tsconfigPath, "utf-8");
3241
+ const tsconfig = JSON.parse(content);
3242
+ let changed = false;
3243
+ const mod = (tsconfig.compilerOptions?.module || "").toLowerCase();
3244
+ if (mod === "esnext" || mod === "es2022" || mod === "es2020" || mod === "nodenext" || mod === "node16") {
3245
+ tsconfig.compilerOptions.module = "CommonJS";
3246
+ changed = true;
3247
+ }
3248
+ const res = (tsconfig.compilerOptions?.moduleResolution || "").toLowerCase();
3249
+ if (res === "bundler" || res === "nodenext" || res === "node16") {
3250
+ tsconfig.compilerOptions.moduleResolution = "node";
3251
+ changed = true;
3252
+ }
3253
+ if (changed) {
3254
+ writeFileSync3(tsconfigPath, JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
3255
+ console.log(" \x1B[32m\u2713\x1B[0m Auto-fixed: functions/tsconfig.json \u2192 CommonJS + node resolution");
3256
+ }
3257
+ }
3258
+ } catch {
3259
+ }
3182
3260
  }
3183
3261
  // ─── Service Enable ────────────────────────────────────────────────
3184
3262
  enableService(service) {
package/dist/dev.cjs CHANGED
@@ -3570,6 +3570,15 @@ var FirebaseSetup = class {
3570
3570
  if (!(0, import_node_fs4.existsSync)(pkgPath)) {
3571
3571
  return { success: false, message: "functions/package.json not found." };
3572
3572
  }
3573
+ this.ensureFunctionsCJS(functionsDir);
3574
+ const distDir = (0, import_node_path4.resolve)(functionsDir, "dist");
3575
+ if ((0, import_node_fs4.existsSync)(distDir)) {
3576
+ try {
3577
+ (0, import_node_fs4.rmSync)(distDir, { recursive: true, force: true });
3578
+ console.log(" \x1B[32m\u2713\x1B[0m Cleaned functions/dist/");
3579
+ } catch {
3580
+ }
3581
+ }
3573
3582
  try {
3574
3583
  await this.execTimeout("npm", ["install"], 12e4, functionsDir);
3575
3584
  } catch (err) {
@@ -3586,11 +3595,80 @@ var FirebaseSetup = class {
3586
3595
  await this.execTimeout("npx", ["tsc"], 6e4, functionsDir);
3587
3596
  }
3588
3597
  }
3589
- return { success: true, message: "Functions built successfully." };
3590
3598
  } catch (err) {
3591
3599
  const msg = err instanceof Error ? err.message : "Unknown error";
3592
3600
  return { success: false, message: `Functions build failed: ${msg}` };
3593
3601
  }
3602
+ const mainEntry = (0, import_node_path4.resolve)(functionsDir, "dist/index.js");
3603
+ if (!(0, import_node_fs4.existsSync)(mainEntry)) {
3604
+ return { success: false, message: "Build produced no output (dist/index.js not found)." };
3605
+ }
3606
+ try {
3607
+ const firstLine = (0, import_node_fs4.readFileSync)(mainEntry, "utf-8").split("\n")[0];
3608
+ const isESM = firstLine.startsWith("import ") || firstLine.startsWith("export ");
3609
+ if (isESM) {
3610
+ console.log(" \x1B[33m\u26A0\x1B[0m Warning: dist/index.js appears to be ESM, not CJS");
3611
+ } else {
3612
+ console.log(" \x1B[32m\u2713\x1B[0m Build output verified (CJS)");
3613
+ }
3614
+ } catch {
3615
+ }
3616
+ try {
3617
+ const verifyScript = [
3618
+ 'process.env.FIREBASE_CONFIG=JSON.stringify({projectId:"verify"});',
3619
+ 'process.env.GCLOUD_PROJECT="verify";',
3620
+ 'try{require("./dist/index.js");console.log("OK")}',
3621
+ 'catch(e){console.error("LOAD_ERROR:"+e.message);process.exit(1)}'
3622
+ ].join("");
3623
+ await this.execTimeout("node", ["-e", verifyScript], 15e3, functionsDir);
3624
+ console.log(" \x1B[32m\u2713\x1B[0m Module load verification passed");
3625
+ } catch (verifyErr) {
3626
+ const msg = verifyErr instanceof Error ? verifyErr.message : "Unknown";
3627
+ const match = msg.match(/LOAD_ERROR:(.+?)(\n|$)/);
3628
+ const detail = match ? match[1].trim() : msg.substring(0, 300);
3629
+ console.log(` \x1B[31m\u2717\x1B[0m Module load failed: ${detail}`);
3630
+ return { success: false, message: `Functions built but failed to load: ${detail}` };
3631
+ }
3632
+ return { success: true, message: "Functions built successfully." };
3633
+ }
3634
+ /**
3635
+ * Ensure functions/ uses CommonJS for Firebase Functions compatibility.
3636
+ * ESM + Firebase CLI analysis often fails. Auto-fix if needed.
3637
+ */
3638
+ ensureFunctionsCJS(functionsDir) {
3639
+ const pkgPath = (0, import_node_path4.resolve)(functionsDir, "package.json");
3640
+ try {
3641
+ const pkg = JSON.parse((0, import_node_fs4.readFileSync)(pkgPath, "utf-8"));
3642
+ if (pkg.type === "module") {
3643
+ delete pkg.type;
3644
+ (0, import_node_fs4.writeFileSync)(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf-8");
3645
+ console.log(' \x1B[32m\u2713\x1B[0m Auto-fixed: removed "type": "module" from functions/package.json');
3646
+ }
3647
+ } catch {
3648
+ }
3649
+ const tsconfigPath = (0, import_node_path4.resolve)(functionsDir, "tsconfig.json");
3650
+ try {
3651
+ if ((0, import_node_fs4.existsSync)(tsconfigPath)) {
3652
+ let content = (0, import_node_fs4.readFileSync)(tsconfigPath, "utf-8");
3653
+ const tsconfig = JSON.parse(content);
3654
+ let changed = false;
3655
+ const mod = (tsconfig.compilerOptions?.module || "").toLowerCase();
3656
+ if (mod === "esnext" || mod === "es2022" || mod === "es2020" || mod === "nodenext" || mod === "node16") {
3657
+ tsconfig.compilerOptions.module = "CommonJS";
3658
+ changed = true;
3659
+ }
3660
+ const res = (tsconfig.compilerOptions?.moduleResolution || "").toLowerCase();
3661
+ if (res === "bundler" || res === "nodenext" || res === "node16") {
3662
+ tsconfig.compilerOptions.moduleResolution = "node";
3663
+ changed = true;
3664
+ }
3665
+ if (changed) {
3666
+ (0, import_node_fs4.writeFileSync)(tsconfigPath, JSON.stringify(tsconfig, null, 2) + "\n", "utf-8");
3667
+ console.log(" \x1B[32m\u2713\x1B[0m Auto-fixed: functions/tsconfig.json \u2192 CommonJS + node resolution");
3668
+ }
3669
+ }
3670
+ } catch {
3671
+ }
3594
3672
  }
3595
3673
  // ─── Service Enable ────────────────────────────────────────────────
3596
3674
  enableService(service) {