@visulima/package 5.0.10 → 5.0.11
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/CHANGELOG.md +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/lockfile.js +1 -1
- package/dist/monorepo.js +1 -1
- package/dist/package-json.d.ts +1 -1
- package/dist/package-json.js +3 -3
- package/dist/package-manager.js +3 -3
- package/dist/packem_shared/lockfile-candidates-B-i5hlDs.js +1 -0
- package/dist/packem_shared/{package-json.d-CuTm_EgE.d.ts → package-json.d-62php2nC.d.ts} +5 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## @visulima/package [5.0.11](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.10...%40visulima%2Fpackage%405.0.11) (2026-08-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Dependencies
|
|
5
|
+
|
|
6
|
+
* **@visulima/fs:** upgraded to 5.1.0
|
|
7
|
+
* **@visulima/path:** upgraded to 3.1.0
|
|
8
|
+
|
|
1
9
|
## @visulima/package [5.0.10](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.9...%40visulima%2Fpackage%405.0.10) (2026-07-27)
|
|
2
10
|
|
|
3
11
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { PackageNotFoundError } from "./error.js";
|
|
|
2
2
|
export { type LockFileEntry, type LockFileIntegrity, type LockFileIntegrityAlgorithm, type LockFileParseResult, type LockFileType, decodeSriIntegrity, parseBunLockFile, parseLockFile, parseLockFileContent, parseLockFileSync, parseNpmLockFile, parsePnpmLockFile, parseYarnLockFile } from "./lockfile.js";
|
|
3
3
|
export { type RootMonorepo, type Strategy, findMonorepoRoot, findMonorepoRootSync } from "./monorepo.js";
|
|
4
4
|
export { findPackageRoot, findPackageRootSync } from "./package.js";
|
|
5
|
-
export { type E as EnsurePackagesOptions, type F as FindPackageJsonCache, type N as NormalizedPackageJson, type a as NormalizedReadResult, type P as PackageJson, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-
|
|
5
|
+
export { type E as EnsurePackagesOptions, type F as FindPackageJsonCache, type N as NormalizedPackageJson, type a as NormalizedReadResult, type P as PackageJson, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-62php2nC.js";
|
|
6
6
|
export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from "./package-manager.js";
|
|
7
7
|
export { type PnpmCatalog, type PnpmCatalogs, isPackageInWorkspace, readPnpmCatalogs, readPnpmCatalogsSync, resolveCatalogReference, resolveCatalogReferences, resolveDependenciesCatalogReferences } from "./pnpm.js";
|
|
8
8
|
import '@visulima/fs';
|
package/dist/lockfile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as E}from"node:module";import{findUp as N,findUpSync as U}from"@visulima/fs";let
|
|
1
|
+
import{createRequire as E}from"node:module";import{findUp as N,findUpSync as U}from"@visulima/fs";import{L as q}from"./packem_shared/lockfile-candidates-B-i5hlDs.js";let A;const C=n=>(A??=E(import.meta.url))(n),g=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,_=n=>{if(typeof g<"u"&&g.versions&&g.versions.node){const[e,t]=g.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return g.getBuiltinModule(n)}return C(n)},{readFileSync:I}=_("node:fs"),{readFile:R}=_("node:fs/promises"),B={sha256:"sha256",sha384:"sha384",sha512:"sha512"},M=1024,T=/^[A-Z0-9+/]+={0,2}$/i,b="node_modules/",m=/^['"]/,k=/['"]$/,P=/^[a-z][a-zA-Z0-9]*:\s*$/m,z=/resolution:\s*\{[^}]*integrity:\s*([^,}\s]+)/,J=/^["']?((?:@[^/@"']+\/)?[^@"'\n]+)@[^\n]+\n((?:[\t ][^\n]*(?:\n|$))+)/gm,K=/^\s+version:?\s+"?([^"\n]+)"?/m,Z=/^\s+integrity[\s:]+"?([^"\s]+)"?/m,w=n=>{if(n.length>M)return;const e=n.indexOf("-");if(e<=0)return;const t=B[n.slice(0,e).toLowerCase()];if(!t)return;const s=n.slice(e+1);if(T.test(s))try{const r=Buffer.from(s,"base64");return r.length===0?void 0:{algorithm:t,hex:r.toString("hex")}}catch{return}},v=(n,e,t)=>{const s=`${t.name}@${t.version}`;e.has(s)||(e.add(s),n.push(t))},u=(n,e,t)=>{t&&Object.keys(t).length>0&&(n[e]={...t})},h=n=>{if(!n)return;const e={};for(const[t,s]of Object.entries(n))e[t]=[s];return Object.keys(e).length>0?e:void 0},Y=n=>{const e=[],t=new Set;let s;try{s=JSON.parse(n)}catch{return e}if(!s.packages)return e;for(const[r,o]of Object.entries(s.packages)){if(!r||!o.version)continue;const p=r.lastIndexOf(b);if(p===-1)continue;const i=r.slice(p+b.length);if(i.length===0)continue;const c=i.split("/"),a=i.startsWith("@")?2:1;if(c.length!==a||c.some(f=>f.length===0))continue;const l=o.name??i;if(l.startsWith("."))continue;const d={name:l,version:o.version};if(o.integrity){const f=w(o.integrity);f&&(d.integrity=f)}u(d,"dependencies",h(o.dependencies)),u(d,"peerDependencies",h(o.peerDependencies)),u(d,"optionalDependencies",h(o.optionalDependencies)),v(e,t,d)}return e},O=n=>{let e=n.trim();e.startsWith("/")&&(e=e.slice(1)),e=e.replace(m,"").replace(k,"");const t=e.indexOf("(");t>0&&(e=e.slice(0,t));const s=e.lastIndexOf("@");if(s<=0)return;const r=e.slice(0,s),o=e.slice(s+1);if(!(!r||!o||o.startsWith("link:")||o.startsWith("workspace:")||o.startsWith("file:")))return{name:r,version:o}},$=(n,e)=>{const t=new RegExp(String.raw`^${e}:\s*$`,"m").exec(n);if(!t)return;const s=t.index+t[0].length,r=P.exec(n.slice(s));return n.slice(s,r?s+r.index:n.length)},G=n=>{const e=new Map,t=$(n,"snapshots");if(!t)return e;const s=/^ {2}(['"]?[^\s:][^:\n]*?['"]?):\s*\n((?: {4}[^\n]*\n?)+)/gm;let r;for(;(r=s.exec(t)??void 0)!==void 0;){const o=O(r[1]);if(!o)continue;const p=`${o.name}@${o.version}`,i=r[2],c=e.get(p)??{};for(const a of["dependencies","peerDependencies","optionalDependencies"]){const l=y(i,a);if(!l)continue;const d=c[a]??{};for(const[f,F]of Object.entries(l)){const x=d[f]??[];for(const j of F)x.includes(j)||x.push(j);d[f]=x}c[a]=d}e.set(p,c)}return e},H=n=>{const e=[],t=new Set,s=$(n,"packages");if(!s)return e;const r=G(n),o=/^ {2}(['"]?[^\s:][^:\n]*?['"]?):\s*\n((?: {4}[^\n]*\n?)+)/gm;let p;for(;(p=o.exec(s)??void 0)!==void 0;){const i=O(p[1]);if(!i)continue;const c=p[2],a=z.exec(c),l={name:i.name,version:i.version};if(a?.[1]){const f=w(a[1]);f&&(l.integrity=f)}const d=r.get(`${i.name}@${i.version}`);u(l,"dependencies",d?.dependencies??y(c,"dependencies")),u(l,"peerDependencies",d?.peerDependencies??y(c,"peerDependencies")),u(l,"optionalDependencies",d?.optionalDependencies??y(c,"optionalDependencies")),v(e,t,l)}return e},y=(n,e)=>{const t=new RegExp(String.raw`^ {4}${e}:\s*\n((?: {6,}[^\n]*\n?)+)`,"m").exec(n);if(!t?.[1])return;const s={},r=/^ {6}([^\s:]+):\s*([^\n]+)/gm;let o;for(;(o=r.exec(t[1])??void 0)!==void 0;){const p=o[1].replace(m,"").replace(k,"");let i=o[2].trim();i=i.replace(m,"").replace(k,"");const c=i.indexOf("(");if(c>0&&(i=i.slice(0,c).trim()),!p||!i)continue;const a=s[p]??[];a.includes(i)||a.push(i),s[p]=a}return Object.keys(s).length>0?s:void 0},Q=n=>{const e=[],t=new Set,s=J;s.lastIndex=0;let r;for(;(r=s.exec(n)??void 0)!==void 0;){const o=r[1].replace(m,"").replace(k,"");if(!o)continue;const p=r[2],i=K.exec(p);if(!i?.[1])continue;const c={name:o,version:i[1].trim()},a=Z.exec(p);if(a?.[1]){const l=w(a[1]);l&&(c.integrity=l)}u(c,"dependencies",D(p,"dependencies")),u(c,"peerDependencies",D(p,"peerDependencies")),u(c,"optionalDependencies",D(p,"optionalDependencies")),v(e,t,c)}return e},D=(n,e)=>{const t=new RegExp(String.raw`^ {2}${e}:\s*\n((?: {4,}[^\n]*\n?)+)`,"m").exec(n);if(!t?.[1])return;const s={},r=/^ {4}(['"]?[^\s:'"]+['"]?)\s*(?::\s*)?['"]([^'"\n]+)['"]/gm;let o;for(;(o=r.exec(t[1])??void 0)!==void 0;){const p=o[1].replace(m,"").replace(k,""),i=o[2];if(p&&i){const c=s[p]??[];c.includes(i)||c.push(i),s[p]=c}}return Object.keys(s).length>0?s:void 0},V=/,(?=\s*[}\]])/g,X=n=>{const e=[],t=new Set;let s;try{s=JSON.parse(n.replaceAll(V,""))}catch{return e}if(!s.packages)return e;for(const r of Object.values(s.packages)){const o=r[0];if(typeof o!="string")continue;const p=o.indexOf("@",1);if(p<=0)continue;const i=o.slice(0,p),c=o.slice(p+1);if(!i||!c||c.startsWith("workspace:")||c.startsWith("link:")||c.startsWith("file:"))continue;const a={name:i,version:c},l=r[3];if(typeof l=="string"&&l.length>0){const f=w(l);f&&(a.integrity=f)}const d=r[2];if(d&&typeof d=="object"&&!Array.isArray(d)){const f=d;u(a,"dependencies",h(f.dependencies)),u(a,"peerDependencies",h(f.peerDependencies)),u(a,"optionalDependencies",h(f.optionalDependencies))}v(e,t,a)}return e},S=n=>{if(n.endsWith("pnpm-lock.yaml"))return"pnpm";if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return"npm";if(n.endsWith("yarn.lock"))return"yarn";if(n.endsWith("bun.lockb")||n.endsWith("bun.lock"))return"bun"},W=(n,e)=>{switch(e){case"bun":return X(n);case"npm":return Y(n);case"pnpm":return H(n);case"yarn":return Q(n);default:return[]}},L=[...q],se=async n=>{const e=await N(L,{type:"file",...n&&{cwd:n}});if(!e)throw new Error("Could not find a supported lock file (pnpm-lock.yaml, package-lock.json, npm-shrinkwrap.json, yarn.lock, bun.lock)");const t=S(e);if(!t)throw new Error(`Unsupported lock file: ${e}`);const s=await R(e,"utf8");return{entries:W(s,t),path:e,type:t}},oe=n=>{const e=U(L,{type:"file",...n&&{cwd:n}});if(!e)throw new Error("Could not find a supported lock file (pnpm-lock.yaml, package-lock.json, npm-shrinkwrap.json, yarn.lock, bun.lock)");const t=S(e);if(!t)throw new Error(`Unsupported lock file: ${e}`);return{entries:W(I(e,"utf8"),t),path:e,type:t}};export{w as decodeSriIntegrity,X as parseBunLockFile,se as parseLockFile,W as parseLockFileContent,oe as parseLockFileSync,Y as parseNpmLockFile,H as parsePnpmLockFile,Q as parseYarnLockFile};
|
package/dist/monorepo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as
|
|
1
|
+
import{createRequire as l}from"node:module";import{findUp as j,readJson as b,findUpSync as w,readJsonSync as k}from"@visulima/fs";import{NotFoundError as u}from"@visulima/fs/error";import{parseJson as _}from"@visulima/fs/utils";import{dirname as d,join as a}from"@visulima/path";import{findPackageManager as M,findPackageManagerSync as S}from"./package-manager.js";let m;const g=t=>(m??=l(import.meta.url))(t),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=t=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[o,e]=c.versions.node.split(".").map(Number);if(o>22||o===22&&e>=3||o===20&&e>=16)return c.getBuiltinModule(t)}return g(t)},{existsSync:i,readFileSync:f}=h("node:fs"),y=t=>{let o;try{o=_(t)}catch{return!1}if(!o||typeof o!="object"||Array.isArray(o))return!1;const{workspaces:e}=o;return typeof e=="object"&&e!==null},E=async t=>{const o=await j(["lerna.json","turbo.json"],{type:"file",...t&&{cwd:t}});if(o?.endsWith("lerna.json")){const r=await b(o);if(r&&typeof r=="object"&&!Array.isArray(r)){const n=r;if(n.useWorkspaces||n.packages)return{path:d(o),strategy:"lerna"}}}const e=o?.endsWith("turbo.json");try{const{packageManager:r,path:n}=await M(t);if(["npm","yarn"].includes(r)){const s=a(n,"package.json");if(i(s)){const p=f(a(n,"package.json"),"utf8");if(y(p))return{path:n,strategy:e?"turbo":r}}}else if(r==="pnpm"){const s=a(n,"pnpm-workspace.yaml");if(i(s))return{path:n,strategy:e?"turbo":"pnpm"}}}catch(r){if(!(r instanceof u))throw r}throw new Error(`No monorepo root could be found upwards from the directory ${String(t??process.cwd())} using lerna, yarn, pnpm, or npm as indicators.`)},J=t=>{const o=w(["lerna.json","turbo.json"],{type:"file",...t&&{cwd:t}});if(o?.endsWith("lerna.json")){const r=k(o);if(r&&typeof r=="object"&&!Array.isArray(r)){const n=r;if(n.useWorkspaces||n.packages)return{path:d(o),strategy:"lerna"}}}const e=o?.endsWith("turbo.json");try{const{packageManager:r,path:n}=S(t);if(["npm","yarn"].includes(r)){const s=a(n,"package.json");if(i(s)){const p=f(a(n,"package.json"),"utf8");if(y(p))return{path:n,strategy:e?"turbo":r}}}else if(r==="pnpm"){const s=a(n,"pnpm-workspace.yaml");if(i(s))return{path:n,strategy:e?"turbo":"pnpm"}}}catch(r){if(!(r instanceof u))throw r}throw new Error(`No monorepo root could be found upwards from the directory ${String(t??process.cwd())} using lerna, yarn, pnpm, or npm as indicators.`)};export{E as findMonorepoRoot,J as findMonorepoRootSync};
|
package/dist/package-json.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@visulima/fs';
|
|
2
2
|
import 'type-fest';
|
|
3
|
-
export { F as FindPackageJsonCache, a as NormalizedReadResult, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-
|
|
3
|
+
export { F as FindPackageJsonCache, a as NormalizedReadResult, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-62php2nC.js";
|
|
4
4
|
import '@antfu/install-pkg';
|
|
5
5
|
import '@inquirer/core';
|
|
6
6
|
import '@inquirer/type';
|
package/dist/package-json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as
|
|
2
|
-
${l(["gray"],"→")} ${
|
|
1
|
+
import{createRequire as B}from"node:module";import{installPackage as M}from"@antfu/install-pkg";import{findUp as Y,findUpSync as G,writeJson as X,writeJsonSync as z,readJson as U,readJsonSync as V,readFile as L,readFileSync as H}from"@visulima/fs";import{NotFoundError as v}from"@visulima/fs/error";import{toPath as j,parseJson as x}from"@visulima/fs/utils";import{readYaml as K,readYamlSync as Q}from"@visulima/fs/yaml";import{join as P}from"@visulima/path";import _ from"json5";import Z from"normalize-package-data";import{readPnpmCatalogs as S,resolveCatalogReferences as y,readPnpmCatalogsSync as N}from"./pnpm.js";let R;const q=r=>(R??=B(import.meta.url))(r),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,k=r=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[e,o]=h.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return h.getBuiltinModule(r)}return q(r)},{existsSync:E}=k("node:fs"),{createInterface:ee}=k("node:readline"),{styleText:l}=k("node:util"),b=r=>{const e=typeof r;return r!==null&&(e==="object"||e==="function")},I=new Set(["__proto__","prototype","constructor"]),J=1e6,re=r=>r>="0"&&r<="9";function T(r){if(r==="0")return!0;if(/^[1-9]\d*$/.test(r)){const e=Number.parseInt(r,10);return e<=Number.MAX_SAFE_INTEGER&&e<=J}return!1}function $(r,e){return I.has(r)?!1:(r&&T(r)?e.push(Number.parseInt(r,10)):e.push(r),!0)}function te(r){if(typeof r!="string")throw new TypeError(`Expected a string, got ${typeof r}`);const e=[];let o="",t="start",n=!1,s=0;for(const a of r){if(s++,n){o+=a,n=!1;continue}if(a==="\\"){if(t==="index")throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(t==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);n=!0,t=t==="start"?"property":t;continue}switch(a){case".":{if(t==="index")throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(t==="indexEnd"){t="property";break}if(!$(o,e))return[];o="",t="property";break}case"[":{if(t==="index")throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(t==="indexEnd"){t="index";break}if(t==="property"||t==="start"){if((o||t==="property")&&!$(o,e))return[];o=""}t="index";break}case"]":{if(t==="index"){if(o==="")o=(e.pop()||"")+"[]",t="property";else{const i=Number.parseInt(o,10);!Number.isNaN(i)&&Number.isFinite(i)&&i>=0&&i<=Number.MAX_SAFE_INTEGER&&i<=J&&o===String(i)?e.push(i):e.push(o),o="",t="indexEnd"}break}if(t==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);o+=a;break}default:{if(t==="index"&&!re(a))throw new Error(`Invalid character '${a}' in an index at position ${s}`);if(t==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);t==="start"&&(t="property"),o+=a}}}switch(n&&(o+="\\"),t){case"property":{if(!$(o,e))return[];break}case"index":throw new Error("Index was not closed");case"start":{e.push("");break}}return e}function C(r){if(typeof r=="string")return te(r);if(Array.isArray(r)){const e=[];for(const[o,t]of r.entries()){if(typeof t!="string"&&typeof t!="number")throw new TypeError(`Expected a string or number for path segment at index ${o}, got ${typeof t}`);if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError(`Path segment at index ${o} must be a finite number, got ${t}`);if(I.has(t))return[];typeof t=="string"&&T(t)?e.push(Number.parseInt(t,10)):e.push(t)}return e}return[]}function p(r,e,o){if(!b(r)||typeof e!="string"&&!Array.isArray(e))return o===void 0?r:o;const t=C(e);if(t.length===0)return o;for(let n=0;n<t.length;n++){const s=t[n];if(r=r[s],r==null){if(n!==t.length-1)return o;break}}return r===void 0?o:r}function oe(r,e){if(!b(r)||typeof e!="string"&&!Array.isArray(e))return!1;const o=C(e);if(o.length===0)return!1;for(const t of o){if(!b(r)||!(t in r))return!1;r=r[t]}return!0}const ne=async r=>{const{default:e=!1,message:o,transformer:t}=r,n=a=>{const i=l(["cyan","bold"],"?"),c=l(["bold"],a),f=e?`${l(["greenBright"],"Y")}${l(["gray"],"/n")}`:`y/${l(["yellowBright"],"N")}`;return`${i} ${c} ${l(["gray"],`(${f})`)}`},s=a=>t?t(a):a?l(["greenBright"],"Yes"):l(["yellowBright"],"No");return new Promise(a=>{const i=ee({input:process.stdin,output:process.stdout}),c=n(o);i.question(c,f=>{i.close();const g=f.trim().toLowerCase();if(g===""){a(e);return}if(g==="y"||g==="yes"){console.log(`${l(["greenBright"],"✓")} ${s(!0)}`),a(!0);return}if(g==="n"||g==="no"){console.log(`${l(["yellowBright"],"✗")} ${s(!1)}`),a(!1);return}console.log(`${l(["gray"],"→")} ${s(e)}`),a(e)}),i.on("SIGINT",()=>{i.close(),console.log(`
|
|
2
|
+
${l(["gray"],"→")} ${s(!1)}`),a(!1)})})},se=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window,A=/, ([^,]*)$/,u=new Map,m=new Map,d=(r,e={})=>{const o=e.strict&&e.ignoreWarnings?e.ignoreWarnings.map(String).toSorted((t,n)=>t.localeCompare(n)).join(","):"";return`${r}|s${String(e.strict?1:0)}|c${String(e.resolveCatalogs?1:0)}|j${String(e.json5===!1?0:1)}|y${String(e.yaml===!1?0:1)}|w${o}`},W=r=>r.trimStart().startsWith("{"),D=r=>{const e=`${r}|`;for(const o of[m,u])for(const t of o.keys())t.startsWith(e)&&o.delete(t)};class ae extends Error{constructor(e){super(`The following warnings were encountered while normalizing package data:
|
|
3
3
|
- ${e.join(`
|
|
4
|
-
- `)}`),this.name="PackageJsonValidationError"}}const
|
|
4
|
+
- `)}`),this.name="PackageJsonValidationError"}}const w=(r,e,o=[])=>{const t=[];if(Z(r,n=>{t.push(n)},e),e&&t.length>0){const n=t.filter(s=>!o.some(a=>a instanceof RegExp?a.test(s):a===s));if(n.length>0)throw new ae(n)}return r},ie=async r=>await K(r),ce=r=>Q(r),fe=async r=>{const e=await L(r);return _.parse(e)},le=r=>{const e=H(r);return _.parse(e)},F=async(r,e)=>e?.yaml!==!1&&(r.endsWith(".yaml")||r.endsWith(".yml"))?ie(r):e?.json5!==!1&&r.endsWith(".json5")?fe(r):U(r),O=(r,e)=>e?.yaml!==!1&&(r.endsWith(".yaml")||r.endsWith(".yml"))?ce(r):e?.json5!==!1&&r.endsWith(".json5")?le(r):V(r),ke=async(r,e={})=>{const o={type:"file"};r&&(o.cwd=r);const t=["package.json"];e.yaml!==!1&&t.push("package.yaml","package.yml"),e.json5!==!1&&t.push("package.json5");const n=await Y(t,o);if(!n)throw new v(`No such file or directory, for ${t.join(", ").replace(A," or $1")} found.`);const s=e.cache&&typeof e.cache!="boolean"?e.cache:m,a=d(n,e);if(e.cache&&s.has(a))return s.get(a);const i=await F(n,e);if(e.resolveCatalogs){const f=await S(n);f&&y(i,f)}w(i,e.strict??!1,e.ignoreWarnings);const c={packageJson:i,path:n};return e.cache&&s.set(a,c),c},je=(r,e={})=>{const o={type:"file"};r&&(o.cwd=r);const t=["package.json"];e.yaml!==!1&&t.push("package.yaml","package.yml"),e.json5!==!1&&t.push("package.json5");const n=G(t,o);if(!n)throw new v(`No such file or directory, for ${t.join(", ").replace(A," or $1")} found.`);const s=e.cache&&typeof e.cache!="boolean"?e.cache:m,a=d(n,e);if(e.cache&&s.has(a))return s.get(a);const i=O(n,e);if(e.resolveCatalogs){const f=N(n);f&&y(i,f)}w(i,e.strict??!1,e.ignoreWarnings);const c={packageJson:i,path:n};return e.cache&&s.set(a,c),c},Ee=async(r,e={})=>{const{cwd:o,...t}=e,n=j(o??process.cwd()),s=P(n,"package.json");await X(s,r,t),D(s)},ve=(r,e={})=>{const{cwd:o,...t}=e,n=j(o??process.cwd()),s=P(n,"package.json");z(s,r,t),D(s)},xe=()=>{m.clear(),u.clear()},Pe=(r,e)=>{const o=typeof r=="object"&&!Array.isArray(r);if(!o&&typeof r!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let t,n=!1,s;if(o)t=structuredClone(r);else if(!W(r)&&E(r)){s=r;const i=e?.cache&&typeof e.cache!="boolean"?e.cache:u,c=d(s,e);if(e?.cache&&i.has(c))return i.get(c);t=O(s,e),n=!0}else t=x(r);if(e?.resolveCatalogs)if(n){const i=N(r);i&&y(t,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");w(t,e?.strict??!1,e?.ignoreWarnings);const a=t;return n&&e?.cache&&(typeof e.cache=="boolean"?u:e.cache).set(d(s,e),a),a},_e=async(r,e)=>{const o=typeof r=="object"&&!Array.isArray(r);if(!o&&typeof r!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let t,n=!1,s;if(o)t=structuredClone(r);else if(!W(r)&&E(r)){s=r;const i=e?.cache&&typeof e.cache!="boolean"?e.cache:u,c=d(s,e);if(e?.cache&&i.has(c))return i.get(c);t=await F(s,e),n=!0}else t=x(r);if(e?.resolveCatalogs)if(n){const i=await S(r);i&&y(t,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");w(t,e?.strict??!1,e?.ignoreWarnings);const a=t;return n&&e?.cache&&(typeof e.cache=="boolean"?u:e.cache).set(d(s,e),a),a},Se=(r,e,o)=>p(r,e,o),Ne=(r,e)=>oe(r,e),Ie=(r,e,o)=>{const t=p(r,"dependencies",{}),n=p(r,"devDependencies",{}),s=p(r,"peerDependencies",{}),a={...t,...n,...o?.peerDeps===!1?{}:s};for(const i of e)if(Object.hasOwn(a,i))return!0;return!1},Je=async(r,e,o="dependencies",t={})=>{const n=p(r,"dependencies",{}),s=p(r,"devDependencies",{}),a=p(r,"peerDependencies",{}),i=[],c={deps:!0,devDeps:!0,peerDeps:!1,...t,...t.confirm?{confirm:{...t.confirm}}:{}};for(const f of e)c.deps&&Object.hasOwn(n??{},f)||c.devDeps&&Object.hasOwn(s??{},f)||c.peerDeps&&Object.hasOwn(a??{},f)||i.push(f);if(i.length!==0){if(process.env.CI||se&&!process.stdout.isTTY){const f=`Skipping package installation for [${e.join(", ")}] because the process is not interactive.`;if(t.throwOnWarn)throw new Error(f);t.logger?.warn?t.logger.warn(f):console.warn(f);return}if(typeof c.confirm?.message=="function"&&(c.confirm.message=c.confirm.message(i)),c.confirm?.message===void 0){const f=`${i.length===1?"Package is":"Packages are"} required for this config: ${i.join(", ")}. Do you want to install them?`;c.confirm===void 0?c.confirm={message:f}:c.confirm.message=f}await ne(c.confirm)&&await M(i,{...c.installPackage,cwd:c.cwd?j(c.cwd):void 0,dev:o==="devDependencies"})}};export{xe as clearPackageJsonCache,Je as ensurePackages,ke as findPackageJson,je as findPackageJsonSync,Se as getPackageJsonProperty,Ie as hasPackageJsonAnyDependency,Ne as hasPackageJsonProperty,_e as parsePackageJson,Pe as parsePackageJsonSync,Ee as writePackageJson,ve as writePackageJsonSync};
|
package/dist/package-manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as b}from"node:module";import{findUp as
|
|
1
|
+
import{createRequire as b}from"node:module";import{findUp as h,findUpSync as k}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{parseJson as W}from"@visulima/fs/utils";import{join as p,dirname as s}from"@visulima/path";import{L as P}from"./packem_shared/lockfile-candidates-B-i5hlDs.js";let $;const E=e=>($??=b(import.meta.url))(e),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,m=e=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[n,a]=o.versions.node.split(".").map(Number);if(n>22||n===22&&a>=3||n===20&&a>=16)return o.getBuiltinModule(e)}return E(e)},{execFileSync:S}=m("node:child_process"),{existsSync:l,readFileSync:x}=m("node:fs"),g=[...P],u=new Set(["bun","npm","pnpm","yarn"]),w=e=>{const n=W(x(e,"utf8"));return typeof n?.packageManager=="string"?n.packageManager:void 0},y=e=>{let n;if(g.forEach(r=>{!n&&l(p(e,r))&&(n=p(e,r))}),n)return n;const a=p(e,"package.json");if(l(a)&&w(a)!==void 0)return a},_=e=>{if(!e)throw new f("Could not find a package manager");if(e.endsWith("package.json")){const n=w(e);if(n){const a=["npm","yarn","pnpm","bun"].find(r=>n.startsWith(r));if(a)return{packageManager:a,path:s(e)}}}if(e.endsWith("yarn.lock"))return{packageManager:"yarn",path:s(e)};if(e.endsWith("package-lock.json")||e.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:s(e)};if(e.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:s(e)};if(e.endsWith("bun.lock")||e.endsWith("bun.lockb"))return{packageManager:"bun",path:s(e)};throw new f("Could not find a package manager")},q=async e=>{const n=await h(g,{type:"file",...e&&{cwd:e}});if(!n)throw new Error("Could not find lock file");return n},D=e=>{const n=k(g,{type:"file",...e&&{cwd:e}});if(!n)throw new Error("Could not find lock file");return n},U=async e=>{const n=await h(y,{...e&&{cwd:e}});return _(n)},O=e=>{const n=k(y,{...e&&{cwd:e}});return _(n)},R=e=>{if(!u.has(e))throw new Error(`Unsupported package manager "${e}". Expected one of: ${[...u].join(", ")}.`);return S(e,["--version"]).toString("utf8").trim()},A=()=>{if(!process.env.npm_config_user_agent)return;const e=process.env.npm_config_user_agent.split(" ")[0],n=e.lastIndexOf("/"),a=e.slice(0,Math.max(0,n));return{name:a==="npminstall"?"cnpm":a,version:e.slice(Math.max(0,n+1))}},B=(e,n,a)=>{const r=n.length===1?"":"s",d=a.packageManagers??["npm","pnpm","yarn"];if(d.length===0)throw new Error("No package managers provided, please provide at least one package manager");if(n.length===0)throw new Error("No missing packages provided, please provide at least one missing package");let c=`
|
|
2
2
|
${a.preMessage??""}
|
|
3
3
|
${e} could not find the following package${r}
|
|
4
4
|
|
|
@@ -6,8 +6,8 @@ ${e} could not find the following package${r}
|
|
|
6
6
|
`)}
|
|
7
7
|
|
|
8
8
|
To install the missing package${r}, please run the following command:
|
|
9
|
-
`;const
|
|
9
|
+
`;const M=t=>t.lastIndexOf("@")>0?t:`${t}@latest`,v=d.map(t=>{const i=n.map(j=>M(j)).join(" ");switch(t){case"bun":return` bun add ${i} -D`;case"npm":return` npm install ${i} --save-dev`;case"pnpm":return` pnpm add ${i} -D`;case"yarn":return` yarn add ${i} --dev`;default:throw new Error("Unknown package manager")}});return c+=v.join(`
|
|
10
10
|
|
|
11
11
|
or
|
|
12
12
|
|
|
13
|
-
`),a.postMessage&&(c+=a.postMessage),c};export{
|
|
13
|
+
`),a.postMessage&&(c+=a.postMessage),c};export{q as findLockFile,D as findLockFileSync,U as findPackageManager,O as findPackageManagerSync,B as generateMissingPackagesInstallMessage,R as getPackageManagerVersion,A as identifyInitiatingPackageManager};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=["pnpm-lock.yaml","package-lock.json","npm-shrinkwrap.json","yarn.lock","bun.lock","bun.lockb"];export{n as L};
|
|
@@ -14,7 +14,11 @@ type EnsurePackagesOptions = {
|
|
|
14
14
|
default?: boolean;
|
|
15
15
|
/** Message to display in the confirmation prompt, or a function that receives packages array */
|
|
16
16
|
message: string | ((packages: string[]) => string);
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Theme configuration for the prompt interface.
|
|
19
|
+
* @deprecated Not implemented — the readline-based prompt ignores this option and uses
|
|
20
|
+
* fixed styling. It will be removed in a future major release.
|
|
21
|
+
*/
|
|
18
22
|
theme?: PartialDeep<Theme>;
|
|
19
23
|
/** Function to transform the boolean value for display */
|
|
20
24
|
transformer?: (value: boolean) => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/package",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.11",
|
|
4
4
|
"description": "A comprehensive package management utility that helps you find root directories, monorepos, package managers, and parse package.json, package.yaml, and package.json5 files with advanced features like catalog resolution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -109,8 +109,8 @@
|
|
|
109
109
|
},
|
|
110
110
|
"dependencies": {
|
|
111
111
|
"@antfu/install-pkg": "^1.1.0",
|
|
112
|
-
"@visulima/fs": "5.0
|
|
113
|
-
"@visulima/path": "3.
|
|
112
|
+
"@visulima/fs": "5.1.0",
|
|
113
|
+
"@visulima/path": "3.1.0",
|
|
114
114
|
"json5": "^2.2.3",
|
|
115
115
|
"normalize-package-data": "^9.0.0",
|
|
116
116
|
"yaml": "2.9.0"
|