@visulima/package 3.4.7 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## @visulima/package [3.5.0](https://github.com/visulima/visulima/compare/@visulima/package@3.4.8...@visulima/package@3.5.0) (2025-01-26)
2
+
3
+ ### Features
4
+
5
+ * **package:** adding strict parsing to findPackageJson, findPackageJsonSync and parsePackageJson ([#485](https://github.com/visulima/visulima/issues/485)) ([67636d2](https://github.com/visulima/visulima/commit/67636d2022bca95c60d92e5b7ccbdd9cbe0bd9e9))
6
+
7
+ ## @visulima/package [3.4.8](https://github.com/visulima/visulima/compare/@visulima/package@3.4.7...@visulima/package@3.4.8) (2025-01-25)
8
+
9
+ ### Bug Fixes
10
+
11
+ * fixed wrong node version range in package.json ([4ae2929](https://github.com/visulima/visulima/commit/4ae292984681c71a770e4d4560432f7b7c5a141a))
12
+
13
+ ### Miscellaneous Chores
14
+
15
+ * fixed typescript url ([fe65a8c](https://github.com/visulima/visulima/commit/fe65a8c0296ece7ee26474c70d065b06d4d0da89))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * **@visulima/fs:** upgraded to 3.0.1
21
+ * **@visulima/path:** upgraded to 1.3.4
22
+
1
23
  ## @visulima/package [3.4.7](https://github.com/visulima/visulima/compare/@visulima/package@3.4.6...@visulima/package@3.4.7) (2025-01-25)
2
24
 
3
25
  ### Miscellaneous Chores
package/README.md CHANGED
@@ -166,7 +166,7 @@ If you would like to help take a look at the [list of issues](https://github.com
166
166
  The visulima package is open-sourced software licensed under the [MIT][license-url]
167
167
 
168
168
  [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
169
- [typescript-url]: "typescript"
169
+ [typescript-url]: https://www.typescriptlang.org/ "TypeScript" "typescript"
170
170
  [license-image]: https://img.shields.io/npm/l/@visulima/package?color=blueviolet&style=for-the-badge
171
171
  [license-url]: LICENSE.md "license"
172
172
  [npm-image]: https://img.shields.io/npm/v/@visulima/package/latest.svg?style=for-the-badge&logo=npm
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { PackageNotFoundError } from './error.cjs';
2
2
  export { RootMonorepo, Strategy, findMonorepoRoot, findMonorepoRootSync } from './monorepo.cjs';
3
3
  export { findPackageRoot, findPackageRootSync } from './package.cjs';
4
- export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-BRauYh0w.cjs';
4
+ export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-B2CLbuXK.cjs';
5
5
  export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.cjs';
6
6
  import '@visulima/fs';
7
7
  import '@antfu/install-pkg';
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { PackageNotFoundError } from './error.mjs';
2
2
  export { RootMonorepo, Strategy, findMonorepoRoot, findMonorepoRootSync } from './monorepo.mjs';
3
3
  export { findPackageRoot, findPackageRootSync } from './package.mjs';
4
- export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-BRauYh0w.mjs';
4
+ export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-B2CLbuXK.mjs';
5
5
  export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.mjs';
6
6
  import '@visulima/fs';
7
7
  import '@antfu/install-pkg';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { PackageNotFoundError } from './error.js';
2
2
  export { RootMonorepo, Strategy, findMonorepoRoot, findMonorepoRootSync } from './monorepo.js';
3
3
  export { findPackageRoot, findPackageRootSync } from './package.js';
4
- export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-BRauYh0w.d.mjs';
4
+ export { E as EnsurePackagesOptions, F as FindPackageJsonCache, d as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-B2CLbuXK.d.mjs';
5
5
  export { PackageManager, PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, generateMissingPackagesInstallMessage, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
6
6
  import '@visulima/fs';
7
7
  import '@antfu/install-pkg';
@@ -289,6 +289,40 @@ const isNode = typeof process.stdout < "u" && !process.versions?.deno && !global
289
289
  var __defProp = Object.defineProperty;
290
290
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
291
291
  const PackageJsonFileCache = /* @__PURE__ */ new Map();
292
+ class PackageJsonValidationError extends Error {
293
+ static {
294
+ __name(this, "PackageJsonValidationError");
295
+ }
296
+ constructor(warnings) {
297
+ super(`The following warnings were encountered while normalizing package data:
298
+ - ${warnings.join("\n- ")}`);
299
+ this.name = "PackageJsonValidationError";
300
+ }
301
+ }
302
+ const normalizeInput = /* @__PURE__ */ __name((input, strict, ignoreWarnings = []) => {
303
+ const warnings = [];
304
+ normalizeData__default(
305
+ input,
306
+ (message) => {
307
+ warnings.push(message);
308
+ },
309
+ strict
310
+ );
311
+ if (strict && warnings.length > 0) {
312
+ const filteredWarnings = warnings.filter(
313
+ (warning) => !ignoreWarnings.some((pattern) => {
314
+ if (pattern instanceof RegExp) {
315
+ return pattern.test(warning);
316
+ }
317
+ return pattern === warning;
318
+ })
319
+ );
320
+ if (filteredWarnings.length > 0) {
321
+ throw new PackageJsonValidationError(filteredWarnings);
322
+ }
323
+ }
324
+ return input;
325
+ }, "normalizeInput");
292
326
  const findPackageJson = /* @__PURE__ */ __name(async (cwd, options = {}) => {
293
327
  const findUpConfig = {
294
328
  type: "file"
@@ -305,7 +339,7 @@ const findPackageJson = /* @__PURE__ */ __name(async (cwd, options = {}) => {
305
339
  return cache.get(filePath);
306
340
  }
307
341
  const packageJson = await fs.readJson(filePath);
308
- normalizeData__default(packageJson);
342
+ normalizeInput(packageJson, options.strict ?? false, options.ignoreWarnings);
309
343
  const output = {
310
344
  packageJson,
311
345
  path: filePath
@@ -329,7 +363,7 @@ const findPackageJsonSync = /* @__PURE__ */ __name((cwd, options = {}) => {
329
363
  return cache.get(filePath);
330
364
  }
331
365
  const packageJson = fs.readJsonSync(filePath);
332
- normalizeData__default(packageJson);
366
+ normalizeInput(packageJson, options.strict ?? false, options.ignoreWarnings);
333
367
  const output = {
334
368
  packageJson,
335
369
  path: filePath
@@ -347,7 +381,7 @@ const writePackageJsonSync = /* @__PURE__ */ __name((data, options = {}) => {
347
381
  const directory = utils.toPath(options.cwd ?? process.cwd());
348
382
  fs.writeJsonSync(path.join(directory, "package.json"), data, writeOptions);
349
383
  }, "writePackageJsonSync");
350
- const parsePackageJson = /* @__PURE__ */ __name((packageFile) => {
384
+ const parsePackageJson = /* @__PURE__ */ __name((packageFile, options) => {
351
385
  const isObject = packageFile !== null && typeof packageFile === "object" && !Array.isArray(packageFile);
352
386
  const isString = typeof packageFile === "string";
353
387
  if (!isObject && !isString) {
@@ -357,7 +391,7 @@ const parsePackageJson = /* @__PURE__ */ __name((packageFile) => {
357
391
  // eslint-disable-next-line security/detect-non-literal-fs-filename
358
392
  node_fs.existsSync(packageFile) ? fs.readJsonSync(packageFile) : utils.parseJson(packageFile)
359
393
  );
360
- normalizeData__default(json);
394
+ normalizeInput(json, options?.strict ?? false, options?.ignoreWarnings);
361
395
  return json;
362
396
  }, "parsePackageJson");
363
397
  const getPackageJsonProperty = /* @__PURE__ */ __name((packageJson, property, defaultValue) => getProperty(packageJson, property, defaultValue), "getPackageJsonProperty");
@@ -1,4 +1,4 @@
1
- export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-BRauYh0w.cjs';
1
+ export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-B2CLbuXK.cjs';
2
2
  import '@visulima/fs';
3
3
  import '@antfu/install-pkg';
4
4
  import 'normalize-package-data';
@@ -1,4 +1,4 @@
1
- export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-BRauYh0w.mjs';
1
+ export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-B2CLbuXK.mjs';
2
2
  import '@visulima/fs';
3
3
  import '@antfu/install-pkg';
4
4
  import 'normalize-package-data';
@@ -1,4 +1,4 @@
1
- export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-BRauYh0w.d.mjs';
1
+ export { F as FindPackageJsonCache, N as NormalizedReadResult, e as ensurePackages, f as findPackageJson, a as findPackageJsonSync, g as getPackageJsonProperty, h as hasPackageJsonAnyDependency, b as hasPackageJsonProperty, p as parsePackageJson, w as writePackageJson, c as writePackageJsonSync } from './packem_shared/package-json-B2CLbuXK.d.mjs';
2
2
  import '@visulima/fs';
3
3
  import '@antfu/install-pkg';
4
4
  import 'normalize-package-data';
@@ -280,6 +280,40 @@ const isNode = typeof process.stdout < "u" && !process.versions?.deno && !global
280
280
  var __defProp = Object.defineProperty;
281
281
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
282
282
  const PackageJsonFileCache = /* @__PURE__ */ new Map();
283
+ class PackageJsonValidationError extends Error {
284
+ static {
285
+ __name(this, "PackageJsonValidationError");
286
+ }
287
+ constructor(warnings) {
288
+ super(`The following warnings were encountered while normalizing package data:
289
+ - ${warnings.join("\n- ")}`);
290
+ this.name = "PackageJsonValidationError";
291
+ }
292
+ }
293
+ const normalizeInput = /* @__PURE__ */ __name((input, strict, ignoreWarnings = []) => {
294
+ const warnings = [];
295
+ normalizeData(
296
+ input,
297
+ (message) => {
298
+ warnings.push(message);
299
+ },
300
+ strict
301
+ );
302
+ if (strict && warnings.length > 0) {
303
+ const filteredWarnings = warnings.filter(
304
+ (warning) => !ignoreWarnings.some((pattern) => {
305
+ if (pattern instanceof RegExp) {
306
+ return pattern.test(warning);
307
+ }
308
+ return pattern === warning;
309
+ })
310
+ );
311
+ if (filteredWarnings.length > 0) {
312
+ throw new PackageJsonValidationError(filteredWarnings);
313
+ }
314
+ }
315
+ return input;
316
+ }, "normalizeInput");
283
317
  const findPackageJson = /* @__PURE__ */ __name(async (cwd, options = {}) => {
284
318
  const findUpConfig = {
285
319
  type: "file"
@@ -296,7 +330,7 @@ const findPackageJson = /* @__PURE__ */ __name(async (cwd, options = {}) => {
296
330
  return cache.get(filePath);
297
331
  }
298
332
  const packageJson = await readJson(filePath);
299
- normalizeData(packageJson);
333
+ normalizeInput(packageJson, options.strict ?? false, options.ignoreWarnings);
300
334
  const output = {
301
335
  packageJson,
302
336
  path: filePath
@@ -320,7 +354,7 @@ const findPackageJsonSync = /* @__PURE__ */ __name((cwd, options = {}) => {
320
354
  return cache.get(filePath);
321
355
  }
322
356
  const packageJson = readJsonSync(filePath);
323
- normalizeData(packageJson);
357
+ normalizeInput(packageJson, options.strict ?? false, options.ignoreWarnings);
324
358
  const output = {
325
359
  packageJson,
326
360
  path: filePath
@@ -338,7 +372,7 @@ const writePackageJsonSync = /* @__PURE__ */ __name((data, options = {}) => {
338
372
  const directory = toPath(options.cwd ?? process.cwd());
339
373
  writeJsonSync(join(directory, "package.json"), data, writeOptions);
340
374
  }, "writePackageJsonSync");
341
- const parsePackageJson = /* @__PURE__ */ __name((packageFile) => {
375
+ const parsePackageJson = /* @__PURE__ */ __name((packageFile, options) => {
342
376
  const isObject = packageFile !== null && typeof packageFile === "object" && !Array.isArray(packageFile);
343
377
  const isString = typeof packageFile === "string";
344
378
  if (!isObject && !isString) {
@@ -348,7 +382,7 @@ const parsePackageJson = /* @__PURE__ */ __name((packageFile) => {
348
382
  // eslint-disable-next-line security/detect-non-literal-fs-filename
349
383
  existsSync(packageFile) ? readJsonSync(packageFile) : parseJson(packageFile)
350
384
  );
351
- normalizeData(json);
385
+ normalizeInput(json, options?.strict ?? false, options?.ignoreWarnings);
352
386
  return json;
353
387
  }, "parsePackageJson");
354
388
  const getPackageJsonProperty = /* @__PURE__ */ __name((packageJson, property, defaultValue) => getProperty(packageJson, property, defaultValue), "getPackageJsonProperty");
@@ -1850,6 +1850,8 @@ type EnsurePackagesOptions = {
1850
1850
 
1851
1851
  type ReadOptions = {
1852
1852
  cache?: FindPackageJsonCache | boolean;
1853
+ ignoreWarnings?: (RegExp | string)[];
1854
+ strict?: boolean;
1853
1855
  };
1854
1856
  type FindPackageJsonCache = Cache<NormalizedReadResult>;
1855
1857
  type NormalizedReadResult = {
@@ -1864,7 +1866,10 @@ declare const writePackageJson: <T = PackageJson$1>(data: T, options?: WriteJson
1864
1866
  declare const writePackageJsonSync: <T = PackageJson$1>(data: T, options?: WriteJsonOptions & {
1865
1867
  cwd?: URL | string;
1866
1868
  }) => void;
1867
- declare const parsePackageJson: (packageFile: JsonObject | string) => NormalizedPackageJson;
1869
+ declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
1870
+ ignoreWarnings?: (RegExp | string)[];
1871
+ strict?: boolean;
1872
+ }) => NormalizedPackageJson;
1868
1873
  declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
1869
1874
  declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
1870
1875
  declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
@@ -1850,6 +1850,8 @@ type EnsurePackagesOptions = {
1850
1850
 
1851
1851
  type ReadOptions = {
1852
1852
  cache?: FindPackageJsonCache | boolean;
1853
+ ignoreWarnings?: (RegExp | string)[];
1854
+ strict?: boolean;
1853
1855
  };
1854
1856
  type FindPackageJsonCache = Cache<NormalizedReadResult>;
1855
1857
  type NormalizedReadResult = {
@@ -1864,7 +1866,10 @@ declare const writePackageJson: <T = PackageJson$1>(data: T, options?: WriteJson
1864
1866
  declare const writePackageJsonSync: <T = PackageJson$1>(data: T, options?: WriteJsonOptions & {
1865
1867
  cwd?: URL | string;
1866
1868
  }) => void;
1867
- declare const parsePackageJson: (packageFile: JsonObject | string) => NormalizedPackageJson;
1869
+ declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
1870
+ ignoreWarnings?: (RegExp | string)[];
1871
+ strict?: boolean;
1872
+ }) => NormalizedPackageJson;
1868
1873
  declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
1869
1874
  declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
1870
1875
  declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
@@ -1850,6 +1850,8 @@ type EnsurePackagesOptions = {
1850
1850
 
1851
1851
  type ReadOptions = {
1852
1852
  cache?: FindPackageJsonCache | boolean;
1853
+ ignoreWarnings?: (RegExp | string)[];
1854
+ strict?: boolean;
1853
1855
  };
1854
1856
  type FindPackageJsonCache = Cache<NormalizedReadResult>;
1855
1857
  type NormalizedReadResult = {
@@ -1864,7 +1866,10 @@ declare const writePackageJson: <T = PackageJson$1>(data: T, options?: WriteJson
1864
1866
  declare const writePackageJsonSync: <T = PackageJson$1>(data: T, options?: WriteJsonOptions & {
1865
1867
  cwd?: URL | string;
1866
1868
  }) => void;
1867
- declare const parsePackageJson: (packageFile: JsonObject | string) => NormalizedPackageJson;
1869
+ declare const parsePackageJson: (packageFile: JsonObject | string, options?: {
1870
+ ignoreWarnings?: (RegExp | string)[];
1871
+ strict?: boolean;
1872
+ }) => NormalizedPackageJson;
1868
1873
  declare const getPackageJsonProperty: <T = unknown>(packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>, defaultValue?: T) => T;
1869
1874
  declare const hasPackageJsonProperty: (packageJson: NormalizedPackageJson, property: Paths<NormalizedPackageJson>) => boolean;
1870
1875
  declare const hasPackageJsonAnyDependency: (packageJson: NormalizedPackageJson, arguments_: string[], options?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "3.4.7",
3
+ "version": "3.5.0",
4
4
  "description": "One Package to rule them all, finds your root-dir, monorepo, or package manager.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -147,12 +147,12 @@
147
147
  "dependencies": {
148
148
  "@antfu/install-pkg": "^1.0.0",
149
149
  "@inquirer/confirm": "^5.1.3",
150
- "@visulima/fs": "3.0.0",
151
- "@visulima/path": "1.3.3",
150
+ "@visulima/fs": "3.0.1",
151
+ "@visulima/path": "1.3.4",
152
152
  "normalize-package-data": "^7.0.0"
153
153
  },
154
154
  "engines": {
155
- "node": ">=18.* <=23.*"
155
+ "node": ">=18.0.0 <=23.x"
156
156
  },
157
157
  "os": [
158
158
  "darwin",