knarr 0.1.3 → 0.2.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 +1 -1
- package/dist/add-Clbi3vJ2.mjs +3 -0
- package/dist/add-flow-DdDziP5M.mjs +5 -0
- package/dist/batch-push-pVkjhRbp.mjs +3 -0
- package/dist/bell-BJuCym_5.mjs +11 -0
- package/dist/bell-CIzHg0kw.mjs +3 -0
- package/dist/bell-UNNirKkz.mjs +3 -0
- package/dist/build-detect-mSo9jKXK.mjs +3 -0
- package/dist/bundler-detect-Cx8_R2hT.mjs +3 -0
- package/dist/check-Boh8WU_W.mjs +3 -0
- package/dist/chokidar-BkIWf7Ix.mjs +3 -0
- package/dist/clean-DHh6fpmR.mjs +3 -0
- package/dist/cli.mjs +4 -4
- package/dist/config-CQpgsGyL.mjs +4 -0
- package/dist/console-BxhMcj-D.mjs +81 -0
- package/dist/console-X31Y_QS5.mjs +3 -0
- package/dist/dev-DeOwxr_7.mjs +3 -0
- package/dist/dist-CFkjiIqD.mjs +7 -0
- package/dist/doctor-XEdsr84Q.mjs +6 -0
- package/dist/dry-run-BxVjpNqJ.mjs +3 -0
- package/dist/errors-CV7G61Hr.mjs +3 -0
- package/dist/explain-BBv3U-D3.mjs +3 -0
- package/dist/format-DRqD29u-.mjs +3 -0
- package/dist/fs-BjaNhdzt.mjs +683 -0
- package/dist/fs-Cf1JTFyh.mjs +3 -0
- package/dist/fs-DUcoWJ1g.mjs +3 -0
- package/dist/hints-Hz3V4h3A.mjs +3 -0
- package/dist/history-BZS2YUIt.mjs +3 -0
- package/dist/history-C5ehozRy.mjs +3 -0
- package/dist/index.d.ts +242 -260
- package/dist/index.mjs +3349 -4669
- package/dist/init-Dwf-EIG3.mjs +4 -0
- package/dist/init-helpers-BfDosqvf.mjs +15 -0
- package/dist/injector-XwK_LBUh.mjs +3 -0
- package/dist/json-C6XtcMC4.mjs +46 -0
- package/dist/json-CWzEb9Rt.mjs +3 -0
- package/dist/list-DcREV9JM.mjs +3 -0
- package/dist/logger-DlikgOlh.mjs +3 -0
- package/dist/migrate-DW5KQeDq.mjs +5 -0
- package/dist/nextjs-config-BfHv8mBE.mjs +3 -0
- package/dist/nextjs-config-CA4N_9VY.mjs +4 -0
- package/dist/output-BxyRer_F.mjs +3 -0
- package/dist/package-manager-DBBQ0XtZ.mjs +13 -0
- package/dist/picomatch-B0_Pxgms.mjs +3 -0
- package/dist/preflight-B17VQJs0.mjs +3 -0
- package/dist/preflight-B8ypfoKV.mjs +3 -0
- package/dist/publish-BLk5_qx1.mjs +3 -0
- package/dist/publisher-Br4Od-iL.mjs +4 -0
- package/dist/push-C6UFcNGO.mjs +3 -0
- package/dist/push-engine-D3rfg2Tj.mjs +3 -0
- package/dist/remove-Bz9dNgDM.mjs +3 -0
- package/dist/remove-DMj6k2PK.mjs +3 -0
- package/dist/reset--AuvAPTc.mjs +3 -0
- package/dist/restore-CIBe2F1d.mjs +3 -0
- package/dist/rollback-CFLIncnW.mjs +3 -0
- package/dist/rolldown-runtime-BZbIAPMk.mjs +3 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/dist/shell-RQ7Hf1kp.mjs +3 -0
- package/dist/status-Dy-e_RtI.mjs +3 -0
- package/dist/store-BNeGfW_b.mjs +3 -0
- package/dist/tailwind-source-Cgva0Hte.mjs +5 -0
- package/dist/timer-DqgB175x.mjs +3 -0
- package/dist/topo-sort-DOCpHjT7.mjs +3 -0
- package/dist/topo-sort-yd4jxr_E.mjs +3 -0
- package/dist/tracker-DXSo5wXO.mjs +3 -0
- package/dist/tracker-DofCXLTP.mjs +3 -0
- package/dist/update-Dacjzw4f.mjs +3 -0
- package/dist/use-BSCV4IQ5.mjs +3 -0
- package/dist/vite-config-CbYEhn5K.mjs +3 -0
- package/dist/vite-config-DqxvL5TW.mjs +12 -0
- package/dist/vite-plugin.d.ts +6 -5
- package/dist/vite-plugin.mjs +206 -211
- package/dist/watch-orchestrator-CghvwrNS.mjs +3 -0
- package/dist/watcher-Bw_qcI0M.mjs +3 -0
- package/dist/webpack-plugin.d.ts +29 -30
- package/dist/webpack-plugin.mjs +140 -138
- package/dist/workspace-D4vhzpO4.mjs +3 -0
- package/dist/workspace-DVY5o1g8.mjs +3 -0
- package/dist/xxhash-wasm-D_QjdUuv.mjs +3 -0
- package/package.json +21 -30
- package/dist/add-LQ6WMCGD.mjs +0 -3
- package/dist/bell-SIN4ERLS.mjs +0 -2
- package/dist/check-7CJHAF6Y.mjs +0 -6
- package/dist/chokidar-2G63V464.mjs +0 -4
- package/dist/chunk-3SXN6MQL.mjs +0 -4
- package/dist/chunk-7GCKCCHU.mjs +0 -3
- package/dist/chunk-BH2WXCLS.mjs +0 -4
- package/dist/chunk-CBOYKBSM.mjs +0 -13
- package/dist/chunk-E3HZCU3S.mjs +0 -5
- package/dist/chunk-G7HFTV5Y.mjs +0 -3
- package/dist/chunk-HVN6HBWZ.mjs +0 -3
- package/dist/chunk-ICU4V73X.mjs +0 -3
- package/dist/chunk-IP5ROSRE.mjs +0 -3
- package/dist/chunk-J6HZHQVL.mjs +0 -3
- package/dist/chunk-K6OAYJKS.mjs +0 -6
- package/dist/chunk-KRX4JX6V.mjs +0 -4
- package/dist/chunk-KUQULMM6.mjs +0 -3
- package/dist/chunk-L7O2RSTN.mjs +0 -3
- package/dist/chunk-M3TRMEJV.mjs +0 -3
- package/dist/chunk-MN4DV2NO.mjs +0 -3
- package/dist/chunk-N3B2JO4H.mjs +0 -13
- package/dist/chunk-NGPAGRK4.mjs +0 -7
- package/dist/chunk-NV3ASN6X.mjs +0 -3
- package/dist/chunk-OQDZJP55.mjs +0 -3
- package/dist/chunk-QEH5VHRO.mjs +0 -13
- package/dist/chunk-QFHYSC3K.mjs +0 -3
- package/dist/chunk-QHNHLR6T.mjs +0 -3
- package/dist/chunk-RIHOZDFW.mjs +0 -22
- package/dist/chunk-SMR4HT6A.mjs +0 -3
- package/dist/chunk-SPHWZS5P.mjs +0 -3
- package/dist/chunk-U6O35NZ7.mjs +0 -3
- package/dist/chunk-W2MMKBWU.mjs +0 -3
- package/dist/chunk-WBTSRLB6.mjs +0 -7
- package/dist/chunk-WN3DOKIM.mjs +0 -3
- package/dist/chunk-XDWZZBCM.mjs +0 -3
- package/dist/chunk-Z5K6DFA6.mjs +0 -3
- package/dist/clean-EJIYYQZM.mjs +0 -3
- package/dist/dev-WU5KB5PJ.mjs +0 -3
- package/dist/doctor-W2G34POC.mjs +0 -6
- package/dist/explain-LZLNIMVZ.mjs +0 -5
- package/dist/fs-NU36NNEG.mjs +0 -2
- package/dist/history-MLJHRV3Q.mjs +0 -2
- package/dist/init-SNG5LBZK.mjs +0 -7
- package/dist/list-4PTHMIQ4.mjs +0 -5
- package/dist/migrate-USY26Y5R.mjs +0 -8
- package/dist/nextjs-config-T5D6LOJE.mjs +0 -2
- package/dist/preflight-IXICTR6G.mjs +0 -2
- package/dist/publish-2IH7IQV4.mjs +0 -3
- package/dist/push-W3TM2QYK.mjs +0 -3
- package/dist/remove-MVQOIN2I.mjs +0 -2
- package/dist/reset-BTOJ54MJ.mjs +0 -3
- package/dist/restore-TWOOF2BN.mjs +0 -3
- package/dist/rollback-CFYSE5YG.mjs +0 -3
- package/dist/status-3ZXM3CRH.mjs +0 -4
- package/dist/tailwind-source-HCTY2XDU.mjs +0 -5
- package/dist/topo-sort-ZNGR6D7M.mjs +0 -2
- package/dist/tracker-QAKEXYUJ.mjs +0 -2
- package/dist/update-TGGCUOOO.mjs +0 -3
- package/dist/use-4Z5KXRVR.mjs +0 -3
- package/dist/vite-config-XOGAKYGQ.mjs +0 -2
- package/dist/watch-orchestrator-6BQYU5YS.mjs +0 -3
- package/dist/watcher-ES2APFH4.mjs +0 -3
- package/dist/workspace-T6PNO4L3.mjs +0 -2
- package/dist/xxhash-wasm-I6Q3T2SL.mjs +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire as __cr}from"node:module";globalThis.require=__cr(import.meta.url);
|
|
3
|
+
import"./rolldown-runtime-BZbIAPMk.mjs";import{i as e,n as t}from"./logger-DlikgOlh.mjs";import{t as n}from"./console-X31Y_QS5.mjs";import{l as r,o as i}from"./json-CWzEb9Rt.mjs";import{i as a}from"./dry-run-BxVjpNqJ.mjs";import{availableParallelism as o,homedir as s}from"node:os";import{constants as c,copyFile as l,cp as u,lstat as d,mkdir as f,readFile as p,readdir as m,realpath as h,rename as g,rm as _,stat as v,symlink as y,utimes as b,writeFile as x}from"node:fs/promises";import{dirname as S,isAbsolute as C,join as w,parse as T,relative as E,resolve as D}from"node:path";import{createHash as O}from"node:crypto";const k=/^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/,A=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/,j=/[\x00-\x1F\x7F]/;function validatePackageName(e){if(!e||e.length>214||j.test(e)||e.includes(`\\`)||e.includes(`//`)||e.split(`/`).some(e=>e===`.`||e===`..`)||!k.test(e))throw Error(`Invalid package name "${e}"`)}function validatePackageVersion(e){if(!e||j.test(e)||e.includes(`/`)||e.includes(`\\`)||e.includes(`..`)||!A.test(e))throw Error(`Invalid package version "${e}"`)}function validatePackageIdentity(e,t){validatePackageName(e),validatePackageVersion(t)}function isKnarrMeta(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.contentHash==`string`&&typeof t.publishedAt==`string`&&typeof t.sourcePath==`string`&&(t.buildId===void 0||typeof t.buildId==`string`)&&(t.schemaVersion===void 0||typeof t.schemaVersion==`number`)}function isLinkEntry(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.version==`string`&&typeof t.contentHash==`string`&&typeof t.linkedAt==`string`&&typeof t.sourcePath==`string`&&typeof t.backupExists==`boolean`&&typeof t.packageManager==`string`&&[`npm`,`pnpm`,`yarn`,`bun`].includes(t.packageManager)&&(t.buildId===void 0||typeof t.buildId==`string`)}function isConsumerState(e){if(typeof e!=`object`||!e)return!1;let t=e;if(t.version!==`1`||typeof t.links!=`object`||t.links===null)return!1;let n=t.links;for(let e of Object.values(n))if(!isLinkEntry(e))return!1;return!0}async function warnVersionMismatch(e,t,a){try{let o=await p(w(e,`package.json`),`utf-8`),s=i(o,`package.json`),c=r(s,`dependencies`)[t]??r(s,`devDependencies`)[t]??r(s,`peerDependencies`)[t];if(!c||/^(workspace:|catalog:|\*)/.test(c))return;let l=c.match(/(\d+)\.\d+\.\d+/);if(!l?.[1])return;parseInt(l[1],10)!==parseInt(a.split(`.`)[0]??``,10)&&n.warn(`Version mismatch: store has ${t}@${a} but your package.json declares "${c}". Consider updating your dependency range.`)}catch{}}function isConsumersRegistry(e){if(typeof e!=`object`||!e)return!1;let t=e;for(let e of Object.values(t)){if(!Array.isArray(e))return!1;for(let t of e)if(typeof t!=`string`)return!1}return!0}function assertInside(e,t,n){let r=D(e),i=D(t),a=E(r,i);if(a!==``&&(a.startsWith(`..`)||C(a)))throw Error(`${n} escapes expected directory: ${t}`)}function getKnarrHome(){return process.env.KNARR_HOME||w(s(),`.knarr`)}function getStorePath(){return w(getKnarrHome(),`store`)}function getConsumersPath(){return w(getKnarrHome(),`consumers.json`)}function encodePackageName(e){return validatePackageName(e),e.replace(/\//g,`+`)}function decodePackageName(e){if(e.startsWith(`@`)){let t=e.indexOf(`+`);if(t!==-1)return e.slice(0,t)+`/`+e.slice(t+1)}return e}function getStoreEntryPath(e,t){validatePackageIdentity(e,t);let n=getStorePath(),r=w(n,`${encodePackageName(e)}@${t}`);return assertInside(n,r,`Store entry path`),r}function getStorePackagePath(e,t){return w(getStoreEntryPath(e,t),`package`)}function getStoreMetaPath(e,t){return w(getStoreEntryPath(e,t),`.knarr-meta.json`)}function getStoreHistoryPath(e,t){return w(getStoreEntryPath(e,t),`history`)}function getHistoryEntryPath(e,t,n){if(!/^[a-f0-9]{8,64}$/i.test(n))throw Error(`Invalid build id "${n}"`);return w(getStoreHistoryPath(e,t),n)}function getConsumerKnarrDir(e){return w(e,`.knarr`)}function getConsumerStatePath(e){return w(e,`.knarr`,`state.json`)}function getConsumerBackupPath(e,t){validatePackageName(t);let n=w(e,`.knarr`,`backups`),r=w(n,encodePackageName(t));return assertInside(n,r,`Backup path`),r}function normalizePath(e){return e.replace(/\\/g,`/`)}function getNodeModulesPackagePath(e,t){validatePackageName(t);let n=w(e,`node_modules`),r=w(n,t);return assertInside(n,r,`node_modules package path`),r}function pLimit(e){let t=0,n=[],r=0,next=()=>{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((i,a)=>{let run=()=>{r().then(e=>{t--,i(e),next()},e=>{t--,a(e),next()})};t<e?(t++,run()):n.push(run)})}let M=null;function getXXHash(){return M||=import(`./xxhash-wasm-D_QjdUuv.mjs`).then(e=>e.default()).catch(e=>{throw M=null,e}),M}const N=pLimit(Math.max(o(),8)),P=/* @__PURE__ */ new Map;async function computeContentHash(t,n,r=/* @__PURE__ */ new Map){let i=new Map(t.map(e=>[normalizePath(E(n,e)),e]));for(let e of r.keys())i.has(e)||i.set(e,w(n,e));let a=[...i.entries()].sort(([e],[t])=>e.localeCompare(t)),o=new Set(i.values()),s=0,c=await Promise.all(a.map(([e,t])=>N(async()=>{let n=r.get(e);if(n!==void 0)return{rel:e,content:Buffer.isBuffer(n)?n:Buffer.from(n)};let i=await v(t),a=P.get(t);if(a&&a.mtimeMs===i.mtimeMs&&a.size===i.size)return s++,{rel:e,content:a.content};let o=await p(t);return P.set(t,{mtimeMs:i.mtimeMs,size:i.size,content:o}),{rel:e,content:o}})));for(let e of P.keys())o.has(e)||P.delete(e);e(`[hash] Computing content hash for ${a.length} files (${s} cached)`);let l=O(`sha256`),u=Buffer.alloc(4);for(let{rel:e,content:t}of c)l.update(e),l.update(`\0`),u.writeUInt32LE(t.length),l.update(u),l.update(t);let d=`sha256v2:`+l.digest(`hex`);return e(`[hash] Result: ${d.slice(0,20)}...`),d}async function hashFile(e,t){let n=t??(await v(e)).size,r=await getXXHash();if(n>1048576)return hashFileStream(e,r);let i=await p(e);return r.h64Raw(i).toString(16)}async function hashFileStream(e,t){let{createReadStream:n}=await import(`node:fs`),r=t.create64();return new Promise((t,i)=>{let a=n(e);a.on(`data`,e=>r.update(e)),a.on(`end`,()=>t(r.digest().toString(16))),a.on(`error`,i)})}const F=pLimit(Math.max(o(),8));function isNodeError(e){return e instanceof Error&&`code`in e}const I=/* @__PURE__ */ new Map;function volumeRoot(e){let{root:t}=T(e);return t||`/`}async function copyWithCoW(n,r,i){if(t()){e(`[dry-run] would copy ${n} → ${r}`),a({type:`copy`,path:n,dest:r});return}i?.ensureParent!==!1&&await f(S(r),{recursive:!0});let o=volumeRoot(r),s=I.get(o);if(s===!1)await l(n,r);else if(s===!0)await l(n,r,c.COPYFILE_FICLONE);else try{await l(n,r,c.COPYFILE_FICLONE_FORCE),I.set(o,!0)}catch{I.set(o,!1),e(`[copy] reflink not supported on ${o}, using plain copy`),await l(n,r)}}async function collectFiles(e){return(await m(e,{recursive:!0,withFileTypes:!0})).filter(e=>e.isFile()).map(e=>w(e.parentPath,e.name))}async function removeDestinationConflicts(e,n){let r=n.split(/[\\/]/).filter(Boolean),i=e;for(let[e,n]of r.entries()){i=w(i,n);try{let n=await v(i),o=e===r.length-1;if(n.isDirectory()){o&&(t()?a({type:`remove`,path:i}):await _(i,{recursive:!0,force:!0}));continue}if(!o){if(t()){a({type:`remove`,path:i});return}await _(i,{force:!0})}}catch(e){if(isNodeError(e)&&e.code===`ENOENT`)return;throw e}}}async function incrementalCopy(n,r,i={}){let o=collectFiles(n),s=collectFiles(r).catch(e=>{if(isNodeError(e)&&e.code===`ENOENT`)return[];throw e}),[c,l]=await Promise.all([o,s]),u=0,d=0,f=await Promise.all(c.map(a=>F(async()=>{let o=E(n,a),s=w(r,o),c=!0,l=null;if(i.force)e(`[copy] ${o} (forced)`);else try{let[t,n]=await Promise.all([v(a),v(s)]);if(l={atime:t.atime,mtime:t.mtime},t.size!==n.size)e(`[copy] ${o} (size differs: ${t.size} vs ${n.size})`);else if(t.mtimeMs===n.mtimeMs)c=!1,e(`[skip] ${o} (size+mtime match)`);else{let[r,i]=await Promise.all([hashFile(a,t.size),hashFile(s,n.size)]);r===i?(c=!1,e(`[skip] ${o} (unchanged)`)):e(`[copy] ${o} (hash differs)`)}}catch(t){if(isNodeError(t)&&(t.code===`ENOENT`||t.code===`ENOTDIR`))e(`[copy] ${o} (new file)`);else throw t}if(c){if(await removeDestinationConflicts(r,o),await copyWithCoW(a,s),t())return`copied`;if(!l){let e=await v(a);l={atime:e.atime,mtime:e.mtime}}return await b(s,l.atime,l.mtime),`copied`}return`skipped`})));for(let e of f)e===`copied`?u++:d++;let p=new Set(c.map(e=>E(n,e))),m=l.filter(e=>!p.has(E(r,e)));await Promise.all(m.map(n=>F(async()=>{e(`[remove] ${E(r,n)} (no longer in source)`),t()?a({type:`remove`,path:n}):await _(n,{force:!0}).catch(e=>{if(!isNodeError(e)||e.code!==`ENOENT`&&e.code!==`ENOTDIR`&&e.code!==`EISDIR`&&e.code!==`ERR_FS_EISDIR`)throw e})})));let h=m.length;return{copied:u,removed:h,skipped:d}}async function moveDir(n,r){if(t())e(`[dry-run] would move ${n} → ${r}`),a({type:`move`,path:n,dest:r});else try{await g(n,r)}catch(e){if(isNodeError(e)&&e.code===`EXDEV`)await u(n,r,{recursive:!0}),await _(n,{recursive:!0,force:!0});else throw e}}async function removeDir(n){t()?(e(`[dry-run] would remove ${n}`),a({type:`remove`,path:n})):await _(n,{recursive:!0,force:!0})}async function ensureDir(n){t()?(e(`[dry-run] would ensure dir ${n}`),a({type:`mkdir`,path:n})):await f(n,{recursive:!0})}async function ensurePrivateDir(n){t()?(e(`[dry-run] would ensure private dir ${n}`),a({type:`mkdir`,path:n})):await f(n,{recursive:!0,mode:448})}async function exists(e){try{return await v(e),!0}catch{return!1}}async function atomicWriteFile(n,r){if(t()){e(`[dry-run] would write ${n}`),a({type:`write`,path:n});return}let i=n+`.tmp-${process.pid}-${Date.now()}`;await x(i,r),await g(i,n)}async function dirSize(e){try{let t=await collectFiles(e);return(await Promise.all(t.map(e=>v(e).then(e=>e.size).catch(()=>0)))).reduce((e,t)=>e+t,0)}catch{return 0}}async function copyDir(n,r){if(t())e(`[dry-run] would copy directory ${n} → ${r}`),a({type:`copy`,path:n,dest:r});else try{await u(n,r,{recursive:!0})}catch(e){if(process.platform!==`win32`||!isNodeError(e)||e.code!==`EPERM`||e.syscall!==`symlink`||!(await d(n)).isSymbolicLink())throw e;let t=await h(n);if(!(await v(t)).isDirectory())throw e;await f(S(r),{recursive:!0}),await y(t,r,`junction`)}}export{isConsumersRegistry as A,getStoreEntryPath as C,getStorePath as D,getStorePackagePath as E,warnVersionMismatch as F,validatePackageIdentity as M,validatePackageName as N,normalizePath as O,validatePackageVersion as P,getNodeModulesPackagePath as S,getStoreMetaPath as T,getConsumerBackupPath as _,dirSize as a,getConsumersPath as b,exists as c,moveDir as d,removeDir as f,encodePackageName as g,decodePackageName as h,copyWithCoW as i,isKnarrMeta as j,isConsumerState as k,incrementalCopy as l,pLimit as m,collectFiles as n,ensureDir as o,computeContentHash as p,copyDir as r,ensurePrivateDir as s,atomicWriteFile as t,isNodeError as u,getConsumerKnarrDir as v,getStoreHistoryPath as w,getHistoryEntryPath as x,getConsumerStatePath as y};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire as __cr}from"node:module";globalThis.require=__cr(import.meta.url);
|
|
3
|
+
import"./rolldown-runtime-BZbIAPMk.mjs";import{existsSync as e}from"node:fs";import{delimiter as t,isAbsolute as n,join as r,relative as i}from"node:path";let a;function knarrCommand(n=process.env,i=process.platform){if(n===process.env&&a)return a;let o=n.PATH??n.Path??n.path??``,s=i===`win32`?[`knarr.cmd`,`knarr.exe`,`knarr.ps1`,`knarr`]:[`knarr`],c=i===`win32`?`;`:t,l=o.split(c).filter(Boolean).some(t=>s.some(n=>e(r(t,n))))?`knarr`:`npx knarr`;return n===process.env&&(a=l),l}function displayPath(e,t=process.cwd()){let r=i(t,e),a=r===``?`.`:!n(r)&&r.length<e.length?r:e;return/\s/.test(a)?`"${a}"`:a}function devLoopHint(e,t=process.cwd(),n){return n&&n!==e?`cd ${displayPath(n,t)} && ${knarrCommand()} dev --all`:`cd ${displayPath(e,t)} && ${knarrCommand()} dev`}export{knarrCommand as n,devLoopHint as t};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{createRequire as __cr}from"node:module";globalThis.require=__cr(import.meta.url);
|
|
3
|
+
import"./rolldown-runtime-BZbIAPMk.mjs";import{C as e,c as t,d as n,f as r,j as i,o as a,t as o,w as s,x as c}from"./fs-Cf1JTFyh.mjs";import{i as l}from"./logger-DlikgOlh.mjs";import{a as u}from"./json-CWzEb9Rt.mjs";import{readFile as d,readdir as f}from"node:fs/promises";import{join as p}from"node:path";async function readMetaFile(e){let t=u(await d(e,`utf-8`));if(!i(t))throw Error(`Invalid build metadata: ${e}`);return t}async function captureHistory(e,i,u,d){let f=p(u,`.knarr-meta.json`),m;try{m=await readMetaFile(f)}catch{l(`[history] Could not read meta from ${f}, skipping history capture`);return}let h=m.buildId;if(!h){l(`[history] No buildId in meta, skipping history capture`);return}let g=s(e,i),_=c(e,i,h);if(await t(_)){l(`[history] Build ${h} already in history, skipping`);return}await a(g);let v=_+`.tmp-${process.pid}`;try{await a(v);let e=p(u,`package`);await t(e)&&await n(e,p(v,`package`)),await o(p(v,`.knarr-meta.json`),JSON.stringify(m,null,2)),await n(v,_),l(`[history] Captured build ${h} to history`)}catch(e){l(`[history] Failed to capture history: ${e instanceof Error?e.message:String(e)}`),await r(v)}await pruneHistory(e,i,d??3)}async function listHistory(e,n){let r=s(e,n);if(!await t(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 readMetaFile(n);a.push({buildId:r.buildId??e,contentHash:r.contentHash,publishedAt:r.publishedAt,sourcePath:r.sourcePath,packageDir:p(t,`package`)})}catch{}}return a.sort((e,t)=>new Date(t.publishedAt).getTime()-new Date(e.publishedAt).getTime()),a}async function getHistoryEntry(e,t,n){let r=c(e,t,n),i=p(r,`.knarr-meta.json`);try{let e=await readMetaFile(i);return{buildId:e.buildId??n,contentHash:e.contentHash,publishedAt:e.publishedAt,sourcePath:e.sourcePath,packageDir:p(r,`package`)}}catch{return null}}async function restoreHistoryEntry(i,s,u,f){let m=await getHistoryEntry(i,s,u);if(!m)return null;let h=e(i,s),g=c(i,s,u),_=p(g,`package`),v=p(g,`.knarr-meta.json`),y=await d(v,`utf-8`),b=p(h,`package`),x=p(h,`.knarr-meta.json`);if(!await t(_))throw Error(`History entry ${u} is missing its package directory`);let S=await d(x,`utf-8`).catch(()=>null),C=h+`.restore-old-${process.pid}-${Date.now()}`,w=p(C,`package`),T=!1,E=!1;try{if((await t(b)||S)&&(await a(C),await t(b)&&await n(b,w),S&&await o(p(C,`.knarr-meta.json`),S),T=!0),await n(_,b),E=!0,await o(x,y),await r(g),T)try{await captureHistory(i,s,C,f)}finally{await r(C)}}catch(e){throw E&&await t(b)?(await a(g),await n(b,_)):T&&await t(b)&&await r(b),T&&await t(w)&&await n(w,b),S&&await o(x,S),await r(C),e}return l(`[history] Restored build ${u} as current`),m}async function pruneHistory(e,t,n){if(n<0)return 0;let i=await listHistory(e,t);if(i.length<=n)return 0;let a=i.slice(n),o=0;for(let n of a){let i=c(e,t,n.buildId);try{await r(i),o++,l(`[history] Pruned old build ${n.buildId}`)}catch{}}return o}function resolveHistoryLimit(e){return e??3}export{resolveHistoryLimit as a,pruneHistory as i,getHistoryEntry as n,restoreHistoryEntry as o,listHistory as r,captureHistory as t};
|