@visulima/package 4.0.2 → 4.1.1

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 CHANGED
@@ -1,3 +1,42 @@
1
+ ## @visulima/package [4.1.1](https://github.com/visulima/visulima/compare/@visulima/package@4.1.0...@visulima/package@4.1.1) (2025-10-20)
2
+
3
+ ### Documentation
4
+
5
+ * update migration guide for @visulima/package v4.0.0 ([695b8c3](https://github.com/visulima/visulima/commit/695b8c38c3291d4f060a22d4b53f0bf647c82cb8))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * **deps:** update package versions and dependencies ([88d8d32](https://github.com/visulima/visulima/commit/88d8d32c4629a7a06c8770369191da2cc81087cc))
10
+ * update package dependencies across multiple packages ([17e3f23](https://github.com/visulima/visulima/commit/17e3f2377c8a3f98e2eed2192c5adaf6e32558b5))
11
+
12
+
13
+ ### Dependencies
14
+
15
+ * **@visulima/fs:** upgraded to 4.0.1
16
+
17
+ ## @visulima/package [4.1.0](https://github.com/visulima/visulima/compare/@visulima/package@4.0.2...@visulima/package@4.1.0) (2025-10-15)
18
+
19
+ ### Features
20
+
21
+ * Support pnpm package yaml and json5 ([#531](https://github.com/visulima/visulima/issues/531)) ([3b6591c](https://github.com/visulima/visulima/commit/3b6591c400be2ee435929f34f2560dac06b7cd3d))
22
+
23
+ ### Bug Fixes
24
+
25
+ * update @visulima/packem to 2.0.0-alpha.30 across multiple packages for improved compatibility ([27b346e](https://github.com/visulima/visulima/commit/27b346eaa1c0fb0e420d9a9824482028307f4249))
26
+ * update LICENSE.md and package.json dependencies ([cea0533](https://github.com/visulima/visulima/commit/cea0533dda1161c2280a823d2ecaefb814818535))
27
+
28
+ ### Miscellaneous Chores
29
+
30
+ * update linting commands and dependencies in package.json ([6a479b0](https://github.com/visulima/visulima/commit/6a479b04251d2bdde39ace13548b067b86d00c86))
31
+ * update package dependencies across multiple packages for improved compatibility and performance ([9567591](https://github.com/visulima/visulima/commit/9567591c415da3002f3a4fe08f8caf7ce01ca5f7))
32
+ * update type-fest dependency and adjust package configurations ([e8a1d89](https://github.com/visulima/visulima/commit/e8a1d8969f5e15f9323b1ca2a4bcff1beb8446fb))
33
+
34
+
35
+ ### Dependencies
36
+
37
+ * **@visulima/fs:** upgraded to 4.0.0
38
+ * **@visulima/path:** upgraded to 2.0.0
39
+
1
40
  ## @visulima/package [4.0.2](https://github.com/visulima/visulima/compare/@visulima/package@4.0.1...@visulima/package@4.0.2) (2025-10-02)
2
41
 
3
42
  ### Bug Fixes
package/LICENSE.md CHANGED
@@ -48,7 +48,7 @@ Repository: sindresorhus/dot-prop
48
48
 
49
49
  # Licenses of bundled types
50
50
  The published @visulima/package artifact additionally contains code with the following licenses:
51
- MIT, (MIT OR CC0-1.0)
51
+ MIT
52
52
 
53
53
  # Bundled types:
54
54
  ## @inquirer/core
@@ -109,133 +109,4 @@ Repository: https://github.com/SBoudrias/Inquirer.js.git
109
109
  > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
110
110
  > OTHER DEALINGS IN THE SOFTWARE.
111
111
 
112
- ---------------------------------------
113
-
114
- ## type-fest
115
- License: (MIT OR CC0-1.0)
116
- By: Sindre Sorhus
117
- Repository: sindresorhus/type-fest
118
-
119
- > Creative Commons Legal Code
120
- >
121
- > CC0 1.0 Universal
122
- >
123
- > CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
124
- > LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
125
- > ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
126
- > INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
127
- > REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
128
- > PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
129
- > THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
130
- > HEREUNDER.
131
- >
132
- > Statement of Purpose
133
- >
134
- > The laws of most jurisdictions throughout the world automatically confer
135
- > exclusive Copyright and Related Rights (defined below) upon the creator
136
- > and subsequent owner(s) (each and all, an "owner") of an original work of
137
- > authorship and/or a database (each, a "Work").
138
- >
139
- > Certain owners wish to permanently relinquish those rights to a Work for
140
- > the purpose of contributing to a commons of creative, cultural and
141
- > scientific works ("Commons") that the public can reliably and without fear
142
- > of later claims of infringement build upon, modify, incorporate in other
143
- > works, reuse and redistribute as freely as possible in any form whatsoever
144
- > and for any purposes, including without limitation commercial purposes.
145
- > These owners may contribute to the Commons to promote the ideal of a free
146
- > culture and the further production of creative, cultural and scientific
147
- > works, or to gain reputation or greater distribution for their Work in
148
- > part through the use and efforts of others.
149
- >
150
- > For these and/or other purposes and motivations, and without any
151
- > expectation of additional consideration or compensation, the person
152
- > associating CC0 with a Work (the "Affirmer"), to the extent that he or she
153
- > is an owner of Copyright and Related Rights in the Work, voluntarily
154
- > elects to apply CC0 to the Work and publicly distribute the Work under its
155
- > terms, with knowledge of his or her Copyright and Related Rights in the
156
- > Work and the meaning and intended legal effect of CC0 on those rights.
157
- >
158
- > 1. Copyright and Related Rights. A Work made available under CC0 may be
159
- > protected by copyright and related or neighboring rights ("Copyright and
160
- > Related Rights"). Copyright and Related Rights include, but are not
161
- > limited to, the following:
162
- >
163
- > i. the right to reproduce, adapt, distribute, perform, display,
164
- > communicate, and translate a Work;
165
- > ii. moral rights retained by the original author(s) and/or performer(s);
166
- > iii. publicity and privacy rights pertaining to a person's image or
167
- > likeness depicted in a Work;
168
- > iv. rights protecting against unfair competition in regards to a Work,
169
- > subject to the limitations in paragraph 4(a), below;
170
- > v. rights protecting the extraction, dissemination, use and reuse of data
171
- > in a Work;
172
- > vi. database rights (such as those arising under Directive 96/9/EC of the
173
- > European Parliament and of the Council of 11 March 1996 on the legal
174
- > protection of databases, and under any national implementation
175
- > thereof, including any amended or successor version of such
176
- > directive); and
177
- > vii. other similar, equivalent or corresponding rights throughout the
178
- > world based on applicable law or treaty, and any national
179
- > implementations thereof.
180
- >
181
- > 2. Waiver. To the greatest extent permitted by, but not in contravention
182
- > of, applicable law, Affirmer hereby overtly, fully, permanently,
183
- > irrevocably and unconditionally waives, abandons, and surrenders all of
184
- > Affirmer's Copyright and Related Rights and associated claims and causes
185
- > of action, whether now known or unknown (including existing as well as
186
- > future claims and causes of action), in the Work (i) in all territories
187
- > worldwide, (ii) for the maximum duration provided by applicable law or
188
- > treaty (including future time extensions), (iii) in any current or future
189
- > medium and for any number of copies, and (iv) for any purpose whatsoever,
190
- > including without limitation commercial, advertising or promotional
191
- > purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
192
- > member of the public at large and to the detriment of Affirmer's heirs and
193
- > successors, fully intending that such Waiver shall not be subject to
194
- > revocation, rescission, cancellation, termination, or any other legal or
195
- > equitable action to disrupt the quiet enjoyment of the Work by the public
196
- > as contemplated by Affirmer's express Statement of Purpose.
197
- >
198
- > 3. Public License Fallback. Should any part of the Waiver for any reason
199
- > be judged legally invalid or ineffective under applicable law, then the
200
- > Waiver shall be preserved to the maximum extent permitted taking into
201
- > account Affirmer's express Statement of Purpose. In addition, to the
202
- > extent the Waiver is so judged Affirmer hereby grants to each affected
203
- > person a royalty-free, non transferable, non sublicensable, non exclusive,
204
- > irrevocable and unconditional license to exercise Affirmer's Copyright and
205
- > Related Rights in the Work (i) in all territories worldwide, (ii) for the
206
- > maximum duration provided by applicable law or treaty (including future
207
- > time extensions), (iii) in any current or future medium and for any number
208
- > of copies, and (iv) for any purpose whatsoever, including without
209
- > limitation commercial, advertising or promotional purposes (the
210
- > "License"). The License shall be deemed effective as of the date CC0 was
211
- > applied by Affirmer to the Work. Should any part of the License for any
212
- > reason be judged legally invalid or ineffective under applicable law, such
213
- > partial invalidity or ineffectiveness shall not invalidate the remainder
214
- > of the License, and in such case Affirmer hereby affirms that he or she
215
- > will not (i) exercise any of his or her remaining Copyright and Related
216
- > Rights in the Work or (ii) assert any associated claims and causes of
217
- > action with respect to the Work, in either case contrary to Affirmer's
218
- > express Statement of Purpose.
219
- >
220
- > 4. Limitations and Disclaimers.
221
- >
222
- > a. No trademark or patent rights held by Affirmer are waived, abandoned,
223
- > surrendered, licensed or otherwise affected by this document.
224
- > b. Affirmer offers the Work as-is and makes no representations or
225
- > warranties of any kind concerning the Work, express, implied,
226
- > statutory or otherwise, including without limitation warranties of
227
- > title, merchantability, fitness for a particular purpose, non
228
- > infringement, or the absence of latent or other defects, accuracy, or
229
- > the present or absence of errors, whether or not discoverable, all to
230
- > the greatest extent permissible under applicable law.
231
- > c. Affirmer disclaims responsibility for clearing rights of other persons
232
- > that may apply to the Work or any use thereof, including without
233
- > limitation any person's Copyright and Related Rights in the Work.
234
- > Further, Affirmer disclaims responsibility for obtaining any necessary
235
- > consents, permissions or other rights required for any use of the
236
- > Work.
237
- > d. Affirmer understands and acknowledges that Creative Commons is not a
238
- > party to this document and has no duty or obligation with respect to
239
- > this CC0 or use of the Work.
240
-
241
112
  <!-- /TYPE_DEPENDENCIES -->
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <div align="center">
2
2
  <h3>Visulima package</h3>
3
3
  <p>
4
- A comprehensive package management utility that helps you find root directories, monorepos, package managers, and parse package.json files with advanced features like catalog resolution.
4
+ 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 and caching.
5
5
 
6
6
  Built on top of
7
7
 
@@ -85,15 +85,41 @@ const result = await findPackageRoot();
85
85
 
86
86
  #### findPackageJson
87
87
 
88
- Finds and parses a package.json file, searching parent directories if needed.
88
+ Finds and parses a package.json, package.yaml, or package.json5 file, searching parent directories if needed.
89
89
 
90
90
  ```typescript
91
91
  import { findPackageJson } from "@visulima/package";
92
92
 
93
+ // Basic usage - searches for package.json, package.yaml, and package.json5
93
94
  const result = await findPackageJson();
94
95
  // => { packageJson: { name: 'my-package', ... }, path: '/path/to/package.json' }
96
+
97
+ // With options to enable/disable specific formats and features
98
+ const result = await findPackageJson("/path/to/project", {
99
+ yaml: true, // Enable package.yaml support (default: true)
100
+ json5: true, // Enable package.json5 support (default: true)
101
+ resolveCatalogs: true, // Resolve pnpm catalog references (default: false)
102
+ cache: true, // Enable caching of parsed results (default: false)
103
+ });
95
104
  ```
96
105
 
106
+ **File Search Priority**: The function searches for files in the following order:
107
+
108
+ 1. `package.json` (highest priority)
109
+ 2. `package.yaml`
110
+ 3. `package.json5` (lowest priority)
111
+
112
+ **Supported Formats**:
113
+
114
+ - **package.json**: Standard JSON format
115
+ - **package.yaml**: YAML format (introduced in pnpm/pnpm#1799)
116
+ - **package.json5**: JSON5 format with comments and trailing commas support
117
+
118
+ **Additional Options**:
119
+
120
+ - **resolveCatalogs**: Resolve pnpm catalog references to actual versions (requires pnpm workspace)
121
+ - **cache**: Cache parsed results to improve performance on repeated calls
122
+
97
123
  ### Package Manager Detection
98
124
 
99
125
  #### findPackageManager
@@ -133,27 +159,95 @@ const version = await getPackageManagerVersion("pnpm");
133
159
 
134
160
  #### parsePackageJson
135
161
 
136
- Parses and normalizes package.json data with optional catalog resolution support.
162
+ Parses and normalizes package.json, package.yaml, or package.json5 data with optional catalog resolution support.
137
163
 
138
164
  ```typescript
139
165
  import { parsePackageJson } from "@visulima/package";
140
166
 
141
- // Basic parsing
167
+ // Basic parsing - automatically detects format by file extension
142
168
  const packageJson = await parsePackageJson("./package.json");
169
+ const packageYaml = await parsePackageJson("./package.yaml");
170
+ const packageJson5 = await parsePackageJson("./package.json5");
143
171
 
144
172
  // With catalog resolution (pnpm workspaces only)
145
173
  const packageJson = await parsePackageJson("./package.json", {
146
174
  resolveCatalogs: true,
147
175
  });
148
176
 
177
+ // With format control and caching options
178
+ const packageJson = await parsePackageJson("./package.yaml", {
179
+ yaml: true, // Enable package.yaml support (default: true)
180
+ json5: false, // Disable package.json5 support (default: true)
181
+ resolveCatalogs: true, // Resolve pnpm catalog references (default: false)
182
+ cache: true, // Enable caching for file-based parsing (default: false)
183
+ });
184
+
149
185
  // Synchronous version
150
186
  import { parsePackageJsonSync } from "@visulima/package";
151
187
 
152
188
  const packageJson = parsePackageJsonSync("./package.json", {
153
189
  resolveCatalogs: true,
190
+ cache: true, // Enable caching for file-based parsing (default: false)
154
191
  });
155
192
  ```
156
193
 
194
+ **Supported File Formats**:
195
+
196
+ - **package.json**: Standard JSON format
197
+ - **package.yaml**: YAML format with support for comments and more readable syntax
198
+ - **package.json5**: JSON5 format with support for comments, trailing commas, and unquoted keys
199
+
200
+ **Format Detection**: The function automatically detects the file format based on the file extension:
201
+
202
+ - `.json` → JSON parsing
203
+ - `.yaml` or `.yml` → YAML parsing
204
+ - `.json5` → JSON5 parsing
205
+
206
+ **Caching**: When `cache: true` is set, the function uses a global cache to store parsed results for file-based inputs only (not for object or JSON string inputs). This can improve performance when parsing the same file multiple times.
207
+
208
+ ```typescript
209
+ // File-based caching with global cache
210
+ const result1 = await parsePackageJson("./package.json", { cache: true }); // Parses and caches
211
+ const result2 = await parsePackageJson("./package.json", { cache: true }); // Returns cached result
212
+
213
+ // Custom cache instance
214
+ const myCache = new Map();
215
+ const result3 = await parsePackageJson("./package.json", { cache: myCache }); // Uses custom cache
216
+
217
+ // Objects and strings are never cached
218
+ const result4 = await parsePackageJson({ name: "test" }, { cache: true }); // Always parsed fresh
219
+ ```
220
+
221
+ **Example File Formats**:
222
+
223
+ ```yaml
224
+ # package.yaml
225
+ name: my-package
226
+ version: 1.0.0
227
+ dependencies:
228
+ react: ^18.0.0
229
+ typescript: ^5.0.0
230
+ scripts:
231
+ build: "tsc"
232
+ test: "vitest"
233
+ ```
234
+
235
+ ```json5
236
+ // package.json5
237
+ {
238
+ name: "my-package",
239
+ version: "1.0.0",
240
+ dependencies: {
241
+ react: "^18.0.0",
242
+ typescript: "^5.0.0",
243
+ },
244
+ scripts: {
245
+ build: "tsc",
246
+ test: "vitest",
247
+ },
248
+ }
249
+ ```
250
+
157
251
  **Catalog Resolution**: When `resolveCatalogs: true` is set, the function will:
158
252
 
159
253
  1. Search for `pnpm-workspace.yaml` in parent directories
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export { PackageNotFoundError } from './error.js';
2
2
  export { RootMonorepo, Strategy, findMonorepoRoot, findMonorepoRootSync } from './monorepo.js';
3
3
  export { findPackageRoot, findPackageRootSync } from './package.js';
4
- export { E as EnsurePackagesOptions, F as FindPackageJsonCache, i as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, c as parsePackageJsonSync, w as writePackageJson, d as writePackageJsonSync } from './packem_shared/package-json-t7TSgmrQ.js';
4
+ export { E as EnsurePackagesOptions, F as FindPackageJsonCache, i as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, c as parsePackageJsonSync, w as writePackageJson, d as writePackageJsonSync } from './packem_shared/package-json-CiMqtMwD.js';
5
5
  export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
6
6
  export { PnpmCatalog, PnpmCatalogs, isPackageInWorkspace, readPnpmCatalogs, readPnpmCatalogsSync, resolveCatalogReference, resolveCatalogReferences, resolveDependenciesCatalogReferences } from './pnpm.js';
7
7
  import '@visulima/fs';
8
- import './packem_shared/json-value.d-DU4PzU4Z.js';
8
+ import 'type-fest';
9
9
  import '@antfu/install-pkg';
10
10
  import 'normalize-package-data';
@@ -6,4 +6,5 @@ interface RootMonorepo<T extends Strategy = Strategy> {
6
6
  declare const findMonorepoRoot: (cwd?: URL | string) => Promise<RootMonorepo>;
7
7
  declare const findMonorepoRootSync: (cwd?: URL | string) => RootMonorepo;
8
8
 
9
- export { type RootMonorepo, type Strategy, findMonorepoRoot, findMonorepoRootSync };
9
+ export { findMonorepoRoot, findMonorepoRootSync };
10
+ export type { RootMonorepo, Strategy };
package/dist/monorepo.js CHANGED
@@ -1 +1 @@
1
- var m=Object.defineProperty;var c=(n,r)=>m(n,"name",{value:r,configurable:!0});import{findUp as l,readJson as y,findUpSync as g,readJsonSync as h}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{dirname as u,join as a}from"@visulima/path";import{findPackageManager as w,findPackageManagerSync as k}from"./package-manager.js";const{existsSync:p,readFileSync:i}=globalThis.process.getBuiltinModule("node:fs");var j=Object.defineProperty,d=c((n,r)=>j(n,"name",{value:r,configurable:!0}),"i");const v=d(async n=>{const r=await l(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(r?.endsWith("lerna.json")){const o=await y(r);if(o.useWorkspaces||o.packages)return{path:u(r),strategy:"lerna"}}const s=r?.endsWith("turbo.json");try{const{packageManager:o,path:e}=await w(n);if(["npm","yarn"].includes(o)){const t=a(e,"package.json");if(p(t)&&i(a(e,"package.json"),"utf8").includes("workspaces"))return{path:e,strategy:s?"turbo":o}}else if(o==="pnpm"){const t=a(e,"pnpm-workspace.yaml");if(p(t))return{path:e,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof f))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)},"findMonorepoRoot"),E=d(n=>{const r=g(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(r?.endsWith("lerna.json")){const o=h(r);if(o.useWorkspaces||o.packages)return{path:u(r),strategy:"lerna"}}const s=r?.endsWith("turbo.json");try{const{packageManager:o,path:e}=k(n);if(["npm","yarn"].includes(o)){const t=a(e,"package.json");if(p(t)&&i(a(e,"package.json"),"utf8").includes("workspaces"))return{path:e,strategy:s?"turbo":o}}else if(o==="pnpm"){const t=a(e,"pnpm-workspace.yaml");if(p(t))return{path:e,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof f))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)},"findMonorepoRootSync");export{v as findMonorepoRoot,E as findMonorepoRootSync};
1
+ var l=Object.defineProperty;var p=(r,e)=>l(r,"name",{value:e,configurable:!0});import{createRequire as y}from"node:module";import{findUp as j,readJson as w,findUpSync as b,readJsonSync as k}from"@visulima/fs";import{NotFoundError as u}from"@visulima/fs/error";import{dirname as d,join as a}from"@visulima/path";import{findPackageManager as _,findPackageManagerSync as M}from"./package-manager.js";const g=y(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=p(r=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[e,t]=i.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return i.getBuiltinModule(r)}return g(r)},"__cjs_getBuiltinModule"),{existsSync:c,readFileSync:f}=h("node:fs");var S=Object.defineProperty,m=p((r,e)=>S(r,"name",{value:e,configurable:!0}),"i");const E=m(async r=>{const e=await j(["lerna.json","turbo.json"],{type:"file",...r&&{cwd:r}});if(e?.endsWith("lerna.json")){const o=await w(e);if(o.useWorkspaces||o.packages)return{path:d(e),strategy:"lerna"}}const t=e?.endsWith("turbo.json");try{const{packageManager:o,path:n}=await _(r);if(["npm","yarn"].includes(o)){const s=a(n,"package.json");if(c(s)&&f(a(n,"package.json"),"utf8").includes("workspaces"))return{path:n,strategy:t?"turbo":o}}else if(o==="pnpm"){const s=a(n,"pnpm-workspace.yaml");if(c(s))return{path:n,strategy:t?"turbo":"pnpm"}}}catch(o){if(!(o instanceof u))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${r} using lerna, yarn, pnpm, or npm as indicators.`)},"findMonorepoRoot"),T=m(r=>{const e=b(["lerna.json","turbo.json"],{type:"file",...r&&{cwd:r}});if(e?.endsWith("lerna.json")){const o=k(e);if(o.useWorkspaces||o.packages)return{path:d(e),strategy:"lerna"}}const t=e?.endsWith("turbo.json");try{const{packageManager:o,path:n}=M(r);if(["npm","yarn"].includes(o)){const s=a(n,"package.json");if(c(s)&&f(a(n,"package.json"),"utf8").includes("workspaces"))return{path:n,strategy:t?"turbo":o}}else if(o==="pnpm"){const s=a(n,"pnpm-workspace.yaml");if(c(s))return{path:n,strategy:t?"turbo":"pnpm"}}}catch(o){if(!(o instanceof u))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${r} using lerna, yarn, pnpm, or npm as indicators.`)},"findMonorepoRootSync");export{E as findMonorepoRoot,T as findMonorepoRootSync};
@@ -1,5 +1,5 @@
1
1
  import '@visulima/fs';
2
- import './packem_shared/json-value.d-DU4PzU4Z.js';
3
- export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, c as parsePackageJsonSync, w as writePackageJson, d as writePackageJsonSync } from './packem_shared/package-json-t7TSgmrQ.js';
2
+ import 'type-fest';
3
+ export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, c as parsePackageJsonSync, w as writePackageJson, d as writePackageJsonSync } from './packem_shared/package-json-CiMqtMwD.js';
4
4
  import '@antfu/install-pkg';
5
5
  import 'normalize-package-data';
@@ -1,3 +1,3 @@
1
- var W=Object.defineProperty;var i=(e,t)=>W(e,"name",{value:t,configurable:!0});import{installPackage as K}from"@antfu/install-pkg";import R from"@inquirer/confirm";import{readJsonSync as I,findUp as q,readJson as S,findUpSync as F,writeJson as M,writeJsonSync as V}from"@visulima/fs";import{NotFoundError as A}from"@visulima/fs/error";import{parseJson as D,toPath as b}from"@visulima/fs/utils";import{join as C}from"@visulima/path";import{readPnpmCatalogsSync as U,resolveCatalogReferences as N,readPnpmCatalogs as Y}from"./pnpm.js";const z=globalThis.process.getBuiltinModule("module").createRequire(import.meta.url),{existsSync:j}=globalThis.process.getBuiltinModule("node:fs"),B=z("normalize-package-data");var G=Object.defineProperty,f=i((e,t)=>G(e,"name",{value:t,configurable:!0}),"f$1");const u=f(e=>{const t=typeof e;return e!==null&&(t==="object"||t==="function")},"isObject"),H=f(e=>u(e)&&Object.keys(e).length===0,"isEmptyObject"),P=new Set(["__proto__","prototype","constructor"]),L=new Set("0123456789");function v(e){return typeof e=="string"&&/^\d+$/.test(e)&&Number.parseInt(e,10)>=0&&(e==="0"||!e.startsWith("0"))}i(v,"h");f(v,"isValidArrayIndex");function y(e,t,r){return r>0&&typeof e=="string"&&Array.isArray(t)&&v(e)?Number.parseInt(e,10):e}i(y,"u");f(y,"normalizeKey");function w(e){const t=[];let r="",n="start",o=!1;for(const s of e)switch(s){case"\\":{if(n==="index")throw new Error("Invalid character in an index");if(n==="indexEnd")throw new Error("Invalid character after an index");o&&(r+=s),n="property",o=!o;break}case".":{if(n==="index")throw new Error("Invalid character in an index");if(n==="indexEnd"){n="property";break}if(o){o=!1,r+=s;break}if(P.has(r))return[];t.push(r),r="",n="property";break}case"[":{if(n==="index")throw new Error("Invalid character in an index");if(n==="indexEnd"){n="index";break}if(o){o=!1,r+=s;break}if(n==="property"){if(P.has(r))return[];t.push(r),r=""}n="index";break}case"]":{if(n==="index"){t.push(Number.parseInt(r,10)),r="",n="indexEnd";break}if(n==="indexEnd")throw new Error("Invalid character after an index")}default:{if(n==="index"&&!L.has(s))throw new Error("Invalid character in an index");if(n==="indexEnd")throw new Error("Invalid character after an index");n==="start"&&(n="property"),o&&(o=!1,r+="\\"),r+=s}}switch(o&&(r+="\\"),n){case"property":{if(P.has(r))return[];t.push(r);break}case"index":throw new Error("Index was not closed");case"start":{t.push("");break}}return t}i(w,"l");f(w,"getPathSegments");function m(e,t){if(!Array.isArray(e)||typeof t=="number")return!1;const r=Number.parseInt(t,10);return Number.isInteger(r)&&String(r)===t}i(m,"c$1");f(m,"isStringIndex");function x(e,t){if(m(e,t))throw new Error("Cannot use string index")}i(x,"x");f(x,"assertNotStringIndex");function g(e,t,r){if(!u(e)||typeof t!="string")return r===void 0?e:r;const n=w(t);if(n.length===0)return r;for(let o=0;o<n.length;o++){const s=n[o],a=y(s,e,o);if(a===s&&m(e,s)?e=o===n.length-1?void 0:null:e=e[a],e==null){if(o!==n.length-1)return r;break}}return e===void 0?r:e}i(g,"getProperty");f(g,"getProperty");function T(e,t,r){if(!u(e)||typeof t!="string")return e;const n=e,o=w(t);for(let s=0;s<o.length;s++){const a=o[s],p=y(a,e,s);if(p===a&&x(e,a),s===o.length-1)e[p]=r;else if(!u(e[p])){const c=o[s+1],l=typeof c=="number"||typeof c=="string"&&v(c);e[p]=l?[]:{}}e=e[p]}return n}i(T,"setProperty");f(T,"setProperty");function Q(e,t){if(!u(e)||typeof t!="string")return!1;const r=w(t);for(let n=0;n<r.length;n++){const o=r[n],s=y(o,e,n);if(s===o&&x(e,o),n===r.length-1)return Object.hasOwn(e,s)?(delete e[s],!0):!1;if(e=e[s],!u(e))return!1}}i(Q,"deleteProperty");f(Q,"deleteProperty");function h(e,t){if(!u(e)||typeof t!="string")return!1;const r=w(t);if(r.length===0)return!1;for(const[n,o]of r.entries()){const s=y(o,e,n),a=s===o&&m(e,o);if(!u(e)||!(s in e)||a)return!1;e=e[s]}return!0}i(h,"hasProperty");f(h,"hasProperty");function O(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}i(O,"escapePath");f(O,"escapePath");function E(e){const t=Object.entries(e);return Array.isArray(e)?t.map(([r,n])=>[Number(r),n]):t}i(E,"g");f(E,"entries");function _(e){let t="";for(let[r,n]of E(e))typeof n=="number"?t+=`[${n}]`:(n=O(n),t+=r===0?n:`.${n}`);return t}i(_,"A");f(_,"stringifyPath");function*J(e,t=[]){if(!u(e)||H(e)){t.length>0&&(yield _(t));return}for(const[r,n]of E(e))yield*J(n,[...t,r])}i(J,"w");f(J,"deepKeysIterator");function X(e){return[...J(e)]}i(X,"deepKeys");f(X,"deepKeys");function Z(e){const t={};if(!u(e))return t;for(const[r,n]of Object.entries(e))T(t,r,n);return t}i(Z,"unflatten");f(Z,"unflatten");const ee=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window;var te=Object.defineProperty,d=i((e,t)=>te(e,"name",{value:t,configurable:!0}),"c");const $=new Map;class ne extends Error{static{i(this,"S")}static{d(this,"PackageJsonValidationError")}constructor(t){super(`The following warnings were encountered while normalizing package data:
2
- - ${t.join(`
3
- - `)}`),this.name="PackageJsonValidationError"}}const k=d((e,t,r=[])=>{const n=[];if(B(e,o=>{n.push(o)},t),t&&n.length>0){const o=n.filter(s=>!r.some(a=>a instanceof RegExp?a.test(s):a===s));if(o.length>0)throw new ne(o)}return e},"normalizeInput"),le=d(async(e,t={})=>{const r={type:"file"};e&&(r.cwd=e);const n=await q("package.json",r);if(!n)throw new A("No such file or directory, for package.json found.");const o=t.cache&&typeof t.cache!="boolean"?t.cache:$;if(t.cache&&o.has(n))return o.get(n);const s=await S(n);k(s,t.strict??!1,t.ignoreWarnings);const a={packageJson:s,path:n};return o.set(n,a),a},"findPackageJson"),de=d((e,t={})=>{const r={type:"file"};e&&(r.cwd=e);const n=F("package.json",r);if(!n)throw new A("No such file or directory, for package.json found.");const o=t.cache&&typeof t.cache!="boolean"?t.cache:$;if(t.cache&&o.has(n))return o.get(n);const s=I(n);k(s,t.strict??!1,t.ignoreWarnings);const a={packageJson:s,path:n};return o.set(n,a),a},"findPackageJsonSync"),ue=d(async(e,t={})=>{const{cwd:r,...n}=t,o=b(t.cwd??process.cwd());await M(C(o,"package.json"),e,n)},"writePackageJson"),ge=d((e,t={})=>{const{cwd:r,...n}=t,o=b(t.cwd??process.cwd());V(C(o,"package.json"),e,n)},"writePackageJsonSync"),he=d((e,t)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!r&&typeof e!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let n,o=!1;if(r?n=structuredClone(e):j(e)?(n=I(e),o=!0):n=D(e),t?.resolveCatalogs)if(o){const s=U(e);s&&N(n,s)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");return k(n,t?.strict??!1,t?.ignoreWarnings),n},"parsePackageJsonSync"),ye=d(async(e,t)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!r&&typeof e!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let n,o=!1;if(r?n=structuredClone(e):j(e)?(n=await S(e),o=!0):n=D(e),t?.resolveCatalogs)if(o){const s=await Y(e);s&&N(n,s)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");return k(n,t?.strict??!1,t?.ignoreWarnings),n},"parsePackageJson"),we=d((e,t,r)=>g(e,t,r),"getPackageJsonProperty"),me=d((e,t)=>h(e,t),"hasPackageJsonProperty"),ke=d((e,t,r)=>{const n=g(e,"dependencies",{}),o=g(e,"devDependencies",{}),s=g(e,"peerDependencies",{}),a={...n,...o,...r?.peerDeps===!1?{}:s};for(const p of t)if(h(a,p))return!0;return!1},"hasPackageJsonAnyDependency"),Pe=d(async(e,t,r="dependencies",n={})=>{const o=g(e,"dependencies",{}),s=g(e,"devDependencies",{}),a=g(e,"peerDependencies",{}),p=[],c={deps:!0,devDeps:!0,peerDeps:!1,...n};for(const l of t)c.deps&&h(o,l)||c.devDeps&&h(s,l)||c.peerDeps&&h(a,l)||p.push(l);if(p.length!==0){if(process.env.CI||ee&&!process.stdout?.isTTY){const l=`Skipping package installation for [${t.join(", ")}] because the process is not interactive.`;if(n.throwOnWarn)throw new Error(l);n.logger?.warn?n.logger.warn(l):console.warn(l);return}if(typeof c.confirm?.message=="function"&&(c.confirm.message=c.confirm.message(p)),c.confirm?.message===void 0){const l=`${p.length===1?"Package is":"Packages are"} required for this config: ${p.join(", ")}. Do you want to install them?`;c.confirm===void 0?c.confirm={message:l}:c.confirm.message=l}await R(c.confirm)&&await K(p,{...c.installPackage,cwd:c.cwd?b(c.cwd):void 0,dev:r==="devDependencies"})}},"ensurePackages");export{Pe as ensurePackages,le as findPackageJson,de as findPackageJsonSync,we as getPackageJsonProperty,ke as hasPackageJsonAnyDependency,me as hasPackageJsonProperty,ye as parsePackageJson,he as parsePackageJsonSync,ue as writePackageJson,ge as writePackageJsonSync};
1
+ var q=Object.defineProperty;var f=(e,n)=>q(e,"name",{value:n,configurable:!0});import{createRequire as B}from"node:module";import{installPackage as V}from"@antfu/install-pkg";import G from"@inquirer/confirm";import{readJsonSync as U,readFileSync as X,findUp as H,findUpSync as L,writeJson as Q,writeJsonSync as Z,readJson as ee,readFile as ne}from"@visulima/fs";import{NotFoundError as A}from"@visulima/fs/error";import{parseJson as S,toPath as v}from"@visulima/fs/utils";import{readYamlSync as te,readYaml as re}from"@visulima/fs/yaml";import{join as N}from"@visulima/path";import{readPnpmCatalogsSync as T,resolveCatalogReferences as P,readPnpmCatalogs as _}from"./pnpm.js";const j=B(import.meta.url),y=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,K=f(e=>{if(typeof y<"u"&&y.versions&&y.versions.node){const[n,r]=y.versions.node.split(".").map(Number);if(n>22||n===22&&r>=3||n===20&&r>=16)return y.getBuiltinModule(e)}return j(e)},"__cjs_getBuiltinModule"),{existsSync:J}=K("node:fs"),I=j("json5"),oe=j("normalize-package-data");var se=Object.defineProperty,l=f((e,n)=>se(e,"name",{value:n,configurable:!0}),"f");const h=l(e=>{const n=typeof e;return e!==null&&(n==="object"||n==="function")},"isObject"),ae=l(e=>{if(!h(e))return!1;for(const n in e)if(Object.hasOwn(e,n))return!1;return!0},"isEmptyObject"),F=new Set(["__proto__","prototype","constructor"]),D=1e6,ie=l(e=>e>="0"&&e<="9","isDigit");function m(e){if(e==="0")return!0;if(/^[1-9]\d*$/.test(e)){const n=Number.parseInt(e,10);return n<=Number.MAX_SAFE_INTEGER&&n<=D}return!1}f(m,"p");l(m,"shouldCoerceToNumber");function b(e,n){return F.has(e)?!1:(e&&m(e)?n.push(Number.parseInt(e,10)):n.push(e),!0)}f(b,"y");l(b,"processSegment");function C(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);const n=[];let r="",t="start",o=!1,s=0;for(const a of e){if(s++,o){r+=a,o=!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}`);o=!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(!b(r,n))return[];r="",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((r||t==="property")&&!b(r,n))return[];r=""}t="index";break}case"]":{if(t==="index"){if(r==="")r=(n.pop()||"")+"[]",t="property";else{const i=Number.parseInt(r,10);!Number.isNaN(i)&&Number.isFinite(i)&&i>=0&&i<=Number.MAX_SAFE_INTEGER&&i<=D&&r===String(i)?n.push(i):n.push(r),r="",t="indexEnd"}break}if(t==="indexEnd")throw new Error(`Invalid character '${a}' after an index at position ${s}`);r+=a;break}default:{if(t==="index"&&!ie(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"),r+=a}}}switch(o&&(r+="\\"),t){case"property":{if(!b(r,n))return[];break}case"index":throw new Error("Index was not closed");case"start":{n.push("");break}}return n}f(C,"parsePath");l(C,"parsePath");function w(e){if(typeof e=="string")return C(e);if(Array.isArray(e)){const n=[];for(const[r,t]of e.entries()){if(typeof t!="string"&&typeof t!="number")throw new TypeError(`Expected a string or number for path segment at index ${r}, got ${typeof t}`);if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError(`Path segment at index ${r} must be a finite number, got ${t}`);if(F.has(t))return[];typeof t=="string"&&m(t)?n.push(Number.parseInt(t,10)):n.push(t)}return n}return[]}f(w,"d");l(w,"normalizePath");function d(e,n,r){if(!h(e)||typeof n!="string"&&!Array.isArray(n))return r===void 0?e:r;const t=w(n);if(t.length===0)return r;for(let o=0;o<t.length;o++){const s=t[o];if(e=e[s],e==null){if(o!==t.length-1)return r;break}}return e===void 0?r:e}f(d,"getProperty");l(d,"getProperty");function O(e,n,r){if(!h(e)||typeof n!="string"&&!Array.isArray(n))return e;const t=e,o=w(n);if(o.length===0)return e;for(let s=0;s<o.length;s++){const a=o[s];if(s===o.length-1)e[a]=r;else if(!h(e[a])){const i=typeof o[s+1]=="number";e[a]=i?[]:{}}e=e[a]}return t}f(O,"setProperty");l(O,"setProperty");function ce(e,n){if(!h(e)||typeof n!="string"&&!Array.isArray(n))return!1;const r=w(n);if(r.length===0)return!1;for(let t=0;t<r.length;t++){const o=r[t];if(t===r.length-1)return Object.hasOwn(e,o)?(delete e[o],!0):!1;if(e=e[o],!h(e))return!1}}f(ce,"deleteProperty");l(ce,"deleteProperty");function g(e,n){if(!h(e)||typeof n!="string"&&!Array.isArray(n))return!1;const r=w(n);if(r.length===0)return!1;for(const t of r){if(!h(e)||!(t in e))return!1;e=e[t]}return!0}f(g,"hasProperty");l(g,"hasProperty");function $(e){if(typeof e!="string")throw new TypeError(`Expected a string, got ${typeof e}`);return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}f($,"escapePath");l($,"escapePath");function W(e){const n=Object.entries(e);return Array.isArray(e)?n.map(([r,t])=>[m(r)?Number.parseInt(r,10):r,t]):n}f(W,"m$1");l(W,"normalizeEntries");function M(e,n={}){if(!Array.isArray(e))throw new TypeError(`Expected an array, got ${typeof e}`);const{preferDotForIndices:r=!1}=n,t=[];for(const[o,s]of e.entries()){if(typeof s!="string"&&typeof s!="number")throw new TypeError(`Expected a string or number for path segment at index ${o}, got ${typeof s}`);if(typeof s=="number")if(!Number.isInteger(s)||s<0){const a=$(String(s));t.push(o===0?a:`.${a}`)}else r&&o>0?t.push(`.${s}`):t.push(`[${s}]`);else if(typeof s=="string")if(s==="")o===0||t.push(".");else if(m(s)){const a=Number.parseInt(s,10);r&&o>0?t.push(`.${a}`):t.push(`[${a}]`)}else{const a=$(s);t.push(o===0?a:`.${a}`)}}return t.join("")}f(M,"stringifyPath");l(M,"stringifyPath");function*x(e,n=[],r=new Set){if(!h(e)||ae(e)){n.length>0&&(yield M(n));return}if(!r.has(e)){r.add(e);for(const[t,o]of W(e))n.push(t),yield*x(o,n,r),n.pop();r.delete(e)}}f(x,"x");l(x,"deepKeysIterator");function fe(e){return[...x(e)]}f(fe,"deepKeys");l(fe,"deepKeys");function pe(e){const n={};if(!h(e))return n;for(const[r,t]of Object.entries(e))O(n,r,t);return n}f(pe,"unflatten");l(pe,"unflatten");const le=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window;var ue=Object.defineProperty,p=f((e,n)=>ue(e,"name",{value:n,configurable:!0}),"l");const k=new Map,R=new Map;class he extends Error{static{f(this,"F")}static{p(this,"PackageJsonValidationError")}constructor(n){super(`The following warnings were encountered while normalizing package data:
2
+ - ${n.join(`
3
+ - `)}`),this.name="PackageJsonValidationError"}}const E=p((e,n,r=[])=>{const t=[];if(oe(e,o=>{t.push(o)},n),n&&t.length>0){const o=t.filter(s=>!r.some(a=>a instanceof RegExp?a.test(s):a===s));if(o.length>0)throw new he(o)}return e},"normalizeInput"),de=p(async e=>await re(e),"parseYamlFile"),ge=p(e=>te(e),"parseYamlFileSync"),ye=p(async e=>{const n=await ne(e);return I.parse(n)},"parseJson5File"),me=p(e=>{const n=X(e);return I.parse(n)},"parseJson5FileSync"),z=p(async(e,n)=>n?.yaml!==!1&&(e.endsWith(".yaml")||e.endsWith(".yml"))?de(e):n?.json5!==!1&&e.endsWith(".json5")?ye(e):ee(e),"parsePackageFile"),Y=p((e,n)=>n?.yaml!==!1&&(e.endsWith(".yaml")||e.endsWith(".yml"))?ge(e):n?.json5!==!1&&e.endsWith(".json5")?me(e):U(e),"parsePackageFileSync"),Ae=p(async(e,n={})=>{const r={type:"file"};e&&(r.cwd=e);const t=["package.json"];n.yaml!==!1&&t.push("package.yaml","package.yml"),n.json5!==!1&&t.push("package.json5");let o;for await(const c of t)if(o=await H(c,r),o)break;if(!o)throw new A(`No such file or directory, for ${t.join(", ").replace(/, ([^,]*)$/," or $1")} found.`);const s=n.cache&&typeof n.cache!="boolean"?n.cache:R;if(n.cache&&s.has(o))return s.get(o);const a=await z(o,n);if(n.resolveCatalogs){const c=await _(o);c&&P(a,c)}E(a,n.strict??!1,n.ignoreWarnings);const i={packageJson:a,path:o};return n.cache&&s.set(o,i),i},"findPackageJson"),Se=p((e,n={})=>{const r={type:"file"};e&&(r.cwd=e);const t=["package.json"];n.yaml!==!1&&t.push("package.yaml","package.yml"),n.json5!==!1&&t.push("package.json5");let o;for(const c of t)if(o=L(c,r),o)break;if(!o)throw new A(`No such file or directory, for ${t.join(", ").replace(/, ([^,]*)$/," or $1")} found.`);const s=n.cache&&typeof n.cache!="boolean"?n.cache:R;if(n.cache&&s.has(o))return s.get(o);const a=Y(o,n);if(n.resolveCatalogs){const c=T(o);c&&P(a,c)}E(a,n.strict??!1,n.ignoreWarnings);const i={packageJson:a,path:o};return n.cache&&s.set(o,i),i},"findPackageJsonSync"),Ne=p(async(e,n={})=>{const{cwd:r,...t}=n,o=v(n.cwd??process.cwd());await Q(N(o,"package.json"),e,t)},"writePackageJson"),Ie=p((e,n={})=>{const{cwd:r,...t}=n,o=v(n.cwd??process.cwd());Z(N(o,"package.json"),e,t)},"writePackageJsonSync"),Te=p((e,n)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!r&&typeof e!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let t,o=!1,s;if(r)t=structuredClone(e);else if(J(e)){s=e;const i=n?.cache&&typeof n.cache!="boolean"?n.cache:k;if(n?.cache&&i.has(s))return i.get(s);t=Y(s,n),o=!0}else t=S(e);if(n?.resolveCatalogs)if(o){const i=T(e);i&&P(t,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");E(t,n?.strict??!1,n?.ignoreWarnings);const a=t;return o&&s&&n?.cache&&(n.cache&&typeof n.cache!="boolean"?n.cache:k).set(s,a),a},"parsePackageJsonSync"),_e=p(async(e,n)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!r&&typeof e!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let t,o=!1,s;if(r)t=structuredClone(e);else if(J(e)){s=e;const i=n?.cache&&typeof n.cache!="boolean"?n.cache:k;if(n?.cache&&i.has(s))return i.get(s);t=await z(s,n),o=!0}else t=S(e);if(n?.resolveCatalogs)if(o){const i=await _(e);i&&P(t,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");E(t,n?.strict??!1,n?.ignoreWarnings);const a=t;return o&&s&&n?.cache&&(n.cache&&typeof n.cache!="boolean"?n.cache:k).set(s,a),a},"parsePackageJson"),Fe=p((e,n,r)=>d(e,n,r),"getPackageJsonProperty"),De=p((e,n)=>g(e,n),"hasPackageJsonProperty"),Ce=p((e,n,r)=>{const t=d(e,"dependencies",{}),o=d(e,"devDependencies",{}),s=d(e,"peerDependencies",{}),a={...t,...o,...r?.peerDeps===!1?{}:s};for(const i of n)if(g(a,i))return!0;return!1},"hasPackageJsonAnyDependency"),Oe=p(async(e,n,r="dependencies",t={})=>{const o=d(e,"dependencies",{}),s=d(e,"devDependencies",{}),a=d(e,"peerDependencies",{}),i=[],c={deps:!0,devDeps:!0,peerDeps:!1,...t};for(const u of n)c.deps&&g(o,u)||c.devDeps&&g(s,u)||c.peerDeps&&g(a,u)||i.push(u);if(i.length!==0){if(process.env.CI||le&&!process.stdout?.isTTY){const u=`Skipping package installation for [${n.join(", ")}] because the process is not interactive.`;if(t.throwOnWarn)throw new Error(u);t.logger?.warn?t.logger.warn(u):console.warn(u);return}if(typeof c.confirm?.message=="function"&&(c.confirm.message=c.confirm.message(i)),c.confirm?.message===void 0){const u=`${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:u}:c.confirm.message=u}await G(c.confirm)&&await V(i,{...c.installPackage,cwd:c.cwd?v(c.cwd):void 0,dev:r==="devDependencies"})}},"ensurePackages");export{Oe as ensurePackages,Ae as findPackageJson,Se as findPackageJsonSync,Fe as getPackageJsonProperty,Ce as hasPackageJsonAnyDependency,De as hasPackageJsonProperty,_e as parsePackageJson,Te as parsePackageJsonSync,Ne as writePackageJson,Ie as writePackageJsonSync};
@@ -18,4 +18,5 @@ declare const generateMissingPackagesInstallMessage: (packageName: string, missi
18
18
  preMessage?: string;
19
19
  }) => string;
20
20
 
21
- export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager };
21
+ export { findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager };
22
+ export type { PackageManager, PackageManagerResult };
@@ -1,13 +1,13 @@
1
- var b=Object.defineProperty;var d=(n,a)=>b(n,"name",{value:a,configurable:!0});import{findUpSync as f,findUp as m}from"@visulima/fs";import{NotFoundError as c}from"@visulima/fs/error";import{join as p,dirname as t}from"@visulima/path";import{parsePackageJsonSync as u,parsePackageJson as j}from"./package-json.js";const{execSync:v}=globalThis.process.getBuiltinModule("node:child_process"),{existsSync:k,readFileSync:P}=globalThis.process.getBuiltinModule("node:fs");var W=Object.defineProperty,r=d((n,a)=>W(n,"name",{value:a,configurable:!0}),"t");const l=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],h=r(n=>{let a;if(l.forEach(i=>{!a&&k(p(n,i))&&(a=p(n,i))}),a)return a;const e=p(n,"package.json");if(k(e)&&u(P(e,"utf8")).packageManager!==void 0)return e},"packageMangerFindUpMatcher"),S=r(async n=>{if(!n)throw new c("Could not find a package manager");if(n.endsWith("package.json")){const a=await j(n);if(a.packageManager){const e=["npm","yarn","pnpm","bun"].find(i=>a.packageManager.startsWith(i));if(e)return{packageManager:e,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 c("Could not find a package manager")},"findPackageManagerOnFile"),$=r(n=>{if(!n)throw new c("Could not find a package manager");if(n.endsWith("package.json")){const a=u(n);if(a.packageManager){const e=["npm","yarn","pnpm","bun"].find(i=>a.packageManager.startsWith(i));if(e)return{packageManager:e,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 c("Could not find a package manager")},"findPackageManagerOnFileSync"),I=r(async n=>{const a=await m(l,{type:"file",...n&&{cwd:n}});if(!a)throw new Error("Could not find lock file");return a},"findLockFile"),L=r(n=>{const a=f(l,{type:"file",...n&&{cwd:n}});if(!a)throw new Error("Could not find lock file");return a},"findLockFileSync"),O=r(async n=>{const a=await m(h,{...n&&{cwd:n}});return S(a)},"findPackageManager"),U=r(n=>{const a=f(h,{...n&&{cwd:n}});return $(a)},"findPackageManagerSync"),N=r(n=>v(`${n} --version`).toString("utf8").trim(),"getPackageManagerVersion"),T=r(async()=>{if(!process.env.npm_config_user_agent)return;const n=process.env.npm_config_user_agent.split(" ")[0],a=n.lastIndexOf("/"),e=n.slice(0,Math.max(0,a));return{name:e==="npminstall"?"cnpm":e,version:n.slice(Math.max(0,a+1))}},"identifyInitiatingPackageManager"),B=r((n,a,e)=>{const i=a.length===1?"":"s";if(e.packageManagers===void 0&&(e.packageManagers=["npm","pnpm","yarn"]),e.packageManagers.length===0)throw new Error("No package managers provided, please provide at least one package manager");if(a.length===0)throw new Error("No missing packages provided, please provide at least one missing package");let g=`
2
- ${e.preMessage??""}
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=`
2
+ ${a.preMessage??""}
3
3
  ${n} could not find the following package${i}
4
4
 
5
- ${a.join(`
5
+ ${e.join(`
6
6
  `)}
7
7
 
8
8
  To install the missing package${i}, please run the following command:
9
- `;const M=r(o=>o.split("@").includes("@")?o:`${o}@latest`,"atLatest"),w=e.packageManagers.map(o=>{const s=a.map(y=>M(y)).join(" ");switch(o){case"bun":return` bun add ${s} -D`;case"npm":return` npm install ${s} --save-dev`;case"pnpm":return` pnpm add ${s} -D`;case"yarn":return` yarn add ${s} --dev`;default:throw new Error("Unknown package manager")}});return g+=w.join(`
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(`
10
10
 
11
11
  or
12
12
 
13
- `),e.postMessage&&(g+=e.postMessage),g},"generateMissingPackagesInstallMessage");export{I as findLockFile,L as findLockFileSync,O as findPackageManager,U as findPackageManagerSync,B as generateMissingPackagesInstallMessage,N as getPackageManagerVersion,T as identifyInitiatingPackageManager};
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};
package/dist/package.js CHANGED
@@ -1 +1 @@
1
- var p=Object.defineProperty;var c=(n,o)=>p(n,"name",{value:o,configurable:!0});import{findUp as a,findUpSync as f,readJsonSync as y}from"@visulima/fs";import{dirname as e,join as d}from"@visulima/path";import{findLockFile as u,findLockFileSync as l}from"./package-manager.js";const{existsSync:g}=globalThis.process.getBuiltinModule("node:fs");var w=Object.defineProperty,i=c((n,o)=>w(n,"name",{value:o,configurable:!0}),"i");const s=i(n=>{if(g(d(n,"package.json"))){const o=y(d(n,"package.json"));if(o.name&&o.private!==!0)return"package.json"}},"packageJsonMatcher"),j=i(async n=>{try{const t=await u(n);return e(t)}catch{}const o=await a(".git/config",{...n&&{cwd:n},type:"file"});if(o)return e(e(o));const r=await a(s,{...n&&{cwd:n},type:"file"});if(r)return e(r);throw new Error("Could not find root directory")},"findPackageRoot"),P=i(n=>{try{const t=l(n);return e(t)}catch{}const o=f(".git/config",{...n&&{cwd:n},type:"file"});if(o)return e(e(o));const r=f(s,{...n&&{cwd:n},type:"file"});if(r)return e(r);throw new Error("Could not find root directory")},"findPackageRootSync");export{j as findPackageRoot,P as findPackageRootSync};
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),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=c(e=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[o,n]=t.versions.node.split(".").map(Number);if(o>22||o===22&&n>=3||o===20&&n>=16)return t.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}),"i");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 i=await w(e);return r(i)}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 i=j(e);return r(i)}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};