knarr 0.1.0 → 0.1.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/README.md CHANGED
@@ -16,9 +16,9 @@
16
16
 
17
17
  # Knarr
18
18
 
19
- Test local npm packages in real apps without `npm link`, duplicate React, or dirty `package.json` diffs.
19
+ Test local npm packages in real apps without `npm link` symlink surprises or local package references in `package.json`.
20
20
 
21
- Knarr copies the built package output directly into the consumer app's `node_modules/`, so your package behaves like the version you would publish to npm. It works well with pnpm, Vite, Next.js, Webpack/rspack, Turbopack, and teams that want local package overrides to stay out of git.
21
+ Knarr copies the package files you would publish into the consumer app's `node_modules/`, then keeps registered consumers updated. It detects npm, pnpm, Bun, and Yarn projects that use `node_modules` or Yarn's pnpm linker. Yarn PnP is not compatible because it removes `node_modules`.
22
22
 
23
23
  ```bash
24
24
  cd my-app
@@ -35,15 +35,17 @@ If you have not installed Knarr globally, use `npx knarr dev` for the second com
35
35
  ## Who this is for
36
36
 
37
37
  - Library and design-system authors testing packages inside real consumer apps
38
- - React developers avoiding duplicate React instances and invalid hook calls from symlinks
39
- - pnpm users where `npm link` or yalc do not match the installed dependency tree
40
- - Teams that want clean git diffs while iterating on local packages
38
+ - React developers avoiding duplicate dependency instances and invalid hook calls from symlinks
39
+ - pnpm users who want updates copied into the existing virtual-store install when possible
40
+ - Teams that want local package overrides to stay out of dependency specs and lockfiles
41
41
 
42
42
  ## Why Knarr?
43
43
 
44
- `npm link` creates symlinks that can break module resolution: duplicate React instances, peer dependency mismatches, and bundlers that cannot follow links outside the project root. yalc improves this by copying files, but it rewrites consumer dependency specs and usually needs extra watch tooling.
44
+ `npm link` creates symlinks that can break module resolution: duplicate dependency instances, peer dependency mismatches, and bundlers that cannot follow links outside the project root. yalc improves this by copying files, but its workflow can rewrite consumer dependency specs or require extra watch tooling.
45
45
 
46
- Knarr keeps your `package.json` and lockfile clean. It publishes a local package into `~/.knarr/store/`, injects that package into every registered consumer, and can watch, rebuild, and push changes continuously.
46
+ Knarr keeps the local override out of your dependency spec. It publishes a local package into `~/.knarr/store/`, injects that package into every registered consumer, and can watch, rebuild, and push changes continuously. Setup helpers may still add `.knarr/`, `.gitignore`, a restore hook, or bundler config when needed.
47
+
48
+ If pnpm workspaces, `file:`, or `dependenciesMeta.*.injected` already fit your repo, use those native features first. Knarr is for the narrower case where you want publishable package files copied into real consumers while their dependency specs stay normal.
47
49
 
48
50
  ## Quick Start
49
51
 
@@ -65,7 +67,7 @@ knarr dev
65
67
 
66
68
  If Knarr is not installed globally, run `npx knarr dev` instead.
67
69
 
68
- That is the everyday loop: edit `my-lib`, Knarr rebuilds it, pushes changed files into `my-app/node_modules/`, and your bundler sees the update.
70
+ That is the everyday loop: edit `my-lib`, Knarr rebuilds it, pushes changed files into `my-app/node_modules/`, and your dev server sees normal file changes there.
69
71
 
70
72
  If you prefer the explicit steps:
71
73
 
@@ -98,20 +100,20 @@ graph LR
98
100
  4. `push` publishes and copies to all registered consumers
99
101
  5. `dev` watches, builds, publishes, and pushes continuously
100
102
 
101
- ## At A Glance
103
+ ## What Knarr Does
102
104
 
103
- | | npm link | yalc | Knarr |
104
- | ---------------------- | ----------------------- | --------------------------- | ------------------- |
105
- | Mechanism | Symlinks | Copy + package.json rewrite | Copy only |
106
- | Module resolution | Broken (dual instances) | Works | Works |
107
- | Git contamination | None | package.json + .yalc/ | None |
108
- | Bundler HMR | Often broken | Varies | Works |
109
- | pnpm support | Fragile | Limited | Full |
110
- | Watch mode | None | External | Built-in |
111
- | Survives `npm install` | No | No | `knarr restore` |
112
- | Incremental sync | N/A | Full copy each time | mtime + xxhash diff |
105
+ | Area | Behavior |
106
+ | --- | --- |
107
+ | Store | `~/.knarr/store/<name>@<version>/package/`, or `KNARR_HOME/store/...` when `KNARR_HOME` is set |
108
+ | Consumer copy | Copies package files into `node_modules/<package>/` and records link state in `.knarr/state.json` |
109
+ | Package files | Uses npm-pack-compatible file resolution, including the `files` field and `publishConfig.directory` |
110
+ | pnpm | Follows existing pnpm virtual-store symlinks when present; falls back to a direct `node_modules` path |
111
+ | Watch loop | `knarr dev` runs an initial push, then watches, rebuilds, publishes, and pushes again |
112
+ | Reinstall recovery | `knarr restore` re-injects registered packages after `node_modules` is replaced |
113
+ | Bundlers | Vite plugin triggers reload/restart, Next.js uses `transpilePackages`, Webpack/rspack plugin invalidates watch/cache, and other bundlers rely on file changes under `node_modules` |
114
+ | Incremental sync | Skips same size and mtime, hashes same-size changed-mtime files with xxHash64, and removes stale destination files |
113
115
 
114
- See [detailed comparison](docs/comparison.md) for a deeper breakdown.
116
+ See [detailed comparison](docs/comparison.md) for native pnpm options, yalc, symlink workflows, and Knarr tradeoffs.
115
117
 
116
118
  ## Migrate From yalc In 60 Seconds
117
119
 
@@ -129,13 +131,13 @@ See [Migrating from yalc](docs/migrating-from-yalc.md) for the full guide.
129
131
  ## Install
130
132
 
131
133
  ```bash
