@zenbujs/core 0.0.1 → 0.0.3

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.
@@ -1,4 +1,4 @@
1
- import { a as findBuildConfig, o as loadBuildConfig, r as initSeedRepo } from "./mirror-sync-CodOnwkD.mjs";
1
+ import { n as loadBuildConfig, t as findBuildConfig } from "./load-build-config-DozuRhAN.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import fs from "node:fs";
4
4
  import os from "node:os";
@@ -7,8 +7,8 @@ import { fileURLToPath } from "node:url";
7
7
  import crypto from "node:crypto";
8
8
  import fsp from "node:fs/promises";
9
9
  import { execFile, execFileSync, spawn } from "node:child_process";
10
- import { promisify } from "node:util";
11
10
  import https from "node:https";
11
+ import { promisify } from "node:util";
12
12
  //#region src/cli/lib/toolchain.ts
13
13
  const execFileAsync = promisify(execFile);
14
14
  /**
@@ -216,10 +216,7 @@ function resolveProjectDir() {
216
216
  * as a zen flag (and unknown flags error out).
217
217
  */
218
218
  function parseFlags(argv) {
219
- const flags = {
220
- noSource: false,
221
- passthrough: []
222
- };
219
+ const flags = { passthrough: [] };
223
220
  let sawSeparator = false;
224
221
  for (let i = 0; i < argv.length; i++) {
225
222
  const arg = argv[i];
@@ -233,10 +230,9 @@ function parseFlags(argv) {
233
230
  }
234
231
  if (arg === "--config" || arg === "-c") flags.config = argv[++i];
235
232
  else if (arg.startsWith("--config=")) flags.config = arg.slice(9);
236
- else if (arg === "--no-source") flags.noSource = true;
237
233
  else {
238
234
  console.error(`zen build:electron: unknown flag "${arg}"`);
239
- console.error(`valid: zen build:electron [--config <zenbu.build.ts>] [--no-source] [-- <electron-builder args>]`);
235
+ console.error(`valid: zen build:electron [--config <zenbu.build.ts>] [-- <electron-builder args>]`);
240
236
  process.exit(1);
241
237
  }
242
238
  }
@@ -330,35 +326,15 @@ function readElectronBuilderConfig(projectDir) {
330
326
  if (path.basename(found.path) === "package.json") return { ...readJson(found.path).build ?? {} };
331
327
  return readJson(found.path);
332
328
  }
333
- async function ensureSource(projectDir, config, noSource) {
334
- const stagingDir = path.resolve(projectDir, config.out);
335
- const shaPath = path.join(stagingDir, ".sha");
336
- const currentSha = (() => {
337
- try {
338
- return execFileSync("git", ["rev-parse", "HEAD"], {
339
- cwd: projectDir,
340
- encoding: "utf8"
341
- }).trim();
342
- } catch {
343
- return "uncommitted";
344
- }
345
- })();
346
- if (fs.existsSync(shaPath)) {
347
- const meta = readJson(shaPath);
348
- if (meta.sourceSha === currentSha) return meta;
349
- if (noSource) {
350
- console.warn(`[build:electron] --no-source: using stale staging (built from ${meta.sourceSha.slice(0, 7)}, current HEAD ${currentSha.slice(0, 7)})`);
351
- return meta;
352
- }
353
- }
354
- if (noSource) {
355
- console.error("zen build:electron: --no-source given but no staging found. Run `zen build:source` first.");
356
- process.exit(1);
329
+ function currentSourceSha(projectDir) {
330
+ try {
331
+ return execFileSync("git", ["rev-parse", "HEAD"], {
332
+ cwd: projectDir,
333
+ encoding: "utf8"
334
+ }).trim();
335
+ } catch {
336
+ return "uncommitted";
357
337
  }
358
- console.log(` → running zen build:source (seed is missing or stale)`);
359
- const { runBuildSource } = await import("./build-source-_q1n1zTV.mjs");
360
- await runBuildSource([]);
361
- return readJson(shaPath);
362
338
  }
363
339
  async function spawnAsync(cmd, args, cwd, env = process.env) {
364
340
  await new Promise((resolve, reject) => {
@@ -384,9 +360,10 @@ async function spawnAsync(cmd, args, cwd, env = process.env) {
384
360
  * entries would not resolve anyway
385
361
  * - `extraResources` additive — we APPEND the toolchain entry to
386
362
  * whatever the user already declared
387
- * - `npmRebuild` forced to false — the seed ships its own
388
- * lockfile and `pnpm install` runs at first
389
- * launch, no rebuild step needed at build time
363
+ * - `npmRebuild` forced to false — the launcher clones the
364
+ * source from the mirror at first launch and
365
+ * runs `pnpm install` then; nothing to rebuild
366
+ * at electron-builder time
390
367
  *
391
368
  * Everything else (`appId`, `productName`, `mac`, `win`, `linux`,
392
369
  * `publish`, `directories.output`, `directories.buildResources`, `asar`,
@@ -399,7 +376,7 @@ function mergeElectronBuilderConfig(userConfig, overlay) {
399
376
  app: overlay.appDir,
400
377
  output: overlay.output
401
378
  };
402
- merged.files = overlay.seedFiles;
379
+ merged.files = overlay.bundleFiles;
403
380
  merged.extraResources = [...Array.isArray(userConfig.extraResources) ? userConfig.extraResources : [], overlay.extraResource];
404
381
  if (userConfig.npmRebuild !== false) merged.npmRebuild = false;
405
382
  if (userConfig.asar === void 0) merged.asar = false;
@@ -413,40 +390,28 @@ async function runBuildElectron(argv) {
413
390
  const projectDir = resolveProjectDir();
414
391
  const flags = parseFlags(argv);
415
392
  const config = await loadBuildConfig(flags.config ? path.resolve(projectDir, flags.config) : findBuildConfig(projectDir));
416
- const meta = await ensureSource(projectDir, config, flags.noSource);
417
- const seedDir = path.resolve(projectDir, config.out);
393
+ const mirrorTarget = config.mirror?.target;
394
+ if (!mirrorTarget) throw new Error("zen build:electron: `mirror.target` is required in zenbu.build.ts. Set mirror: { target: \"<owner>/<repo>\", branch: \"main\" } and run `zen publish:source init` before building.");
395
+ const mirrorBranch = config.mirror?.branch ?? "main";
396
+ const mirrorUrl = expandMirrorUrl(mirrorTarget);
418
397
  const projectPkg = readJson(path.join(projectDir, "package.json"));
419
398
  const appName = projectPkg.name ?? path.basename(projectDir);
420
399
  const appVersion = projectPkg.version ?? "0.0.1";
421
400
  const bundleDir = await fsp.mkdtemp(path.join(os.tmpdir(), `zenbu-electron-${appName}-`));
422
- const stagedSeed = path.join(bundleDir, "seed");
423
401
  const toolchainDir = path.join(bundleDir, "toolchain");
424
402
  const launcherOut = path.join(bundleDir, "launcher.mjs");
425
403
  const bundlePkgOut = path.join(bundleDir, "package.json");
426
404
  const appConfigOut = path.join(bundleDir, "app-config.json");
427
405
  const mergedConfigPath = path.join(bundleDir, "electron-builder.merged.json");
428
- const mirrorTarget = config.mirror?.target ?? null;
429
- const mirrorBranch = config.mirror?.branch ?? "main";
430
- const mirrorUrl = mirrorTarget ? expandMirrorUrl(mirrorTarget) : null;
406
+ const sourceSha = currentSourceSha(projectDir);
431
407
  console.log(`\n zen build:electron`);
432
408
  console.log(` name: ${appName}`);
433
409
  console.log(` version: ${appVersion}`);
434
- console.log(` source: ${meta.sourceSha === "uncommitted" ? "uncommitted" : meta.sourceSha.slice(0, 7)}`);
435
- console.log(` mirror: ${mirrorTarget ?? "(none — set config.mirror.target to enable updates)"}`);
410
+ console.log(` source: ${sourceSha === "uncommitted" ? "uncommitted" : sourceSha.slice(0, 7)}`);
411
+ console.log(` mirror: ${mirrorTarget} (${mirrorBranch})`);
436
412
  console.log(` bundle: ${bundleDir}`);
437
413
  console.log(" → staging launcher.mjs");
438
414
  await copyFile(resolveLauncher(projectDir), launcherOut);
439
- console.log(" → staging seed/");
440
- await fsp.cp(seedDir, stagedSeed, {
441
- recursive: true,
442
- filter: (src) => path.basename(src) !== ".sha"
443
- });
444
- if (mirrorUrl) await initSeedRepo({
445
- dir: stagedSeed,
446
- mirrorUrl,
447
- branch: mirrorBranch,
448
- sourceSha: meta.sourceSha === "uncommitted" ? "0000000000000000000000000000000000000000" : meta.sourceSha
449
- });
450
415
  console.log(" → provisioning bundled toolchain (bun + pnpm)");
451
416
  await provisionToolchain(toolchainDir);
452
417
  console.log(" → writing bundle package.json + app-config.json");
@@ -456,11 +421,11 @@ async function runBuildElectron(argv) {
456
421
  version: appVersion,
457
422
  main: "launcher.mjs",
458
423
  type: "module",
459
- zenbu: { host }
460
- };
461
- if (mirrorUrl) bundlePkg.repository = {
462
- type: "git",
463
- url: mirrorUrl
424
+ zenbu: { host },
425
+ repository: {
426
+ type: "git",
427
+ url: mirrorUrl
428
+ }
464
429
  };
465
430
  await fsp.writeFile(bundlePkgOut, JSON.stringify(bundlePkg, null, 2) + "\n");
466
431
  const appConfig = {
@@ -477,11 +442,10 @@ async function runBuildElectron(argv) {
477
442
  const merged = mergeElectronBuilderConfig(userConfig, {
478
443
  appDir: bundleDir,
479
444
  output: resolvedOutput,
480
- seedFiles: [
445
+ bundleFiles: [
481
446
  "package.json",
482
447
  "app-config.json",
483
448
  "launcher.mjs",
484
- "seed/**/*",
485
449
  "!node_modules",
486
450
  "!**/node_modules",
487
451
  "!**/node_modules/**"
@@ -495,7 +459,7 @@ async function runBuildElectron(argv) {
495
459
  console.log(" → injected into electron-builder config:");
496
460
  console.log(` directories.app = ${bundleDir}`);
497
461
  console.log(` directories.output = ${resolvedOutput}`);
498
- console.log(` files = [zenbu seed]`);
462
+ console.log(` files = [launcher + app-config + bundle pkg]`);
499
463
  console.log(` extraResources += { from: <bundle>/toolchain, to: toolchain }`);
500
464
  console.log(` asar = ${merged.asar !== void 0 ? merged.asar : "(unset)"}`);
501
465
  console.log(` npmRebuild = false`);
@@ -1,4 +1,5 @@
1
- import { a as findBuildConfig, o as loadBuildConfig, t as hashDir } from "./mirror-sync-CodOnwkD.mjs";
1
+ import { n as loadBuildConfig, t as findBuildConfig } from "./load-build-config-DozuRhAN.mjs";
2
+ import { t as hashDir } from "./mirror-sync-BN59kMCG.mjs";
2
3
  import fs from "node:fs";
3
4
  import path from "node:path";
4
5
  import fsp from "node:fs/promises";
package/dist/cli/bin.mjs CHANGED
@@ -44,37 +44,37 @@ async function main() {
44
44
  const rest = argv.slice(1);
45
45
  switch (first) {
46
46
  case "dev": {
47
- const { runDev } = await import("../dev-BuqklM0k.mjs");
47
+ const { runDev } = await import("../dev-BU_llQh1.mjs");
48
48
  await runDev(rest);
49
49
  return;
50
50
  }
51
51
  case "build:source": {
52
- const { runBuildSource } = await import("../build-source-_q1n1zTV.mjs");
52
+ const { runBuildSource } = await import("../build-source-CnTfQBGK.mjs");
53
53
  await runBuildSource(rest);
54
54
  return;
55
55
  }
56
56
  case "build:electron": {
57
- const { runBuildElectron } = await import("../build-electron-B4Gd0Gi4.mjs");
57
+ const { runBuildElectron } = await import("../build-electron-BzHa_hRi.mjs");
58
58
  await runBuildElectron(rest);
59
59
  return;
60
60
  }
61
61
  case "publish:source": {
62
- const { runPublishSource } = await import("../publish-source-BVgB62Zj.mjs");
62
+ const { runPublishSource } = await import("../publish-source-BJdpDAFH.mjs");
63
63
  await runPublishSource(rest);
64
64
  return;
65
65
  }
66
66
  case "link": {
67
- const { runLink } = await import("../link-6roQ7Cn6.mjs");
67
+ const { runLink } = await import("../link-VOoGs-pY.mjs");
68
68
  await runLink(rest);
69
69
  return;
70
70
  }
71
71
  case "monorepo": {
72
- const { runMonorepo } = await import("../monorepo-CmGPHsVm.mjs");
72
+ const { runMonorepo } = await import("../monorepo-CQeQBIpa.mjs");
73
73
  await runMonorepo(rest);
74
74
  return;
75
75
  }
76
76
  case "db": {
77
- const { runDb } = await import("../db-DhuAJrye.mjs");
77
+ const { runDb } = await import("../db-BXadETOb.mjs");
78
78
  await runDb(rest);
79
79
  return;
80
80
  }
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as bootstrapEnv } from "./env-bootstrap-rj7I-59x.mjs";
2
- import { t as setupGate } from "./setup-gate-BeD6WS6d.mjs";
2
+ import { t as setupGate } from "./setup-gate-BcoqWu8S.mjs";
3
3
  import { a as serviceWithDeps, i as runtime, n as ServiceRuntime, r as optional, t as Service } from "./runtime-DUFKDIe4.mjs";
4
4
  import { t as schema } from "./schema-dGK6qkfR.mjs";
5
5
  export { Service, ServiceRuntime, bootstrapEnv, schema as coreSchema, optional, runtime, serviceWithDeps, setupGate };