@visulima/package 5.0.8 → 5.0.10
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 +14 -0
- package/MIGRATION-GUIDE.md +287 -0
- package/dist/error.d.ts +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/lockfile.d.ts +72 -72
- package/dist/lockfile.js +1 -1
- package/dist/monorepo.d.ts +16 -16
- package/dist/monorepo.js +1 -1
- package/dist/package-json.d.ts +1 -1
- package/dist/package-json.js +3 -3
- package/dist/package-manager.d.ts +47 -47
- package/dist/package-manager.js +2 -2
- package/dist/package.d.ts +8 -8
- package/dist/package.js +1 -1
- package/dist/packem_shared/package-json.d-CuTm_EgE.d.ts +182 -0
- package/package.json +4 -3
- package/dist/packem_shared/package-json.d-BHWsl_Em.d.ts +0 -182
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## @visulima/package [5.0.10](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.9...%40visulima%2Fpackage%405.0.10) (2026-07-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Dependencies
|
|
5
|
+
|
|
6
|
+
* **@visulima/fs:** upgraded to 5.0.11
|
|
7
|
+
|
|
8
|
+
## @visulima/package [5.0.9](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.8...%40visulima%2Fpackage%405.0.9) (2026-07-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* **@visulima/fs:** upgraded to 5.0.10
|
|
14
|
+
|
|
1
15
|
## @visulima/package [5.0.8](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.7...%40visulima%2Fpackage%405.0.8) (2026-07-27)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# Migration Guide
|
|
2
|
+
|
|
3
|
+
This guide documents breaking changes and migration steps for the `@visulima/package` package.
|
|
4
|
+
|
|
5
|
+
## Version 4.0.0
|
|
6
|
+
|
|
7
|
+
### `parsePackageJson` Function Now Asynchronous
|
|
8
|
+
|
|
9
|
+
The `parsePackageJson` function has been updated to be asynchronous and returns a `Promise<NormalizedPackageJson>` instead of `NormalizedPackageJson` directly.
|
|
10
|
+
|
|
11
|
+
#### Before (v3.x)
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { parsePackageJson } from "@visulima/package";
|
|
15
|
+
|
|
16
|
+
const packageJson = parsePackageJson("./package.json");
|
|
17
|
+
|
|
18
|
+
// packageJson is immediately available
|
|
19
|
+
console.log(packageJson.name);
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### After (v4.x)
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { parsePackageJson } from "@visulima/package";
|
|
26
|
+
|
|
27
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
28
|
+
|
|
29
|
+
// parsePackageJson now returns a Promise and must be awaited
|
|
30
|
+
console.log(packageJson.name);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### CommonJS (CJS) Export Removed
|
|
34
|
+
|
|
35
|
+
The CommonJS (CJS) export has been removed in favor of ECMAScript Modules (ESM) only. For CJS compatibility in Node.js 20.19+, use dynamic imports.
|
|
36
|
+
|
|
37
|
+
#### Before (v3.x)
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
// This no longer works
|
|
41
|
+
const { parsePackageJson } = require("@visulima/package");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
#### After (v4.x) - Node.js 20.19+
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
// Use dynamic import for ESM modules from CJS
|
|
48
|
+
const { parsePackageJson } = await import("@visulima/package");
|
|
49
|
+
// parsePackageJson is async and must be awaited
|
|
50
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Alternative: Convert to ESM
|
|
54
|
+
|
|
55
|
+
For better compatibility and performance, convert your project to use ESM:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
// package.json
|
|
59
|
+
{
|
|
60
|
+
"type": "module"
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Your files can now use ESM imports
|
|
66
|
+
import { parsePackageJson } from "@visulima/package";
|
|
67
|
+
|
|
68
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Why These Changes?
|
|
72
|
+
|
|
73
|
+
#### Benefits of Asynchronous API
|
|
74
|
+
|
|
75
|
+
- **Better Performance**: Non-blocking I/O operations
|
|
76
|
+
- **Resource Efficiency**: Improved memory usage and responsiveness
|
|
77
|
+
- **Modern JavaScript**: Aligns with async/await patterns
|
|
78
|
+
- **Error Handling**: More predictable error propagation
|
|
79
|
+
|
|
80
|
+
#### Benefits of ESM Only
|
|
81
|
+
|
|
82
|
+
- **Standards Compliance**: Follows official JavaScript module specification
|
|
83
|
+
- **Tree Shaking**: Better dead code elimination in bundlers
|
|
84
|
+
- **Static Analysis**: Improved tooling and IDE support
|
|
85
|
+
- **Future-Proof**: ESM is the standard for modern JavaScript
|
|
86
|
+
|
|
87
|
+
### Migration Steps
|
|
88
|
+
|
|
89
|
+
#### 1. Update Function Calls
|
|
90
|
+
|
|
91
|
+
Replace all `parsePackageJson` calls to use `await`:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
// Before
|
|
95
|
+
const packageJson = parsePackageJson("./package.json");
|
|
96
|
+
|
|
97
|
+
// After
|
|
98
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### 2. Mark Functions as Async
|
|
102
|
+
|
|
103
|
+
Ensure all functions calling `parsePackageJson` are marked as `async`:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
// Before
|
|
107
|
+
function getPackageName() {
|
|
108
|
+
const packageJson = parsePackageJson("./package.json");
|
|
109
|
+
return packageJson.name;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// After
|
|
113
|
+
async function getPackageName() {
|
|
114
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
115
|
+
return packageJson.name;
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
#### 3. Update Error Handling
|
|
120
|
+
|
|
121
|
+
Error handling patterns remain the same but must account for async context:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
// Before
|
|
125
|
+
function getPackageInfo() {
|
|
126
|
+
try {
|
|
127
|
+
const packageJson = parsePackageJson("./package.json");
|
|
128
|
+
return { name: packageJson.name, version: packageJson.version };
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error("Failed to parse package.json:", error);
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// After
|
|
136
|
+
async function getPackageInfo() {
|
|
137
|
+
try {
|
|
138
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
139
|
+
return { name: packageJson.name, version: packageJson.version };
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error("Failed to parse package.json:", error);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### New Features in v4.0.0
|
|
148
|
+
|
|
149
|
+
#### Pnpm Catalog Resolution Support
|
|
150
|
+
|
|
151
|
+
The new version adds support for pnpm catalog resolution:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { parsePackageJson } from "@visulima/package";
|
|
155
|
+
|
|
156
|
+
// Enable catalog resolution for pnpm workspaces
|
|
157
|
+
const packageJson = await parsePackageJson("./package.json", {
|
|
158
|
+
resolveCatalogs: true,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// Automatically resolves catalog references like "react": "catalog:"
|
|
162
|
+
console.log(packageJson.dependencies.react); // "18.2.0" (resolved from catalog)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Enhanced Error Messages
|
|
166
|
+
|
|
167
|
+
Better error reporting for common issues:
|
|
168
|
+
|
|
169
|
+
- **File not found**: Clear path resolution errors
|
|
170
|
+
- **Invalid JSON**: Detailed syntax error information
|
|
171
|
+
- **Permission issues**: Helpful suggestions for file access problems
|
|
172
|
+
|
|
173
|
+
### Migration Issues & Solutions
|
|
174
|
+
|
|
175
|
+
#### 1. Missing await Keywords
|
|
176
|
+
|
|
177
|
+
**Problem**: Forgetting to await `parsePackageJson` calls.
|
|
178
|
+
|
|
179
|
+
**Solution**: Add `await` before all `parsePackageJson` calls and mark calling functions as `async`.
|
|
180
|
+
|
|
181
|
+
#### 2. CJS require() Calls
|
|
182
|
+
|
|
183
|
+
**Problem**: `require("@visulima/package")` no longer works.
|
|
184
|
+
|
|
185
|
+
**Solution**: Use dynamic imports:
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
// Dynamic import for ESM modules from CJS
|
|
189
|
+
const { parsePackageJson } = await import("@visulima/package");
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
#### 3. Async Function Requirements
|
|
193
|
+
|
|
194
|
+
**Problem**: Functions calling `parsePackageJson` must be async.
|
|
195
|
+
|
|
196
|
+
**Solution**: Mark all calling functions as `async`:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
// Before
|
|
200
|
+
function getPackageName() {
|
|
201
|
+
const packageJson = parsePackageJson("./package.json");
|
|
202
|
+
return packageJson.name;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// After
|
|
206
|
+
async function getPackageName() {
|
|
207
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
208
|
+
return packageJson.name;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Migration Script
|
|
213
|
+
|
|
214
|
+
Use this script to identify files that need updating:
|
|
215
|
+
|
|
216
|
+
```javascript
|
|
217
|
+
// migration-helper.mjs
|
|
218
|
+
import { readdirSync, statSync, readFileSync } from "node:fs";
|
|
219
|
+
import { join, extname } from "node:path";
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param {string} dir
|
|
223
|
+
* @param {string[]} files
|
|
224
|
+
* @returns {string[]}
|
|
225
|
+
*/
|
|
226
|
+
function findFilesWithParsePackageJson(dir, files = []) {
|
|
227
|
+
const items = readdirSync(dir);
|
|
228
|
+
|
|
229
|
+
for (const item of items) {
|
|
230
|
+
const fullPath = join(dir, item);
|
|
231
|
+
const stat = statSync(fullPath);
|
|
232
|
+
|
|
233
|
+
if (stat.isDirectory() && !item.startsWith(".") && item !== "node_modules") {
|
|
234
|
+
findFilesWithParsePackageJson(fullPath, files);
|
|
235
|
+
} else if (stat.isFile() && (extname(item) === ".ts" || extname(item) === ".js")) {
|
|
236
|
+
const content = readFileSync(fullPath, "utf8");
|
|
237
|
+
|
|
238
|
+
if (content.includes("parsePackageJson") && (!content.includes("await parsePackageJson") || content.includes('require("@visulima/package")'))) {
|
|
239
|
+
files.push(fullPath);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return files;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const files = findFilesWithParsePackageJson("./src");
|
|
248
|
+
console.log("Files that may need updating:", files);
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### Testing Migration
|
|
252
|
+
|
|
253
|
+
After migration, verify that your code works correctly:
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { parsePackageJson } from "@visulima/package";
|
|
257
|
+
|
|
258
|
+
// Test basic functionality
|
|
259
|
+
const packageJson = await parsePackageJson("./package.json");
|
|
260
|
+
console.log(`Project: ${packageJson.name} v${packageJson.version}`);
|
|
261
|
+
|
|
262
|
+
// Test with catalog resolution
|
|
263
|
+
const packageJsonWithCatalogs = await parsePackageJson("./package.json", {
|
|
264
|
+
resolveCatalogs: true,
|
|
265
|
+
});
|
|
266
|
+
console.log("Catalog resolution working:", packageJsonWithCatalogs.dependencies);
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Migration Benefits
|
|
270
|
+
|
|
271
|
+
- **Better Performance**: Non-blocking I/O operations
|
|
272
|
+
- **Modern JavaScript**: Async/await patterns throughout
|
|
273
|
+
- **ESM Compatibility**: Works with modern bundlers and tools
|
|
274
|
+
- **Type Safety**: Better TypeScript integration
|
|
275
|
+
- **Future-Proof**: Aligned with JavaScript ecosystem direction
|
|
276
|
+
|
|
277
|
+
### Need Additional Help?
|
|
278
|
+
|
|
279
|
+
If you encounter issues during migration:
|
|
280
|
+
|
|
281
|
+
1. Ensure all `parsePackageJson` calls are properly awaited
|
|
282
|
+
2. Mark all calling functions as `async`
|
|
283
|
+
3. Use ESM imports instead of CJS require()
|
|
284
|
+
4. Update error handling for async context
|
|
285
|
+
5. Test with catalog resolution features
|
|
286
|
+
|
|
287
|
+
For additional support, please file an issue on the GitHub repository.
|
package/dist/error.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Error thrown when a package was not found.
|
|
3
|
-
*/
|
|
2
|
+
* Error thrown when a package was not found.
|
|
3
|
+
*/
|
|
4
4
|
declare class PackageNotFoundError extends Error {
|
|
5
5
|
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
* @param packageName The name of the package that was not found.
|
|
7
|
+
* @param packageManager The package manager used to install the package.
|
|
8
|
+
*/
|
|
9
9
|
constructor(packageName: string[] | string, packageManager?: string);
|
|
10
10
|
get code(): string;
|
|
11
11
|
set code(_name: string);
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { PackageNotFoundError } from "./error.js";
|
|
|
2
2
|
export { type LockFileEntry, type LockFileIntegrity, type LockFileIntegrityAlgorithm, type LockFileParseResult, type LockFileType, decodeSriIntegrity, parseBunLockFile, parseLockFile, parseLockFileContent, parseLockFileSync, parseNpmLockFile, parsePnpmLockFile, parseYarnLockFile } from "./lockfile.js";
|
|
3
3
|
export { type RootMonorepo, type Strategy, findMonorepoRoot, findMonorepoRootSync } from "./monorepo.js";
|
|
4
4
|
export { findPackageRoot, findPackageRootSync } from "./package.js";
|
|
5
|
-
export { type E as EnsurePackagesOptions, type F as FindPackageJsonCache, type N as NormalizedPackageJson, type a as NormalizedReadResult, type P as PackageJson, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-
|
|
5
|
+
export { type E as EnsurePackagesOptions, type F as FindPackageJsonCache, type N as NormalizedPackageJson, type a as NormalizedReadResult, type P as PackageJson, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-CuTm_EgE.js";
|
|
6
6
|
export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from "./package-manager.js";
|
|
7
7
|
export { type PnpmCatalog, type PnpmCatalogs, isPackageInWorkspace, readPnpmCatalogs, readPnpmCatalogsSync, resolveCatalogReference, resolveCatalogReferences, resolveDependenciesCatalogReferences } from "./pnpm.js";
|
|
8
8
|
import '@visulima/fs';
|
package/dist/lockfile.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Lockfiles the parser recognises. Both the modern text `bun.lock` and the
|
|
3
|
-
* legacy binary `bun.lockb` map to the `bun` type, but only `bun.lock`
|
|
4
|
-
* content is parseable — `bun.lockb` is a binary format and yields no entries.
|
|
5
|
-
*/
|
|
2
|
+
* Lockfiles the parser recognises. Both the modern text `bun.lock` and the
|
|
3
|
+
* legacy binary `bun.lockb` map to the `bun` type, but only `bun.lock`
|
|
4
|
+
* content is parseable — `bun.lockb` is a binary format and yields no entries.
|
|
5
|
+
*/
|
|
6
6
|
type LockFileType = "bun" | "npm" | "pnpm" | "yarn";
|
|
7
7
|
/** SRI algorithms the parser can decode into hex. */
|
|
8
8
|
type LockFileIntegrityAlgorithm = "sha256" | "sha384" | "sha512";
|
|
@@ -14,19 +14,19 @@ interface LockFileIntegrity {
|
|
|
14
14
|
/** A single resolved package extracted from a lockfile. */
|
|
15
15
|
interface LockFileEntry {
|
|
16
16
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
* Declared runtime dependencies — `name → specifier[]` map. Values
|
|
18
|
+
* are arrays so pnpm v9+ peer-context variants (the same dep name
|
|
19
|
+
* resolved to different versions under different peer contexts)
|
|
20
|
+
* can all be preserved. npm, yarn v1, bun, and pnpm v6-v8 always
|
|
21
|
+
* produce single-element arrays; pnpm v9+ may produce multi-element
|
|
22
|
+
* arrays for peer-context-sensitive deps.
|
|
23
|
+
*
|
|
24
|
+
* Specifiers are whatever the lockfile recorded — a range
|
|
25
|
+
* (`^1.0.0`) for npm / yarn / bun, or an already-resolved exact
|
|
26
|
+
* version for pnpm. Callers resolve each specifier against
|
|
27
|
+
* {@link LockFileEntry.version} values elsewhere in the lockfile
|
|
28
|
+
* when they need a concrete edge.
|
|
29
|
+
*/
|
|
30
30
|
dependencies?: Record<string, string[]>;
|
|
31
31
|
/** Decoded SRI digest, if the lockfile recorded one. */
|
|
32
32
|
integrity?: LockFileIntegrity;
|
|
@@ -47,74 +47,74 @@ interface LockFileParseResult {
|
|
|
47
47
|
type: LockFileType;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* Decodes a Subresource Integrity string (`sha512-<base64>`) into a
|
|
51
|
-
* `{ algorithm, hex }` pair. Returns `undefined` if the string is
|
|
52
|
-
* malformed, oversized, or uses an unsupported algorithm.
|
|
53
|
-
* @param sri Full SRI string, e.g. `sha512-<base64>`.
|
|
54
|
-
* @returns Decoded algorithm + hex digest, or `undefined` when the
|
|
55
|
-
* input can't be parsed.
|
|
56
|
-
*/
|
|
50
|
+
* Decodes a Subresource Integrity string (`sha512-<base64>`) into a
|
|
51
|
+
* `{ algorithm, hex }` pair. Returns `undefined` if the string is
|
|
52
|
+
* malformed, oversized, or uses an unsupported algorithm.
|
|
53
|
+
* @param sri Full SRI string, e.g. `sha512-<base64>`.
|
|
54
|
+
* @returns Decoded algorithm + hex digest, or `undefined` when the
|
|
55
|
+
* input can't be parsed.
|
|
56
|
+
*/
|
|
57
57
|
declare const decodeSriIntegrity: (sri: string) => LockFileIntegrity | undefined;
|
|
58
58
|
/**
|
|
59
|
-
* Parses `package-lock.json` (npm v2 / v3 format).
|
|
60
|
-
* @param content Raw JSON text of the lockfile.
|
|
61
|
-
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
62
|
-
*/
|
|
59
|
+
* Parses `package-lock.json` (npm v2 / v3 format).
|
|
60
|
+
* @param content Raw JSON text of the lockfile.
|
|
61
|
+
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
62
|
+
*/
|
|
63
63
|
declare const parseNpmLockFile: (content: string) => LockFileEntry[];
|
|
64
64
|
/**
|
|
65
|
-
* Parses `pnpm-lock.yaml`. Regex-based; works for lockfile v6 through
|
|
66
|
-
* v9. v9 moves concrete resolved dependency versions out of `packages:`
|
|
67
|
-
* and into `snapshots:`; this parser reads both sections and unions
|
|
68
|
-
* their dep-maps onto the final entry.
|
|
69
|
-
* @param content Raw YAML text of the lockfile.
|
|
70
|
-
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
71
|
-
*/
|
|
65
|
+
* Parses `pnpm-lock.yaml`. Regex-based; works for lockfile v6 through
|
|
66
|
+
* v9. v9 moves concrete resolved dependency versions out of `packages:`
|
|
67
|
+
* and into `snapshots:`; this parser reads both sections and unions
|
|
68
|
+
* their dep-maps onto the final entry.
|
|
69
|
+
* @param content Raw YAML text of the lockfile.
|
|
70
|
+
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
71
|
+
*/
|
|
72
72
|
declare const parsePnpmLockFile: (content: string) => LockFileEntry[];
|
|
73
73
|
/**
|
|
74
|
-
* Parses `yarn.lock` for Yarn Classic (v1) and Berry (v2+). Berry's
|
|
75
|
-
* XXH64 `checksum:` is not a cryptographic hash and is intentionally
|
|
76
|
-
* dropped; only v1's SRI `integrity:` flows through to
|
|
77
|
-
* {@link LockFileEntry.integrity}.
|
|
78
|
-
* @param content Raw text of the lockfile.
|
|
79
|
-
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
80
|
-
*/
|
|
74
|
+
* Parses `yarn.lock` for Yarn Classic (v1) and Berry (v2+). Berry's
|
|
75
|
+
* XXH64 `checksum:` is not a cryptographic hash and is intentionally
|
|
76
|
+
* dropped; only v1's SRI `integrity:` flows through to
|
|
77
|
+
* {@link LockFileEntry.integrity}.
|
|
78
|
+
* @param content Raw text of the lockfile.
|
|
79
|
+
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
80
|
+
*/
|
|
81
81
|
declare const parseYarnLockFile: (content: string) => LockFileEntry[];
|
|
82
82
|
/**
|
|
83
|
-
* Parses `bun.lock` (Bun v1.1+, JSON-ish with trailing commas). The
|
|
84
|
-
* legacy binary `bun.lockb` format is recognised by {@link inferLockFileType}
|
|
85
|
-
* but cannot be decoded here — feeding its binary contents in returns an
|
|
86
|
-
* empty array (the `JSON.parse` fails and is swallowed).
|
|
87
|
-
*
|
|
88
|
-
* Attribution: format + tuple layout verified against lockparse
|
|
89
|
-
* (https://github.com/43081j/lockparse, MIT).
|
|
90
|
-
* @param content Raw text of the lockfile.
|
|
91
|
-
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
92
|
-
*/
|
|
83
|
+
* Parses `bun.lock` (Bun v1.1+, JSON-ish with trailing commas). The
|
|
84
|
+
* legacy binary `bun.lockb` format is recognised by {@link inferLockFileType}
|
|
85
|
+
* but cannot be decoded here — feeding its binary contents in returns an
|
|
86
|
+
* empty array (the `JSON.parse` fails and is swallowed).
|
|
87
|
+
*
|
|
88
|
+
* Attribution: format + tuple layout verified against lockparse
|
|
89
|
+
* (https://github.com/43081j/lockparse, MIT).
|
|
90
|
+
* @param content Raw text of the lockfile.
|
|
91
|
+
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
92
|
+
*/
|
|
93
93
|
declare const parseBunLockFile: (content: string) => LockFileEntry[];
|
|
94
94
|
/**
|
|
95
|
-
* Parses raw lockfile content of the given type. Returns an empty
|
|
96
|
-
* array if the content is malformed or doesn't contain any package
|
|
97
|
-
* entries.
|
|
98
|
-
* @param content Raw text of the lockfile.
|
|
99
|
-
* @param type Which parser to dispatch to.
|
|
100
|
-
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
101
|
-
*/
|
|
95
|
+
* Parses raw lockfile content of the given type. Returns an empty
|
|
96
|
+
* array if the content is malformed or doesn't contain any package
|
|
97
|
+
* entries.
|
|
98
|
+
* @param content Raw text of the lockfile.
|
|
99
|
+
* @param type Which parser to dispatch to.
|
|
100
|
+
* @returns One {@link LockFileEntry} per distinct `name@version`.
|
|
101
|
+
*/
|
|
102
102
|
declare const parseLockFileContent: (content: string, type: LockFileType) => LockFileEntry[];
|
|
103
103
|
/**
|
|
104
|
-
* Walks up from `cwd`, locates the nearest supported lockfile, reads
|
|
105
|
-
* it, and returns the parsed entries alongside the lockfile type and
|
|
106
|
-
* absolute path.
|
|
107
|
-
* @param cwd Directory to start the search from. Defaults to
|
|
108
|
-
* `process.cwd()` (delegated to `findUp`).
|
|
109
|
-
* @returns The parsed result, keyed by the discovered lockfile path.
|
|
110
|
-
* @throws If no supported lockfile can be found above `cwd`.
|
|
111
|
-
*/
|
|
104
|
+
* Walks up from `cwd`, locates the nearest supported lockfile, reads
|
|
105
|
+
* it, and returns the parsed entries alongside the lockfile type and
|
|
106
|
+
* absolute path.
|
|
107
|
+
* @param cwd Directory to start the search from. Defaults to
|
|
108
|
+
* `process.cwd()` (delegated to `findUp`).
|
|
109
|
+
* @returns The parsed result, keyed by the discovered lockfile path.
|
|
110
|
+
* @throws If no supported lockfile can be found above `cwd`.
|
|
111
|
+
*/
|
|
112
112
|
declare const parseLockFile: (cwd?: URL | string) => Promise<LockFileParseResult>;
|
|
113
113
|
/**
|
|
114
|
-
* Synchronous counterpart to {@link parseLockFile}.
|
|
115
|
-
* @param cwd Directory to start the search from.
|
|
116
|
-
* @returns The parsed result, keyed by the discovered lockfile path.
|
|
117
|
-
* @throws If no supported lockfile can be found above `cwd`.
|
|
118
|
-
*/
|
|
114
|
+
* Synchronous counterpart to {@link parseLockFile}.
|
|
115
|
+
* @param cwd Directory to start the search from.
|
|
116
|
+
* @returns The parsed result, keyed by the discovered lockfile path.
|
|
117
|
+
* @throws If no supported lockfile can be found above `cwd`.
|
|
118
|
+
*/
|
|
119
119
|
declare const parseLockFileSync: (cwd?: URL | string) => LockFileParseResult;
|
|
120
120
|
export { LockFileEntry, LockFileIntegrity, LockFileIntegrityAlgorithm, LockFileParseResult, LockFileType, decodeSriIntegrity, parseBunLockFile, parseLockFile, parseLockFileContent, parseLockFileSync, parseNpmLockFile, parsePnpmLockFile, parseYarnLockFile };
|
package/dist/lockfile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as E}from"node:module";import{findUp as
|
|
1
|
+
import{createRequire as E}from"node:module";import{findUp as N,findUpSync as U}from"@visulima/fs";let R;const A=n=>(R??=E(import.meta.url))(n),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,_=n=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[e,t]=h.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return h.getBuiltinModule(n)}return A(n)},{readFileSync:C}=_("node:fs"),{readFile:I}=_("node:fs/promises"),q={sha256:"sha256",sha384:"sha384",sha512:"sha512"},B=1024,M=/^[A-Z0-9+/]+={0,2}$/i,j="node_modules/",m=/^['"]/,k=/['"]$/,T=/^[a-z][a-zA-Z0-9]*:\s*$/m,P=/resolution:\s*\{[^}]*integrity:\s*([^,}\s]+)/,z=/^["']?((?:@[^/@"']+\/)?[^@"'\n]+)@[^\n]+\n((?:[\t ][^\n]*(?:\n|$))+)/gm,J=/^\s+version:?\s+"?([^"\n]+)"?/m,Z=/^\s+integrity[\s:]+"?([^"\s]+)"?/m,v=n=>{if(n.length>B)return;const e=n.indexOf("-");if(e<=0)return;const t=q[n.slice(0,e).toLowerCase()];if(!t)return;const s=n.slice(e+1);if(M.test(s))try{const c=Buffer.from(s,"base64");return c.length===0?void 0:{algorithm:t,hex:c.toString("hex")}}catch{return}},w=(n,e,t)=>{const s=`${t.name}@${t.version}`;e.has(s)||(e.add(s),n.push(t))},u=(n,e,t)=>{t&&Object.keys(t).length>0&&(n[e]={...t})},g=n=>{if(!n)return;const e={};for(const[t,s]of Object.entries(n))e[t]=[s];return Object.keys(e).length>0?e:void 0},Y=n=>{const e=[],t=new Set;let s;try{s=JSON.parse(n)}catch{return e}if(!s.packages)return e;for(const[c,o]of Object.entries(s.packages)){if(!c||!o.version)continue;const p=c.lastIndexOf(j);if(p===-1)continue;const i=c.slice(p+j.length);if(i.length===0)continue;const r=i.split("/"),a=i.startsWith("@")?2:1;if(r.length!==a||r.some(f=>f.length===0))continue;const l=o.name??i;if(l.startsWith("."))continue;const d={name:l,version:o.version};if(o.integrity){const f=v(o.integrity);f&&(d.integrity=f)}u(d,"dependencies",g(o.dependencies)),u(d,"peerDependencies",g(o.peerDependencies)),u(d,"optionalDependencies",g(o.optionalDependencies)),w(e,t,d)}return e},$=n=>{let e=n.trim();e.startsWith("/")&&(e=e.slice(1)),e=e.replace(m,"").replace(k,"");const t=e.indexOf("(");t>0&&(e=e.slice(0,t));const s=e.lastIndexOf("@");if(s<=0)return;const c=e.slice(0,s),o=e.slice(s+1);if(!(!c||!o||o.startsWith("link:")||o.startsWith("workspace:")||o.startsWith("file:")))return{name:c,version:o}},O=(n,e)=>{const t=new RegExp(String.raw`^${e}:\s*$`,"m").exec(n);if(!t)return;const s=t.index+t[0].length,c=T.exec(n.slice(s));return n.slice(s,c?s+c.index:n.length)},G=n=>{const e=new Map,t=O(n,"snapshots");if(!t)return e;const s=/^ {2}(['"]?[^\s:][^:\n]*?['"]?):\s*\n((?: {4}[^\n]*\n?)+)/gm;let c;for(;(c=s.exec(t)??void 0)!==void 0;){const o=$(c[1]);if(!o)continue;const p=`${o.name}@${o.version}`,i=c[2],r=e.get(p)??{};for(const a of["dependencies","peerDependencies","optionalDependencies"]){const l=y(i,a);if(!l)continue;const d=r[a]??{};for(const[f,L]of Object.entries(l)){const x=d[f]??[];for(const D of L)x.includes(D)||x.push(D);d[f]=x}r[a]=d}e.set(p,r)}return e},H=n=>{const e=[],t=new Set,s=O(n,"packages");if(!s)return e;const c=G(n),o=/^ {2}(['"]?[^\s:][^:\n]*?['"]?):\s*\n((?: {4}[^\n]*\n?)+)/gm;let p;for(;(p=o.exec(s)??void 0)!==void 0;){const i=$(p[1]);if(!i)continue;const r=p[2],a=P.exec(r),l={name:i.name,version:i.version};if(a?.[1]){const f=v(a[1]);f&&(l.integrity=f)}const d=c.get(`${i.name}@${i.version}`);u(l,"dependencies",d?.dependencies??y(r,"dependencies")),u(l,"peerDependencies",d?.peerDependencies??y(r,"peerDependencies")),u(l,"optionalDependencies",d?.optionalDependencies??y(r,"optionalDependencies")),w(e,t,l)}return e},y=(n,e)=>{const t=new RegExp(String.raw`^ {4}${e}:\s*\n((?: {6,}[^\n]*\n?)+)`,"m").exec(n);if(!t?.[1])return;const s={},c=/^ {6}([^\s:]+):\s*([^\n]+)/gm;let o;for(;(o=c.exec(t[1])??void 0)!==void 0;){const p=o[1].replace(m,"").replace(k,"");let i=o[2].trim();i=i.replace(m,"").replace(k,"");const r=i.indexOf("(");if(r>0&&(i=i.slice(0,r).trim()),!p||!i)continue;const a=s[p]??[];a.includes(i)||a.push(i),s[p]=a}return Object.keys(s).length>0?s:void 0},K=n=>{const e=[],t=new Set,s=z;s.lastIndex=0;let c;for(;(c=s.exec(n)??void 0)!==void 0;){const o=c[1].replace(m,"").replace(k,"");if(!o)continue;const p=c[2],i=J.exec(p);if(!i?.[1])continue;const r={name:o,version:i[1].trim()},a=Z.exec(p);if(a?.[1]){const l=v(a[1]);l&&(r.integrity=l)}u(r,"dependencies",b(p,"dependencies")),u(r,"peerDependencies",b(p,"peerDependencies")),u(r,"optionalDependencies",b(p,"optionalDependencies")),w(e,t,r)}return e},b=(n,e)=>{const t=new RegExp(String.raw`^ {2}${e}:\s*\n((?: {4,}[^\n]*\n?)+)`,"m").exec(n);if(!t?.[1])return;const s={},c=/^ {4}(['"]?[^\s:'"]+['"]?)\s*(?::\s*)?['"]([^'"\n]+)['"]/gm;let o;for(;(o=c.exec(t[1])??void 0)!==void 0;){const p=o[1].replace(m,"").replace(k,""),i=o[2];if(p&&i){const r=s[p]??[];r.includes(i)||r.push(i),s[p]=r}}return Object.keys(s).length>0?s:void 0},Q=/,(?=\s*[}\]])/g,V=n=>{const e=[],t=new Set;let s;try{s=JSON.parse(n.replaceAll(Q,""))}catch{return e}if(!s.packages)return e;for(const c of Object.values(s.packages)){const o=c[0];if(typeof o!="string")continue;const p=o.indexOf("@",1);if(p<=0)continue;const i=o.slice(0,p),r=o.slice(p+1);if(!i||!r||r.startsWith("workspace:")||r.startsWith("link:")||r.startsWith("file:"))continue;const a={name:i,version:r},l=c[3];if(typeof l=="string"&&l.length>0){const f=v(l);f&&(a.integrity=f)}const d=c[2];if(d&&typeof d=="object"&&!Array.isArray(d)){const f=d;u(a,"dependencies",g(f.dependencies)),u(a,"peerDependencies",g(f.peerDependencies)),u(a,"optionalDependencies",g(f.optionalDependencies))}w(e,t,a)}return e},S=n=>{if(n.endsWith("pnpm-lock.yaml"))return"pnpm";if(n.endsWith("package-lock.json"))return"npm";if(n.endsWith("yarn.lock"))return"yarn";if(n.endsWith("bun.lockb")||n.endsWith("bun.lock"))return"bun"},W=(n,e)=>{switch(e){case"bun":return V(n);case"npm":return Y(n);case"pnpm":return H(n);case"yarn":return K(n);default:return[]}},F=["pnpm-lock.yaml","package-lock.json","yarn.lock","bun.lock","bun.lockb"],ne=async n=>{const e=await N(F,{type:"file",...n&&{cwd:n}});if(!e)throw new Error("Could not find a supported lock file (pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lock)");const t=S(e);if(!t)throw new Error(`Unsupported lock file: ${e}`);const s=await I(e,"utf8");return{entries:W(s,t),path:e,type:t}},te=n=>{const e=U(F,{type:"file",...n&&{cwd:n}});if(!e)throw new Error("Could not find a supported lock file (pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lock)");const t=S(e);if(!t)throw new Error(`Unsupported lock file: ${e}`);return{entries:W(C(e,"utf8"),t),path:e,type:t}};export{v as decodeSriIntegrity,V as parseBunLockFile,ne as parseLockFile,W as parseLockFileContent,te as parseLockFileSync,Y as parseNpmLockFile,H as parsePnpmLockFile,K as parseYarnLockFile};
|
package/dist/monorepo.d.ts
CHANGED
|
@@ -4,23 +4,23 @@ interface RootMonorepo<T extends Strategy = Strategy> {
|
|
|
4
4
|
strategy: T;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* An asynchronous function to find the root directory path and strategy for a monorepo based on
|
|
8
|
-
* the given current working directory (cwd).
|
|
9
|
-
* @param cwd The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options["cwd"]`.
|
|
10
|
-
* Default is undefined.
|
|
11
|
-
* @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.
|
|
12
|
-
* The type of the returned promise is `Promise<RootMonorepo>`.
|
|
13
|
-
* @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.
|
|
14
|
-
*/
|
|
7
|
+
* An asynchronous function to find the root directory path and strategy for a monorepo based on
|
|
8
|
+
* the given current working directory (cwd).
|
|
9
|
+
* @param cwd The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options["cwd"]`.
|
|
10
|
+
* Default is undefined.
|
|
11
|
+
* @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.
|
|
12
|
+
* The type of the returned promise is `Promise<RootMonorepo>`.
|
|
13
|
+
* @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.
|
|
14
|
+
*/
|
|
15
15
|
declare const findMonorepoRoot: (cwd?: URL | string) => Promise<RootMonorepo>;
|
|
16
16
|
/**
|
|
17
|
-
* An function to find the root directory path and strategy for a monorepo based on
|
|
18
|
-
* the given current working directory (cwd).
|
|
19
|
-
* @param cwd The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options["cwd"]`.
|
|
20
|
-
* Default is undefined.
|
|
21
|
-
* @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.
|
|
22
|
-
* The type of the returned promise is `Promise<RootMonorepo>`.
|
|
23
|
-
* @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.
|
|
24
|
-
*/
|
|
17
|
+
* An function to find the root directory path and strategy for a monorepo based on
|
|
18
|
+
* the given current working directory (cwd).
|
|
19
|
+
* @param cwd The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options["cwd"]`.
|
|
20
|
+
* Default is undefined.
|
|
21
|
+
* @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.
|
|
22
|
+
* The type of the returned promise is `Promise<RootMonorepo>`.
|
|
23
|
+
* @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.
|
|
24
|
+
*/
|
|
25
25
|
declare const findMonorepoRootSync: (cwd?: URL | string) => RootMonorepo;
|
|
26
26
|
export { RootMonorepo, Strategy, findMonorepoRoot, findMonorepoRootSync };
|
package/dist/monorepo.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as d}from"node:module";import{findUp as
|
|
1
|
+
import{createRequire as d}from"node:module";import{findUp as g,readJson as h,findUpSync as j,readJsonSync as w}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{dirname as u,join as a}from"@visulima/path";import{findPackageManager as k,findPackageManagerSync as b}from"./package-manager.js";let m;const l=o=>(m??=d(import.meta.url))(o),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,y=o=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[r,t]=c.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return c.getBuiltinModule(o)}return l(o)},{existsSync:i,readFileSync:p}=y("node:fs"),q=async o=>{const r=await g(["lerna.json","turbo.json"],{type:"file",...o&&{cwd:o}});if(r?.endsWith("lerna.json")){const n=await h(r);if(n&&typeof n=="object"&&!Array.isArray(n)){const e=n;if(e.useWorkspaces||e.packages)return{path:u(r),strategy:"lerna"}}}const t=r?.endsWith("turbo.json");try{const{packageManager:n,path:e}=await k(o);if(["npm","yarn"].includes(n)){const s=a(e,"package.json");if(i(s)&&p(a(e,"package.json"),"utf8").includes("workspaces"))return{path:e,strategy:t?"turbo":n}}else if(n==="pnpm"){const s=a(e,"pnpm-workspace.yaml");if(i(s))return{path:e,strategy:t?"turbo":"pnpm"}}}catch(n){if(!(n instanceof f))throw n}throw new Error(`No monorepo root could be found upwards from the directory ${String(o??process.cwd())} using lerna, yarn, pnpm, or npm as indicators.`)},N=o=>{const r=j(["lerna.json","turbo.json"],{type:"file",...o&&{cwd:o}});if(r?.endsWith("lerna.json")){const n=w(r);if(n.useWorkspaces||n.packages)return{path:u(r),strategy:"lerna"}}const t=r?.endsWith("turbo.json");try{const{packageManager:n,path:e}=b(o);if(["npm","yarn"].includes(n)){const s=a(e,"package.json");if(i(s)&&p(a(e,"package.json"),"utf8").includes("workspaces"))return{path:e,strategy:t?"turbo":n}}else if(n==="pnpm"){const s=a(e,"pnpm-workspace.yaml");if(i(s))return{path:e,strategy:t?"turbo":"pnpm"}}}catch(n){if(!(n instanceof f))throw n}throw new Error(`No monorepo root could be found upwards from the directory ${String(o??process.cwd())} using lerna, yarn, pnpm, or npm as indicators.`)};export{q as findMonorepoRoot,N as findMonorepoRootSync};
|
package/dist/package-json.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import '@visulima/fs';
|
|
2
2
|
import 'type-fest';
|
|
3
|
-
export { F as FindPackageJsonCache, a as NormalizedReadResult, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-
|
|
3
|
+
export { F as FindPackageJsonCache, a as NormalizedReadResult, c as clearPackageJsonCache, e as ensurePackages, f as findPackageJson, b as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, d as hasPackageJsonProperty, p as parsePackageJson, i as parsePackageJsonSync, w as writePackageJson, j as writePackageJsonSync } from "./packem_shared/package-json.d-CuTm_EgE.js";
|
|
4
4
|
import '@antfu/install-pkg';
|
|
5
5
|
import '@inquirer/core';
|
|
6
6
|
import '@inquirer/type';
|
package/dist/package-json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as q}from"node:module";import{installPackage as
|
|
2
|
-
${l(["gray"],"→")} ${n(e)}`),s(e)})})},
|
|
1
|
+
import{createRequire as q}from"node:module";import{installPackage as G}from"@antfu/install-pkg";import{findUp as X,findUpSync as z,writeJson as U,writeJsonSync as V,readJson as L,readJsonSync as O,readFile as H,readFileSync as K}from"@visulima/fs";import{NotFoundError as x}from"@visulima/fs/error";import{toPath as v,parseJson as P}from"@visulima/fs/utils";import{readYaml as Q,readYamlSync as Z}from"@visulima/fs/yaml";import{join as _}from"@visulima/path";import S from"json5";import ee from"normalize-package-data";import{readPnpmCatalogs as N,resolveCatalogReferences as m,readPnpmCatalogsSync as I}from"./pnpm.js";let M;const Y=r=>(M??=q(import.meta.url))(r),h=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,E=r=>{if(typeof h<"u"&&h.versions&&h.versions.node){const[e,o]=h.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return h.getBuiltinModule(r)}return Y(r)},{existsSync:j}=E("node:fs"),{createInterface:re}=E("node:readline"),{styleText:l}=E("node:util"),k=r=>{const e=typeof r;return r!==null&&(e==="object"||e==="function")},J=new Set(["__proto__","prototype","constructor"]),T=1e6,te=r=>r>="0"&&r<="9";function C(r){if(r==="0")return!0;if(/^[1-9]\d*$/.test(r)){const e=Number.parseInt(r,10);return e<=Number.MAX_SAFE_INTEGER&&e<=T}return!1}function b(r,e){return J.has(r)?!1:(r&&C(r)?e.push(Number.parseInt(r,10)):e.push(r),!0)}function oe(r){if(typeof r!="string")throw new TypeError(`Expected a string, got ${typeof r}`);const e=[];let o="",t="start",a=!1,n=0;for(const s of r){if(n++,a){o+=s,a=!1;continue}if(s==="\\"){if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${n}`);if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${n}`);a=!0,t=t==="start"?"property":t;continue}switch(s){case".":{if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${n}`);if(t==="indexEnd"){t="property";break}if(!b(o,e))return[];o="",t="property";break}case"[":{if(t==="index")throw new Error(`Invalid character '${s}' in an index at position ${n}`);if(t==="indexEnd"){t="index";break}if(t==="property"||t==="start"){if((o||t==="property")&&!b(o,e))return[];o=""}t="index";break}case"]":{if(t==="index"){if(o==="")o=(e.pop()||"")+"[]",t="property";else{const i=Number.parseInt(o,10);!Number.isNaN(i)&&Number.isFinite(i)&&i>=0&&i<=Number.MAX_SAFE_INTEGER&&i<=T&&o===String(i)?e.push(i):e.push(o),o="",t="indexEnd"}break}if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${n}`);o+=s;break}default:{if(t==="index"&&!te(s))throw new Error(`Invalid character '${s}' in an index at position ${n}`);if(t==="indexEnd")throw new Error(`Invalid character '${s}' after an index at position ${n}`);t==="start"&&(t="property"),o+=s}}}switch(a&&(o+="\\"),t){case"property":{if(!b(o,e))return[];break}case"index":throw new Error("Index was not closed");case"start":{e.push("");break}}return e}function A(r){if(typeof r=="string")return oe(r);if(Array.isArray(r)){const e=[];for(const[o,t]of r.entries()){if(typeof t!="string"&&typeof t!="number")throw new TypeError(`Expected a string or number for path segment at index ${o}, got ${typeof t}`);if(typeof t=="number"&&!Number.isFinite(t))throw new TypeError(`Path segment at index ${o} must be a finite number, got ${t}`);if(J.has(t))return[];typeof t=="string"&&C(t)?e.push(Number.parseInt(t,10)):e.push(t)}return e}return[]}function p(r,e,o){if(!k(r)||typeof e!="string"&&!Array.isArray(e))return o===void 0?r:o;const t=A(e);if(t.length===0)return o;for(let a=0;a<t.length;a++){const n=t[a];if(r=r[n],r==null){if(a!==t.length-1)return o;break}}return r===void 0?o:r}function y(r,e){if(!k(r)||typeof e!="string"&&!Array.isArray(e))return!1;const o=A(e);if(o.length===0)return!1;for(const t of o){if(!k(r)||!(t in r))return!1;r=r[t]}return!0}const ne=async r=>{const{default:e=!1,message:o,transformer:t}=r,a=s=>{const i=l(["cyan","bold"],"?"),c=l(["bold"],s),f=e?`${l(["greenBright"],"Y")}${l(["gray"],"/n")}`:`y/${l(["yellowBright"],"N")}`;return`${i} ${c} ${l(["gray"],`(${f})`)}`},n=s=>t?t(s):s?l(["greenBright"],"Yes"):l(["yellowBright"],"No");return new Promise(s=>{const i=re({input:process.stdin,output:process.stdout}),c=a(o);i.question(c,f=>{i.close();const g=f.trim().toLowerCase();if(g===""){s(e);return}if(g==="y"||g==="yes"){console.log(`${l(["greenBright"],"✓")} ${n(!0)}`),s(!0);return}if(g==="n"||g==="no"){console.log(`${l(["yellowBright"],"✗")} ${n(!1)}`),s(!1);return}console.log(`${l(["gray"],"→")} ${n(e)}`),s(e)}),i.on("SIGINT",()=>{i.close(),console.log(`
|
|
2
|
+
${l(["gray"],"→")} ${n(e)}`),s(e)})})},se=typeof process.stdout<"u"&&!process.versions.deno&&!globalThis.window,W=/, ([^,]*)$/,u=new Map,w=new Map,d=(r,e={})=>`${r}|s${String(e.strict?1:0)}|c${String(e.resolveCatalogs?1:0)}|j${String(e.json5===!1?0:1)}|y${String(e.yaml===!1?0:1)}|w${String(e.ignoreWarnings?1:0)}`,D=r=>r.trimStart().startsWith("{"),F=r=>{const e=`${r}|`;for(const o of[w,u])for(const t of o.keys())t.startsWith(e)&&o.delete(t)};class ae extends Error{constructor(e){super(`The following warnings were encountered while normalizing package data:
|
|
3
3
|
- ${e.join(`
|
|
4
|
-
- `)}`),this.name="PackageJsonValidationError"}}const $=(r,e,o=[])=>{const t=[];if(
|
|
4
|
+
- `)}`),this.name="PackageJsonValidationError"}}const $=(r,e,o=[])=>{const t=[];if(ee(r,a=>{t.push(a)},e),e&&t.length>0){const a=t.filter(n=>!o.some(s=>s instanceof RegExp?s.test(n):s===n));if(a.length>0)throw new ae(a)}return r},ie=async r=>await Q(r),ce=r=>Z(r),fe=async r=>{const e=await H(r);return S.parse(e)},le=r=>{const e=K(r);return S.parse(e)},B=async(r,e)=>e?.yaml!==!1&&(r.endsWith(".yaml")||r.endsWith(".yml"))?ie(r):e?.json5!==!1&&r.endsWith(".json5")?fe(r):L(r),R=(r,e)=>e?.yaml!==!1&&(r.endsWith(".yaml")||r.endsWith(".yml"))?ce(r):e?.json5!==!1&&r.endsWith(".json5")?le(r):O(r),ke=async(r,e={})=>{const o={type:"file"};r&&(o.cwd=r);const t=["package.json"];e.yaml!==!1&&t.push("package.yaml","package.yml"),e.json5!==!1&&t.push("package.json5");const a=await X(t,o);if(!a)throw new x(`No such file or directory, for ${t.join(", ").replace(W," or $1")} found.`);const n=e.cache&&typeof e.cache!="boolean"?e.cache:w,s=d(a,e);if(e.cache&&n.has(s))return n.get(s);const i=await B(a,e);if(e.resolveCatalogs){const f=await N(a);f&&m(i,f)}$(i,e.strict??!1,e.ignoreWarnings);const c={packageJson:i,path:a};return e.cache&&n.set(s,c),c},Ee=(r,e={})=>{const o={type:"file"};r&&(o.cwd=r);const t=["package.json"];e.yaml!==!1&&t.push("package.yaml","package.yml"),e.json5!==!1&&t.push("package.json5");const a=z(t,o);if(!a)throw new x(`No such file or directory, for ${t.join(", ").replace(W," or $1")} found.`);const n=e.cache&&typeof e.cache!="boolean"?e.cache:w,s=d(a,e);if(e.cache&&n.has(s))return n.get(s);const i=R(a,e);if(e.resolveCatalogs){const f=I(a);f&&m(i,f)}$(i,e.strict??!1,e.ignoreWarnings);const c={packageJson:i,path:a};return e.cache&&n.set(s,c),c},ve=async(r,e={})=>{const{cwd:o,...t}=e,a=v(o??process.cwd()),n=_(a,"package.json");await U(n,r,t),F(n)},je=(r,e={})=>{const{cwd:o,...t}=e,a=v(o??process.cwd()),n=_(a,"package.json");V(n,r,t),F(n)},xe=()=>{w.clear(),u.clear()},Pe=(r,e)=>{const o=typeof r=="object"&&!Array.isArray(r);if(!o&&typeof r!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let t,a=!1,n;if(o)t=structuredClone(r);else if(!D(r)&&j(r)){n=r;const i=e?.cache&&typeof e.cache!="boolean"?e.cache:u,c=d(n,e);if(e?.cache&&i.has(c))return i.get(c);t=R(n,e),a=!0}else t=P(r);if(e?.resolveCatalogs)if(a){const i=I(r);i&&m(t,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");$(t,e?.strict??!1,e?.ignoreWarnings);const s=t;return a&&e?.cache&&(typeof e.cache=="boolean"?u:e.cache).set(d(n,e),s),s},_e=async(r,e)=>{const o=typeof r=="object"&&!Array.isArray(r);if(!o&&typeof r!="string")throw new TypeError("`packageFile` should be either an `object` or a `string`.");let t,a=!1,n;if(o)t=structuredClone(r);else if(!D(r)&&j(r)){n=r;const i=e?.cache&&typeof e.cache!="boolean"?e.cache:u,c=d(n,e);if(e?.cache&&i.has(c))return i.get(c);t=await B(n,e),a=!0}else t=P(r);if(e?.resolveCatalogs)if(a){const i=await N(r);i&&m(t,i)}else throw new Error("The 'resolveCatalogs' option can only be used on a file path.");$(t,e?.strict??!1,e?.ignoreWarnings);const s=t;return a&&e?.cache&&(typeof e.cache=="boolean"?u:e.cache).set(d(n,e),s),s},Se=(r,e,o)=>p(r,e,o),Ne=(r,e)=>y(r,e),Ie=(r,e,o)=>{const t=p(r,"dependencies",{}),a=p(r,"devDependencies",{}),n=p(r,"peerDependencies",{}),s={...t,...a,...o?.peerDeps===!1?{}:n};for(const i of e)if(y(s,i))return!0;return!1},Je=async(r,e,o="dependencies",t={})=>{const a=p(r,"dependencies",{}),n=p(r,"devDependencies",{}),s=p(r,"peerDependencies",{}),i=[],c={deps:!0,devDeps:!0,peerDeps:!1,...t,...t.confirm?{confirm:{...t.confirm}}:{}};for(const f of e)c.deps&&y(a,f)||c.devDeps&&y(n,f)||c.peerDeps&&y(s,f)||i.push(f);if(i.length!==0){if(process.env.CI||se&&!process.stdout.isTTY){const f=`Skipping package installation for [${e.join(", ")}] because the process is not interactive.`;if(t.throwOnWarn)throw new Error(f);t.logger?.warn?t.logger.warn(f):console.warn(f);return}if(typeof c.confirm?.message=="function"&&(c.confirm.message=c.confirm.message(i)),c.confirm?.message===void 0){const f=`${i.length===1?"Package is":"Packages are"} required for this config: ${i.join(", ")}. Do you want to install them?`;c.confirm===void 0?c.confirm={message:f}:c.confirm.message=f}await ne(c.confirm)&&await G(i,{...c.installPackage,cwd:c.cwd?v(c.cwd):void 0,dev:o==="devDependencies"})}};export{xe as clearPackageJsonCache,Je as ensurePackages,ke as findPackageJson,Ee as findPackageJsonSync,Se as getPackageJsonProperty,Ie as hasPackageJsonAnyDependency,Ne as hasPackageJsonProperty,_e as parsePackageJson,Pe as parsePackageJsonSync,ve as writePackageJson,je as writePackageJsonSync};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* An asynchronous function that finds a lock file in the specified directory or any of its parent directories.
|
|
3
|
-
* @param cwd Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,
|
|
4
|
-
* specifically `URL | string`. Defaults to the current working directory.
|
|
5
|
-
* @returns A `Promise` that resolves with the path of the found lock file.
|
|
6
|
-
* The type of the returned promise is `Promise<string>`.
|
|
7
|
-
* @throws An `Error` if no lock file is found.
|
|
8
|
-
*/
|
|
2
|
+
* An asynchronous function that finds a lock file in the specified directory or any of its parent directories.
|
|
3
|
+
* @param cwd Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,
|
|
4
|
+
* specifically `URL | string`. Defaults to the current working directory.
|
|
5
|
+
* @returns A `Promise` that resolves with the path of the found lock file.
|
|
6
|
+
* The type of the returned promise is `Promise<string>`.
|
|
7
|
+
* @throws An `Error` if no lock file is found.
|
|
8
|
+
*/
|
|
9
9
|
declare const findLockFile: (cwd?: URL | string) => Promise<string>;
|
|
10
10
|
declare const findLockFileSync: (cwd?: URL | string) => string;
|
|
11
11
|
type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
|
|
@@ -14,57 +14,57 @@ type PackageManagerResult = {
|
|
|
14
14
|
path: string;
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
|
-
* An asynchronous function that finds the package manager used in a project based on the presence of lock files
|
|
18
|
-
* or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.
|
|
19
|
-
* Throws an error if no lock file or package.json is found.
|
|
20
|
-
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`
|
|
21
|
-
* type, specifically `URL | string`.
|
|
22
|
-
* @returns A `Promise` that resolves to an object containing the package manager and path.
|
|
23
|
-
* The return type of the function is `Promise<PackageManagerResult>`.
|
|
24
|
-
* @throws An `Error` if no lock file or package.json is found.
|
|
25
|
-
*/
|
|
17
|
+
* An asynchronous function that finds the package manager used in a project based on the presence of lock files
|
|
18
|
+
* or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.
|
|
19
|
+
* Throws an error if no lock file or package.json is found.
|
|
20
|
+
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`
|
|
21
|
+
* type, specifically `URL | string`.
|
|
22
|
+
* @returns A `Promise` that resolves to an object containing the package manager and path.
|
|
23
|
+
* The return type of the function is `Promise<PackageManagerResult>`.
|
|
24
|
+
* @throws An `Error` if no lock file or package.json is found.
|
|
25
|
+
*/
|
|
26
26
|
declare const findPackageManager: (cwd?: URL | string) => Promise<PackageManagerResult>;
|
|
27
27
|
/**
|
|
28
|
-
* An function that finds the package manager used in a project based on the presence of lock files
|
|
29
|
-
* or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.
|
|
30
|
-
* Throws an error if no lock file or package.json is found.
|
|
31
|
-
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`
|
|
32
|
-
* type, specifically `URL | string`.
|
|
33
|
-
* @returns A `Promise` that resolves to an object containing the package manager and path.
|
|
34
|
-
* The return type of the function is `Promise<PackageManagerResult>`.
|
|
35
|
-
* @throws An `Error` if no lock file or package.json is found.
|
|
36
|
-
*/
|
|
28
|
+
* An function that finds the package manager used in a project based on the presence of lock files
|
|
29
|
+
* or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.
|
|
30
|
+
* Throws an error if no lock file or package.json is found.
|
|
31
|
+
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`
|
|
32
|
+
* type, specifically `URL | string`.
|
|
33
|
+
* @returns A `Promise` that resolves to an object containing the package manager and path.
|
|
34
|
+
* The return type of the function is `Promise<PackageManagerResult>`.
|
|
35
|
+
* @throws An `Error` if no lock file or package.json is found.
|
|
36
|
+
*/
|
|
37
37
|
declare const findPackageManagerSync: (cwd?: URL | string) => PackageManagerResult;
|
|
38
38
|
/**
|
|
39
|
-
* Function that retrieves the version of the specified package manager.
|
|
40
|
-
* @param name The name of the package manager. Must be one of the known managers (`npm`, `pnpm`, `yarn`, `bun`).
|
|
41
|
-
* @returns The version of the package manager. The return type of the function is `string`.
|
|
42
|
-
* @throws An `Error` if `name` is not a recognized package manager. This guards against executing an
|
|
43
|
-
* arbitrary or relative-path binary derived from untrusted input.
|
|
44
|
-
*/
|
|
39
|
+
* Function that retrieves the version of the specified package manager.
|
|
40
|
+
* @param name The name of the package manager. Must be one of the known managers (`npm`, `pnpm`, `yarn`, `bun`).
|
|
41
|
+
* @returns The version of the package manager. The return type of the function is `string`.
|
|
42
|
+
* @throws An `Error` if `name` is not a recognized package manager. This guards against executing an
|
|
43
|
+
* arbitrary or relative-path binary derived from untrusted input.
|
|
44
|
+
*/
|
|
45
45
|
declare const getPackageManagerVersion: (name: string) => string;
|
|
46
46
|
/**
|
|
47
|
-
* An asynchronous function that detects what package manager executes the process.
|
|
48
|
-
*
|
|
49
|
-
* Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.
|
|
50
|
-
* @returns An object containing the name and version of the package manager,
|
|
51
|
-
* or undefined if the package manager information cannot be determined.
|
|
52
|
-
*/
|
|
47
|
+
* An asynchronous function that detects what package manager executes the process.
|
|
48
|
+
*
|
|
49
|
+
* Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.
|
|
50
|
+
* @returns An object containing the name and version of the package manager,
|
|
51
|
+
* or undefined if the package manager information cannot be determined.
|
|
52
|
+
*/
|
|
53
53
|
declare const identifyInitiatingPackageManager: () => {
|
|
54
54
|
name: PackageManager | "cnpm" | (string & {});
|
|
55
55
|
version: string;
|
|
56
56
|
} | undefined;
|
|
57
57
|
/**
|
|
58
|
-
* Function that generates a message to install missing packages.
|
|
59
|
-
* @param packageName The name of the package that requires the missing packages.
|
|
60
|
-
* @param missingPackages An array of missing package names.
|
|
61
|
-
* @param options An object containing optional parameters:
|
|
62
|
-
* @param options.packageManagers An array of package managers to include in the message. Defaults to \["npm", "pnpm", "yarn"\].
|
|
63
|
-
* @param options.postMessage A string to append to the end of the message.
|
|
64
|
-
* @param options.preMessage A string to prepend to the beginning of the message.
|
|
65
|
-
* @returns A string message with instructions to install the missing packages using the specified package managers.
|
|
66
|
-
* @throws An `Error` if no package managers are provided in the options.
|
|
67
|
-
*/
|
|
58
|
+
* Function that generates a message to install missing packages.
|
|
59
|
+
* @param packageName The name of the package that requires the missing packages.
|
|
60
|
+
* @param missingPackages An array of missing package names.
|
|
61
|
+
* @param options An object containing optional parameters:
|
|
62
|
+
* @param options.packageManagers An array of package managers to include in the message. Defaults to \["npm", "pnpm", "yarn"\].
|
|
63
|
+
* @param options.postMessage A string to append to the end of the message.
|
|
64
|
+
* @param options.preMessage A string to prepend to the beginning of the message.
|
|
65
|
+
* @returns A string message with instructions to install the missing packages using the specified package managers.
|
|
66
|
+
* @throws An `Error` if no package managers are provided in the options.
|
|
67
|
+
*/
|
|
68
68
|
declare const generateMissingPackagesInstallMessage: (packageName: string, missingPackages: string[], options: {
|
|
69
69
|
packageManagers?: PackageManager[];
|
|
70
70
|
postMessage?: string;
|
package/dist/package-manager.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createRequire as b}from"node:module";import{findUp as k,findUpSync as h}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{parseJson as
|
|
1
|
+
import{createRequire as b}from"node:module";import{findUp as k,findUpSync as h}from"@visulima/fs";import{NotFoundError as f}from"@visulima/fs/error";import{parseJson as W}from"@visulima/fs/utils";import{join as p,dirname as s}from"@visulima/path";let $;const E=e=>($??=b(import.meta.url))(e),t=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,m=e=>{if(typeof t<"u"&&t.versions&&t.versions.node){const[n,a]=t.versions.node.split(".").map(Number);if(n>22||n===22&&a>=3||n===20&&a>=16)return t.getBuiltinModule(e)}return E(e)},{execFileSync:x}=m("node:child_process"),{existsSync:d,readFileSync:S}=m("node:fs"),g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lock","bun.lockb"],u=new Set(["bun","npm","pnpm","yarn"]),w=e=>{const n=W(S(e,"utf8"));return typeof n?.packageManager=="string"?n.packageManager:void 0},y=e=>{let n;if(g.forEach(r=>{!n&&d(p(e,r))&&(n=p(e,r))}),n)return n;const a=p(e,"package.json");if(d(a)&&w(a)!==void 0)return a},M=e=>{if(!e)throw new f("Could not find a package manager");if(e.endsWith("package.json")){const n=w(e);if(n){const a=["npm","yarn","pnpm","bun"].find(r=>n.startsWith(r));if(a)return{packageManager:a,path:s(e)}}}if(e.endsWith("yarn.lock"))return{packageManager:"yarn",path:s(e)};if(e.endsWith("package-lock.json")||e.endsWith("npm-shrinkwrap.json"))return{packageManager:"npm",path:s(e)};if(e.endsWith("pnpm-lock.yaml"))return{packageManager:"pnpm",path:s(e)};if(e.endsWith("bun.lock")||e.endsWith("bun.lockb"))return{packageManager:"bun",path:s(e)};throw new f("Could not find a package manager")},N=async e=>{const n=await k(g,{type:"file",...e&&{cwd:e}});if(!n)throw new Error("Could not find lock file");return n},T=e=>{const n=h(g,{type:"file",...e&&{cwd:e}});if(!n)throw new Error("Could not find lock file");return n},U=async e=>{const n=await k(y,{...e&&{cwd:e}});return M(n)},R=e=>{const n=h(y,{...e&&{cwd:e}});return M(n)},B=e=>{if(!u.has(e))throw new Error(`Unsupported package manager "${e}". Expected one of: ${[...u].join(", ")}.`);return x(e,["--version"]).toString("utf8").trim()},D=()=>{if(!process.env.npm_config_user_agent)return;const e=process.env.npm_config_user_agent.split(" ")[0],n=e.lastIndexOf("/"),a=e.slice(0,Math.max(0,n));return{name:a==="npminstall"?"cnpm":a,version:e.slice(Math.max(0,n+1))}},L=(e,n,a)=>{const r=n.length===1?"":"s",l=a.packageManagers??["npm","pnpm","yarn"];if(l.length===0)throw new Error("No package managers provided, please provide at least one package manager");if(n.length===0)throw new Error("No missing packages provided, please provide at least one missing package");let c=`
|
|
2
2
|
${a.preMessage??""}
|
|
3
3
|
${e} could not find the following package${r}
|
|
4
4
|
|
|
@@ -10,4 +10,4 @@ To install the missing package${r}, please run the following command:
|
|
|
10
10
|
|
|
11
11
|
or
|
|
12
12
|
|
|
13
|
-
`),a.postMessage&&(c+=a.postMessage),c};export{N as findLockFile,T as findLockFileSync,U as findPackageManager,
|
|
13
|
+
`),a.postMessage&&(c+=a.postMessage),c};export{N as findLockFile,T as findLockFileSync,U as findPackageManager,R as findPackageManagerSync,L as generateMissingPackagesInstallMessage,B as getPackageManagerVersion,D as identifyInitiatingPackageManager};
|
package/dist/package.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* An asynchronous function that finds the root directory of a project based on certain lookup criteria.
|
|
3
|
-
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is `string`.
|
|
4
|
-
* @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.
|
|
5
|
-
* @throws An `Error` if the root directory could not be found.
|
|
6
|
-
* @example
|
|
7
|
-
* const rootDirectory = await findPackageRoot();
|
|
8
|
-
* console.log(rootDirectory); // '/path/to/project'
|
|
9
|
-
*/
|
|
2
|
+
* An asynchronous function that finds the root directory of a project based on certain lookup criteria.
|
|
3
|
+
* @param cwd Optional. The current working directory to start the search from. The type of `cwd` is `string`.
|
|
4
|
+
* @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.
|
|
5
|
+
* @throws An `Error` if the root directory could not be found.
|
|
6
|
+
* @example
|
|
7
|
+
* const rootDirectory = await findPackageRoot();
|
|
8
|
+
* console.log(rootDirectory); // '/path/to/project'
|
|
9
|
+
*/
|
|
10
10
|
declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
|
|
11
11
|
declare const findPackageRootSync: (cwd?: URL | string) => string;
|
|
12
12
|
export { findPackageRoot, findPackageRootSync };
|
package/dist/package.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as d}from"node:module";import{findUp as c,findUpSync as s,readJsonSync as
|
|
1
|
+
import{createRequire as d}from"node:module";import{findUp as c,findUpSync as s,readJsonSync as g}from"@visulima/fs";import{dirname as r,join as a}from"@visulima/path";import{findLockFile as m,findLockFileSync as _}from"./package-manager.js";let u;const p=e=>(u??=d(import.meta.url))(e),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,l=e=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[t,o]=i.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return i.getBuiltinModule(e)}return p(e)},{existsSync:y}=l("node:fs"),f=e=>{if(y(a(e,"package.json"))){const t=g(a(e,"package.json"));if(t.name&&t.private!==!0)return"package.json"}},R=async e=>{try{const n=await m(e);return r(n)}catch{}const t=await c(".git/config",{...e&&{cwd:e},type:"file"});if(t)return r(r(t));const o=await c(f,{...e&&{cwd:e},type:"file"});if(o)return r(o);throw new Error("Could not find root directory")},S=e=>{try{const n=_(e);return r(n)}catch{}const t=s(".git/config",{...e&&{cwd:e},type:"file"});if(t)return r(r(t));const o=s(f,{...e&&{cwd:e},type:"file"});if(o)return r(o);throw new Error("Could not find root directory")};export{R as findPackageRoot,S as findPackageRootSync};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { WriteJsonOptions } from '@visulima/fs';
|
|
2
|
+
import { PackageJson as PackageJson$1, Paths, JsonObject } from 'type-fest';
|
|
3
|
+
import { InstallPackageOptions } from '@antfu/install-pkg';
|
|
4
|
+
import { Theme } from '@inquirer/core';
|
|
5
|
+
import { PartialDeep } from '@inquirer/type';
|
|
6
|
+
import { Package } from 'normalize-package-data';
|
|
7
|
+
type NormalizedPackageJson = Package & PackageJson;
|
|
8
|
+
type PackageJson = PackageJson$1;
|
|
9
|
+
type Cache<T = unknown> = Map<string, T>;
|
|
10
|
+
type EnsurePackagesOptions = {
|
|
11
|
+
/** Configuration for user confirmation prompts when installing packages */
|
|
12
|
+
confirm?: {
|
|
13
|
+
/** Default value for the confirmation prompt */
|
|
14
|
+
default?: boolean;
|
|
15
|
+
/** Message to display in the confirmation prompt, or a function that receives packages array */
|
|
16
|
+
message: string | ((packages: string[]) => string);
|
|
17
|
+
/** Theme configuration for the prompt interface */
|
|
18
|
+
theme?: PartialDeep<Theme>;
|
|
19
|
+
/** Function to transform the boolean value for display */
|
|
20
|
+
transformer?: (value: boolean) => string;
|
|
21
|
+
};
|
|
22
|
+
/** Current working directory for package operations */
|
|
23
|
+
cwd?: URL | string;
|
|
24
|
+
/** Whether to include regular dependencies in the operation */
|
|
25
|
+
deps?: boolean;
|
|
26
|
+
/** Whether to include development dependencies in the operation */
|
|
27
|
+
devDeps?: boolean;
|
|
28
|
+
/** Additional options for package installation (excluding cwd and dev which are handled separately) */
|
|
29
|
+
installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
|
|
30
|
+
/** Custom logger interface for warning messages */
|
|
31
|
+
logger?: {
|
|
32
|
+
warn: (message: string) => void;
|
|
33
|
+
};
|
|
34
|
+
/** Whether to include peer dependencies in the operation */
|
|
35
|
+
peerDeps?: boolean;
|
|
36
|
+
/** Whether to throw an error when warnings are logged instead of just logging them */
|
|
37
|
+
throwOnWarn?: boolean;
|
|
38
|
+
};
|
|
39
|
+
type ReadOptions = {
|
|
40
|
+
cache?: FindPackageJsonCache | boolean;
|
|
41
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
42
|
+
json5?: boolean;
|
|
43
|
+
resolveCatalogs?: boolean;
|
|
44
|
+
strict?: boolean;
|
|
45
|
+
yaml?: boolean;
|
|
46
|
+
};
|
|
47
|
+
type FindPackageJsonCache = Cache<NormalizedReadResult>;
|
|
48
|
+
type NormalizedReadResult = {
|
|
49
|
+
packageJson: NormalizedPackageJson;
|
|
50
|
+
path: string;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* An asynchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
54
|
+
* @param cwd The current working directory.
|
|
55
|
+
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
56
|
+
* @returns A `Promise` that resolves to an object containing the parsed package data and the file path.
|
|
57
|
+
* The type of the returned promise is `Promise<NormalizedReadResult>`.
|
|
58
|
+
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
59
|
+
*/
|
|
60
|
+
declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
|
|
61
|
+
/**
|
|
62
|
+
* A synchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
63
|
+
* @param cwd The current working directory.
|
|
64
|
+
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
65
|
+
* @returns An object containing the parsed package data and the file path.
|
|
66
|
+
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
67
|
+
*/
|
|
68
|
+
declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
|
|
69
|
+
/**
|
|
70
|
+
* An asynchronous function to write the package.json file with the given data.
|
|
71
|
+
* @param data The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.
|
|
72
|
+
* @param options Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.
|
|
73
|
+
* This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options["cwd"]`.
|
|
74
|
+
* `cwd` represents the current working directory. If not specified, the default working directory will be used.
|
|
75
|
+
* @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.
|
|
76
|
+
*/
|
|
77
|
+
declare const writePackageJson: (data: PackageJson, options?: WriteJsonOptions & {
|
|
78
|
+
cwd?: URL | string;
|
|
79
|
+
}) => Promise<void>;
|
|
80
|
+
declare const writePackageJsonSync: (data: PackageJson, options?: WriteJsonOptions & {
|
|
81
|
+
cwd?: URL | string;
|
|
82
|
+
}) => void;
|
|
83
|
+
/**
|
|
84
|
+
* Clears the module-level package.json file and parse caches.
|
|
85
|
+
*
|
|
86
|
+
* The caches populated by `findPackageJson[Sync]` / `parsePackageJson[Sync]` when
|
|
87
|
+
* `cache: true` (and no custom cache is supplied) never expire on their own. Call this
|
|
88
|
+
* to drop all cached reads — for example in long-running processes or tests that mutate
|
|
89
|
+
* package files out of band.
|
|
90
|
+
*/
|
|
91
|
+
declare const clearPackageJsonCache: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* A synchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
94
|
+
* @param packageFile
|
|
95
|
+
* @param options
|
|
96
|
+
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
97
|
+
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
98
|
+
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
99
|
+
* @param options.strict Whether to throw errors on normalization warnings
|
|
100
|
+
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
101
|
+
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
102
|
+
* @returns
|
|
103
|
+
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
104
|
+
*/
|
|
105
|
+
declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
|
|
106
|
+
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
107
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
108
|
+
json5?: boolean;
|
|
109
|
+
resolveCatalogs?: boolean;
|
|
110
|
+
strict?: boolean;
|
|
111
|
+
yaml?: boolean;
|
|
112
|
+
}) => NormalizedPackageJson;
|
|
113
|
+
/**
|
|
114
|
+
* An asynchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
115
|
+
* @param packageFile
|
|
116
|
+
* @param options
|
|
117
|
+
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
118
|
+
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
119
|
+
* @param options.strict Whether to throw errors on normalization warnings
|
|
120
|
+
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
121
|
+
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
122
|
+
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
123
|
+
* @returns
|
|
124
|
+
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
125
|
+
*/
|
|
126
|
+
declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
|
|
127
|
+
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
128
|
+
ignoreWarnings?: (RegExp | string)[];
|
|
129
|
+
json5?: boolean;
|
|
130
|
+
resolveCatalogs?: boolean;
|
|
131
|
+
strict?: boolean;
|
|
132
|
+
yaml?: boolean;
|
|
133
|
+
}) => Promise<NormalizedPackageJson>;
|
|
134
|
+
/**
|
|
135
|
+
* An asynchronous function to get the value of a property from the package.json file.
|
|
136
|
+
* @param packageJson
|
|
137
|
+
* @param property
|
|
138
|
+
* @param defaultValue
|
|
139
|
+
* @returns
|
|
140
|
+
*/
|
|
141
|
+
declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
|
|
142
|
+
/**
|
|
143
|
+
* An asynchronous function to check if a property exists in the package.json file.
|
|
144
|
+
* @param packageJson
|
|
145
|
+
* @param property
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
|
|
149
|
+
/**
|
|
150
|
+
* An asynchronous function to check if any of the specified dependencies exist in the package.json file.
|
|
151
|
+
* @param packageJson
|
|
152
|
+
* @param arguments_
|
|
153
|
+
* @param options
|
|
154
|
+
* @param options.peerDeps Whether to include peer dependencies
|
|
155
|
+
* @returns
|
|
156
|
+
*/
|
|
157
|
+
declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
|
|
158
|
+
peerDeps?: boolean;
|
|
159
|
+
}) => boolean;
|
|
160
|
+
/**
|
|
161
|
+
* An asynchronous function to ensure that the specified packages are installed in the package.json file.
|
|
162
|
+
* If the packages are not installed, the user will be prompted to install them.
|
|
163
|
+
* If the user agrees, the packages will be installed.
|
|
164
|
+
* If the user declines, the function will return without installing the packages.
|
|
165
|
+
* If the user does not respond, the function will return without installing the packages.
|
|
166
|
+
* @param packageJson
|
|
167
|
+
* @param packages
|
|
168
|
+
* @param installKey
|
|
169
|
+
* @param options
|
|
170
|
+
* @param options.deps Whether to include regular dependencies
|
|
171
|
+
* @param options.devDeps Whether to include development dependencies
|
|
172
|
+
* @param options.peerDeps Whether to include peer dependencies
|
|
173
|
+
* @param options.throwOnWarn Whether to throw an error when warnings are logged instead of just logging them
|
|
174
|
+
* @param options.logger Whether to use a custom logger
|
|
175
|
+
* @param options.confirm Whether to use a custom confirmation prompt
|
|
176
|
+
* @param options.installPackage Whether to use a custom installation package
|
|
177
|
+
* @param options.cwd Whether to use a custom current working directory
|
|
178
|
+
* @param options.dev Whether to use a custom installation key
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
181
|
+
declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
|
|
182
|
+
export { EnsurePackagesOptions as E, FindPackageJsonCache as F, NormalizedPackageJson as N, PackageJson as P, NormalizedReadResult as a, findPackageJsonSync as b, clearPackageJsonCache as c, hasPackageJsonProperty as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJsonSync as i, writePackageJsonSync as j, parsePackageJson as p, writePackageJson as w };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/package",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.10",
|
|
4
4
|
"description": "A comprehensive package management utility that helps you find root directories, monorepos, package managers, and parse package.json, package.yaml, and package.json5 files with advanced features like catalog resolution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"anolilab",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"dist/**",
|
|
59
59
|
"README.md",
|
|
60
60
|
"CHANGELOG.md",
|
|
61
|
-
"LICENSE.md"
|
|
61
|
+
"LICENSE.md",
|
|
62
|
+
"MIGRATION-GUIDE.md"
|
|
62
63
|
],
|
|
63
64
|
"os": [
|
|
64
65
|
"darwin",
|
|
@@ -108,7 +109,7 @@
|
|
|
108
109
|
},
|
|
109
110
|
"dependencies": {
|
|
110
111
|
"@antfu/install-pkg": "^1.1.0",
|
|
111
|
-
"@visulima/fs": "5.0.
|
|
112
|
+
"@visulima/fs": "5.0.11",
|
|
112
113
|
"@visulima/path": "3.0.0",
|
|
113
114
|
"json5": "^2.2.3",
|
|
114
115
|
"normalize-package-data": "^9.0.0",
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import { WriteJsonOptions } from '@visulima/fs';
|
|
2
|
-
import { PackageJson as PackageJson$1, Paths, JsonObject } from 'type-fest';
|
|
3
|
-
import { InstallPackageOptions } from '@antfu/install-pkg';
|
|
4
|
-
import { Theme } from '@inquirer/core';
|
|
5
|
-
import { PartialDeep } from '@inquirer/type';
|
|
6
|
-
import { Package } from 'normalize-package-data';
|
|
7
|
-
type NormalizedPackageJson = Package & PackageJson;
|
|
8
|
-
type PackageJson = PackageJson$1;
|
|
9
|
-
type Cache<T = unknown> = Map<string, T>;
|
|
10
|
-
type EnsurePackagesOptions = {
|
|
11
|
-
/** Configuration for user confirmation prompts when installing packages */
|
|
12
|
-
confirm?: {
|
|
13
|
-
/** Default value for the confirmation prompt */
|
|
14
|
-
default?: boolean;
|
|
15
|
-
/** Message to display in the confirmation prompt, or a function that receives packages array */
|
|
16
|
-
message: string | ((packages: string[]) => string);
|
|
17
|
-
/** Theme configuration for the prompt interface */
|
|
18
|
-
theme?: PartialDeep<Theme>;
|
|
19
|
-
/** Function to transform the boolean value for display */
|
|
20
|
-
transformer?: (value: boolean) => string;
|
|
21
|
-
};
|
|
22
|
-
/** Current working directory for package operations */
|
|
23
|
-
cwd?: URL | string;
|
|
24
|
-
/** Whether to include regular dependencies in the operation */
|
|
25
|
-
deps?: boolean;
|
|
26
|
-
/** Whether to include development dependencies in the operation */
|
|
27
|
-
devDeps?: boolean;
|
|
28
|
-
/** Additional options for package installation (excluding cwd and dev which are handled separately) */
|
|
29
|
-
installPackage?: Omit<InstallPackageOptions, "cwd" | "dev">;
|
|
30
|
-
/** Custom logger interface for warning messages */
|
|
31
|
-
logger?: {
|
|
32
|
-
warn: (message: string) => void;
|
|
33
|
-
};
|
|
34
|
-
/** Whether to include peer dependencies in the operation */
|
|
35
|
-
peerDeps?: boolean;
|
|
36
|
-
/** Whether to throw an error when warnings are logged instead of just logging them */
|
|
37
|
-
throwOnWarn?: boolean;
|
|
38
|
-
};
|
|
39
|
-
type ReadOptions = {
|
|
40
|
-
cache?: FindPackageJsonCache | boolean;
|
|
41
|
-
ignoreWarnings?: (RegExp | string)[];
|
|
42
|
-
json5?: boolean;
|
|
43
|
-
resolveCatalogs?: boolean;
|
|
44
|
-
strict?: boolean;
|
|
45
|
-
yaml?: boolean;
|
|
46
|
-
};
|
|
47
|
-
type FindPackageJsonCache = Cache<NormalizedReadResult>;
|
|
48
|
-
type NormalizedReadResult = {
|
|
49
|
-
packageJson: NormalizedPackageJson;
|
|
50
|
-
path: string;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* An asynchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
54
|
-
* @param cwd The current working directory.
|
|
55
|
-
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
56
|
-
* @returns A `Promise` that resolves to an object containing the parsed package data and the file path.
|
|
57
|
-
* The type of the returned promise is `Promise<NormalizedReadResult>`.
|
|
58
|
-
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
59
|
-
*/
|
|
60
|
-
declare const findPackageJson: (cwd?: URL | string, options?: ReadOptions) => Promise<NormalizedReadResult>;
|
|
61
|
-
/**
|
|
62
|
-
* A synchronous function to find the package.json, package.yaml, or package.json5 file in the specified directory or its parent directories.
|
|
63
|
-
* @param cwd The current working directory.
|
|
64
|
-
* @param options Configuration options including yaml, json5, and resolveCatalogs flags.
|
|
65
|
-
* @returns An object containing the parsed package data and the file path.
|
|
66
|
-
* @throws {Error} If no package file can be found or if strict mode is enabled and normalize warnings are thrown.
|
|
67
|
-
*/
|
|
68
|
-
declare const findPackageJsonSync: (cwd?: URL | string, options?: ReadOptions) => NormalizedReadResult;
|
|
69
|
-
/**
|
|
70
|
-
* An asynchronous function to write the package.json file with the given data.
|
|
71
|
-
* @param data The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.
|
|
72
|
-
* @param options Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.
|
|
73
|
-
* This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options["cwd"]`.
|
|
74
|
-
* `cwd` represents the current working directory. If not specified, the default working directory will be used.
|
|
75
|
-
* @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.
|
|
76
|
-
*/
|
|
77
|
-
declare const writePackageJson: (data: PackageJson, options?: WriteJsonOptions & {
|
|
78
|
-
cwd?: URL | string;
|
|
79
|
-
}) => Promise<void>;
|
|
80
|
-
declare const writePackageJsonSync: (data: PackageJson, options?: WriteJsonOptions & {
|
|
81
|
-
cwd?: URL | string;
|
|
82
|
-
}) => void;
|
|
83
|
-
/**
|
|
84
|
-
* Clears the module-level package.json file and parse caches.
|
|
85
|
-
*
|
|
86
|
-
* The caches populated by `findPackageJson[Sync]` / `parsePackageJson[Sync]` when
|
|
87
|
-
* `cache: true` (and no custom cache is supplied) never expire on their own. Call this
|
|
88
|
-
* to drop all cached reads — for example in long-running processes or tests that mutate
|
|
89
|
-
* package files out of band.
|
|
90
|
-
*/
|
|
91
|
-
declare const clearPackageJsonCache: () => void;
|
|
92
|
-
/**
|
|
93
|
-
* A synchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
94
|
-
* @param packageFile
|
|
95
|
-
* @param options
|
|
96
|
-
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
97
|
-
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
98
|
-
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
99
|
-
* @param options.strict Whether to throw errors on normalization warnings
|
|
100
|
-
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
101
|
-
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
102
|
-
* @returns
|
|
103
|
-
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
104
|
-
*/
|
|
105
|
-
declare const parsePackageJsonSync: (packageFile: JsonObject | string, options?: {
|
|
106
|
-
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
107
|
-
ignoreWarnings?: (RegExp | string)[];
|
|
108
|
-
json5?: boolean;
|
|
109
|
-
resolveCatalogs?: boolean;
|
|
110
|
-
strict?: boolean;
|
|
111
|
-
yaml?: boolean;
|
|
112
|
-
}) => NormalizedPackageJson;
|
|
113
|
-
/**
|
|
114
|
-
* An asynchronous function to parse the package.json, package.yaml, or package.json5 file/object/string and return normalize the data.
|
|
115
|
-
* @param packageFile
|
|
116
|
-
* @param options
|
|
117
|
-
* @param options.cache Cache for parsed results (only applies to file paths)
|
|
118
|
-
* @param options.ignoreWarnings List of warning messages or patterns to skip in strict mode
|
|
119
|
-
* @param options.strict Whether to throw errors on normalization warnings
|
|
120
|
-
* @param options.resolveCatalogs Whether to resolve pnpm catalog references
|
|
121
|
-
* @param options.yaml Whether to enable package.yaml parsing (default: true)
|
|
122
|
-
* @param options.json5 Whether to enable package.json5 parsing (default: true)
|
|
123
|
-
* @returns
|
|
124
|
-
* @throws {Error} If the packageFile parameter is not an object or a string or if strict mode is enabled and normalize warnings are thrown.
|
|
125
|
-
*/
|
|
126
|
-
declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
|
|
127
|
-
cache?: Cache<NormalizedPackageJson> | boolean;
|
|
128
|
-
ignoreWarnings?: (RegExp | string)[];
|
|
129
|
-
json5?: boolean;
|
|
130
|
-
resolveCatalogs?: boolean;
|
|
131
|
-
strict?: boolean;
|
|
132
|
-
yaml?: boolean;
|
|
133
|
-
}) => Promise<NormalizedPackageJson>;
|
|
134
|
-
/**
|
|
135
|
-
* An asynchronous function to get the value of a property from the package.json file.
|
|
136
|
-
* @param packageJson
|
|
137
|
-
* @param property
|
|
138
|
-
* @param defaultValue
|
|
139
|
-
* @returns
|
|
140
|
-
*/
|
|
141
|
-
declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
|
|
142
|
-
/**
|
|
143
|
-
* An asynchronous function to check if a property exists in the package.json file.
|
|
144
|
-
* @param packageJson
|
|
145
|
-
* @param property
|
|
146
|
-
* @returns
|
|
147
|
-
*/
|
|
148
|
-
declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
|
|
149
|
-
/**
|
|
150
|
-
* An asynchronous function to check if any of the specified dependencies exist in the package.json file.
|
|
151
|
-
* @param packageJson
|
|
152
|
-
* @param arguments_
|
|
153
|
-
* @param options
|
|
154
|
-
* @param options.peerDeps Whether to include peer dependencies
|
|
155
|
-
* @returns
|
|
156
|
-
*/
|
|
157
|
-
declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
|
|
158
|
-
peerDeps?: boolean;
|
|
159
|
-
}) => boolean;
|
|
160
|
-
/**
|
|
161
|
-
* An asynchronous function to ensure that the specified packages are installed in the package.json file.
|
|
162
|
-
* If the packages are not installed, the user will be prompted to install them.
|
|
163
|
-
* If the user agrees, the packages will be installed.
|
|
164
|
-
* If the user declines, the function will return without installing the packages.
|
|
165
|
-
* If the user does not respond, the function will return without installing the packages.
|
|
166
|
-
* @param packageJson
|
|
167
|
-
* @param packages
|
|
168
|
-
* @param installKey
|
|
169
|
-
* @param options
|
|
170
|
-
* @param options.deps Whether to include regular dependencies
|
|
171
|
-
* @param options.devDeps Whether to include development dependencies
|
|
172
|
-
* @param options.peerDeps Whether to include peer dependencies
|
|
173
|
-
* @param options.throwOnWarn Whether to throw an error when warnings are logged instead of just logging them
|
|
174
|
-
* @param options.logger Whether to use a custom logger
|
|
175
|
-
* @param options.confirm Whether to use a custom confirmation prompt
|
|
176
|
-
* @param options.installPackage Whether to use a custom installation package
|
|
177
|
-
* @param options.cwd Whether to use a custom current working directory
|
|
178
|
-
* @param options.dev Whether to use a custom installation key
|
|
179
|
-
* @returns
|
|
180
|
-
*/
|
|
181
|
-
declare const ensurePackages: (packageJson: NormalizedPackageJson, packages: string[], installKey?: "dependencies" | "devDependencies", options?: EnsurePackagesOptions) => Promise<void>;
|
|
182
|
-
export { EnsurePackagesOptions as E, FindPackageJsonCache as F, NormalizedPackageJson as N, PackageJson as P, NormalizedReadResult as a, findPackageJsonSync as b, clearPackageJsonCache as c, hasPackageJsonProperty as d, ensurePackages as e, findPackageJson as f, getPackageJsonProperty as g, hasPackageJsonAnyDependency as h, parsePackageJsonSync as i, writePackageJsonSync as j, parsePackageJson as p, writePackageJson as w };
|