knarr 0.3.2 → 1.0.0-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/add-flow-CffgNcwl.mjs +3 -0
- package/dist/{add-CZp5YVWF.mjs → add-gNa3t7pB.mjs} +1 -1
- package/dist/batch-push-Xp-9Gipa.mjs +1 -0
- package/dist/{bundler-detect-BaShXORS.mjs → bundler-detect-DGb3enFz.mjs} +1 -1
- package/dist/{check-BFgQ7Px_.mjs → check-CfY58ssu.mjs} +1 -1
- package/dist/{clean-B4S8pHpI.mjs → clean-0JDjLApX.mjs} +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/{config-DEpSKyI8.mjs → config-D2dxGdR0.mjs} +1 -1
- package/dist/dev-CjZq04EN.mjs +1 -0
- package/dist/doctor-CPjy06Ce.mjs +4 -0
- package/dist/{dry-run-DPoN8bZo.mjs → dry-run-dHs1UCw6.mjs} +1 -1
- package/dist/{explain-U6-XLo4U.mjs → explain-ayyyCGP3.mjs} +1 -1
- package/dist/{fs-DusqxRQR.mjs → fs-CQN7XoRJ.mjs} +1 -1
- package/dist/fs-DllZdG46.mjs +1 -0
- package/dist/history-BLugzUtP.mjs +1 -0
- package/dist/history-COM3Qzmw.mjs +1 -0
- package/dist/index.d.ts +11 -79
- package/dist/index.mjs +1 -1
- package/dist/{init-BJZdXWmg.mjs → init-BrtOdn06.mjs} +1 -1
- package/dist/{init-helpers-DfznkCwv.mjs → init-helpers-cPiBMjll.mjs} +1 -1
- package/dist/injector-BASQ1zbM.mjs +1 -0
- package/dist/{list-BekXJBqC.mjs → list-CRvFrdbY.mjs} +1 -1
- package/dist/logger-Bib7d-kD.mjs +1 -0
- package/dist/{migrate-DGXYBPRz.mjs → migrate-B0KoRfDB.mjs} +1 -1
- package/dist/{nextjs-config-C2Xv-pZR.mjs → nextjs-config-BL72LxXy.mjs} +1 -1
- package/dist/{nextjs-config-D3H6P4Is.mjs → nextjs-config-DEsPFOHp.mjs} +1 -1
- package/dist/output-GYAldYAZ.mjs +1 -0
- package/dist/{package-manager-DENvuHqT.mjs → package-manager-C4Jxwe0t.mjs} +1 -1
- package/dist/{paths-V3_BeE_z.mjs → paths-CE53uQIL.mjs} +1 -1
- package/dist/{preflight-DPlVrYLp.mjs → preflight-Cgd-Rd2c.mjs} +1 -1
- package/dist/preflight-IRfXIpb-.mjs +1 -0
- package/dist/publish-eZF0cGPR.mjs +1 -0
- package/dist/publisher-C_10LOjC.mjs +2 -0
- package/dist/push-CSNi4CpT.mjs +1 -0
- package/dist/push-engine-0nZ1vhhj.mjs +1 -0
- package/dist/remove-Dc7nNODL.mjs +1 -0
- package/dist/remove-DfYqEISu.mjs +1 -0
- package/dist/reset-BRlinr5x.mjs +1 -0
- package/dist/restore-C9JOb13Y.mjs +1 -0
- package/dist/{rollback-B7QjnKje.mjs → rollback-DDRBoJt-.mjs} +1 -1
- package/dist/shell-CdudI-mX.mjs +1 -0
- package/dist/{status-BHe6UGa2.mjs → status-jTVBS0Ig.mjs} +1 -1
- package/dist/{store-D2r3Vo5S.mjs → store-BohPY8Sk.mjs} +1 -1
- package/dist/{tailwind-source-Ck2WyTX8.mjs → tailwind-source-eUjG3Kqd.mjs} +1 -1
- package/dist/{tracker-BUpkmn8j.mjs → tracker-CrwJDZl5.mjs} +1 -1
- package/dist/tracker-CwhClHt8.mjs +1 -0
- package/dist/update-Bq2MOPfY.mjs +1 -0
- package/dist/{use-By-V869_.mjs → use-BstBDXM0.mjs} +1 -1
- package/dist/validators-DYxuYau9.mjs +1 -0
- package/dist/{vite-config-DQfi8QwQ.mjs → vite-config-fgVbx8V8.mjs} +1 -1
- package/dist/vite-config-yJsIbnL3.mjs +10 -0
- package/dist/vite-plugin.mjs +1 -1
- package/dist/{watch-orchestrator-B1hlJ10Y.mjs → watch-orchestrator-BoIVJmj8.mjs} +1 -1
- package/dist/watcher-5H9ytV97.mjs +1 -0
- package/dist/{watcher-DN6vT6nw.mjs → watcher-BXDeecbT.mjs} +1 -1
- package/dist/{workspace-CYaUDFd5.mjs → workspace-BRh8wQOD.mjs} +1 -1
- package/dist/{workspace-BBfh7dJY.mjs → workspace-DJBqBvHr.mjs} +1 -1
- package/package.json +4 -1
- package/dist/add-flow-D9HxSmKS.mjs +0 -3
- package/dist/batch-push-CT5k2SrS.mjs +0 -1
- package/dist/dev-DtbwBD_E.mjs +0 -1
- package/dist/doctor-Ca2eGyC8.mjs +0 -4
- package/dist/fs-Ce7wcxvx.mjs +0 -1
- package/dist/history-BNX-3W-p.mjs +0 -1
- package/dist/history-Da5gEptz.mjs +0 -1
- package/dist/injector-CwNZ9rDe.mjs +0 -1
- package/dist/logger-Oo2Slehd.mjs +0 -1
- package/dist/output-B7NC4xgj.mjs +0 -1
- package/dist/preflight-tgLzruAR.mjs +0 -1
- package/dist/publish-DViw9ie6.mjs +0 -1
- package/dist/publisher-PQIqCt7r.mjs +0 -2
- package/dist/push-ChVt0ofE.mjs +0 -1
- package/dist/push-engine-IoOaMeZe.mjs +0 -1
- package/dist/remove-BVr3n-3t.mjs +0 -1
- package/dist/remove-Ch5tlQkh.mjs +0 -1
- package/dist/reset-DD5BaA6m.mjs +0 -1
- package/dist/restore-DaJjdT2B.mjs +0 -1
- package/dist/shell-DQfdqK0J.mjs +0 -1
- package/dist/tracker-Cf_gNhit.mjs +0 -1
- package/dist/update-BuQUMzU2.mjs +0 -1
- package/dist/validators-C0_prNkT.mjs +0 -1
- package/dist/vite-config-Bvv75_oH.mjs +0 -10
- package/dist/watch-orchestrator-5eaHlofc.mjs +0 -1
- package/dist/watcher-LcNLwOgA.mjs +0 -1
package/README.md
CHANGED
|
@@ -114,8 +114,10 @@ See [Migrating from yalc](docs/migrating-from-yalc.md).
|
|
|
114
114
|
- [Bundlers](docs/bundlers.md) and [monorepos](docs/monorepo.md)
|
|
115
115
|
- [Troubleshooting](docs/troubleshooting.md) and [FAQ](docs/faq.md)
|
|
116
116
|
- [CI/CD](docs/ci-cd.md): Knarr is for local development; use canary releases in CI.
|
|
117
|
-
- [Programmatic API](docs/api.md)
|
|
118
|
-
- [
|
|
117
|
+
- [Programmatic API](docs/api.md)
|
|
118
|
+
- [Stability policy](docs/adr/0005-stability-policy-for-1-0.md): what 1.x keeps stable
|
|
119
|
+
- [Contributing](CONTRIBUTING.md), [governance](GOVERNANCE.md), and [roadmap](ROADMAP.md)
|
|
120
|
+
- [Security policy](SECURITY.md) and [assurance case](docs/assurance-case.md)
|
|
119
121
|
|
|
120
122
|
## Acknowledgments
|
|
121
123
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{n as e}from"./shell-CdudI-mX.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-BohPY8Sk.mjs";import{t as a}from"./publisher-C_10LOjC.mjs";import{i as o,n as s,r as c,t as l}from"./injector-BASQ1zbM.mjs";import{d as u,h as d,n as f,o as p}from"./tracker-CrwJDZl5.mjs";import{c as m}from"./fs-CQN7XoRJ.mjs";import{t as h}from"./package-manager-C4Jxwe0t.mjs";import{t as g}from"./build-detect-Bf2HAfXm.mjs";import{n as _}from"./bundler-detect-DGb3enFz.mjs";import{i as v,o as y}from"./init-helpers-cPiBMjll.mjs";import{t as b}from"./nextjs-config-DEsPFOHp.mjs";import{i as x}from"./paths-CE53uQIL.mjs";import{t as S}from"./timer-BZNWRS3O.mjs";import{t as C}from"./output-GYAldYAZ.mjs";import{t as w}from"./errors-DRugrv36.mjs";import{n as T,o as E,r as D}from"./logger-Bib7d-kD.mjs";import{i as O,r as k}from"./dry-run-dHs1UCw6.mjs";import{a as A,o as j,s as M}from"./validators-DYxuYau9.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),E,D=null,O=!1,A=!1,N;function P(t,r,i){n.info(`Done in ${s.elapsed()}`);let a={package:_,version:t,...r,elapsed:s.elapsedMs(),buildCmd:D,buildRan:O,buildSkipped:A,nextSteps:i};return e.emitOutput!==!1&&C(a),T()&&k(),a}if(V(_,e.packageArg),b)try{j(b)}catch{w(`Invalid package version "${b}" in "${e.packageArg}".`),process.exit(1)}let F=(await h(g)).resolve(),I=F.packageManager;if(F.nodeModulesCompatible||(n.error(F.incompatibilityReason),process.exit(1)),e.from){let t=L(e.from);E=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}...`),N=await a(t)}let R=b??(N?.name===_?N.version:void 0),z=R?await r(_,R):await i(_),W=N?.name===_&&(!b||N.version===b);if(!z&&N&&W&&T())return n.info(`[dry-run] Would link ${N.name}@${N.version} -> node_modules/${_} (consumer changes are not listed until the package is in the store)`),P(N.version,{copied:0,skipped:0,binLinks:0},[]);if(!z){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,I),n.success(`Auto-initialized knarr (consumer mode)`)),n.info(`Detected package manager: ${I}`);let q=await p(g,_);q&&(q.version===z.version?n.info(`Updating ${_}@${z.version} (already linked)`):n.info(`Updating ${_}: ${q.version} -> ${z.version}`));let J=q?q.backupExists:await l(g,_,I);!q&&J&&n.info(`Backed up existing ${_} installation`),await M(g,_,z.version),await K(g,_,F),await G(z,g,F,e.yes??!1);let Y=await c(z,g,I);n.success(`Linked ${_}@${z.version} -> node_modules/${_} (${Y.copied} files copied, ${Y.skipped} unchanged)`),Y.binLinks>0&&n.info(`Created ${Y.binLinks} bin link(s)`);let X={version:z.version,contentHash:z.meta.contentHash,linkedAt:(/* @__PURE__ */ new Date()).toISOString(),sourcePath:z.meta.sourcePath,backupExists:J,packageManager:I,buildId:z.meta.buildId??``};await f(g,_,X),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 Z=E?[`cd ${E} && knarr dev`]:[];E&&n.info(`Next: ${t(E,process.cwd(),await U(E))}`);let{copied:Q,skipped:$,binLinks:ee}=Y;return P(z.version,{copied:Q,skipped:$,binLinks:ee},Z)}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 E(`[add] Detected build command but skipping in json mode: ${r}`),{buildCmd:r,ran:!1,skipped:!0};return n.info(T()?`[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-BRh8wQOD.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())E(`[add] Missing transitive deps (json mode): ${o.join(`, `)}`);else if(i){let e=r.installCommand(o),t=r.formatCommand(e);n.info(T()?`[dry-run] Would install missing dependencies: ${o.join(`, `)}`:`Installing missing dependencies: ${o.join(`, `)}`);let i=await r.run(e);i&&!T()?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&&!T()?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-fgVbx8V8.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(T()?`[dry-run] Would install knarr as devDependency`:`Installing knarr as devDependency...`);let a=await r.run(e);a&&!T()?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-eUjG3Kqd.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 T()?(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"./dist-jMqCJR3W.mjs";import{t}from"./timer-BZNWRS3O.mjs";import{n}from"./output-
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{t}from"./timer-BZNWRS3O.mjs";import{n}from"./output-GYAldYAZ.mjs";import{t as r}from"./add-flow-CffgNcwl.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 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{n as t,r as n,t as r}from"./workspace-DJBqBvHr.mjs";import{n as i,t as a}from"./topo-sort-I086ZoiN.mjs";import{t as o}from"./push-engine-0nZ1vhhj.mjs";import{t as s}from"./timer-BZNWRS3O.mjs";import{i as c,o as l}from"./logger-Bib7d-kD.mjs";import{t as u}from"./output-GYAldYAZ.mjs";async function d(d,p={}){let m=new s,h=await t(d),g=n(h);if(g.packages.length===0){e.warn(`No publishable workspace packages found`),u({packages:0,pushed:0,failed:[],skipped:[],elapsed:m.elapsedMs(),summaries:[]});return}let _=h.packages.length-g.packages.length;_>0&&e.info(`Skipping ${_} private workspace package(s)`);let v;try{v=i(g.adjacency)}catch(t){throw t instanceof a&&e.error(`Cannot push: ${t.message}`),t}let y=new Map(g.packages.map(e=>[e.name,e.dir]));e.info(`Pushing ${v.length} packages in dependency order`),l(`[batch-push] Order: ${v.join(` → `)}`);let b=r(g.adjacency),x=new Set(p.skipPackages??[]);for(let e of[...x])f(e,b,x);let S=0,C=[],w=[],T=[],E=c();for(let t of v){let n=y.get(t);if(n){if(x.has(t))l(`[batch-push] Skipping ${t}: dependency build/push failed`),w.push(t);else try{let e=await o(n,{...p,emitOutput:E});T.push(e),e.failedConsumers>0?(C.push(t),f(t,b,x)):S++}catch(n){e.warn(`Failed to push ${t}: ${n instanceof Error?n.message:String(n)}`),C.push(t),f(t,b,x)}}}E||u({packages:v.length,pushed:S,failed:C,skipped:w,elapsed:m.elapsedMs(),summaries:T});let D=[C.length>0?`${C.length} failed`:null,w.length>0?`${w.length} skipped`:null].filter(e=>e!==null),O=`Pushed ${S}/${v.length} packages in ${m.elapsed()}`+(D.length>0?` (${D.join(`, `)})`:``);if(C.length>0)throw e.warn(O),Error(`Failed to push ${C.length} workspace package(s)`);w.length>0?e.warn(O):e.success(O)}function f(e,t,n){for(let r of t.get(e)??[])n.has(r)||(n.add(r),f(r,t,n))}export{d as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as e}from"./fs-
|
|
1
|
+
import{c as e}from"./fs-CQN7XoRJ.mjs";import{join as t}from"node:path";const n=[[`vite`,[`vite.config.ts`,`vite.config.js`,`vite.config.mts`,`vite.config.mjs`]],[`next`,[`next.config.js`,`next.config.ts`,`next.config.mjs`]],[`webpack`,[`webpack.config.js`,`webpack.config.ts`]],[`turbo`,[`turbo.json`]],[`rollup`,[`rollup.config.js`,`rollup.config.ts`,`rollup.config.mjs`]]];async function r(r){for(let[i,a]of n)for(let n of a){let a=t(r,n);if(await e(a))return{type:i,configFile:a}}return{type:null,configFile:null}}async function i(r){let i=n.flatMap(([n,i])=>i.map(async i=>({type:n,configFile:t(r,i),found:await e(t(r,i))}))),a=await Promise.all(i),o=/* @__PURE__ */ new Set,s=[];for(let{type:e,configFile:t,found:n}of a)n&&!o.has(e)&&(o.add(e),s.push({type:e,configFile:t}));return s}export{r as n,i 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-Cgd-Rd2c.mjs";import{n as i,t as a}from"./output-GYAldYAZ.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-CrwJDZl5.mjs";import{a,r as o,s}from"./store-BohPY8Sk.mjs";import{a as c,c as l,f as u}from"./fs-CQN7XoRJ.mjs";import{t as d}from"./format-IsfSiyGV.mjs";import{n as f,o as p}from"./logger-Bib7d-kD.mjs";import{r as m}from"./dry-run-dHs1UCw6.mjs";import{n as h,t as g}from"./output-GYAldYAZ.mjs";import{f as _,p as v}from"./paths-CE53uQIL.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);p(`[clean] Protected packages (corrupt state): ${[...A].join(`, `)}`)}p(`[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)){p(`[clean] Preserving ${t} (consumer state unreadable)`);continue}let n=Date.now()-new Date(e.meta.publishedAt).getTime();if(n<S){p(`[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?p(`[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`),g({removedConsumers:w,removedPackages:T,removedEntries:0,removedOrphans:0,reclaimedBytes:0,elapsed:C.elapsedMs()});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())p(`[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())p(`[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()}),f()&&m()}});export{C as default};
|
package/dist/cli.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{n as e,t}from"./dist-jMqCJR3W.mjs";import{t as n}from"./logger-
|
|
2
|
+
import{n as e,t}from"./dist-jMqCJR3W.mjs";import{t as n}from"./logger-Bib7d-kD.mjs";import{n as r,t as i}from"./console-C8XtlRyM.mjs";import{availableParallelism as a}from"node:os";function o(){console.log(r.yellow(`
|
|
3
3
|
_ __
|
|
4
4
|
| |/ /_ __ __ _ _ __ _ __
|
|
5
5
|
| ' /| '_ \\ / _\` | '__| '__|
|
|
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(`--
|
|
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(`--version`),d=s.includes(`--help`)||s.includes(`-h`)||u;if(!l&&!d&&process.stdin.isTTY){o();let e=await f();e&&process.argv.splice(2,0,e)}else!l&&!u&&o();async function f(){try{let{readConsumerStateSafe:e}=await import(`./tracker-CwhClHt8.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 p=t({meta:{name:`knarr`,version:`1.0.0-canary.0`,description:`Local npm package development - copies built files into consumer node_modules`},args:{verbose:{type:`boolean`,alias:`v`,description:`Enable verbose debug logging`,default:!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-BrtOdn06.mjs`).then(e=>e.default),publish:()=>import(`./publish-eZF0cGPR.mjs`).then(e=>e.default),add:()=>import(`./add-gNa3t7pB.mjs`).then(e=>e.default),use:()=>import(`./use-BstBDXM0.mjs`).then(e=>e.default),remove:()=>import(`./remove-Dc7nNODL.mjs`).then(e=>e.default),push:()=>import(`./push-CSNi4CpT.mjs`).then(e=>e.default),dev:()=>import(`./dev-CjZq04EN.mjs`).then(e=>e.default),restore:()=>import(`./restore-C9JOb13Y.mjs`).then(e=>e.default),list:()=>import(`./list-CRvFrdbY.mjs`).then(e=>e.default),status:()=>import(`./status-jTVBS0Ig.mjs`).then(e=>e.default),explain:()=>import(`./explain-ayyyCGP3.mjs`).then(e=>e.default),update:()=>import(`./update-Bq2MOPfY.mjs`).then(e=>e.default),clean:()=>import(`./clean-0JDjLApX.mjs`).then(e=>e.default),gc:()=>import(`./clean-0JDjLApX.mjs`).then(e=>e.default),doctor:()=>import(`./doctor-CPjy06Ce.mjs`).then(e=>e.default),migrate:()=>import(`./migrate-B0KoRfDB.mjs`).then(e=>e.default),reset:()=>import(`./reset-BRlinr5x.mjs`).then(e=>e.default),rollback:()=>import(`./rollback-DDRBoJt-.mjs`).then(e=>e.default),check:()=>import(`./check-CfY58ssu.mjs`).then(e=>e.default)}});e(p);export{};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{o as e}from"./logger-Bib7d-kD.mjs";import{t}from"./fs-CQN7XoRJ.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./dist-jMqCJR3W.mjs";import{n as t}from"./output-GYAldYAZ.mjs";import{a as n,i as r,o as i,s as a,t as o}from"./push-engine-0nZ1vhhj.mjs";import{t as s}from"./batch-push-Xp-9Gipa.mjs";import{t as c}from"./config-D2dxGdR0.mjs";import{a as l,n as u}from"./logger-Bib7d-kD.mjs";import{r as d}from"./dry-run-dHs1UCw6.mjs";import{resolve as f}from"node:path";var p=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)`},scripts:{type:`boolean`,description:`Run prepack/postpack lifecycle hooks`,negativeDescription:`Skip prepack/postpack lifecycle hooks`,default:!0},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`},cascade:{type:`boolean`,description:`Rebuild dependents when a package rebuilds in --all mode`,negativeDescription:`Disable cascading rebuilds in --all mode`,default:!0}},async run({args:e}){t(),l();let p=f(`.`),m=await c(p),h={runScripts:e.scripts,force:e.force};if(e.all){let t=await n(p,e),r=/* @__PURE__ */ new Set([...t.failedPackages,...t.skippedPackages]);if(t.canPush&&await s(p,{...h,skipPackages:r}),u()){d();return}await i(p,e,h)}else{let t=()=>o(p,h);if(await r(p,e,m)&&await t(),u()){d();return}await a(p,e,t)}}});export{p as default};
|
|
@@ -0,0 +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-CrwJDZl5.mjs";import{n as ee,r as c}from"./store-BohPY8Sk.mjs";import{o as te}from"./injector-BASQ1zbM.mjs";import{c as l,u}from"./fs-CQN7XoRJ.mjs";import{a as ne,f as re,i as d,r as f}from"./paths-CE53uQIL.mjs";import{t as p}from"./package-manager-C4Jxwe0t.mjs";import{n as m}from"./bundler-detect-DGb3enFz.mjs";import{a as h,c as ie,d as ae,l as g,o as _,u as v}from"./init-helpers-cPiBMjll.mjs";import{n as y,t as b}from"./output-GYAldYAZ.mjs";import{n as x,r as S}from"./logger-Bib7d-kD.mjs";import{r as C}from"./dry-run-dHs1UCw6.mjs";import{c as w,i as T,l as E}from"./json-b5d4W58a.mjs";import{lstat as D,readFile as O,stat as k}from"node:fs/promises";import{basename as A,join as j,resolve as M}from"node:path";async function N(e,t={}){let n=[],u=x(),v=t.fix===!0,y=u?`Would `:``;async function b(e,t){let r={fixable:!1,fixed:!1,fixes:[],unfixableReason:null,...e};if(v&&r.fixable&&t){let e=await t();e&&(r.fixed=!u,r.fixes.push(`${y}${e}`))}n.push(r)}let S=(await p(e)).resolve(),C=S.packageManager,D=!S.nodeModulesCompatible,O=!D,k="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`.",M=re();await l(M)?await b({name:`Store directory`,status:`pass`,message:`${(await c()).length} entries in ${M}`}):await b({name:`Store directory`,status:`warn`,message:`Store not found at ${M}. Run 'knarr publish' to create it.`});let N=ne(),{registry:P,reliable:I}=await s();if(!I)await b({name:`Global registry`,status:`fail`,message:`${N} is corrupt or unreadable.`,unfixableReason:i()});else if(await l(N)){let e=Object.values(P).flat().length;await b({name:`Global registry`,status:`pass`,message:`${Object.keys(P).length} packages, ${e} consumer registrations`})}else await b({name:`Global registry`,status:`warn`,message:`No consumers registered yet. Use 'knarr add' to link packages.`});let R=await oe(P),z=R.missingDirectories+R.missingLinks;z>0&&await b({name:`Stale registry entries`,status:`warn`,message:`${z} stale consumer registration(s) found`+(R.unreadableConsumers>0?`; ${R.unreadableConsumers} unreadable state file(s) skipped`:``),fixable:!0},async()=>`remove ${(await o({removeMissingLinks:!0})).removedConsumers} stale consumer registration(s)`);let B=d(e),V=f(e),H=await ce(V),U=await l(B),{state:W,reliable:G}=await r(e),K=H===`file`?`Move or delete ${V}, then run 'knarr init'.`:void 0,q=D?k:K,J=q?{fixable:!1,unfixableReason:q}:{fixable:!0,unfixableReason:null};if(K)await b({name:`Consumer state`,status:`fail`,message:`${V} exists but is not a directory.`,unfixableReason:K}),G=!1;else if(U)G||await b({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:O,fixed:!1,fixes:[],unfixableReason:O?null:k};v&&t.fixable&&(await a(e,e=>{e.packageManager=C,e.role=`consumer`}),t.fixed=!u,t.fixes.push(`${y}create .knarr/state.json`),U=await l(B),{state:W,reliable:G}=await r(e)),n.push(t)}let Y=G?Object.entries(W.links):[];G&&U&&(Y.length>0?await b({name:`Consumer state`,status:`pass`,message:`${Y.length} linked package(s)`}):await b({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 ee(t,n.version);r?r.meta.contentHash===n.contentHash?await b({name:`Store: ${t}`,status:`pass`,message:`${t}@${n.version} in sync`}):await b({name:`Store: ${t}`,status:`warn`,message:`Store has newer content. Run 'knarr update' to sync.`}):await b({name:`Store: ${t}`,status:`fail`,message:`Store entry missing for ${t}@${n.version}. Re-publish it.`});let i;try{i=await te(e,t,n.packageManager,n.version,{warnOnFallback:!1})}catch(e){await b({name:`node_modules: ${t}`,status:`fail`,message:`Cannot resolve package target. ${e instanceof Error?e.message:String(e)}`});continue}if(!await l(i))await b({name:`node_modules: ${t}`,status:`fail`,message:`Missing from node_modules. Run 'knarr restore'.`});else try{let e=await w(j(i,`package.json`)),r=E(e,`name`),a=E(e,`version`);r&&r!==t?await b({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 b({name:`node_modules: ${t}`,status:`warn`,message:`node_modules has v${a} but Knarr linked v${n.version}. Run 'knarr restore'.`}):await b({name:`node_modules: ${t}`,status:`pass`,message:`present`})}catch{await b({name:`node_modules: ${t}`,status:`pass`,message:`present`})}}await b({name:`Package manager`,status:`pass`,message:C}),S.yarnLinkerDiagnostic&&await b({name:`Yarn linker`,...S.yarnLinkerDiagnostic});let X=await m(e);if(X.type?await b({name:`Bundler`,status:`pass`,message:`${X.type}${X.configFile?` (${X.configFile})`:``}`}):await b({name:`Bundler`,status:`warn`,message:`No bundler config detected`}),X.type===`vite`&&X.configFile){let{addKnarrVitePlugin:e,hasKnarrVitePlugin:t}=await import(`./vite-config-fgVbx8V8.mjs`),r=await t(X.configFile);if(r.error)await b({name:`Vite integration`,status:`warn`,message:r.error});else if(r.configured)await b({name:`Vite integration`,status:`pass`,message:`Knarr plugin configured`});else{let t={name:`Vite integration`,status:`warn`,message:`Knarr Vite plugin is missing.`,fixable:O,fixed:!1,fixes:[],unfixableReason:O?null:k};if(v&&t.fixable){let n=await e(X.configFile);n.modified?(t.fixed=!u,t.fixes.push(`${y}add Knarr Vite plugin to ${A(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-BL72LxXy.mjs`);for(let[r]of Y){let i=await t(X.configFile,r);if(i.configured){await b({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&&O,fixed:!1,fixes:[],unfixableReason:i.error??(O?null:k)};if(v&&a.fixable){let t=await e(X.configFile,r);t.modified?(a.fixed=!u,a.fixes.push(`${y}add ${r} to transpilePackages in ${A(X.configFile)}`)):t.error&&(a.unfixableReason=t.error)}n.push(a)}}let Z=j(e,`.gitignore`);await se(Z)?await b({name:`.gitignore`,status:`pass`,message:`.knarr/ is ignored`}):await b({name:`.gitignore`,status:`warn`,message:`.knarr/ not in .gitignore.`,fixable:O,unfixableReason:O?null:k},async()=>await h(Z)?`add .knarr/ to .gitignore`:null);let Q=j(e,`package.json`);if(await l(Q)){let t=await L(Q),n=t?T(t,`scripts`)?.postinstall:void 0;typeof n==`string`&&g(n)?await l(j(e,`.knarr`,`restore.cjs`))?await b({name:`Postinstall restore`,status:`pass`,message:`postinstall re-applies links via .knarr/restore.cjs`}):await b({name:`Postinstall restore`,status:`warn`,message:`.knarr/restore.cjs is missing, so installs won't re-apply links.`,...J},async()=>(await ae(e),`write .knarr/restore.cjs`)):typeof n==`string`&&ie(n)?await F(e,t,n)?await b({name:`Postinstall restore`,status:`pass`,message:`postinstall runs knarr restore`}):n.includes(`knarr restore --silent || node -e "process.exit(0)"`)?await b({name:`Postinstall restore`,status:`warn`,message:`postinstall runs knarr restore, but no local knarr dependency or binary was found, so installs silently drop links.`,...J},async()=>(await _(e),`upgrade postinstall restore hook (works without a global knarr)`)):await b({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 b({name:`Postinstall restore`,status:`warn`,message:`postinstall exists but does not run knarr restore.`,unfixableReason:`Existing postinstall scripts are not merged automatically.`}):await b({name:`Postinstall restore`,status:`warn`,message:`postinstall restore hook is missing.`,...J},async()=>(await _(e),`add postinstall restore hook to package.json`))}else await b({name:`Postinstall restore`,status:`warn`,message:`No package.json found.`});let[$=0,le=0]=process.versions.node.split(`.`).map(e=>parseInt(e,10));return $>22||$===22&&le>=22?await b({name:`Node.js version`,status:`pass`,message:`v${process.versions.node}`}):await b({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:u?n.reduce((e,t)=>e+t.fixes.length,0):0,dryRun:u}}var P=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}){y();let r=M(`.`);n.info(e.fix?`Running Knarr diagnostics with safe fixes...
|
|
2
|
+
`:`Running Knarr diagnostics...
|
|
3
|
+
`);let i=await N(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(x()?`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!`),b(i),i.results.some(e=>e.status===`fail`&&!e.fixed)&&(process.exitCode=1),e.fix&&x()&&!S()&&C()}});async function oe(e){let t=0,n=0,i=0;for(let[a,o]of Object.entries(e))for(let e of o){if(!await l(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 se(e){try{return(await O(e,`utf-8`)).split(`
|
|
4
|
+
`).some(e=>{let t=e.trim();return t===`.knarr/`||t===`.knarr`||t===`/.knarr/`||t===`/.knarr`})}catch{return!1}}async function ce(e){try{return(await k(e)).isDirectory()?`dir`:`file`}catch(t){return u(t)&&t.code===`ENOENT`?await D(e).then(()=>!0,()=>!1)?`file`:`missing`:`file`}}async function F(e,t,n){return v(n)||I(t)?!0:await l(j(e,`node_modules`,`.bin`,`knarr`))||await l(j(e,`node_modules`,`.bin`,`knarr.cmd`))}function I(e){return e?[`dependencies`,`devDependencies`,`optionalDependencies`,`peerDependencies`].some(t=>T(e,t)?.knarr!==void 0):!1}async function L(e){try{return await w(e)}catch{return null}}export{P as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./logger-
|
|
1
|
+
import{r as e}from"./logger-Bib7d-kD.mjs";import{t}from"./console-C8XtlRyM.mjs";import{homedir as n}from"node:os";import{isAbsolute as r,relative as i,sep as a}from"node:path";function o(e,t=process.cwd(),o=n()){let s=t=>{let n=i(t,e);return n!==``&&!n.startsWith(`..`)&&!r(n)?n:n===``?`.`:null},c=s(t);if(c!==null)return c;let l=s(o);return l===null?e:l===`.`?`~`:`~${a}${l}`}const s=[];let c=!1;function l(e){s.push(e)}function u(){return[...s]}function d(){c=!0}function f(){if(s.length===0){t.info(`[dry-run] No mutations would be performed`);return}if(e()){if(c)return;console.log(JSON.stringify({dryRun:!0,mutations:s},null,2)),c=!0;return}let n=/* @__PURE__ */ new Map;for(let e of s){let t=n.get(e.type);t||(t=[],n.set(e.type,t)),t.push(e)}t.info(`\n[dry-run] ${s.length} mutation(s) would be performed:\n`);let r={copy:`Copy`,remove:`Remove`,move:`Move`,mkdir:`Create directory`,write:`Write file`,"bin-link":`Create bin link`,"bin-unlink":`Remove bin link`,"cache-invalidate":`Invalidate cache`,"lock-skip":`Skip lock`,"lifecycle-skip":`Skip lifecycle hook`,"command-skip":`Skip command`};for(let[e,i]of n){t.info(` ${r[e]} (${i.length}):`);for(let e of i.slice(0,20)){let n=e.dest?` → ${o(e.dest)}`:``,r=e.detail?` (${e.detail})`:``;t.info(` ${o(e.path)}${n}${r}`)}i.length>20&&t.info(` ... and ${i.length-20} more`)}}export{l as i,d as n,f as r,u 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{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-BohPY8Sk.mjs";import{o as a}from"./injector-BASQ1zbM.mjs";import{c as o,l as s}from"./tracker-CrwJDZl5.mjs";import{t as c}from"./package-manager-C4Jxwe0t.mjs";import{c as l}from"./fs-CQN7XoRJ.mjs";import{n as u,p as d,s as f}from"./paths-CE53uQIL.mjs";import{n as p,t as m}from"./output-GYAldYAZ.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{n as e,o as t}from"./logger-Bib7d-kD.mjs";import{i as n}from"./dry-run-dHs1UCw6.mjs";import{availableParallelism as r}from"node:os";import{constants as i,copyFile as a,cp as o,lstat as s,mkdir as c,open as l,readFile as u,readdir as d,realpath as f,rename as p,rm as m,stat as h,symlink as g,writeFile as _}from"node:fs/promises";import{dirname as v,join as y,parse as b,relative as x}from"node:path";import{randomUUID as S}from"node:crypto";import{setTimeout as C}from"node:timers/promises";function w(e){let t=0,n=[],r=0,i=()=>{let i=t<e?n[r]:void 0;i&&(r++,t++,i()),r>0&&r===n.length&&(n.length=0,r=0)};return r=>new Promise((a,o)=>{let s=()=>{r().then(e=>{t--,a(e),i()},e=>{t--,o(e),i()})};t<e?(t++,s()):n.push(s)})}const T=w(Math.max(r(),8));function E(e){return e instanceof Error&&`code`in e}const D=/* @__PURE__ */ new Map;function O(e){let{root:t}=b(e);return t||`/`}async function k(r,i,a){if(e()){t(`[dry-run] would copy ${r} → ${i}`),n({type:`copy`,path:r,dest:i});return}a?.ensureParent!==!1&&await c(v(i),{recursive:!0});let o=`${i}${A}${process.pid}-${S()}`;try{await I(r,o,O(i)),await F(o,i)}catch(e){throw await m(o,{force:!0}),e}}const A=`.knarr-tmp-`,j=/\.knarr-tmp-(\d+)-[0-9a-f-]{36}$/;function M(e){let t=j.exec(e)?.[1];if(t===void 0)return!1;try{return process.kill(Number(t),0),!0}catch(e){return E(e)&&e.code===`EPERM`}}const N=[10,20,40,80,160,300,400],P=/* @__PURE__ */ new Set([`EPERM`,`EACCES`,`EBUSY`]);async function F(e,t){for(let n of N)try{await p(e,t);return}catch(e){if(process.platform!==`win32`||!E(e)||!P.has(e.code??``))throw e;await C(n)}await p(e,t)}async function I(e,n,r){let o=D.get(r);if(o===!1)await a(e,n);else if(o===!0)await a(e,n,i.COPYFILE_FICLONE);else try{await a(e,n,i.COPYFILE_FICLONE_FORCE),D.set(r,!0)}catch{D.set(r,!1),t(`[copy] reflink not supported on ${r}, using plain copy`),await a(e,n)}}async function L(e){return(await d(e,{recursive:!0,withFileTypes:!0})).filter(e=>e.isFile()).map(e=>y(e.parentPath,e.name))}async function R(t,r){let i=r.split(/[\\/]/).filter(Boolean),a=t;for(let[t,r]of i.entries()){a=y(a,r);try{let r=await h(a),o=t===i.length-1;if(r.isDirectory()){o&&(e()?n({type:`remove`,path:a}):await m(a,{recursive:!0,force:!0}));continue}if(!o){if(e()){n({type:`remove`,path:a});return}await m(a,{force:!0})}}catch(e){if(E(e)&&e.code===`ENOENT`)return;throw e}}}const z=1048576;async function B(e,t,n){if(n<=z){let[n,r]=await Promise.all([u(e),u(t)]);return n.equals(r)}let r=await l(e,`r`);try{let e=await l(t,`r`);try{let t=Buffer.allocUnsafe(z),n=Buffer.allocUnsafe(z);for(let i=0;;i+=z){let[a,o]=await Promise.all([r.read(t,0,z,i),e.read(n,0,z,i)]);if(a.bytesRead!==o.bytesRead)return!1;if(a.bytesRead===0)return!0;if(!t.subarray(0,a.bytesRead).equals(n.subarray(0,o.bytesRead)))return!1}}finally{await e.close()}}finally{await r.close()}}async function V(r,i,a={}){let o=L(r),s=L(i).catch(e=>{if(E(e)&&e.code===`ENOENT`)return[];throw e}),[c,l]=await Promise.all([o,s]),u=0,d=0,f=await Promise.all(c.map(e=>T(async()=>{let n=x(r,e),o=y(i,n),s=!0;if(a.force)t(`[copy] ${n} (forced)`);else try{let[r,i]=await Promise.all([h(e),h(o)]);i.isFile()?r.size===i.size?await B(e,o,r.size)?(s=!1,t(`[skip] ${n} (unchanged)`)):t(`[copy] ${n} (content differs)`):t(`[copy] ${n} (size differs: ${r.size} vs ${i.size})`):t(`[copy] ${n} (destination is not a file)`)}catch(e){if(E(e)&&(e.code===`ENOENT`||e.code===`ENOTDIR`))t(`[copy] ${n} (new file)`);else throw e}return s?(await R(i,n),await k(e,o),`copied`):`skipped`})));for(let e of f)e===`copied`?u++:d++;let p=new Set(c.map(e=>x(r,e))),g=l.filter(e=>!p.has(x(i,e))&&!M(e));await Promise.all(g.map(r=>T(async()=>{t(`[remove] ${x(i,r)} (no longer in source)`),e()?n({type:`remove`,path:r}):await m(r,{force:!0}).catch(e=>{if(!E(e)||e.code!==`ENOENT`&&e.code!==`ENOTDIR`&&e.code!==`EISDIR`&&e.code!==`ERR_FS_EISDIR`)throw e})})));let _=g.length;return{copied:u,removed:_,skipped:d}}async function H(r,i){if(e())t(`[dry-run] would move ${r} → ${i}`),n({type:`move`,path:r,dest:i});else try{await p(r,i)}catch(e){if(E(e)&&e.code===`EXDEV`)await o(r,i,{recursive:!0}),await m(r,{recursive:!0,force:!0});else throw e}}async function U(r){e()?(t(`[dry-run] would remove ${r}`),n({type:`remove`,path:r})):await m(r,{recursive:!0,force:!0})}async function W(r){e()?(t(`[dry-run] would ensure dir ${r}`),n({type:`mkdir`,path:r})):await c(r,{recursive:!0})}async function G(r){e()?(t(`[dry-run] would ensure private dir ${r}`),n({type:`mkdir`,path:r})):await c(r,{recursive:!0,mode:448})}async function K(e){try{return await h(e),!0}catch{return!1}}async function q(r,i){if(e()){t(`[dry-run] would write ${r}`),n({type:`write`,path:r});return}let a=`${r}.tmp-${process.pid}-${S()}`;try{await _(a,i),await p(a,r)}catch(e){throw await m(a,{force:!0}),e}}async function J(e){try{let t=await L(e);return(await Promise.all(t.map(e=>h(e).then(e=>e.size).catch(()=>0)))).reduce((e,t)=>e+t,0)}catch{return 0}}async function Y(r,i){if(e())t(`[dry-run] would copy directory ${r} → ${i}`),n({type:`copy`,path:r,dest:i});else try{await o(r,i,{recursive:!0})}catch(e){if(process.platform!==`win32`||!E(e)||e.code!==`EPERM`||e.syscall!==`symlink`||!(await s(r)).isSymbolicLink())throw e;let t=await f(r);if(!(await h(t)).isDirectory())throw e;await c(v(i),{recursive:!0}),await g(t,i,`junction`)}}export{J as a,K as c,H as d,U as f,k as i,V as l,L as n,W as o,w as p,Y as r,G as s,q as t,E as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{c as exists}from"./fs-CQN7XoRJ.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{t as captureHistory}from"./history-COM3Qzmw.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as e,d as t,f as n,o as r,t as i}from"./fs-CQN7XoRJ.mjs";import{c as a,l as o,o as s}from"./paths-CE53uQIL.mjs";import{o as c}from"./logger-Bib7d-kD.mjs";import{o as l}from"./json-b5d4W58a.mjs";import{t as u}from"./validators-DYxuYau9.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),b=d??3,x=JSON.stringify({...h,replacedAt:(/* @__PURE__ */ new Date()).toISOString()},null,2);if(await e(v)){await i(p(v,`.knarr-meta.json`),x),c(`[history] Build ${g} already in history, marked it as just replaced`),await y(a,l,b);return}await r(_);let S=v+`.tmp-${process.pid}`;try{await r(S);let n=p(u,`package`);await e(n)&&await t(n,p(S,`package`)),await i(p(S,`.knarr-meta.json`),x),await t(S,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(S)}await y(a,l,b)}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,replacedAt:r.replacedAt??r.publishedAt,sourcePath:r.sourcePath,packageDir:p(t,`package`)})}catch{}}let s=e=>new Date(e).getTime();return a.sort((e,t)=>s(t.replacedAt)-s(e.replacedAt)||s(t.publishedAt)-s(e.publishedAt)),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,replacedAt:e.replacedAt??e.publishedAt,sourcePath:e.sourcePath,packageDir:p(r,`package`)}}catch{return null}}async function v(o,l,u,f){let g=await _(o,l,u);if(!g)return null;let v=a(o,l),y=s(o,l,u),b=p(y,`package`),x=p(y,`.knarr-meta.json`),S=JSON.stringify({...await m(x),replacedAt:void 0},null,2),C=p(v,`package`),w=p(v,`.knarr-meta.json`);if(!await e(b))throw Error(`History entry ${u} is missing its package directory`);let T=await d(w,`utf-8`).catch(()=>null),E=v+`.restore-old-${process.pid}-${Date.now()}`,D=p(E,`package`),O=!1,k=!1;try{if((await e(C)||T)&&(await r(E),await e(C)&&await t(C,D),T&&await i(p(E,`.knarr-meta.json`),T),O=!0),await t(b,C),k=!0,await i(w,S),await n(y),O)try{await h(o,l,E,f)}finally{await n(E)}}catch(a){throw k&&await e(C)?(await r(y),await t(C,b)):O&&await e(C)&&await n(C),O&&await e(D)&&await t(D,C),T&&await i(w,T),await n(E),a}return c(`[history] Restored build ${u} as current`),g}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};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ interface PublishOptions {
|
|
|
4
4
|
runScripts?: boolean;
|
|
5
5
|
/** Force publish, bypassing hash comparison */
|
|
6
6
|
force?: boolean;
|
|
7
|
-
/** Max historical builds to keep (default: 3). Set to 0 to disable. */
|
|
7
|
+
/** Max historical builds to keep (default: package.json#knarr.historyLimit, else 3). Set to 0 to disable. */
|
|
8
8
|
historyLimit?: number;
|
|
9
9
|
}
|
|
10
10
|
interface PublishResult {
|
|
@@ -36,6 +36,8 @@ interface KnarrMeta {
|
|
|
36
36
|
sourcePath: string;
|
|
37
37
|
/** 8-char hex ID derived from content hash. Missing in pre-buildId store entries. */
|
|
38
38
|
buildId?: string;
|
|
39
|
+
/** When this build stopped being live. Set on history entries only. */
|
|
40
|
+
replacedAt?: string;
|
|
39
41
|
}
|
|
40
42
|
/** A store entry representing a published package */
|
|
41
43
|
interface StoreEntry {
|
|
@@ -82,6 +84,8 @@ interface HistoryEntry {
|
|
|
82
84
|
buildId: string;
|
|
83
85
|
contentHash: string;
|
|
84
86
|
publishedAt: string;
|
|
87
|
+
/** When this build stopped being live. History is ordered by this, newest first. */
|
|
88
|
+
replacedAt: string;
|
|
85
89
|
sourcePath: string;
|
|
86
90
|
/** Path to the history entry's package directory */
|
|
87
91
|
packageDir: string;
|
|
@@ -237,22 +241,13 @@ interface KnarrConfig {
|
|
|
237
241
|
* wrong types are ignored rather than trusted.
|
|
238
242
|
*/
|
|
239
243
|
export declare function loadKnarrConfig(projectDir: string): Promise<KnarrConfig>;
|
|
240
|
-
/**
|
|
241
|
-
* Simple timer for measuring command execution time.
|
|
242
|
-
*/
|
|
243
|
-
export declare class Timer {
|
|
244
|
-
private start;
|
|
245
|
-
/** Return elapsed time in ms */
|
|
246
|
-
elapsedMs(): number;
|
|
247
|
-
/** Return human-readable elapsed time (e.g., "1.2s" or "150ms") */
|
|
248
|
-
elapsed(): string;
|
|
249
|
-
}
|
|
250
244
|
interface PushOptions {
|
|
251
245
|
runScripts?: boolean;
|
|
252
246
|
/** Force copy all files, bypassing hash comparison */
|
|
253
247
|
force?: boolean;
|
|
254
248
|
/** Max historical builds to keep per package */
|
|
255
249
|
historyLimit?: number;
|
|
250
|
+
emitOutput?: boolean;
|
|
256
251
|
}
|
|
257
252
|
interface PushConsumerResult {
|
|
258
253
|
consumerPath: string;
|
|
@@ -262,15 +257,15 @@ interface PushConsumerResult {
|
|
|
262
257
|
skipped: number;
|
|
263
258
|
binLinks: number;
|
|
264
259
|
cacheInvalidations: number;
|
|
265
|
-
reason
|
|
266
|
-
error
|
|
260
|
+
reason: string | null;
|
|
261
|
+
error: string | null;
|
|
267
262
|
}
|
|
268
263
|
interface PushSummary {
|
|
269
264
|
name: string;
|
|
270
265
|
version: string;
|
|
271
266
|
buildId: string;
|
|
272
267
|
noChange: boolean;
|
|
273
|
-
skippedReason
|
|
268
|
+
skippedReason: string | null;
|
|
274
269
|
consumers: number;
|
|
275
270
|
updatedConsumers: number;
|
|
276
271
|
failedConsumers: number;
|
|
@@ -288,15 +283,6 @@ interface PushSummary {
|
|
|
288
283
|
* Shared by both `push` and `dev` commands.
|
|
289
284
|
*/
|
|
290
285
|
export declare function doPush(packageDir: string, options?: PushOptions): Promise<PushSummary>;
|
|
291
|
-
/** Common CLI args shared by push --watch and dev */
|
|
292
|
-
interface WatchArgs {
|
|
293
|
-
build?: string;
|
|
294
|
-
"skip-build"?: boolean;
|
|
295
|
-
debounce?: string;
|
|
296
|
-
cooldown?: string;
|
|
297
|
-
notify?: boolean;
|
|
298
|
-
"no-cascade"?: boolean;
|
|
299
|
-
}
|
|
300
286
|
interface PushAllOptions extends PushOptions {
|
|
301
287
|
/**
|
|
302
288
|
* Workspace packages to skip before pushing. Used by watch-mode initial
|
|
@@ -316,7 +302,7 @@ export declare function doPushAll(startDir: string, options?: PushAllOptions): P
|
|
|
316
302
|
*/
|
|
317
303
|
export declare function captureHistory(name: string, version: string, oldEntryDir: string, historyLimit?: number): Promise<void>;
|
|
318
304
|
/**
|
|
319
|
-
* List all history entries for a package,
|
|
305
|
+
* List all history entries for a package, newest replacedAt first, then newest publishedAt.
|
|
320
306
|
*/
|
|
321
307
|
export declare function listHistory(name: string, version: string): Promise<HistoryEntry[]>;
|
|
322
308
|
/**
|
|
@@ -338,8 +324,6 @@ export declare function pruneHistory(name: string, version: string, limit: numbe
|
|
|
338
324
|
export declare function clearHistory(name: string, version: string): Promise<void>;
|
|
339
325
|
/** Resolve the effective history limit from config or default */
|
|
340
326
|
export declare function resolveHistoryLimit(configValue?: number): number;
|
|
341
|
-
/** Kill the active build process if one is running */
|
|
342
|
-
export declare function killActiveBuild(): void;
|
|
343
327
|
/**
|
|
344
328
|
* Start watching a directory for changes and trigger a callback.
|
|
345
329
|
*
|
|
@@ -356,28 +340,6 @@ export declare function startWatcher(watchDir: string, options: WatchOptions, on
|
|
|
356
340
|
* Run a build command and return true if it succeeds.
|
|
357
341
|
*/
|
|
358
342
|
export declare function runBuildCommand(cmd: string, cwd: string, label?: string): Promise<boolean>;
|
|
359
|
-
/**
|
|
360
|
-
* Orchestrates watch mode for all workspace packages with optional
|
|
361
|
-
* cascading rebuilds. When a package is pushed, its dependents in
|
|
362
|
-
* the workspace are automatically rebuilt and pushed.
|
|
363
|
-
*
|
|
364
|
-
* State machine per package prevents infinite loops:
|
|
365
|
-
* idle → building → idle (normal)
|
|
366
|
-
* building + trigger → queued → building (coalesced)
|
|
367
|
-
* queued + trigger → queued (no-op)
|
|
368
|
-
*/
|
|
369
|
-
export declare class WatchOrchestrator {
|
|
370
|
-
private packages;
|
|
371
|
-
private dependents;
|
|
372
|
-
private cascade;
|
|
373
|
-
private pushOptions;
|
|
374
|
-
constructor(cascade: boolean);
|
|
375
|
-
start(startDir: string, args: WatchArgs, pushOptions: PushOptions): Promise<void>;
|
|
376
|
-
private onPackagePushed;
|
|
377
|
-
private runExclusive;
|
|
378
|
-
private requestRebuild;
|
|
379
|
-
close(): Promise<void>;
|
|
380
|
-
}
|
|
381
343
|
type PackageManagerDetectionSource = "packageManager" | "lockfile" | "yarnArtifact" | "default";
|
|
382
344
|
interface PackageManagerDetection {
|
|
383
345
|
packageManager: PackageManager;
|
|
@@ -447,34 +409,4 @@ interface PreflightIssue {
|
|
|
447
409
|
* Returns an array of issues found (empty = all good).
|
|
448
410
|
*/
|
|
449
411
|
export declare function runPreflightChecks(packageDir: string): Promise<PreflightIssue[]>;
|
|
450
|
-
|
|
451
|
-
* Ring the terminal bell (BEL character).
|
|
452
|
-
* Writes to stderr so it doesn't interfere with --json output on stdout.
|
|
453
|
-
*/
|
|
454
|
-
export declare function ringBell(enabled: boolean): void;
|
|
455
|
-
/** Type guard for Node.js system errors with an error code */
|
|
456
|
-
export declare function isNodeError(err: unknown): err is NodeJS.ErrnoException;
|
|
457
|
-
/** Normalize a file path to use forward slashes (for cross-platform consistency). */
|
|
458
|
-
export declare function normalizePath(p: string): string;
|
|
459
|
-
type MutationType = "copy" | "remove" | "move" | "mkdir" | "write" | "bin-link" | "bin-unlink" | "cache-invalidate" | "lock-skip" | "lifecycle-skip" | "command-skip";
|
|
460
|
-
interface DryRunMutation {
|
|
461
|
-
type: MutationType;
|
|
462
|
-
path: string;
|
|
463
|
-
dest?: string;
|
|
464
|
-
detail?: string;
|
|
465
|
-
}
|
|
466
|
-
/** Record a mutation that was skipped due to --dry-run */
|
|
467
|
-
export declare function recordMutation(mutation: DryRunMutation): void;
|
|
468
|
-
/** Print a summary of all recorded dry-run mutations */
|
|
469
|
-
export declare function printDryRunReport(): void;
|
|
470
|
-
/** Reset recorded mutations (for testing) */
|
|
471
|
-
export declare function resetMutations(): void;
|
|
472
|
-
/**
|
|
473
|
-
* Heuristic to detect configs that are too complex for automatic rewriting.
|
|
474
|
-
* Returns null if safe to rewrite, or a reason string if too complex.
|
|
475
|
-
*/
|
|
476
|
-
export declare function isComplexConfig(content: string): {
|
|
477
|
-
complex: boolean;
|
|
478
|
-
reason?: string;
|
|
479
|
-
};
|
|
480
|
-
export type { ConsumerState, ConsumersRegistry, DryRunMutation, HistoryEntry, InjectOptions, InjectResult, KnarrConfig, KnarrMeta, LinkEntry, MutationType, OwnRecord, PackageJson, PackageManager, PackageManagerDetection, PackageManagerDetectionSource, PreflightIssue, PreflightSeverity, PublishOptions, PublishResult, PushOptions, StoreEntry, WatchOptions, WorkspaceGraph, WorkspacePackage };
|
|
412
|
+
export type { ConsumerState, ConsumersRegistry, HistoryEntry, InjectOptions, InjectResult, KnarrConfig, KnarrMeta, LinkEntry, OwnRecord, PackageJson, PackageManager, PackageManagerDetection, PackageManagerDetectionSource, PreflightIssue, PreflightSeverity, PublishOptions, PublishResult, PushAllOptions, PushConsumerResult, PushOptions, PushSummary, StoreEntry, WatchOptions, WorkspaceGraph, WorkspacePackage };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./publisher-
|
|
1
|
+
import{t as e}from"./publisher-C_10LOjC.mjs";import{a as t,n,r,s as i,t as a}from"./injector-BASQ1zbM.mjs";import{n as o,r as s,t as c}from"./store-BohPY8Sk.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-CrwJDZl5.mjs";import{t as v}from"./push-engine-0nZ1vhhj.mjs";import{t as y}from"./batch-push-Xp-9Gipa.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-COM3Qzmw.mjs";import{i as D,n as O}from"./watcher-BXDeecbT.mjs";import{n as k,r as A}from"./package-manager-C4Jxwe0t.mjs";import{t as j}from"./config-D2dxGdR0.mjs";import{n as M,t as N}from"./topo-sort-I086ZoiN.mjs";import{n as P,t as F}from"./workspace-DJBqBvHr.mjs";import{t as I}from"./preflight-Cgd-Rd2c.mjs";export{N as CycleError,p as addLink,a as backupExisting,F as buildReverseAdjacency,P as buildWorkspaceGraph,E as captureHistory,n as checkMissingDeps,g as cleanStaleConsumers,S as clearHistory,k as detectPackageManager,A 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,x as listHistory,s as listStoreEntries,j as loadKnarrConfig,b as pruneHistory,e as publish,_ as readConsumerState,u as readConsumerStateSafe,d as registerConsumer,t as removeInjected,f as removeLink,C as resolveHistoryLimit,i as restoreBackup,T as restoreHistoryEntry,O as runBuildCommand,I as runPreflightChecks,D as startWatcher,M 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-
|
|
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-CQN7XoRJ.mjs";import{t as a}from"./package-manager-C4Jxwe0t.mjs";import{n as o}from"./bundler-detect-DGb3enFz.mjs";import{t as s}from"./build-detect-Bf2HAfXm.mjs";import{a as c,d as l,r as u}from"./init-helpers-cPiBMjll.mjs";import{t as d}from"./timer-BZNWRS3O.mjs";import{n as f,t as p}from"./output-GYAldYAZ.mjs";import{n as m}from"./logger-Bib7d-kD.mjs";import{r as h}from"./dry-run-dHs1UCw6.mjs";import{n as g}from"./config-D2dxGdR0.mjs";import{m as _}from"./tracker-CrwJDZl5.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-fgVbx8V8.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-
|
|
1
|
+
import{n as e,t}from"./console-C8XtlRyM.mjs";import{c as n,o as r,t as i}from"./fs-CQN7XoRJ.mjs";import{i as a,n as o,s}from"./json-b5d4W58a.mjs";import{r as c}from"./paths-CE53uQIL.mjs";import{m as l}from"./tracker-CrwJDZl5.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-CE53uQIL.mjs";import{c as i,f as a,l as o,o as s,r as c,u as l}from"./fs-CQN7XoRJ.mjs";import{n as u,o as d}from"./logger-Bib7d-kD.mjs";import{i as f}from"./dry-run-dHs1UCw6.mjs";import{t as p}from"./package-manager-C4Jxwe0t.mjs";import{t as m}from"./bundler-detect-DGb3enFz.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,open as ne,readFile as x,readdir as S,readlink as re,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";import{constants as N}from"node:fs";const ie=/[\x00-\x1F\x7F]/,ae=/^[A-Za-z0-9._+-]+$/;function P(e){return e&&ae.test(e)?e:`node`}function oe(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 P(e[0]===`-S`?e[1]:e[0])}return P(i)}async function se(e){try{return oe(await x(e,`utf-8`))}catch{return`node`}}function F(e,t,n=``){if(!t||t===`.`||t===`..`||ie.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 I(e){return e.bin?typeof e.bin==`string`?{[e.name.startsWith(`@`)&&e.name.split(`/`)[1]||e.name]:e.bin}:e.bin:{}}async function L(t,r,i){let a=I(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:F(o,e),cmdPath:F(o,e,`.cmd`),ps1Path:F(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(u()){for(let{linkPath:e}of m)f({type:`bin-link`,path:e,detail:r});return d(`[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),u=n(A(o,s)),f=await se(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%\\${u.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/${u}" $args\nexit $LASTEXITCODE\n`;await E(a,t);let n=`#!/bin/sh\nbasedir=$(dirname "$0")\nexec ${f} "$basedir/${u}" "$@"\n`;await E(r,n)}else{try{await w(r,{force:!0})}catch{}try{await T(u,r),await y(s,493)}catch(t){if(l(t)&&(t.code===`EPERM`||t.code===`EACCES`)){d(`[bin-linker] Symlink failed (${t.code}), using shell wrapper for ${e}`);let n=`#!/bin/sh\nbasedir=$(dirname "$0")\nexec ${f} "$basedir/${u}" "$@"\n`;await E(r,n),await y(r,493)}else throw t}}g++}return g}async function R(e,t){let n=I(t),r=k(e,`node_modules`,`.bin`),i=Object.keys(n).map(e=>({binName:e,linkPath:F(r,e),cmdPath:F(r,e,`.cmd`),ps1Path:F(r,e,`.ps1`)})).filter(e=>!!e.linkPath&&!!e.cmdPath&&!!e.ps1Path);if(u()){for(let{linkPath:e}of i)f({type:`bin-unlink`,path:e});d(`[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 z(r,e,o)&&await w(e,{force:!0}),a&&(await z(r,t,o)&&await w(t,{force:!0}),await z(r,n,o)&&await w(n,{force:!0}))}catch{}}async function z(e,t,r){let i;try{i=await re(t)}catch(e){if(l(e)&&e.code===`ENOENT`)return!1;if(!(l(e)&&e.code===`EINVAL`))throw e}if(i!==void 0){let t=j(r),n=j(e,i);return n===t||n.startsWith(t+M)}let a;try{a=await ne(t,N.O_RDONLY|(N.O_NONBLOCK??0))}catch(e){if(l(e)&&(e.code===`ENOENT`||e.code===`EISDIR`))return!1;throw e}let o;try{if(!(await a.stat()).isFile())return!1;o=await a.readFile(`utf-8`)}finally{await a.close()}let s=n(A(e,r)),c=s.replace(/\//g,`\\`);return o.includes(`${s}/`)||o.includes(`${s}"`)||o.includes(`${c}\\`)||o.includes(`${c}"`)}const ce={next:[`.next/cache`],webpack:[`node_modules/.cache`]},B=/* @__PURE__ */ new Map;async function le(e){if(u())return d(`[dry-run] would invalidate bundler caches for ${e}`),f({type:`cache-invalidate`,path:e}),0;let t=B.get(e);t||(t=await m(e),B.set(e,t));let n=0;for(let r of t){if(!r.type)continue;let t=ce[r.type];if(t)for(let o of t){let t=k(e,o);if(await i(t))try{await a(t),n++,d(`[inject] Invalidated ${r.type} cache: ${o}`)}catch{d(`[inject] Could not clear ${r.type} cache: ${o} (locked?)`)}}}return n}async function ue(e,t,n,r={}){let i=await V(t,e.name,n,e.version,{repairMissingLink:!0});d(`[inject] ${e.name}@${e.version} → ${i}`),await s(i);let a=await Q(i),{copied:c,removed:l,skipped:u}=await o(e.packageDir,i,{force:r.force});d(`[inject] ${c} copied, ${l} removed, ${u} skipped`);let f=c>0||l>0?await le(t):0,p=await Q(e.packageDir);a&&await R(t,a);let m=p?await L(t,e.name,p):0;return m>0&&d(`[inject] Created ${m} bin link(s)`),{copied:c,removed:l,skipped:u,binLinks:m,cacheInvalidations:f}}async function de(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 fe(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 Q(l);f&&await R(e,f),await a(l),await c(s,l);let p=await Q(u()?s:l);if(p){let t=await L(e,n,p);t>0&&d(`[restore] Restored ${t} original bin link(s) for ${n}`)}return await a(s),!0}async function pe(e,t,n,i){let o=r(e,t),s=await V(e,t,n,i),c=await Q(s);c&&await R(e,c),await a(s),j(s)!==j(o)&&await a(o)}async function me(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 he(r,e,t,n)})))).filter(e=>!e.installed).map(e=>e.dep)}async function he(e,t,n,r){return await i(k(n,`node_modules`,e))?!0:r?ge(await V(n,t.name,r,t.version,{warnOnFallback:!1}),e):!1}async function ge(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),u=(await p(t)).resolve(a);if(!u.nodeModulesCompatible)throw Error(u.incompatibilityReason);let f=u.layout===`pnpm`||u.layout===`yarn-pnpm`?u.layout:null;if(!f)return u.layout===`bun`?_e(t,c,n):c;let m=f===`pnpm`?await xe(t):await Se(t,u.virtualStoreFolder);try{let e=await ve(c);if(e){if(!(f===`pnpm`?await Te(m,n,e):await Ee(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),d(`[inject] ${H(f)}: resolved symlink → ${e}`),e}}catch(e){if(!(l(e)&&e.code===`ENOENT`))throw l(e)&&d(`${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 Z(t,n))return d(`[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){d(`[inject] yarn-pnpm: scanning ${A(t,r)||`.`} for ${n}`);let i=await ye(r,n,o);i&&e.push(i)}let r=q(n,f,e);if(r)return d(`[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(d(`[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 d(`[inject] pnpm: exact version match in virtual store → ${i}`),s.repairMissingLink&&await G(c,i,n,f),i}let i=await S(r),a=[];for(let t of i)if(be(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 d(`[inject] pnpm: found in virtual store → ${l}`),s.repairMissingLink&&await G(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 ${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 d(`[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 _e(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(!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`),d(`[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 ve(e){return(await b(e)).isSymbolicLink()?C(e):null}async function W(e,t,n,r){let i=r===`Bun isolated`?r:H(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 G(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(u()){let i=A(a,t);d(`[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=v()===`win32`;await s(a);let c=await C(a).catch(()=>a),p=A(c,t);d(`[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(!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 W(a,t,n,`pnpm`),a}catch(e){if(l(e)&&e.code===`ENOENT`)return null;throw e}}async function ye(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 q(t,`yarn-pnpm`,i)}function be(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 xe(e){let t=k(e,`node_modules`),n=[],r=k(t,`.pnpm`);await J(e,r)&&n.push(r);let i=await Ce(t);if(!i)return n;let a=O(i)?i:j(t,i);return await J(e,a)?(n.some(e=>j(e)===j(a))||n.push(a),n):(d(`[inject] pnpm: ignoring external virtualStoreDir ${a}`),n)}async function Se(e,t){let n=k(e,`node_modules`),r=[],i=k(n,`.store`);if(await J(e,i)&&r.push(i),!t)return r;let a=O(t)?t:j(e,t);return await J(e,a)?(r.some(e=>j(e)===j(a))||r.push(a),r):(d(`[inject] yarn-pnpm: ignoring external pnpmStoreFolder ${a}`),r)}async function J(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 Ce(e){try{return we(await x(k(e,`.modules.yaml`),`utf-8`))}catch(e){if(l(e)&&e.code===`ENOENT`)return null;throw e}}function we(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 Te(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 Ee(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(!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 X(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 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{pe as a,Z as i,me as n,V as o,ue as r,fe as s,de 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{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-CrwJDZl5.mjs";import{i as a}from"./history-COM3Qzmw.mjs";import{n as o,r as s}from"./store-BohPY8Sk.mjs";import{a as c,p as l}from"./fs-CQN7XoRJ.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-GYAldYAZ.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),o={history:d()};if(r.length===0)n.info(`No linked packages in this project`),p(o);else{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.history[e]=r.map(e=>({buildId:e.buildId,publishedAt:e.publishedAt,contentHash:e.contentHash}))}p(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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";let t=!1,n=!1,r=!1,i=!1;function a(){t=process.argv.includes(`--verbose`)||process.argv.includes(`-v`),n=process.argv.includes(`--dry-run`),r=process.argv.includes(`--json`),i=!1,t&&(e.level=4)}function o(){i=!0}function s(){return i}function c(){return n}function l(){return r}function u(n,...r){t&&e.debug(n,...r)}export{o as a,s as i,c as n,u as o,l as r,a as t};
|
|
@@ -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-
|
|
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-CQN7XoRJ.mjs";import{t as o}from"./timer-BZNWRS3O.mjs";import{n as s,t as c}from"./output-GYAldYAZ.mjs";import{n as l,r as u}from"./logger-Bib7d-kD.mjs";import{i as d,r as f}from"./dry-run-dHs1UCw6.mjs";import{n as p,t as m}from"./add-flow-CffgNcwl.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
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-DEsPFOHp.mjs";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./fs-
|
|
1
|
+
import{t as e}from"./fs-CQN7XoRJ.mjs";import{r as t}from"./vite-config-yJsIbnL3.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./console-C8XtlRyM.mjs";import{i as t,n,r}from"./logger-Bib7d-kD.mjs";import{n as i,t as a}from"./dry-run-dHs1UCw6.mjs";function o(e){if(!r())return;let o=t()?void 0:2;n()?(i(),console.log(JSON.stringify(e&&typeof e==`object`&&!Array.isArray(e)?{...e,dryRun:!0,mutations:a()}:{data:e,dryRun:!0,mutations:a()},null,o))):console.log(JSON.stringify(e,null,o))}function s(){r()&&(e.level=2)}export{s as n,o as t};
|