@visulima/package 3.6.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/LICENSE.md +0 -116
  3. package/README.md +153 -51
  4. package/dist/error.js +1 -0
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.js +1 -0
  7. package/dist/monorepo.js +1 -0
  8. package/dist/package-json.d.ts +3 -1
  9. package/dist/package-json.js +3 -0
  10. package/dist/package-manager.js +13 -0
  11. package/dist/package.js +1 -0
  12. package/dist/packem_shared/PackageNotFoundError-BictYTIA.js +1 -0
  13. package/dist/packem_shared/json-value.d-DU4PzU4Z.d.ts +33 -0
  14. package/dist/packem_shared/{package-json-KA2fTML0.d.cts → package-json-k3TJ_oy7.d.ts} +1056 -710
  15. package/dist/pnpm.d.ts +15 -0
  16. package/dist/pnpm.js +1 -0
  17. package/package.json +27 -78
  18. package/dist/error.cjs +0 -1
  19. package/dist/error.d.cts +0 -9
  20. package/dist/error.d.mts +0 -9
  21. package/dist/error.mjs +0 -1
  22. package/dist/index.cjs +0 -1
  23. package/dist/index.d.cts +0 -7
  24. package/dist/index.d.mts +0 -7
  25. package/dist/index.mjs +0 -1
  26. package/dist/monorepo.cjs +0 -1
  27. package/dist/monorepo.d.cts +0 -9
  28. package/dist/monorepo.d.mts +0 -9
  29. package/dist/monorepo.mjs +0 -1
  30. package/dist/package-json.cjs +0 -3
  31. package/dist/package-json.d.cts +0 -3
  32. package/dist/package-json.d.mts +0 -3
  33. package/dist/package-json.mjs +0 -3
  34. package/dist/package-manager.cjs +0 -13
  35. package/dist/package-manager.d.cts +0 -21
  36. package/dist/package-manager.d.mts +0 -21
  37. package/dist/package-manager.mjs +0 -13
  38. package/dist/package.cjs +0 -1
  39. package/dist/package.d.cts +0 -4
  40. package/dist/package.d.mts +0 -4
  41. package/dist/package.mjs +0 -1
  42. package/dist/packem_shared/PackageNotFoundError-CEETCi0X.mjs +0 -1
  43. package/dist/packem_shared/PackageNotFoundError-CY57YCot.cjs +0 -1
  44. package/dist/packem_shared/package-json-KA2fTML0.d.mts +0 -2405
  45. package/dist/packem_shared/package-json-KA2fTML0.d.ts +0 -2405
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## @visulima/package [4.0.0](https://github.com/visulima/visulima/compare/@visulima/package@3.6.1...@visulima/package@4.0.0) (2025-10-02)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ * **package:** - parsePackageJson is now async and returns Promise<NormalizedPackageJson>
6
+ - Removed CommonJS exports - package is now ESM-only
7
+ - All functions must be awaited when upgrading from v3.x
8
+
9
+ ### Features
10
+
11
+ * **package:** add pnpm catalog protocol support with breaking changes ([#529](https://github.com/visulima/visulima/issues/529)) ([76e72bd](https://github.com/visulima/visulima/commit/76e72bdb40192f271837e90acca026ef1eb79907))
12
+
13
+ ## @visulima/package [3.6.1](https://github.com/visulima/visulima/compare/@visulima/package@3.6.0...@visulima/package@3.6.1) (2025-10-01)
14
+
15
+ ### Bug Fixes
16
+
17
+ * update package dependencies and remove ESLint configuration files ([f964ad7](https://github.com/visulima/visulima/commit/f964ad7d7e6e27da19b8b9b283552336192fd596))
18
+
19
+ ### Miscellaneous Chores
20
+
21
+ * update LICENSE and package.json for consistency ([c2d6ad4](https://github.com/visulima/visulima/commit/c2d6ad41322581639f37c6c648919fba2986211e))
22
+
1
23
  ## @visulima/package [3.6.0](https://github.com/visulima/visulima/compare/@visulima/package@3.5.12...@visulima/package@3.6.0) (2025-09-30)
2
24
 
3
25
  ### Features
package/LICENSE.md CHANGED
@@ -27,35 +27,6 @@ The published @visulima/package artifact additionally contains code with the fol
27
27
  MIT
28
28
 
29
29
  # Bundled dependencies:
30
- ## @antfu/install-pkg
31
- License: MIT
32
- By: Anthony Fu
33
- Repository: git+https://github.com/antfu/install-pkg.git
34
-
35
- > MIT License
36
- >
37
- > Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
38
- >
39
- > Permission is hereby granted, free of charge, to any person obtaining a copy
40
- > of this software and associated documentation files (the "Software"), to deal
41
- > in the Software without restriction, including without limitation the rights
42
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
- > copies of the Software, and to permit persons to whom the Software is
44
- > furnished to do so, subject to the following conditions:
45
- >
46
- > The above copyright notice and this permission notice shall be included in all
47
- > copies or substantial portions of the Software.
48
- >
49
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
- > SOFTWARE.
56
-
57
- ---------------------------------------
58
-
59
30
  ## dot-prop
60
31
  License: MIT
61
32
  By: Sindre Sorhus
@@ -71,64 +42,6 @@ Repository: sindresorhus/dot-prop
71
42
  >
72
43
  > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
73
44
 
74
- ---------------------------------------
75
-
76
- ## package-manager-detector
77
- License: MIT
78
- By: Anthony Fu
79
- Repository: git+https://github.com/antfu-collective/package-manager-detector.git
80
-
81
- > MIT License
82
- >
83
- > Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
84
- >
85
- > Permission is hereby granted, free of charge, to any person obtaining a copy
86
- > of this software and associated documentation files (the "Software"), to deal
87
- > in the Software without restriction, including without limitation the rights
88
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
89
- > copies of the Software, and to permit persons to whom the Software is
90
- > furnished to do so, subject to the following conditions:
91
- >
92
- > The above copyright notice and this permission notice shall be included in all
93
- > copies or substantial portions of the Software.
94
- >
95
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
96
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
97
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
98
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
99
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
100
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
101
- > SOFTWARE.
102
-
103
- ---------------------------------------
104
-
105
- ## tinyexec
106
- License: MIT
107
- By: James Garbutt
108
- Repository: git+https://github.com/tinylibs/tinyexec.git
109
-
110
- > MIT License
111
- >
112
- > Copyright (c) 2024 Tinylibs
113
- >
114
- > Permission is hereby granted, free of charge, to any person obtaining a copy
115
- > of this software and associated documentation files (the "Software"), to deal
116
- > in the Software without restriction, including without limitation the rights
117
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
118
- > copies of the Software, and to permit persons to whom the Software is
119
- > furnished to do so, subject to the following conditions:
120
- >
121
- > The above copyright notice and this permission notice shall be included in all
122
- > copies or substantial portions of the Software.
123
- >
124
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
125
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
126
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
127
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
128
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
129
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
130
- > SOFTWARE.
131
-
132
45
  <!-- /DEPENDENCIES -->
133
46
 
134
47
  <!-- TYPE_DEPENDENCIES -->
@@ -138,35 +51,6 @@ The published @visulima/package artifact additionally contains code with the fol
138
51
  MIT, (MIT OR CC0-1.0)
139
52
 
140
53
  # Bundled types:
141
- ## @antfu/install-pkg
142
- License: MIT
143
- By: Anthony Fu
144
- Repository: git+https://github.com/antfu/install-pkg.git
145
-
146
- > MIT License
147
- >
148
- > Copyright (c) 2021 Anthony Fu <https://github.com/antfu>
149
- >
150
- > Permission is hereby granted, free of charge, to any person obtaining a copy
151
- > of this software and associated documentation files (the "Software"), to deal
152
- > in the Software without restriction, including without limitation the rights
153
- > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
154
- > copies of the Software, and to permit persons to whom the Software is
155
- > furnished to do so, subject to the following conditions:
156
- >
157
- > The above copyright notice and this permission notice shall be included in all
158
- > copies or substantial portions of the Software.
159
- >
160
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161
- > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
162
- > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
163
- > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
164
- > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
165
- > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
166
- > SOFTWARE.
167
-
168
- ---------------------------------------
169
-
170
54
  ## @inquirer/core
171
55
  License: MIT
172
56
  By: Simon Boudrias
package/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  <div align="center">
2
2
  <h3>Visulima package</h3>
3
3
  <p>
4
- One Package to rule them all, finds your root-dir, monorepo or package manager is built on top of
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.
5
+
6
+ Built on top of
5
7
 
6
8
  [@visulima/fs](https://github.com/visulima/visulima/tree/main/packages/fs),
7
9
  [@visulima/path](https://github.com/visulima/visulima/tree/main/packages/path),
8
10
  [normalize-package-data](https://github.com/npm/normalize-package-data),
9
- [pathe](https://github.com/unjs/pathe),and
11
+ [pathe](https://github.com/unjs/pathe), and
10
12
  [type-fest](https://github.com/sindresorhus/type-fest)
11
13
 
12
14
  </p>
@@ -34,109 +36,209 @@
34
36
 
35
37
  ## Install
36
38
 
37
- ```sh
39
+ ```bash
38
40
  npm install @visulima/package
39
41
  ```
40
42
 
41
- ```sh
43
+ ```bash
42
44
  yarn add @visulima/package
43
45
  ```
44
46
 
45
- ```sh
47
+ ```bash
46
48
  pnpm add @visulima/package
47
49
  ```
48
50
 
49
- ## Usage
51
+ ## API
52
+
53
+ ### Monorepo Detection
50
54
 
51
- ### findMonorepoRoot
55
+ #### findMonorepoRoot
52
56
 
53
- Find the root directory path and strategy for a monorepo based on the given current working directory (cwd).
57
+ Finds the root directory and strategy for a monorepo by searching for workspace configuration files.
54
58
 
55
- ```ts
59
+ ```typescript
56
60
  import { findMonorepoRoot } from "@visulima/package";
57
- // or import { findMonorepoRoot } from '@visulima/package/monorepo';
58
61
 
59
- const root = findMonorepoRoot(); // => /Users/../Projects/visulima
62
+ const result = await findMonorepoRoot();
63
+ // => { path: '/path/to/monorepo', strategy: 'pnpm' }
60
64
  ```
61
65
 
62
- ### findPackageRoot
66
+ Supports detection of:
67
+
68
+ - pnpm workspaces (pnpm-workspace.yaml)
69
+ - npm/yarn workspaces (package.json workspaces field)
70
+ - Lerna (lerna.json)
71
+ - Turborepo (turbo.json)
63
72
 
64
- Find the root directory path and strategy for a package based on the given current working directory (cwd).
73
+ ### Package Detection
65
74
 
66
- ```ts
75
+ #### findPackageRoot
76
+
77
+ Finds the root directory of a package by locating its package.json file.
78
+
79
+ ```typescript
67
80
  import { findPackageRoot } from "@visulima/package";
68
- // or import { findPackageRoot } from '@visulima/package/package';
69
81
 
70
- const root = findPackageRoot(); // => /Users/../Projects/visulima/packages/package
82
+ const result = await findPackageRoot();
83
+ // => { path: '/path/to/package', strategy: 'package' }
71
84
  ```
72
85
 
73
- ### findPackageJson
86
+ #### findPackageJson
74
87
 
75
- Find the package.json file in the specified directory or its parent directories.
88
+ Finds and parses a package.json file, searching parent directories if needed.
76
89
 
77
- ```ts
90
+ ```typescript
78
91
  import { findPackageJson } from "@visulima/package";
79
- // or import { findPackageJson } from '@visulima/package/package-json';
80
92
 
81
- const root = findPackageJson(); // => /Users/../Projects/visulima/packages/package/package.json
93
+ const result = await findPackageJson();
94
+ // => { packageJson: { name: 'my-package', ... }, path: '/path/to/package.json' }
82
95
  ```
83
96
 
84
- ### writePackageJson
97
+ ### Package Manager Detection
85
98
 
86
- Writes the package.json file with the given data.
99
+ #### findPackageManager
87
100
 
88
- ```ts
89
- import { writePackageJson } from "@visulima/package";
90
- // or import { writePackageJson } from '@visulima/package/package-json';
101
+ Detects the package manager used in a project by examining lock files and package.json.
91
102
 
92
- writePackageJson({ name: "visulima" } /* ,{ cwd: "./" }*/);
103
+ ```typescript
104
+ import { findPackageManager } from "@visulima/package";
105
+
106
+ const result = await findPackageManager();
107
+ // => { packageManager: 'pnpm', path: '/path/to/project' }
93
108
  ```
94
109
 
95
- ### parsePackageJson
110
+ #### findLockFile
111
+
112
+ Finds the lock file for the current project.
113
+
114
+ ```typescript
115
+ import { findLockFile } from "@visulima/package";
116
+
117
+ const lockFile = await findLockFile();
118
+ // => '/path/to/pnpm-lock.yaml'
119
+ ```
120
+
121
+ #### getPackageManagerVersion
122
+
123
+ Retrieves the version of a specific package manager.
124
+
125
+ ```typescript
126
+ import { getPackageManagerVersion } from "@visulima/package";
127
+
128
+ const version = await getPackageManagerVersion("pnpm");
129
+ // => '8.15.0'
130
+ ```
131
+
132
+ ### Package.json Operations
133
+
134
+ #### parsePackageJson
96
135
 
97
- Parse the package.json file.
136
+ Parses and normalizes package.json data with optional catalog resolution support.
98
137
 
99
- ```ts
138
+ ```typescript
100
139
  import { parsePackageJson } from "@visulima/package";
101
140
 
102
- const packageJson = parsePackageJson(/* object or package.json as string */);
141
+ // Basic parsing
142
+ const packageJson = await parsePackageJson("./package.json");
143
+
144
+ // With catalog resolution (pnpm workspaces only)
145
+ const packageJson = await parsePackageJson("./package.json", {
146
+ resolveCatalogs: true,
147
+ });
148
+
149
+ // Synchronous version
150
+ import { parsePackageJsonSync } from "@visulima/package";
151
+
152
+ const packageJson = parsePackageJsonSync("./package.json", {
153
+ resolveCatalogs: true,
154
+ });
103
155
  ```
104
156
 
105
- ### findLockFile
157
+ **Catalog Resolution**: When `resolveCatalogs: true` is set, the function will:
106
158
 
107
- Asynchronously finds a lock file in the specified directory or any of its parent directories.
159
+ 1. Search for `pnpm-workspace.yaml` in parent directories
160
+ 2. Verify the package.json is part of the workspace
161
+ 3. Resolve catalog references like `"react": "catalog:"` to actual versions
108
162
 
109
- ```ts
110
- import { findLockFile } from "@visulima/package";
111
- // or import { findLockFile } from '@visulima/package/package-manager';
163
+ Example with pnpm catalogs:
164
+
165
+ ```yaml
166
+ # pnpm-workspace.yaml
167
+ catalog:
168
+ react: ^18.0.0
169
+ typescript: ^5.0.0
112
170
 
113
- const lockFile = await findLockFile(); // => /Users/../Projects/visulima/packages/package/package-lock.json
171
+ catalogs:
172
+ next:
173
+ react: ^19.0.0
174
+
175
+ packages:
176
+ - packages/*
114
177
  ```
115
178
 
116
- ### findPackageManager
179
+ ```json
180
+ // package.json
181
+ {
182
+ "dependencies": {
183
+ "react": "catalog:",
184
+ "typescript": "catalog:",
185
+ "next": "catalog:next"
186
+ }
187
+ }
188
+ ```
117
189
 
118
- Finds the package manager used in a project based on the presence of lock files or package.json configuration.
190
+ After resolution:
119
191
 
120
- If found, returns the package manager and the path to the lock file or package.json.
192
+ ```json
193
+ {
194
+ "dependencies": {
195
+ "react": "^18.0.0",
196
+ "typescript": "^5.0.0",
197
+ "next": "^19.0.0"
198
+ }
199
+ }
200
+ ```
121
201
 
122
- Throws an error if no lock file or package.json is found.
202
+ #### writePackageJson
123
203
 
124
- ```ts
125
- import { findPackageManager } from "@visulima/package";
126
- // or import { findPackageManager } from '@visulima/package/package-manager';
204
+ Writes normalized package.json data to a file.
205
+
206
+ ```typescript
207
+ import { writePackageJson } from "@visulima/package";
127
208
 
128
- const { packageManager, path } = findPackageManager(); // => { packageManager: 'npm', path: '/Users/../Projects/visulima/packages/package' }
209
+ await writePackageJson({
210
+ name: "my-package",
211
+ version: "1.0.0",
212
+ });
129
213
  ```
130
214
 
131
- ### getPackageManagerVersion
215
+ #### Package.json Utilities
132
216
 
133
- Retrieves the version of the specified package manager.
217
+ ```typescript
218
+ import { getPackageJsonProperty, hasPackageJsonProperty, hasPackageJsonAnyDependency } from "@visulima/package";
134
219
 
135
- ```ts
136
- import { getPackageManagerVersion } from "@visulima/package";
137
- // or import { getPackageManagerVersion } from '@visulima/package/package-manager';
220
+ const packageJson = await parsePackageJson("./package.json");
221
+
222
+ // Get a property value
223
+ const name = getPackageJsonProperty(packageJson, "name");
224
+
225
+ // Check if property exists
226
+ const hasScripts = hasPackageJsonProperty(packageJson, "scripts");
227
+
228
+ // Check for dependencies
229
+ const hasReact = hasPackageJsonAnyDependency(packageJson, ["react", "preact"]);
230
+ ```
231
+
232
+ ### Package Installation
233
+
234
+ #### ensurePackages
235
+
236
+ Ensures specified packages are installed, prompting the user if needed.
237
+
238
+ ```typescript
239
+ import { ensurePackages } from "@visulima/package";
138
240
 
139
- const version = await getPackageManagerVersion("npm"); // => 7.5.4
241
+ await ensurePackages(packageJson, ["typescript", "@types/node"], "devDependencies");
140
242
  ```
141
243
 
142
244
  ## Supported Node.js Versions
package/dist/error.js ADDED
@@ -0,0 +1 @@
1
+ import{default as a}from"./packem_shared/PackageNotFoundError-BictYTIA.js";export{a as PackageNotFoundError};
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
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, d 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, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-KA2fTML0.js';
4
+ export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d 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, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-k3TJ_oy7.js';
5
5
  export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
6
6
  import '@visulima/fs';
7
+ import './packem_shared/json-value.d-DU4PzU4Z.js';
8
+ import '@antfu/install-pkg';
7
9
  import 'normalize-package-data';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{default as n}from"./packem_shared/PackageNotFoundError-BictYTIA.js";import{findMonorepoRoot as r,findMonorepoRootSync as g}from"./monorepo.js";import{findPackageRoot as i,findPackageRootSync as t}from"./package.js";import{ensurePackages as k,findPackageJson as P,findPackageJsonSync as f,getPackageJsonProperty as d,hasPackageJsonAnyDependency as p,hasPackageJsonProperty as y,parsePackageJson as J,writePackageJson as M,writePackageJsonSync as S}from"./package-json.js";import{findLockFile as m,findLockFileSync as x,findPackageManager as R,findPackageManagerSync as u,generateMissingPackagesInstallMessage as F,getPackageManagerVersion as h,identifyInitiatingPackageManager as w}from"./package-manager.js";export{n as PackageNotFoundError,k as ensurePackages,m as findLockFile,x as findLockFileSync,r as findMonorepoRoot,g as findMonorepoRootSync,P as findPackageJson,f as findPackageJsonSync,R as findPackageManager,u as findPackageManagerSync,i as findPackageRoot,t as findPackageRootSync,F as generateMissingPackagesInstallMessage,d as getPackageJsonProperty,h as getPackageManagerVersion,p as hasPackageJsonAnyDependency,y as hasPackageJsonProperty,w as identifyInitiatingPackageManager,J as parsePackageJson,M as writePackageJson,S as writePackageJsonSync};
@@ -0,0 +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,3 +1,5 @@
1
1
  import '@visulima/fs';
2
- 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, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-KA2fTML0.js';
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, i as parsePackageJsonSync, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-k3TJ_oy7.js';
4
+ import '@antfu/install-pkg';
3
5
  import 'normalize-package-data';
@@ -0,0 +1,3 @@
1
+ var _=Object.defineProperty;var i=(e,n)=>_(e,"name",{value:n,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 x}from"@visulima/fs/utils";import{join as N}from"@visulima/path";import{readPnpmCatalogsSync as U,resolveCatalogReferences as O,readPnpmCatalogs as Y}from"./pnpm.js";const z=globalThis.process.getBuiltinModule("module").createRequire(import.meta.url),{existsSync:m}=globalThis.process.getBuiltinModule("node:fs"),B=z("normalize-package-data");var G=Object.defineProperty,f=i((e,n)=>G(e,"name",{value:n,configurable:!0}),"f");const u=f(e=>{const n=typeof e;return e!==null&&(n==="object"||n==="function")},"isObject"),H=f(e=>u(e)&&Object.keys(e).length===0,"isEmptyObject"),b=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,n,r){return r>0&&typeof e=="string"&&Array.isArray(n)&&v(e)?Number.parseInt(e,10):e}i(y,"u");f(y,"normalizeKey");function w(e){const n=[];let r="",t="start",o=!1;for(const a of e)switch(a){case"\\":{if(t==="index")throw new Error("Invalid character in an index");if(t==="indexEnd")throw new Error("Invalid character after an index");o&&(r+=a),t="property",o=!o;break}case".":{if(t==="index")throw new Error("Invalid character in an index");if(t==="indexEnd"){t="property";break}if(o){o=!1,r+=a;break}if(b.has(r))return[];n.push(r),r="",t="property";break}case"[":{if(t==="index")throw new Error("Invalid character in an index");if(t==="indexEnd"){t="index";break}if(o){o=!1,r+=a;break}if(t==="property"){if(b.has(r))return[];n.push(r),r=""}t="index";break}case"]":{if(t==="index"){n.push(Number.parseInt(r,10)),r="",t="indexEnd";break}if(t==="indexEnd")throw new Error("Invalid character after an index")}default:{if(t==="index"&&!L.has(a))throw new Error("Invalid character in an index");if(t==="indexEnd")throw new Error("Invalid character after an index");t==="start"&&(t="property"),o&&(o=!1,r+="\\"),r+=a}}switch(o&&(r+="\\"),t){case"property":{if(b.has(r))return[];n.push(r);break}case"index":throw new Error("Index was not closed");case"start":{n.push("");break}}return n}i(w,"l");f(w,"getPathSegments");function k(e,n){if(!Array.isArray(e)||typeof n=="number")return!1;const r=Number.parseInt(n,10);return Number.isInteger(r)&&String(r)===n}i(k,"c$1");f(k,"isStringIndex");function E(e,n){if(k(e,n))throw new Error("Cannot use string index")}i(E,"x");f(E,"assertNotStringIndex");function g(e,n,r){if(!u(e)||typeof n!="string")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 a=t[o],s=y(a,e,o);if(s===a&&k(e,a)?e=o===t.length-1?void 0:null:e=e[s],e==null){if(o!==t.length-1)return r;break}}return e===void 0?r:e}i(g,"getProperty");f(g,"getProperty");function $(e,n,r){if(!u(e)||typeof n!="string")return e;const t=e,o=w(n);for(let a=0;a<o.length;a++){const s=o[a],p=y(s,e,a);if(p===s&&E(e,s),a===o.length-1)e[p]=r;else if(!u(e[p])){const c=o[a+1],l=typeof c=="number"||typeof c=="string"&&v(c);e[p]=l?[]:{}}e=e[p]}return t}i($,"setProperty");f($,"setProperty");function Q(e,n){if(!u(e)||typeof n!="string")return!1;const r=w(n);for(let t=0;t<r.length;t++){const o=r[t],a=y(o,e,t);if(a===o&&E(e,o),t===r.length-1)return Object.hasOwn(e,a)?(delete e[a],!0):!1;if(e=e[a],!u(e))return!1}}i(Q,"deleteProperty");f(Q,"deleteProperty");function h(e,n){if(!u(e)||typeof n!="string")return!1;const r=w(n);if(r.length===0)return!1;for(const[t,o]of r.entries()){const a=y(o,e,t),s=a===o&&k(e,o);if(!u(e)||!(a in e)||s)return!1;e=e[a]}return!0}i(h,"hasProperty");f(h,"hasProperty");function C(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replaceAll(/[\\.[]/g,String.raw`\$&`)}i(C,"escapePath");f(C,"escapePath");function J(e){const n=Object.entries(e);return Array.isArray(e)?n.map(([r,t])=>[Number(r),t]):n}i(J,"g");f(J,"entries");function T(e){let n="";for(let[r,t]of J(e))typeof t=="number"?n+=`[${t}]`:(t=C(t),n+=r===0?t:`.${t}`);return n}i(T,"A");f(T,"stringifyPath");function*j(e,n=[]){if(!u(e)||H(e)){n.length>0&&(yield T(n));return}for(const[r,t]of J(e))yield*j(t,[...n,r])}i(j,"w");f(j,"deepKeysIterator");function X(e){return[...j(e)]}i(X,"deepKeys");f(X,"deepKeys");function Z(e){const n={};if(!u(e))return n;for(const[r,t]of Object.entries(e))$(n,r,t);return n}i(Z,"unflatten");f(Z,"unflatten");const ee=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window;var ne=Object.defineProperty,d=i((e,n)=>ne(e,"name",{value:n,configurable:!0}),"c");const W=new Map;class te extends Error{static{i(this,"W")}static{d(this,"PackageJsonValidationError")}constructor(n){super(`The following warnings were encountered while normalizing package data:
2
+ - ${n.join(`
3
+ - `)}`),this.name="PackageJsonValidationError"}}const P=d((e,n,r=[])=>{const t=[];if(B(e,o=>{t.push(o)},n),n&&t.length>0){const o=t.filter(a=>!r.some(s=>s instanceof RegExp?s.test(a):s===a));if(o.length>0)throw new te(o)}return e},"normalizeInput"),le=d(async(e,n={})=>{const r={type:"file"};e&&(r.cwd=e);const t=await q("package.json",r);if(!t)throw new A("No such file or directory, for package.json found.");const o=n.cache&&typeof n.cache!="boolean"?n.cache:W;if(n.cache&&o.has(t))return o.get(t);const a=await S(t);P(a,n.strict??!1,n.ignoreWarnings);const s={packageJson:a,path:t};return o.set(t,s),s},"findPackageJson"),de=d((e,n={})=>{const r={type:"file"};e&&(r.cwd=e);const t=F("package.json",r);if(!t)throw new A("No such file or directory, for package.json found.");const o=n.cache&&typeof n.cache!="boolean"?n.cache:W;if(n.cache&&o.has(t))return o.get(t);const a=I(t);P(a,n.strict??!1,n.ignoreWarnings);const s={packageJson:a,path:t};return o.set(t,s),s},"findPackageJsonSync"),ue=d(async(e,n={})=>{const{cwd:r,...t}=n,o=x(n.cwd??process.cwd());await M(N(o,"package.json"),e,t)},"writePackageJson"),ge=d((e,n={})=>{const{cwd:r,...t}=n,o=x(n.cwd??process.cwd());V(N(o,"package.json"),e,t)},"writePackageJsonSync"),he=d((e,n)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e),t=typeof e=="string";if(!r&&!t)throw new TypeError("`packageFile` should be either an `object` or a `string`.");let o;if(r?o=structuredClone(e):m(e)?o=I(e):o=D(e),n?.resolveCatalogs&&t&&m(e)){const a=U(e);a&&O(o,a)}return P(o,n?.strict??!1,n?.ignoreWarnings),o},"parsePackageJsonSync"),ye=d(async(e,n)=>{const r=e!==null&&typeof e=="object"&&!Array.isArray(e),t=typeof e=="string";if(!r&&!t)throw new TypeError("`packageFile` should be either an `object` or a `string`.");let o;if(r?o=structuredClone(e):m(e)?o=await S(e):o=D(e),n?.resolveCatalogs&&t&&m(e)){const a=await Y(e);a&&O(o,a)}return P(o,n?.strict??!1,n?.ignoreWarnings),o},"parsePackageJson"),we=d((e,n,r)=>g(e,n,r),"getPackageJsonProperty"),me=d((e,n)=>h(e,n),"hasPackageJsonProperty"),ke=d((e,n,r)=>{const t=g(e,"dependencies",{}),o=g(e,"devDependencies",{}),a=g(e,"peerDependencies",{}),s={...t,...o,...r?.peerDeps===!1?{}:a};for(const p of n)if(h(s,p))return!0;return!1},"hasPackageJsonAnyDependency"),Pe=d(async(e,n,r="dependencies",t={})=>{const o=g(e,"dependencies",{}),a=g(e,"devDependencies",{}),s=g(e,"peerDependencies",{}),p=[],c={deps:!0,devDeps:!0,peerDeps:!1,...t};for(const l of n)c.deps&&h(o,l)||c.devDeps&&h(a,l)||c.peerDeps&&h(s,l)||p.push(l);if(p.length!==0){if(process.env.CI||ee&&!process.stdout?.isTTY){const l=`Skipping package installation for [${n.join(", ")}] because the process is not interactive.`;if(t.throwOnWarn)throw new Error(l);t.logger?.warn?t.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?x(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};
@@ -0,0 +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??""}
3
+ ${n} could not find the following package${i}
4
+
5
+ ${a.join(`
6
+ `)}
7
+
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(`
10
+
11
+ or
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};
@@ -0,0 +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};
@@ -0,0 +1 @@
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};
@@ -0,0 +1,33 @@
1
+ /**
2
+ Matches a JSON object.
3
+
4
+ This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
5
+
6
+ @category JSON
7
+ */
8
+ type JsonObject = {[Key in string]: JsonValue} & {[Key in string]?: JsonValue | undefined};
9
+
10
+ /**
11
+ Matches a JSON array.
12
+
13
+ @category JSON
14
+ */
15
+ type JsonArray = JsonValue[] | readonly JsonValue[];
16
+
17
+ /**
18
+ Matches any valid JSON primitive value.
19
+
20
+ @category JSON
21
+ */
22
+ type JsonPrimitive = string | number | boolean | null;
23
+
24
+ /**
25
+ Matches any valid JSON value.
26
+
27
+ @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
28
+
29
+ @category JSON
30
+ */
31
+ type JsonValue = JsonPrimitive | JsonObject | JsonArray;
32
+
33
+ export type { JsonObject as J, JsonValue as a };