@visulima/package 5.0.0-alpha.3 → 5.0.0-alpha.31

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.
@@ -1,13 +1,13 @@
1
- var v=Object.defineProperty;var d=(n,e)=>v(n,"name",{value:e,configurable:!0});import{createRequire as _}from"node:module";import{findUpSync as m,findUp as h}from"@visulima/fs";import{NotFoundError as p}from"@visulima/fs/error";import{join as l,dirname as t}from"@visulima/path";import{parsePackageJsonSync as M,parsePackageJson as $}from"./package-json.js";const P=_(import.meta.url),s=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=d(n=>{if(typeof s<"u"&&s.versions&&s.versions.node){const[e,a]=s.versions.node.split(".").map(Number);if(e>22||e===22&&a>=3||e===20&&a>=16)return s.getBuiltinModule(n)}return P(n)},"__cjs_getBuiltinModule"),{execSync:W}=u("node:child_process"),{existsSync:k,readFileSync:S}=u("node:fs");var F=Object.defineProperty,r=d((n,e)=>F(n,"name",{value:e,configurable:!0}),"t");const f=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],y=r(n=>{let e;if(f.forEach(i=>{!e&&k(l(n,i))&&(e=l(n,i))}),e)return e;const a=l(n,"package.json");if(k(a)&&M(S(a,"utf8")).packageManager!==void 0)return a},"packageMangerFindUpMatcher"),E=r(async n=>{if(!n)throw new p("Could not find a package manager");if(n.endsWith("package.json")){const e=await $(n);if(e.packageManager){const a=["npm","yarn","pnpm","bun"].find(i=>e.packageManager.startsWith(i));if(a)return{packageManager:a,path:t(n)}}}if(n.endsWith("yarn.lock"))return{packageManager:"yarn",path:t(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:t(n)};if(n.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:t(n)};if(n.endsWith("bun.lockb"))return{packageManager:"bun",path:t(n)};throw new p("Could not find a package manager")},"findPackageManagerOnFile"),x=r(n=>{if(!n)throw new p("Could not find a package manager");if(n.endsWith("package.json")){const e=M(n);if(e.packageManager){const a=["npm","yarn","pnpm","bun"].find(i=>e.packageManager.startsWith(i));if(a)return{packageManager:a,path:t(n)}}}if(n.endsWith("yarn.lock"))return{packageManager:"yarn",path:t(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:t(n)};if(n.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:t(n)};if(n.endsWith("bun.lockb"))return{packageManager:"bun",path:t(n)};throw new p("Could not find a package manager")},"findPackageManagerOnFileSync"),U=r(async n=>{const e=await h(f,{type:"file",...n&&{cwd:n}});if(!e)throw new Error("Could not find lock file");return e},"findLockFile"),q=r(n=>{const e=m(f,{type:"file",...n&&{cwd:n}});if(!e)throw new Error("Could not find lock file");return e},"findLockFileSync"),B=r(async n=>{const e=await h(y,{...n&&{cwd:n}});return E(e)},"findPackageManager"),D=r(n=>{const e=m(y,{...n&&{cwd:n}});return x(e)},"findPackageManagerSync"),J=r(n=>W(`${n} --version`).toString("utf8").trim(),"getPackageManagerVersion"),R=r(async()=>{if(!process.env.npm_config_user_agent)return;const n=process.env.npm_config_user_agent.split(" ")[0],e=n.lastIndexOf("/"),a=n.slice(0,Math.max(0,e));return{name:a==="npminstall"?"cnpm":a,version:n.slice(Math.max(0,e+1))}},"identifyInitiatingPackageManager"),V=r((n,e,a)=>{const i=e.length===1?"":"s";if(a.packageManagers===void 0&&(a.packageManagers=["npm","pnpm","yarn"]),a.packageManagers.length===0)throw new Error("No package managers provided, please provide at least one package manager");if(e.length===0)throw new Error("No missing packages provided, please provide at least one missing package");let g=`
1
+ import{createRequire as b}from"node:module";import{findUp as k,findUpSync as h}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{parseJson as S}from"@visulima/fs/utils";import{join as p,dirname as s}from"@visulima/path";const $=b(import.meta.url),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[n,a]=t.versions.node.split(".").map(Number);if(n>22||n===22&&a>=3||n===20&&a>=16)return t.getBuiltinModule(e)}return $(e)},{execFileSync:E}=u("node:child_process"),{existsSync:d,readFileSync:x}=u("node:fs"),g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lock","bun.lockb"],m=new Set(["bun","npm","pnpm","yarn"]),w=e=>{const n=S(x(e,"utf8"));return typeof n?.packageManager=="string"?n.packageManager:void 0},y=e=>{let n;if(g.forEach(r=>{!n&&d(p(e,r))&&(n=p(e,r))}),n)return n;const a=p(e,"package.json");if(d(a)&&w(a)!==void 0)return a},M=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")},N=async e=>{const n=await k(g,{type:"file",...e&&{cwd:e}});if(!n)throw new Error("Could not find lock file");return n},T=e=>{const n=h(g,{type:"file",...e&&{cwd:e}});if(!n)throw new Error("Could not find lock file");return n},U=async e=>{const n=await k(y,{...e&&{cwd:e}});return M(n)},q=e=>{const n=h(y,{...e&&{cwd:e}});return M(n)},B=e=>{if(!m.has(e))throw new Error(`Unsupported package manager "${e}". Expected one of: ${[...m].join(", ")}.`);return E(e,["--version"]).toString("utf8").trim()},D=()=>{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))}},L=(e,n,a)=>{const r=n.length===1?"":"s",l=a.packageManagers??["npm","pnpm","yarn"];if(l.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
- ${n} could not find the following package${i}
3
+ ${e} could not find the following package${r}
4
4
 
5
- ${e.join(`
5
+ ${n.join(`
6
6
  `)}
7
7
 
8
- To install the missing package${i}, please run the following command:
9
- `;const w=r(o=>o.split("@").includes("@")?o:`${o}@latest`,"atLatest"),j=a.packageManagers.map(o=>{const c=e.map(b=>w(b)).join(" ");switch(o){case"bun":return` bun add ${c} -D`;case"npm":return` npm install ${c} --save-dev`;case"pnpm":return` pnpm add ${c} -D`;case"yarn":return` yarn add ${c} --dev`;default:throw new Error("Unknown package manager")}});return g+=j.join(`
8
+ To install the missing package${r}, please run the following command:
9
+ `;const _=o=>o.lastIndexOf("@")>0?o:`${o}@latest`,j=l.map(o=>{const i=n.map(v=>_(v)).join(" ");switch(o){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+=j.join(`
10
10
 
11
11
  or
12
12
 
13
- `),a.postMessage&&(g+=a.postMessage),g},"generateMissingPackagesInstallMessage");export{U as findLockFile,q as findLockFileSync,B as findPackageManager,D as findPackageManagerSync,V as generateMissingPackagesInstallMessage,J as getPackageManagerVersion,R as identifyInitiatingPackageManager};
13
+ `),a.postMessage&&(c+=a.postMessage),c};export{N as findLockFile,T as findLockFileSync,U as findPackageManager,q as findPackageManagerSync,L as generateMissingPackagesInstallMessage,B as getPackageManagerVersion,D as identifyInitiatingPackageManager};
package/dist/package.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  /**
2
- * An asynchronous function that finds the root directory of a project based on certain lookup criteria.
3
- * @param cwd Optional. The current working directory to start the search from. The type of `cwd` is `string`.
4
- * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise&lt;string>`.
5
- * @throws An `Error` if the root directory could not be found.
6
- * @example
7
- * const rootDirectory = await findPackageRoot();
8
- * console.log(rootDirectory); // '/path/to/project'
9
- */
10
- export declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
11
- export declare const findPackageRootSync: (cwd?: URL | string) => string;
2
+ * An asynchronous function that finds the root directory of a project based on certain lookup criteria.
3
+ * @param cwd Optional. The current working directory to start the search from. The type of `cwd` is `string`.
4
+ * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise&lt;string>`.
5
+ * @throws An `Error` if the root directory could not be found.
6
+ * @example
7
+ * const rootDirectory = await findPackageRoot();
8
+ * console.log(rootDirectory); // '/path/to/project'
9
+ */
10
+ declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
11
+ declare const findPackageRootSync: (cwd?: URL | string) => string;
12
+ export { findPackageRoot, findPackageRootSync };
package/dist/package.js CHANGED
@@ -1 +1 @@
1
- var u=Object.defineProperty;var c=(e,o)=>u(e,"name",{value:o,configurable:!0});import{createRequire as l}from"node:module";import{findUp as a,findUpSync as f,readJsonSync as _}from"@visulima/fs";import{dirname as r,join as d}from"@visulima/path";import{findLockFile as w,findLockFileSync as j}from"./package-manager.js";const g=l(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=c(e=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[o,n]=i.versions.node.split(".").map(Number);if(o>22||o===22&&n>=3||o===20&&n>=16)return i.getBuiltinModule(e)}return g(e)},"__cjs_getBuiltinModule"),{existsSync:m}=y("node:fs");var k=Object.defineProperty,s=c((e,o)=>k(e,"name",{value:o,configurable:!0}),"r");const p=s(e=>{if(m(d(e,"package.json"))){const o=_(d(e,"package.json"));if(o.name&&o.private!==!0)return"package.json"}},"packageJsonMatcher"),S=s(async e=>{try{const t=await w(e);return r(t)}catch{}const o=await a(".git/config",{...e&&{cwd:e},type:"file"});if(o)return r(r(o));const n=await a(p,{...e&&{cwd:e},type:"file"});if(n)return r(n);throw new Error("Could not find root directory")},"findPackageRoot"),q=s(e=>{try{const t=j(e);return r(t)}catch{}const o=f(".git/config",{...e&&{cwd:e},type:"file"});if(o)return r(r(o));const n=f(p,{...e&&{cwd:e},type:"file"});if(n)return r(n);throw new Error("Could not find root directory")},"findPackageRootSync");export{S as findPackageRoot,q as findPackageRootSync};
1
+ import{createRequire as d}from"node:module";import{findUp as c,findUpSync as s,readJsonSync as y}from"@visulima/fs";import{dirname as r,join as f}from"@visulima/path";import{findLockFile as g,findLockFileSync as m}from"./package-manager.js";const p=d(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[o,t]=i.versions.node.split(".").map(Number);if(o>22||o===22&&t>=3||o===20&&t>=16)return i.getBuiltinModule(e)}return p(e)},{existsSync:l}=u("node:fs"),a=e=>{if(l(f(e,"package.json"))){const o=y(f(e,"package.json"));if(o.name&&o.private!==!0)return"package.json"}},k=async e=>{try{const n=await g(e);return r(n)}catch{}const o=await c(".git/config",{...e&&{cwd:e},type:"file"});if(o)return r(r(o));const t=await c(a,{...e&&{cwd:e},type:"file"});if(t)return r(t);throw new Error("Could not find root directory")},S=e=>{try{const n=m(e);return r(n)}catch{}const o=s(".git/config",{...e&&{cwd:e},type:"file"});if(o)return r(r(o));const t=s(a,{...e&&{cwd:e},type:"file"});if(t)return r(t);throw new Error("Could not find root directory")};export{k as findPackageRoot,S as findPackageRootSync};
@@ -0,0 +1 @@
1
+ import{findPackageManagerSync as o}from"../package-manager.js";class n extends Error{constructor(e,r){if(typeof e=="string"&&(e=[e]),e.length===0){super("Package was not found.");return}if(r===void 0)try{r=o().packageManager}catch{}r??="npm",super(`Package '${e.join(" ")}' was not found. Please install it using '${r} install ${e.join(" ")}'`)}get code(){return"PACKAGE_NOT_FOUND"}set code(e){throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND")}get name(){return"PackageNotFoundError"}set name(e){throw new Error("Cannot overwrite name of PackageNotFoundError")}}export{n as default};
@@ -0,0 +1,182 @@
1
+ import { WriteJsonOptions } from '@visulima/fs';
2
+ import { PackageJson as PackageJson$1, Paths, JsonObject } from 'type-fest';
3
+ import { InstallPackageOptions } from '@antfu/install-pkg';
4
+ import { Theme } from '@inquirer/core';
5
+ import { PartialDeep } from '@inquirer/type';
6
+ import { Package } from 'normalize-package-data';
7
+ type NormalizedPackageJson = Package & PackageJson;
8
+ type PackageJson = PackageJson$1;
9
+ type Cache<T = unknown> = Map<string, T>;
10
+ type EnsurePackagesOptions = {
11
+ /** Configuration for user confirmation prompts when installing packages */
12
+ confirm?: {
13
+ /** Default value for the confirmation prompt */
14
+ default?: boolean;
15
+ /** Message to display in the confirmation prompt, or a function that receives packages array */
16
+ message: string | ((packages: string[]) => string);
17
+ /** Theme configuration for the prompt interface */
18
+ theme?: PartialDeep<Theme>;
19
+ /** Function to transform the boolean value for display */
20
+ transformer?: (value: boolean) => string;
21
+ };
22
+ /** Current working directory for package operations */
23
+ cwd?: URL | string;
24
+ /** Whether to include regular dependencies in the operation */
25
+ deps?: boolean;
26
+ /** Whether to include development dependencies in the operation */
27
+ devDeps?: boolean;
28
+ /** Additional options for package installation (excluding cwd and dev which are handled separately) */
29
+ installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
30
+ /** Custom logger interface for warning messages */
31
+ logger?: {
32
+ warn: (message: string) => void;
33
+ };
34
+ /** Whether to include peer dependencies in the operation */
35
+ peerDeps?: boolean;
36
+ /** Whether to throw an error when warnings are logged instead of just logging them */
37
+ throwOnWarn?: boolean;
38
+ };
39
+ type ReadOptions = {
40
+ cache?: FindPackageJsonCache | boolean;
41
+ ignoreWarnings?: (RegExp | string)[];
42
+ json5?: boolean;
43
+ resolveCatalogs?: boolean;
44
+ strict?: boolean;
45
+ yaml?: boolean;
46
+ };
47
+ type FindPackageJsonCache = Cache<NormalizedReadResult>;
48
+ type NormalizedReadResult = {
49
+ packageJson: NormalizedPackageJson;
50
+ path: string;
51
+ };
52
+ /**
53
+ * An asynchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
54
+ * @param cwd The current working directory.
55
+ * @param options Configuration options including yaml, json5, and resolveCatalogs flags.
56
+ * @returns A `Promise` that resolves to an object containing the parsed package data and the file path.
57
+ * The type of the returned promise is `Promise&lt;NormalizedReadResult>`.
58
+ * @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
59
+ */
60
+ declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
61
+ /**
62
+ * A synchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
63
+ * @param cwd The current working directory.
64
+ * @param options Configuration options including yaml, json5, and resolveCatalogs flags.
65
+ * @returns An object containing the parsed package data and the file path.
66
+ * @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
67
+ */
68
+ declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
69
+ /**
70
+ * An asynchronous function to write the package.json file with the given data.
71
+ * @param data The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.
72
+ * @param options Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.
73
+ * This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options["cwd"]`.
74
+ * `cwd` represents the current working directory. If not specified, the default working directory will be used.
75
+ * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise&lt;void>`.
76
+ */
77
+ declare const writePackageJson: (data: PackageJson, options?: WriteJsonOptions & {
78
+ cwd?: URL | string;
79
+ }) => Promise<void>;
80
+ declare const writePackageJsonSync: (data: PackageJson, options?: WriteJsonOptions & {
81
+ cwd?: URL | string;
82
+ }) => void;
83
+ /**
84
+ * Clears the module-level package.json file and parse caches.
85
+ *
86
+ * The caches populated by `findPackageJson[Sync]` / `parsePackageJson[Sync]` when
87
+ * `cache: true` (and no custom cache is supplied) never expire on their own. Call this
88
+ * to drop all cached reads — for example in long-running processes or tests that mutate
89
+ * package files out of band.
90
+ */
91
+ declare const clearPackageJsonCache: () => void;
92
+ /**
93
+ * A synchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
94
+ * @param packageFile
95
+ * @param options
96
+ * @param options.cache Cache for parsed results (only applies to file paths)
97
+ * @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
98
+ * @param options.resolveCatalogs Whether to resolve pnpm catalog references
99
+ * @param options.strict Whether to throw errors on normalization warnings
100
+ * @param options.yaml Whether to enable package.yaml parsing (default: true)
101
+ * @param options.json5 Whether to enable package.json5 parsing (default: true)
102
+ * @returns
103
+ * @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
104
+ */
105
+ declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
106
+ cache?: Cache<NormalizedPackageJson> | boolean;
107
+ ignoreWarnings?: (RegExp | string)[];
108
+ json5?: boolean;
109
+ resolveCatalogs?: boolean;
110
+ strict?: boolean;
111
+ yaml?: boolean;
112
+ }) => NormalizedPackageJson;
113
+ /**
114
+ * An asynchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
115
+ * @param packageFile
116
+ * @param options
117
+ * @param options.cache Cache for parsed results (only applies to file paths)
118
+ * @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
119
+ * @param options.strict Whether to throw errors on normalization warnings
120
+ * @param options.resolveCatalogs Whether to resolve pnpm catalog references
121
+ * @param options.yaml Whether to enable package.yaml parsing (default: true)
122
+ * @param options.json5 Whether to enable package.json5 parsing (default: true)
123
+ * @returns
124
+ * @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
125
+ */
126
+ declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
127
+ cache?: Cache<NormalizedPackageJson> | boolean;
128
+ ignoreWarnings?: (RegExp | string)[];
129
+ json5?: boolean;
130
+ resolveCatalogs?: boolean;
131
+ strict?: boolean;
132
+ yaml?: boolean;
133
+ }) => Promise<NormalizedPackageJson>;
134
+ /**
135
+ * An asynchronous function to get the value of a property from the package.json file.
136
+ * @param packageJson
137
+ * @param property
138
+ * @param defaultValue
139
+ * @returns
140
+ */
141
+ declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
142
+ /**
143
+ * An asynchronous function to check if a property exists in the package.json file.
144
+ * @param packageJson
145
+ * @param property
146
+ * @returns
147
+ */
148
+ declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
149
+ /**
150
+ * An asynchronous function to check if any of the specified dependencies exist in the package.json file.
151
+ * @param packageJson
152
+ * @param arguments_
153
+ * @param options
154
+ * @param options.peerDeps Whether to include peer dependencies
155
+ * @returns
156
+ */
157
+ declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
158
+ peerDeps?: boolean;
159
+ }) => boolean;
160
+ /**
161
+ * An asynchronous function to ensure that the specified packages are installed in the package.json file.
162
+ * If the packages are not installed, the user will be prompted to install them.
163
+ * If the user agrees, the packages will be installed.
164
+ * If the user declines, the function will return without installing the packages.
165
+ * If the user does not respond, the function will return without installing the packages.
166
+ * @param packageJson
167
+ * @param packages
168
+ * @param installKey
169
+ * @param options
170
+ * @param options.deps Whether to include regular dependencies
171
+ * @param options.devDeps Whether to include development dependencies
172
+ * @param options.peerDeps Whether to include peer dependencies
173
+ * @param options.throwOnWarn Whether to throw an error when warnings are logged instead of just logging them
174
+ * @param options.logger Whether to use a custom logger
175
+ * @param options.confirm Whether to use a custom confirmation prompt
176
+ * @param options.installPackage Whether to use a custom installation package
177
+ * @param options.cwd Whether to use a custom current working directory
178
+ * @param options.dev Whether to use a custom installation key
179
+ * @returns
180
+ */
181
+ declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
182
+ export { EnsurePackagesOptions as E, FindPackageJsonCache as F, NormalizedPackageJson as N, PackageJson as P, NormalizedReadResult as a, findPackageJsonSync as b, clearPackageJsonCache as c, hasPackageJsonProperty as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJsonSync as i, writePackageJsonSync as j, parsePackageJson as p, writePackageJson as w };
package/dist/pnpm.d.ts CHANGED
@@ -1,18 +1,19 @@
1
- import type { JsonObject } from "type-fest";
2
- export type PnpmCatalog = Record<string, string>;
3
- export type PnpmCatalogs = {
4
- catalog?: PnpmCatalog;
5
- catalogs?: Record<string, PnpmCatalog>;
1
+ import { JsonObject } from 'type-fest';
2
+ type PnpmCatalog = Record<string, string>;
3
+ type PnpmCatalogs = {
4
+ catalog?: PnpmCatalog;
5
+ catalogs?: Record<string, PnpmCatalog>;
6
6
  };
7
7
  /** Checks if a package directory is included in the workspace packages configuration. */
8
- export declare const isPackageInWorkspace: (workspacePath: string, packagePath: string, workspacePackages: string[]) => boolean;
8
+ declare const isPackageInWorkspace: (workspacePath: string, packagePath: string, workspacePackages: string[]) => boolean;
9
9
  /** Reads, parses, and resolves catalogs from a pnpm-workspace file found by walking up the directory tree. */
10
- export declare const readPnpmCatalogs: (packagePath: string) => Promise<PnpmCatalogs | undefined>;
10
+ declare const readPnpmCatalogs: (packagePath: string) => Promise<PnpmCatalogs | undefined>;
11
11
  /** Reads, parses, and resolves catalogs from a pnpm-workspace file found by walking up the directory tree (synchronous). */
12
- export declare const readPnpmCatalogsSync: (packagePath: string) => PnpmCatalogs | undefined;
12
+ declare const readPnpmCatalogsSync: (packagePath: string) => PnpmCatalogs | undefined;
13
13
  /** Resolves a single catalog reference to its actual version. */
14
- export declare const resolveCatalogReference: (packageName: string, versionSpec: string, catalogs: PnpmCatalogs) => string | undefined;
14
+ declare const resolveCatalogReference: (packageName: string, versionSpec: string, catalogs: PnpmCatalogs) => string | undefined;
15
15
  /** Resolves catalog references in a single dependency object. */
16
- export declare const resolveDependenciesCatalogReferences: (dependencies: Record<string, string>, catalogs: PnpmCatalogs) => void;
16
+ declare const resolveDependenciesCatalogReferences: (dependencies: Record<string, string>, catalogs: PnpmCatalogs) => void;
17
17
  /** Resolves catalog references in package.json dependencies using the provided catalogs. */
18
- export declare const resolveCatalogReferences: (packageJson: JsonObject, catalogs: PnpmCatalogs) => void;
18
+ declare const resolveCatalogReferences: (packageJson: JsonObject, catalogs: PnpmCatalogs) => void;
19
+ export { PnpmCatalog, PnpmCatalogs, isPackageInWorkspace, readPnpmCatalogs, readPnpmCatalogsSync, resolveCatalogReference, resolveCatalogReferences, resolveDependenciesCatalogReferences };
package/dist/pnpm.js CHANGED
@@ -1 +1 @@
1
- var y=Object.defineProperty;var f=(t,a)=>y(t,"name",{value:a,configurable:!0});import{findUpSync as u,findUp as m}from"@visulima/fs";import{readYamlSync as v,readYaml as k}from"@visulima/fs/yaml";import{dirname as l,relative as b}from"@visulima/path";var h=Object.defineProperty,i=f((t,a)=>h(t,"name",{value:a,configurable:!0}),"c");const d=i((t,a,e)=>{const c=l(t),o=l(a),g=o===c?".":b(c,o);return e.some(p=>{const n=p.startsWith("./")?p.slice(2):p,s=g.startsWith("./")?g.slice(2):g;if(n==="."&&s===".")return!0;if(n.endsWith("/**")){const r=n.slice(0,-3);return s===r||s.startsWith(`${r}/`)}if(n.endsWith("/*")){const r=n.slice(0,-2);return r===""?s!=="."&&!s.includes("/"):s.startsWith(`${r}/`)||s===r}return s===n||s.startsWith(`${n}/`)})},"isPackageInWorkspace"),D=i(async t=>{const a=await m("pnpm-workspace.yaml",{cwd:l(t),type:"file"});if(!a)return;const e=await k(a),c=Array.isArray(e.packages)?e.packages:[];if(!d(a,t,c))return;const o={};return e.catalog&&typeof e.catalog=="object"&&(o.catalog=e.catalog),e.catalogs&&typeof e.catalogs=="object"&&(o.catalogs=e.catalogs),Object.keys(o).length>0?o:void 0},"readPnpmCatalogs"),A=i(t=>{const a=u("pnpm-workspace.yaml",{cwd:l(t),type:"file"});if(!a)return;const e=v(a),c=Array.isArray(e.packages)?e.packages:[];if(!d(a,t,c))return;const o={};return e.catalog&&typeof e.catalog=="object"&&(o.catalog=e.catalog),e.catalogs&&typeof e.catalogs=="object"&&(o.catalogs=e.catalogs),Object.keys(o).length>0?o:void 0},"readPnpmCatalogsSync"),C=i((t,a,e)=>{if(a==="catalog:")return e.catalog?.[t];if(a.startsWith("catalog:")){const c=a.slice(8);return e.catalogs?.[c]?.[t]}},"resolveCatalogReference"),W=i((t,a)=>{for(const[e,c]of Object.entries(t)){if(typeof c!="string")continue;const o=C(e,c,a);o&&(t[e]=o)}},"resolveDependenciesCatalogReferences"),O=i((t,a)=>{const e=["dependencies","devDependencies","peerDependencies","optionalDependencies"];for(const c of e){if(!t[c]||typeof t[c]!="object")continue;const o=t[c];W(o,a)}},"resolveCatalogReferences");export{d as isPackageInWorkspace,D as readPnpmCatalogs,A as readPnpmCatalogsSync,C as resolveCatalogReference,O as resolveCatalogReferences,W as resolveDependenciesCatalogReferences};
1
+ import{findUp as f,findUpSync as d}from"@visulima/fs";import{readYaml as y,readYamlSync as u}from"@visulima/fs/yaml";import{dirname as i,relative as m}from"@visulima/path";const p=(e,a,t)=>{const o=i(e),s=i(a),l=s===o?".":m(o,s);return t.some(g=>{const n=g.startsWith("./")?g.slice(2):g,c=l.startsWith("./")?l.slice(2):l;if(n==="."&&c===".")return!0;if(n.endsWith("/**")){const r=n.slice(0,-3);return c===r||c.startsWith(`${r}/`)}if(n.endsWith("/*")){const r=n.slice(0,-2);return r===""?c!=="."&&!c.includes("/"):c.startsWith(`${r}/`)||c===r}return c===n||c.startsWith(`${n}/`)})},v=async e=>{const a=await f("pnpm-workspace.yaml",{cwd:i(e),type:"file"});if(!a)return;const t=await y(a),o=Array.isArray(t.packages)?t.packages:[];if(!p(a,e,o))return;const s={};return t.catalog&&typeof t.catalog=="object"&&(s.catalog=t.catalog),t.catalogs&&typeof t.catalogs=="object"&&(s.catalogs=t.catalogs),Object.keys(s).length>0?s:void 0},w=e=>{const a=d("pnpm-workspace.yaml",{cwd:i(e),type:"file"});if(!a)return;const t=u(a),o=Array.isArray(t.packages)?t.packages:[];if(!p(a,e,o))return;const s={};return t.catalog&&typeof t.catalog=="object"&&(s.catalog=t.catalog),t.catalogs&&typeof t.catalogs=="object"&&(s.catalogs=t.catalogs),Object.keys(s).length>0?s:void 0},h=(e,a,t)=>{if(a==="catalog:")return t.catalog?.[e];if(a.startsWith("catalog:")){const o=a.slice(8);return t.catalogs?.[o]?.[e]}},k=(e,a)=>{for(const[t,o]of Object.entries(e)){if(typeof o!="string")continue;const s=h(t,o,a);s&&(e[t]=s)}},C=(e,a)=>{const t=["dependencies","devDependencies","peerDependencies","optionalDependencies"];for(const o of t){if(!e[o]||typeof e[o]!="object")continue;const s=e[o];k(s,a)}};export{p as isPackageInWorkspace,v as readPnpmCatalogs,w as readPnpmCatalogsSync,h as resolveCatalogReference,C as resolveCatalogReferences,k as resolveDependenciesCatalogReferences};
package/package.json CHANGED
@@ -1,41 +1,39 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "5.0.0-alpha.3",
3
+ "version": "5.0.0-alpha.31",
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",
7
+ "bun",
7
8
  "find",
8
9
  "find-monorepo-root",
9
- "find-up-pkg",
10
10
  "find-package-manager",
11
+ "find-up-pkg",
12
+ "json5",
11
13
  "mono-repo",
12
14
  "monorepo",
15
+ "npm",
13
16
  "package",
14
17
  "package-json",
15
18
  "package-manager",
16
19
  "package.json",
17
- "package.yaml",
18
20
  "package.json5",
21
+ "package.yaml",
19
22
  "packages",
20
23
  "pkg-dir",
21
24
  "pkg-manager",
22
25
  "pkg-types",
23
26
  "pkg-up",
27
+ "pnpm",
24
28
  "read-pkg",
25
29
  "read-pkg-up",
26
30
  "root",
27
- "pnpm",
28
- "bun",
29
- "npm",
30
- "yarn",
31
+ "visulima",
31
32
  "yaml",
32
- "json5",
33
- "visulima"
33
+ "yarn"
34
34
  ],
35
- "homepage": "https://www.visulima.com/docs/package/package",
36
- "bugs": {
37
- "url": "https://github.com/visulima/visulima/issues"
38
- },
35
+ "homepage": "https://visulima.com/packages/package/",
36
+ "bugs": "https://github.com/visulima/visulima/issues",
39
37
  "repository": {
40
38
  "type": "git",
41
39
  "url": "git+https://github.com/visulima/visulima.git",
@@ -79,6 +77,10 @@
79
77
  "types": "./dist/package-manager.d.ts",
80
78
  "default": "./dist/package-manager.js"
81
79
  },
80
+ "./lockfile": {
81
+ "types": "./dist/lockfile.d.ts",
82
+ "default": "./dist/lockfile.js"
83
+ },
82
84
  "./pnpm": {
83
85
  "types": "./dist/pnpm.d.ts",
84
86
  "default": "./dist/pnpm.js"
@@ -97,15 +99,14 @@
97
99
  ],
98
100
  "dependencies": {
99
101
  "@antfu/install-pkg": "^1.1.0",
100
- "@visulima/fs": "5.0.0-alpha.3",
101
- "@visulima/path": "3.0.0-alpha.4",
102
+ "@visulima/fs": "5.0.0-alpha.32",
103
+ "@visulima/path": "3.0.0-alpha.13",
102
104
  "json5": "^2.2.3",
103
- "normalize-package-data": "^8.0.0",
104
- "type-fest": "^5.3.1",
105
- "yaml": "^2.8.2"
105
+ "normalize-package-data": "^9.0.0",
106
+ "yaml": "2.9.0"
106
107
  },
107
108
  "engines": {
108
- "node": ">=22.13 <=25.x"
109
+ "node": "^22.14.0 || >=24.10.0"
109
110
  },
110
111
  "os": [
111
112
  "darwin",
@@ -1,15 +0,0 @@
1
- /**
2
- * Error thrown when a package was not found.
3
- */
4
- declare class PackageNotFoundError extends Error {
5
- /**
6
- * @param packageName The name of the package that was not found.
7
- * @param packageManager The package manager used to install the package.
8
- */
9
- constructor(packageName: string[] | string, packageManager?: string);
10
- get code(): string;
11
- set code(_name: string);
12
- get name(): string;
13
- set name(_name: string);
14
- }
15
- export default PackageNotFoundError;
@@ -1 +0,0 @@
1
- var o=Object.defineProperty;var a=(t,e)=>o(t,"name",{value:e,configurable:!0});import{findPackageManagerSync as n}from"../package-manager.js";var c=Object.defineProperty,i=a((t,e)=>c(t,"name",{value:e,configurable:!0}),"t");class g extends Error{static{a(this,"u")}static{i(this,"PackageNotFoundError")}constructor(e,r){if(typeof e=="string"&&(e=[e]),e.length===0){super("Package was not found.");return}if(r===void 0)try{r=n().packageManager}catch{}r===void 0&&(r="npm"),super(`Package '${e.join(" ")}' was not found. Please install it using '${r} install ${e.join(" ")}'`)}get code(){return"PACKAGE_NOT_FOUND"}set code(e){throw new Error("Cannot overwrite code PACKAGE_NOT_FOUND")}get name(){return"PackageNotFoundError"}set name(e){throw new Error("Cannot overwrite name of PackageNotFoundError")}}export{g as default};
package/dist/types.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import type { InstallPackageOptions } from "@antfu/install-pkg";
2
- import type { Theme } from "@inquirer/core";
3
- import type { PartialDeep } from "@inquirer/type";
4
- import type { Package as normalizePackage } from "normalize-package-data";
5
- import type { PackageJson as typeFestPackageJson } from "type-fest";
6
- export type NormalizedPackageJson = normalizePackage & PackageJson;
7
- export type PackageJson = typeFestPackageJson;
8
- export type Cache<T = any> = Map<string, T>;
9
- export type EnsurePackagesOptions = {
10
- /** Configuration for user confirmation prompts when installing packages */
11
- confirm?: {
12
- /** Default value for the confirmation prompt */
13
- default?: boolean;
14
- /** Message to display in the confirmation prompt, or a function that receives packages array */
15
- message: string | ((packages: string[]) => string);
16
- /** Theme configuration for the prompt interface */
17
- theme?: PartialDeep<Theme>;
18
- /** Function to transform the boolean value for display */
19
- transformer?: (value: boolean) => string;
20
- };
21
- /** Current working directory for package operations */
22
- cwd?: URL | string;
23
- /** Whether to include regular dependencies in the operation */
24
- deps?: boolean;
25
- /** Whether to include development dependencies in the operation */
26
- devDeps?: boolean;
27
- /** Additional options for package installation (excluding cwd and dev which are handled separately) */
28
- installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
29
- /** Custom logger interface for warning messages */
30
- logger?: {
31
- warn: (message: string) => void;
32
- };
33
- /** Whether to include peer dependencies in the operation */
34
- peerDeps?: boolean;
35
- /** Whether to throw an error when warnings are logged instead of just logging them */
36
- throwOnWarn?: boolean;
37
- };
@@ -1,11 +0,0 @@
1
- import type { EnsurePackagesOptions } from "../types.d.ts";
2
- type ConfirmOptions = EnsurePackagesOptions["confirm"] & {
3
- message: string;
4
- };
5
- /**
6
- * Creates a styled confirmation prompt using readline.
7
- * @param options Configuration options for the confirmation prompt
8
- * @returns A promise that resolves to true if confirmed, false otherwise
9
- */
10
- declare const confirm: (options: ConfirmOptions) => Promise<boolean>;
11
- export default confirm;
@@ -1,2 +0,0 @@
1
- declare const isNode: boolean;
2
- export default isNode;