knarr 0.3.1 → 0.3.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/{add-CyrFHzUe.mjs → add-CZp5YVWF.mjs} +1 -1
- package/dist/add-flow-D9HxSmKS.mjs +3 -0
- package/dist/{batch-push-Cee2SPW3.mjs → batch-push-CT5k2SrS.mjs} +1 -1
- package/dist/{build-detect-Bo1fe8OV.mjs → build-detect-Bf2HAfXm.mjs} +1 -1
- package/dist/{check-ChNlHxR5.mjs → check-BFgQ7Px_.mjs} +1 -1
- package/dist/{clean-oNr4nUNk.mjs → clean-B4S8pHpI.mjs} +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/{config-D0TqqAAJ.mjs → config-DEpSKyI8.mjs} +1 -1
- package/dist/{dev-vA8K5egW.mjs → dev-DtbwBD_E.mjs} +1 -1
- package/dist/{doctor-ITFcIVoj.mjs → doctor-Ca2eGyC8.mjs} +1 -1
- package/dist/{explain-xtY13-Ex.mjs → explain-U6-XLo4U.mjs} +1 -1
- package/dist/history-BNX-3W-p.mjs +1 -0
- package/dist/history-Da5gEptz.mjs +1 -0
- package/dist/index.mjs +1 -1
- package/dist/{init-KBwXbX7j.mjs → init-BJZdXWmg.mjs} +1 -1
- package/dist/{init-helpers-DGSTVbNx.mjs → init-helpers-DfznkCwv.mjs} +1 -1
- package/dist/injector-CwNZ9rDe.mjs +1 -0
- package/dist/{json-1jsvqdBb.mjs → json-b5d4W58a.mjs} +1 -1
- package/dist/{list-BkniWIlD.mjs → list-BekXJBqC.mjs} +1 -1
- package/dist/{migrate-DM80YXOF.mjs → migrate-DGXYBPRz.mjs} +2 -2
- package/dist/{nextjs-config-BlbmHmCb.mjs → nextjs-config-C2Xv-pZR.mjs} +1 -1
- package/dist/{nextjs-config-m83qz9Qp.mjs → nextjs-config-D3H6P4Is.mjs} +1 -1
- package/dist/{package-manager-Cs9kCsjJ.mjs → package-manager-DENvuHqT.mjs} +1 -1
- package/dist/paths-V3_BeE_z.mjs +1 -0
- package/dist/{preflight-fF8g1t6F.mjs → preflight-DPlVrYLp.mjs} +1 -1
- package/dist/preflight-tgLzruAR.mjs +1 -0
- package/dist/{publish-PaTRQ5Ga.mjs → publish-DViw9ie6.mjs} +1 -1
- package/dist/publisher-PQIqCt7r.mjs +2 -0
- package/dist/{push-DX9dRKDw.mjs → push-ChVt0ofE.mjs} +1 -1
- package/dist/{push-engine-ByiNZr52.mjs → push-engine-IoOaMeZe.mjs} +1 -1
- package/dist/{remove-BEBkMPak.mjs → remove-BVr3n-3t.mjs} +1 -1
- package/dist/remove-Ch5tlQkh.mjs +1 -0
- package/dist/{reset-B9Xcepo1.mjs → reset-DD5BaA6m.mjs} +1 -1
- package/dist/{restore-B8aEJn3N.mjs → restore-DaJjdT2B.mjs} +1 -1
- package/dist/{rollback-pqomySb-.mjs → rollback-B7QjnKje.mjs} +1 -1
- package/dist/{status-2-lE-2hH.mjs → status-BHe6UGa2.mjs} +1 -1
- package/dist/store-D2r3Vo5S.mjs +1 -0
- package/dist/{tailwind-source-Ho_nKVtd.mjs → tailwind-source-Ck2WyTX8.mjs} +1 -1
- package/dist/tracker-BUpkmn8j.mjs +1 -0
- package/dist/tracker-Cf_gNhit.mjs +1 -0
- package/dist/update-BuQUMzU2.mjs +1 -0
- package/dist/{use-BCXyvJf2.mjs → use-By-V869_.mjs} +1 -1
- package/dist/validators-C0_prNkT.mjs +1 -0
- package/dist/{vite-config-D_iXaoHh.mjs → vite-config-Bvv75_oH.mjs} +1 -1
- package/dist/{vite-config-B6bZDoGe.mjs → vite-config-DQfi8QwQ.mjs} +1 -1
- package/dist/vite-plugin.mjs +1 -1
- package/dist/watch-orchestrator-5eaHlofc.mjs +1 -0
- package/dist/{watch-orchestrator-DkuwJOEb.mjs → watch-orchestrator-B1hlJ10Y.mjs} +1 -1
- package/dist/webpack-plugin.mjs +1 -1
- package/dist/{workspace-7rWwh6jI.mjs → workspace-BBfh7dJY.mjs} +1 -1
- package/dist/{workspace-CSQVbAw4.mjs → workspace-CYaUDFd5.mjs} +1 -1
- package/package.json +1 -1
- package/dist/add-flow-BjjRSNWm.mjs +0 -3
- package/dist/history-540r0BHF.mjs +0 -1
- package/dist/history-B3E1DMFO.mjs +0 -1
- package/dist/injector-BMOi1uN3.mjs +0 -1
- package/dist/paths-B5sEvS_7.mjs +0 -1
- package/dist/preflight-C_Zr3uyO.mjs +0 -1
- package/dist/publisher-oHVy3LA2.mjs +0 -2
- package/dist/remove-DxezmGfU.mjs +0 -1
- package/dist/store-CAzxNmpU.mjs +0 -1
- package/dist/tracker-OhIA445x.mjs +0 -1
- package/dist/tracker-nsfA6PWa.mjs +0 -1
- package/dist/update-CjAl0ZO9.mjs +0 -1
- package/dist/watch-orchestrator-DGe9gBjj.mjs +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./timer-BZNWRS3O.mjs";import{n}from"./output-B7NC4xgj.mjs";import{t as r}from"./add-flow-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./timer-BZNWRS3O.mjs";import{n}from"./output-B7NC4xgj.mjs";import{t as r}from"./add-flow-D9HxSmKS.mjs";var i=e({meta:{name:`add`,description:`Link a package from the Knarr store into this project`},args:{package:{type:`positional`,description:`Package name to add`,required:!0},from:{type:`string`,description:`Path to package source (will publish first)`},build:{type:`string`,description:`Build command to run before publishing --from`},"skip-build":{type:`boolean`,description:`Skip build detection before publishing --from`,default:!1},yes:{type:`boolean`,alias:`y`,description:`Auto-accept prompts (install missing deps, etc.)`,default:!1}},async run({args:e}){n(),await r({packageArg:e.package,from:e.from,build:e.build,skipBuild:e[`skip-build`],yes:e.yes,timer:new t})}});export{i as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{n as e}from"./shell-DQfdqK0J.mjs";import{t}from"./hints-BKo_2axg.mjs";import{t as n}from"./console-C8XtlRyM.mjs";import{n as r,t as i}from"./store-D2r3Vo5S.mjs";import{t as a}from"./publisher-PQIqCt7r.mjs";import{i as o,n as s,r as c,t as l}from"./injector-CwNZ9rDe.mjs";import{d as u,h as d,n as f,o as p}from"./tracker-BUpkmn8j.mjs";import{c as m}from"./fs-DusqxRQR.mjs";import{t as h}from"./package-manager-DENvuHqT.mjs";import{t as g}from"./build-detect-Bf2HAfXm.mjs";import{n as _}from"./bundler-detect-BaShXORS.mjs";import{i as v,o as y}from"./init-helpers-DfznkCwv.mjs";import{t as b}from"./nextjs-config-D3H6P4Is.mjs";import{i as x}from"./paths-V3_BeE_z.mjs";import{t as S}from"./timer-BZNWRS3O.mjs";import{t as C}from"./output-B7NC4xgj.mjs";import{t as w}from"./errors-DRugrv36.mjs";import{i as T,n as E,r as D}from"./logger-Oo2Slehd.mjs";import{i as O,r as k}from"./dry-run-DPoN8bZo.mjs";import{a as A,o as j,s as M}from"./validators-C0_prNkT.mjs";import{o as N}from"./json-b5d4W58a.mjs";import{readFile as P}from"node:fs/promises";import{basename as F,join as I,resolve as L}from"node:path";async function R(e){let s=e.timer??new S,g=L(`.`),{name:_,version:b}=B(e.packageArg),T,D=null,O=!1,A=!1;if(V(_,e.packageArg),b)try{j(b)}catch{w(`Invalid package version "${b}" in "${e.packageArg}".`),process.exit(1)}let N=(await h(g)).resolve(),P=N.packageManager;if(N.nodeModulesCompatible||(n.error(N.incompatibilityReason),process.exit(1)),e.from){let t=L(e.from);T=t;let r=await H(t,{build:e.build,skipBuild:e.skipBuild,yes:e.yes??!1});D=r.buildCmd,O=r.ran,A=r.skipped,n.info(`Publishing from ${t}...`),await a(t)}let F=b?await r(_,b):await i(_);if(!F){let e=b?`@${b}`:``;w(`Package "${_}${e}" not found in store. Run 'knarr publish' in the package directory first, or use --from <path>.`),process.exit(1)}await m(x(g))||(await v(g,P),n.success(`Auto-initialized knarr (consumer mode)`)),n.info(`Detected package manager: ${P}`);let I=await p(g,_);I&&(I.version===F.version?n.info(`Updating ${_}@${F.version} (already linked)`):n.info(`Updating ${_}: ${I.version} -> ${F.version}`));let R=I?I.backupExists:await l(g,_,P);!I&&R&&n.info(`Backed up existing ${_} installation`),await M(g,_,F.version),await K(g,_,N),await G(F,g,N,e.yes??!1);let z=await c(F,g,P);n.success(`Linked ${_}@${F.version} -> node_modules/${_} (${z.copied} files copied, ${z.skipped} unchanged)`),z.binLinks>0&&n.info(`Created ${z.binLinks} bin link(s)`);let W={version:F.version,contentHash:F.meta.contentHash,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),sourcePath:F.meta.sourcePath,backupExists:R,packageManager:P,buildId:F.meta.buildId??``};await f(g,_,W),await u(_,g).catch(d),await y(g),await o(g,_)||n.info(`${_} isn't in package.json, so adding or removing other packages can prune it. Run \`knarr restore\` afterwards, or add it to dependencies.`);let q=T?[`cd ${T} && knarr dev`]:[];T&&n.info(`Next: ${t(T,process.cwd(),await U(T))}`),n.info(`Done in ${s.elapsed()}`);let J={package:_,version:F.version,copied:z.copied,skipped:z.skipped,binLinks:z.binLinks,elapsed:s.elapsedMs(),buildCmd:D,buildRan:O,buildSkipped:A,nextSteps:q};return e.emitOutput!==!1&&C(J),E()&&k(),J}async function z(e){let t=L(e);await m(t)||(w(`Source path not found: ${t}`),process.exit(1));let n=I(t,`package.json`);await m(n)||(w(`No package.json found at ${n}. Pass a package directory to 'knarr use'.`),process.exit(1));let r;try{r=N(await P(n,`utf-8`))}catch(e){w(`Could not read package.json at ${n}: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}r&&typeof r==`object`&&typeof r.name==`string`||(w(`package.json at ${n} must include a package name for 'knarr use'.`),process.exit(1));let i=r.name.trim();return V(i,i),i}function B(e){if(e.startsWith(`@`)){let t=e.indexOf(`/`);if(t>0){let n=e.indexOf(`@`,t);if(n>t)return{name:e.slice(0,n),version:e.slice(n+1)}}return{name:e,version:null}}let t=e.lastIndexOf(`@`);return t>0?{name:e.slice(0,t),version:e.slice(t+1)}:{name:e,version:null}}function V(e,t){try{A(e)}catch{w(`Invalid package name "${t}". Use format: package-name or @scope/package-name.`),process.exit(1)}}async function H(e,t){if(t.skipBuild)return t.build&&n.warn(`--skip-build was provided; ignoring --build`),{buildCmd:null,ran:!1,skipped:!0};let r=t.build,i=!!r;if(!r){let t=(await h(e)).resolve().packageManager;r=await g(e,t)??void 0}if(!r)return{buildCmd:null,ran:!1,skipped:!1};if(!i&&!t.yes&&!D()){let e=await n.prompt(`Run detected build command before publishing? (${r})`,{type:`confirm`,initial:!0});if(!e||typeof e==`symbol`)return n.info(`Skipping build before publish`),{buildCmd:r,ran:!1,skipped:!0}}else if(!i&&D()&&!t.yes)return T(`[add] Detected build command but skipping in json mode: ${r}`),{buildCmd:r,ran:!1,skipped:!0};return n.info(E()?`[dry-run] Would run build command: ${r}`:`Running build command: ${r}`),await q(r,e)||(w(`Build command failed: ${r}`),await W(e),process.exit(1)),{buildCmd:r,ran:!0,skipped:!1}}async function U(e){let{findWorkspacePackageRoot:t,findWorkspacePackages:n}=await import(`./workspace-CYaUDFd5.mjs`),r=await t(e);if(!r)return null;let i=await n(r),a=L(e);return i.some(e=>L(e)===a)?r:null}async function W(e){if(!await m(I(e,`node_modules`))){let t=(await h(e)).resolve().packageManager;n.info(`Suggestion: ${e} has no node_modules. Run \`${t} install\` there, then retry.`)}n.info(`Suggestion: if the package is already built, re-run with --skip-build.`)}async function G(e,t,r,i){let a=r.packageManager,o=await s(e,t,a);if(o.length!==0){if(D())T(`[add] Missing transitive deps (json mode): ${o.join(`, `)}`);else if(i){let e=r.installCommand(o),t=r.formatCommand(e);n.info(E()?`[dry-run] Would install missing dependencies: ${o.join(`, `)}`:`Installing missing dependencies: ${o.join(`, `)}`);let i=await r.run(e);i&&!E()?n.success(`Installed missing dependencies`):i||n.warn(`Install failed. Run manually: ${t}`)}else if(await n.prompt(`Install ${o.length} missing dependencies? (${o.join(`, `)})`,{type:`confirm`,initial:!0})){let e=r.installCommand(o),t=r.formatCommand(e),i=await r.run(e);i&&!E()?n.success(`Installed missing dependencies`):i||n.warn(`Install failed. Run manually: ${t}`)}else{let e=r.installCommand(o);n.warn(`Missing transitive dependencies: ${o.join(`, `)}\n Run: ${r.formatCommand(e)}`)}}}async function K(e,t,r){let i=await _(e);if(i.type===`next`&&i.configFile){let e=await b(i.configFile,t);e.modified?n.success(`Added ${t} to transpilePackages in ${F(i.configFile)}`):e.error&&n.info(`Add to next.config manually: transpilePackages: ['${t}']`)}else if(i.type===`vite`&&i.configFile){let{addKnarrVitePlugin:e}=await import(`./vite-config-DQfi8QwQ.mjs`),t=await e(i.configFile);if(t.modified){n.success(`Added knarr plugin to ${F(i.configFile)}`);let e=r.installCommand([`knarr`],{dev:!0}),t=r.formatCommand(e);n.info(E()?`[dry-run] Would install knarr as devDependency`:`Installing knarr as devDependency...`);let a=await r.run(e);a&&!E()?n.success(`Installed knarr`):a||n.warn(`Install failed. Run manually: ${t}`)}else t.error&&n.info(`Add manually:
|
|
2
|
+
import knarr from "knarr/vite"
|
|
3
|
+
plugins: [knarr()]`)}let{findTailwindCss:a,addTailwindSource:o}=await import(`./tailwind-source-Ck2WyTX8.mjs`),s=await a(e);if(s){let r=await o(s,t,e);r.modified?n.success(`Added @source for ${t} to ${F(s)}`):r.error&&n.info(`Add to your CSS manually: @source "../node_modules/${t}";`)}}function q(t,n){return E()?(O({type:`command-skip`,path:n,detail:t}),Promise.resolve(!0)):new Promise(r=>{let i=e(t,{cwd:n,stdio:`inherit`});i.on(`close`,e=>r(e===0)),i.on(`error`,()=>r(!1))})}export{z as n,R as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./console-C8XtlRyM.mjs";import{n as t,r as n,t as r}from"./workspace-
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{n as t,r as n,t as r}from"./workspace-BBfh7dJY.mjs";import{n as i,t as a}from"./topo-sort-I086ZoiN.mjs";import{t as o}from"./push-engine-IoOaMeZe.mjs";import{t as s}from"./timer-BZNWRS3O.mjs";import{i as c}from"./logger-Oo2Slehd.mjs";async function l(l,d={}){let f=new s,p=await t(l),m=n(p);if(m.packages.length===0){e.warn(`No publishable workspace packages found`);return}let h=p.packages.length-m.packages.length;h>0&&e.info(`Skipping ${h} private workspace package(s)`);let g;try{g=i(m.adjacency)}catch(t){throw t instanceof a&&e.error(`Cannot push: ${t.message}`),t}let _=new Map(m.packages.map(e=>[e.name,e.dir]));e.info(`Pushing ${g.length} packages in dependency order`),c(`[batch-push] Order: ${g.join(` → `)}`);let v=r(m.adjacency),y=new Set(d.skipPackages??[]);for(let e of[...y])u(e,v,y);let b=0,x=0,S=0;for(let t of g){let n=_.get(t);if(n){if(y.has(t))c(`[batch-push] Skipping ${t}: dependency build/push failed`),S++;else try{(await o(n,d)).failedConsumers>0?(x++,u(t,v,y)):b++}catch(n){e.warn(`Failed to push ${t}: ${n instanceof Error?n.message:String(n)}`),x++,u(t,v,y)}}}let C=[x>0?`${x} failed`:null,S>0?`${S} skipped`:null].filter(e=>e!==null),w=`Pushed ${b}/${g.length} packages in ${f.elapsed()}`+(C.length>0?` (${C.join(`, `)})`:``);if(x>0)throw e.warn(w),Error(`Failed to push ${x} workspace package(s)`);S>0?e.warn(w):e.success(w)}function u(e,t,n){for(let r of t.get(e)??[])n.has(r)||(n.add(r),u(r,t,n))}export{l as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e,u as t}from"./json-
|
|
1
|
+
import{c as e,u as t}from"./json-b5d4W58a.mjs";import{join as n}from"node:path";async function r(r,i){let a=i===`npm`||i===`bun`?`${i} run `:`${i} `;try{let i=t(await e(n(r,`package.json`)),`scripts`);for(let e of[`build`,`compile`,`bundle`,`tsc`])if(i[e])return`${a}${e}`}catch{}return null}export{r as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{t as r}from"./preflight-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{t as r}from"./preflight-DPlVrYLp.mjs";import{n as i,t as a}from"./output-B7NC4xgj.mjs";import{resolve as o}from"node:path";var s=e({meta:{name:`check`,description:`Validate package configuration (exports, types, entry points)`},args:{dir:{type:`positional`,description:`Package directory (default: current directory)`,required:!1}},async run({args:e}){i();let s=o(e.dir||`.`),c=await r(s);if(c.length===0){n.success(`All pre-flight checks passed`),a({issues:[],passed:!0});return}let l=c.filter(e=>e.severity===`error`),u=c.filter(e=>e.severity===`warn`);n.info(`Found ${c.length} issue(s):\n`);for(let e of l)n.log(` ${t.red(`ERROR`)} ${t.dim(`[${e.code}]`)} ${e.message}`);for(let e of u)n.log(` ${t.yellow(`WARN`)} ${t.dim(`[${e.code}]`)} ${e.message}`);l.length>0?n.error(`\n${l.length} error(s), ${u.length} warning(s)`):n.warn(`\n${u.length} warning(s)`),a({issues:c,passed:l.length===0})}});export{s as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{c as n,l as r,r as i}from"./tracker-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{c as n,l as r,r as i}from"./tracker-BUpkmn8j.mjs";import{a,r as o,s}from"./store-D2r3Vo5S.mjs";import{a as c,c as l,f as u}from"./fs-DusqxRQR.mjs";import{t as d}from"./format-IsfSiyGV.mjs";import{i as f,n as p}from"./logger-Oo2Slehd.mjs";import{r as m}from"./dry-run-DPoN8bZo.mjs";import{n as h,t as g}from"./output-B7NC4xgj.mjs";import{f as _,p as v}from"./paths-V3_BeE_z.mjs";import{t as y}from"./timer-BZNWRS3O.mjs";import{readdir as b}from"node:fs/promises";import{join as x}from"node:path";const S=3e5;var C=e({meta:{name:`clean`,description:`Remove unreferenced store entries and stale consumer registrations`},args:{yes:{type:`boolean`,alias:`y`,description:`Skip confirmation prompts`,default:!1}},async run({args:e}){h();let C=new y;t.start(`Checking consumer registrations...`);let{removedConsumers:w,removedPackages:T}=await i();w>0&&t.success(`Removed ${w} stale consumer registration(s) across ${T} package(s)`);let E=await r(),D=/* @__PURE__ */ new Set,O=[...new Set(Object.values(E).flat())],k=await Promise.all(O.map(async e=>{let{state:t,reliable:r}=await n(e);return{path:e,state:t,reliable:r}}));for(let{state:e,reliable:t}of k)if(t)for(let[t,n]of Object.entries(e.links))D.add(`${t}@${n.version}`);let A=/* @__PURE__ */ new Set,j=k.filter(e=>!e.reliable);if(j.length>0){t.warn(`${j.length} consumer(s) have corrupt state; their store entries will be preserved`);let e=new Set(j.map(e=>v(e.path)));for(let[t,n]of Object.entries(E))n.some(t=>e.has(t))&&A.add(t);f(`[clean] Protected packages (corrupt state): ${[...A].join(`, `)}`)}f(`[clean] Referenced entries: ${[...D].join(`, `)||`(none)`}`);let M=await o(),N=[];for(let e of M){let t=`${e.name}@${e.version}`;if(!D.has(t)){if(A.has(e.name)){f(`[clean] Preserving ${t} (consumer state unreadable)`);continue}let n=Date.now()-new Date(e.meta.publishedAt).getTime();if(n<S){f(`[clean] Skipping recently published entry: ${t} (${Math.round(n/1e3)}s old)`);continue}N.push(e)}}let P=[],F=_();if(await l(F)){let e=await b(F,{withFileTypes:!0});for(let t of e){let e=t.isDirectory()?a(t.name):null;if(e===null)continue;let n=Date.now()-e;n<S?f(`[clean] Skipping recent temp directory: ${t.name} (${Math.round(n/1e3)}s old)`):P.push(t.name)}}if(N.length+P.length>0&&!e.yes){let e=[];N.length>0&&e.push(`${N.length} unreferenced store entry(ies)`),P.length>0&&e.push(`${P.length} orphaned temp directory(ies)`);let n=await t.prompt(`Remove ${e.join(` and `)}?`,{type:`confirm`});if(!n||typeof n==`symbol`){t.info(`Cancelled`);return}}let I=0,L=await Promise.all(N.map(e=>c(e.packageDir))),R=await Promise.all(P.map(e=>c(x(F,e)))),z=0;for(let[e,t]of N.entries())f(`[clean] Removing unreferenced store entry: ${t.name}@${t.version}`),await s(t.name,t.version),I+=L[e]??0,z++;z>0&&t.success(`Removed ${z} unreferenced store entry(ies)`);let B=0;for(let[e,t]of P.entries())f(`[clean] Removing orphaned directory: ${t}`),await u(x(F,t)),I+=R[e]??0,B++;B>0&&t.success(`Removed ${B} orphaned temp directory(ies)`),w===0&&z===0&&B===0&&t.info(`Store is clean; no stale entries or registrations found`);let V=I>0?` (reclaimed ${d(I)})`:``;t.info(`Clean complete in ${C.elapsed()}${V}`),g({removedConsumers:w,removedPackages:T,removedEntries:z,removedOrphans:B,reclaimedBytes:I,elapsed:C.elapsedMs()}),p()&&m()}});export{C as default};
|
package/dist/cli.mjs
CHANGED
|
@@ -6,4 +6,4 @@ import{n as e,t}from"./dist-jMqCJR3W.mjs";import{t as n}from"./logger-Oo2Slehd.m
|
|
|
6
6
|
| . \\| | | | (_| | | | |
|
|
7
7
|
|_|\\_\\_| |_|\\__,_|_| |_|
|
|
8
8
|
`)),console.log(r.cyan(` Local npm package development without symlinks`)),console.log(r.dim(` Copies built files into consumer node_modules with incremental sync
|
|
9
|
-
`))}process.env.UV_THREADPOOL_SIZE??=String(Math.max(a(),8)),n();const s=process.argv.slice(2),c=[`init`,`publish`,`add`,`use`,`remove`,`push`,`dev`,`restore`,`list`,`status`,`update`,`clean`,`gc`,`doctor`,`explain`,`migrate`,`reset`,`rollback`,`check`],l=s.some(e=>!e.startsWith(`-`)&&c.includes(e)),u=s.includes(`--help`)||s.includes(`-h`)||s.includes(`--version`);if(!l&&!u&&process.stdin.isTTY){o();let e=await d();e&&process.argv.splice(2,0,e)}else l||o();async function d(){try{let{readConsumerStateSafe:e}=await import(`./tracker-
|
|
9
|
+
`))}process.env.UV_THREADPOOL_SIZE??=String(Math.max(a(),8)),n();const s=process.argv.slice(2),c=[`init`,`publish`,`add`,`use`,`remove`,`push`,`dev`,`restore`,`list`,`status`,`update`,`clean`,`gc`,`doctor`,`explain`,`migrate`,`reset`,`rollback`,`check`],l=s.some(e=>!e.startsWith(`-`)&&c.includes(e)),u=s.includes(`--help`)||s.includes(`-h`)||s.includes(`--version`);if(!l&&!u&&process.stdin.isTTY){o();let e=await d();e&&process.argv.splice(2,0,e)}else l||o();async function d(){try{let{readConsumerStateSafe:e}=await import(`./tracker-Cf_gNhit.mjs`),{resolve:t}=await import(`node:path`),{state:n}=await e(t(`.`)),r=Object.keys(n.links).length;r>0&&i.info(`${r} package(s) linked in this project`)}catch{}return await i.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}const f=t({meta:{name:`knarr`,version:`0.3.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:!1},"dry-run":{type:`boolean`,description:`Preview changes without writing files`,default:!1},json:{type:`boolean`,description:`Output machine-readable JSON`,default:!1}},subCommands:{init:()=>import(`./init-BJZdXWmg.mjs`).then(e=>e.default),publish:()=>import(`./publish-DViw9ie6.mjs`).then(e=>e.default),add:()=>import(`./add-CZp5YVWF.mjs`).then(e=>e.default),use:()=>import(`./use-By-V869_.mjs`).then(e=>e.default),remove:()=>import(`./remove-Ch5tlQkh.mjs`).then(e=>e.default),push:()=>import(`./push-ChVt0ofE.mjs`).then(e=>e.default),dev:()=>import(`./dev-DtbwBD_E.mjs`).then(e=>e.default),restore:()=>import(`./restore-DaJjdT2B.mjs`).then(e=>e.default),list:()=>import(`./list-BekXJBqC.mjs`).then(e=>e.default),status:()=>import(`./status-BHe6UGa2.mjs`).then(e=>e.default),explain:()=>import(`./explain-U6-XLo4U.mjs`).then(e=>e.default),update:()=>import(`./update-BuQUMzU2.mjs`).then(e=>e.default),clean:()=>import(`./clean-B4S8pHpI.mjs`).then(e=>e.default),gc:()=>import(`./clean-B4S8pHpI.mjs`).then(e=>e.default),doctor:()=>import(`./doctor-Ca2eGyC8.mjs`).then(e=>e.default),migrate:()=>import(`./migrate-DGXYBPRz.mjs`).then(e=>e.default),reset:()=>import(`./reset-DD5BaA6m.mjs`).then(e=>e.default),rollback:()=>import(`./rollback-B7QjnKje.mjs`).then(e=>e.default),check:()=>import(`./check-BFgQ7Px_.mjs`).then(e=>e.default)}});e(f);export{};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./logger-Oo2Slehd.mjs";import{t}from"./fs-DusqxRQR.mjs";import{i as n,n as r,s as i}from"./json-
|
|
1
|
+
import{i as e}from"./logger-Oo2Slehd.mjs";import{t}from"./fs-DusqxRQR.mjs";import{i as n,n as r,s as i}from"./json-b5d4W58a.mjs";import{readFile as a}from"node:fs/promises";import{join as o}from"node:path";function s(e){return typeof e==`number`&&Number.isFinite(e)?e:void 0}async function c(t){try{let r=await a(o(t,`package.json`),`utf-8`),c=n(i(r,`package.json`),`knarr`);if(!c)return{};let l={};typeof c.buildCmd==`string`&&(l.buildCmd=c.buildCmd);let u=c.watchPatterns;Array.isArray(u)&&(l.watchPatterns=u.filter(e=>typeof e==`string`));let d=s(c.debounce);d!==void 0&&(l.debounce=d);let f=s(c.cooldown);f!==void 0&&(l.cooldown=f);let p=s(c.historyLimit);return p!==void 0&&(l.historyLimit=Math.max(0,Math.floor(p))),typeof c.notify==`boolean`&&(l.notify=c.notify),e(`[config] Loaded knarr config from package.json: ${JSON.stringify(l)}`),l}catch{return{}}}async function l(e,o){if(!o)return!1;let s=await a(e,`utf-8`),c=i(s,e),l=n(c,`knarr`);return l&&typeof l.buildCmd==`string`?!1:(c.knarr={...l,buildCmd:o},await t(e,JSON.stringify(c,null,r(s))+`
|
|
2
2
|
`),!0)}export{l as n,c as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t}from"./output-B7NC4xgj.mjs";import{a as n,i as r,o as i,s as a,t as o}from"./push-engine-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t}from"./output-B7NC4xgj.mjs";import{a as n,i as r,o as i,s as a,t as o}from"./push-engine-IoOaMeZe.mjs";import{t as s}from"./batch-push-CT5k2SrS.mjs";import{t as c}from"./config-DEpSKyI8.mjs";import{n as l}from"./logger-Oo2Slehd.mjs";import{r as u}from"./dry-run-DPoN8bZo.mjs";import{resolve as d}from"node:path";var f=e({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:!1},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:!1},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:!1},force:{type:`boolean`,alias:`f`,description:`Force copy all files, bypassing hash comparison`,default:!1},notify:{type:`boolean`,description:`Ring terminal bell on push completion`,default:!1},"no-cascade":{type:`boolean`,description:`Disable cascading rebuilds in --all mode`,default:!1}},async run({args:e}){t();let f=d(`.`),p=await c(f),m={runScripts:!e[`no-scripts`],force:e.force,historyLimit:p.historyLimit};if(e.all){let t=await n(f,e),r=/* @__PURE__ */ new Set([...t.failedPackages,...t.skippedPackages]);if(t.canPush&&await s(f,{...m,skipPackages:r}),l()){u();return}await i(f,e,m)}else{let t=()=>o(f,m);if(await r(f,e,p)&&await t(),l()){u();return}await a(f,e,t)}}});export{f as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,i,m as a,r as o,u as s}from"./tracker-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,i,m as a,r as o,u as s}from"./tracker-BUpkmn8j.mjs";import{n as c,r as l}from"./store-D2r3Vo5S.mjs";import{o as u}from"./injector-CwNZ9rDe.mjs";import{c as d,u as f}from"./fs-DusqxRQR.mjs";import{a as ee,f as p,i as m,r as te}from"./paths-V3_BeE_z.mjs";import{t as h}from"./package-manager-DENvuHqT.mjs";import{n as g}from"./bundler-detect-BaShXORS.mjs";import{a as ne,c as _,d as v,l as re,o as y,u as b}from"./init-helpers-DfznkCwv.mjs";import{n as x,t as S}from"./output-B7NC4xgj.mjs";import{n as C,r as w}from"./logger-Oo2Slehd.mjs";import{r as T}from"./dry-run-DPoN8bZo.mjs";import{c as E,i as D,l as O}from"./json-b5d4W58a.mjs";import{readFile as k,stat as A}from"node:fs/promises";import{basename as j,join as M,resolve as N}from"node:path";async function P(e,t={}){let n=[],f=C(),b=t.fix===!0,x=f?`Would `:``;async function S(e,t){let r={fixable:!1,fixed:!1,fixes:[],...e};if(b&&r.fixable&&t){let e=await t();e&&(r.fixed=!f,r.fixes.push(`${x}${e}`))}n.push(r)}let w=(await h(e)).resolve(),T=w.packageManager,k=!!w.nodeModulesCompatible,A="Yarn PnP has no node_modules tree for Knarr to manage. Set `nodeLinker: node-modules` or `nodeLinker: pnpm`, run `yarn install`, then re-run `knarr doctor --fix`.",N=p();await d(N)?await S({name:`Store directory`,status:`pass`,message:`${(await l()).length} entries in ${N}`}):await S({name:`Store directory`,status:`warn`,message:`Store not found at ${N}. Run 'knarr publish' to create it.`});let P=ee(),{registry:F,reliable:z}=await s();if(!z)await S({name:`Global registry`,status:`fail`,message:`${P} is corrupt or unreadable.`,unfixableReason:i()});else if(await d(P)){let e=Object.values(F).flat().length;await S({name:`Global registry`,status:`pass`,message:`${Object.keys(F).length} packages, ${e} consumer registrations`})}else await S({name:`Global registry`,status:`warn`,message:`No consumers registered yet. Use 'knarr add' to link packages.`});let V=await ie(F),H=V.missingDirectories+V.missingLinks;H>0&&await S({name:`Stale registry entries`,status:`warn`,message:`${H} stale consumer registration(s) found`+(V.unreadableConsumers>0?`; ${V.unreadableConsumers} unreadable state file(s) skipped`:``),fixable:!0},async()=>`remove ${(await o({removeMissingLinks:!0})).removedConsumers} stale consumer registration(s)`);let U=m(e),W=te(e),G=await L(W),K=await d(U),{state:q,reliable:J}=await r(e);if(G===`file`)await S({name:`Consumer state`,status:`fail`,message:`${W} exists but is not a directory.`,unfixableReason:`Move or delete ${W}, then run 'knarr init'.`}),J=!1;else if(K)J||await S({name:`Consumer state`,status:`fail`,message:`state.json is corrupt or unreadable. Delete .knarr/state.json and re-run 'knarr add' for each package.`,unfixableReason:`Corrupt state may contain links Knarr cannot safely reconstruct.`});else{let t={name:`Consumer state`,status:`warn`,message:`No .knarr/state.json found.`,fixable:k,fixed:!1,fixes:[],...k?{}:{unfixableReason:A}};b&&t.fixable&&(await a(e,e=>{e.packageManager=T,e.role=`consumer`}),t.fixed=!f,t.fixes.push(`${x}create .knarr/state.json`),K=await d(U),{state:q,reliable:J}=await r(e)),n.push(t)}let Y=J?Object.entries(q.links):[];J&&K&&(Y.length>0?await S({name:`Consumer state`,status:`pass`,message:`${Y.length} linked package(s)`}):await S({name:`Consumer state`,status:`warn`,message:`No packages linked. Use 'knarr add' to link a package.`}));for(let[t,n]of Y){let r=await c(t,n.version);r?r.meta.contentHash===n.contentHash?await S({name:`Store: ${t}`,status:`pass`,message:`${t}@${n.version} in sync`}):await S({name:`Store: ${t}`,status:`warn`,message:`Store has newer content. Run 'knarr update' to sync.`}):await S({name:`Store: ${t}`,status:`fail`,message:`Store entry missing for ${t}@${n.version}. Re-publish it.`});let i;try{i=await u(e,t,n.packageManager,n.version,{warnOnFallback:!1})}catch(e){await S({name:`node_modules: ${t}`,status:`fail`,message:`Cannot resolve package target. ${e instanceof Error?e.message:String(e)}`});continue}if(!await d(i))await S({name:`node_modules: ${t}`,status:`fail`,message:`Missing from node_modules. Run 'knarr restore'.`});else try{let e=await E(M(i,`package.json`)),r=O(e,`name`),a=O(e,`version`);r&&r!==t?await S({name:`node_modules: ${t}`,status:`fail`,message:`node_modules target contains package "${r}". Run your package manager install, then 'knarr restore'.`}):a&&a!==n.version?await S({name:`node_modules: ${t}`,status:`warn`,message:`node_modules has v${a} but Knarr linked v${n.version}. Run 'knarr restore'.`}):await S({name:`node_modules: ${t}`,status:`pass`,message:`present`})}catch{await S({name:`node_modules: ${t}`,status:`pass`,message:`present`})}}await S({name:`Package manager`,status:`pass`,message:T}),w.yarnLinkerDiagnostic&&await S({name:`Yarn linker`,...w.yarnLinkerDiagnostic});let X=await g(e);if(X.type?await S({name:`Bundler`,status:`pass`,message:`${X.type}${X.configFile?` (${X.configFile})`:``}`}):await S({name:`Bundler`,status:`warn`,message:`No bundler config detected`}),X.type===`vite`&&X.configFile){let{addKnarrVitePlugin:e,hasKnarrVitePlugin:t}=await import(`./vite-config-DQfi8QwQ.mjs`),r=await t(X.configFile);if(r.error)await S({name:`Vite integration`,status:`warn`,message:r.error});else if(r.configured)await S({name:`Vite integration`,status:`pass`,message:`Knarr plugin configured`});else{let t={name:`Vite integration`,status:`warn`,message:`Knarr Vite plugin is missing.`,fixable:k,fixed:!1,fixes:[],...k?{}:{unfixableReason:A}};if(b&&t.fixable){let n=await e(X.configFile);n.modified?(t.fixed=!f,t.fixes.push(`${x}add Knarr Vite plugin to ${j(X.configFile)}`)):n.error&&(t.unfixableReason=n.error)}n.push(t)}}if(X.type===`next`&&X.configFile){let{addToTranspilePackages:e,hasTranspilePackage:t}=await import(`./nextjs-config-C2Xv-pZR.mjs`);for(let[r]of Y){let i=await t(X.configFile,r);if(i.configured){await S({name:`Next.js integration: ${r}`,status:`pass`,message:`transpilePackages configured`});continue}let a={name:`Next.js integration: ${r}`,status:`warn`,message:`${r} is missing from transpilePackages.`,fixable:!i.error&&k,fixed:!1,fixes:[],...i.error?{unfixableReason:i.error}:k?{}:{unfixableReason:A}};if(b&&a.fixable){let t=await e(X.configFile,r);t.modified?(a.fixed=!f,a.fixes.push(`${x}add ${r} to transpilePackages in ${j(X.configFile)}`)):t.error&&(a.unfixableReason=t.error)}n.push(a)}}let Z=M(e,`.gitignore`);await I(Z)?await S({name:`.gitignore`,status:`pass`,message:`.knarr/ is ignored`}):await S({name:`.gitignore`,status:`warn`,message:`.knarr/ not in .gitignore.`,fixable:k,...k?{}:{unfixableReason:A}},async()=>await ne(Z)?`add .knarr/ to .gitignore`:null);let Q=M(e,`package.json`);if(await d(Q)){let t=await B(Q),n=t?D(t,`scripts`)?.postinstall:void 0;typeof n==`string`&&re(n)?await d(M(e,`.knarr`,`restore.cjs`))?await S({name:`Postinstall restore`,status:`pass`,message:`postinstall re-applies links via .knarr/restore.cjs`}):await S({name:`Postinstall restore`,status:`warn`,message:`.knarr/restore.cjs is missing, so installs won't re-apply links.`,fixable:k,...k?{}:{unfixableReason:A}},async()=>(await v(e),`write .knarr/restore.cjs`)):typeof n==`string`&&_(n)?await R(e,t,n)?await S({name:`Postinstall restore`,status:`pass`,message:`postinstall runs knarr restore`}):n.includes(`knarr restore --silent || node -e "process.exit(0)"`)?await S({name:`Postinstall restore`,status:`warn`,message:`postinstall runs knarr restore, but no local knarr dependency or binary was found, so installs silently drop links.`,fixable:k,...k?{}:{unfixableReason:A}},async()=>(await y(e),`upgrade postinstall restore hook (works without a global knarr)`)):await S({name:`Postinstall restore`,status:`warn`,message:`postinstall runs knarr restore, but no local knarr dependency or binary was found.`,unfixableReason:`Install knarr as a devDependency for reliable auto-restore, or ensure a global knarr binary is available during installs.`}):typeof n==`string`?await S({name:`Postinstall restore`,status:`warn`,message:`postinstall exists but does not run knarr restore.`,unfixableReason:`Existing postinstall scripts are not merged automatically.`}):await S({name:`Postinstall restore`,status:`warn`,message:`postinstall restore hook is missing.`,fixable:k,...k?{}:{unfixableReason:A}},async()=>(await y(e),`add postinstall restore hook to package.json`))}else await S({name:`Postinstall restore`,status:`warn`,message:`No package.json found.`});let[$=0,ae=0]=process.versions.node.split(`.`).map(e=>parseInt(e,10));return $>22||$===22&&ae>=22?await S({name:`Node.js version`,status:`pass`,message:`v${process.versions.node}`}):await S({name:`Node.js version`,status:`fail`,message:`v${process.versions.node}; Knarr requires Node.js >= 22.22`}),{results:n,failures:n.filter(e=>e.status===`fail`).length,warnings:n.filter(e=>e.status===`warn`).length,fixed:n.filter(e=>e.fixed).length,plannedFixes:f?n.reduce((e,t)=>e+t.fixes.length,0):0,dryRun:f}}var F=e({meta:{name:`doctor`,description:`Run diagnostic checks on your Knarr setup`},args:{fix:{type:`boolean`,description:`Apply safe automatic repairs`,default:!1}},async run({args:e}){x();let r=N(`.`);n.info(e.fix?`Running Knarr diagnostics with safe fixes...
|
|
2
2
|
`:`Running Knarr diagnostics...
|
|
3
3
|
`);let i=await P(r,{fix:e.fix}),a={pass:t.green(`PASS`),fail:t.red(`FAIL`),warn:t.yellow(`WARN`)};for(let e of i.results){n.log(` ${a[e.status]} ${e.name}: ${t.dim(e.message)}`);for(let r of e.fixes)n.log(` ${t.cyan(C()?`PLAN`:`FIX`)} ${t.dim(r)}`);e.unfixableReason&&n.log(` ${t.yellow(`!`)} ${t.dim(e.unfixableReason)}`)}n.log(``),i.plannedFixes>0?n.info(`${i.plannedFixes} fix(es) would be applied`):i.fixed>0&&n.success(`Applied ${i.fixed} fix(es)`),i.failures>0?n.error(`${i.failures} issue(s) found that need attention`):i.warnings>0?n.warn(`${i.warnings} warning(s), but no critical issues`):n.success(`All checks passed!`),S(i),e.fix&&C()&&!w()&&T()}});async function ie(e){let t=0,n=0,i=0;for(let[a,o]of Object.entries(e))for(let e of o){if(!await d(e)){t++;continue}let{state:o,reliable:s}=await r(e);s?o.links[a]||n++:i++}return{missingDirectories:t,missingLinks:n,unreadableConsumers:i}}async function I(e){try{return(await k(e,`utf-8`)).split(`
|
|
4
4
|
`).some(e=>{let t=e.trim();return t===`.knarr/`||t===`.knarr`||t===`/.knarr/`||t===`/.knarr`})}catch{return!1}}async function L(e){try{return(await A(e)).isDirectory()?`dir`:`file`}catch(e){return f(e)&&e.code===`ENOENT`?`missing`:`file`}}async function R(e,t,n){return b(n)||z(t)?!0:await d(M(e,`node_modules`,`.bin`,`knarr`))||await d(M(e,`node_modules`,`.bin`,`knarr.cmd`))}function z(e){return e?[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`].some(t=>D(e,t)?.knarr!==void 0):!1}async function B(e){try{return await E(e)}catch{return null}}export{F as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{n as r,t as i}from"./store-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{n as r,t as i}from"./store-D2r3Vo5S.mjs";import{o as a}from"./injector-CwNZ9rDe.mjs";import{c as o,l as s}from"./tracker-BUpkmn8j.mjs";import{t as c}from"./package-manager-DENvuHqT.mjs";import{c as l}from"./fs-DusqxRQR.mjs";import{n as u,p as d,s as f}from"./paths-V3_BeE_z.mjs";import{n as p,t as m}from"./output-B7NC4xgj.mjs";import{c as h,l as g}from"./json-b5d4W58a.mjs";import{join as _,resolve as v}from"node:path";async function y(e,t){let{state:n,reliable:r}=await o(e),i=(await c(e)).resolve().packageManager;if(!r)return{consumerPath:e,stateReliable:!1,packages:t?[await x(e,t,null,i,!1)]:[]};let a=t?[[t,n.links[t]??null]]:Object.entries(n.links);return{consumerPath:e,stateReliable:!0,packages:await Promise.all(a.map(([t,n])=>x(e,t,n,i,!0)))}}var b=e({meta:{name:`explain`,description:`Explain linked package state and suggested recovery actions`},args:{package:{type:`positional`,description:`Package name to explain (default: all linked packages)`,required:!1}},async run({args:e}){p();let r=await y(v(`.`),e.package);if(!r.stateReliable)n.error(`Consumer state is corrupt or unreadable`),n.info(`Delete .knarr/state.json and re-run 'knarr add' for each package.`);else if(!r.packages[0])n.info(`No linked packages in this project`);else if(e.package)S(r.packages[0]);else{n.info(`Linked packages (${r.packages.length}):\n`);for(let e of r.packages){let r=e.status===`ok`?t.green(`OK`):e.status===`warn`?t.yellow(`!`):t.red(`FAIL`),i=e.version?t.dim(`@${e.version}`):t.dim(`(not linked)`),a=e.buildId?t.dim(` [${e.buildId}]`):``;n.log(` ${r} ${t.cyan(e.name)} ${i}${a}`),n.log(` ${t.dim(e.summary)}`)}n.log(``),n.info(`Run ${t.cyan(`knarr explain <package>`)} for details.`)}m(r)}});async function x(e,t,n,c,p){let m=n?await r(t,n.version):await i(t),h=(await s())[t]??[],g=d(e),_=[];p||_.push(`consumer state is corrupt or unreadable`),n||_.push(`package is not linked in this project`);let v=n?.sourcePath??m?.meta.sourcePath??null,y=v?await l(v):null;v&&y===!1&&_.push(`source directory missing: ${v}`),m?n&&m.meta.contentHash!==n.contentHash&&_.push(`store has newer content than the current link`):_.push(n?`store entry missing for ${t}@${n.version}`:`package not found in store`);let b=f(e,t),x=n?await a(e,t,n.packageManager,n.version,{warnOnFallback:!1}):b,S=await l(x),E=S?await T(x):null;n&&!S?_.push(`package is missing from node_modules`):n&&E&&E!==n.version&&_.push(`node_modules has v${E} but link expects v${n.version}`);let D=n?u(e,t):null,O=D?await l(D):!1;n?.backupExists&&!O&&_.push(`backup is recorded but missing on disk`);let k=await Promise.all(h.map(async e=>{if(!await l(e))return{path:e,exists:!1,stateReliable:null,hasLink:null};let{state:n,reliable:r}=await o(e);return{path:e,exists:!0,stateReliable:r,hasLink:r?!!n.links[t]:null}}));return n&&!h.includes(g)&&_.push(`current project is not registered for pushes`),{name:t,status:_.some(e=>e.includes(`corrupt`)||e.includes(`missing from node_modules`)||e.includes(`store entry missing`)||e.includes(`not linked`))?`fail`:_.length>0?`warn`:`ok`,summary:C(t,n,_),suggestedAction:w(t,n,_,v),linked:!!n,version:n?.version??m?.version??null,buildId:n?.buildId||m?.meta.buildId||null,sourcePath:v,sourceExists:y,packageManager:n?.packageManager??c,store:{exists:!!m,path:m?.packageDir??null,contentHash:m?.meta.contentHash??null,matchesLink:n&&m?m.meta.contentHash===n.contentHash:null,publishedAt:m?.meta.publishedAt??null},nodeModules:{path:b,targetPath:x,exists:S,packageVersion:E},backup:{expected:n?.backupExists??!1,exists:O,path:D},consumers:k,issues:_}}function S(e){let r=e.status===`ok`?t.green(`OK`):e.status===`warn`?t.yellow(`WARN`):t.red(`FAIL`);if(n.info(`${r} ${t.cyan(e.name)} ${t.dim(e.summary)}\n`),n.log(` Version: ${e.version??`(not linked)`}`),n.log(` Build ID: ${e.buildId??`(none)`}`),n.log(` Package manager: ${e.packageManager}`),n.log(` Source: ${e.sourcePath??`(unknown)`}${e.sourceExists===!1?` (missing)`:``}`),n.log(` Store: ${e.store.exists?e.store.path:`(missing)`}`),e.store.matchesLink!==null&&n.log(` Content hash: ${e.store.matchesLink?`matches link`:`differs from link`}`),n.log(` node_modules: ${e.nodeModules.targetPath}${e.nodeModules.exists?``:` (missing)`}`),n.log(` Backup: ${e.backup.expected?e.backup.exists?`present`:`missing`:`not recorded`}`),n.log(` Registered consumers: ${e.consumers.length}`),e.issues.length>0){n.log(``);for(let r of e.issues)n.log(` ${t.yellow(`!`)} ${r}`)}n.log(``),n.info(`Suggested action: ${e.suggestedAction}`)}function C(e,t,n){return t?n.length===0?`link, store, and node_modules are in sync`:n[0]??`link, store, and node_modules are in sync`:`${e} is not linked in this project`}function w(e,t,n,r){return n.some(e=>e.includes(`corrupt`))?`Delete .knarr/state.json and re-run 'knarr add' for each package.`:t?n.some(e=>e.includes(`store entry missing`))?r?`Run 'knarr publish' in ${r}, then 'knarr restore'.`:`Re-publish the package, then run 'knarr restore'.`:n.some(e=>e.includes(`newer content`))?`Run 'knarr update ${e}'.`:n.some(e=>e.includes(`node_modules`))?`Run 'knarr restore'.`:n.some(e=>e.includes(`not registered`))?`Run 'knarr add ${e}' again to refresh registration.`:n.some(e=>e.includes(`source directory`))?`Check the source path or re-run 'knarr use <path>'.`:`No action needed.`:`Run 'knarr add ${e}' or 'knarr use <path>'.`}async function T(e){try{let t=await h(_(e,`package.json`));return g(t,`version`)??null}catch{return null}}export{b as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,d as t,f as n,o as r,t as i}from"./fs-DusqxRQR.mjs";import{c as a,l as o,o as s}from"./paths-V3_BeE_z.mjs";import{i as c}from"./logger-Oo2Slehd.mjs";import{o as l}from"./json-b5d4W58a.mjs";import{t as u}from"./validators-C0_prNkT.mjs";import{readFile as d,readdir as f}from"node:fs/promises";import{join as p}from"node:path";async function m(e){let t=l(await d(e,`utf-8`));if(!u(t))throw Error(`Invalid build metadata: ${e}`);return t}async function h(a,l,u,d){let f=p(u,`.knarr-meta.json`),h;try{h=await m(f)}catch{c(`[history] Could not read meta from ${f}, skipping history capture`);return}let g=h.buildId;if(!g){c(`[history] No buildId in meta, skipping history capture`);return}let _=o(a,l),v=s(a,l,g);if(await e(v)){c(`[history] Build ${g} already in history, skipping`);return}await r(_);let b=v+`.tmp-${process.pid}`;try{await r(b);let n=p(u,`package`);await e(n)&&await t(n,p(b,`package`)),await i(p(b,`.knarr-meta.json`),JSON.stringify(h,null,2)),await t(b,v),c(`[history] Captured build ${g} to history`)}catch(e){c(`[history] Failed to capture history: ${e instanceof Error?e.message:String(e)}`),await n(b)}await y(a,l,d??3)}async function g(t,n){let r=o(t,n);if(!await e(r))return[];let i;try{i=await f(r)}catch{return[]}let a=[];for(let e of i){let t=p(r,e),n=p(t,`.knarr-meta.json`);try{let r=await m(n);a.push({buildId:r.buildId??e,contentHash:r.contentHash,publishedAt:r.publishedAt,sourcePath:r.sourcePath,packageDir:p(t,`package`)})}catch{}}return a.sort((e,t)=>new Date(t.publishedAt).getTime()-new Date(e.publishedAt).getTime()),a}async function _(e,t,n){let r=s(e,t,n),i=p(r,`.knarr-meta.json`);try{let e=await m(i);return{buildId:e.buildId??n,contentHash:e.contentHash,publishedAt:e.publishedAt,sourcePath:e.sourcePath,packageDir:p(r,`package`)}}catch{return null}}async function v(o,l,u,f){let m=await _(o,l,u);if(!m)return null;let g=a(o,l),v=s(o,l,u),y=p(v,`package`),b=p(v,`.knarr-meta.json`),x=await d(b,`utf-8`),S=p(g,`package`),C=p(g,`.knarr-meta.json`);if(!await e(y))throw Error(`History entry ${u} is missing its package directory`);let w=await d(C,`utf-8`).catch(()=>null),T=g+`.restore-old-${process.pid}-${Date.now()}`,E=p(T,`package`),D=!1,O=!1;try{if((await e(S)||w)&&(await r(T),await e(S)&&await t(S,E),w&&await i(p(T,`.knarr-meta.json`),w),D=!0),await t(y,S),O=!0,await i(C,x),await n(v),D)try{await h(o,l,T,f)}finally{await n(T)}}catch(a){throw O&&await e(S)?(await r(v),await t(S,y)):D&&await e(S)&&await n(S),D&&await e(E)&&await t(E,S),w&&await i(C,w),await n(T),a}return c(`[history] Restored build ${u} as current`),m}async function y(e,t,r){if(r<0)return 0;let i=await g(e,t);if(i.length<=r)return 0;let a=i.slice(r),o=0;for(let r of a){let i=s(e,t,r.buildId);try{await n(i),o++,c(`[history] Pruned old build ${r.buildId}`)}catch{}}return o}async function b(t,r){let i=o(t,r);await e(i)&&await n(i)}function x(e){return e??3}export{y as a,g as i,b as n,x as o,_ as r,v as s,h as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as captureHistory}from"./history-BNX-3W-p.mjs";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./publisher-
|
|
1
|
+
import{t as e}from"./publisher-PQIqCt7r.mjs";import{a as t,n,r,s as i,t as a}from"./injector-CwNZ9rDe.mjs";import{n as o,r as s,t as c}from"./store-D2r3Vo5S.mjs";import{a as l,c as u,d,f,n as p,o as m,p as h,r as g,s as _}from"./tracker-BUpkmn8j.mjs";import{t as v}from"./push-engine-IoOaMeZe.mjs";import{t as y}from"./batch-push-CT5k2SrS.mjs";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"./history-BNX-3W-p.mjs";import{a as D,i as O,n as k,t as A}from"./watcher-DN6vT6nw.mjs";import{t as j}from"./watch-orchestrator-B1hlJ10Y.mjs";import{n as M,r as N}from"./package-manager-DENvuHqT.mjs";import{t as P}from"./config-DEpSKyI8.mjs";import{n as F,t as I}from"./topo-sort-I086ZoiN.mjs";import{n as L,t as R}from"./workspace-BBfh7dJY.mjs";import{t as z}from"./preflight-DPlVrYLp.mjs";import{t as B}from"./timer-BZNWRS3O.mjs";import{u as V}from"./fs-DusqxRQR.mjs";import{p as H}from"./paths-V3_BeE_z.mjs";import{a as U,i as W,r as G}from"./dry-run-DPoN8bZo.mjs";import{r as K}from"./vite-config-Bvv75_oH.mjs";export{I as CycleError,B as Timer,j as WatchOrchestrator,p as addLink,a as backupExisting,R as buildReverseAdjacency,L as buildWorkspaceGraph,E as captureHistory,n as checkMissingDeps,g as cleanStaleConsumers,S as clearHistory,M as detectPackageManager,N as detectPackageManagerInfo,v as doPush,y as doPushAll,c as findStoreEntry,l as getConsumers,w as getHistoryEntry,m as getLink,o as getStoreEntry,r as inject,K as isComplexConfig,V as isNodeError,A as killActiveBuild,x as listHistory,s as listStoreEntries,P as loadKnarrConfig,H as normalizePath,G as printDryRunReport,b as pruneHistory,e as publish,_ as readConsumerState,u as readConsumerStateSafe,W as recordMutation,d as registerConsumer,t as removeInjected,f as removeLink,U as resetMutations,C as resolveHistoryLimit,i as restoreBackup,T as restoreHistoryEntry,D as ringBell,k as runBuildCommand,z as runPreflightChecks,O as startWatcher,F as topoSort,h as unregisterConsumer};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,t as i}from"./fs-DusqxRQR.mjs";import{t as a}from"./package-manager-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,t as i}from"./fs-DusqxRQR.mjs";import{t as a}from"./package-manager-DENvuHqT.mjs";import{n as o}from"./bundler-detect-BaShXORS.mjs";import{t as s}from"./build-detect-Bf2HAfXm.mjs";import{a as c,d as l,r as u}from"./init-helpers-DfznkCwv.mjs";import{t as d}from"./timer-BZNWRS3O.mjs";import{n as f,t as p}from"./output-B7NC4xgj.mjs";import{n as m}from"./logger-Oo2Slehd.mjs";import{r as h}from"./dry-run-DPoN8bZo.mjs";import{n as g}from"./config-DEpSKyI8.mjs";import{m as _}from"./tracker-BUpkmn8j.mjs";import{n as v}from"./hints-BKo_2axg.mjs";import{i as y,n as b,s as x}from"./json-b5d4W58a.mjs";import{readFile as S}from"node:fs/promises";import{basename as C,join as w,resolve as T}from"node:path";var E=e({meta:{name:`init`,description:`Set up knarr in the current project`},args:{yes:{type:`boolean`,alias:`y`,description:`Skip confirmation prompts`,default:!1},role:{type:`string`,description:`Project role: "consumer" or "library"`}},async run({args:e}){f();let i=new d,s=T(`.`),y=e.yes,b=!1,x=[];n.info(`Initializing knarr in ${t.cyan(s)}\n`);let S=await a(s),E=S.resolve().packageManager;n.success(`Detected package manager: ${t.cyan(E)}`);let A=E;if(!y&&await n.prompt(`Use ${E}?`,{type:`confirm`,initial:!0})===!1){let e=[`npm`,`pnpm`,`yarn`,`bun`].filter(e=>e!==E),t=await n.prompt(`Select package manager:`,{type:`select`,options:e.map(e=>({label:e,value:e}))});typeof t==`string`&&(A=t)}let j=`consumer`;e.role===`consumer`||e.role===`library`?j=e.role:y||await n.prompt(`How will you use knarr in this project?`,{type:`select`,nonInteractiveHint:`Pass --role consumer or --role library (or --yes for consumer).`,options:[{label:`Consumer (app) - I want to link packages INTO this project`,value:`consumer`},{label:`Library (package) - I want to publish this package FOR other projects`,value:`library`}]})===`library`&&(j=`library`),n.success(`Project role: ${t.cyan(j)}`);let M=(A===E?S:await a(s,{packageManager:A})).resolve();j===`consumer`&&!M.nodeModulesCompatible&&(n.error(M.incompatibilityReason),process.exit(1));let N=w(s,`.gitignore`);await c(N)&&n.success(`Added .knarr/ to .gitignore`);let P=w(s,`package.json`),F;if(await r(P)){if(j===`consumer`){if(await l(s),await u(P)&&n.success(`Added a postinstall hook so installs re-apply linked packages (a no-op for teammates without Knarr)`),!y){let e=await n.prompt(`Package name to link (leave blank to skip):`,{type:`text`,default:``});if(typeof e==`string`&&e.trim()){let t=e.trim();await D(P,`knarr:add`,`knarr add ${t}`)&&n.success(`Added "knarr:add": "knarr add ${t}" to package.json scripts`)}}}else{F=await O(P,A,y),b=await g(P,F),b&&F&&n.success(`Saved build command to package.json#knarr.buildCmd`);let e=await k(P);for(let t of e)n.success(`Added "${t}" script to package.json`)}}let I=!await r(w(s,`.knarr`));if(await _(s,e=>{e.packageManager=A,e.role=j}),I&&n.success(`Created .knarr/ state directory`),j===`consumer`){let e=await o(s);if(e.type===`vite`&&e.configFile){n.success(`Detected bundler: ${t.cyan(`Vite`)} (${C(e.configFile)})`);let{addKnarrVitePlugin:r}=await import(`./vite-config-DQfi8QwQ.mjs`),i=await r(e.configFile);if(i.modified){n.success(`Added knarr plugin to ${C(e.configFile)}`);let t=M.installCommand([`knarr`],{dev:!0}),r=M.formatCommand(t);n.info(m()?`[dry-run] Would install knarr as devDependency`:`Installing knarr as devDependency...`);let i=await M.run(t);i&&!m()?n.success(`Installed knarr`):i||n.warn(`Install failed. Run manually: ${r}`)}else i.error&&n.info(`Add the Vite plugin for automatic dev server restarts:\n ${t.cyan(`import knarr from "knarr/vite"`)}\n ${t.cyan(`plugins: [knarr()]`)}`)}else e.type===`next`&&e.configFile?(n.success(`Detected bundler: ${t.cyan(`Next.js`)} (${C(e.configFile)})`),n.info(`Next.js transpilePackages will be auto-configured when you run ${t.cyan(`knarr add`)}`)):e.type&&n.success(`Detected bundler: ${t.cyan({webpack:`Webpack`,turbo:`Turbopack`,rollup:`Rollup`}[e.type]||e.type)} - no config needed, works out of the box`);n.log(``),n.info(`${t.bold(`Next steps:`)}`);let r=`${v()} use ../my-lib`,i=`cd ../my-lib && ${v()} dev`;x.push(r,i);let a=Math.max(r.length,i.length)+2;n.log(` 1. ${t.cyan(r.padEnd(a))}<- publish + link a local package`),n.log(` 2. ${t.cyan(i.padEnd(a))}<- watch + rebuild + auto-push`)}else{n.log(``),n.info(`${t.bold(`Next steps:`)}`);let e=`${A} run knarr:publish`,r=`${A} run knarr:dev`,i=`${v()} use ${s}`;x.push(e,r,i);let a=Math.max(e.length,r.length)+2;n.log(` 1. ${t.cyan(e.padEnd(a))}<- copy built files to knarr store`),n.log(` 2. ${t.cyan(r.padEnd(a))}<- watch + rebuild + auto-push to consumers`),n.log(` 3. In consumer project: ${t.cyan(i)}`)}n.info(`Done in ${i.elapsed()}`),p({packageManager:A,role:j,buildCmd:F??null,configUpdated:b,nextSteps:x,elapsed:i.elapsedMs()}),m()&&h()}});async function D(e,t,n){let r=await S(e,`utf-8`),a=x(r,e),o=y(a,`scripts`)??{};return!o[t]&&(o[t]=n,a.scripts=o,await i(e,JSON.stringify(a,null,b(r))+`
|
|
2
2
|
`),!0)}async function O(e,r,i){let a=w(e,`..`),o=await s(a,r);if(o)return n.success(`Detected build script: ${t.cyan(o)}`),o;if(!i){n.warn(`No build script found in package.json`);let e=await n.prompt(`Build command (e.g. tsc, tsup, rollup -c):`,{type:`text`,default:``});if(typeof e==`string`&&e.trim())return e.trim()}n.warn(`No build command saved - add a "build" script to package.json or configure package.json#knarr.buildCmd`)}async function k(e){let t=[],n=x(await S(e,`utf-8`),e),r=y(n,`dependencies`)?.knarr||y(n,`devDependencies`)?.knarr?`knarr`:`npx --yes knarr`;return await D(e,`knarr:publish`,`${r} publish`)&&t.push(`knarr:publish`),await D(e,`knarr:dev`,`${r} dev`)&&t.push(`knarr:dev`),t}export{E as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e,t}from"./console-C8XtlRyM.mjs";import{c as n,o as r,t as i}from"./fs-DusqxRQR.mjs";import{i as a,n as o,s}from"./json-
|
|
1
|
+
import{n as e,t}from"./console-C8XtlRyM.mjs";import{c as n,o as r,t as i}from"./fs-DusqxRQR.mjs";import{i as a,n as o,s}from"./json-b5d4W58a.mjs";import{r as c}from"./paths-V3_BeE_z.mjs";import{m as l}from"./tracker-BUpkmn8j.mjs";import{readFile as u}from"node:fs/promises";import{dirname as d,join as f}from"node:path";import{existsSync as p}from"node:fs";import{fileURLToPath as m}from"node:url";const h=`node -e "try{require('./.knarr/restore.cjs')}catch(e){if(e.code!=='MODULE_NOT_FOUND')throw e}"`,g=`knarr restore --silent || node -e "process.exit(0)"`,_=`restore.cjs`;function v(e){return e.includes(`.knarr/${_}`)}function y(){let e=f(d(m(import.meta.url)),`cli.mjs`);return p(e)?e:null}function b(e){return[`// Generated by Knarr. Re-applies Knarr-linked packages after an install.`,`// Local only (.knarr/ is gitignored). knarr add, use, and restore rewrite it.`,`"use strict";`,`const { spawnSync } = require("node:child_process");`,`const { existsSync } = require("node:fs");`,``,`const cli = ${JSON.stringify(e)};`,`const args = ["restore", "--silent"];`,`const result = cli && existsSync(cli)`,` ? spawnSync(process.execPath, [cli, ...args], { stdio: "inherit" })`,` : spawnSync("knarr " + args.join(" "), { stdio: ["inherit", "inherit", "pipe"], shell: true });`,``,`if (result.error || result.status !== 0) {`,` console.warn("[knarr] Linked packages were NOT restored after this install. Run: npx knarr restore");`,`}`,``].join(`
|
|
2
2
|
`)}async function x(e){let t=c(e);await r(t),await i(f(t,_),b(y()))}function S(e){return/\b(?:npx(?:\s+--yes|\s+-y)?|pnpm\s+dlx|yarn\s+dlx|bunx)\s+knarr\s+restore(?:\s|$)/.test(e)}function C(e){return v(e)?!0:/(?:^|[;&|()\s])(?:(?:npx(?:\s+(?:--yes|-y))?|pnpm\s+dlx|yarn\s+dlx|bunx)\s+)?knarr\s+restore(?:\s|$)/.test(e)}function w(e){let t=e.trim();return t===`node -e "try{require('./.knarr/restore.cjs')}catch(e){if(e.code!=='MODULE_NOT_FOUND')throw e}"`||t===`knarr restore --silent || node -e "process.exit(0)"`||t===`knarr restore --silent`||S(t)}async function T(e){let t=``;try{t=await u(e,`utf-8`)}catch{}if(t.split(`
|
|
3
3
|
`).some(e=>e.trim()===`.knarr/`||e.trim()===`.knarr`||e.trim()===`/.knarr/`||e.trim()===`/.knarr`))return!1;let n=t.length>0&&!t.endsWith(`
|
|
4
4
|
`)?`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{n as t,p as n,s as r}from"./paths-V3_BeE_z.mjs";import{c as i,f as a,l as o,o as s,r as c,u as l}from"./fs-DusqxRQR.mjs";import{i as u,n as d}from"./logger-Oo2Slehd.mjs";import{i as f}from"./dry-run-DPoN8bZo.mjs";import{t as p}from"./package-manager-DENvuHqT.mjs";import{t as m}from"./bundler-detect-BaShXORS.mjs";import{i as h,l as g,s as _,t as ee}from"./json-b5d4W58a.mjs";import{platform as v}from"node:os";import{chmod as y,lstat as b,mkdir as te,readFile as x,readdir as S,readlink as ne,realpath as C,rm as w,symlink as T,writeFile as E}from"node:fs/promises";import{dirname as D,isAbsolute as O,join as k,relative as A,resolve as j,sep as M}from"node:path";const re=/[\x00-\x1F\x7F]/,ie=/^[A-Za-z0-9._+-]+$/;function N(e){return e&&ie.test(e)?e:`node`}function ae(e){let t=e.split(/\r?\n/,1)[0]?.trim();if(!t?.startsWith(`#!`))return`node`;let n=t.slice(2).trim().split(/\s+/).filter(Boolean),[r]=n;if(r===void 0)return`node`;let i=r.replace(/\\/g,`/`).split(`/`).pop();if(i===`env`){let e=n.slice(1);return N(e[0]===`-S`?e[1]:e[0])}return N(i)}async function oe(e){try{return ae(await x(e,`utf-8`))}catch{return`node`}}function P(e,t,n=``){if(!t||t===`.`||t===`..`||re.test(t)||t.includes(`/`)||t.includes(`\\`)||t.includes(`:`))return null;let r=k(e,`${t}${n}`),i=j(e),a=j(r);return a!==i&&a.startsWith(i+M)?r:null}function F(e){return e.bin?typeof e.bin==`string`?{[e.name.startsWith(`@`)&&e.name.split(`/`)[1]||e.name]:e.bin}:e.bin:{}}async function I(t,r,i){let a=F(i);if(Object.keys(a).length===0)return 0;let o=k(t,`node_modules`,`.bin`),s=Object.entries(a).map(([e,t])=>({binName:e,binPath:t,linkPath:P(o,e),cmdPath:P(o,e,`.cmd`),ps1Path:P(o,e,`.ps1`)})).filter(t=>!t.linkPath||!t.cmdPath||!t.ps1Path?(e.warn(`bin name "${t.binName}" is not safe, skipping`),!1):!0),c=k(t,`node_modules`,r),p=j(c),m=s.filter(({binName:t,binPath:n})=>{let r=j(k(c,n));return r.startsWith(p+M)||r===p?!0:(e.warn(`bin "${t}" points outside package directory, skipping`),!1)});if(m.length===0)return 0;if(d()){for(let{linkPath:e}of m)f({type:`bin-link`,path:e,detail:r});return u(`[dry-run] would create ${m.length} bin link(s) for ${r}`),m.length}await te(o,{recursive:!0});let h=v()===`win32`,g=0;for(let{binName:e,binPath:t,linkPath:r,cmdPath:i,ps1Path:a}of m){let s=k(c,t),d=n(A(o,s)),f=await oe(s);if(h){let e=`@ECHO off\r\nGOTO start\r\n:find_dp0\r\nSET dp0=%~dp0\r\nEXIT /b\r\n:start\r\nCALL :find_dp0\r\n${f} "%dp0%\\${d.replace(/\//g,`\\`)}" %*\r\n`;await E(i,e);let t=`#!/usr/bin/env pwsh\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n& ${f} "$basedir/${d}" $args\nexit $LASTEXITCODE\n`;await E(a,t);let n=`#!/bin/sh\nbasedir=$(dirname "$0")\nexec ${f} "$basedir/${d}" "$@"\n`;await E(r,n)}else{try{await w(r,{force:!0})}catch{}try{await T(d,r),await y(s,493)}catch(t){if(l(t)&&(t.code===`EPERM`||t.code===`EACCES`)){u(`[bin-linker] Symlink failed (${t.code}), using shell wrapper for ${e}`);let n=`#!/bin/sh\nbasedir=$(dirname "$0")\nexec ${f} "$basedir/${d}" "$@"\n`;await E(r,n),await y(r,493)}else throw t}}g++}return g}async function L(e,t){let n=F(t),r=k(e,`node_modules`,`.bin`),i=Object.keys(n).map(e=>({binName:e,linkPath:P(r,e),cmdPath:P(r,e,`.cmd`),ps1Path:P(r,e,`.ps1`)})).filter(e=>!!e.linkPath&&!!e.cmdPath&&!!e.ps1Path);if(d()){for(let{linkPath:e}of i)f({type:`bin-unlink`,path:e});u(`[dry-run] would remove ${i.length} bin link(s)`);return}let a=v()===`win32`,o=k(e,`node_modules`,t.name);for(let{linkPath:e,cmdPath:t,ps1Path:n}of i)try{await R(r,e,o)&&await w(e,{force:!0}),a&&(await R(r,t,o)&&await w(t,{force:!0}),await R(r,n,o)&&await w(n,{force:!0}))}catch{}}async function R(e,t,r){let i;try{i=await b(t)}catch(e){if(l(e)&&e.code===`ENOENT`)return!1;throw e}let a=j(r);if(i.isSymbolicLink()){let n=await ne(t),r=j(e,n);return r===a||r.startsWith(a+M)}if(!i.isFile())return!1;let o=await x(t,`utf-8`),s=n(A(e,r)),c=s.replace(/\//g,`\\`);return o.includes(`${s}/`)||o.includes(`${s}"`)||o.includes(`${c}\\`)||o.includes(`${c}"`)}const se={next:[`.next/cache`],webpack:[`node_modules/.cache`]},z=/* @__PURE__ */ new Map;async function ce(e){if(d())return u(`[dry-run] would invalidate bundler caches for ${e}`),f({type:`cache-invalidate`,path:e}),0;let t=z.get(e);t||(t=await m(e),z.set(e,t));let n=0;for(let r of t){if(!r.type)continue;let t=se[r.type];if(t)for(let o of t){let t=k(e,o);if(await i(t))try{await a(t),n++,u(`[inject] Invalidated ${r.type} cache: ${o}`)}catch{u(`[inject] Could not clear ${r.type} cache: ${o} (locked?)`)}}}return n}async function le(e,t,n,r={}){let i=await B(t,e.name,n,e.version,{repairMissingLink:!0});u(`[inject] ${e.name}@${e.version} → ${i}`),await s(i);let a=await Q(i),{copied:c,removed:l,skipped:d}=await o(e.packageDir,i,{force:r.force});u(`[inject] ${c} copied, ${l} removed, ${d} skipped`);let f=c>0||l>0?await ce(t):0,p=await Q(e.packageDir);a&&await L(t,a);let m=p?await I(t,e.name,p):0;return m>0&&u(`[inject] Created ${m} bin link(s)`),{copied:c,removed:l,skipped:d,binLinks:m,cacheInvalidations:f}}async function ue(e,n,r){let o=await B(e,n,r,void 0,{warnOnFallback:!1});if(!await i(o))return!1;let s=t(e,n);return await a(s),await c(o,s),!0}async function de(e,n,r,o){let s=t(e,n);if(!await i(s))return!1;let l=await B(e,n,r,o),f=await Q(l);f&&await L(e,f),await a(l),await c(s,l);let p=await Q(d()?s:l);if(p){let t=await I(e,n,p);t>0&&u(`[restore] Restored ${t} original bin link(s) for ${n}`)}return await a(s),!0}async function fe(e,t,n,i){let o=r(e,t),s=await B(e,t,n,i),c=await Q(s);c&&await L(e,c),await a(s),j(s)!==j(o)&&await a(o)}async function pe(e,t,n){let r=await Q(e.packageDir);if(!r)return[];let i={...r.dependencies,...Object.fromEntries(Object.entries(r.peerDependencies??{}).filter(([e])=>!r.peerDependenciesMeta?.[e]?.optional))};if(Object.keys(i).length===0)return[];let a=Object.keys(i);return(await Promise.all(a.map(async r=>({dep:r,installed:await me(r,e,t,n)})))).filter(e=>!e.installed).map(e=>e.dep)}async function me(e,t,n,r){return await i(k(n,`node_modules`,e))?!0:r?he(await B(n,t.name,r,t.version,{warnOnFallback:!1}),e):!1}async function he(e,t){let n=await C(e).catch(t=>{if(l(t)&&t.code===`ENOENT`)return e;throw t});for(;;){if(await i(k(n,`node_modules`,t)))return!0;let e=D(n);if(e===n)return!1;n=e}}async function B(t,n,a,o,s={}){let c=r(t,n),d=(await p(t)).resolve(a);if(!d.nodeModulesCompatible)throw Error(d.incompatibilityReason);let f=d.layout===`pnpm`||d.layout===`yarn-pnpm`?d.layout:null;if(!f)return d.layout===`bun`?ge(t,c,n):c;let m=f===`pnpm`?await be(t):await xe(t,d.virtualStoreFolder);try{let e=await _e(c);if(e){if(!(f===`pnpm`?await Ce(m,n,e):await we(m,e)))throw Error(`Refusing to inject ${n}: node_modules entry resolves outside a configured ${V(f)} virtual store (${e})`);return await U(e,n,void 0,f),u(`[inject] ${V(f)}: resolved symlink → ${e}`),e}}catch(e){if(!(l(e)&&e.code===`ENOENT`))throw l(e)&&u(`${V(f)} symlink resolution error: ${e instanceof Error?e.message:String(e)}`),e}let h=[];for(let e of m)await i(e)&&h.push(e);if(h.length>0){if(!await Z(t,n))return u(`[inject] ${V(f)}: ${n} is not declared by the consumer, skipping virtual store scan`),c;if(f===`yarn-pnpm`){let e=[];for(let r of h){u(`[inject] yarn-pnpm: scanning ${A(t,r)||`.`} for ${n}`);let i=await ve(r,n,o);i&&e.push(i)}let r=K(n,f,e);if(r)return u(`[inject] yarn-pnpm: found in virtual store → ${r}`),s.repairMissingLink&&await W(c,r,n,f),r}if(f===`pnpm`){let e=n.replaceAll(`/`,`+`);for(let r of h){if(u(`[inject] pnpm: scanning ${A(t,r)||`.`} for ${n}`),o){let t=`${e}@${o}`,i=await G(r,n,o,k(r,t,`node_modules`,n));if(i)return u(`[inject] pnpm: exact version match in virtual store → ${i}`),s.repairMissingLink&&await W(c,i,n,f),i}let i=await S(r),a=[];for(let t of i)if(ye(e,o,t)){let e=await G(r,n,o,k(r,t,`node_modules`,n));e&&a.push(e)}let l=K(n,f,a);if(l)return u(`[inject] pnpm: found in virtual store → ${l}`),s.repairMissingLink&&await W(c,l,n,f),l}}}if(s.warnOnFallback!==!1){if(await Z(t,n)){let t=f===`pnpm`?`pnpm`:`yarn`;e.warn(`${n} is in package.json but not installed in the ${V(f)} virtual store, so Knarr is linking it at node_modules/${n} directly. Run \`${t} install\` and then \`knarr add ${n}\` to update the installed copy instead.`)}else u(`[inject] ${V(f)}: ${n} not installed yet, linking at node_modules/${n}`)}return c}function V(e){return e===`pnpm`?`pnpm`:`Yarn pnpm-linker`}async function ge(e,t,n){try{if(!(await b(t)).isSymbolicLink())return t}catch(e){if(l(e)&&e.code===`ENOENT`)return t;throw e}let r=await C(t),i=k(e,`node_modules`,`.bun`);if(!H(await C(i).catch(e=>{if(l(e)&&e.code===`ENOENT`)return i;throw e}),r))throw Error(`Refusing to inject ${n}: Bun target resolves outside the local node_modules/.bun store (${r})`);return await U(r,n,void 0,`Bun isolated`),u(`[inject] Bun isolated: resolved symlink → ${r}`),r}function H(e,t){let n=A(j(e),j(t));return n===``||!!n&&!n.startsWith(`..`)&&!O(n)}async function _e(e){return(await b(e)).isSymbolicLink()?C(e):null}async function U(e,t,n,r){let i=r===`Bun isolated`?r:V(r),a=await Q(e);if(a){if(a.name&&a.name!==t)throw Error(`Refusing to inject ${t}: ${i} target contains package "${a.name}"`);if(n&&a.version&&a.version!==n)throw Error(`Refusing to inject ${t}@${n}: ${i} target contains version ${a.version}`)}}async function W(e,t,n,r){let i=!1;try{if(!(await b(e)).isSymbolicLink())return;i=!0}catch(e){if(!l(e)||e.code!==`ENOENT`)throw e}let a=D(e);if(d()){let i=A(a,t);u(`[inject] ${V(r)}: would restore node_modules symlink for ${n} → ${i}`),f({type:`write`,path:e,dest:t,detail:`${V(r)} package symlink`});return}let o=v()===`win32`;await s(a);let c=await C(a).catch(()=>a),p=A(c,t);u(`[inject] ${V(r)}: restoring node_modules symlink for ${n} → ${p}`),i&&await w(e,{force:!0}),await T(o?t:p,e,o?`junction`:`dir`)}async function G(e,t,n,r){if(!Y(e,t,r))return null;try{let[i,a]=await Promise.all([C(e),C(r)]);if(!Y(i,t,a))throw Error(`Refusing to inject ${t}: virtual store candidate resolves outside a configured pnpm virtual store (${a})`);return await U(a,t,n,`pnpm`),a}catch(e){if(l(e)&&e.code===`ENOENT`)return null;throw e}}async function ve(e,t,n){let r=await S(e),i=[];for(let a of r){let r=k(e,a,`package`),o=await Q(r);if(!o||o.name!==t||n&&o.version!==n)continue;let[s,c]=await Promise.all([C(e),C(r)]);if(!X(s,c))throw Error(`Refusing to inject ${t}: virtual store candidate resolves outside a configured Yarn pnpm-linker virtual store (${c})`);i.push(c)}return K(t,`yarn-pnpm`,i)}function ye(e,t,n){if(!t)return n.startsWith(`${e}@`);let r=`${e}@${t}`;return n===r||n.startsWith(`${r}_`)}function K(e,t,n){if(n.length<=1)return n[0]??null;throw Error(`Refusing to repair ${e}: multiple ${V(t)} virtual-store entries match. Run your package manager's install command, then try again.`)}async function be(e){let t=k(e,`node_modules`),n=[],r=k(t,`.pnpm`);await q(e,r)&&n.push(r);let i=await J(t);if(!i)return n;let a=O(i)?i:j(t,i);return await q(e,a)?(n.some(e=>j(e)===j(a))||n.push(a),n):(u(`[inject] pnpm: ignoring external virtualStoreDir ${a}`),n)}async function xe(e,t){let n=k(e,`node_modules`),r=[],i=k(n,`.store`);if(await q(e,i)&&r.push(i),!t)return r;let a=O(t)?t:j(e,t);return await q(e,a)?(r.some(e=>j(e)===j(a))||r.push(a),r):(u(`[inject] yarn-pnpm: ignoring external pnpmStoreFolder ${a}`),r)}async function q(e,t){return H(await C(e).catch(()=>j(e)),await C(t).catch(e=>{if(l(e)&&e.code===`ENOENT`)return j(t);throw e}))}async function J(e){try{return Se(await x(k(e,`.modules.yaml`),`utf-8`))}catch(e){if(l(e)&&e.code===`ENOENT`)return null;throw e}}function Se(e){try{let t=g(_(e),`virtualStoreDir`)?.trim();if(t)return t}catch{}let t=e.match(/^virtualStoreDir:\s*(.+?)\s*$/m);if(!t)return null;let n=(t[1]??``).trim().replace(/\s+#.*$/,``);return(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`))&&(n=n.slice(1,-1)),n||null}async function Ce(e,t,n){for(let r of e)try{if(Y(await C(r),t,n))return!0}catch(e){if(l(e)&&e.code===`ENOENT`)continue;throw e}return!1}async function we(e,t){for(let n of e)try{if(X(await C(n),t))return!0}catch(e){if(l(e)&&e.code===`ENOENT`)continue;throw e}return!1}function Y(e,t,n){if(!H(e,n))return!1;let r=A(e,n).replace(/\\/g,`/`),i=`node_modules/${t}`.replace(/\\/g,`/`);return r===i||r.endsWith(`/${i}`)}function X(e,t){if(!H(e,t))return!1;let n=A(e,t).replace(/\\/g,`/`).split(`/`);return n.length===2&&n[1]===`package`}async function Z(e,t){let n=await $(e);return n?[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`].some(e=>{let r=h(n,e);return r!==void 0&&Object.hasOwn(r,t)}):!1}async function Q(e){let t=await $(e);return t&&ee(t)}async function $(t){try{let e=await x(k(t,`package.json`),`utf-8`);return _(e,k(t,`package.json`))}catch(n){return l(n)&&n.code!==`ENOENT`&&e.warn(`Failed to read package.json in ${t}: ${n instanceof Error?n.message:String(n)}`),null}}export{fe as a,Z as i,pe as n,B as o,le as r,de as s,ue as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile as e}from"node:fs/promises";function t(e){let t=Object.create(null);if(e)for(let[n,r]of Object.entries(e))t[n]=r;return t}function n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function r(e){return JSON.parse(e)}function i(e,t=`JSON`){let i=r(e);if(!n(i))throw Error(`${t} must contain a JSON object`);return i}async function a(t,n=t){return i(await e(t,`utf-8`),n)}function o(e,t){let n=e[t];return typeof n==`string`?n:void 0}function s(e,t){let r=e[t];return n(r)?r:void 0}function c(e,n){let r=s(e,n),i=t();if(!r)return i;for(let[e,t]of Object.entries(r))typeof t==`string`&&(i[e]=t);return i}function l(e){return typeof e.name!=`string`||typeof e.version!=`string`?null:e}function u(e){return/^(\
|
|
1
|
+
import{readFile as e}from"node:fs/promises";function t(e){let t=Object.create(null);if(e)for(let[n,r]of Object.entries(e))t[n]=r;return t}function n(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function r(e){return JSON.parse(e)}function i(e,t=`JSON`){let i=r(e);if(!n(i))throw Error(`${t} must contain a JSON object`);return i}async function a(t,n=t){return i(await e(t,`utf-8`),n)}function o(e,t){let n=e[t];return typeof n==`string`?n:void 0}function s(e,t){let r=e[t];return n(r)?r:void 0}function c(e,n){let r=s(e,n),i=t();if(!r)return i;for(let[e,t]of Object.entries(r))typeof t==`string`&&(i[e]=t);return i}function l(e){return typeof e.name!=`string`||typeof e.version!=`string`?null:e}function u(e){return/^([ \t]+)"/m.exec(e)?.[1]??` `}export{t as a,a as c,s as i,o as l,u as n,r as o,n as r,i as s,l as t,c as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{l as r,s as i}from"./tracker-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{l as r,s as i}from"./tracker-BUpkmn8j.mjs";import{i as a}from"./history-BNX-3W-p.mjs";import{n as o,r as s}from"./store-D2r3Vo5S.mjs";import{a as c,p as l}from"./fs-DusqxRQR.mjs";import{t as u}from"./format-IsfSiyGV.mjs";import{a as d}from"./json-b5d4W58a.mjs";import{n as f,t as p}from"./output-B7NC4xgj.mjs";import{resolve as m}from"node:path";var h=e({meta:{name:`list`,description:`List linked packages in current project or in the store`},args:{store:{type:`boolean`,description:`List all packages in the global Knarr store`,default:!1},history:{type:`boolean`,description:`Show build history for linked packages`,default:!1}},async run({args:e}){f(),e.store?await _():e.history?await v():await g()}});async function g(){let e=await i(m(`.`)),r=Object.entries(e.links);if(r.length===0){n.info(`No linked packages in this project`),p({packages:[]});return}n.info(`Linked packages (${r.length}):\n`);let a=l(8),s=await Promise.all(r.map(([e,t])=>a(async()=>{let n=await o(e,t.version),r=!!(n&&n.meta.contentHash!==t.contentHash);return{name:e,version:t.version,buildId:t.buildId??null,stale:r,sourcePath:t.sourcePath}})));for(let e of s){let r=e.buildId?`[${e.buildId}]`:`[--------]`,i=e.stale?t.yellow(` (stale)`):``;n.log(` ${t.cyan(e.name)} ${t.dim(`@`+e.version)} ${t.dim(r)}${i} ← ${t.dim(e.sourcePath)}`)}p({packages:s})}async function _(){let[e,i]=await Promise.all([s(),r()]);if(e.length===0){n.info(`Knarr store is empty`),p({entries:[],totalSize:0});return}let a=l(8),o=await Promise.all(e.map(e=>a(()=>c(e.packageDir)))),d=o.reduce((e,t)=>e+t,0);n.info(`Store entries (${e.length}, ${u(d)} total):\n`);let f=[];for(let[r,a]of e.entries()){let e=o[r]??0,s=y(new Date(a.meta.publishedAt)),c=a.meta.buildId?`[${a.meta.buildId}]`:`[--------]`,l=i[a.name]?.length??0,d=l>0?t.green(`${l} consumer${l>1?`s`:``}`):t.dim(`no consumers`);n.log(` ${t.cyan(a.name)} ${t.dim(`@`+a.version)} ${t.dim(c)} ${t.dim(u(e))} ${t.dim(`published ${s}`)} ${d}`),n.log(` ${t.dim(`from: ${a.meta.sourcePath}`)}`),f.push({name:a.name,version:a.version,buildId:a.meta.buildId??null,publishedAt:a.meta.publishedAt,sourcePath:a.meta.sourcePath,consumers:l,size:e})}p({entries:f,totalSize:d})}async function v(){let e=await i(m(`.`)),r=Object.entries(e.links);if(r.length===0){n.info(`No linked packages in this project`),p({packages:[]});return}let o=d();for(let[e,i]of r){let r=await a(e,i.version);n.info(`${t.cyan(e)} ${t.dim(`@`+i.version)} — ${r.length} historical build(s)`);for(let e of r){let r=y(new Date(e.publishedAt));n.log(` ${t.dim(e.buildId)} ${t.dim(`published ${r}`)}`)}o[e]=r.map(e=>({buildId:e.buildId,publishedAt:e.publishedAt,contentHash:e.contentHash}))}p({history:o})}function y(e){let t=Date.now()-e.getTime(),n=Math.floor(t/1e3);if(n<60)return`${n}s ago`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}export{h as default};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,f as i,t as a}from"./fs-DusqxRQR.mjs";import{t as o}from"./timer-BZNWRS3O.mjs";import{n as s,t as c}from"./output-B7NC4xgj.mjs";import{n as l,r as u}from"./logger-Oo2Slehd.mjs";import{i as d,r as f}from"./dry-run-DPoN8bZo.mjs";import{n as p,t as m}from"./add-flow-
|
|
2
|
-
`);let u=y(s,`.yalc`),p=y(s,`yalc.lock`),g=y(s,`package.json`),_=await r(u),v=await r(p);if(!_&&!v){n.info(`No yalc usage detected in this project.`);let e={migrated:!1,packages:[],linkedPackages:[],plannedLinks:[],elapsed:a.elapsedMs()};return c(e),e}let x=await C(p,v);if(!e.yes){let e=await n.prompt(`Migrate from yalc to Knarr? This will modify package.json and remove .yalc/ and yalc.lock.`,{type:`confirm`});if(!e||typeof e==`symbol`){n.info(`Cancelled`);let e={migrated:!1,packages:x,linkedPackages:[],plannedLinks:[],elapsed:a.elapsedMs()};return c(e),e}}if(x.length>0&&n.info(`Found ${x.length} yalc-linked package(s): ${x.map(e=>t.cyan(e)).join(`, `)}`),await w(g),_&&(await i(u),n.success(`Removed .yalc/ directory`)),v){if(l())d({type:`remove`,path:p});else{let{rm:e}=await import(`node:fs/promises`);await e(p,{force:!0})}n.success(`Removed yalc.lock`)}let S=await T(x,e),E=[],D=[];if(S.length>0)for(let t of S){let n=`knarr add ${t.packageName} --from ${t.sourcePath}`;l()?(d({type:`command-skip`,path:s,detail:n}),D.push(n)):(await m({packageArg:t.packageName,from:t.sourcePath,yes:e.yes??!1,emitOutput:!1}),E.push(t.packageName))}if(n.log(``),n.info(`${t.bold(`Migration complete!`)} Next steps:\n`),S.length===0||D.length>0){n.log(` 1. ${t.cyan(`knarr init`)}`);let e=x.length>0?x:[`<package>`],r=2;for(let i of e){let e=D.find(e=>e.includes(` ${i} `))??`knarr add ${i} --from <path-to-${i}>`;n.log(` ${r}. ${t.cyan(e)}`),r++}}else{n.log(` 1. ${t.cyan(`knarr doctor --fix`)}`);for(let e of S)n.log(` 2. ${t.cyan(h(e.sourcePath))}`)}n.log(`\n Run ${t.cyan(`knarr doctor`)} to verify your setup.\n`),n.info(`Migrated in ${a.elapsed()}`);let O={migrated:!0,packages:x,linkedPackages:E,plannedLinks:D,elapsed:a.elapsedMs()};return c(O),l()&&f(),O}async function C(e,t){if(!t)return[];try{let t=await v(e,`utf-8`),n=g(_(t,`yalc.lock`),`packages`);return n?Object.keys(n):[]}catch{return n.warn(`Could not parse yalc.lock - the file may be corrupted. Continuing with cleanup.`),[]}}async function w(e){if(await r(e))try{let r=await v(e,`utf-8`),i=_(r,e),o=!1;for(let e of[`dependencies`,`devDependencies`,`peerDependencies`]){let r=g(i,e);if(r)for(let[e,i]of Object.entries(r))typeof i==`string`&&i.includes(`.yalc/`)&&(delete r[e],o=!0,n.info(`Removed file:.yalc/ reference for ${t.cyan(e)}`))}if(o){let t=r.match(/^(\
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,f as i,t as a}from"./fs-DusqxRQR.mjs";import{t as o}from"./timer-BZNWRS3O.mjs";import{n as s,t as c}from"./output-B7NC4xgj.mjs";import{n as l,r as u}from"./logger-Oo2Slehd.mjs";import{i as d,r as f}from"./dry-run-DPoN8bZo.mjs";import{n as p,t as m}from"./add-flow-D9HxSmKS.mjs";import{t as h}from"./hints-BKo_2axg.mjs";import{i as g,s as _}from"./json-b5d4W58a.mjs";import{readFile as v}from"node:fs/promises";import{join as y,resolve as b}from"node:path";var x=e({meta:{name:`migrate`,description:`Migrate from yalc to Knarr`},args:{from:{type:`string`,description:`Path to a local package source to publish and link after cleanup`},yes:{type:`boolean`,alias:`y`,description:`Skip confirmation prompts`,default:!1}},async run({args:e}){s(),await S({yes:e.yes,from:e.from})}});async function S(e={}){let a=new o,s=b(`.`);n.info(`Checking for yalc usage...
|
|
2
|
+
`);let u=y(s,`.yalc`),p=y(s,`yalc.lock`),g=y(s,`package.json`),_=await r(u),v=await r(p);if(!_&&!v){n.info(`No yalc usage detected in this project.`);let e={migrated:!1,packages:[],linkedPackages:[],plannedLinks:[],elapsed:a.elapsedMs()};return c(e),e}let x=await C(p,v);if(!e.yes){let e=await n.prompt(`Migrate from yalc to Knarr? This will modify package.json and remove .yalc/ and yalc.lock.`,{type:`confirm`});if(!e||typeof e==`symbol`){n.info(`Cancelled`);let e={migrated:!1,packages:x,linkedPackages:[],plannedLinks:[],elapsed:a.elapsedMs()};return c(e),e}}if(x.length>0&&n.info(`Found ${x.length} yalc-linked package(s): ${x.map(e=>t.cyan(e)).join(`, `)}`),await w(g),_&&(await i(u),n.success(`Removed .yalc/ directory`)),v){if(l())d({type:`remove`,path:p});else{let{rm:e}=await import(`node:fs/promises`);await e(p,{force:!0})}n.success(`Removed yalc.lock`)}let S=await T(x,e),E=[],D=[];if(S.length>0)for(let t of S){let n=`knarr add ${t.packageName} --from ${t.sourcePath}`;l()?(d({type:`command-skip`,path:s,detail:n}),D.push(n)):(await m({packageArg:t.packageName,from:t.sourcePath,yes:e.yes??!1,emitOutput:!1}),E.push(t.packageName))}if(n.log(``),n.info(`${t.bold(`Migration complete!`)} Next steps:\n`),S.length===0||D.length>0){n.log(` 1. ${t.cyan(`knarr init`)}`);let e=x.length>0?x:[`<package>`],r=2;for(let i of e){let e=D.find(e=>e.includes(` ${i} `))??`knarr add ${i} --from <path-to-${i}>`;n.log(` ${r}. ${t.cyan(e)}`),r++}}else{n.log(` 1. ${t.cyan(`knarr doctor --fix`)}`);for(let e of S)n.log(` 2. ${t.cyan(h(e.sourcePath))}`)}n.log(`\n Run ${t.cyan(`knarr doctor`)} to verify your setup.\n`),n.info(`Migrated in ${a.elapsed()}`);let O={migrated:!0,packages:x,linkedPackages:E,plannedLinks:D,elapsed:a.elapsedMs()};return c(O),l()&&f(),O}async function C(e,t){if(!t)return[];try{let t=await v(e,`utf-8`),n=g(_(t,`yalc.lock`),`packages`);return n?Object.keys(n):[]}catch{return n.warn(`Could not parse yalc.lock - the file may be corrupted. Continuing with cleanup.`),[]}}async function w(e){if(await r(e))try{let r=await v(e,`utf-8`),i=_(r,e),o=!1;for(let e of[`dependencies`,`devDependencies`,`peerDependencies`]){let r=g(i,e);if(r)for(let[e,i]of Object.entries(r))typeof i==`string`&&i.includes(`.yalc/`)&&(delete r[e],o=!0,n.info(`Removed file:.yalc/ reference for ${t.cyan(e)}`))}if(o){let t=r.match(/^([ \t]+)"/m)?.[1]||` `;await a(e,JSON.stringify(i,null,t)+`
|
|
3
3
|
`),n.success(`Cleaned up package.json`)}}catch(e){n.warn(`Could not clean package.json: ${e instanceof Error?e.message:String(e)}. You may need to manually remove file:.yalc/ references.`)}}async function T(e,t){if(t.from){if(e.length>1){if(n.warn(`--from is only used for one-package migrations; source paths are needed per package.`),t.yes||u())return[]}else{let r=b(t.from),i=await p(r);return e.length===1&&e[0]!==i&&n.warn(`yalc.lock lists ${e[0]}, but ${r} is ${i}; linking ${i}.`),[{packageName:i,sourcePath:r}]}}if(e.length<=1||t.yes||u())return[];let r=[];for(let t of e){let e=await n.prompt(`Source path for ${t} (leave blank to skip):`,{type:`text`,default:``});if(typeof e!=`string`||!e.trim())continue;let i=b(e.trim()),a=await p(i);a!==t&&n.warn(`yalc.lock lists ${t}, but ${i} is ${a}; linking ${a}.`),r.push({packageName:a,sourcePath:i})}return r}export{x as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as addToTranspilePackages,n as hasTranspilePackage}from"./nextjs-config-
|
|
1
|
+
export{t as addToTranspilePackages,n as hasTranspilePackage}from"./nextjs-config-D3H6P4Is.mjs";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./fs-DusqxRQR.mjs";import{r as t}from"./vite-config-
|
|
1
|
+
import{t as e}from"./fs-DusqxRQR.mjs";import{r as t}from"./vite-config-Bvv75_oH.mjs";import{readFile as n}from"node:fs/promises";function r(e){return e.match(/^([ \t]+)\S/m)?.[1]||` `}function i(e){let t=[],n=/['"]([^'"]*)['"]/g,r;for(;(r=n.exec(e))!==null;)t.push(r[1]??``);return t}async function a(e,t){let r;try{r=await n(e,`utf-8`)}catch{return{configured:!1,error:`could not read config file`}}let a=/transpilePackages\s*:\s*\[([^\]]*)\]/s.exec(r);return a?{configured:i(a[1]??``).includes(t)}:{configured:!1}}function o(e,t){return e.length===0?`[]`:e.length<=3?`[${e.map(e=>`'${e}'`).join(`, `)}]`:`[\n${e.map(e=>`${t}${t}'${e}',`).join(`
|
|
2
2
|
`)}\n${t}]`}function s(e){let n=t(e);return n.complex?n:/(?:module\.exports\s*=\s*|export\s+default\s+)[\w.]+\s*\(\s*\{/.test(e)?{complex:!0,reason:`wrapper function pattern`}:/\w+\s*\(\s*\w+\s*\(/.test(e)&&e.includes(`module.exports`)?{complex:!0,reason:`chained wrapper functions`}:{complex:!1}}async function c(t,a){let c;try{c=await n(t,`utf-8`)}catch{return{modified:!1,error:`could not read config file`}}let l=s(c);if(l.complex)return{modified:!1,error:`config too complex (${l.reason})`};let u=r(c),d=/transpilePackages\s*:\s*\[([^\]]*)\]/s,f=d.exec(c);if(f){let n=i(f[1]??``);if(n.includes(a))return{modified:!1};n.push(a);let r=o(n,u),s=c.replace(d,`transpilePackages: ${r}`);return await e(t,s),{modified:!0}}for(let n of[/module\.exports\s*=\s*\{/,/export\s+default\s+\{/,/(?:const|let|var)\s+\w*[Cc]onfig\w*\s*=\s*\{/]){let r=n.exec(c);if(r){let n=r.index+r[0].length,i=`\n${u}transpilePackages: ['${a}'],`,o=c.slice(0,n)+i+c.slice(n);return await e(t,o),{modified:!0}}}return{modified:!1,error:`unrecognized config pattern`}}async function l(t,a){let s;try{s=await n(t,`utf-8`)}catch{return{modified:!1}}let c=r(s),l=/transpilePackages\s*:\s*\[([^\]]*)\]/s,u=l.exec(s);if(!u)return{modified:!1};let d=i(u[1]??``),f=d.filter(e=>e!==a);if(f.length===d.length)return{modified:!1};let p=o(f,c),m=s.replace(l,`transpilePackages: ${p}`);return await e(t,m),{modified:!0}}export{a as n,l as r,c as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./shell-DQfdqK0J.mjs";import{i as t}from"./dry-run-DPoN8bZo.mjs";import{n}from"./logger-Oo2Slehd.mjs";import{s as r}from"./json-
|
|
1
|
+
import{t as e}from"./shell-DQfdqK0J.mjs";import{i as t}from"./dry-run-DPoN8bZo.mjs";import{n}from"./logger-Oo2Slehd.mjs";import{s as r}from"./json-b5d4W58a.mjs";import{a as i}from"./validators-C0_prNkT.mjs";import{readFile as a,stat as o}from"node:fs/promises";import{dirname as s,join as c}from"node:path";const l=/* @__PURE__ */ new Set([`npm`,`pnpm`,`yarn`,`bun`]),u=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lockb`,`bun`],[`bun.lock`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`],[`npm-shrinkwrap.json`,`npm`]],d=[`.pnp.cjs`,`.pnp.js`,`.pnp.loader.mjs`],f=[`.yarnrc.yml`,...d];function p(e){if(typeof e!=`string`)return null;let t=e.trim().match(/^([^@\s]+)(?:@(.+))?$/);if(!t)return null;let n=t[1];return!n||!l.has(n)?null:{name:n,version:t[2]?.trim()??``}}async function m(e){try{let t=await a(c(e,`package.json`),`utf-8`);return p(r(t).packageManager)}catch{return null}}async function h(e){let t=e;for(;;){let e=await m(t);if(e)return e;let n=s(t);if(n===t)return null;t=n}}function g(e){let t=e.trim().replace(/^npm:/,``);if(t===`classic`)return!1;let n=t.match(/^v?(\d+)(?:[.+-]|$)/);return n?Number(n[1])>=2:t.length>0}async function _(e){return(await v(e)).packageManager}async function v(e){let t=e;for(;;){let n=await m(t);if(n)return{packageManager:n.name,source:`packageManager`,dir:t,file:c(t,`package.json`)};let r=(await Promise.all(u.map(async([e,n])=>{try{return await o(c(t,e)),{lockfile:e,packageManager:n}}catch{return null}}))).find(e=>e!==null);if(r)return{packageManager:r.packageManager,source:`lockfile`,dir:t,file:c(t,r.lockfile)};let i=await y(t,f);if(i)return{packageManager:`yarn`,source:`yarnArtifact`,dir:t,file:c(t,i)};let a=s(t);if(a===t)return{packageManager:`npm`,source:`default`,dir:e};t=a}}async function y(e,t){for(let n of t)try{return await o(c(e,n)),n}catch{}return null}function b(e,t){for(let n of e.split(`
|
|
2
2
|
`)){let e=n.trim();if(e.startsWith(`#`)||!e.includes(t))continue;let r=e.match(RegExp(`^${t}:\\s*(.+)$`));if(!r?.[1])continue;let i=r[1].trim().replace(/\s+#.*$/,``).trim().replace(/^["']|["']$/g,``);if(i)return i}return null}async function x(e,t){let n=e;for(;;){try{let e=b(await a(c(n,`.yarnrc.yml`),`utf-8`),t);if(e)return e}catch{}let e=s(n);if(e===n)return null;n=e}}async function S(e){let t=await x(e,`nodeLinker`);return t===`node-modules`||t===`pnpm`||t===`pnp`?t:null}async function C(e){return x(e,`pnpmStoreFolder`)}async function w(e){let t=e;for(;;)try{return await o(c(t,`.yarnrc.yml`)),!0}catch{let e=s(t);if(e===t)return!1;t=e}}async function T(e){let t=e;for(;;){if((await Promise.all(d.map(async e=>{try{return await o(c(t,e)),!0}catch{return!1}}))).some(Boolean))return!0;let e=s(t);if(e===t)return!1;t=e}}async function E(e){let t=await S(e);if(t===`pnp`)return!0;if(t===`node-modules`||t===`pnpm`)return!1;if(await T(e)||await w(e))return!0;let n=await h(e);return n?.name===`yarn`&&g(n.version)}const D={npm:{layout:()=>`node-modules`,installArgs:(e,t)=>[`install`,...t?[`-D`]:[],...e]},pnpm:{layout:()=>`pnpm`,installArgs:(e,t)=>[`add`,...t?[`-D`]:[],...e]},yarn:{layout:e=>e===`pnpm`?`yarn-pnpm`:`node-modules`,installArgs:(e,t)=>[`add`,...t?[`-D`]:[],...e]},bun:{layout:()=>`bun`,installArgs:(e,t)=>[`add`,...t?[`-d`]:[],...e]}};async function O(e,t={}){let[n,r,i,a,o,s]=await Promise.all([v(e),w(e),T(e),S(e),C(e),E(e)]);return{resolve:c=>{let l=t.packageManager??(n.source==="default"&&c?c:n.packageManager),u=D[l],d=i||a===`pnp`||l===`yarn`&&s,f=u.layout(a),p={packageManager:l,layout:f,virtualStoreFolder:f===`yarn-pnpm`?o:null,yarnLinkerDiagnostic:k({packageManager:l,configExists:r,pnpManifestExists:i,nodeLinker:a,isPnp:d}),installCommand(e,t={}){return A(l,e,t.dev===!0)},formatCommand:j,run(t){return M(t,e)}};return d?{...p,nodeModulesCompatible:!1,incompatibilityReason:`Yarn PnP mode is not compatible with Knarr.
|
|
3
3
|
|
|
4
4
|
Knarr works by copying files into node_modules/, but PnP eliminates
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t}from"./validators-C0_prNkT.mjs";import{homedir as n}from"node:os";import{isAbsolute as r,join as i,relative as a,resolve as o}from"node:path";function s(e,t,n){let i=o(e),s=o(t),c=a(i,s);if(c!==``&&(c.startsWith(`..`)||r(c)))throw Error(`${n} escapes expected directory: ${t}`)}function c(){return process.env.KNARR_HOME||i(n(),`.knarr`)}function l(){return i(c(),`store`)}function u(){return i(c(),`consumers.json`)}function d(t){return e(t),t.replace(/\//g,`+`)}function f(e){if(e.startsWith(`@`)){let t=e.indexOf(`+`);if(t!==-1)return e.slice(0,t)+`/`+e.slice(t+1)}return e}function p(e,n){t(e,n);let r=l(),a=i(r,`${d(e)}@${n}`);return s(r,a,`Store entry path`),a}function m(e,t){return i(p(e,t),`package`)}function h(e,t){return i(p(e,t),`.knarr-meta.json`)}function g(e,t){return i(p(e,t),`history`)}function _(e,t,n){if(!/^[a-f0-9]{8,64}$/i.test(n))throw Error(`Invalid build id "${n}"`);return i(g(e,t),n)}function v(e){return i(e,`.knarr`)}function y(e){return i(e,`.knarr`,`state.json`)}function b(t,n){e(n);let r=i(t,`.knarr`,`backups`),a=i(r,d(n));return s(r,a,`Backup path`),a}function x(e){return e.replace(/\\/g,`/`)}function S(t,n){e(n);let r=i(t,`node_modules`),a=i(r,n);return s(r,a,`node_modules package path`),a}export{u as a,p as c,m as d,l as f,y as i,g as l,b as n,_ as o,x as p,v as r,S as s,f as t,h as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e}from"./logger-Oo2Slehd.mjs";import{s as t}from"./json-
|
|
1
|
+
import{i as e}from"./logger-Oo2Slehd.mjs";import{s as t}from"./json-b5d4W58a.mjs";import{readFile as n,stat as r}from"node:fs/promises";import{join as i,resolve as a}from"node:path";async function o(r){let a=[],o;try{o=await n(i(r,`package.json`),`utf-8`)}catch{return a.push({code:`NO_PACKAGE_JSON`,severity:`error`,message:`No package.json found`}),a}let s;try{s=t(o,`package.json`)}catch{return a.push({code:`INVALID_PACKAGE_JSON`,severity:`error`,message:`package.json is not valid JSON`}),a}let u=s.files;if(u&&u.length!==0||a.push({code:`EMPTY_FILES`,severity:`warn`,message:`No "files" field in package.json — npm will include almost everything. Consider adding a "files" field to control what gets published.`}),typeof s.main==`string`&&await c(r,s.main,`main`,a),typeof s.module==`string`&&await c(r,s.module,`module`,a),typeof s.types==`string`?await c(r,s.types,`types`,a):typeof s.typings==`string`&&await c(r,s.typings,`typings`,a),typeof s.exports==`string`?await c(r,s.exports,`exports`,a):s.exports&&typeof s.exports==`object`&&await l(r,s.exports,a),typeof s.bin==`string`)await c(r,s.bin,`bin`,a);else if(s.bin&&typeof s.bin==`object`)for(let[e,t]of Object.entries(s.bin))typeof t==`string`&&await c(r,t,`bin.${e}`,a);return e(`[preflight] ${a.length} issue(s) found in ${r}`),a}async function s(e){try{return(await r(e)).isFile()}catch{return!1}}async function c(e,t,n,r){await s(a(e,t))||r.push({code:`MISSING_PATH`,severity:`warn`,message:`"${n}" points to "${t}" which does not exist`})}async function l(e,t,n){for(let[r,i]of Object.entries(t))typeof i==`string`?i.startsWith(`.`)&&(await s(a(e,i))||n.push({code:`EXPORTS_PATH_MISSING`,severity:`warn`,message:`exports["${r}"] points to "${i}" which does not exist`})):i&&typeof i==`object`&&await u(e,r,i,n)}async function u(e,t,n,r){let i=Object.keys(n),o=i.indexOf(`types`),c=i.indexOf(`import`),l=i.indexOf(`require`),d=i.indexOf(`default`);if(o!==-1){let e=Math.min(c===-1?1/0:c,l===-1?1/0:l,d===-1?1/0:d);o>e&&e!==1/0&&r.push({code:`TYPES_CONDITION_ORDER`,severity:`warn`,message:`exports["${t}"].types should come before import/require/default for TypeScript to resolve it correctly`})}for(let[i,o]of Object.entries(n))typeof o==`string`&&o.startsWith(`.`)?await s(a(e,o))||r.push({code:`EXPORTS_PATH_MISSING`,severity:`warn`,message:`exports["${t}"].${i} points to "${o}" which does not exist`}):o&&typeof o==`object`&&await u(e,t,o,r)}export{o as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as runPreflightChecks}from"./preflight-DPlVrYLp.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{p as n}from"./fs-DusqxRQR.mjs";import{t as r}from"./publisher-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{p as n}from"./fs-DusqxRQR.mjs";import{t as r}from"./publisher-PQIqCt7r.mjs";import{a as i}from"./tracker-BUpkmn8j.mjs";import{t as a}from"./timer-BZNWRS3O.mjs";import{n as o,t as s}from"./output-B7NC4xgj.mjs";import{t as c}from"./errors-DRugrv36.mjs";import{i as l,n as u}from"./logger-Oo2Slehd.mjs";import{r as d}from"./dry-run-DPoN8bZo.mjs";import{resolve as f}from"node:path";const p=n(4);var m=e({meta:{name:`publish`,description:`Publish current package to the Knarr store`},args:{dir:{type:`positional`,description:`Package directory (default: current directory)`,required:!1},private:{type:`boolean`,description:`Allow publishing private packages`,default:!1},"no-scripts":{type:`boolean`,description:`Skip prepack/postpack lifecycle hooks`,default:!1},recursive:{type:`boolean`,alias:`r`,description:`Publish all packages in the workspace`,default:!1},"no-check":{type:`boolean`,description:`Skip pre-flight validation checks`,default:!1}},async run({args:e}){o();let n=new a,m=f(e.dir||`.`),h={allowPrivate:e.private,runScripts:!e[`no-scripts`]};if(!e[`no-check`]&&!e.recursive){let{runPreflightChecks:e}=await import(`./preflight-tgLzruAR.mjs`),n=await e(m);for(let e of n)e.severity===`error`?t.error(`[${e.code}] ${e.message}`):t.warn(`[${e.code}] ${e.message}`)}if(e.recursive){l(`[publish] Discovering workspace packages from ${m}`);let{findWorkspacePackages:e}=await import(`./workspace-CYaUDFd5.mjs`),i=await e(m);i.length===0&&(c(`No workspace packages found. Make sure you're in a workspace root or subdirectory.`),process.exit(1));let a=0,o=0,u=0,d=await Promise.all(i.map(e=>p(async()=>{try{return(await r(e,h)).skipped?`skipped`:`published`}catch(n){return t.warn(`Failed to publish ${e}: ${n instanceof Error?n.message:String(n)}`),`failed`}})));for(let e of d)e===`published`?a++:e===`skipped`?o++:u++;t.success(`Workspace publish: ${a} published, ${o} up to date, ${u} failed`),s({recursive:!0,packages:i.length,published:a,skipped:o,failed:u,elapsed:n.elapsedMs()})}else{l(`[publish] Publishing from ${m}`);try{let e=await r(m,h);if(s({...e,elapsed:n.elapsedMs()}),!e.skipped&&!u()){let n=await i(e.name);n.length>0&&t.info(`${n.length} linked project(s) still have the previous build. Run \`knarr push\` to update them, or \`knarr dev\` to keep them in sync as you edit.`)}}catch(e){c(e instanceof Error?e.message:String(e)),process.exit(1)}}u()&&d()}});export{m as default};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{n as e}from"./shell-DQfdqK0J.mjs";import{t}from"./console-C8XtlRyM.mjs";import{c as n,d as r,f as i,i as a,o,p as s,s as c,t as l,u}from"./fs-DusqxRQR.mjs";import{c as d,p as f}from"./paths-V3_BeE_z.mjs";import{n as p,t as m}from"./picomatch-DEttMFSR.mjs";import{i as h,n as g}from"./logger-Oo2Slehd.mjs";import{i as _,o as v}from"./store-D2r3Vo5S.mjs";import{g as y}from"./tracker-BUpkmn8j.mjs";import{i as b}from"./dry-run-DPoN8bZo.mjs";import{i as x}from"./validators-C0_prNkT.mjs";import{t as S}from"./package-manager-DENvuHqT.mjs";import{c as C,s as w,t as T}from"./json-b5d4W58a.mjs";import{availableParallelism as E,platform as D}from"node:os";import{readFile as O,readdir as k,stat as A}from"node:fs/promises";import{delimiter as j,dirname as ee,join as M,relative as N,resolve as P,sep as F}from"node:path";import{createHash as I}from"node:crypto";var L=/* @__PURE__ */ p(m(),1);async function te(e,n){let r=[],i=P(e);r.push(M(i,`package.json`));let a=await W(i,i),o=a.map(e=>f(N(i,e)));if(n.files&&n.files.length>0)for(let e of n.files){let n=M(i,e),s=P(n);if(!s.startsWith(i+F)&&s!==i){t.warn(`files pattern "${e}" escapes package directory, skipping`);continue}let c=!1;try{if((await A(n)).isDirectory()){let e=f(N(i,n))+`/`;for(let[t,n]of a.entries())o[t]?.startsWith(e)&&r.push(n);c=!0}else r.push(n),c=!0}catch(e){if(u(e)&&e.code!==`ENOENT`)throw e}if(!c){let n=(0,L.default)(e,{dot:!0}),s=0;for(let[e,t]of a.entries()){let a=o[e];if(a!==void 0&&n(a)){let e=P(t);if(!e.startsWith(i+F)&&e!==i)continue;r.push(t),s++}}s===0&&t.warn(`files pattern "${e}" matched no files`)}}else{let e=await B(i);for(let[t,n]of a.entries()){let i=o[t];i!==void 0&&!z(i,e)&&r.push(n)}}let s=new Set(r),c=new Set(a);for(let e of[`README.md`,`README`,`LICENSE`,`LICENCE`,`CHANGELOG.md`]){let t=M(i,e);s.has(t)||c.has(t)&&(r.push(t),s.add(t))}return[...s]}const R=/* @__PURE__ */ new Set(/* @__PURE__ */ `node_modules,.git,.svn,.hg,.DS_Store,.npmrc,.gitignore,.knarr,test,tests,__tests__,.github,.vscode,.idea,coverage,.nyc_output,tsconfig.json,tsconfig.build.json,.eslintrc,.eslintrc.js,.eslintrc.json,.prettierrc,.prettierrc.js,jest.config.js,jest.config.ts,vitest.config.ts,vitest.config.js`.split(`,`));function z(e,t){for(let n of t.negations)if(n(e))return!1;let n=e.split(/[\\/]/);for(let e of n)if(R.has(e)||t.literals.has(e))return!0;if(t.literals.has(e))return!0;for(let n of t.patterns)if(n(e))return!0;return!1}async function B(e){let t=await V(e,`.npmignore`);if(t!==null)return H(t);let n=await V(e,`.gitignore`);return n===null?ne():H(n)}async function V(e,t){try{return await O(M(e,t),`utf-8`)}catch(e){if(u(e)&&e.code===`ENOENT`)return null;throw e}}function ne(){return{literals:/* @__PURE__ */ new Set,patterns:[],negations:[]}}function H(e){let t={literals:/* @__PURE__ */ new Set,patterns:[],negations:[]};for(let n of e.split(`
|
|
2
|
+
`)){let e=n.trim();if(e&&!e.startsWith(`#`)){if(e.startsWith(`!`)){let n=e.slice(1);U(n),t.negations.push((0,L.default)(n,{dot:!0}))}else U(e)?t.patterns.push((0,L.default)(e,{dot:!0})):t.literals.add(e.replace(/\/$/,``))}}return t}function U(e){return/[*?[\]{}()]/.test(e)}async function W(e,t){let n=[];try{let r=await k(e,{withFileTypes:!0});for(let i of r){let r=M(e,i.name);if(i.isDirectory()){if(i.name===`.git`||e===t&&i.name===`node_modules`||i.isSymbolicLink())continue;n.push(...await W(r,t))}else i.isSymbolicLink()||n.push(r)}}catch(e){if(u(e)&&e.code===`ENOENT`)return[];throw e}return n}const re=s(Math.max(E(),8));async function ie(e,t,n=/* @__PURE__ */ new Map){let r=new Map(e.map(e=>[f(N(t,e)),e]));for(let e of n.keys())r.has(e)||r.set(e,M(t,e));let i=[...r.entries()].sort(([e],[t])=>e.localeCompare(t)),a=await Promise.all(i.map(([e,t])=>re(async()=>{let r=n.get(e);return r===void 0?{rel:e,content:await O(t)}:{rel:e,content:Buffer.isBuffer(r)?r:Buffer.from(r)}})));h(`[hash] Computing content hash for ${i.length} files`);let o=I(`sha256`),s=Buffer.alloc(4);for(let{rel:e,content:t}of a)o.update(e),o.update(`\0`),s.writeUInt32LE(t.length),o.update(s),o.update(t);let c=`sha256v2:`+o.digest(`hex`);return h(`[hash] Result: ${c.slice(0,20)}...`),c}const ae=s(Math.max(E(),8));async function oe(e,s={}){let u=M(e,`package.json`),f;try{f=await O(u,`utf-8`)}catch{throw Error(`No package.json found in ${e}`)}let p=w(f,u);if(typeof p.name!=`string`||!p.name)throw Error(`package.json missing 'name' field`);if(typeof p.version!=`string`||!p.version)throw Error(`package.json missing 'version' field`);let m=T(p);if(!m)throw Error(`package.json missing 'name' or 'version' field`);x(m.name,m.version),await J(e,m,`preknarr`),s.runScripts!==!1&&await J(e,m,`prepack`);let b=e;if(m.publishConfig?.directory){b=P(e,m.publishConfig.directory);try{if(!(await A(b)).isDirectory())throw Error(`publishConfig.directory "${m.publishConfig.directory}" is not a directory`)}catch(e){throw e instanceof Error&&`code`in e&&e.code===`ENOENT`?Error(`publishConfig.directory "${m.publishConfig.directory}" does not exist`,{cause:e}):e}h(`[publish] Using publishConfig.directory: ${b}`)}let S=M(b,`package.json`),C=b===e||await n(S),E=C?T(w(await O(S,`utf-8`),S)):m;if(!E?.name)throw Error(`publish package.json missing 'name' field`);if(!E.version)throw Error(`publish package.json missing 'version' field`);if(x(E.name,E.version),E.private&&!s.allowPrivate)throw Error(`Package "${E.name}" is private. Use --private flag to publish private packages.`);let D=C?E:{...E,files:void 0},k=await te(b,D);if(k.length===0)throw Error(`No publishable files found`);h(`[publish] Resolved ${k.length} files for ${E.name}@${E.version}`),await me(E,e),await ge(E,e);let j=de(E);j=ue(j);let F=/* @__PURE__ */ new Map;j===E&&C||F.set(`package.json`,JSON.stringify(j,null,2));let I=[...k],L=new Set(k.map(e=>N(b,e).replace(/\\/g,`/`)));for(let e of F.keys())L.has(e)||I.push(M(b,e));let R=await ie(I,b,F);if(!s.force){let e=await v(E.name,E.version);if(e&&e.contentHash===R)return t.info(`${E.name}@${E.version} already up to date (no changes since last publish)`),{name:E.name,version:E.version,fileCount:k.length,skipped:!0,contentHash:R,buildId:e.buildId??``}}let z=d(E.name,E.version),B=await y(z+`.lock`,async()=>{if(!s.force){let e=await v(E.name,E.version);if(e&&e.contentHash===R)return t.info(`${E.name}@${E.version} already up to date (no changes since last publish)`),{name:E.name,version:E.version,fileCount:k.length,skipped:!0,contentHash:R,buildId:e.buildId??``}}let u=_(z,`tmp`),d=M(u,`package`),f=R.slice(9,17);try{await c(d),h(`[publish] Copying files to temp store...`);let t=new Set(k.map(e=>ee(M(d,N(b,e)))));await Promise.all([...t].map(e=>o(e))),await Promise.all(k.map(e=>ae(async()=>{let t=N(b,e),n=t.replace(/\\/g,`/`),r=M(d,t),i=F.get(n);i===void 0?await a(e,r,{ensureParent:!1}):await l(r,Buffer.isBuffer(i)?i.toString(`utf-8`):i)}))),F.has(`package.json`)&&await l(M(d,`package.json`),JSON.stringify(j,null,2));let p={schemaVersion:1,contentHash:R,publishedAt:(/* @__PURE__ */ new Date()).toISOString(),sourcePath:e,buildId:f};await l(M(u,`.knarr-meta.json`),JSON.stringify(p,null,2));let m=await n(z),v=_(z,`old`),y=!1;try{m&&(await r(z,v),y=!g()),await r(u,z)}catch(e){throw y&&await n(v)&&(await n(z)&&await i(z),await r(v,z)),e}if(m&&!g()){try{let{captureHistory:e}=await import(`./history-Da5gEptz.mjs`);await e(E.name,E.version,v,s.historyLimit)}catch(e){h(`[publish] History capture failed: ${e instanceof Error?e.message:String(e)}`)}await i(v)}h(`[publish] Stored at ${z}`)}catch(e){throw await i(u),e}return{name:E.name,version:E.version,fileCount:k.length,skipped:!1,contentHash:R,buildId:f}},{stale:6e4});return B.skipped||(s.runScripts!==!1&&await J(e,m,`postpack`),await J(e,m,`postknarr`),t.success(`Published ${E.name}@${E.version} (${k.length} files) [${B.buildId}]`)),B}const G=parseInt(process.env.KNARR_HOOK_TIMEOUT??`30000`,10);function K(e){return D()===`win32`?Object.keys(e).find(e=>e.toLowerCase()===`path`)??`Path`:`PATH`}function q(e,t,n){if(D()===`win32`){let n=t.toLowerCase();for(let t of Object.keys(e))t.toLowerCase()===n&&delete e[t]}e[t]=n}function se(e,t,n,r){let i={...process.env},a=K(i),o=i[a]??``;return q(i,a,[M(e,`node_modules`,`.bin`),o].filter(Boolean).join(j)),`INIT_CWD`in i&&i.INIT_CWD||q(i,`INIT_CWD`,e),q(i,`npm_lifecycle_event`,n),q(i,`npm_lifecycle_script`,r),q(i,`npm_package_name`,t.name),q(i,`npm_package_version`,t.version),i}async function J(t,n,r){let i=n.scripts?.[r];if(!i)return;if(g()){b({type:`lifecycle-skip`,path:t,detail:`${r}: ${i}`});return}let a=await ce(t,r,i);return h(`[lifecycle] Running ${r}: ${a}`),new Promise((o,s)=>{let c=se(t,n,r,i),l=e(a,{cwd:t,env:c,stdio:`inherit`}),u=setTimeout(()=>{l.kill(`SIGTERM`),s(/* @__PURE__ */ Error(`${r} script timed out after ${G/1e3}s. Increase KNARR_HOOK_TIMEOUT env var if the script needs more time.`))},G);l.on(`close`,e=>{clearTimeout(u),e===0?o():s(/* @__PURE__ */ Error(`${r} script failed with exit code ${e}`))}),l.on(`error`,e=>{clearTimeout(u),s(/* @__PURE__ */ Error(`${r} script error: ${e.message}`))})})}async function ce(e,t,n){return(await S(e)).resolve().nodeModulesCompatible?n:`yarn run ${t}`}const le=[`main`,`module`,`exports`,`types`,`typings`,`browser`,`bin`];function ue(e){if(!e.publishConfig)return e;let t={...e};for(let n of le)n in e.publishConfig&&(t[n]=e.publishConfig[n]);return delete t.publishConfig,t}function de(e){let n=!1,r={...e},i=null,a=!1;for(let o of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let s=e[o];if(!s)continue;let c=!1,l={...s};for(let[e,r]of Object.entries(s))if(r.startsWith(`workspace:`)){let t=fe(e,r);if(!t)continue;l[e]=t,c=!0,n=!0}else if(r.startsWith(`catalog:`)){if(a||=(i=he(),!0),i){let a=Y(r,e,i);a?(l[e]=a,c=!0,n=!0):t.warn(`catalog: specifier for "${e}" could not be resolved — published package.json will contain "${r}" which may cause install failures`)}else h(`[publish] No pnpm-workspace.yaml found, cannot resolve catalog: for "${e}"`)}c&&(r[o]=l)}return n?r:e}function fe(e,n){let r=n.slice(10),i=pe(r),a=i?.name??e,o=i?.range??r;if(o===`*`||o===`^`||o===`~`){let r=Q?.versions.get(a);if(!r)return t.warn(`workspace: specifier for "${a}" could not be resolved — published package.json will contain "${n}" which may cause install failures`),null;let s=o===`*`?r:o+r;return i&&a!==e?`npm:${a}@${s}`:s}return i&&a!==e?`npm:${a}@${o}`:o}function pe(e){let t=e.lastIndexOf(`@`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return!n||!r?null:{name:n,range:r}}function Y(e,t,n){let r=e.slice(8);return r===``||r==="default"?n.default[t]??null:n.named[r]?.[t]??null}let X=null;async function Z(e){if(X?.dir===e)return X.root;let{findWorkspacePackageRoot:t}=await import(`./workspace-CYaUDFd5.mjs`),n=await t(e);return X={dir:e,root:n},n}let Q=null;async function me(e,t){if(![`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`].some(t=>{let n=e[t];return n&&Object.values(n).some(e=>e.startsWith(`workspace:`))}))return;let n=await Z(t);if(!n){Q=null;return}let{findWorkspacePackages:r}=await import(`./workspace-CYaUDFd5.mjs`),i=await r(n),a=/* @__PURE__ */ new Map;await Promise.all(i.map(async e=>{try{let t=T(await C(M(e,`package.json`)));t?.name&&t.version&&a.set(t.name,t.version)}catch{}})),Q={root:n,versions:a}}let $=null;function he(){return $?.catalogs??null}async function ge(e,t){if(![`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`].some(t=>{let n=e[t];return n&&Object.values(n).some(e=>e.startsWith(`catalog:`))}))return;let n=await Z(t);if(!n){$=null;return}let r=M(n,`pnpm-workspace.yaml`),i=(await A(r).catch(()=>null))?.mtimeMs??0;if($?.root===n&&$.mtimeMs===i)return;let{parseCatalogs:a}=await import(`./workspace-CYaUDFd5.mjs`);$={root:n,mtimeMs:i,catalogs:await a(n)}}export{oe as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t}from"./output-B7NC4xgj.mjs";import{a as n,i as r,o as i,s as a,t as o}from"./push-engine-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t}from"./output-B7NC4xgj.mjs";import{a as n,i as r,o as i,s as a,t as o}from"./push-engine-IoOaMeZe.mjs";import{t as s}from"./batch-push-CT5k2SrS.mjs";import{t as c}from"./config-DEpSKyI8.mjs";import{n as l}from"./logger-Oo2Slehd.mjs";import{r as u}from"./dry-run-DPoN8bZo.mjs";import{resolve as d}from"node:path";var f=e({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:!1},all:{type:`boolean`,description:`Push all workspace packages in dependency order`,default:!1},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:!1},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:!1},force:{type:`boolean`,alias:`f`,description:`Force copy all files, bypassing hash comparison`,default:!1},notify:{type:`boolean`,description:`Ring terminal bell on push completion (watch mode)`,default:!1},"no-cascade":{type:`boolean`,description:`Disable cascading rebuilds in --all watch mode`,default:!1}},async run({args:e}){t();let f=d(`.`),p=await c(f),m={runScripts:!e[`no-scripts`],force:e.force,historyLimit:p.historyLimit};if(e.all){let t=e.watch?await n(f,e):{canPush:!0,failedPackages:/* @__PURE__ */ new Set,skippedPackages:/* @__PURE__ */ new Set},r=/* @__PURE__ */ new Set([...t.failedPackages,...t.skippedPackages]);if(t.canPush&&await s(f,{...m,skipPackages:r}),l()){u();return}e.watch&&await i(f,e,m)}else{let t=()=>o(f,m);if((!e.watch||await r(f,e,p))&&await t(),l()){u();return}e.watch&&await a(f,e,t)}}});export{f as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{p as e}from"./fs-DusqxRQR.mjs";import{t}from"./publisher-
|
|
1
|
+
import{p as e}from"./fs-DusqxRQR.mjs";import{t}from"./publisher-PQIqCt7r.mjs";import{n}from"./store-D2r3Vo5S.mjs";import{r}from"./injector-CwNZ9rDe.mjs";import{a as i,n as a,o}from"./tracker-BUpkmn8j.mjs";import{t as s}from"./build-detect-Bf2HAfXm.mjs";import{t as c}from"./package-manager-DENvuHqT.mjs";import{t as l}from"./config-DEpSKyI8.mjs";import{t as u}from"./timer-BZNWRS3O.mjs";import{t as d}from"./output-B7NC4xgj.mjs";import{t as f}from"./errors-DRugrv36.mjs";import{i as p,n as m}from"./logger-Oo2Slehd.mjs";import{i as h}from"./dry-run-DPoN8bZo.mjs";import{t as g}from"./console-C8XtlRyM.mjs";import{c as _,l as v,r as y}from"./json-b5d4W58a.mjs";import{join as b}from"node:path";const x=e(4);async function S(e,r={}){let a=new u,o=await t(e,{runScripts:r.runScripts,force:r.force,historyLimit:r.historyLimit});if(o.skipped){let e=await n(o.name,o.version);if(e)return C(e,{force:r.force,timer:a,noConsumersStatus:`available`,noChange:!0,skippedReason:`content unchanged`});{let e=w(o.name,o.version,o.buildId,a.elapsedMs());return e.noChange=!0,e.skippedReason=`content unchanged`,g.info(`No changes to push for ${o.name}@${o.version}`+(o.buildId?` [${o.buildId}]`:``)),d(e),e}}if(m()){let e=await i(o.name),t=w(o.name,o.version,o.buildId,a.elapsedMs());return t.skippedReason=`dry-run`,t.consumers=e.length,t.skippedConsumers=e.length,t.consumerResults=e.map(e=>({consumerPath:e,status:`skipped`,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,reason:`dry-run publish preview; store entry was not written`})),g.info(`Dry-run: would publish ${o.name}@${o.version}`+(o.buildId?` [${o.buildId}]`:``)+`. Skipping consumer injection preview because the store entry was not written.`),d(t),t}let s=await n(o.name,o.version);if(!s){f(`Failed to read store entry for ${o.name}@${o.version} after publish`);let t=w(o.name,o.version,o.buildId,a.elapsedMs());return t.failedConsumers=1,t.consumerResults=[{consumerPath:e,status:`failed`,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,error:`store entry missing after publish`}],t}return C(s,{force:r.force,timer:a,noConsumersStatus:`published`})}async function C(e,t={}){let n=t.timer??new u,s=await i(e.name);if(s.length===0){let r=t.noConsumersStatus??`available`;g.success(`${e.name}@${e.version} ${r} in store`),g.info(`No consumers registered yet. Run 'knarr add `+e.name+`' in a consumer project to start receiving pushes.`);let i=w(e.name,e.version,e.meta.buildId??``,n.elapsedMs());return i.noChange=t.noChange??!1,i.skippedReason=t.skippedReason,t.emitOutput!==!1&&d(i),i}let l=0,f=0,m=0,h=0,_=0,v=0,y=0,b=0,S=await Promise.all(s.map(n=>x(async()=>{let i=await o(n,e.name);if(!i)return p(`[push] No link found for ${e.name} in ${n}, skipping`),{consumerPath:n,status:`skipped`,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,reason:`not linked in consumer state`};try{let o=(await c(n)).resolve(i.packageManager).packageManager,s=await r(e,n,o,{force:t.force});return await a(n,e.name,{...i,version:e.version,contentHash:e.meta.contentHash,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),buildId:e.meta.buildId??``,packageManager:o}),{consumerPath:n,status:`updated`,copied:s.copied,removed:s.removed,skipped:s.skipped,binLinks:s.binLinks,cacheInvalidations:s.cacheInvalidations}}catch(e){let t=e instanceof Error?e.message:String(e);return g.warn(`Failed to push to ${n}: ${t}`),{consumerPath:n,status:`failed`,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,error:t}}})));for(let e of S)e.status===`updated`?(l+=e.copied,f+=e.removed,m+=e.skipped,h+=e.binLinks,_+=e.cacheInvalidations,v++):e.status===`skipped`?y++:b++;let C=e.meta.buildId??``,T=C?` [${C}]`:``,E=[`${l} copied`,`${f} removed`,`${m} unchanged`];h>0&&E.push(`${h} bin links`),_>0&&E.push(`${_} cache invalidations`),y>0&&E.push(`${y} consumer(s) skipped`),b>0&&E.push(`${b} failed`);let D=b>0||y>0?`${v}/${s.length} consumer(s)`:`${v} consumer(s)`,O=`Pushed ${e.name}@${e.version}${T} to ${D} in ${n.elapsed()} (${E.join(`, `)})`;b>0?g.warn(O):g.success(O);let k={name:e.name,version:e.version,buildId:C,noChange:!1,consumers:s.length,updatedConsumers:v,failedConsumers:b,skippedConsumers:y,copied:l,removed:f,skipped:m,binLinks:h,cacheInvalidations:_,elapsed:n.elapsedMs(),consumerResults:S};return k.noChange=t.noChange??!1,k.skippedReason=t.skippedReason,t.emitOutput!==!1&&d(k),k}function w(e,t,n,r){return{name:e,version:t,buildId:n,noChange:!1,consumers:0,updatedConsumers:0,failedConsumers:0,skippedConsumers:0,copied:0,removed:0,skipped:0,binLinks:0,cacheInvalidations:0,elapsed:r,consumerResults:[]}}function T(e){if(!e)return;let t=parseInt(e,10);return Number.isFinite(t)?t:void 0}async function E(e,t,n){let{startWatcher:r}=await import(`./watcher-LcNLwOgA.mjs`),i=await l(e),{buildCmd:a,patterns:o}=await P(e,t,i),s=t.notify??i.notify??!1,c=await r(e,{patterns:o,buildCmd:a,debounce:T(t.debounce)??i.debounce,cooldown:T(t.cooldown)??i.cooldown,notify:s},async()=>{await n()});await new Promise(e=>{let t=()=>{g.info(`Stopping watcher...`),c.close().catch(e=>{g.warn(`Watcher did not close cleanly: ${e instanceof Error?e.message:String(e)}`)}).finally(e)};process.once(`SIGINT`,t),process.once(`SIGTERM`,t)})}async function D(e,t,n){let{buildCmd:r}=await P(e,t,n??await l(e));if(!r)return!0;if(m())return h({type:`command-skip`,path:e,detail:r}),!0;let{runBuildCommand:i}=await import(`./watcher-LcNLwOgA.mjs`),a=await i(r,e);return a||g.warn(`Initial build failed; skipping initial push. Watch mode will continue.`),a}async function O(e,t){let{buildReverseAdjacency:n,buildWorkspaceGraph:r,filterPublishableWorkspaceGraph:i}=await import(`./workspace-CYaUDFd5.mjs`),{topoSort:a,CycleError:o}=await import(`./topo-sort-CNCKE3Ap.mjs`),s=i(await r(e));if(s.packages.length===0)return{canPush:!0,failedPackages:/* @__PURE__ */ new Set,skippedPackages:/* @__PURE__ */ new Set};let c;try{c=a(s.adjacency)}catch(e){if(e instanceof o)return g.error(`Cannot build workspace before watch: ${e.message}`),{canPush:!1,failedPackages:new Set(s.packages.map(e=>e.name)),skippedPackages:/* @__PURE__ */ new Set};throw e}let l=new Map(s.packages.map(e=>[e.name,e.dir])),u=n(s.adjacency),d=/* @__PURE__ */ new Set,f=/* @__PURE__ */ new Set,m=/* @__PURE__ */ new Set;for(let e of c){let n=l.get(e);n&&(m.has(e)?(f.add(e),p(`[watch] Skipping initial build for ${e}: dependency build failed`)):await D(n,t)||(d.add(e),k(e,u,m)))}return{canPush:!0,failedPackages:d,skippedPackages:f}}function k(e,t,n){for(let r of t.get(e)??[])n.has(r)||(n.add(r),k(r,t,n))}const A=/* @__PURE__ */ new Set;function j(e,t){let n=JSON.stringify([e,t]);A.has(n)||(A.add(n),g.info(t))}async function M(e){let t;try{t=await _(b(e,`package.json`))}catch{return/* @__PURE__ */ new Set}let n=e=>e?.replace(/^\.\//,``).split(/[\\/]/)[0]??[],r=t.files,i=(Array.isArray(r)?r.filter(e=>typeof e==`string`):[]).flatMap(n).filter(e=>e!==`src`),a=[`main`,`module`,`types`].flatMap(e=>n(v(t,e))),o=N(t.exports).flatMap(n);return/* @__PURE__ */ new Set([...i,...a,...o])}function N(e){return typeof e==`string`?[e]:Array.isArray(e)?e.flatMap(N):y(e)?Object.values(e).flatMap(N):[]}async function P(e,t,n){let r=t.build,i=n?.watchPatterns;if(!t.build&&!t[`skip-build`]){if(n?.buildCmd)r=n.buildCmd,j(e,`Using build command from config: ${r}`);else{let t=(await c(e)).resolve().packageManager,n=await s(e,t);n&&(r=n,j(e,`Auto-detected build command: ${n}`))}}if(r&&!i){let{exists:t}=await import(`./fs-Ce7wcxvx.mjs`),n=await M(e),r=[`src`,`lib`,`source`,`app`,`pages`,`components`].filter(e=>!n.has(e)),a=(await Promise.all(r.map(async n=>({dir:n,exists:await t(b(e,n))})))).filter(e=>e.exists).map(e=>e.dir);i=a.length>0?a:[`src`],p(`[watch] Using source patterns with build command: ${i.join(`, `)}`)}else if(r&&i)p(`[watch] Using configured watch patterns with build command: ${i.join(`, `)}`);else{j(e,`No build command detected — watching output directories directly`);try{let t=(await _(b(e,`package.json`))).files,n=Array.isArray(t)?t.filter(e=>typeof e==`string`):[];n.length>0?(i=n,g.info(`Watching from package.json "files": ${i.join(`, `)}`)):g.warn(`No "files" field in package.json — falling back to watching src/ and lib/. Add a "files" field or use --build to specify a build command.`)}catch(e){p(`[watch] Could not read package.json: ${e instanceof Error?e.message:String(e)}`)}}return{buildCmd:r,patterns:i}}async function F(e,t,n){let r=!t[`no-cascade`],{WatchOrchestrator:i}=await import(`./watch-orchestrator-5eaHlofc.mjs`);await new i(r).start(e,t,n)}export{O as a,D as i,C as n,F as o,P as r,E as s,S as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{a as n,s as r}from"./injector-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{a as n,s as r}from"./injector-CwNZ9rDe.mjs";import{f as i,h as a,o,p as s,s as c}from"./tracker-BUpkmn8j.mjs";import{n as l}from"./bundler-detect-BaShXORS.mjs";import{r as u}from"./nextjs-config-D3H6P4Is.mjs";import{t as d}from"./timer-BZNWRS3O.mjs";import{n as f,t as p}from"./output-B7NC4xgj.mjs";import{t as m}from"./errors-DRugrv36.mjs";import{i as h,n as g}from"./logger-Oo2Slehd.mjs";import{r as _}from"./dry-run-DPoN8bZo.mjs";import{basename as v,resolve as y}from"node:path";var b=e({meta:{name:`remove`,description:`Remove a Knarr-linked package and restore the original`},args:{package:{type:`positional`,description:`Package name to remove`,required:!1},all:{type:`boolean`,description:`Remove all linked packages`,default:!1},force:{type:`boolean`,description:`Skip error checking`,default:!1},yes:{type:`boolean`,alias:`y`,description:`Skip confirmation prompts`,default:!1}},async run({args:e}){f();let n=new d,r=y(`.`);if(e.all){let i=await c(r),a=Object.entries(i.links);if(a.length===0){t.info(`No linked packages to remove`),p({removed:0});return}if(!e.yes){let e=a.map(([e])=>e).join(`, `),n=await t.prompt(`Remove ${a.length} linked package(s)? (${e})`,{type:`confirm`});if(!n||typeof n==`symbol`){t.info(`Cancelled`);return}}let o=0,s=0;for(let[e,n]of a)try{await x(r,e,n),o++}catch(n){s++,t.warn(`Failed to remove ${e}: ${n instanceof Error?n.message:String(n)}`)}t.success(`Removed ${o} Knarr link(s)${s>0?`, ${s} failed`:``} in ${n.elapsed()}`),p({removed:o,failed:s,elapsed:n.elapsedMs()}),g()&&_();return}let i=e.package;i||(m(`Package name required. Use --all to remove all linked packages.`),process.exit(1));let a=await o(r,i);if(!a){if(e.force){t.warn(`Package "${i}" is not linked, skipping`),p({removed:0});return}m(`Package "${i}" is not linked in this project`),process.exit(1)}await x(r,i,a),t.success(`Removed Knarr link for ${i} in ${n.elapsed()}`),p({removed:1,package:i,elapsed:n.elapsedMs()}),g()&&_()}});async function x(e,o,d){h(`[remove] Removing ${o}`);let f=!1;if(d.backupExists)try{f=await r(e,o,d.packageManager,d.version),f&&t.success(`Restored original ${o} from backup`)}catch(e){t.warn(`Failed to restore backup for ${o}: ${e instanceof Error?e.message:String(e)}. Run your package manager's install command to restore it.`)}f||await n(e,o,d.packageManager,d.version);let p=await l(e);p.type===`next`&&p.configFile&&(await u(p.configFile,o)).modified&&h(`[remove] Removed ${o} from ${v(p.configFile)}`);let{findTailwindCss:m,removeTailwindSource:g}=await import(`./tailwind-source-Ck2WyTX8.mjs`),_=await m(e);if(_&&(await g(_,o)).modified&&h(`[remove] Removed @source for ${o} from ${v(_)}`),await i(e,o),await s(o,e).catch(a),p.type===`vite`&&p.configFile){let t=await c(e);if(Object.keys(t.links).length===0){let{removeFromViteConfig:e}=await import(`./vite-config-DQfi8QwQ.mjs`);(await e(p.configFile)).modified&&h(`[remove] Removed Knarr plugin from ${v(p.configFile)}`)}}}export{b as n,x as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{n as default}from"./remove-BVr3n-3t.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{s as n}from"./tracker-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{s as n}from"./tracker-BUpkmn8j.mjs";import{t as r}from"./remove-BVr3n-3t.mjs";import{c as i,f as a}from"./fs-DusqxRQR.mjs";import{s as o}from"./init-helpers-DfznkCwv.mjs";import{r as s}from"./paths-V3_BeE_z.mjs";import{t as c}from"./timer-BZNWRS3O.mjs";import{n as l,t as u}from"./output-B7NC4xgj.mjs";import{i as d,n as f}from"./logger-Oo2Slehd.mjs";import{r as p}from"./dry-run-DPoN8bZo.mjs";import{join as m,resolve as h}from"node:path";var g=e({meta:{name:`reset`,description:`Remove all Knarr links and teardown Knarr from this project`},args:{yes:{type:`boolean`,alias:`y`,description:`Skip confirmation prompts`,default:!1}},async run({args:e}){l();let g=new c,_=h(`.`),v=s(_);if(!await i(v)){t.info(`No Knarr setup found in this project`),u({reset:!1});return}let y=await n(_),b=Object.entries(y.links);if(!e.yes){let e=[];b.length>0&&e.push(`remove ${b.length} linked package(s)`),e.push(`delete .knarr/ directory`,`remove postinstall hook`);let n=await t.prompt(`Reset Knarr? This will ${e.join(`, `)}.`,{type:`confirm`});if(!n||typeof n==`symbol`){t.info(`Cancelled`);return}}d(`[reset] Removing ${b.length} linked package(s) from ${_}`);let x=0;for(let[e,n]of b)try{await r(_,e,n),x++}catch(n){t.warn(`Failed to remove ${e}: ${n instanceof Error?n.message:String(n)}`)}await a(v),t.success(`Removed .knarr/ directory`);let S=m(_,`package.json`);await i(S)&&await o(S)&&t.success(`Removed postinstall hook from package.json`),t.success(`Reset complete: ${x} package(s) restored in ${g.elapsed()}`),u({reset:!0,removed:x,elapsed:g.elapsedMs()}),f()&&p()}});export{g as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{p as n}from"./fs-DusqxRQR.mjs";import{n as r,s as i}from"./tracker-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{p as n}from"./fs-DusqxRQR.mjs";import{n as r,s as i}from"./tracker-BUpkmn8j.mjs";import{n as a}from"./store-D2r3Vo5S.mjs";import{r as o}from"./injector-CwNZ9rDe.mjs";import{t as s}from"./timer-BZNWRS3O.mjs";import{n as c,t as l}from"./output-B7NC4xgj.mjs";import{i as u,n as d}from"./logger-Oo2Slehd.mjs";import{r as f}from"./dry-run-DPoN8bZo.mjs";import{t as p}from"./package-manager-DENvuHqT.mjs";import{d as m}from"./init-helpers-DfznkCwv.mjs";import{resolve as h}from"node:path";const g=n(4);var _=e({meta:{name:`restore`,description:`Re-inject all linked packages (use after npm install wipes overrides)`},args:{silent:{type:`boolean`,description:`Suppress output when no packages are linked (for postinstall scripts)`,default:!1}},async run({args:e}){c();let n=new s,_=h(`.`),v=await i(_),y=await p(_),b=y.resolve();b.nodeModulesCompatible||(t.error(b.incompatibilityReason),process.exit(1));let x=Object.entries(v.links);if(x.length===0){e.silent||t.info(`No linked packages in this project`),l({restored:0,failed:0});return}await m(_);let S=0,C=0,w=await Promise.all(x.map(([e,n])=>g(async()=>{let i=await a(e,n.version);if(!i)return t.warn(`Store entry missing for ${e}@${n.version}. Re-publish it.`),{packageName:e,success:!1};try{let t=y.resolve(n.packageManager).packageManager,a=await o(i,_,t);return await r(_,e,{...n,contentHash:i.meta.contentHash,buildId:i.meta.buildId??``,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),packageManager:t}),u(`[restore] ${e}@${n.version}: ${a.copied} files`),{packageName:e,success:!0,copied:a.copied}}catch(n){return t.error(`Failed to restore ${e}: ${n instanceof Error?n.message:String(n)}`),{packageName:e,success:!1}}}))),T=[];for(let e of w)e.success?(t.success(`Restored ${e.packageName} (${e.copied} files)`),S++):(C++,T.push(e.packageName));t.info(`Restore complete: ${S} restored, ${C} failed in ${n.elapsed()}`),l({restored:S,failed:C,failedPackages:T,elapsed:n.elapsedMs()}),d()&&f()}});export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{i as r,o as i,s as a}from"./history-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{i as r,o as i,s as a}from"./history-BNX-3W-p.mjs";import{n as o}from"./store-D2r3Vo5S.mjs";import{n as s}from"./push-engine-IoOaMeZe.mjs";import{t as c}from"./config-DEpSKyI8.mjs";import{n as l,t as u}from"./output-B7NC4xgj.mjs";import{t as d}from"./errors-DRugrv36.mjs";import{n as f}from"./logger-Oo2Slehd.mjs";import{r as p}from"./dry-run-DPoN8bZo.mjs";import{c as m,t as h}from"./json-b5d4W58a.mjs";import{resolve as g}from"node:path";function _(e){u({rolledBack:e.rolledBack??!1,buildId:e.buildId??null,pushed:e.pushed??!1,pushSummary:e.pushSummary??null,pushError:e.pushError??null})}var v=e({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:!1}},async run({args:e}){l();let u=g(`.`),v;try{v=h(await m(g(u,`package.json`)))}catch{d(`No package.json found in current directory`),process.exit(1)}v?.name&&v.version||(d(`package.json missing name or version field`),process.exit(1));let y=await r(v.name,v.version);if(y.length===0){n.info(`No build history available`),_({rolledBack:!1});return}let b;if(e[`build-id`]){if(b=e[`build-id`],!y.find(e=>e.buildId===b)){n.error(`Build ${b} not found in history`),n.info(`Available builds:`);for(let e of y)n.log(` ${t.cyan(e.buildId)} ${t.dim(e.publishedAt)}`);_({rolledBack:!1});return}}else{let[e]=y;if(!e)throw Error(`No build history available`);b=e.buildId}let x=y.find(e=>e.buildId===b);if(!x)throw Error(`Build ${b} is not in history`);if(!e.yes){let e=await n.prompt(`Restore build ${b} (published ${x.publishedAt})?`,{type:`confirm`});if(!e||typeof e==`symbol`){n.info(`Cancelled`),_({rolledBack:!1,buildId:b});return}}let S=await c(u),C=i(S.historyLimit);if(!await a(v.name,v.version,b,C)){n.error(`Failed to restore build ${b}`),_({rolledBack:!1,buildId:b});return}n.success(`Restored ${v.name}@${v.version} to build ${b}`);let w=null,T;try{let e=await o(v.name,v.version);e?(w=await s(e,{force:!0,emitOutput:!1}),w.failedConsumers>0&&(process.exitCode=1)):(T=`Store entry missing after rollback for ${v.name}@${v.version}`,n.warn(T),process.exitCode=1)}catch(e){T=e instanceof Error?e.message:String(e),n.warn(`Push after rollback failed: ${T}`),process.exitCode=1}_({rolledBack:!0,buildId:b,pushed:w?w.failedConsumers===0:!1,pushSummary:w,pushError:T}),f()&&p()}});export{v as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,p as i}from"./fs-DusqxRQR.mjs";import{s as a}from"./tracker-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t,t as n}from"./console-C8XtlRyM.mjs";import{c as r,p as i}from"./fs-DusqxRQR.mjs";import{s as a}from"./tracker-BUpkmn8j.mjs";import{n as o}from"./store-D2r3Vo5S.mjs";import{n as s,t as c}from"./output-B7NC4xgj.mjs";import{join as l,resolve as u}from"node:path";const d=i(4);var f=e({meta:{name:`status`,description:`Show status of linked packages with health checks`},async run(){s();let e=u(`.`),i=await a(e),f=Object.entries(i.links);if(f.length===0){n.info(`No linked packages in this project`),c({packages:[]});return}n.info(`Package status (${f.length} linked):\n`);let p=await Promise.all(f.map(([t,n])=>d(async()=>{let i=[],a=await o(t,n.version);a?a.meta.contentHash!==n.contentHash&&i.push(`store has newer content (run knarr update)`):i.push(`store entry missing`);let s=l(e,`node_modules`,t);return await r(s)||i.push(`missing from node_modules (run knarr restore)`),await r(n.sourcePath)||i.push(`source directory missing: ${n.sourcePath}`),{name:t,version:n.version,buildId:n.buildId??``,issues:i,linkedAt:n.linkedAt,sourcePath:n.sourcePath}})));for(let e of p){let r=e.issues.length===0?t.green(`OK`):t.yellow(`!`),i=e.buildId?`[${e.buildId}]`:`[--------]`;n.log(` ${r} ${t.cyan(e.name)} ${t.dim(`@`+e.version)} ${t.dim(i)}`),n.log(` ${t.dim(`linked ${new Date(e.linkedAt).toLocaleString()} from ${e.sourcePath}`)}`);for(let r of e.issues)n.log(` ${t.yellow(`!`)} ${r}`)}c({packages:p.map(({name:e,version:t,buildId:n,issues:r})=>({name:e,version:t,buildId:n||null,healthy:r.length===0,issues:r}))})}});export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{c as t,d as n,f as r,t as i,u as a}from"./paths-V3_BeE_z.mjs";import{c as o,f as s,u as c}from"./fs-DusqxRQR.mjs";import{i as l,t as u}from"./validators-C0_prNkT.mjs";import{o as d}from"./json-b5d4W58a.mjs";import{readFile as f,readdir as p}from"node:fs/promises";async function m(t,n){let r=a(t,n);try{let i=await f(r,`utf-8`),a=d(i);return u(a)?a:(e.warn(`Invalid metadata for ${t}@${n}, ignoring`),null)}catch(r){return c(r)&&r.code!==`ENOENT`&&e.warn(`Failed to read metadata for ${t}@${n}: ${r instanceof Error?r.message:String(r)}`),null}}async function h(e,t){let r=n(e,t),i=await m(e,t);return!i||!await o(r)?null:{name:e,version:t,packageDir:r,meta:i}}async function g(e){let t=(await x()).filter(t=>t.name===e);return t.length===0?null:t.reduce((e,t)=>new Date(t.meta.publishedAt).getTime()>new Date(e.meta.publishedAt).getTime()?t:e)}const _=/\.(?:tmp-\d+|old)-(\d{13})$/;function v(e,t){return`${e}.${t===`tmp`?`tmp-${process.pid}`:`old`}-${Date.now()}`}function y(e){let t=_.exec(e)?.[1];return t===void 0?null:Number(t)}function b(e){if(y(e)!==null)return null;let t=e.lastIndexOf(`@`);if(t<=0)return null;let n=i(e.slice(0,t)),r=e.slice(t+1);try{l(n,r)}catch{return null}return{name:n,version:r}}async function x(){let e=r();if(!await o(e))return[];let t=await p(e,{withFileTypes:!0});return(await Promise.all(t.map(async e=>{let t=e.isDirectory()?b(e.name):null;if(!t)return null;let{name:r,version:i}=t,a=await m(r,i);return a?{name:r,version:i,packageDir:n(r,i),meta:a}:null}))).filter(e=>e!==null)}async function S(e,n){await s(t(e,n))}export{y as a,v as i,h as n,m as o,x as r,S as s,g as t};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{t as e}from"./fs-DusqxRQR.mjs";import{p as t}from"./paths-
|
|
1
|
+
import{t as e}from"./fs-DusqxRQR.mjs";import{p as t}from"./paths-V3_BeE_z.mjs";import{readFile as n,readdir as r}from"node:fs/promises";import{dirname as i,join as a,relative as o}from"node:path";const s=/* @__PURE__ */ new Set([`node_modules`,`.knarr`,`dist`,`.git`]);async function c(e){let i;try{i=await r(e,{recursive:!0,encoding:`utf-8`})}catch{return null}let o=i.filter(e=>e.endsWith(`.css`)?!t(e).split(`/`).some(e=>s.has(e)):!1).map(t=>a(e,t));for(let e of o){let t;try{t=await n(e,`utf-8`)}catch{continue}if(t.includes(`@import "tailwindcss"`)||t.includes(`@import 'tailwindcss'`))return e}return null}async function l(t,r,i){let a;try{a=await n(t,`utf-8`)}catch{return{modified:!1,error:`could not read CSS file`}}if(a.includes(`node_modules/${r}`))return{modified:!1};let o=d(t,r,i),s=/^@(import|source|plugin|theme)\s.+$/gm,c=null,l;for(;(l=s.exec(a))!==null;)c=l;let u=`@source "${o}";`;if(c){let e=c.index+c[0].length;a=a.slice(0,e)+`
|
|
2
2
|
`+u+a.slice(e)}else a=u+`
|
|
3
3
|
`+a;return await e(t,a),{modified:!0}}async function u(t,r){let i;try{i=await n(t,`utf-8`)}catch{return{modified:!1}}let a=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),o=RegExp(`^@source\\s+["'][^"']*node_modules/${a}["'];?\\s*\\n?`,`m`);return o.test(i)?(i=i.replace(o,``),await e(t,i),{modified:!0}):{modified:!1}}function d(e,n,r){let s=i(e),c=a(r,`node_modules`,n);return t(o(s,c))}export{l as addTailwindSource,c as findTailwindCss,u as removeTailwindSource};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{a as t,i as n,p as r,r as i}from"./paths-V3_BeE_z.mjs";import{c as a,o,s,t as c,u as l}from"./fs-DusqxRQR.mjs";import{n as u}from"./logger-Oo2Slehd.mjs";import{i as d}from"./dry-run-DPoN8bZo.mjs";import{n as f,r as p}from"./validators-C0_prNkT.mjs";import{a as m,o as h}from"./json-b5d4W58a.mjs";import{mkdir as g,readFile as _,rm as v,stat as y}from"node:fs/promises";import{dirname as b}from"node:path";import{setTimeout as x}from"node:timers/promises";const S={retries:5,minTimeout:100,maxTimeout:1e3,factor:2,stale:3e4};async function C(e,t,n){if(u())return d({type:`lock-skip`,path:e}),t();await g(b(e),{recursive:!0});let r=e+`.lk`,i=n?.stale??S.stale,a=!1;for(let e=0;e<=S.retries;e++)try{await g(r),a=!0;break}catch(t){if(l(t)&&t.code===`EEXIST`){try{let e=await y(r);if(Date.now()-e.mtimeMs>i){await v(r,{recursive:!0,force:!0});continue}}catch{continue}if(e<S.retries){let t=Math.min(S.minTimeout*S.factor**e,S.maxTimeout);await x(t)}}else throw t}if(!a)throw Error(`Failed to acquire lock after ${S.retries} attempts. Another Knarr process may be running. If this persists, delete ${r} and retry.`);try{return await t()}finally{await v(r,{recursive:!0,force:!0})}}async function w(e){let{state:t}=await T(e);return t}async function T(t){let r=n(t);try{let t=await _(r,`utf-8`),n=f(h(t));return n?{state:n,reliable:!0}:(e.warn(`Invalid consumer state in ${r}, using defaults`),{state:{version:`1`,links:m()},reliable:!1})}catch(t){return l(t)&&t.code===`ENOENT`?{state:{version:`1`,links:m()},reliable:!0}:(e.warn(`Failed to read consumer state: ${t instanceof Error?t.message:String(t)}`),{state:{version:`1`,links:m()},reliable:!1})}}async function E(e,t){await o(i(e));let r=n(e);await c(r,JSON.stringify(t,null,2))}async function D(e,t){let r=n(e);await C(r,async()=>{let{state:n,reliable:i}=await T(e);if(!i)throw Error(`Consumer state in ${r} is corrupt — refusing to write to avoid destroying existing links. Delete .knarr/state.json and re-run 'knarr add' for each package.`);let o=JSON.stringify(n);t(n),JSON.stringify(n)===o&&await a(r)||await E(e,n)})}async function O(e,t,n){await D(e,e=>{e.links[t]=n})}async function k(e,t){await D(e,e=>{delete e.links[t]})}async function A(e,t){return(await w(e)).links[t]??null}async function j(){let n=t();try{let t=p(h(await _(n,`utf-8`)));return t?{registry:t,reliable:!0}:(e.warn(`Invalid consumers registry in ${n}, using empty registry`),{registry:m(),reliable:!1})}catch(t){return l(t)&&t.code===`ENOENT`?{registry:m(),reliable:!0}:(e.warn(`Failed to read consumers registry: ${t instanceof Error?t.message:String(t)}`),{registry:m(),reliable:!1})}}async function M(){return(await j()).registry}function N(){return`Fix or delete ${t()}, then re-run 'knarr add' in each consumer project.`}var P=class extends Error{constructor(){super(`Consumers registry ${t()} is corrupt; refusing to overwrite it. ${N()}`),this.name=`CorruptRegistryError`}};function F(n){if(!(n instanceof P))throw n;e.warn(`Consumers registry ${t()} is corrupt, so it was left unchanged. ${N()}`)}async function I(){let{registry:e,reliable:t}=await j();if(!t)throw new P;return e}async function L(e){let n=t();await s(b(t())),await c(n,JSON.stringify(e,null,2))}async function R(e,n){await C(t(),async()=>{let t=await I();t[e]||(t[e]=[]);let i=r(n);t[e].includes(i)||t[e].push(i),await L(t)})}async function z(e,n){await C(t(),async()=>{let t=await I();if(!t[e])return;let i=r(n);t[e]=t[e].filter(e=>e!==i),t[e].length===0&&delete t[e],await L(t)})}async function B(e){return(await M())[e]??[]}async function V(e={}){let n=t(),r=0,i=0,o=0,s=0;return await C(n,async()=>{let t=await I(),n=m();for(let[c,l]of Object.entries(t)){let t=await Promise.all(l.map(async t=>{if(!await a(t))return{consumerPath:t,valid:!1,reason:`missing-dir`};if(e.removeMissingLinks){let{state:e,reliable:n}=await T(t);if(!n)return s++,{consumerPath:t,valid:!0,reason:`unreliable-state`};if(!e.links[c])return{consumerPath:t,valid:!1,reason:`missing-link`}}return{consumerPath:t,valid:!0,reason:null}})),u=t.filter(e=>e.valid).map(e=>e.consumerPath);r+=l.length-u.length,o+=t.filter(e=>e.reason===`missing-link`).length,u.length>0?n[c]=u:i++}await L(n)}),{removedConsumers:r,removedPackages:i,removedMissingLinks:o,skippedUnreliableConsumers:s}}export{B as a,T as c,R as d,k as f,C as g,F as h,N as i,M as l,D as m,O as n,A as o,z as p,V as r,w as s,P as t,j as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{c as readConsumerStateSafe}from"./tracker-BUpkmn8j.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{p as n}from"./fs-DusqxRQR.mjs";import{n as r,s as i}from"./tracker-BUpkmn8j.mjs";import{t as a}from"./store-D2r3Vo5S.mjs";import{r as o}from"./injector-CwNZ9rDe.mjs";import{t as s}from"./timer-BZNWRS3O.mjs";import{n as c,t as l}from"./output-B7NC4xgj.mjs";import{t as u}from"./errors-DRugrv36.mjs";import{i as d}from"./logger-Oo2Slehd.mjs";import{s as f}from"./validators-C0_prNkT.mjs";import{t as p}from"./package-manager-DENvuHqT.mjs";import{resolve as m}from"node:path";const h=n(4);var g=e({meta:{name:`update`,description:`Pull latest versions from the store for linked packages`},args:{package:{type:`positional`,description:`Package name to update (default: all linked)`,required:!1}},async run({args:e}){c();let n=new s,g=m(`.`),_=await i(g),v=await p(g),y=v.resolve();y.nodeModulesCompatible||(t.error(y.incompatibilityReason),process.exit(1));let b=Object.entries(_.links);if(b.length===0){t.info(`No linked packages in this project`),l({updated:0,skipped:0});return}let x=e.package?b.filter(([t])=>t===e.package):b;e.package&&x.length===0&&(u(`Package "${e.package}" is not linked in this project. Run 'knarr list' to see linked packages.`),process.exit(1));let S=0,C=0,w=0,T=0,E=await Promise.all(x.map(([e,n])=>h(async()=>{let i=await a(e);if(!i)return t.warn(`Store entry missing for ${e}. Re-publish it.`),`missing`;let s=v.resolve(n.packageManager).packageManager,c=s!==n.packageManager;if(i.meta.contentHash===n.contentHash&&!c)return d(`[update] ${e}@${i.version} already up to date`),`skipped`;try{let a=await o(i,g,s),c={...n,version:i.version,contentHash:i.meta.contentHash,buildId:i.meta.buildId??``,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),packageManager:s};return await r(g,e,c),await f(g,e,i.version),t.success(`Updated ${e}@${i.version} (${a.copied} files changed)`),`updated`}catch(n){return t.warn(`Failed to update ${e}: ${n instanceof Error?n.message:String(n)}`),`failed`}})));for(let e of E)e===`updated`?S++:e===`skipped`?C++:e===`missing`?w++:T++;let D=[`${S} updated`,`${C} unchanged`];w>0&&D.push(`${w} missing`),T>0&&D.push(`${T} failed`),t.info(`Update complete: ${D.join(`, `)} in ${n.elapsed()}`),l({updated:S,skipped:C,missing:w,failed:T,elapsed:n.elapsedMs()})}});export{g as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./timer-BZNWRS3O.mjs";import{n}from"./output-B7NC4xgj.mjs";import{n as r,t as i}from"./add-flow-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./timer-BZNWRS3O.mjs";import{n}from"./output-B7NC4xgj.mjs";import{n as r,t as i}from"./add-flow-D9HxSmKS.mjs";import{resolve as a}from"node:path";var o=e({meta:{name:`use`,description:`Publish a local package path and link it into this project`},args:{path:{type:`positional`,description:`Path to the local package source`,required:!0},build:{type:`string`,description:`Build command to run before publishing`},"skip-build":{type:`boolean`,description:`Skip build detection before publishing`,default:!1},yes:{type:`boolean`,alias:`y`,description:`Auto-accept prompts (install missing deps, etc.)`,default:!1}},async run({args:e}){n();let o=new t,s=a(e.path),c=await r(s);await i({packageArg:c,from:s,build:e.build,skipBuild:e[`skip-build`],yes:e.yes,timer:o})}});export{o as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{a as t,s as n,u as r}from"./json-b5d4W58a.mjs";import{readFile as i}from"node:fs/promises";import{join as a}from"node:path";const o=/^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/,s=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/,c=/[\x00-\x1F\x7F]/;function l(e){if(!e||e.length>214||c.test(e)||e.includes(`\\`)||e.includes(`//`)||e.split(`/`).some(e=>e===`.`||e===`..`)||!o.test(e))throw Error(`Invalid package name "${e}"`)}function u(e){if(!e||c.test(e)||e.includes(`/`)||e.includes(`\\`)||e.includes(`..`)||!s.test(e))throw Error(`Invalid package version "${e}"`)}function d(e,t){l(e),u(t)}function f(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.contentHash==`string`&&typeof t.publishedAt==`string`&&typeof t.sourcePath==`string`&&(t.buildId===void 0||typeof t.buildId==`string`)&&(t.schemaVersion===void 0||typeof t.schemaVersion==`number`)}function p(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.version==`string`&&typeof t.contentHash==`string`&&typeof t.linkedAt==`string`&&typeof t.sourcePath==`string`&&typeof t.backupExists==`boolean`&&typeof t.packageManager==`string`&&[`npm`,`pnpm`,`yarn`,`bun`].includes(t.packageManager)&&(t.buildId===void 0||typeof t.buildId==`string`)}function m(e){if(typeof e!=`object`||!e)return null;let n=e;if(n.version!==`1`||typeof n.links!=`object`||n.links===null)return null;let r=t();for(let[e,t]of Object.entries(n.links)){if(!p(t))return null;r[e]=t}return{...n,links:r}}async function h(t,o,s){try{let c=await i(a(t,`package.json`),`utf-8`),l=n(c,`package.json`),u=r(l,`dependencies`)[o]??r(l,`devDependencies`)[o]??r(l,`peerDependencies`)[o];if(!u||/^(workspace:|catalog:|\*)/.test(u))return;let d=u.match(/(\d+)\.\d+\.\d+/);if(!d?.[1])return;parseInt(d[1],10)!==parseInt(s.split(`.`)[0]??``,10)&&e.warn(`Version mismatch: store has ${o}@${s} but your package.json declares "${u}". Consider updating your dependency range.`)}catch{}}function g(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let n=t();for(let[t,r]of Object.entries(e)){if(!Array.isArray(r)||!r.every(e=>typeof e==`string`))return null;n[t]=r}return n}export{l as a,d as i,m as n,u as o,g as r,h as s,f as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{t as e}from"./fs-DusqxRQR.mjs";import{readFile as t}from"node:fs/promises";function n(e){return e.match(/^(\
|
|
1
|
+
import{t as e}from"./fs-DusqxRQR.mjs";import{readFile as t}from"node:fs/promises";function n(e){return e.match(/^([ \t]+)\S/m)?.[1]||` `}function r(e){return e.includes(`knarr/vite`)||e.includes(`vite-plugin-knarr`)}async function i(e){try{return{configured:r(await t(e,`utf-8`))}}catch{return{configured:!1,error:`could not read config file`}}}function a(e){let t=/(^|[^A-Za-z0-9_$])defineConfig\s*\(/g,n;for(;(n=t.exec(e))!==null;){let r=n.index+n[0].length-1,i=1,a=r+1,o=!1,s=!1;for(;a<e.length&&i>0;){let t=e[a];if(s)s=!1,a++;else if(t===`\\`)s=!0,a++;else if(o)t===o&&(o=!1),a++;else if(t===`"`||t===`'`||t==="`")o=t,a++;else if(t===`/`&&e[a+1]===`/`){let t=e.indexOf(`
|
|
2
2
|
`,a);a=t===-1?e.length:t+1}else if(t===`/`&&e[a+1]===`*`){let t=e.indexOf(`*/`,a+2);a=t===-1?e.length:t+2}else{if(t===`?`){let t=e[a+1];if(t===`.`||t===`?`){a+=2;continue}return!0}t===`(`&&i++,t===`)`&&i--,a++}}t.lastIndex=a}return!1}function o(e){let t=[],n=``,r=0;for(let i of e)if(i===`(`&&r++,i===`)`&&r--,i===`,`&&r===0){let e=n.trim();e&&t.push(e),n=``}else n+=i;let i=n.trim();return i&&t.push(i),t}function s(e,t){return e.length===0?`[]`:e.length===1?`[${e[0]}]`:`[\n${e.map(e=>`${t}${t}${e},`).join(`
|
|
3
3
|
`)}\n${t}]`}function c(e){let t=/plugins\s*:\s*\[/g.exec(e);if(!t)return null;let n=t.index+t[0].length-1,r=1,i=n+1,a=!1,o=!1;for(;i<e.length&&r>0;){let t=e[i];if(o)o=!1,i++;else if(t===`\\`)o=!0,i++;else if(a)t===a&&(a=!1),i++;else if(t===`"`||t===`'`||t==="`")a=t,i++;else if(t===`/`&&e[i+1]===`/`){let t=e.indexOf(`
|
|
4
4
|
`,i);i=t===-1?e.length:t+1}else if(t===`/`&&e[i+1]===`*`){let t=e.indexOf(`*/`,i+2);i=t===-1?e.length:t+2}else(t===`[`||t===`(`||t===`{`)&&r++,(t===`]`||t===`)`||t===`}`)&&r--,i++}return r===0?{start:n,end:i,inner:e.slice(n+1,i-1)}:null}function l(e){let t=0,n=/^import\s/gm,r;for(;(r=n.exec(e))!==null;){let n=r.index,i=n+r[0].length,a=!1,o=0;for(;i<e.length;){let t=e[i];if(a)t===a&&(a=!1),i++;else if(t===`"`||t===`'`||t==="`")a=t,i++;else{if(t===`{`&&o++,t===`}`&&o--,t===`;`&&o<=0){i++;break}if(t===`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as addKnarrVitePlugin,n as hasKnarrVitePlugin,i as removeFromViteConfig}from"./vite-config-
|
|
1
|
+
export{t as addKnarrVitePlugin,n as hasKnarrVitePlugin,i as removeFromViteConfig}from"./vite-config-Bvv75_oH.mjs";
|
package/dist/vite-plugin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,s as t}from"./json-
|
|
1
|
+
import{i as e,s as t}from"./json-b5d4W58a.mjs";import{a as n}from"./validators-C0_prNkT.mjs";import{dirname as r,extname as i,join as a,normalize as o}from"node:path";import{existsSync as s,readFileSync as c,realpathSync as l}from"node:fs";function u(n){try{let r=c(n,`utf-8`),i=e(t(r,n),`links`);return i?Object.keys(i):[]}catch{return[]}}function d(e){try{return t(c(a(e,`package.json`),`utf-8`),e)}catch{return}}function f(e,t){let n=e;for(;;){let e=a(n,`node_modules`,t);if(s(a(e,`package.json`)))return e;let i=r(n);if(i===n)return;n=i}}const p=[`import`,`module`,`browser`,`default`,`require`],m=/* @__PURE__ */ new Set([`.js`,`.mjs`,`.cjs`,`.jsx`]);function h(e){if(typeof e==`string`)return e;if(typeof e!=`object`||!e||Array.isArray(e))return;let t=e;for(let e of p){let n=h(t[e]);if(n)return n}}function g(e){let t=e.exports;if(t!==void 0)return h(typeof t==`object`&&t&&!Array.isArray(t)&&Object.keys(t).some(e=>e.startsWith(`.`))?t[`.`]:t);for(let t of[`module`,`main`]){let n=e[t];if(typeof n==`string`)return n}return`index.js`}function _(e,t){let n=g(t);if(!n)return!1;let r=i(n),o=a(e,n);return r===``?s(`${o}.js`)||s(a(o,`index.js`)):m.has(r)&&s(o)}function v(t,r){let i=new Set(r),o=[];for(let s of r){let r;try{r=l(a(t,s))}catch{continue}let c=e(d(r)??{},`dependencies`);for(let e of Object.keys(c??{})){if(i.has(e))continue;try{n(e)}catch{continue}let t=f(r,e),a=t&&d(t);t&&a&&_(t,a)&&o.push(`${s} > ${e}`)}}return o}function y(e={}){let t=e.verbose??process.env.KNARR_VERBOSE===`1`,n=e=>{t&&console.log(e)},r,i,s;return{name:`vite-plugin-knarr`,apply:`serve`,config(e,{command:t}){if(t!==`serve`)return;let r=e.root??process.cwd(),i=u(a(r,`.knarr`,`state.json`)),o={};if(i.length>0){let t=e.optimizeDeps?.exclude??[],s=[...t,...i.filter(e=>!t.includes(e))];console.log(`[knarr] Excluding from pre-bundling: ${s.join(`, `)}`);let c=e.optimizeDeps?.include??[],l=v(a(r,`node_modules`),i).filter(e=>!c.includes(e));n(`[knarr] Pre-bundling dependencies of linked packages: ${l.join(`, `)||`none`}`),o.optimizeDeps={exclude:s,include:l}}if(process.versions?.webcontainer&&!e.server?.watch?.usePolling&&(o.server={watch:{usePolling:!0,interval:1e3}},console.log(`[knarr] WebContainer detected, enabling filesystem polling`)),Object.keys(o).length!==0)return o},configResolved(e){i=a(e.root,`node_modules`),r=o(a(e.root,`.knarr`,`state.json`)),n(`[knarr] Watching state file: ${r}`)},configureServer(e){let t=/* @__PURE__ */ new Set,l=!1,d=!1,f=null,p=null;function m(){let o=!1;for(let e of u(r))t.has(e)||(t.add(e),o=!0);if(o&&t.size>0){let r=[...t].sort((e,t)=>t.length-e.length).map(e=>e.replace(/[/\\.*+?^${}()|[\]]/g,`\\$&`)).join(`|`);e.watcher.options={...e.watcher.options,ignored:[RegExp(`node_modules\\/(?!(?:${r})(?:\\/|$)).*`),/[/\\]\.git[/\\]/,/[/\\]test-results[/\\]/]},e.watcher._userIgnored=void 0;for(let r of t){let t=a(i,r);e.watcher.add(t),n(`[knarr] Added watcher for package: ${t}`)}}}async function h(t){if(l)d=!0,n(`[knarr] Restart already in progress, queued: ${t}`);else{l=!0,m(),console.log(`[knarr] ${t}, restarting server...`);try{await e.restart()}catch(e){console.error(`[knarr] Dev server restart failed: ${e instanceof Error?e.message:String(e)}`)}finally{l=!1,d&&(d=!1,await h(`Queued change detected`))}}}function g(e){f||=setTimeout(()=>{f=null,h(e)},1500)}function _(){p&&clearTimeout(p),p=setTimeout(()=>{p=null,console.log(`[knarr] Linked package updated, reloading`),e.hot.send({type:`full-reload`,path:`*`})},200)}function v(t){let n=o(t),r=e.moduleGraph.getModulesByFile(n);r&&r.forEach(t=>e.moduleGraph.invalidateModule(t)),_()}function y(){for(let[n,r]of e.moduleGraph.urlToModuleMap)for(let i of t)if(n.includes(i)){e.moduleGraph.invalidateModule(r);break}_()}if(e.watcher.add(r),n(`[knarr] Added watcher for: ${r}`),m(),e.watcher.on(`change`,e=>{let n=o(e);n===r?u(r).some(e=>!t.has(e))?g(`New package linked`):y():[...t].some(e=>n.includes(o(a(i,e))))&&v(e)}),e.watcher.on(`add`,e=>{let n=o(e);[...t].some(e=>n.includes(o(a(i,e))))&&v(e)}),process.versions?.webcontainer){s&&clearInterval(s);let e=``;try{e=c(r,`utf-8`)}catch{}s=setInterval(()=>{try{let n=c(r,`utf-8`);e&&n!==e&&(e=n,u(r).some(e=>!t.has(e))?g(`New package linked (polling fallback)`):y()),e||=n}catch{}},1e3),console.log(`[knarr] WebContainer polling fallback active (1s interval)`)}e.httpServer?.on(`close`,()=>{s&&=(clearInterval(s),void 0),f&&=(clearTimeout(f),null),p&&=(clearTimeout(p),null)})}}}export{y as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as WatchOrchestrator}from"./watch-orchestrator-B1hlJ10Y.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./console-C8XtlRyM.mjs";import{i as t}from"./logger-Oo2Slehd.mjs";import{t as n}from"./config-
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{i as t}from"./logger-Oo2Slehd.mjs";import{t as n}from"./config-DEpSKyI8.mjs";import{r,t as i}from"./push-engine-IoOaMeZe.mjs";var a=class{packages=/* @__PURE__ */ new Map;dependents=/* @__PURE__ */ new Map;cascade;pushOptions={};constructor(e){this.cascade=e}async start(t,a,s){this.pushOptions=s;let{buildWorkspaceGraph:c,buildReverseAdjacency:l,filterPublishableWorkspaceGraph:u}=await import(`./workspace-CYaUDFd5.mjs`),{topoSort:d,CycleError:f}=await import(`./topo-sort-CNCKE3Ap.mjs`),{startWatcher:p}=await import(`./watcher-LcNLwOgA.mjs`),m=await c(t),h=u(m);if(h.packages.length===0){e.warn(`No publishable workspace packages found`);return}let g=m.packages.length-h.packages.length;g>0&&e.info(`Skipping ${g} private workspace package(s)`);let _;try{_=d(h.adjacency)}catch(t){if(t instanceof f){e.error(`Cannot watch: ${t.message}`);return}throw t}this.cascade&&(this.dependents=l(h.adjacency),e.info(`Cascade mode enabled`));let v=new Map(h.packages.map(e=>[e.name,e.dir]));for(let e of _){let t=v.get(e);if(!t)continue;let c=await n(t),{buildCmd:l,patterns:u}=await r(t,a,c),d=a.notify??c.notify??!1,f=async()=>{await this.runExclusive(e,async()=>{o(await i(t,s),e),await this.onPackagePushed(e)})},m=e=>{if(!e)return;let t=parseInt(e,10);return Number.isFinite(t)?t:void 0},h={dir:t,buildCmd:l,state:`idle`,watcher:{close:async()=>{}}};this.packages.set(e,h),h.watcher=await p(t,{patterns:u,buildCmd:l,debounce:m(a.debounce)??c.debounce,cooldown:m(a.cooldown)??c.cooldown,notify:d,label:e},f)}e.info(`Watching ${this.packages.size} workspace packages`),await new Promise(t=>{let n=()=>{e.info(`Stopping watchers...`),this.close().catch(t=>{e.warn(`Watchers did not close cleanly: ${t instanceof Error?t.message:String(t)}`)}).finally(t)};process.once(`SIGINT`,n),process.once(`SIGTERM`,n)})}async onPackagePushed(t){if(!this.cascade)return;let n=this.dependents.get(t);if(n&&n.size!==0){e.info(`${t} changed, rebuilding dependents: ${[...n].join(`, `)}`);for(let e of n)await this.requestRebuild(e)}}async runExclusive(e,n){let r=this.packages.get(e);if(r){if(r.state===`queued`)t(`[cascade] ${e} already queued, skipping`);else if(r.state===`building`)t(`[cascade] ${e} is building, marking as queued`),r.state=`queued`;else{r.state=`building`;try{await n(r)}finally{let t=r.state===`queued`;r.state=`idle`,t&&await this.requestRebuild(e)}}}}async requestRebuild(n){await this.runExclusive(n,async r=>{if(t(`[cascade] Rebuilding ${n}`),r.buildCmd){let{runBuildCommand:t}=await import(`./watcher-LcNLwOgA.mjs`);if(!await t(r.buildCmd,r.dir,n)){e.warn(`[cascade] Build failed for ${n}, skipping dependents`);return}}o(await i(r.dir,this.pushOptions),n),await this.onPackagePushed(n)}).catch(t=>{e.warn(`[cascade] Push failed for ${n}: ${t instanceof Error?t.message:String(t)}`)})}async close(){await Promise.all([...this.packages.values()].map(e=>e.watcher.close())),this.packages.clear()}};function o(e,t){if(e.failedConsumers!==0)throw Error(`Push for ${t} failed for ${e.failedConsumers} consumer(s)`)}export{a as t};
|
package/dist/webpack-plugin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as e,s as t}from"./json-
|
|
1
|
+
import{i as e,s as t}from"./json-b5d4W58a.mjs";import{join as n,normalize as r}from"node:path";import{readFileSync as i}from"node:fs";function a(n){try{let r=i(n,`utf-8`),a=e(t(r,n),`links`);return a?Object.keys(a):[]}catch{return[]}}var o=class{options;constructor(e={}){this.options=e}apply(e){let t=this.options.root??e.options.context??process.cwd(),o=r(n(t,`.knarr`,`state.json`)),s=n(t,`node_modules`),c=null,l,u=null,d=``,f=/* @__PURE__ */ new Set,p=()=>{u&&clearTimeout(u),u=setTimeout(()=>{u=null,e.watching&&e.watching.invalidate()},200)},m=()=>{let e=!1;for(let t of a(o))f.has(t)||(f.add(t),e=!0);return e};e.hooks.afterEnvironment.tap(`KnarrWebpackPlugin`,()=>{if(m(),f.size===0)return;let t=e.options.snapshot??={},n=t.managedPaths??=[],r=[...f].sort((e,t)=>t.length-e.length).map(e=>e.replace(/[/\\.*+?^${}()|[\]]/g,`\\$&`)).join(`|`),i=RegExp(`node_modules[\\\\/](?!(?:${r})(?:[\\\\/]|$))`),a=n.filter(e=>typeof e==`string`?!e.includes(`node_modules`):!e.source?.includes(`node_modules`));a.push(i),t.managedPaths=a}),e.hooks.watchRun.tapPromise(`KnarrWebpackPlugin`,async()=>{if(c)return;let e=!!process.versions?.webcontainer;if(e){try{d=i(o,`utf-8`)}catch{}l=setInterval(()=>{try{let e=i(o,`utf-8`);d&&e!==d&&(d=e,m(),p()),d||=e}catch{}},1e3)}let{watch:t}=await import(`./chokidar-DoHpObCq.mjs`),a=[o];for(let e of f)a.push(n(s,e));let u=t(a,{ignoreInitial:!0,ignored:[/[/\\]\.git[/\\]/],backend:e?`polling`:`auto`,...e&&{pollingInterval:1e3}}),h=!1;u.on(`change`,e=>{if(r(e)===o&&m()&&!h)for(let e of f)u.add(n(s,e));p()}),u.on(`add`,()=>p()),u.on(`unlink`,()=>p()),c={close:()=>(h=!0,u.close())}}),e.hooks.afterCompile.tapPromise(`KnarrWebpackPlugin`,e=>{for(let t of f)e.contextDependencies.add(n(s,t));return Promise.resolve()}),e.hooks.watchClose.tap(`KnarrWebpackPlugin`,()=>{u&&=(clearTimeout(u),null),l&&=(clearInterval(l),void 0),c&&=(c.close().catch(()=>{}),null)})}};export{o as KnarrWebpackPlugin,o as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,t}from"./picomatch-DEttMFSR.mjs";import{c as n}from"./fs-DusqxRQR.mjs";import{p as r}from"./paths-
|
|
1
|
+
import{n as e,t}from"./picomatch-DEttMFSR.mjs";import{c as n}from"./fs-DusqxRQR.mjs";import{p as r}from"./paths-V3_BeE_z.mjs";import{a as i,c as a,r as o,t as s}from"./json-b5d4W58a.mjs";import{readFile as c,readdir as l}from"node:fs/promises";import{dirname as u,join as d,relative as f,resolve as p}from"node:path";var m=/* @__PURE__ */ e(t(),1);async function h(e){let t=e;for(;;){if(await n(d(t,`pnpm-workspace.yaml`)))return t;let e=u(t);if(e===t)return null;t=e}}async function g(e){return await h(e)??await b(e)}async function _(e){let t={default:i(),named:i()},n=d(e,`pnpm-workspace.yaml`),r;try{r=await c(n,`utf-8`)}catch{return t}let a=r.split(/\r?\n/),o=`top`,s=``;for(let e of a){if(e.trim()===``||e.trim().startsWith(`#`))continue;let n=e.length-e.trimStart().length;if(n===0){if(e.startsWith(`catalog:`)){o=`default-catalog`;continue}if(e.startsWith(`catalogs:`)){o=`named-catalogs`;continue}o=`top`}else if(o===`default-catalog`&&n>=2){let n=E(e);n&&(t.default[n[0]]=n[1])}else if(o===`named-catalogs`&&n>=2&&n<4){let n=e.trim();n.endsWith(`:`)&&(s=n.slice(0,-1),t.named[s]=i(),o=`named-catalog-entries`)}else if(o===`named-catalog-entries`&&n>=4){let n=E(e),r=s?t.named[s]:void 0;n&&r&&(r[n[0]]=n[1])}else if(o===`named-catalog-entries`&&n>=2&&n<4){let n=e.trim();n.endsWith(`:`)?(s=n.slice(0,-1),t.named[s]=i()):o=`named-catalogs`}}return t}async function v(e){let t=await h(e);if(t){let e=await y(t),n=e.filter(e=>!e.startsWith(`!`)),r=e.filter(e=>e.startsWith(`!`)).map(e=>e.slice(1));if(n.length>0)return x(t,n,r)}let n=t??await b(e);if(!n)return[];try{let e=(await a(d(n,`package.json`))).workspaces,t=Array.isArray(e)?e:o(e)?e.packages:[],r=Array.isArray(t)?t.filter(e=>typeof e==`string`):[];return r.length===0?[]:x(n,r.filter(e=>!e.startsWith(`!`)),r.filter(e=>e.startsWith(`!`)).map(e=>e.slice(1)))}catch{return[]}}async function y(e){let t=d(e,`pnpm-workspace.yaml`),n;try{n=await c(t,`utf-8`)}catch{return[]}let r=[],i=!1;for(let e of n.split(/\r?\n/)){let t=e.trim();if(t===``||t.startsWith(`#`))continue;let n=e.length-e.trimStart().length;if(n===0)i=t===`packages:`;else if(i&&n>=2){let e=t.match(/^-\s+["']?([^"']+)["']?$/);e?.[1]&&r.push(e[1])}}return r}async function b(e){let t=e;for(;;){try{if((await a(d(t,`package.json`))).workspaces)return t}catch{}let e=u(t);if(e===t)return null;t=e}}async function x(e,t,i=[]){let a=[];for(let i of t)if(i.includes(`*`)){let t=i.split(`/`),o=e,s=[],c=!1;for(let e of t)c||e.includes(`*`)?(c=!0,s.push(e)):o=d(o,e);if(s.length===1&&s[0]===`*`)try{let e=await l(o,{withFileTypes:!0});for(let t of e)if(t.isDirectory()){let e=d(o,t.name);await n(d(e,`package.json`))&&a.push(e)}}catch{}else{let t=(0,m.default)(i),o=await S(e,8);for(let i of o)t(r(f(e,i)))&&await n(d(i,`package.json`))&&a.push(i)}}else{let t=p(e,i);await n(d(t,`package.json`))&&a.push(t)}let o=[...new Set(a)];if(i.length===0)return o;let s=(0,m.default)(i);return o.filter(t=>{let n=r(f(e,t));return!s(n)})}async function S(e,t){if(t<=0)return[];let n=[];try{let r=await l(e,{withFileTypes:!0});for(let i of r){if(!i.isDirectory()||i.name===`node_modules`||i.name===`.git`)continue;let r=d(e,i.name);n.push(r),n.push(...await S(r,t-1))}}catch{}return n}async function C(e){let t=await v(e),n=[];for(let e of t)try{let t=s(await a(d(e,`package.json`)));t?.name&&t.version&&n.push({name:t.name,version:t.version,dir:e,pkg:t})}catch{}let r=new Set(n.map(e=>e.name)),i=/* @__PURE__ */ new Map;for(let e of n){let t=/* @__PURE__ */ new Set;for(let n of[`dependencies`,`devDependencies`]){let i=e.pkg[n];if(i)for(let e of Object.keys(i))r.has(e)&&t.add(e)}i.set(e.name,t)}return{packages:n,adjacency:i}}function w(e){let t=e.packages.filter(e=>!e.pkg.private),n=new Set(t.map(e=>e.name)),r=/* @__PURE__ */ new Map;for(let i of t){let t=e.adjacency.get(i.name)??/* @__PURE__ */ new Set;r.set(i.name,new Set([...t].filter(e=>n.has(e))))}return{packages:t,adjacency:r}}function T(e){let t=/* @__PURE__ */ new Map;for(let n of e.keys())t.set(n,/* @__PURE__ */ new Set);for(let[n,r]of e)for(let e of r){let r=t.get(e);r||(r=/* @__PURE__ */ new Set,t.set(e,r)),r.add(n)}return t}function E(e){let t=e.trim(),n=t.indexOf(`:`);if(n<=0)return null;let r=t.slice(0,n).trim(),i=D(t.slice(n+1)).trim();return!r||!i?null:[r.replace(/^["']|["']$/g,``),i.replace(/^["']|["']$/g,``)]}function D(e){let t=null;for(let n=0;n<e.length;n++){let r=e[n];if((r===`"`||r===`'`)&&e[n-1]!==`\\`)t=t===r?null:t??r;else if(!t&&r===`#`&&(n===0||/\s/.test(e[n-1]??``)))return e.slice(0,n)}return e}export{v as a,g as i,C as n,h as o,w as r,_ as s,T as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{t as buildReverseAdjacency,n as buildWorkspaceGraph,r as filterPublishableWorkspaceGraph,i as findWorkspacePackageRoot,a as findWorkspacePackages,s as parseCatalogs}from"./workspace-
|
|
1
|
+
export{t as buildReverseAdjacency,n as buildWorkspaceGraph,r as filterPublishableWorkspaceGraph,i as findWorkspacePackageRoot,a as findWorkspacePackages,s as parseCatalogs}from"./workspace-BBfh7dJY.mjs";
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./shell-DQfdqK0J.mjs";import{t}from"./hints-BKo_2axg.mjs";import{t as n}from"./console-C8XtlRyM.mjs";import{n as r,t as i}from"./store-CAzxNmpU.mjs";import{t as a}from"./publisher-oHVy3LA2.mjs";import{i as o,n as s,r as c,t as l}from"./injector-BMOi1uN3.mjs";import{d as u,h as d,n as f,o as p}from"./tracker-nsfA6PWa.mjs";import{c as m}from"./fs-DusqxRQR.mjs";import{t as h}from"./package-manager-Cs9kCsjJ.mjs";import{t as g}from"./build-detect-Bo1fe8OV.mjs";import{n as _}from"./bundler-detect-BaShXORS.mjs";import{i as v,o as y}from"./init-helpers-DGSTVbNx.mjs";import{t as b}from"./nextjs-config-m83qz9Qp.mjs";import{b as x,i as S,v as C,y as w}from"./paths-B5sEvS_7.mjs";import{t as T}from"./timer-BZNWRS3O.mjs";import{t as E}from"./output-B7NC4xgj.mjs";import{t as D}from"./errors-DRugrv36.mjs";import{i as O,n as k,r as A}from"./logger-Oo2Slehd.mjs";import{i as j,r as M}from"./dry-run-DPoN8bZo.mjs";import{o as N}from"./json-1jsvqdBb.mjs";import{readFile as P}from"node:fs/promises";import{basename as F,join as I,resolve as L}from"node:path";async function R(e){let s=e.timer??new T,g=L(`.`),{name:_,version:b}=B(e.packageArg),C,O=null,A=!1,j=!1;if(V(_,e.packageArg),b)try{w(b)}catch{D(`Invalid package version "${b}" in "${e.packageArg}".`),process.exit(1)}let N=(await h(g)).resolve(),P=N.packageManager;if(N.nodeModulesCompatible||(n.error(N.incompatibilityReason),process.exit(1)),e.from){let t=L(e.from);C=t;let r=await H(t,{build:e.build,skipBuild:e.skipBuild,yes:e.yes??!1});O=r.buildCmd,A=r.ran,j=r.skipped,n.info(`Publishing from ${t}...`),await a(t)}let F=b?await r(_,b):await i(_);if(!F){let e=b?`@${b}`:``;D(`Package "${_}${e}" not found in store. Run 'knarr publish' in the package directory first, or use --from <path>.`),process.exit(1)}await m(S(g))||(await v(g,P),n.success(`Auto-initialized knarr (consumer mode)`)),n.info(`Detected package manager: ${P}`);let I=await p(g,_);I&&(I.version===F.version?n.info(`Updating ${_}@${F.version} (already linked)`):n.info(`Updating ${_}: ${I.version} -> ${F.version}`));let R=I?I.backupExists:await l(g,_,P);!I&&R&&n.info(`Backed up existing ${_} installation`),await x(g,_,F.version),await K(g,_,N),await G(F,g,N,e.yes??!1);let z=await c(F,g,P);n.success(`Linked ${_}@${F.version} -> node_modules/${_} (${z.copied} files copied, ${z.skipped} unchanged)`),z.binLinks>0&&n.info(`Created ${z.binLinks} bin link(s)`);let W={version:F.version,contentHash:F.meta.contentHash,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),sourcePath:F.meta.sourcePath,backupExists:R,packageManager:P,buildId:F.meta.buildId??``};await f(g,_,W),await u(_,g).catch(d),await y(g),await o(g,_)||n.info(`${_} isn't in package.json, so adding or removing other packages can prune it. Run \`knarr restore\` afterwards, or add it to dependencies.`);let q=C?[`cd ${C} && knarr dev`]:[];C&&n.info(`Next: ${t(C,process.cwd(),await U(C))}`),n.info(`Done in ${s.elapsed()}`);let J={package:_,version:F.version,copied:z.copied,skipped:z.skipped,binLinks:z.binLinks,elapsed:s.elapsedMs(),buildCmd:O,buildRan:A,buildSkipped:j,nextSteps:q};return e.emitOutput!==!1&&E(J),k()&&M(),J}async function z(e){let t=L(e);await m(t)||(D(`Source path not found: ${t}`),process.exit(1));let n=I(t,`package.json`);await m(n)||(D(`No package.json found at ${n}. Pass a package directory to 'knarr use'.`),process.exit(1));let r;try{r=N(await P(n,`utf-8`))}catch(e){D(`Could not read package.json at ${n}: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}r&&typeof r==`object`&&typeof r.name==`string`||(D(`package.json at ${n} must include a package name for 'knarr use'.`),process.exit(1));let i=r.name.trim();return V(i,i),i}function B(e){if(e.startsWith(`@`)){let t=e.indexOf(`/`);if(t>0){let n=e.indexOf(`@`,t);if(n>t)return{name:e.slice(0,n),version:e.slice(n+1)}}return{name:e,version:null}}let t=e.lastIndexOf(`@`);return t>0?{name:e.slice(0,t),version:e.slice(t+1)}:{name:e,version:null}}function V(e,t){try{C(e)}catch{D(`Invalid package name "${t}". Use format: package-name or @scope/package-name.`),process.exit(1)}}async function H(e,t){if(t.skipBuild)return t.build&&n.warn(`--skip-build was provided; ignoring --build`),{buildCmd:null,ran:!1,skipped:!0};let r=t.build,i=!!r;if(!r){let t=(await h(e)).resolve().packageManager;r=await g(e,t)??void 0}if(!r)return{buildCmd:null,ran:!1,skipped:!1};if(!i&&!t.yes&&!A()){let e=await n.prompt(`Run detected build command before publishing? (${r})`,{type:`confirm`,initial:!0});if(!e||typeof e==`symbol`)return n.info(`Skipping build before publish`),{buildCmd:r,ran:!1,skipped:!0}}else if(!i&&A()&&!t.yes)return O(`[add] Detected build command but skipping in json mode: ${r}`),{buildCmd:r,ran:!1,skipped:!0};return n.info(k()?`[dry-run] Would run build command: ${r}`:`Running build command: ${r}`),await q(r,e)||(D(`Build command failed: ${r}`),await W(e),process.exit(1)),{buildCmd:r,ran:!0,skipped:!1}}async function U(e){let{findWorkspacePackageRoot:t,findWorkspacePackages:n}=await import(`./workspace-CSQVbAw4.mjs`),r=await t(e);if(!r)return null;let i=await n(r),a=L(e);return i.some(e=>L(e)===a)?r:null}async function W(e){if(!await m(I(e,`node_modules`))){let t=(await h(e)).resolve().packageManager;n.info(`Suggestion: ${e} has no node_modules. Run \`${t} install\` there, then retry.`)}n.info(`Suggestion: if the package is already built, re-run with --skip-build.`)}async function G(e,t,r,i){let a=r.packageManager,o=await s(e,t,a);if(o.length!==0){if(A())O(`[add] Missing transitive deps (json mode): ${o.join(`, `)}`);else if(i){let e=r.installCommand(o),t=r.formatCommand(e);n.info(k()?`[dry-run] Would install missing dependencies: ${o.join(`, `)}`:`Installing missing dependencies: ${o.join(`, `)}`);let i=await r.run(e);i&&!k()?n.success(`Installed missing dependencies`):i||n.warn(`Install failed. Run manually: ${t}`)}else if(await n.prompt(`Install ${o.length} missing dependencies? (${o.join(`, `)})`,{type:`confirm`,initial:!0})){let e=r.installCommand(o),t=r.formatCommand(e),i=await r.run(e);i&&!k()?n.success(`Installed missing dependencies`):i||n.warn(`Install failed. Run manually: ${t}`)}else{let e=r.installCommand(o);n.warn(`Missing transitive dependencies: ${o.join(`, `)}\n Run: ${r.formatCommand(e)}`)}}}async function K(e,t,r){let i=await _(e);if(i.type===`next`&&i.configFile){let e=await b(i.configFile,t);e.modified?n.success(`Added ${t} to transpilePackages in ${F(i.configFile)}`):e.error&&n.info(`Add to next.config manually: transpilePackages: ['${t}']`)}else if(i.type===`vite`&&i.configFile){let{addKnarrVitePlugin:e}=await import(`./vite-config-B6bZDoGe.mjs`),t=await e(i.configFile);if(t.modified){n.success(`Added knarr plugin to ${F(i.configFile)}`);let e=r.installCommand([`knarr`],{dev:!0}),t=r.formatCommand(e);n.info(k()?`[dry-run] Would install knarr as devDependency`:`Installing knarr as devDependency...`);let a=await r.run(e);a&&!k()?n.success(`Installed knarr`):a||n.warn(`Install failed. Run manually: ${t}`)}else t.error&&n.info(`Add manually:
|
|
2
|
-
import knarr from "knarr/vite"
|
|
3
|
-
plugins: [knarr()]`)}let{findTailwindCss:a,addTailwindSource:o}=await import(`./tailwind-source-Ho_nKVtd.mjs`),s=await a(e);if(s){let r=await o(s,t,e);r.modified?n.success(`Added @source for ${t} to ${F(s)}`):r.error&&n.info(`Add to your CSS manually: @source "../node_modules/${t}";`)}}function q(t,n){return k()?(j({type:`command-skip`,path:n,detail:t}),Promise.resolve(!0)):new Promise(r=>{let i=e(t,{cwd:n,stdio:`inherit`});i.on(`close`,e=>r(e===0)),i.on(`error`,()=>r(!1))})}export{z as n,R as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{c as e,d as t,f as n,o as r,t as i}from"./fs-DusqxRQR.mjs";import{c as a,l as o,m as s,o as c}from"./paths-B5sEvS_7.mjs";import{i as l}from"./logger-Oo2Slehd.mjs";import{o as u}from"./json-1jsvqdBb.mjs";import{readFile as d,readdir as f}from"node:fs/promises";import{join as p}from"node:path";async function m(e){let t=u(await d(e,`utf-8`));if(!s(t))throw Error(`Invalid build metadata: ${e}`);return t}async function h(a,s,u,d){let f=p(u,`.knarr-meta.json`),h;try{h=await m(f)}catch{l(`[history] Could not read meta from ${f}, skipping history capture`);return}let g=h.buildId;if(!g){l(`[history] No buildId in meta, skipping history capture`);return}let _=o(a,s),v=c(a,s,g);if(await e(v)){l(`[history] Build ${g} already in history, skipping`);return}await r(_);let b=v+`.tmp-${process.pid}`;try{await r(b);let n=p(u,`package`);await e(n)&&await t(n,p(b,`package`)),await i(p(b,`.knarr-meta.json`),JSON.stringify(h,null,2)),await t(b,v),l(`[history] Captured build ${g} to history`)}catch(e){l(`[history] Failed to capture history: ${e instanceof Error?e.message:String(e)}`),await n(b)}await y(a,s,d??3)}async function g(t,n){let r=o(t,n);if(!await e(r))return[];let i;try{i=await f(r)}catch{return[]}let a=[];for(let e of i){let t=p(r,e),n=p(t,`.knarr-meta.json`);try{let r=await m(n);a.push({buildId:r.buildId??e,contentHash:r.contentHash,publishedAt:r.publishedAt,sourcePath:r.sourcePath,packageDir:p(t,`package`)})}catch{}}return a.sort((e,t)=>new Date(t.publishedAt).getTime()-new Date(e.publishedAt).getTime()),a}async function _(e,t,n){let r=c(e,t,n),i=p(r,`.knarr-meta.json`);try{let e=await m(i);return{buildId:e.buildId??n,contentHash:e.contentHash,publishedAt:e.publishedAt,sourcePath:e.sourcePath,packageDir:p(r,`package`)}}catch{return null}}async function v(o,s,u,f){let m=await _(o,s,u);if(!m)return null;let g=a(o,s),v=c(o,s,u),y=p(v,`package`),b=p(v,`.knarr-meta.json`),x=await d(b,`utf-8`),S=p(g,`package`),C=p(g,`.knarr-meta.json`);if(!await e(y))throw Error(`History entry ${u} is missing its package directory`);let w=await d(C,`utf-8`).catch(()=>null),T=g+`.restore-old-${process.pid}-${Date.now()}`,E=p(T,`package`),D=!1,O=!1;try{if((await e(S)||w)&&(await r(T),await e(S)&&await t(S,E),w&&await i(p(T,`.knarr-meta.json`),w),D=!0),await t(y,S),O=!0,await i(C,x),await n(v),D)try{await h(o,s,T,f)}finally{await n(T)}}catch(a){throw O&&await e(S)?(await r(v),await t(S,y)):D&&await e(S)&&await n(S),D&&await e(E)&&await t(E,S),w&&await i(C,w),await n(T),a}return l(`[history] Restored build ${u} as current`),m}async function y(e,t,r){if(r<0)return 0;let i=await g(e,t);if(i.length<=r)return 0;let a=i.slice(r),o=0;for(let r of a){let i=c(e,t,r.buildId);try{await n(i),o++,l(`[history] Pruned old build ${r.buildId}`)}catch{}}return o}async function b(t,r){let i=o(t,r);await e(i)&&await n(i)}function x(e){return e??3}export{y as a,g as i,b as n,x as o,_ as r,v as s,h as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as captureHistory}from"./history-540r0BHF.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./console-C8XtlRyM.mjs";import{n as t,p as n,s as r}from"./paths-B5sEvS_7.mjs";import{c as i,f as a,l as o,o as s,r as c,u as l}from"./fs-DusqxRQR.mjs";import{i as u,n as d}from"./logger-Oo2Slehd.mjs";import{i as f}from"./dry-run-DPoN8bZo.mjs";import{t as p}from"./package-manager-Cs9kCsjJ.mjs";import{t as m}from"./bundler-detect-BaShXORS.mjs";import{l as h,s as g,t as ee}from"./json-1jsvqdBb.mjs";import{platform as _}from"node:os";import{chmod as v,lstat as y,mkdir as te,readFile as b,readdir as x,readlink as S,realpath as C,rm as w,symlink as T,writeFile as E}from"node:fs/promises";import{dirname as D,isAbsolute as O,join as k,relative as A,resolve as j,sep as M}from"node:path";const ne=/[\x00-\x1F\x7F]/,re=/^[A-Za-z0-9._+-]+$/;function N(e){return e&&re.test(e)?e:`node`}function ie(e){let t=e.split(/\r?\n/,1)[0]?.trim();if(!t?.startsWith(`#!`))return`node`;let n=t.slice(2).trim().split(/\s+/).filter(Boolean),[r]=n;if(r===void 0)return`node`;let i=r.replace(/\\/g,`/`).split(`/`).pop();if(i===`env`){let e=n.slice(1);return N(e[0]===`-S`?e[1]:e[0])}return N(i)}async function ae(e){try{return ie(await b(e,`utf-8`))}catch{return`node`}}function P(e,t,n=``){if(!t||t===`.`||t===`..`||ne.test(t)||t.includes(`/`)||t.includes(`\\`)||t.includes(`:`))return null;let r=k(e,`${t}${n}`),i=j(e),a=j(r);return a!==i&&a.startsWith(i+M)?r:null}function F(e){return e.bin?typeof e.bin==`string`?{[e.name.startsWith(`@`)&&e.name.split(`/`)[1]||e.name]:e.bin}:e.bin:{}}async function I(t,r,i){let a=F(i);if(Object.keys(a).length===0)return 0;let o=k(t,`node_modules`,`.bin`),s=Object.entries(a).map(([e,t])=>({binName:e,binPath:t,linkPath:P(o,e),cmdPath:P(o,e,`.cmd`),ps1Path:P(o,e,`.ps1`)})).filter(t=>!t.linkPath||!t.cmdPath||!t.ps1Path?(e.warn(`bin name "${t.binName}" is not safe, skipping`),!1):!0),c=k(t,`node_modules`,r),p=j(c),m=s.filter(({binName:t,binPath:n})=>{let r=j(k(c,n));return r.startsWith(p+M)||r===p?!0:(e.warn(`bin "${t}" points outside package directory, skipping`),!1)});if(m.length===0)return 0;if(d()){for(let{linkPath:e}of m)f({type:`bin-link`,path:e,detail:r});return u(`[dry-run] would create ${m.length} bin link(s) for ${r}`),m.length}await te(o,{recursive:!0});let h=_()===`win32`,g=0;for(let{binName:e,binPath:t,linkPath:r,cmdPath:i,ps1Path:a}of m){let s=k(c,t),d=n(A(o,s)),f=await ae(s);if(h){let e=`@ECHO off\r\nGOTO start\r\n:find_dp0\r\nSET dp0=%~dp0\r\nEXIT /b\r\n:start\r\nCALL :find_dp0\r\n${f} "%dp0%\\${d.replace(/\//g,`\\`)}" %*\r\n`;await E(i,e);let t=`#!/usr/bin/env pwsh\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n& ${f} "$basedir/${d}" $args\nexit $LASTEXITCODE\n`;await E(a,t);let n=`#!/bin/sh\nbasedir=$(dirname "$0")\nexec ${f} "$basedir/${d}" "$@"\n`;await E(r,n)}else{try{await w(r,{force:!0})}catch{}try{await T(d,r),await v(s,493)}catch(t){if(l(t)&&(t.code===`EPERM`||t.code===`EACCES`)){u(`[bin-linker] Symlink failed (${t.code}), using shell wrapper for ${e}`);let n=`#!/bin/sh\nbasedir=$(dirname "$0")\nexec ${f} "$basedir/${d}" "$@"\n`;await E(r,n),await v(r,493)}else throw t}}g++}return g}async function L(e,t){let n=F(t),r=k(e,`node_modules`,`.bin`),i=Object.keys(n).map(e=>({binName:e,linkPath:P(r,e),cmdPath:P(r,e,`.cmd`),ps1Path:P(r,e,`.ps1`)})).filter(e=>!!e.linkPath&&!!e.cmdPath&&!!e.ps1Path);if(d()){for(let{linkPath:e}of i)f({type:`bin-unlink`,path:e});u(`[dry-run] would remove ${i.length} bin link(s)`);return}let a=_()===`win32`,o=k(e,`node_modules`,t.name);for(let{linkPath:e,cmdPath:t,ps1Path:n}of i)try{await R(r,e,o)&&await w(e,{force:!0}),a&&(await R(r,t,o)&&await w(t,{force:!0}),await R(r,n,o)&&await w(n,{force:!0}))}catch{}}async function R(e,t,r){let i;try{i=await y(t)}catch(e){if(l(e)&&e.code===`ENOENT`)return!1;throw e}let a=j(r);if(i.isSymbolicLink()){let n=await S(t),r=j(e,n);return r===a||r.startsWith(a+M)}if(!i.isFile())return!1;let o=await b(t,`utf-8`),s=n(A(e,r)),c=s.replace(/\//g,`\\`);return o.includes(`${s}/`)||o.includes(`${s}"`)||o.includes(`${c}\\`)||o.includes(`${c}"`)}const oe={next:[`.next/cache`],webpack:[`node_modules/.cache`]},z=/* @__PURE__ */ new Map;async function se(e){if(d())return u(`[dry-run] would invalidate bundler caches for ${e}`),f({type:`cache-invalidate`,path:e}),0;let t=z.get(e);t||(t=await m(e),z.set(e,t));let n=0;for(let r of t){if(!r.type)continue;let t=oe[r.type];if(t)for(let o of t){let t=k(e,o);if(await i(t))try{await a(t),n++,u(`[inject] Invalidated ${r.type} cache: ${o}`)}catch{u(`[inject] Could not clear ${r.type} cache: ${o} (locked?)`)}}}return n}async function ce(e,t,n,r={}){let i=await V(t,e.name,n,e.version,{repairMissingLink:!0});u(`[inject] ${e.name}@${e.version} → ${i}`),await s(i);let a=await $(i),{copied:c,removed:l,skipped:d}=await o(e.packageDir,i,{force:r.force});u(`[inject] ${c} copied, ${l} removed, ${d} skipped`);let f=c>0||l>0?await se(t):0,p=await $(e.packageDir);a&&await L(t,a);let m=p?await I(t,e.name,p):0;return m>0&&u(`[inject] Created ${m} bin link(s)`),{copied:c,removed:l,skipped:d,binLinks:m,cacheInvalidations:f}}async function le(e,n,r){let o=await V(e,n,r,void 0,{warnOnFallback:!1});if(!await i(o))return!1;let s=t(e,n);return await a(s),await c(o,s),!0}async function ue(e,n,r,o){let s=t(e,n);if(!await i(s))return!1;let l=await V(e,n,r,o),f=await $(l);f&&await L(e,f),await a(l),await c(s,l);let p=await $(d()?s:l);if(p){let t=await I(e,n,p);t>0&&u(`[restore] Restored ${t} original bin link(s) for ${n}`)}return await a(s),!0}async function de(e,t,n,i){let o=r(e,t),s=await V(e,t,n,i),c=await $(s);c&&await L(e,c),await a(s),j(s)!==j(o)&&await a(o)}async function fe(e,t,n){let r=await $(e.packageDir);if(!r)return[];let i={...r.dependencies,...Object.fromEntries(Object.entries(r.peerDependencies??{}).filter(([e])=>!r.peerDependenciesMeta?.[e]?.optional))};if(Object.keys(i).length===0)return[];let a=Object.keys(i);return(await Promise.all(a.map(async r=>({dep:r,installed:await B(r,e,t,n)})))).filter(e=>!e.installed).map(e=>e.dep)}async function B(e,t,n,r){return await i(k(n,`node_modules`,e))?!0:r?pe(await V(n,t.name,r,t.version,{warnOnFallback:!1}),e):!1}async function pe(e,t){let n=await C(e).catch(t=>{if(l(t)&&t.code===`ENOENT`)return e;throw t});for(;;){if(await i(k(n,`node_modules`,t)))return!0;let e=D(n);if(e===n)return!1;n=e}}async function V(t,n,a,o,s={}){let c=r(t,n),d=(await p(t)).resolve(a);if(!d.nodeModulesCompatible)throw Error(d.incompatibilityReason);let f=d.layout===`pnpm`||d.layout===`yarn-pnpm`?d.layout:null;if(!f)return d.layout===`bun`?me(t,c,n):c;let m=f===`pnpm`?await ve(t):await J(t,d.virtualStoreFolder);try{let e=await he(c);if(e){if(!(f===`pnpm`?await xe(m,n,e):await Se(m,e)))throw Error(`Refusing to inject ${n}: node_modules entry resolves outside a configured ${H(f)} virtual store (${e})`);return await W(e,n,void 0,f),u(`[inject] ${H(f)}: resolved symlink → ${e}`),e}}catch(e){if(!(l(e)&&e.code===`ENOENT`))throw l(e)&&u(`${H(f)} symlink resolution error: ${e instanceof Error?e.message:String(e)}`),e}let h=[];for(let e of m)await i(e)&&h.push(e);if(h.length>0){if(!await Q(t,n))return u(`[inject] ${H(f)}: ${n} is not declared by the consumer, skipping virtual store scan`),c;if(f===`yarn-pnpm`){let e=[];for(let r of h){u(`[inject] yarn-pnpm: scanning ${A(t,r)||`.`} for ${n}`);let i=await ge(r,n,o);i&&e.push(i)}let r=q(n,f,e);if(r)return u(`[inject] yarn-pnpm: found in virtual store → ${r}`),s.repairMissingLink&&await G(c,r,n,f),r}if(f===`pnpm`){let e=n.replaceAll(`/`,`+`);for(let r of h){if(u(`[inject] pnpm: scanning ${A(t,r)||`.`} for ${n}`),o){let t=`${e}@${o}`,i=await K(r,n,o,k(r,t,`node_modules`,n));if(i)return u(`[inject] pnpm: exact version match in virtual store → ${i}`),s.repairMissingLink&&await G(c,i,n,f),i}let i=await x(r),a=[];for(let t of i)if(_e(e,o,t)){let e=await K(r,n,o,k(r,t,`node_modules`,n));e&&a.push(e)}let l=q(n,f,a);if(l)return u(`[inject] pnpm: found in virtual store → ${l}`),s.repairMissingLink&&await G(c,l,n,f),l}}}if(s.warnOnFallback!==!1){if(await Q(t,n)){let t=f===`pnpm`?`pnpm`:`yarn`;e.warn(`${n} is in package.json but not installed in the ${H(f)} virtual store, so Knarr is linking it at node_modules/${n} directly. Run \`${t} install\` and then \`knarr add ${n}\` to update the installed copy instead.`)}else u(`[inject] ${H(f)}: ${n} not installed yet, linking at node_modules/${n}`)}return c}function H(e){return e===`pnpm`?`pnpm`:`Yarn pnpm-linker`}async function me(e,t,n){try{if(!(await y(t)).isSymbolicLink())return t}catch(e){if(l(e)&&e.code===`ENOENT`)return t;throw e}let r=await C(t),i=k(e,`node_modules`,`.bun`);if(!U(await C(i).catch(e=>{if(l(e)&&e.code===`ENOENT`)return i;throw e}),r))throw Error(`Refusing to inject ${n}: Bun target resolves outside the local node_modules/.bun store (${r})`);return await W(r,n,void 0,`Bun isolated`),u(`[inject] Bun isolated: resolved symlink → ${r}`),r}function U(e,t){let n=A(j(e),j(t));return n===``||!!n&&!n.startsWith(`..`)&&!O(n)}async function he(e){return(await y(e)).isSymbolicLink()?C(e):null}async function W(e,t,n,r){let i=r===`Bun isolated`?r:H(r),a=await $(e);if(a){if(a.name&&a.name!==t)throw Error(`Refusing to inject ${t}: ${i} target contains package "${a.name}"`);if(n&&a.version&&a.version!==n)throw Error(`Refusing to inject ${t}@${n}: ${i} target contains version ${a.version}`)}}async function G(e,t,n,r){let i=!1;try{if(!(await y(e)).isSymbolicLink())return;i=!0}catch(e){if(!l(e)||e.code!==`ENOENT`)throw e}let a=D(e);if(d()){let i=A(a,t);u(`[inject] ${H(r)}: would restore node_modules symlink for ${n} → ${i}`),f({type:`write`,path:e,dest:t,detail:`${H(r)} package symlink`});return}let o=_()===`win32`;await s(a);let c=await C(a).catch(()=>a),p=A(c,t);u(`[inject] ${H(r)}: restoring node_modules symlink for ${n} → ${p}`),i&&await w(e,{force:!0}),await T(o?t:p,e,o?`junction`:`dir`)}async function K(e,t,n,r){if(!X(e,t,r))return null;try{let[i,a]=await Promise.all([C(e),C(r)]);if(!X(i,t,a))throw Error(`Refusing to inject ${t}: virtual store candidate resolves outside a configured pnpm virtual store (${a})`);return await W(a,t,n,`pnpm`),a}catch(e){if(l(e)&&e.code===`ENOENT`)return null;throw e}}async function ge(e,t,n){let r=await x(e),i=[];for(let a of r){let r=k(e,a,`package`),o=await $(r);if(!o||o.name!==t||n&&o.version!==n)continue;let[s,c]=await Promise.all([C(e),C(r)]);if(!Z(s,c))throw Error(`Refusing to inject ${t}: virtual store candidate resolves outside a configured Yarn pnpm-linker virtual store (${c})`);i.push(c)}return q(t,`yarn-pnpm`,i)}function _e(e,t,n){if(!t)return n.startsWith(`${e}@`);let r=`${e}@${t}`;return n===r||n.startsWith(`${r}_`)}function q(e,t,n){if(n.length<=1)return n[0]??null;throw Error(`Refusing to repair ${e}: multiple ${H(t)} virtual-store entries match. Run your package manager's install command, then try again.`)}async function ve(e){let t=k(e,`node_modules`),n=[],r=k(t,`.pnpm`);await Y(e,r)&&n.push(r);let i=await ye(t);if(!i)return n;let a=O(i)?i:j(t,i);return await Y(e,a)?(n.some(e=>j(e)===j(a))||n.push(a),n):(u(`[inject] pnpm: ignoring external virtualStoreDir ${a}`),n)}async function J(e,t){let n=k(e,`node_modules`),r=[],i=k(n,`.store`);if(await Y(e,i)&&r.push(i),!t)return r;let a=O(t)?t:j(e,t);return await Y(e,a)?(r.some(e=>j(e)===j(a))||r.push(a),r):(u(`[inject] yarn-pnpm: ignoring external pnpmStoreFolder ${a}`),r)}async function Y(e,t){return U(await C(e).catch(()=>j(e)),await C(t).catch(e=>{if(l(e)&&e.code===`ENOENT`)return j(t);throw e}))}async function ye(e){try{return be(await b(k(e,`.modules.yaml`),`utf-8`))}catch(e){if(l(e)&&e.code===`ENOENT`)return null;throw e}}function be(e){try{let t=h(g(e),`virtualStoreDir`)?.trim();if(t)return t}catch{}let t=e.match(/^virtualStoreDir:\s*(.+?)\s*$/m);if(!t)return null;let n=(t[1]??``).trim().replace(/\s+#.*$/,``);return(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`))&&(n=n.slice(1,-1)),n||null}async function xe(e,t,n){for(let r of e)try{if(X(await C(r),t,n))return!0}catch(e){if(l(e)&&e.code===`ENOENT`)continue;throw e}return!1}async function Se(e,t){for(let n of e)try{if(Z(await C(n),t))return!0}catch(e){if(l(e)&&e.code===`ENOENT`)continue;throw e}return!1}function X(e,t,n){if(!U(e,n))return!1;let r=A(e,n).replace(/\\/g,`/`),i=`node_modules/${t}`.replace(/\\/g,`/`);return r===i||r.endsWith(`/${i}`)}function Z(e,t){if(!U(e,t))return!1;let n=A(e,t).replace(/\\/g,`/`).split(`/`);return n.length===2&&n[1]===`package`}async function Q(e,t){let n=await $(e);return n?!!(n.dependencies?.[t]||n.devDependencies?.[t]||n.optionalDependencies?.[t]||n.peerDependencies?.[t]):!1}async function $(t){try{let e=await b(k(t,`package.json`),`utf-8`);return ee(g(e,k(t,`package.json`)))}catch(n){return l(n)&&n.code!==`ENOENT`&&e.warn(`Failed to read package.json in ${t}: ${n instanceof Error?n.message:String(n)}`),null}}export{de as a,Q as i,fe as n,V as o,ce as r,ue as s,le as t};
|
package/dist/paths-B5sEvS_7.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./console-C8XtlRyM.mjs";import{a as t,s as n,u as r}from"./json-1jsvqdBb.mjs";import{homedir as i}from"node:os";import{readFile as a}from"node:fs/promises";import{isAbsolute as o,join as s,relative as c,resolve as l}from"node:path";const u=/^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/,d=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/,f=/[\x00-\x1F\x7F]/;function p(e){if(!e||e.length>214||f.test(e)||e.includes(`\\`)||e.includes(`//`)||e.split(`/`).some(e=>e===`.`||e===`..`)||!u.test(e))throw Error(`Invalid package name "${e}"`)}function m(e){if(!e||f.test(e)||e.includes(`/`)||e.includes(`\\`)||e.includes(`..`)||!d.test(e))throw Error(`Invalid package version "${e}"`)}function h(e,t){p(e),m(t)}function g(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.contentHash==`string`&&typeof t.publishedAt==`string`&&typeof t.sourcePath==`string`&&(t.buildId===void 0||typeof t.buildId==`string`)&&(t.schemaVersion===void 0||typeof t.schemaVersion==`number`)}function _(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.version==`string`&&typeof t.contentHash==`string`&&typeof t.linkedAt==`string`&&typeof t.sourcePath==`string`&&typeof t.backupExists==`boolean`&&typeof t.packageManager==`string`&&[`npm`,`pnpm`,`yarn`,`bun`].includes(t.packageManager)&&(t.buildId===void 0||typeof t.buildId==`string`)}function v(e){if(typeof e!=`object`||!e)return null;let n=e;if(n.version!==`1`||typeof n.links!=`object`||n.links===null)return null;let r=t();for(let[e,t]of Object.entries(n.links)){if(!_(t))return null;r[e]=t}return{...n,links:r}}async function y(t,i,o){try{let c=await a(s(t,`package.json`),`utf-8`),l=n(c,`package.json`),u=r(l,`dependencies`)[i]??r(l,`devDependencies`)[i]??r(l,`peerDependencies`)[i];if(!u||/^(workspace:|catalog:|\*)/.test(u))return;let d=u.match(/(\d+)\.\d+\.\d+/);if(!d?.[1])return;parseInt(d[1],10)!==parseInt(o.split(`.`)[0]??``,10)&&e.warn(`Version mismatch: store has ${i}@${o} but your package.json declares "${u}". Consider updating your dependency range.`)}catch{}}function b(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let n=t();for(let[t,r]of Object.entries(e)){if(!Array.isArray(r)||!r.every(e=>typeof e==`string`))return null;n[t]=r}return n}function x(e,t,n){let r=l(e),i=l(t),a=c(r,i);if(a!==``&&(a.startsWith(`..`)||o(a)))throw Error(`${n} escapes expected directory: ${t}`)}function S(){return process.env.KNARR_HOME||s(i(),`.knarr`)}function C(){return s(S(),`store`)}function w(){return s(S(),`consumers.json`)}function T(e){return p(e),e.replace(/\//g,`+`)}function E(e){if(e.startsWith(`@`)){let t=e.indexOf(`+`);if(t!==-1)return e.slice(0,t)+`/`+e.slice(t+1)}return e}function D(e,t){h(e,t);let n=C(),r=s(n,`${T(e)}@${t}`);return x(n,r,`Store entry path`),r}function O(e,t){return s(D(e,t),`package`)}function k(e,t){return s(D(e,t),`.knarr-meta.json`)}function A(e,t){return s(D(e,t),`history`)}function j(e,t,n){if(!/^[a-f0-9]{8,64}$/i.test(n))throw Error(`Invalid build id "${n}"`);return s(A(e,t),n)}function M(e){return s(e,`.knarr`)}function N(e){return s(e,`.knarr`,`state.json`)}function P(e,t){p(t);let n=s(e,`.knarr`,`backups`),r=s(n,T(t));return x(n,r,`Backup path`),r}function F(e){return e.replace(/\\/g,`/`)}function I(e,t){p(t);let n=s(e,`node_modules`),r=s(n,t);return x(n,r,`node_modules package path`),r}export{h as _,w as a,y as b,D as c,O as d,C as f,b as g,v as h,N as i,A as l,g as m,P as n,j as o,F as p,M as r,I as s,E as t,k as u,p as v,m as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as runPreflightChecks}from"./preflight-fF8g1t6F.mjs";
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{n as e}from"./shell-DQfdqK0J.mjs";import{t}from"./console-C8XtlRyM.mjs";import{c as n,d as r,f as i,i as a,o,p as s,s as c,t as l,u}from"./fs-DusqxRQR.mjs";import{_ as d,c as f,p}from"./paths-B5sEvS_7.mjs";import{n as m,t as h}from"./picomatch-DEttMFSR.mjs";import{i as g,n as _}from"./logger-Oo2Slehd.mjs";import{i as v,o as y}from"./store-CAzxNmpU.mjs";import{g as ee}from"./tracker-nsfA6PWa.mjs";import{i as b}from"./dry-run-DPoN8bZo.mjs";import{t as x}from"./package-manager-Cs9kCsjJ.mjs";import{c as S,s as C,t as w}from"./json-1jsvqdBb.mjs";import{availableParallelism as T,platform as E}from"node:os";import{readFile as D,readdir as O,stat as k}from"node:fs/promises";import{delimiter as A,dirname as te,join as j,relative as M,resolve as N,sep as P}from"node:path";import{createHash as F}from"node:crypto";var I=/* @__PURE__ */ m(h(),1);async function ne(e,n){let r=[],i=N(e);r.push(j(i,`package.json`));let a=await W(i,i),o=a.map(e=>p(M(i,e)));if(n.files&&n.files.length>0)for(let e of n.files){let n=j(i,e),s=N(n);if(!s.startsWith(i+P)&&s!==i){t.warn(`files pattern "${e}" escapes package directory, skipping`);continue}let c=!1;try{if((await k(n)).isDirectory()){let e=p(M(i,n))+`/`;for(let[t,n]of a.entries())o[t]?.startsWith(e)&&r.push(n);c=!0}else r.push(n),c=!0}catch(e){if(u(e)&&e.code!==`ENOENT`)throw e}if(!c){let n=(0,I.default)(e,{dot:!0}),s=0;for(let[e,t]of a.entries()){let a=o[e];if(a!==void 0&&n(a)){let e=N(t);if(!e.startsWith(i+P)&&e!==i)continue;r.push(t),s++}}s===0&&t.warn(`files pattern "${e}" matched no files`)}}else{let e=await z(i);for(let[t,n]of a.entries()){let i=o[t];i!==void 0&&!R(i,e)&&r.push(n)}}let s=new Set(r),c=new Set(a);for(let e of[`README.md`,`README`,`LICENSE`,`LICENCE`,`CHANGELOG.md`]){let t=j(i,e);s.has(t)||c.has(t)&&(r.push(t),s.add(t))}return[...s]}const L=/* @__PURE__ */ new Set(/* @__PURE__ */ `node_modules,.git,.svn,.hg,.DS_Store,.npmrc,.gitignore,.knarr,test,tests,__tests__,.github,.vscode,.idea,coverage,.nyc_output,tsconfig.json,tsconfig.build.json,.eslintrc,.eslintrc.js,.eslintrc.json,.prettierrc,.prettierrc.js,jest.config.js,jest.config.ts,vitest.config.ts,vitest.config.js`.split(`,`));function R(e,t){for(let n of t.negations)if(n(e))return!1;let n=e.split(/[\\/]/);for(let e of n)if(L.has(e)||t.literals.has(e))return!0;if(t.literals.has(e))return!0;for(let n of t.patterns)if(n(e))return!0;return!1}async function z(e){let t=await B(e,`.npmignore`);if(t!==null)return H(t);let n=await B(e,`.gitignore`);return n===null?V():H(n)}async function B(e,t){try{return await D(j(e,t),`utf-8`)}catch(e){if(u(e)&&e.code===`ENOENT`)return null;throw e}}function V(){return{literals:/* @__PURE__ */ new Set,patterns:[],negations:[]}}function H(e){let t={literals:/* @__PURE__ */ new Set,patterns:[],negations:[]};for(let n of e.split(`
|
|
2
|
-
`)){let e=n.trim();if(e&&!e.startsWith(`#`)){if(e.startsWith(`!`)){let n=e.slice(1);U(n),t.negations.push((0,I.default)(n,{dot:!0}))}else U(e)?t.patterns.push((0,I.default)(e,{dot:!0})):t.literals.add(e.replace(/\/$/,``))}}return t}function U(e){return/[*?[\]{}()]/.test(e)}async function W(e,t){let n=[];try{let r=await O(e,{withFileTypes:!0});for(let i of r){let r=j(e,i.name);if(i.isDirectory()){if(i.name===`.git`||e===t&&i.name===`node_modules`||i.isSymbolicLink())continue;n.push(...await W(r,t))}else i.isSymbolicLink()||n.push(r)}}catch(e){if(u(e)&&e.code===`ENOENT`)return[];throw e}return n}const re=s(Math.max(T(),8));async function ie(e,t,n=/* @__PURE__ */ new Map){let r=new Map(e.map(e=>[p(M(t,e)),e]));for(let e of n.keys())r.has(e)||r.set(e,j(t,e));let i=[...r.entries()].sort(([e],[t])=>e.localeCompare(t)),a=await Promise.all(i.map(([e,t])=>re(async()=>{let r=n.get(e);return r===void 0?{rel:e,content:await D(t)}:{rel:e,content:Buffer.isBuffer(r)?r:Buffer.from(r)}})));g(`[hash] Computing content hash for ${i.length} files`);let o=F(`sha256`),s=Buffer.alloc(4);for(let{rel:e,content:t}of a)o.update(e),o.update(`\0`),s.writeUInt32LE(t.length),o.update(s),o.update(t);let c=`sha256v2:`+o.digest(`hex`);return g(`[hash] Result: ${c.slice(0,20)}...`),c}const ae=s(Math.max(T(),8));async function oe(e,s={}){let u=j(e,`package.json`),p;try{p=await D(u,`utf-8`)}catch{throw Error(`No package.json found in ${e}`)}let m=C(p,u);if(typeof m.name!=`string`||!m.name)throw Error(`package.json missing 'name' field`);if(typeof m.version!=`string`||!m.version)throw Error(`package.json missing 'version' field`);let h=w(m);if(!h)throw Error(`package.json missing 'name' or 'version' field`);d(h.name,h.version),await J(e,h,`preknarr`),s.runScripts!==!1&&await J(e,h,`prepack`);let b=e;if(h.publishConfig?.directory){b=N(e,h.publishConfig.directory);try{if(!(await k(b)).isDirectory())throw Error(`publishConfig.directory "${h.publishConfig.directory}" is not a directory`)}catch(e){throw e instanceof Error&&`code`in e&&e.code===`ENOENT`?Error(`publishConfig.directory "${h.publishConfig.directory}" does not exist`,{cause:e}):e}g(`[publish] Using publishConfig.directory: ${b}`)}let x=j(b,`package.json`),S=b===e||await n(x),T=S?w(C(await D(x,`utf-8`),x)):h;if(!T?.name)throw Error(`publish package.json missing 'name' field`);if(!T.version)throw Error(`publish package.json missing 'version' field`);if(d(T.name,T.version),T.private&&!s.allowPrivate)throw Error(`Package "${T.name}" is private. Use --private flag to publish private packages.`);let E=S?T:{...T,files:void 0},O=await ne(b,E);if(O.length===0)throw Error(`No publishable files found`);g(`[publish] Resolved ${O.length} files for ${T.name}@${T.version}`),await me(T,e),await ge(T,e);let A=de(T);A=ue(A);let P=/* @__PURE__ */ new Map;A===T&&S||P.set(`package.json`,JSON.stringify(A,null,2));let F=[...O],I=new Set(O.map(e=>M(b,e).replace(/\\/g,`/`)));for(let e of P.keys())I.has(e)||F.push(j(b,e));let L=await ie(F,b,P);if(!s.force){let e=await y(T.name,T.version);if(e&&e.contentHash===L)return t.info(`${T.name}@${T.version} already up to date (no changes since last publish)`),{name:T.name,version:T.version,fileCount:O.length,skipped:!0,contentHash:L,buildId:e.buildId??``}}let R=f(T.name,T.version),z=await ee(R+`.lock`,async()=>{if(!s.force){let e=await y(T.name,T.version);if(e&&e.contentHash===L)return t.info(`${T.name}@${T.version} already up to date (no changes since last publish)`),{name:T.name,version:T.version,fileCount:O.length,skipped:!0,contentHash:L,buildId:e.buildId??``}}let u=v(R,`tmp`),d=j(u,`package`),f=L.slice(9,17);try{await c(d),g(`[publish] Copying files to temp store...`);let t=new Set(O.map(e=>te(j(d,M(b,e)))));await Promise.all([...t].map(e=>o(e))),await Promise.all(O.map(e=>ae(async()=>{let t=M(b,e),n=t.replace(/\\/g,`/`),r=j(d,t),i=P.get(n);i===void 0?await a(e,r,{ensureParent:!1}):await l(r,Buffer.isBuffer(i)?i.toString(`utf-8`):i)}))),P.has(`package.json`)&&await l(j(d,`package.json`),JSON.stringify(A,null,2));let p={schemaVersion:1,contentHash:L,publishedAt:(/* @__PURE__ */ new Date()).toISOString(),sourcePath:e,buildId:f};await l(j(u,`.knarr-meta.json`),JSON.stringify(p,null,2));let m=await n(R),h=v(R,`old`),y=!1;try{m&&(await r(R,h),y=!_()),await r(u,R)}catch(e){throw y&&await n(h)&&(await n(R)&&await i(R),await r(h,R)),e}if(m&&!_()){try{let{captureHistory:e}=await import(`./history-B3E1DMFO.mjs`);await e(T.name,T.version,h,s.historyLimit)}catch(e){g(`[publish] History capture failed: ${e instanceof Error?e.message:String(e)}`)}await i(h)}g(`[publish] Stored at ${R}`)}catch(e){throw await i(u),e}return{name:T.name,version:T.version,fileCount:O.length,skipped:!1,contentHash:L,buildId:f}},{stale:6e4});return z.skipped||(s.runScripts!==!1&&await J(e,h,`postpack`),await J(e,h,`postknarr`),t.success(`Published ${T.name}@${T.version} (${O.length} files) [${z.buildId}]`)),z}const G=parseInt(process.env.KNARR_HOOK_TIMEOUT??`30000`,10);function K(e){return E()===`win32`?Object.keys(e).find(e=>e.toLowerCase()===`path`)??`Path`:`PATH`}function q(e,t,n){if(E()===`win32`){let n=t.toLowerCase();for(let t of Object.keys(e))t.toLowerCase()===n&&delete e[t]}e[t]=n}function se(e,t,n,r){let i={...process.env},a=K(i),o=i[a]??``;return q(i,a,[j(e,`node_modules`,`.bin`),o].filter(Boolean).join(A)),`INIT_CWD`in i&&i.INIT_CWD||q(i,`INIT_CWD`,e),q(i,`npm_lifecycle_event`,n),q(i,`npm_lifecycle_script`,r),q(i,`npm_package_name`,t.name),q(i,`npm_package_version`,t.version),i}async function J(t,n,r){let i=n.scripts?.[r];if(!i)return;if(_()){b({type:`lifecycle-skip`,path:t,detail:`${r}: ${i}`});return}let a=await ce(t,r,i);return g(`[lifecycle] Running ${r}: ${a}`),new Promise((o,s)=>{let c=se(t,n,r,i),l=e(a,{cwd:t,env:c,stdio:`inherit`}),u=setTimeout(()=>{l.kill(`SIGTERM`),s(/* @__PURE__ */ Error(`${r} script timed out after ${G/1e3}s. Increase KNARR_HOOK_TIMEOUT env var if the script needs more time.`))},G);l.on(`close`,e=>{clearTimeout(u),e===0?o():s(/* @__PURE__ */ Error(`${r} script failed with exit code ${e}`))}),l.on(`error`,e=>{clearTimeout(u),s(/* @__PURE__ */ Error(`${r} script error: ${e.message}`))})})}async function ce(e,t,n){return(await x(e)).resolve().nodeModulesCompatible?n:`yarn run ${t}`}const le=[`main`,`module`,`exports`,`types`,`typings`,`browser`,`bin`];function ue(e){if(!e.publishConfig)return e;let t={...e};for(let n of le)n in e.publishConfig&&(t[n]=e.publishConfig[n]);return delete t.publishConfig,t}function de(e){let n=!1,r={...e},i=null,a=!1;for(let o of[`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`]){let s=e[o];if(!s)continue;let c=!1,l={...s};for(let[e,r]of Object.entries(s))if(r.startsWith(`workspace:`)){let t=fe(e,r);if(!t)continue;l[e]=t,c=!0,n=!0}else if(r.startsWith(`catalog:`)){if(a||=(i=he(),!0),i){let a=Y(r,e,i);a?(l[e]=a,c=!0,n=!0):t.warn(`catalog: specifier for "${e}" could not be resolved — published package.json will contain "${r}" which may cause install failures`)}else g(`[publish] No pnpm-workspace.yaml found, cannot resolve catalog: for "${e}"`)}c&&(r[o]=l)}return n?r:e}function fe(e,n){let r=n.slice(10),i=pe(r),a=i?.name??e,o=i?.range??r;if(o===`*`||o===`^`||o===`~`){let r=Q?.versions.get(a);if(!r)return t.warn(`workspace: specifier for "${a}" could not be resolved — published package.json will contain "${n}" which may cause install failures`),null;let s=o===`*`?r:o+r;return i&&a!==e?`npm:${a}@${s}`:s}return i&&a!==e?`npm:${a}@${o}`:o}function pe(e){let t=e.lastIndexOf(`@`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return!n||!r?null:{name:n,range:r}}function Y(e,t,n){let r=e.slice(8);return r===``||r==="default"?n.default[t]??null:n.named[r]?.[t]??null}let X=null;async function Z(e){if(X?.dir===e)return X.root;let{findWorkspacePackageRoot:t}=await import(`./workspace-CSQVbAw4.mjs`),n=await t(e);return X={dir:e,root:n},n}let Q=null;async function me(e,t){if(![`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`].some(t=>{let n=e[t];return n&&Object.values(n).some(e=>e.startsWith(`workspace:`))}))return;let n=await Z(t);if(!n){Q=null;return}let{findWorkspacePackages:r}=await import(`./workspace-CSQVbAw4.mjs`),i=await r(n),a=/* @__PURE__ */ new Map;await Promise.all(i.map(async e=>{try{let t=w(await S(j(e,`package.json`)));t?.name&&t.version&&a.set(t.name,t.version)}catch{}})),Q={root:n,versions:a}}let $=null;function he(){return $?.catalogs??null}async function ge(e,t){if(![`dependencies`,`devDependencies`,`peerDependencies`,`optionalDependencies`].some(t=>{let n=e[t];return n&&Object.values(n).some(e=>e.startsWith(`catalog:`))}))return;let n=await Z(t);if(!n){$=null;return}let r=j(n,`pnpm-workspace.yaml`),i=(await k(r).catch(()=>null))?.mtimeMs??0;if($?.root===n&&$.mtimeMs===i)return;let{parseCatalogs:a}=await import(`./workspace-CSQVbAw4.mjs`);$={root:n,mtimeMs:i,catalogs:await a(n)}}export{oe as t};
|
package/dist/remove-DxezmGfU.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{n as default}from"./remove-BEBkMPak.mjs";
|
package/dist/store-CAzxNmpU.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./console-C8XtlRyM.mjs";import{_ as t,c as n,d as r,f as i,m as a,t as o,u as s}from"./paths-B5sEvS_7.mjs";import{c,f as l,u}from"./fs-DusqxRQR.mjs";import{o as d}from"./json-1jsvqdBb.mjs";import{readFile as f,readdir as p}from"node:fs/promises";async function m(t,n){let r=s(t,n);try{let i=await f(r,`utf-8`),o=d(i);return a(o)?o:(e.warn(`Invalid metadata for ${t}@${n}, ignoring`),null)}catch(r){return u(r)&&r.code!==`ENOENT`&&e.warn(`Failed to read metadata for ${t}@${n}: ${r instanceof Error?r.message:String(r)}`),null}}async function h(e,t){let n=r(e,t),i=await m(e,t);return!i||!await c(n)?null:{name:e,version:t,packageDir:n,meta:i}}async function g(e){let t=(await x()).filter(t=>t.name===e);return t.length===0?null:t.reduce((e,t)=>new Date(t.meta.publishedAt).getTime()>new Date(e.meta.publishedAt).getTime()?t:e)}const _=/\.(?:tmp-\d+|old)-(\d{13})$/;function v(e,t){return`${e}.${t===`tmp`?`tmp-${process.pid}`:`old`}-${Date.now()}`}function y(e){let t=_.exec(e)?.[1];return t===void 0?null:Number(t)}function b(e){if(y(e)!==null)return null;let n=e.lastIndexOf(`@`);if(n<=0)return null;let r=o(e.slice(0,n)),i=e.slice(n+1);try{t(r,i)}catch{return null}return{name:r,version:i}}async function x(){let e=i();if(!await c(e))return[];let t=await p(e,{withFileTypes:!0});return(await Promise.all(t.map(async e=>{let t=e.isDirectory()?b(e.name):null;if(!t)return null;let{name:n,version:i}=t,a=await m(n,i);return a?{name:n,version:i,packageDir:r(n,i),meta:a}:null}))).filter(e=>e!==null)}async function S(e,t){await l(n(e,t))}export{y as a,v as i,h as n,m as o,x as r,S as s,g as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{c as readConsumerStateSafe}from"./tracker-nsfA6PWa.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./console-C8XtlRyM.mjs";import{a as t,g as n,h as r,i,p as a,r as o}from"./paths-B5sEvS_7.mjs";import{c as s,o as c,s as l,t as u,u as d}from"./fs-DusqxRQR.mjs";import{n as f}from"./logger-Oo2Slehd.mjs";import{i as p}from"./dry-run-DPoN8bZo.mjs";import{a as m,o as h}from"./json-1jsvqdBb.mjs";import{mkdir as g,readFile as _,rm as v,stat as y}from"node:fs/promises";import{dirname as b}from"node:path";import{setTimeout as x}from"node:timers/promises";const S={retries:5,minTimeout:100,maxTimeout:1e3,factor:2,stale:3e4};async function C(e,t,n){if(f())return p({type:`lock-skip`,path:e}),t();await g(b(e),{recursive:!0});let r=e+`.lk`,i=n?.stale??S.stale,a=!1;for(let e=0;e<=S.retries;e++)try{await g(r),a=!0;break}catch(t){if(d(t)&&t.code===`EEXIST`){try{let e=await y(r);if(Date.now()-e.mtimeMs>i){await v(r,{recursive:!0,force:!0});continue}}catch{continue}if(e<S.retries){let t=Math.min(S.minTimeout*S.factor**e,S.maxTimeout);await x(t)}}else throw t}if(!a)throw Error(`Failed to acquire lock after ${S.retries} attempts. Another Knarr process may be running. If this persists, delete ${r} and retry.`);try{return await t()}finally{await v(r,{recursive:!0,force:!0})}}async function w(e){let{state:t}=await T(e);return t}async function T(t){let n=i(t);try{let t=await _(n,`utf-8`),i=r(h(t));return i?{state:i,reliable:!0}:(e.warn(`Invalid consumer state in ${n}, using defaults`),{state:{version:`1`,links:m()},reliable:!1})}catch(t){return d(t)&&t.code===`ENOENT`?{state:{version:`1`,links:m()},reliable:!0}:(e.warn(`Failed to read consumer state: ${t instanceof Error?t.message:String(t)}`),{state:{version:`1`,links:m()},reliable:!1})}}async function E(e,t){await c(o(e));let n=i(e);await u(n,JSON.stringify(t,null,2))}async function D(e,t){let n=i(e);await C(n,async()=>{let{state:r,reliable:i}=await T(e);if(!i)throw Error(`Consumer state in ${n} is corrupt — refusing to write to avoid destroying existing links. Delete .knarr/state.json and re-run 'knarr add' for each package.`);let a=JSON.stringify(r);t(r),JSON.stringify(r)===a&&await s(n)||await E(e,r)})}async function O(e,t,n){await D(e,e=>{e.links[t]=n})}async function k(e,t){await D(e,e=>{delete e.links[t]})}async function A(e,t){return(await w(e)).links[t]??null}async function j(){let r=t();try{let t=n(h(await _(r,`utf-8`)));return t?{registry:t,reliable:!0}:(e.warn(`Invalid consumers registry in ${r}, using empty registry`),{registry:m(),reliable:!1})}catch(t){return d(t)&&t.code===`ENOENT`?{registry:m(),reliable:!0}:(e.warn(`Failed to read consumers registry: ${t instanceof Error?t.message:String(t)}`),{registry:m(),reliable:!1})}}async function M(){return(await j()).registry}function N(){return`Fix or delete ${t()}, then re-run 'knarr add' in each consumer project.`}var P=class extends Error{constructor(){super(`Consumers registry ${t()} is corrupt; refusing to overwrite it. ${N()}`),this.name=`CorruptRegistryError`}};function F(n){if(!(n instanceof P))throw n;e.warn(`Consumers registry ${t()} is corrupt, so it was left unchanged. ${N()}`)}async function I(){let{registry:e,reliable:t}=await j();if(!t)throw new P;return e}async function L(e){let n=t();await l(b(t())),await u(n,JSON.stringify(e,null,2))}async function R(e,n){await C(t(),async()=>{let t=await I();t[e]||(t[e]=[]);let r=a(n);t[e].includes(r)||t[e].push(r),await L(t)})}async function z(e,n){await C(t(),async()=>{let t=await I();if(!t[e])return;let r=a(n);t[e]=t[e].filter(e=>e!==r),t[e].length===0&&delete t[e],await L(t)})}async function B(e){return(await M())[e]??[]}async function V(e={}){let n=t(),r=0,i=0,a=0,o=0;return await C(n,async()=>{let t=await I(),n=m();for(let[c,l]of Object.entries(t)){let t=await Promise.all(l.map(async t=>{if(!await s(t))return{consumerPath:t,valid:!1,reason:`missing-dir`};if(e.removeMissingLinks){let{state:e,reliable:n}=await T(t);if(!n)return o++,{consumerPath:t,valid:!0,reason:`unreliable-state`};if(!e.links[c])return{consumerPath:t,valid:!1,reason:`missing-link`}}return{consumerPath:t,valid:!0,reason:null}})),u=t.filter(e=>e.valid).map(e=>e.consumerPath);r+=l.length-u.length,a+=t.filter(e=>e.reason===`missing-link`).length,u.length>0?n[c]=u:i++}await L(n)}),{removedConsumers:r,removedPackages:i,removedMissingLinks:a,skippedUnreliableConsumers:o}}export{B as a,T as c,R as d,k as f,C as g,F as h,N as i,M as l,D as m,O as n,A as o,z as p,V as r,w as s,P as t,j as u};
|
package/dist/update-CjAl0ZO9.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./console-C8XtlRyM.mjs";import{p as n}from"./fs-DusqxRQR.mjs";import{n as r,s as i}from"./tracker-nsfA6PWa.mjs";import{t as a}from"./store-CAzxNmpU.mjs";import{r as o}from"./injector-BMOi1uN3.mjs";import{t as s}from"./timer-BZNWRS3O.mjs";import{n as c,t as l}from"./output-B7NC4xgj.mjs";import{t as u}from"./errors-DRugrv36.mjs";import{i as d}from"./logger-Oo2Slehd.mjs";import{b as f}from"./paths-B5sEvS_7.mjs";import{t as p}from"./package-manager-Cs9kCsjJ.mjs";import{resolve as m}from"node:path";const h=n(4);var g=e({meta:{name:`update`,description:`Pull latest versions from the store for linked packages`},args:{package:{type:`positional`,description:`Package name to update (default: all linked)`,required:!1}},async run({args:e}){c();let n=new s,g=m(`.`),_=await i(g),v=await p(g),y=v.resolve();y.nodeModulesCompatible||(t.error(y.incompatibilityReason),process.exit(1));let b=Object.entries(_.links);if(b.length===0){t.info(`No linked packages in this project`),l({updated:0,skipped:0});return}let x=e.package?b.filter(([t])=>t===e.package):b;e.package&&x.length===0&&(u(`Package "${e.package}" is not linked in this project. Run 'knarr list' to see linked packages.`),process.exit(1));let S=0,C=0,w=0,T=0,E=await Promise.all(x.map(([e,n])=>h(async()=>{let i=await a(e);if(!i)return t.warn(`Store entry missing for ${e}. Re-publish it.`),`missing`;let s=v.resolve(n.packageManager).packageManager,c=s!==n.packageManager;if(i.meta.contentHash===n.contentHash&&!c)return d(`[update] ${e}@${i.version} already up to date`),`skipped`;try{let a=await o(i,g,s),c={...n,version:i.version,contentHash:i.meta.contentHash,buildId:i.meta.buildId??``,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),packageManager:s};return await r(g,e,c),await f(g,e,i.version),t.success(`Updated ${e}@${i.version} (${a.copied} files changed)`),`updated`}catch(n){return t.warn(`Failed to update ${e}: ${n instanceof Error?n.message:String(n)}`),`failed`}})));for(let e of E)e===`updated`?S++:e===`skipped`?C++:e===`missing`?w++:T++;let D=[`${S} updated`,`${C} unchanged`];w>0&&D.push(`${w} missing`),T>0&&D.push(`${T} failed`),t.info(`Update complete: ${D.join(`, `)} in ${n.elapsed()}`),l({updated:S,skipped:C,missing:w,failed:T,elapsed:n.elapsedMs()})}});export{g as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export{t as WatchOrchestrator}from"./watch-orchestrator-DkuwJOEb.mjs";
|