@arcote.tech/arc-cli 0.7.1 → 0.7.2

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/index.js CHANGED
@@ -26942,7 +26942,9 @@ async function buildContextClient(pkg, rootDir, client, cache, noCache) {
26942
26942
  console.log(` building: ${pkg.name} (${client.name})`);
26943
26943
  const peerDeps = Object.keys(pkg.packageJson.peerDependencies ?? {});
26944
26944
  const allDeps = pkg.packageJson.dependencies ?? {};
26945
- const externals = [...peerDeps, ...Object.keys(allDeps)];
26945
+ const isBrowser2 = client.name === "browser";
26946
+ const workspaceDeps = isBrowser2 ? Object.keys(allDeps) : Object.entries(allDeps).filter(([, spec]) => !spec.startsWith("workspace:")).map(([name]) => name);
26947
+ const externals = [...peerDeps, ...workspaceDeps];
26946
26948
  const result = await Bun.build({
26947
26949
  entrypoints: [pkg.entrypoint],
26948
26950
  outdir: join8(outDir, "main"),
@@ -26971,9 +26973,39 @@ async function buildContextPackages(rootDir, packages, cache, noCache) {
26971
26973
  const contexts = packages.filter((p) => isContextPackage(p.packageJson));
26972
26974
  if (contexts.length === 0)
26973
26975
  return { declarationErrors: [] };
26974
- const tasks = contexts.flatMap((pkg) => CONTEXT_CLIENTS.map((client) => () => buildContextClient(pkg, rootDir, client, cache, noCache)));
26975
- const results = await pAll(tasks);
26976
- const declarationErrors = results.flatMap((r) => r.declarationErrors);
26976
+ const byName = new Map(contexts.map((p) => [p.name, p]));
26977
+ const remaining = new Set(contexts.map((p) => p.name));
26978
+ const done = new Set;
26979
+ const ordered = [];
26980
+ const workspaceDepsOf = (pkg) => {
26981
+ const deps = pkg.packageJson.dependencies ?? {};
26982
+ return Object.entries(deps).filter(([name, spec]) => spec.startsWith("workspace:") && byName.has(name)).map(([name]) => name);
26983
+ };
26984
+ while (remaining.size > 0) {
26985
+ const layer = [];
26986
+ for (const name of remaining) {
26987
+ const pkg = byName.get(name);
26988
+ const unmetDeps = workspaceDepsOf(pkg).filter((d) => !done.has(d));
26989
+ if (unmetDeps.length === 0)
26990
+ layer.push(pkg);
26991
+ }
26992
+ if (layer.length === 0) {
26993
+ const cycle = [...remaining].join(", ");
26994
+ throw new Error(`Workspace dependency cycle detected: ${cycle}`);
26995
+ }
26996
+ ordered.push(layer);
26997
+ for (const pkg of layer) {
26998
+ done.add(pkg.name);
26999
+ remaining.delete(pkg.name);
27000
+ }
27001
+ }
27002
+ const declarationErrors = [];
27003
+ for (const layer of ordered) {
27004
+ const tasks = layer.flatMap((pkg) => CONTEXT_CLIENTS.map((client) => () => buildContextClient(pkg, rootDir, client, cache, noCache)));
27005
+ const results = await pAll(tasks);
27006
+ for (const r of results)
27007
+ declarationErrors.push(...r.declarationErrors);
27008
+ }
26977
27009
  if (declarationErrors.length > 0) {
26978
27010
  console.warn(`
26979
27011
  \x1B[33mType declaration errors:\x1B[0m`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcote.tech/arc-cli",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "CLI tool for Arc framework",
5
5
  "module": "index.ts",
6
6
  "main": "dist/index.js",
@@ -12,12 +12,12 @@
12
12
  "build": "bun build --target=bun ./src/index.ts --outdir=dist --external @arcote.tech/arc --external @arcote.tech/arc-ds --external @arcote.tech/arc-react --external @arcote.tech/platform && chmod +x dist/index.js"
13
13
  },
14
14
  "dependencies": {
15
- "@arcote.tech/arc": "^0.7.1",
16
- "@arcote.tech/arc-ds": "^0.7.1",
17
- "@arcote.tech/arc-react": "^0.7.1",
18
- "@arcote.tech/arc-host": "^0.7.1",
19
- "@arcote.tech/arc-adapter-db-sqlite": "^0.7.1",
20
- "@arcote.tech/platform": "^0.7.1",
15
+ "@arcote.tech/arc": "^0.7.2",
16
+ "@arcote.tech/arc-ds": "^0.7.2",
17
+ "@arcote.tech/arc-react": "^0.7.2",
18
+ "@arcote.tech/arc-host": "^0.7.2",
19
+ "@arcote.tech/arc-adapter-db-sqlite": "^0.7.2",
20
+ "@arcote.tech/platform": "^0.7.2",
21
21
  "@clack/prompts": "^0.9.0",
22
22
  "commander": "^11.1.0",
23
23
  "chokidar": "^3.5.3",
@@ -277,26 +277,32 @@ async function buildContextClient(
277
277
 
278
278
  console.log(` building: ${pkg.name} (${client.name})`);
279
279
 
280
- // Externals: framework peers + npm dependencies + workspace deps.
280
+ // Externals depend on the target client:
281
281
  //
282
- // Workspace deps used to be bundled inline (because the deploy image has
283
- // no workspace symlinks). The consequence: every context package's dist
284
- // carried its own copy of every workspace dep — `@ndt/strategy/dist`
285
- // shipped `@ndt/workspace` inlined, `@ndt/content/dist` shipped another
286
- // copy, etc. At deploy-build time the top-level Bun.build saw N
287
- // pre-inlined copies and could no longer dedupe them — context-package
288
- // singletons (e.g. `WorkspaceContext = createContext`) duplicated per
289
- // entry, breaking `useWorkspace()` provider lookup.
282
+ // - BROWSER client: workspace deps MUST be external. Inlining them per
283
+ // package would make every context package's dist ship its own copy
284
+ // of every workspace dep — the top-level browser Bun.build would see
285
+ // N pre-inlined copies of context singletons (`WorkspaceContext =
286
+ // createContext`) and could not dedupe them, breaking provider lookup.
290
287
  //
291
- // Treating workspace deps as `external` makes per-package dist emit bare
292
- // specifiers (`import { workspace } from "@ndt/workspace"`), which the
293
- // browser-side Bun.build then resolves ONCE across all entries → single
294
- // module instance, splitting hoists into a shared chunk. The deploy
295
- // image is unaffected: the browser bundle is self-contained at that
296
- // layer (we only ship the final chunks, not per-package dist/browser).
288
+ // - SERVER client: workspace deps MUST be bundled inline. The deploy
289
+ // image flattens each package's server bundle to
290
+ // `.arc/platform/server/<pkg>.js` and runs them via a single
291
+ // `loadServerContext()` import loop. There is no `node_modules/@ndt/*`
292
+ // tree inside the image, so bare `@ndt/workspace` specifiers would
293
+ // fail to resolve at startup. Inline duplication is harmless on the
294
+ // server: it's a single Node/Bun process and Arc modules register via
295
+ // a shared platform registry singleton (registry.ts), so two physical
296
+ // copies of the workspace module still merge into one context.
297
297
  const peerDeps = Object.keys(pkg.packageJson.peerDependencies ?? {});
298
298
  const allDeps = (pkg.packageJson.dependencies ?? {}) as Record<string, string>;
299
- const externals = [...peerDeps, ...Object.keys(allDeps)];
299
+ const isBrowser = client.name === "browser";
300
+ const workspaceDeps = isBrowser
301
+ ? Object.keys(allDeps)
302
+ : Object.entries(allDeps)
303
+ .filter(([, spec]) => !spec.startsWith("workspace:"))
304
+ .map(([name]) => name);
305
+ const externals = [...peerDeps, ...workspaceDeps];
300
306
 
301
307
  const result = await Bun.build({
302
308
  entrypoints: [pkg.entrypoint],
@@ -349,14 +355,51 @@ export async function buildContextPackages(
349
355
  const contexts = packages.filter((p) => isContextPackage(p.packageJson));
350
356
  if (contexts.length === 0) return { declarationErrors: [] };
351
357
 
352
- const tasks = contexts.flatMap((pkg) =>
353
- CONTEXT_CLIENTS.map((client) => () =>
354
- buildContextClient(pkg, rootDir, client, cache, noCache),
355
- ),
356
- );
358
+ // Topological order each package's server bundle inlines its workspace
359
+ // deps, so those deps must have their `dist/` ready before Bun.build tries
360
+ // to resolve them. Without this, a fresh checkout (no dist/ yet) fails the
361
+ // first build because content's resolve of @ndt/strategy hits a missing
362
+ // file. Inside a topological level, packages are built in parallel.
363
+ const byName = new Map(contexts.map((p) => [p.name, p]));
364
+ const remaining = new Set(contexts.map((p) => p.name));
365
+ const done = new Set<string>();
366
+ const ordered: WorkspacePackage[][] = [];
367
+
368
+ const workspaceDepsOf = (pkg: WorkspacePackage): string[] => {
369
+ const deps = (pkg.packageJson.dependencies ?? {}) as Record<string, string>;
370
+ return Object.entries(deps)
371
+ .filter(([name, spec]) => spec.startsWith("workspace:") && byName.has(name))
372
+ .map(([name]) => name);
373
+ };
374
+
375
+ while (remaining.size > 0) {
376
+ const layer: WorkspacePackage[] = [];
377
+ for (const name of remaining) {
378
+ const pkg = byName.get(name)!;
379
+ const unmetDeps = workspaceDepsOf(pkg).filter((d) => !done.has(d));
380
+ if (unmetDeps.length === 0) layer.push(pkg);
381
+ }
382
+ if (layer.length === 0) {
383
+ const cycle = [...remaining].join(", ");
384
+ throw new Error(`Workspace dependency cycle detected: ${cycle}`);
385
+ }
386
+ ordered.push(layer);
387
+ for (const pkg of layer) {
388
+ done.add(pkg.name);
389
+ remaining.delete(pkg.name);
390
+ }
391
+ }
357
392
 
358
- const results = await pAll(tasks);
359
- const declarationErrors = results.flatMap((r) => r.declarationErrors);
393
+ const declarationErrors: string[] = [];
394
+ for (const layer of ordered) {
395
+ const tasks = layer.flatMap((pkg) =>
396
+ CONTEXT_CLIENTS.map((client) => () =>
397
+ buildContextClient(pkg, rootDir, client, cache, noCache),
398
+ ),
399
+ );
400
+ const results = await pAll(tasks);
401
+ for (const r of results) declarationErrors.push(...r.declarationErrors);
402
+ }
360
403
 
361
404
  if (declarationErrors.length > 0) {
362
405
  console.warn("\n\x1b[33mType declaration errors:\x1b[0m");