@visulima/package 5.0.7 → 5.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## @visulima/package [5.0.9](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.8...%40visulima%2Fpackage%405.0.9) (2026-07-27)
2
+
3
+
4
+ ### Dependencies
5
+
6
+ * **@visulima/fs:** upgraded to 5.0.10
7
+
8
+ ## @visulima/package [5.0.8](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.7...%40visulima%2Fpackage%405.0.8) (2026-07-27)
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * **@visulima/fs:** upgraded to 5.0.8
14
+
1
15
  ## @visulima/package [5.0.7](https://github.com/visulima/visulima/compare/%40visulima%2Fpackage%405.0.6...%40visulima%2Fpackage%405.0.7) (2026-07-26)
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "5.0.7",
3
+ "version": "5.0.9",
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.7",
112
+ "@visulima/fs": "5.0.10",
112
113
  "@visulima/path": "3.0.0",
113
114
  "json5": "^2.2.3",
114
115
  "normalize-package-data": "^9.0.0",