@arcote.tech/arc-cli 0.7.19 → 0.7.21

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.
@@ -524,6 +524,9 @@ export async function startPlatformServer(
524
524
  mode: devMode ? "development" : "production",
525
525
  sampleRate: devMode ? 1.0 : 1.0, // head-based 100%, collector tail-samples
526
526
  debug: process.env.ARC_OTEL_DEBUG === "true",
527
+ // Production kill-switch for the console→OTLP bridge. Container
528
+ // stdout still reaches Loki via Alloy regardless.
529
+ patchConsole: process.env.ARC_OTEL_PATCH_CONSOLE !== "false",
527
530
  });
528
531
  telemetry = init.telemetry;
529
532
  telemetryShutdown = init.shutdown;
@@ -4,10 +4,12 @@ import { dirname, join } from "path";
4
4
  import {
5
5
  buildBrowserApp,
6
6
  buildContextPackages,
7
+ buildServerApp,
7
8
  buildStyles,
8
9
  buildTranslations,
9
10
  discoverPackages,
10
11
  isContextPackage,
12
+ SERVER_ENTRY_FILE,
11
13
  type BrowserAppResult,
12
14
  type BuildManifest,
13
15
  type ModuleDescriptor,
@@ -161,20 +163,30 @@ export async function buildAll(
161
163
  // else chunk grouping (per-package) silently mis-assigns the extra module.
162
164
  assertOneModulePerPackage(ws.packages);
163
165
 
164
- // Phase 1 — context packages must finish FIRST. The access-extractor
165
- // subprocess imports workspace packages by name, which resolve through
166
- // node_modules to packages' `main` field (typically `dist/server/main/`).
166
+ // Phase 1 — per-package BROWSER context bundles + type declarations.
167
167
  await buildContextPackages(ws.rootDir, ws.packages, cache, noCache);
168
168
 
169
- // Phase 1b — relocate per-package server bundles into `.arc/platform/server/`
170
- // so the deploy image can be self-contained (image COPY needs everything
171
- // server-side under one root). loadServerContext reads from here in prod.
172
- copyContextServerBundles(ws);
169
+ // Phase 1b — combined server bundle at `.arc/platform/server/_server.js`.
170
+ // ONE Bun.build for all context modules (deduped from source, cycle-safe)
171
+ // replaces the old per-package server bundles that nested each other's dist
172
+ // into multi-hundred-MB files. The deploy image COPYs this dir wholesale;
173
+ // loadServerContext + the access extractor import the entry, chunks ride along.
174
+ const serverDir = join(ws.arcDir, "server");
175
+ const { entryFile: serverEntry } = await buildServerApp(
176
+ ws.rootDir,
177
+ serverDir,
178
+ ws.packages,
179
+ cache,
180
+ noCache,
181
+ );
173
182
 
174
183
  // Phase 2 — extract access metadata (token name + hasCheck per module) in
175
- // an isolated subprocess. This MUST run before chunk planning so we know
176
- // which token group each module belongs to.
177
- const accessMap = await extractAccessMap(ws.rootDir, ws.packages);
184
+ // an isolated subprocess that imports the combined server bundle. MUST run
185
+ // before chunk planning so we know which token group each module belongs to.
186
+ const accessMap = await extractAccessMap(
187
+ ws.rootDir,
188
+ join(serverDir, serverEntry),
189
+ );
178
190
 
179
191
  // Persist access map for the runtime host (server.ts reads at startup to
180
192
  // wire up moduleAccessMap for filterManifestForTokens / signed URLs).
@@ -242,34 +254,6 @@ function assembleManifest(
242
254
  };
243
255
  }
244
256
 
245
- // ---------------------------------------------------------------------------
246
- // Context server bundles — flatten to `<arcDir>/server/<safeName>.js`
247
- // ---------------------------------------------------------------------------
248
-
249
- /**
250
- * Copy each context package's compiled server bundle from
251
- * `packages/<pkg>/dist/server/main/index.js` to a flat location at
252
- * `<arcDir>/server/<safeName>.js`. The flat layout makes the deploy image
253
- * self-contained — `COPY .arc/platform/` pulls everything server-side, no
254
- * need to drag the entire `packages/` tree into the image.
255
- */
256
- function copyContextServerBundles(ws: WorkspaceInfo): void {
257
- const outDir = join(ws.arcDir, "server");
258
- mkdirSync(outDir, { recursive: true });
259
-
260
- for (const pkg of ws.packages) {
261
- if (!isContextPackage(pkg.packageJson)) continue;
262
- const src = join(pkg.path, "dist", "server", "main", "index.js");
263
- if (!existsSync(src)) {
264
- err(`Server bundle missing for ${pkg.name}: ${src}`);
265
- continue;
266
- }
267
- const safeName = pkg.path.split("/").pop()!;
268
- const dst = join(outDir, `${safeName}.js`);
269
- copyFileSync(src, dst);
270
- }
271
- }
272
-
273
257
  // ---------------------------------------------------------------------------
274
258
  // Browser assets — @arcote.tech/* deps deklarują w `arc.browserAssets` jakie
275
259
  // pliki muszą być dostępne w przeglądarce (np. SQLite WASM worker + .wasm).
@@ -419,44 +403,21 @@ export async function loadServerContext(
419
403
 
420
404
  await import(platformEntry);
421
405
 
422
- // Primary source: flattened server bundles at `<arcDir>/server/<safeName>.js`.
406
+ // The combined server bundle lives at `<arcDir>/server/_server.js` (entry)
407
+ // next to its `chunk-<hash>.js` siblings. Importing the entry pulls the
408
+ // chunks transitively and registers every module via the platform singleton.
423
409
  // The deploy image only has this directory — there's no workspace `packages/`
424
- // tree. In dev, `copyContextServerBundles` populates this same location, so
425
- // both modes go through the same code path.
426
- const serverDir = join(ws.arcDir, "server");
427
- const bundles = existsSync(serverDir)
428
- ? readdirSync(serverDir).filter((f) => f.endsWith(".js"))
429
- : [];
430
-
431
- if (bundles.length > 0) {
432
- for (const file of bundles) {
433
- const bundlePath = join(serverDir, file);
434
- try {
435
- await import(bundlePath);
436
- } catch (e) {
437
- err(`Failed to load server bundle ${file}: ${e}`);
438
- }
439
- }
440
- } else if (ws.packages.length > 0) {
441
- // Fallback for the "no .arc/platform/server/ yet" case (e.g. somebody
442
- // wired up loadServerContext before running the build). This path goes
443
- // through workspace packages directly — only meaningful in dev.
444
- const ctxPackages = ws.packages.filter((p) => isContextPackage(p.packageJson));
445
- for (const ctx of ctxPackages) {
446
- const serverDist = join(ctx.path, "dist", "server", "main", "index.js");
447
- if (!existsSync(serverDist)) {
448
- err(`Context server dist not found: ${serverDist}`);
449
- continue;
450
- }
451
- try {
452
- await import(serverDist);
453
- } catch (e) {
454
- err(`Failed to load server context from ${ctx.name}: ${e}`);
455
- }
456
- }
457
- } else {
410
+ // tree; dev and prod go through the exact same path.
411
+ const serverEntry = join(ws.arcDir, "server", SERVER_ENTRY_FILE);
412
+ if (!existsSync(serverEntry)) {
413
+ // No build yet (or a static-only workspace) — nothing to register.
458
414
  return { context: null, moduleAccess: new Map() };
459
415
  }
416
+ try {
417
+ await import(serverEntry);
418
+ } catch (e) {
419
+ err(`Failed to load server bundle ${SERVER_ENTRY_FILE}: ${e}`);
420
+ }
460
421
 
461
422
  const { getContext, getAllModuleAccess } = await import(platformEntry);
462
423
  return {
@@ -62,8 +62,8 @@ export async function startPlatform(
62
62
  }
63
63
 
64
64
  // 2. Server context — same code path in both modes; loadServerContext
65
- // prefers .arc/platform/server/*.js (the canonical location after the
66
- // copyContextServerBundles step in buildAll).
65
+ // imports the combined server bundle at .arc/platform/server/_server.js
66
+ // (produced by the buildServerApp step in buildAll).
67
67
  log("Loading server context...");
68
68
  const { context, moduleAccess } = await loadServerContext(ws);
69
69
  if (context) {