132
- pnpm add -g knarr # or npm, yarn, bun
133
- npx knarr init # one-off setup for a consumer project
134
+ pnpm add -g knarr # or npm install -g knarr
135
+ npx knarr init # optional consumer setup and repair helpers
134
136
  ```
135
137
 
136
138
  ## Performance Notes
137
139
 
138
- knarr uses CoW reflinks for instant copy-on-write on APFS/btrfs/ReFS, with automatic fallback. Reflink support is probed once per volume and cached. Incremental sync checks size and mtime first, then falls back to xxhash only when needed, so unchanged files are skipped quickly.
140
+ Knarr uses Node's copy-on-write reflink mode when the current filesystem supports it, with automatic fallback to a normal copy. Reflink support is probed once per volume and cached. Incremental sync checks size and mtime first, then falls back to xxHash64 only when needed, so unchanged files are skipped quickly.
139
141
 
140
142
  ## Documentation
141
143
 
@@ -143,6 +145,7 @@ knarr uses CoW reflinks for instant copy-on-write on APFS/btrfs/ReFS, with autom
143
145
  - [Commands](docs/commands.md)
144
146
  - [Comparison](docs/comparison.md)
145
147
  - [Troubleshooting](docs/troubleshooting.md)
148
+ - [CI/CD](docs/ci-cd.md)
146
149
  - [Examples](examples/)
147
150
  - [Contributing](CONTRIBUTING.md)
148
151
 
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import {createRequire}from'node:module';import {a as a$2}from'./chunk-COI7GWH3.mjs';import {b}from'./chunk-QHNHLR6T.mjs';import {a as a$5}from'./chunk-ABG6UD3X.mjs';import {a as a$4}from'./chunk-XDWZZBCM.mjs';import {a as a$6}from'./chunk-3SXN6MQL.mjs';import {a as a$9}from'./chunk-WN3DOKIM.mjs';import {a as a$1}from'./chunk-HVN6HBWZ.mjs';import {b as b$3,a as a$8}from'./chunk-FSVETLZK.mjs';import {a as a$3}from'./chunk-U6O35NZ7.mjs';import {j,f,d as d$1}from'./chunk-QFHYSC3K.mjs';import {v}from'./chunk-BH2WXCLS.mjs';import {a as a$7}from'./chunk-E3HZCU3S.mjs';import {b as b$2,d}from'./chunk-SPHWZS5P.mjs';import {b as b$1}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';import {readFile}from'fs/promises';import {join}from'path';globalThis.require=createRequire(import.meta.url);
3
- var Y=v(4);async function fe(n,s={}){let a=new a$1,e=await a$2(n,{runScripts:s.runScripts,force:s.force,historyLimit:s.historyLimit});if(e.skipped){let t=await b(e.name,e.version);if(t)return q(t,{force:s.force,timer:a,noConsumersStatus:"available",noChange:true,skippedReason:"content unchanged"});{let o=R(e.name,e.version,e.buildId,a.elapsedMs());return o.noChange=true,o.skippedReason="content unchanged",b$1.info(`No changes to push for ${e.name}@${e.version}`+(e.buildId?` [${e.buildId}]`:"")),a$3(o),o}}if(b$2()){let t=await j(e.name),o=R(e.name,e.version,e.buildId,a.elapsedMs());return o.skippedReason="dry-run",o.consumers=t.length,o.skippedConsumers=t.length,o.consumerResults=t.map(m=>({consumerPath:m,status:"skipped",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,reason:"dry-run publish preview; store entry was not written"})),b$1.info(`Dry-run: would publish ${e.name}@${e.version}`+(e.buildId?` [${e.buildId}]`:"")+". Skipping consumer injection preview because the store entry was not written."),a$3(o),o}let i=await b(e.name,e.version);if(!i){a$4(`Failed to read store entry for ${e.name}@${e.version} after publish`);let t=R(e.name,e.version,e.buildId,a.elapsedMs());return t.failedConsumers=1,t.consumerResults=[{consumerPath:n,status:"failed",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,error:"store entry missing after publish"}],t}return q(i,{force:s.force,timer:a,noConsumersStatus:"published"})}a(fe,"doPush");async function q(n,s={}){let a=s.timer??new a$1,e=await j(n.name);if(e.length===0){let d=s.noConsumersStatus??"available";b$1.success(`${n.name}@${n.version} ${d} in store`),b$1.info("No consumers registered yet. Run 'knarr add "+n.name+"' in a consumer project to start receiving pushes.");let h=R(n.name,n.version,n.meta.buildId??"",a.elapsedMs());return h.noChange=s.noChange??false,h.skippedReason=s.skippedReason,s.emitOutput!==false&&a$3(h),h}let i=0,t=0,o=0,m=0,r=0,f$1=0,p=0,g=0,C=await Promise.all(e.map(d$2=>Y(async()=>{let h=await f(d$2,n.name);if(!h)return d(`[push] No link found for ${n.name} in ${d$2}, skipping`),{consumerPath:d$2,status:"skipped",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,reason:"not linked in consumer state"};try{let w=await b$3(d$2),y=w.source==="default"?h.packageManager:w.packageManager,S=await a$5(n,d$2,y,{force:s.force});return await d$1(d$2,n.name,{...h,contentHash:n.meta.contentHash,linkedAt:new Date().toISOString(),buildId:n.meta.buildId??"",packageManager:y}),{consumerPath:d$2,status:"updated",copied:S.copied,removed:S.removed,skipped:S.skipped,binLinks:S.binLinks,cacheInvalidations:S.cacheInvalidations}}catch(w){let y=w instanceof Error?w.message:String(w);return b$1.warn(`Failed to push to ${d$2}: ${y}`),{consumerPath:d$2,status:"failed",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,error:y}}})));for(let d of C)d.status==="updated"?(i+=d.copied,t+=d.removed,o+=d.skipped,m+=d.binLinks,r+=d.cacheInvalidations,f$1++):d.status==="skipped"?p++:g++;let b=n.meta.buildId??"",$=b?` [${b}]`:"",c=[`${i} copied`,`${t} removed`,`${o} unchanged`];m>0&&c.push(`${m} bin links`),r>0&&c.push(`${r} cache invalidations`),p>0&&c.push(`${p} consumer(s) skipped`),g>0&&c.push(`${g} failed`);let k=g>0||p>0?`${f$1}/${e.length} consumer(s)`:`${f$1} consumer(s)`,W=`Pushed ${n.name}@${n.version}${$} to ${k} in ${a.elapsed()} (${c.join(", ")})`;g>0?b$1.warn(W):b$1.success(W);let I={name:n.name,version:n.version,buildId:b,noChange:false,consumers:e.length,updatedConsumers:f$1,failedConsumers:g,skippedConsumers:p,copied:i,removed:t,skipped:o,binLinks:m,cacheInvalidations:r,elapsed:a.elapsedMs(),consumerResults:C};return I.noChange=s.noChange??false,I.skippedReason=s.skippedReason,s.emitOutput!==false&&a$3(I),I}a(q,"pushStoreEntry");function R(n,s,a,e){return {name:n,version:s,buildId:a,noChange:false,consumers:0,updatedConsumers:0,failedConsumers:0,skippedConsumers:0,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,elapsed:e,consumerResults:[]}}a(R,"createEmptySummary");function z(n){if(!n)return;let s=parseInt(n,10);return Number.isFinite(s)?s:void 0}a(z,"parseMs");async function ge(n,s,a$1){let{startWatcher:e}=await import('./watcher-KOLIXRUG.mjs'),i=await a$6(n),{buildCmd:t,patterns:o}=await V(n,s,i),m=s.notify??i.notify??false,r=await e(n,{patterns:o,buildCmd:t,debounce:z(s.debounce)??i.debounce,cooldown:z(s.cooldown)??i.cooldown,notify:m},async()=>{await a$1();});await new Promise(f=>{let p=a(async()=>{b$1.info("Stopping watcher..."),await r.close(),f();},"cleanup");process.once("SIGINT",p),process.once("SIGTERM",p);});}a(ge,"startWatchMode");async function Z(n,s,a){let e=a??await a$6(n),{buildCmd:i}=await V(n,s,e);if(!i)return true;if(b$2())return a$7({type:"command-skip",path:n,detail:i}),true;let{runBuildCommand:t}=await import('./watcher-KOLIXRUG.mjs'),o=await t(i,n);return o||b$1.warn("Initial build failed; skipping initial push. Watch mode will continue."),o}a(Z,"runInitialWatchBuild");async function he(n,s){let{buildReverseAdjacency:a,buildWorkspaceGraph:e,filterPublishableWorkspaceGraph:i}=await import('./workspace-T6PNO4L3.mjs'),{topoSort:t,CycleError:o}=await import('./topo-sort-ZNGR6D7M.mjs'),m=await e(n),r=i(m);if(r.packages.length===0)return {canPush:true,failedPackages:new Set,skippedPackages:new Set};let f;try{f=t(r.adjacency);}catch(c){if(c instanceof o)return b$1.error(`Cannot build workspace before watch: ${c.message}`),{canPush:false,failedPackages:new Set(r.packages.map(k=>k.name)),skippedPackages:new Set};throw c}let p=new Map(r.packages.map(c=>[c.name,c.dir])),g=a(r.adjacency),C=new Set,b=new Set,$=new Set;for(let c of f){let k=p.get(c);if(!k)continue;if($.has(c)){b.add(c),d(`[watch] Skipping initial build for ${c}: dependency build failed`);continue}await Z(k,s)||(C.add(c),Q(c,g,$));}return {canPush:true,failedPackages:C,skippedPackages:b}}a(he,"runInitialWorkspaceWatchBuilds");function Q(n,s,a){for(let e of s.get(n)??[])a.has(e)||(a.add(e),Q(e,s,a));}a(Q,"markTransitiveDependentsBlocked");async function V(n,s,a){let e=s.build,i=a?.watchPatterns;if(!s.build){if(!s["skip-build"])if(a?.buildCmd)e=a.buildCmd,b$1.info(`Using build command from config: ${e}`);else {let t=await a$8(n),o=await a$9(n,t);o&&(e=o,b$1.info(`Auto-detected build command: ${o}`));}}if(e&&!i){let{exists:t}=await import('./fs-NU36NNEG.mjs'),o=["src","lib","source","app","pages","components"],m=(await Promise.all(o.map(async r=>({dir:r,exists:await t(join(n,r))})))).filter(r=>r.exists).map(r=>r.dir);i=m.length>0?m:["src","lib"],d(`[watch] Using source patterns with build command: ${i.join(", ")}`);}else if(e&&i)d(`[watch] Using configured watch patterns with build command: ${i.join(", ")}`);else {b$1.info("No build command detected \u2014 watching output directories directly");try{let t=JSON.parse(await readFile(join(n,"package.json"),"utf-8"));t.files&&t.files.length>0?(i=t.files,b$1.info(`Watching from package.json "files": ${i.join(", ")}`)):b$1.warn('No "files" field in package.json \u2014 falling back to watching src/ and lib/. Add a "files" field or use --build to specify a build command.');}catch(t){d(`[watch] Could not read package.json: ${t instanceof Error?t.message:String(t)}`);}}return {buildCmd:e,patterns:i}}a(V,"resolveWatchConfig");async function be(n,s,a){let e=!s["no-cascade"],{WatchOrchestrator:i}=await import('./watch-orchestrator-N6HZUDS3.mjs');await new i(e).start(n,s,a);}a(be,"startMultiWatchMode");export{fe as a,q as b,ge as c,Z as d,he as e,V as f,be as g};
3
+ var Y=v(4);async function fe(n,s={}){let a=new a$1,e=await a$2(n,{runScripts:s.runScripts,force:s.force,historyLimit:s.historyLimit});if(e.skipped){let t=await b(e.name,e.version);if(t)return q(t,{force:s.force,timer:a,noConsumersStatus:"available",noChange:true,skippedReason:"content unchanged"});{let o=R(e.name,e.version,e.buildId,a.elapsedMs());return o.noChange=true,o.skippedReason="content unchanged",b$1.info(`No changes to push for ${e.name}@${e.version}`+(e.buildId?` [${e.buildId}]`:"")),a$3(o),o}}if(b$2()){let t=await j(e.name),o=R(e.name,e.version,e.buildId,a.elapsedMs());return o.skippedReason="dry-run",o.consumers=t.length,o.skippedConsumers=t.length,o.consumerResults=t.map(m=>({consumerPath:m,status:"skipped",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,reason:"dry-run publish preview; store entry was not written"})),b$1.info(`Dry-run: would publish ${e.name}@${e.version}`+(e.buildId?` [${e.buildId}]`:"")+". Skipping consumer injection preview because the store entry was not written."),a$3(o),o}let i=await b(e.name,e.version);if(!i){a$4(`Failed to read store entry for ${e.name}@${e.version} after publish`);let t=R(e.name,e.version,e.buildId,a.elapsedMs());return t.failedConsumers=1,t.consumerResults=[{consumerPath:n,status:"failed",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,error:"store entry missing after publish"}],t}return q(i,{force:s.force,timer:a,noConsumersStatus:"published"})}a(fe,"doPush");async function q(n,s={}){let a=s.timer??new a$1,e=await j(n.name);if(e.length===0){let d=s.noConsumersStatus??"available";b$1.success(`${n.name}@${n.version} ${d} in store`),b$1.info("No consumers registered yet. Run 'knarr add "+n.name+"' in a consumer project to start receiving pushes.");let h=R(n.name,n.version,n.meta.buildId??"",a.elapsedMs());return h.noChange=s.noChange??false,h.skippedReason=s.skippedReason,s.emitOutput!==false&&a$3(h),h}let i=0,t=0,o=0,m=0,r=0,f$1=0,p=0,g=0,C=await Promise.all(e.map(d$2=>Y(async()=>{let h=await f(d$2,n.name);if(!h)return d(`[push] No link found for ${n.name} in ${d$2}, skipping`),{consumerPath:d$2,status:"skipped",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,reason:"not linked in consumer state"};try{let w=await b$3(d$2),y=w.source==="default"?h.packageManager:w.packageManager,S=await a$5(n,d$2,y,{force:s.force});return await d$1(d$2,n.name,{...h,contentHash:n.meta.contentHash,linkedAt:new Date().toISOString(),buildId:n.meta.buildId??"",packageManager:y}),{consumerPath:d$2,status:"updated",copied:S.copied,removed:S.removed,skipped:S.skipped,binLinks:S.binLinks,cacheInvalidations:S.cacheInvalidations}}catch(w){let y=w instanceof Error?w.message:String(w);return b$1.warn(`Failed to push to ${d$2}: ${y}`),{consumerPath:d$2,status:"failed",copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,error:y}}})));for(let d of C)d.status==="updated"?(i+=d.copied,t+=d.removed,o+=d.skipped,m+=d.binLinks,r+=d.cacheInvalidations,f$1++):d.status==="skipped"?p++:g++;let b=n.meta.buildId??"",$=b?` [${b}]`:"",c=[`${i} copied`,`${t} removed`,`${o} unchanged`];m>0&&c.push(`${m} bin links`),r>0&&c.push(`${r} cache invalidations`),p>0&&c.push(`${p} consumer(s) skipped`),g>0&&c.push(`${g} failed`);let k=g>0||p>0?`${f$1}/${e.length} consumer(s)`:`${f$1} consumer(s)`,W=`Pushed ${n.name}@${n.version}${$} to ${k} in ${a.elapsed()} (${c.join(", ")})`;g>0?b$1.warn(W):b$1.success(W);let I={name:n.name,version:n.version,buildId:b,noChange:false,consumers:e.length,updatedConsumers:f$1,failedConsumers:g,skippedConsumers:p,copied:i,removed:t,skipped:o,binLinks:m,cacheInvalidations:r,elapsed:a.elapsedMs(),consumerResults:C};return I.noChange=s.noChange??false,I.skippedReason=s.skippedReason,s.emitOutput!==false&&a$3(I),I}a(q,"pushStoreEntry");function R(n,s,a,e){return {name:n,version:s,buildId:a,noChange:false,consumers:0,updatedConsumers:0,failedConsumers:0,skippedConsumers:0,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,elapsed:e,consumerResults:[]}}a(R,"createEmptySummary");function z(n){if(!n)return;let s=parseInt(n,10);return Number.isFinite(s)?s:void 0}a(z,"parseMs");async function ge(n,s,a$1){let{startWatcher:e}=await import('./watcher-ES2APFH4.mjs'),i=await a$6(n),{buildCmd:t,patterns:o}=await V(n,s,i),m=s.notify??i.notify??false,r=await e(n,{patterns:o,buildCmd:t,debounce:z(s.debounce)??i.debounce,cooldown:z(s.cooldown)??i.cooldown,notify:m},async()=>{await a$1();});await new Promise(f=>{let p=a(async()=>{b$1.info("Stopping watcher..."),await r.close(),f();},"cleanup");process.once("SIGINT",p),process.once("SIGTERM",p);});}a(ge,"startWatchMode");async function Z(n,s,a){let e=a??await a$6(n),{buildCmd:i}=await V(n,s,e);if(!i)return true;if(b$2())return a$7({type:"command-skip",path:n,detail:i}),true;let{runBuildCommand:t}=await import('./watcher-ES2APFH4.mjs'),o=await t(i,n);return o||b$1.warn("Initial build failed; skipping initial push. Watch mode will continue."),o}a(Z,"runInitialWatchBuild");async function he(n,s){let{buildReverseAdjacency:a,buildWorkspaceGraph:e,filterPublishableWorkspaceGraph:i}=await import('./workspace-T6PNO4L3.mjs'),{topoSort:t,CycleError:o}=await import('./topo-sort-ZNGR6D7M.mjs'),m=await e(n),r=i(m);if(r.packages.length===0)return {canPush:true,failedPackages:new Set,skippedPackages:new Set};let f;try{f=t(r.adjacency);}catch(c){if(c instanceof o)return b$1.error(`Cannot build workspace before watch: ${c.message}`),{canPush:false,failedPackages:new Set(r.packages.map(k=>k.name)),skippedPackages:new Set};throw c}let p=new Map(r.packages.map(c=>[c.name,c.dir])),g=a(r.adjacency),C=new Set,b=new Set,$=new Set;for(let c of f){let k=p.get(c);if(!k)continue;if($.has(c)){b.add(c),d(`[watch] Skipping initial build for ${c}: dependency build failed`);continue}await Z(k,s)||(C.add(c),Q(c,g,$));}return {canPush:true,failedPackages:C,skippedPackages:b}}a(he,"runInitialWorkspaceWatchBuilds");function Q(n,s,a){for(let e of s.get(n)??[])a.has(e)||(a.add(e),Q(e,s,a));}a(Q,"markTransitiveDependentsBlocked");async function V(n,s,a){let e=s.build,i=a?.watchPatterns;if(!s.build){if(!s["skip-build"])if(a?.buildCmd)e=a.buildCmd,b$1.info(`Using build command from config: ${e}`);else {let t=await a$8(n),o=await a$9(n,t);o&&(e=o,b$1.info(`Auto-detected build command: ${o}`));}}if(e&&!i){let{exists:t}=await import('./fs-NU36NNEG.mjs'),o=["src","lib","source","app","pages","components"],m=(await Promise.all(o.map(async r=>({dir:r,exists:await t(join(n,r))})))).filter(r=>r.exists).map(r=>r.dir);i=m.length>0?m:["src","lib"],d(`[watch] Using source patterns with build command: ${i.join(", ")}`);}else if(e&&i)d(`[watch] Using configured watch patterns with build command: ${i.join(", ")}`);else {b$1.info("No build command detected \u2014 watching output directories directly");try{let t=JSON.parse(await readFile(join(n,"package.json"),"utf-8"));t.files&&t.files.length>0?(i=t.files,b$1.info(`Watching from package.json "files": ${i.join(", ")}`)):b$1.warn('No "files" field in package.json \u2014 falling back to watching src/ and lib/. Add a "files" field or use --build to specify a build command.');}catch(t){d(`[watch] Could not read package.json: ${t instanceof Error?t.message:String(t)}`);}}return {buildCmd:e,patterns:i}}a(V,"resolveWatchConfig");async function be(n,s,a){let e=!s["no-cascade"],{WatchOrchestrator:i}=await import('./watch-orchestrator-SFFGME6W.mjs');await new i(e).start(n,s,a);}a(be,"startMultiWatchMode");export{fe as a,q as b,ge as c,Z as d,he as e,V as f,be as g};
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {createRequire}from'node:module';import {b as b$1,a as a$2}from'./chunk-ICU4V73X.mjs';import {a as a$3}from'./chunk-AA43FODB.mjs';import {a as a$1}from'./chunk-HVN6HBWZ.mjs';import {e,f,g}from'./chunk-7GCKCCHU.mjs';import {d as d$1}from'./chunk-SPHWZS5P.mjs';import {b}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';globalThis.require=createRequire(import.meta.url);
2
+ import {createRequire}from'node:module';import {b as b$1,a as a$2}from'./chunk-ICU4V73X.mjs';import {a as a$3}from'./chunk-C4TZJOCB.mjs';import {a as a$1}from'./chunk-HVN6HBWZ.mjs';import {e,f,g}from'./chunk-7GCKCCHU.mjs';import {d as d$1}from'./chunk-SPHWZS5P.mjs';import {b}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';globalThis.require=createRequire(import.meta.url);
3
3
  async function G(u,t={}){let a=new a$1,n=await e(u),o=f(n);if(o.packages.length===0){b.warn("No publishable workspace packages found");return}let k=n.packages.length-o.packages.length;k>0&&b.info(`Skipping ${k} private workspace package(s)`);let i;try{i=b$1(o.adjacency);}catch(e){throw e instanceof a$2&&b.error(`Cannot push: ${e.message}`),e}let C=new Map(o.packages.map(e=>[e.name,e.dir]));b.info(`Pushing ${i.length} packages in dependency order`),d$1(`[batch-push] Order: ${i.join(" \u2192 ")}`);let f$1=g(o.adjacency),c=new Set(t.skipPackages??[]);for(let e of [...c])d(e,f$1,c);let w=0,r=0,p=0;for(let e of i){let y=C.get(e);if(y){if(c.has(e)){d$1(`[batch-push] Skipping ${e}: dependency build/push failed`),p++;continue}try{(await a$3(y,t)).failedConsumers>0?(r++,d(e,f$1,c)):w++;}catch(l){b.warn(`Failed to push ${e}: ${l instanceof Error?l.message:String(l)}`),r++,d(e,f$1,c);}}}let $=[r>0?`${r} failed`:null,p>0?`${p} skipped`:null].filter(e=>e!==null),g$1=`Pushed ${w}/${i.length} packages in ${a.elapsed()}`+($.length>0?` (${$.join(", ")})`:"");if(r>0)throw b.warn(g$1),new Error(`Failed to push ${r} workspace package(s)`);if(p>0){b.warn(g$1);return}b.success(g$1);}a(G,"doPushAll");function d(u,t,a){for(let n of t.get(u)??[])a.has(n)||(a.add(n),d(n,t,a));}a(d,"markTransitiveDependentsBlocked");export{G as a};
package/dist/cli.mjs CHANGED
@@ -7,4 +7,4 @@ var a=c(a$1(),1);var _=`
7
7
  | . \\| | | | (_| | | | |
8
8
  |_|\\_\\_| |_|\\__,_|_| |_|
9
9
  `;function n(){console.log(a.default.yellow(_)),console.log(a.default.cyan(" Local npm package development without symlinks")),console.log(a.default.dim(` Copies built files into consumer node_modules with incremental sync
10
- `));}a$2(n,"showBanner");process.env.UV_THREADPOOL_SIZE??=String(Math.max(availableParallelism(),8));a$3();var l=process.argv.slice(2),b=["init","publish","add","use","remove","push","dev","restore","list","status","update","clean","gc","doctor","explain","migrate","reset","rollback","check"],u=l.some(e=>!e.startsWith("-")&&b.includes(e)),v=l.includes("--help")||l.includes("-h")||l.includes("--version");if(!u&&!v&&process.stdin.isTTY){n();let e=await g();e&&process.argv.splice(2,0,e);}else u||n();async function g(){try{let{readConsumerStateSafe:p}=await import('./tracker-QAKEXYUJ.mjs'),{resolve:c}=await import('path'),{state:d}=await p(c(".")),i=Object.keys(d.links).length;i>0&&b$1.info(`${i} package(s) linked in this project`);}catch{}return await b$1.prompt("What would you like to do?",{type:"select",options:[{label:"init - Set up knarr in this project",value:"init"},{label:"publish - Publish package to the knarr store",value:"publish"},{label:"add - Link a package from the store",value:"add"},{label:"use - Link a local package path",value:"use"},{label:"push - Publish and push to all consumers",value:"push"},{label:"dev - Watch, rebuild, and push continuously",value:"dev"},{label:"list - Show linked packages",value:"list"},{label:"status - Show project status",value:"status"},{label:"explain - Explain linked package state",value:"explain"},{label:"help - Show help",value:"--help"}]})||null}a$2(g,"showInteractiveMenu");var k={meta:{name:"knarr",version:"0.1.0",description:"Local npm package development - copies built files into consumer node_modules"},args:{verbose:{type:"boolean",alias:"v",description:"Enable verbose debug logging",default:false},"dry-run":{type:"boolean",description:"Preview changes without writing files",default:false},json:{type:"boolean",description:"Output machine-readable JSON",default:false}},subCommands:{init:a$2(()=>import('./init-X4F3XKVC.mjs').then(e=>e.default),"init"),publish:a$2(()=>import('./publish-UGDDG6OT.mjs').then(e=>e.default),"publish"),add:a$2(()=>import('./add-4Z3V5722.mjs').then(e=>e.default),"add"),use:a$2(()=>import('./use-LZ2GIXYZ.mjs').then(e=>e.default),"use"),remove:a$2(()=>import('./remove-EPVDMWCS.mjs').then(e=>e.default),"remove"),push:a$2(()=>import('./push-V575ASM4.mjs').then(e=>e.default),"push"),dev:a$2(()=>import('./dev-PUNHH4MS.mjs').then(e=>e.default),"dev"),restore:a$2(()=>import('./restore-QPISOGEK.mjs').then(e=>e.default),"restore"),list:a$2(()=>import('./list-4PTHMIQ4.mjs').then(e=>e.default),"list"),status:a$2(()=>import('./status-3ZXM3CRH.mjs').then(e=>e.default),"status"),explain:a$2(()=>import('./explain-BDTONX7H.mjs').then(e=>e.default),"explain"),update:a$2(()=>import('./update-RSPDDAJK.mjs').then(e=>e.default),"update"),clean:a$2(()=>import('./clean-EJIYYQZM.mjs').then(e=>e.default),"clean"),gc:a$2(()=>import('./clean-EJIYYQZM.mjs').then(e=>e.default),"gc"),doctor:a$2(()=>import('./doctor-ZK4OPSD4.mjs').then(e=>e.default),"doctor"),migrate:a$2(()=>import('./migrate-VHDLW6I7.mjs').then(e=>e.default),"migrate"),reset:a$2(()=>import('./reset-5M6AU4FU.mjs').then(e=>e.default),"reset"),rollback:a$2(()=>import('./rollback-CTGK7SXG.mjs').then(e=>e.default),"rollback"),check:a$2(()=>import('./check-7CJHAF6Y.mjs').then(e=>e.default),"check")}};a$4(k);
10
+ `));}a$2(n,"showBanner");process.env.UV_THREADPOOL_SIZE??=String(Math.max(availableParallelism(),8));a$3();var l=process.argv.slice(2),b=["init","publish","add","use","remove","push","dev","restore","list","status","update","clean","gc","doctor","explain","migrate","reset","rollback","check"],u=l.some(e=>!e.startsWith("-")&&b.includes(e)),v=l.includes("--help")||l.includes("-h")||l.includes("--version");if(!u&&!v&&process.stdin.isTTY){n();let e=await g();e&&process.argv.splice(2,0,e);}else u||n();async function g(){try{let{readConsumerStateSafe:p}=await import('./tracker-QAKEXYUJ.mjs'),{resolve:c}=await import('path'),{state:d}=await p(c(".")),i=Object.keys(d.links).length;i>0&&b$1.info(`${i} package(s) linked in this project`);}catch{}return await b$1.prompt("What would you like to do?",{type:"select",options:[{label:"init - Set up knarr in this project",value:"init"},{label:"publish - Publish package to the knarr store",value:"publish"},{label:"add - Link a package from the store",value:"add"},{label:"use - Link a local package path",value:"use"},{label:"push - Publish and push to all consumers",value:"push"},{label:"dev - Watch, rebuild, and push continuously",value:"dev"},{label:"list - Show linked packages",value:"list"},{label:"status - Show project status",value:"status"},{label:"explain - Explain linked package state",value:"explain"},{label:"help - Show help",value:"--help"}]})||null}a$2(g,"showInteractiveMenu");var k={meta:{name:"knarr",version:"0.1.2",description:"Local npm package development - copies built files into consumer node_modules"},args:{verbose:{type:"boolean",alias:"v",description:"Enable verbose debug logging",default:false},"dry-run":{type:"boolean",description:"Preview changes without writing files",default:false},json:{type:"boolean",description:"Output machine-readable JSON",default:false}},subCommands:{init:a$2(()=>import('./init-X4F3XKVC.mjs').then(e=>e.default),"init"),publish:a$2(()=>import('./publish-UGDDG6OT.mjs').then(e=>e.default),"publish"),add:a$2(()=>import('./add-4Z3V5722.mjs').then(e=>e.default),"add"),use:a$2(()=>import('./use-LZ2GIXYZ.mjs').then(e=>e.default),"use"),remove:a$2(()=>import('./remove-EPVDMWCS.mjs').then(e=>e.default),"remove"),push:a$2(()=>import('./push-NADBGWI6.mjs').then(e=>e.default),"push"),dev:a$2(()=>import('./dev-RHCNJNQE.mjs').then(e=>e.default),"dev"),restore:a$2(()=>import('./restore-QPISOGEK.mjs').then(e=>e.default),"restore"),list:a$2(()=>import('./list-4PTHMIQ4.mjs').then(e=>e.default),"list"),status:a$2(()=>import('./status-3ZXM3CRH.mjs').then(e=>e.default),"status"),explain:a$2(()=>import('./explain-BDTONX7H.mjs').then(e=>e.default),"explain"),update:a$2(()=>import('./update-RSPDDAJK.mjs').then(e=>e.default),"update"),clean:a$2(()=>import('./clean-EJIYYQZM.mjs').then(e=>e.default),"clean"),gc:a$2(()=>import('./clean-EJIYYQZM.mjs').then(e=>e.default),"gc"),doctor:a$2(()=>import('./doctor-ZK4OPSD4.mjs').then(e=>e.default),"doctor"),migrate:a$2(()=>import('./migrate-VHDLW6I7.mjs').then(e=>e.default),"migrate"),reset:a$2(()=>import('./reset-5M6AU4FU.mjs').then(e=>e.default),"reset"),rollback:a$2(()=>import('./rollback-ECXCFOD3.mjs').then(e=>e.default),"rollback"),check:a$2(()=>import('./check-7CJHAF6Y.mjs').then(e=>e.default),"check")}};a$4(k);
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {createRequire}from'node:module';import {a as a$1}from'./chunk-GAWQLCRB.mjs';import'./chunk-ICU4V73X.mjs';import {e,g,a as a$3,d as d$1,c}from'./chunk-AA43FODB.mjs';import'./chunk-COI7GWH3.mjs';import'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import'./chunk-XDWZZBCM.mjs';import {a}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import {b}from'./chunk-U6O35NZ7.mjs';import'./chunk-NGPAGRK4.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import'./chunk-7GCKCCHU.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import {d}from'./chunk-E3HZCU3S.mjs';import {b as b$1}from'./chunk-SPHWZS5P.mjs';import'./chunk-OQDZJP55.mjs';import {a as a$2}from'./chunk-L7O2RSTN.mjs';import {resolve}from'path';globalThis.require=createRequire(import.meta.url);
2
+ import {createRequire}from'node:module';import {a as a$1}from'./chunk-IZC5ORVG.mjs';import'./chunk-ICU4V73X.mjs';import {e,g,a as a$3,d as d$1,c}from'./chunk-C4TZJOCB.mjs';import'./chunk-COI7GWH3.mjs';import'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import'./chunk-XDWZZBCM.mjs';import {a}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import {b}from'./chunk-U6O35NZ7.mjs';import'./chunk-NGPAGRK4.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import'./chunk-7GCKCCHU.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import {d}from'./chunk-E3HZCU3S.mjs';import {b as b$1}from'./chunk-SPHWZS5P.mjs';import'./chunk-OQDZJP55.mjs';import {a as a$2}from'./chunk-L7O2RSTN.mjs';import {resolve}from'path';globalThis.require=createRequire(import.meta.url);
3
3
  var O={meta:{name:"dev",description:"Watch, rebuild, and push to all consumers. Auto-detects build command."},args:{all:{type:"boolean",description:"Watch all workspace packages in dependency order",default:false},build:{type:"string",description:"Override build command (default: auto-detect from package.json)"},"skip-build":{type:"boolean",description:"Watch output dirs directly, skip build command detection",default:false},debounce:{type:"string",description:"Debounce delay in ms (default: 500)"},cooldown:{type:"string",description:"Minimum time between builds in ms (default: 500)"},"no-scripts":{type:"boolean",description:"Skip prepack/postpack lifecycle hooks",default:false},force:{type:"boolean",alias:"f",description:"Force copy all files, bypassing hash comparison",default:false},notify:{type:"boolean",description:"Ring terminal bell on push completion",default:false},"no-cascade":{type:"boolean",description:"Disable cascading rebuilds in --all mode",default:false}},async run({args:i}){b();let e$1=resolve("."),s=await a(e$1),o={runScripts:!i["no-scripts"],force:i.force,historyLimit:s.historyLimit};if(i.all){let t=await e(e$1,i),l=new Set([...t.failedPackages,...t.skippedPackages]);if(t.canPush&&await a$1(e$1,{...o,skipPackages:l}),b$1()){d();return}await g(e$1,i,o);}else {let t=a$2(()=>a$3(e$1,o),"push");if(await d$1(e$1,i,s)&&await t(),b$1()){d();return}await c(e$1,i,t);}}};export{O as default};
