@north-light/cli 0.3.738 → 0.3.739

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
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- var _=Object.defineProperty;var s=(r,o)=>_(r,"name",{value:o,configurable:!0});import"./suppress-experimental-warnings.js";import{mkdirSync as b,openSync as E,readFileSync as I,renameSync as C,rmSync as O,statSync as h,writeFileSync as k}from"node:fs";import{dirname as w,join as a}from"node:path";import{enableCompileCache as A}from"node:module";import{fileURLToPath as y}from"node:url";import{isDaemonControlInvocation as m,isJoinInvocation as N,isLayoutMigrationInvocation as x,isPkgInstallInvocation as $,isSignInInvocation as P,personOnlyInvocation as T,resolveDaemonControlRoot as F,resolveLayoutMigrationRoot as L,resolveRoot as M}from"./build-root.js";import{maybeBootRoot as D}from"./core/runtime/front-door.js";import{maybeAutoUpdate as j}from"./core/auto-update.js";import{ensureProjectScope as U}from"./core/bootstrap.js";import{provisionExports as B,pruneLegacyExports as K}from"./core/host-exports/export.js";import{revalidateBundlePlugins as J}from"./core/command-plugins/revalidate.js";import{renderNode as V,runCli as v,walk as W}from"./core/command.js";import{dispatchWithStaleRecovery as q}from"./core/manifest-recovery.js";import{installStdoutErrorPolicy as G}from"./core/stdout-errors.js";import{handle as z}from"./core/io.js";import{CrtrError as f,ownerOnly as H}from"./core/errors.js";import{ExitCode as Q}from"./types.js";import{layoutNeedsMigration as X,runtimeRoot as Y}from"./core/layout.js";import{ApiError as R}from"./api/index.js";import{mark as i}from"./core/timing.js";import{launchSnapshotFile as Z,providerProjectionOverBrokerRelay as rr,sandboxCliNodeId as or}from"./shared/env.js";import{nodeRunDir as d}from"./core/canvas/paths.js";import{installBrokerConfigSnapshot as tr}from"./core/config.js";E(y(import.meta.url),"r"),G(),i("cli.entry",{cmd:process.argv[2]??"(bare)"});try{A()}catch{}i("cli.compile_cache");const er=a(w(y(import.meta.url)),".."),l=a(Y(),"first-run.json");function c(r){return(r instanceof Error?r.message:String(r)).split(/\r?\n/,1)[0]??""}s(c,"errorMessage");function ir(r){const o=w(l);b(o,{recursive:!0});const t=`${l}.${process.pid}.${Date.now()}.tmp`;try{k(t,JSON.stringify({packageVersion:r,completedAt:new Date().toISOString()})+`
3
- `,"utf8"),C(t,l)}finally{O(t,{force:!0})}}s(ir,"writeFirstRunMarker");async function nr(){if(process.env.CRTR_NO_AUTO_INIT==="1")return;try{if(h(l,{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile marker check failed: ${c(o)}
4
- `);return}try{if(h(a(er,".git"),{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile source check failed: ${c(o)}
5
- `);return}let r;try{const{reconcileFirstRun:o}=await import("./commands/sys/setup-core.js");r=await o((t,p)=>{process.stderr.write(`crtr: first-run reconcile ${t} failed: ${c(p)}
6
- `)})}catch(o){process.stderr.write(`crtr: first-run reconcile failed: ${c(o)}
7
- `)}finally{if(r!==void 0)try{ir(r)}catch(o){process.stderr.write(`crtr: first-run reconcile marker failed: ${c(o)}
8
- `)}}}s(nr,"maybeReconcileFirstRun");async function sr(){const r=x(process.argv),o=or(),t=o!==void 0;if(o!==void 0){process.env.CRTR_API_SOCKET=a(d(o),"cli.sock");const e=T(process.argv);if(e!==null)throw H(`crtr ${e} is not available to an app's node`,"Run this command from the person's terminal.");const n=JSON.parse(I(Z(d(o))??a(d(o),"broker-launch.json"),"utf8"));if(!n.configSnapshot)throw new Error("node launch is missing its config snapshot");tr(n.configSnapshot)}if(!t&&X()&&!m(process.argv)&&!r)throw new f("layout_migration_required","run crtr sys migrate while the runtime is offline",Q.NETWORK,{next:"Run `crtr sys migrate` while the runtime is offline, then restart it."});if(r){const e=await L();if(process.argv.slice(4).some(n=>n==="-h"||n==="--help")){process.stdout.write(V(W(e,["sys","migrate"]).node)+`
9
- `);return}await v(e,process.argv);return}const p=s(async()=>(await import("./core/scoped-state/person-store.js")).installPreludeSnapshot({profiles:[],defaults:{},settings:{},state:{},apps:{}}),"installEmptySettings");if(!t&&(await import("./commands/api-client.js")).usesRunToken())await p();else if((!t||$(process.argv))&&!m(process.argv)&&!N(process.argv)&&!P(process.argv)){try{t||await(await import("./commands/daemon-generation.js")).assertLocalDaemonMatchesCli(),await(await import("./commands/person-settings.js")).loadPersonSettingsViaApi(),t||await(await import("./core/scoped-state/imported-mac-installs.js")).migrateLegacyInstallsOnce()}catch(e){const n=process.argv.slice(2).some(g=>g==="-h"||g==="--help"),S=e instanceof R&&(e.code==="daemon_unavailable"||e.code==="northlight_unreachable")||e instanceof f&&(e.code==="daemon_generation_mismatch"||e.code==="not_signed_in"||e.code==="move_unfinished"||e.code==="northlight_unreachable");if(!(n&&S))throw e;await p()}i("cli.settings_loaded")}if(t||(K(process.argv),rr()||await nr()),await D(process.argv),i("cli.front_door_passed"),m(process.argv)){await v(await F(),process.argv);return}t||await J(process.argv),i("cli.plugins_revalidated");const u=await M(process.argv[2]);i("cli.root_resolved"),t||(B(u,process.argv),await U(process.argv),await j(process.argv)),i("cli.dispatch_start"),await q(u,process.argv),i("cli.dispatch_done")}s(sr,"main"),sr().catch(r=>{(r instanceof Error&&r.name==="AbortError"||r instanceof Error&&/operation was aborted/i.test(r.message))&&(process.stderr.write(`crtr: Interrupted
10
- `),process.exit(130)),(r instanceof R||r instanceof f)&&(z(r),process.exit(typeof process.exitCode=="number"?process.exitCode:1));const t=r instanceof Error?r.message:String(r);process.stderr.write(`crtr: ${t}
2
+ var I=Object.defineProperty;var s=(r,o)=>I(r,"name",{value:o,configurable:!0});import"./suppress-experimental-warnings.js";import{mkdirSync as b,openSync as E,readFileSync as C,renameSync as O,rmSync as k,statSync as h,writeFileSync as A}from"node:fs";import{dirname as w,join as c}from"node:path";import{enableCompileCache as N}from"node:module";import{fileURLToPath as y}from"node:url";import{isDaemonControlInvocation as l,isJoinInvocation as x,isLayoutMigrationInvocation as $,isPkgInstallInvocation as P,isSignInInvocation as T,personOnlyInvocation as F,resolveDaemonControlRoot as L,resolveLayoutMigrationRoot as M,resolveRoot as D}from"./build-root.js";import{maybeBootRoot as U}from"./core/runtime/front-door.js";import{maybeAutoUpdate as j}from"./core/auto-update.js";import{ensureProjectScope as B}from"./core/bootstrap.js";import{provisionExports as K,pruneLegacyExports as J}from"./core/host-exports/export.js";import{revalidateBundlePlugins as V}from"./core/command-plugins/revalidate.js";import{renderNode as W,runCli as v,walk as q}from"./core/command.js";import{dispatchWithStaleRecovery as G}from"./core/manifest-recovery.js";import{installStdoutErrorPolicy as z}from"./core/stdout-errors.js";import{handle as H}from"./core/io.js";import{CrtrError as f,ownerOnly as Q}from"./core/errors.js";import{ExitCode as X}from"./types.js";import{layoutNeedsMigration as Y,runtimeRoot as Z}from"./core/layout.js";import{ApiError as R}from"./api/index.js";import{mark as i}from"./core/timing.js";import{launchSnapshotFile as rr,providerProjectionOverBrokerRelay as S,sandboxCliNodeId as or}from"./shared/env.js";import{nodeRunDir as d}from"./core/canvas/paths.js";import{installBrokerConfigSnapshot as tr}from"./core/config.js";E(y(import.meta.url),"r"),z(),i("cli.entry",{cmd:process.argv[2]??"(bare)"});try{N()}catch{}i("cli.compile_cache");const er=c(w(y(import.meta.url)),".."),m=c(Z(),"first-run.json");function p(r){return(r instanceof Error?r.message:String(r)).split(/\r?\n/,1)[0]??""}s(p,"errorMessage");function ir(r){const o=w(m);b(o,{recursive:!0});const t=`${m}.${process.pid}.${Date.now()}.tmp`;try{A(t,JSON.stringify({packageVersion:r,completedAt:new Date().toISOString()})+`
3
+ `,"utf8"),O(t,m)}finally{k(t,{force:!0})}}s(ir,"writeFirstRunMarker");async function nr(){if(process.env.CRTR_NO_AUTO_INIT==="1")return;try{if(h(m,{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile marker check failed: ${p(o)}
4
+ `);return}try{if(h(c(er,".git"),{throwIfNoEntry:!1})!==void 0)return}catch(o){process.stderr.write(`crtr: first-run reconcile source check failed: ${p(o)}
5
+ `);return}let r;try{const{reconcileFirstRun:o}=await import("./commands/sys/setup-core.js");r=await o((t,a)=>{process.stderr.write(`crtr: first-run reconcile ${t} failed: ${p(a)}
6
+ `)})}catch(o){process.stderr.write(`crtr: first-run reconcile failed: ${p(o)}
7
+ `)}finally{if(r!==void 0)try{ir(r)}catch(o){process.stderr.write(`crtr: first-run reconcile marker failed: ${p(o)}
8
+ `)}}}s(nr,"maybeReconcileFirstRun");async function sr(){const r=$(process.argv),o=or(),t=o!==void 0;if(o!==void 0){process.env.CRTR_API_SOCKET=c(d(o),"cli.sock");const e=F(process.argv);if(e!==null)throw Q(`crtr ${e} is not available to an app's node`,"Run this command from the person's terminal.");const n=JSON.parse(C(rr(d(o))??c(d(o),"broker-launch.json"),"utf8"));if(!n.configSnapshot)throw new Error("node launch is missing its config snapshot");tr(n.configSnapshot)}if(!t&&Y()&&!l(process.argv)&&!r)throw new f("layout_migration_required","run crtr sys migrate while the runtime is offline",X.NETWORK,{next:"Run `crtr sys migrate` while the runtime is offline, then restart it."});if(r){const e=await M();if(process.argv.slice(4).some(n=>n==="-h"||n==="--help")){process.stdout.write(W(q(e,["sys","migrate"]).node)+`
9
+ `);return}await v(e,process.argv);return}const a=s(async()=>(await import("./core/scoped-state/person-store.js")).installPreludeSnapshot({profiles:[],defaults:{},settings:{},state:{},apps:{}}),"installEmptySettings");if(!t&&(await import("./commands/api-client.js")).usesRunToken())await a();else if(!t&&!S()&&(await import("./daemon/machine-link/config.js")).computerIsUnset()&&!l(process.argv))await a();else if((!t||P(process.argv))&&!l(process.argv)&&!x(process.argv)&&!T(process.argv)){try{t||await(await import("./commands/daemon-generation.js")).assertLocalDaemonMatchesCli(),await(await import("./commands/person-settings.js")).loadPersonSettingsViaApi(),t||await(await import("./core/scoped-state/imported-mac-installs.js")).migrateLegacyInstallsOnce()}catch(e){const n=process.argv.slice(2).some(g=>g==="-h"||g==="--help"),_=e instanceof R&&(e.code==="daemon_unavailable"||e.code==="northlight_unreachable")||e instanceof f&&(e.code==="daemon_generation_mismatch"||e.code==="not_signed_in"||e.code==="move_unfinished"||e.code==="northlight_unreachable");if(!(n&&_))throw e;await a()}i("cli.settings_loaded")}if(t||(J(process.argv),S()||await nr()),await U(process.argv),i("cli.front_door_passed"),l(process.argv)){await v(await L(),process.argv);return}t||await V(process.argv),i("cli.plugins_revalidated");const u=await D(process.argv[2]);i("cli.root_resolved"),t||(K(u,process.argv),await B(process.argv),await j(process.argv)),i("cli.dispatch_start"),await G(u,process.argv),i("cli.dispatch_done")}s(sr,"main"),sr().catch(r=>{(r instanceof Error&&r.name==="AbortError"||r instanceof Error&&/operation was aborted/i.test(r.message))&&(process.stderr.write(`crtr: Interrupted
10
+ `),process.exit(130)),(r instanceof R||r instanceof f)&&(H(r),process.exit(typeof process.exitCode=="number"?process.exitCode:1));const t=r instanceof Error?r.message:String(r);process.stderr.write(`crtr: ${t}
11
11
  `),process.exit(1)});