package/dist/index.mjs CHANGED
@@ -3920,11 +3920,12 @@ var watcher_exports = {};
3920
3920
  __export(watcher_exports, {
3921
3921
  killActiveBuild: () => killActiveBuild,
3922
3922
  runBuildCommand: () => runBuildCommand,
3923
+ shouldUsePolling: () => shouldUsePolling,
3923
3924
  startWatcher: () => startWatcher
3924
3925
  });
3925
3926
  import { spawn as spawn2 } from "child_process";
3926
3927
  import { readdir as readdir7, stat as stat7 } from "fs/promises";
3927
- import { platform as platform4 } from "os";
3928
+ import { platform as platform4, release } from "os";
3928
3929
  import { join as join18 } from "path";
3929
3930
  function killActiveBuild() {
3930
3931
  for (const child of activeChildren) {
@@ -3934,6 +3935,14 @@ function killActiveBuild() {
3934
3935
  }
3935
3936
  activeChildren.clear();
3936
3937
  }
3938
+ function shouldUsePolling(watchDir, env = {
3939
+ platform: platform4(),
3940
+ release: release(),
3941
+ webcontainer: !!process.versions?.webcontainer
3942
+ }) {
3943
+ if (env.webcontainer) return true;
3944
+ return env.platform === "linux" && /microsoft|wsl/i.test(env.release) && /^\/mnt\/[a-z](?:\/|$)/i.test(watchDir);
3945
+ }
3937
3946
  async function walkDir(dir, snapshot) {
3938
3947
  let entries;
3939
3948
  try {
@@ -4061,7 +4070,7 @@ async function startWatcher(watchDir, options, onChange) {
4061
4070
  stabilityThreshold: 200,
4062
4071
  pollInterval: 50
4063
4072
  };
4064
- const usePolling = !!process.versions?.webcontainer;
4073
+ const usePolling = shouldUsePolling(watchDir);
4065
4074
  const watcher = watch(watchPaths, {
4066
4075
  ignoreInitial: true,
4067
4076
  ignored: [
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {createRequire}from'node:module';import {a as a$1}from'./chunk-GAWQLCRB.mjs';import'./chunk-ICU4V73X.mjs';import {e,g,a as a$3,d as d$1,c}from'./chunk-AA43FODB.mjs';import'./chunk-COI7GWH3.mjs';import'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import'./chunk-XDWZZBCM.mjs';import {a}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import {b}from'./chunk-U6O35NZ7.mjs';import'./chunk-NGPAGRK4.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import'./chunk-7GCKCCHU.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import {d}from'./chunk-E3HZCU3S.mjs';import {b as b$1}from'./chunk-SPHWZS5P.mjs';import'./chunk-OQDZJP55.mjs';import {a as a$2}from'./chunk-L7O2RSTN.mjs';import {resolve}from'path';globalThis.require=createRequire(import.meta.url);
2
+ import {createRequire}from'node:module';import {a as a$1}from'./chunk-IZC5ORVG.mjs';import'./chunk-ICU4V73X.mjs';import {e,g,a as a$3,d as d$1,c}from'./chunk-C4TZJOCB.mjs';import'./chunk-COI7GWH3.mjs';import'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import'./chunk-XDWZZBCM.mjs';import {a}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import {b}from'./chunk-U6O35NZ7.mjs';import'./chunk-NGPAGRK4.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import'./chunk-7GCKCCHU.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import {d}from'./chunk-E3HZCU3S.mjs';import {b as b$1}from'./chunk-SPHWZS5P.mjs';import'./chunk-OQDZJP55.mjs';import {a as a$2}from'./chunk-L7O2RSTN.mjs';import {resolve}from'path';globalThis.require=createRequire(import.meta.url);
3
3
  var S={meta:{name:"push",description:"Publish and push to all consumers. Use --watch for continuous mode."},args:{watch:{type:"boolean",description:"Watch for changes and auto-push",default:false},all:{type:"boolean",description:"Push all workspace packages in dependency order",default:false},build:{type:"string",description:"Build command to run before publishing (watch mode)"},"skip-build":{type:"boolean",description:"Watch output dirs directly, skip build command detection",default:false},debounce:{type:"string",description:"Debounce delay in ms for watch mode (default: 500)"},cooldown:{type:"string",description:"Minimum time between builds in ms (default: 500)"},"no-scripts":{type:"boolean",description:"Skip prepack/postpack lifecycle hooks",default:false},force:{type:"boolean",alias:"f",description:"Force copy all files, bypassing hash comparison",default:false},notify:{type:"boolean",description:"Ring terminal bell on push completion (watch mode)",default:false},"no-cascade":{type:"boolean",description:"Disable cascading rebuilds in --all watch mode",default:false}},async run({args:i}){b();let e$1=resolve("."),s=await a(e$1),o={runScripts:!i["no-scripts"],force:i.force,historyLimit:s.historyLimit};if(i.all){let t=i.watch?await e(e$1,i):{canPush:true,failedPackages:new Set,skippedPackages:new Set},c=new Set([...t.failedPackages,...t.skippedPackages]);if(t.canPush&&await a$1(e$1,{...o,skipPackages:c}),b$1()){d();return}i.watch&&await g(e$1,i,o);}else {let t=a$2(()=>a$3(e$1,o),"push");if((!i.watch||await d$1(e$1,i,s))&&await t(),b$1()){d();return}i.watch&&await c(e$1,i,t);}}};export{S as default};
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {createRequire}from'node:module';import {b as b$4}from'./chunk-AA43FODB.mjs';import'./chunk-COI7GWH3.mjs';import {b as b$3}from'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import {a as a$4}from'./chunk-XDWZZBCM.mjs';import {a as a$5}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import {a as a$3,b}from'./chunk-U6O35NZ7.mjs';import'./chunk-NGPAGRK4.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import {b as b$1,g,d}from'./chunk-M3TRMEJV.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import {d as d$1}from'./chunk-E3HZCU3S.mjs';import {b as b$5}from'./chunk-SPHWZS5P.mjs';import {a as a$1,b as b$2}from'./chunk-OQDZJP55.mjs';import {c,a as a$2}from'./chunk-L7O2RSTN.mjs';import {resolve}from'path';import {readFile}from'fs/promises';globalThis.require=createRequire(import.meta.url);
2
+ import {createRequire}from'node:module';import {b as b$4}from'./chunk-C4TZJOCB.mjs';import'./chunk-COI7GWH3.mjs';import {b as b$3}from'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import {a as a$4}from'./chunk-XDWZZBCM.mjs';import {a as a$5}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import {a as a$3,b}from'./chunk-U6O35NZ7.mjs';import'./chunk-NGPAGRK4.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import {b as b$1,g,d}from'./chunk-M3TRMEJV.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import {d as d$1}from'./chunk-E3HZCU3S.mjs';import {b as b$5}from'./chunk-SPHWZS5P.mjs';import {a as a$1,b as b$2}from'./chunk-OQDZJP55.mjs';import {c,a as a$2}from'./chunk-L7O2RSTN.mjs';import {resolve}from'path';import {readFile}from'fs/promises';globalThis.require=createRequire(import.meta.url);
3
3
  var m=c(a$1(),1);function a(t){a$3({rolledBack:t.rolledBack??false,buildId:t.buildId??null,pushed:t.pushed??false,pushSummary:t.pushSummary??null,pushError:t.pushError??null});}a$2(a,"outputRollback");var z={meta:{name:"rollback",description:"Restore a previous build from history"},args:{"build-id":{type:"string",description:"Specific build ID to restore (default: previous build)"},yes:{type:"boolean",alias:"y",description:"Skip confirmation prompts",default:false}},async run({args:t}){b();let p=resolve("."),r;try{r=JSON.parse(await readFile(resolve(p,"package.json"),"utf-8"));}catch{a$4("No package.json found in current directory"),process.exit(1);}(!r.name||!r.version)&&(a$4("package.json missing name or version field"),process.exit(1));let s=await b$1(r.name,r.version);if(s.length===0){b$2.info("No build history available"),a({rolledBack:false});return}let e;if(t["build-id"]){if(e=t["build-id"],!s.find(u=>u.buildId===e)){b$2.error(`Build ${e} not found in history`),b$2.info("Available builds:");for(let u of s)b$2.log(` ${m.default.cyan(u.buildId)} ${m.default.dim(u.publishedAt)}`);a({rolledBack:false});return}}else e=s[0].buildId;let w=s.find(o=>o.buildId===e);if(!t.yes){let o=await b$2.prompt(`Restore build ${e} (published ${w.publishedAt})?`,{type:"confirm"});if(!o||typeof o=="symbol"){b$2.info("Cancelled"),a({rolledBack:false,buildId:e});return}}let R=await a$5(p),C=g(R.historyLimit);if(!await d(r.name,r.version,e,C)){b$2.error(`Failed to restore build ${e}`),a({rolledBack:false,buildId:e});return}b$2.success(`Restored ${r.name}@${r.version} to build ${e}`);let l=null,n;try{let o=await b$3(r.name,r.version);o?(l=await b$4(o,{force:!0,emitOutput:!1}),l.failedConsumers>0&&(process.exitCode=1)):(n=`Store entry missing after rollback for ${r.name}@${r.version}`,b$2.warn(n),process.exitCode=1);}catch(o){n=o instanceof Error?o.message:String(o),b$2.warn(`Push after rollback failed: ${n}`),process.exitCode=1;}a({rolledBack:true,buildId:e,pushed:l?l.failedConsumers===0:false,pushSummary:l,pushError:n}),b$5()&&d$1();}};export{z as default};
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {createRequire}from'node:module';import {f,a as a$2}from'./chunk-AA43FODB.mjs';import'./chunk-COI7GWH3.mjs';import'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import'./chunk-XDWZZBCM.mjs';import {a as a$1}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import'./chunk-U6O35NZ7.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import'./chunk-E3HZCU3S.mjs';import {d}from'./chunk-SPHWZS5P.mjs';import {b}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';globalThis.require=createRequire(import.meta.url);
3
- var S=class{static{a(this,"WatchOrchestrator");}packages=new Map;dependents=new Map;cascade;pushOptions={};constructor(e){this.cascade=e;}async start(e,a$3,s){this.pushOptions=s;let{buildWorkspaceGraph:o,buildReverseAdjacency:h,filterPublishableWorkspaceGraph:E}=await import('./workspace-T6PNO4L3.mjs'),{topoSort:q,CycleError:R}=await import('./topo-sort-ZNGR6D7M.mjs'),{startWatcher:W}=await import('./watcher-KOLIXRUG.mjs'),f$1=await o(e),c=E(f$1);if(c.packages.length===0){b.warn("No publishable workspace packages found");return}let w=f$1.packages.length-c.packages.length;w>0&&b.info(`Skipping ${w} private workspace package(s)`);let m;try{m=q(c.adjacency);}catch(t){if(t instanceof R){b.error(`Cannot watch: ${t.message}`);return}throw t}this.cascade&&(this.dependents=h(c.adjacency),b.info("Cascade mode enabled"));let j=new Map(c.packages.map(t=>[t.name,t.dir]));for(let t of m){let i=j.get(t);if(!i)continue;let u=await a$1(i),{buildCmd:k,patterns:M}=await f(i,a$3,u),O=a$3.notify??u.notify??false,x=a(async()=>{await this.runExclusive(t,async()=>{let p=await a$2(i,s);$(p,t),await this.onPackagePushed(t);});},"wrappedOnChange"),P=a(p=>{if(!p)return;let b=parseInt(p,10);return Number.isFinite(b)?b:void 0},"parseMs"),y={dir:i,buildCmd:k,state:"idle",watcher:{close:a(async()=>{},"close")}};this.packages.set(t,y);let G=await W(i,{patterns:M,buildCmd:k,debounce:P(a$3.debounce)??u.debounce,cooldown:P(a$3.cooldown)??u.cooldown,notify:O},x);y.watcher=G;}b.info(`Watching ${this.packages.size} workspace packages`),await new Promise(t=>{let i=a(async()=>{b.info("Stopping watchers..."),await this.close(),t();},"cleanup");process.once("SIGINT",i),process.once("SIGTERM",i);});}async onPackagePushed(e){if(!this.cascade)return;let a=this.dependents.get(e);if(!(!a||a.size===0)){d(`[cascade] ${e} pushed, triggering dependents: ${[...a].join(", ")}`);for(let s of a)await this.requestRebuild(s);}}async runExclusive(e,a){let s=this.packages.get(e);if(s){if(s.state==="queued"){d(`[cascade] ${e} already queued, skipping`);return}if(s.state==="building"){d(`[cascade] ${e} is building, marking as queued`),s.state="queued";return}s.state="building";try{await a(s);}finally{let o=s.state==="queued";s.state="idle",o&&await this.requestRebuild(e);}}}async requestRebuild(e){await this.runExclusive(e,async a=>{if(d(`[cascade] Rebuilding ${e}`),a.buildCmd){let{runBuildCommand:o}=await import('./watcher-KOLIXRUG.mjs');if(!await o(a.buildCmd,a.dir)){b.warn(`[cascade] Build failed for ${e}, skipping dependents`);return}}let s=await a$2(a.dir,this.pushOptions);$(s,e),await this.onPackagePushed(e);}).catch(a=>{b.warn(`[cascade] Push failed for ${e}: ${a instanceof Error?a.message:String(a)}`);});}async close(){await Promise.all([...this.packages.values()].map(e=>e.watcher.close())),this.packages.clear();}};function $(g,e){if(g.failedConsumers!==0)throw new Error(`Push for ${e} failed for ${g.failedConsumers} consumer(s)`)}a($,"assertPushSucceeded");export{S as WatchOrchestrator};
2
+ import {createRequire}from'node:module';import {f,a as a$2}from'./chunk-C4TZJOCB.mjs';import'./chunk-COI7GWH3.mjs';import'./chunk-QHNHLR6T.mjs';import'./chunk-ABG6UD3X.mjs';import'./chunk-XDWZZBCM.mjs';import {a as a$1}from'./chunk-3SXN6MQL.mjs';import'./chunk-WN3DOKIM.mjs';import'./chunk-MN4DV2NO.mjs';import'./chunk-HVN6HBWZ.mjs';import'./chunk-FSVETLZK.mjs';import'./chunk-U6O35NZ7.mjs';import'./chunk-QFHYSC3K.mjs';import'./chunk-W2MMKBWU.mjs';import'./chunk-G7HFTV5Y.mjs';import'./chunk-BH2WXCLS.mjs';import'./chunk-E3HZCU3S.mjs';import {d}from'./chunk-SPHWZS5P.mjs';import {b}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';globalThis.require=createRequire(import.meta.url);
3
+ var S=class{static{a(this,"WatchOrchestrator");}packages=new Map;dependents=new Map;cascade;pushOptions={};constructor(e){this.cascade=e;}async start(e,a$3,s){this.pushOptions=s;let{buildWorkspaceGraph:o,buildReverseAdjacency:h,filterPublishableWorkspaceGraph:E}=await import('./workspace-T6PNO4L3.mjs'),{topoSort:q,CycleError:R}=await import('./topo-sort-ZNGR6D7M.mjs'),{startWatcher:W}=await import('./watcher-ES2APFH4.mjs'),f$1=await o(e),c=E(f$1);if(c.packages.length===0){b.warn("No publishable workspace packages found");return}let w=f$1.packages.length-c.packages.length;w>0&&b.info(`Skipping ${w} private workspace package(s)`);let m;try{m=q(c.adjacency);}catch(t){if(t instanceof R){b.error(`Cannot watch: ${t.message}`);return}throw t}this.cascade&&(this.dependents=h(c.adjacency),b.info("Cascade mode enabled"));let j=new Map(c.packages.map(t=>[t.name,t.dir]));for(let t of m){let i=j.get(t);if(!i)continue;let u=await a$1(i),{buildCmd:k,patterns:M}=await f(i,a$3,u),O=a$3.notify??u.notify??false,x=a(async()=>{await this.runExclusive(t,async()=>{let p=await a$2(i,s);$(p,t),await this.onPackagePushed(t);});},"wrappedOnChange"),P=a(p=>{if(!p)return;let b=parseInt(p,10);return Number.isFinite(b)?b:void 0},"parseMs"),y={dir:i,buildCmd:k,state:"idle",watcher:{close:a(async()=>{},"close")}};this.packages.set(t,y);let G=await W(i,{patterns:M,buildCmd:k,debounce:P(a$3.debounce)??u.debounce,cooldown:P(a$3.cooldown)??u.cooldown,notify:O},x);y.watcher=G;}b.info(`Watching ${this.packages.size} workspace packages`),await new Promise(t=>{let i=a(async()=>{b.info("Stopping watchers..."),await this.close(),t();},"cleanup");process.once("SIGINT",i),process.once("SIGTERM",i);});}async onPackagePushed(e){if(!this.cascade)return;let a=this.dependents.get(e);if(!(!a||a.size===0)){d(`[cascade] ${e} pushed, triggering dependents: ${[...a].join(", ")}`);for(let s of a)await this.requestRebuild(s);}}async runExclusive(e,a){let s=this.packages.get(e);if(s){if(s.state==="queued"){d(`[cascade] ${e} already queued, skipping`);return}if(s.state==="building"){d(`[cascade] ${e} is building, marking as queued`),s.state="queued";return}s.state="building";try{await a(s);}finally{let o=s.state==="queued";s.state="idle",o&&await this.requestRebuild(e);}}}async requestRebuild(e){await this.runExclusive(e,async a=>{if(d(`[cascade] Rebuilding ${e}`),a.buildCmd){let{runBuildCommand:o}=await import('./watcher-ES2APFH4.mjs');if(!await o(a.buildCmd,a.dir)){b.warn(`[cascade] Build failed for ${e}, skipping dependents`);return}}let s=await a$2(a.dir,this.pushOptions);$(s,e),await this.onPackagePushed(e);}).catch(a=>{b.warn(`[cascade] Push failed for ${e}: ${a instanceof Error?a.message:String(a)}`);});}async close(){await Promise.all([...this.packages.values()].map(e=>e.watcher.close())),this.packages.clear();}};function $(g,e){if(g.failedConsumers!==0)throw new Error(`Push for ${e} failed for ${g.failedConsumers} consumer(s)`)}a($,"assertPushSucceeded");export{S as WatchOrchestrator};
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import {createRequire}from'node:module';import {a as a$1}from'./chunk-J6HZHQVL.mjs';import {b}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';import {spawn}from'child_process';import {readdir,stat}from'fs/promises';import {release,platform}from'os';import {join}from'path';globalThis.require=createRequire(import.meta.url);
3
+ var y=new Set;function G(){for(let t of y)t.killed||t.kill("SIGTERM");y.clear();}a(G,"killActiveBuild");var N=new Set(["node_modules",".git",".knarr"]);function z(t,e={platform:platform(),release:release(),webcontainer:!!process.versions?.webcontainer}){return e.webcontainer?true:e.platform==="linux"&&/microsoft|wsl/i.test(e.release)&&/^\/mnt\/[a-z](?:\/|$)/i.test(t)}a(z,"shouldUsePolling");async function R(t,e){let s;try{s=await readdir(t,{withFileTypes:!0});}catch{return}for(let o of s){if(N.has(o.name))continue;let f=join(t,o.name);if(o.isDirectory())await R(f,e);else try{let d=await stat(f);e.set(f,d.mtimeMs);}catch{}}}a(R,"walkDir");async function D(t){let e=new Map;for(let s of t)try{let o=await stat(s);o.isDirectory()?await R(s,e):e.set(s,o.mtimeMs);}catch{}return e}a(D,"buildSnapshot");async function V(t,e,s){let{watch:o}=await import('./chokidar-2G63V464.mjs'),f=e.patterns??["src","lib"],d=f.map(i=>i.startsWith("/")||i.includes(":")?i:`${t}/${i}`),m=e.debounce??500,l=e.cooldown??500,n=null,h=false,b$1=false,g=0,$=0,v=null,P=false,T=a(async()=>{if(h||b$1)return;let i=Date.now()-g;if(g>0&&i<l){let r=l-i;n&&clearTimeout(n),n=setTimeout(()=>{n=null,T();},r);return}b$1=true,P=false,$++;try{if(b.info(`Change cycle #${$} started`),e.buildCmd&&!await A(e.buildCmd,t)){if(b.warn("Build failed (see output above), skipping push"+(v?`. Last successful push: ${v.toLocaleTimeString()}`:". No successful push yet.")),e.notify){let{ringBell:u}=await import('./bell-SIN4ERLS.mjs');u(!0);}return}await s(),v=new Date,e.notify&&a$1(!0);}catch(r){b.error(`Push failed: ${r instanceof Error?r.message:String(r)}`),e.notify&&a$1(true);}finally{b$1=false,g=Date.now(),P&&!h&&(P=false,n=setTimeout(()=>{n=null,T();},l));}},"doBuild"),p=a(i=>{if(h)return;if(b$1){P=true;return}let r=Date.now()-g;if(g>0&&r<l){n&&clearTimeout(n);let u=l-r;n=setTimeout(()=>{n=null,T();},u+m);return}n&&clearTimeout(n),n=setTimeout(()=>{n=null,T();},m);},"onFileEvent"),x=e.buildCmd?false:e.awaitWriteFinish??{stabilityThreshold:200,pollInterval:50},B=z(t),w=o(d,{ignoreInitial:true,ignored:[/[/\\]node_modules[/\\]/,/[/\\]\.git[/\\]/,/[/\\]\.knarr[/\\]/],awaitWriteFinish:x,usePolling:B,...B&&{interval:1e3}});w.on("change",p),w.on("add",p),w.on("unlink",p),w.on("error",i=>{b.error(`Watcher error: ${i instanceof Error?i.message:String(i)}`);});let S=null;if(B){let i=await D(d);S=setInterval(async()=>{if(!h)try{let r=await D(d);for(let[u,F]of r){let W=i.get(u);if(W===void 0||W!==F){p(u);break}}if(!h){for(let u of i.keys())if(!r.has(u)){p(u);break}}i=r;}catch{}},1e3);}let C={close:a(async()=>{h=true,S&&clearInterval(S),n&&clearTimeout(n),G(),await w.close();},"close")};return b.info(`Watching for changes in: ${f.join(", ")}`),C}a(V,"startWatcher");function A(t,e){return new Promise(s=>{let o=platform()==="win32",f=o?"cmd":"sh",d=o?"/c":"-c";b.start(`Running: ${t}`);let m=spawn(f,[d,t],{cwd:e,stdio:"inherit"});y.add(m),m.on("close",l=>{y.delete(m),l===0?(b.success("Build succeeded"),s(true)):(b.error(`Build failed with code ${l}`),s(false));}),m.on("error",l=>{y.delete(m),b.error(`Build error: ${l.message}`),s(false);});})}a(A,"runBuildCommand");export{G as killActiveBuild,A as runBuildCommand,z as shouldUsePolling,V as startWatcher};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "knarr",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Copy local npm package builds into consumer node_modules with incremental sync and watch mode.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -86,7 +86,7 @@
86
86
  "node": ">=22.12.0"
87
87
  },
88
88
  "devDependencies": {
89
- "@types/node": "^25.6.0",
89
+ "@types/node": "^26.0.0",
90
90
  "@types/picomatch": "^4.0.3",
91
91
  "tsup": "^8.5.1",
92
92
  "typescript": "^6.0.3",
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import {createRequire}from'node:module';import {a as a$1}from'./chunk-J6HZHQVL.mjs';import {b}from'./chunk-OQDZJP55.mjs';import {a}from'./chunk-L7O2RSTN.mjs';import {spawn}from'child_process';import {readdir,stat}from'fs/promises';import {platform}from'os';import {join}from'path';globalThis.require=createRequire(import.meta.url);
3
- var y=new Set;function _(){for(let i of y)i.killed||i.kill("SIGTERM");y.clear();}a(_,"killActiveBuild");var G=new Set(["node_modules",".git",".knarr"]);async function E(i,e){let s;try{s=await readdir(i,{withFileTypes:!0});}catch{return}for(let o of s){if(G.has(o.name))continue;let f=join(i,o.name);if(o.isDirectory())await E(f,e);else try{let m=await stat(f);e.set(f,m.mtimeMs);}catch{}}}a(E,"walkDir");async function I(i){let e=new Map;for(let s of i)try{let o=await stat(s);o.isDirectory()?await E(s,e):e.set(s,o.mtimeMs);}catch{}return e}a(I,"buildSnapshot");async function Q(i,e,s){let{watch:o}=await import('./chokidar-2G63V464.mjs'),f=e.patterns??["src","lib"],m=f.map(n=>n.startsWith("/")||n.includes(":")?n:`${i}/${n}`),d=e.debounce??500,a$2=e.cooldown??500,t=null,h=false,b$1=false,w=0,C=0,P=null,T=false,v=a(async()=>{if(h||b$1)return;let n=Date.now()-w;if(w>0&&n<a$2){let r=a$2-n;t&&clearTimeout(t),t=setTimeout(()=>{t=null,v();},r);return}b$1=true,T=false,C++;try{if(b.info(`Change cycle #${C} started`),e.buildCmd&&!await N(e.buildCmd,i)){if(b.warn("Build failed (see output above), skipping push"+(P?`. Last successful push: ${P.toLocaleTimeString()}`:". No successful push yet.")),e.notify){let{ringBell:c}=await import('./bell-SIN4ERLS.mjs');c(!0);}return}await s(),P=new Date,e.notify&&a$1(!0);}catch(r){b.error(`Push failed: ${r instanceof Error?r.message:String(r)}`),e.notify&&a$1(true);}finally{b$1=false,w=Date.now(),T&&!h&&(T=false,t=setTimeout(()=>{t=null,v();},a$2));}},"doBuild"),g=a(n=>{if(h)return;if(b$1){T=true;return}let r=Date.now()-w;if(w>0&&r<a$2){t&&clearTimeout(t);let c=a$2-r;t=setTimeout(()=>{t=null,v();},c+d);return}t&&clearTimeout(t),t=setTimeout(()=>{t=null,v();},d);},"onFileEvent"),R=e.buildCmd?false:e.awaitWriteFinish??{stabilityThreshold:200,pollInterval:50},B=!!process.versions?.webcontainer,p=o(m,{ignoreInitial:true,ignored:[/[/\\]node_modules[/\\]/,/[/\\]\.git[/\\]/,/[/\\]\.knarr[/\\]/],awaitWriteFinish:R,usePolling:B,...B&&{interval:1e3}});p.on("change",g),p.on("add",g),p.on("unlink",g),p.on("error",n=>{b.error(`Watcher error: ${n instanceof Error?n.message:String(n)}`);});let S=null;if(B){let n=await I(m);S=setInterval(async()=>{if(!h)try{let r=await I(m);for(let[c,F]of r){let $=n.get(c);if($===void 0||$!==F){g(c);break}}if(!h){for(let c of n.keys())if(!r.has(c)){g(c);break}}n=r;}catch{}},1e3);}let W={close:a(async()=>{h=true,S&&clearInterval(S),t&&clearTimeout(t),_(),await p.close();},"close")};return b.info(`Watching for changes in: ${f.join(", ")}`),W}a(Q,"startWatcher");function N(i,e){return new Promise(s=>{let o=platform()==="win32",f=o?"cmd":"sh",m=o?"/c":"-c";b.start(`Running: ${i}`);let d=spawn(f,[m,i],{cwd:e,stdio:"inherit"});y.add(d),d.on("close",a=>{y.delete(d),a===0?(b.success("Build succeeded"),s(true)):(b.error(`Build failed with code ${a}`),s(false));}),d.on("error",a=>{y.delete(d),b.error(`Build error: ${a.message}`),s(false);});})}a(N,"runBuildCommand");export{_ as killActiveBuild,N as runBuildCommand,Q as startWatcher};