@socketsecurity/lib 4.3.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/README.md +1 -1
  3. package/dist/constants/node.js +1 -1
  4. package/dist/{package-default-node-range.js → constants/package-default-node-range.js} +1 -1
  5. package/dist/constants/packages.js +3 -3
  6. package/dist/{dlx-binary.d.ts → dlx/binary.d.ts} +2 -2
  7. package/dist/{dlx-binary.js → dlx/binary.js} +17 -17
  8. package/dist/dlx/cache.d.ts +25 -0
  9. package/dist/dlx/cache.js +32 -0
  10. package/dist/dlx/dir.d.ts +24 -0
  11. package/dist/dlx/dir.js +79 -0
  12. package/dist/{dlx-manifest.js → dlx/manifest.js} +7 -7
  13. package/dist/{dlx-package.d.ts → dlx/package.d.ts} +2 -2
  14. package/dist/{dlx-package.js → dlx/package.js} +16 -16
  15. package/dist/dlx/packages.d.ts +24 -0
  16. package/dist/dlx/packages.js +125 -0
  17. package/dist/dlx/paths.d.ts +31 -0
  18. package/dist/dlx/paths.js +75 -0
  19. package/dist/fs.d.ts +103 -55
  20. package/dist/fs.js +149 -41
  21. package/dist/json/edit.d.ts +16 -0
  22. package/dist/json/edit.js +217 -0
  23. package/dist/json/format.d.ts +140 -0
  24. package/dist/json/format.js +121 -0
  25. package/dist/json/parse.d.ts +76 -0
  26. package/dist/{json.js → json/parse.js} +4 -4
  27. package/dist/json/types.d.ts +229 -0
  28. package/dist/json/types.js +17 -0
  29. package/dist/objects.d.ts +61 -61
  30. package/dist/objects.js +30 -30
  31. package/dist/packages/{editable.js → edit.js} +18 -32
  32. package/dist/packages/operations.js +3 -3
  33. package/dist/packages.d.ts +2 -2
  34. package/dist/packages.js +5 -5
  35. package/dist/promises.d.ts +19 -19
  36. package/dist/promises.js +14 -14
  37. package/dist/sorts.d.ts +10 -10
  38. package/dist/sorts.js +19 -19
  39. package/dist/strings.d.ts +63 -63
  40. package/dist/strings.js +18 -18
  41. package/dist/suppress-warnings.js +4 -0
  42. package/package.json +59 -35
  43. package/dist/dlx.d.ts +0 -104
  44. package/dist/dlx.js +0 -220
  45. package/dist/json.d.ts +0 -196
  46. /package/dist/{lifecycle-script-names.d.ts → constants/lifecycle-script-names.d.ts} +0 -0
  47. /package/dist/{lifecycle-script-names.js → constants/lifecycle-script-names.js} +0 -0
  48. /package/dist/{maintained-node-versions.d.ts → constants/maintained-node-versions.d.ts} +0 -0
  49. /package/dist/{maintained-node-versions.js → constants/maintained-node-versions.js} +0 -0
  50. /package/dist/{package-default-node-range.d.ts → constants/package-default-node-range.d.ts} +0 -0
  51. /package/dist/{package-default-socket-categories.d.ts → constants/package-default-socket-categories.d.ts} +0 -0
  52. /package/dist/{package-default-socket-categories.js → constants/package-default-socket-categories.js} +0 -0
  53. /package/dist/{dlx-manifest.d.ts → dlx/manifest.d.ts} +0 -0
  54. /package/dist/packages/{editable.d.ts → edit.d.ts} +0 -0
@@ -0,0 +1,229 @@
1
+ /**
2
+ * @fileoverview JSON type definitions and interfaces.
3
+ */
4
+ /**
5
+ * JSON primitive types: `null`, `boolean`, `number`, or `string`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const primitives: JsonPrimitive[] = [null, true, 42, 'hello']
10
+ * ```
11
+ */
12
+ export type JsonPrimitive = null | boolean | number | string;
13
+ /**
14
+ * A JSON array containing JSON values.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const arr: JsonArray = [1, 'two', { three: 3 }, [4, 5]]
19
+ * ```
20
+ */
21
+ export interface JsonArray extends Array<JsonValue> {
22
+ }
23
+ /**
24
+ * A JSON object with string keys and JSON values.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const obj: JsonObject = {
29
+ * name: 'example',
30
+ * count: 42,
31
+ * active: true,
32
+ * nested: { key: 'value' }
33
+ * }
34
+ * ```
35
+ */
36
+ export interface JsonObject {
37
+ [key: string]: JsonValue;
38
+ }
39
+ /**
40
+ * Any valid JSON value: primitive, object, or array.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const values: JsonValue[] = [
45
+ * null,
46
+ * true,
47
+ * 42,
48
+ * 'hello',
49
+ * { key: 'value' },
50
+ * [1, 2, 3]
51
+ * ]
52
+ * ```
53
+ */
54
+ export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
55
+ /**
56
+ * Reviver function for transforming parsed JSON values.
57
+ * Called for each key-value pair during parsing.
58
+ *
59
+ * @param key - The object key or array index being parsed
60
+ * @param value - The parsed value
61
+ * @returns The transformed value (or original if no transform needed)
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * // Convert date strings to Date objects
66
+ * const reviver: JsonReviver = (key, value) => {
67
+ * if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value)) {
68
+ * return new Date(value)
69
+ * }
70
+ * return value
71
+ * }
72
+ * ```
73
+ */
74
+ export type JsonReviver = (key: string, value: unknown) => unknown;
75
+ /**
76
+ * Options for JSON parsing operations.
77
+ */
78
+ export interface JsonParseOptions {
79
+ /**
80
+ * Optional filepath for improved error messages.
81
+ * When provided, errors will be prefixed with the filepath.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * // Error message will be: "config.json: Unexpected token } in JSON"
86
+ * jsonParse('invalid', { filepath: 'config.json' })
87
+ * ```
88
+ */
89
+ filepath?: string | undefined;
90
+ /**
91
+ * Optional reviver function to transform parsed values.
92
+ * Called for each key-value pair during parsing.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * // Convert ISO date strings to Date objects
97
+ * const options = {
98
+ * reviver: (key, value) => {
99
+ * if (typeof value === 'string' && /^\d{4}-\d{2}-\d{2}/.test(value)) {
100
+ * return new Date(value)
101
+ * }
102
+ * return value
103
+ * }
104
+ * }
105
+ * ```
106
+ */
107
+ reviver?: JsonReviver | undefined;
108
+ /**
109
+ * Whether to throw on parse errors.
110
+ * When `false`, returns `undefined` instead of throwing.
111
+ *
112
+ * @default true
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * // Throws error
117
+ * jsonParse('invalid', { throws: true })
118
+ *
119
+ * // Returns undefined
120
+ * const result = jsonParse('invalid', { throws: false })
121
+ * ```
122
+ */
123
+ throws?: boolean | undefined;
124
+ }
125
+ /**
126
+ * Options for saving editable JSON files.
127
+ */
128
+ export interface EditableJsonSaveOptions {
129
+ /**
130
+ * Whether to ignore whitespace-only changes when determining if save is needed.
131
+ * @default false
132
+ */
133
+ ignoreWhitespace?: boolean | undefined;
134
+ /**
135
+ * Whether to sort object keys alphabetically before saving.
136
+ * @default false
137
+ */
138
+ sort?: boolean | undefined;
139
+ }
140
+ /**
141
+ * Options for creating or loading editable JSON instances.
142
+ */
143
+ export interface EditableJsonOptions<T = Record<string, unknown>> {
144
+ /**
145
+ * File path for the JSON file (optional for in-memory instances).
146
+ */
147
+ path?: string | undefined;
148
+ /**
149
+ * Whether to create the file if it doesn't exist during load.
150
+ * @default false
151
+ */
152
+ create?: boolean | undefined;
153
+ /**
154
+ * Initial data to populate the instance with.
155
+ */
156
+ data?: T | undefined;
157
+ }
158
+ /**
159
+ * EditableJson instance interface for JSON file manipulation.
160
+ * Provides core functionality for loading, editing, and saving JSON files
161
+ * while preserving formatting (indentation and line endings).
162
+ */
163
+ export interface EditableJsonInstance<T = Record<string, unknown>> {
164
+ /**
165
+ * The parsed JSON content as a readonly object.
166
+ * @readonly
167
+ */
168
+ content: Readonly<T>;
169
+ /**
170
+ * Create a new JSON file at the specified path.
171
+ * @param path - The file path where JSON will be created
172
+ */
173
+ create(path: string): this;
174
+ /**
175
+ * Initialize the instance from a content object.
176
+ * Note: Disables saving when used (no file path associated).
177
+ * @param content - The JSON content object
178
+ */
179
+ fromContent(content: unknown): this;
180
+ /**
181
+ * Initialize the instance from a JSON string.
182
+ * @param json - The JSON content as a string
183
+ */
184
+ fromJSON(json: string): this;
185
+ /**
186
+ * Load a JSON file from the specified path.
187
+ * @param path - The file path to load
188
+ * @param create - Whether to create the file if it doesn't exist
189
+ */
190
+ load(path: string, create?: boolean): Promise<this>;
191
+ /**
192
+ * Update the JSON content with new values.
193
+ * @param content - Partial object with fields to update
194
+ */
195
+ update(content: Partial<T>): this;
196
+ /**
197
+ * Save the JSON file to disk.
198
+ * @param options - Save options for formatting and sorting
199
+ */
200
+ save(options?: EditableJsonSaveOptions): Promise<boolean>;
201
+ /**
202
+ * Synchronously save the JSON file to disk.
203
+ * @param options - Save options for formatting and sorting
204
+ */
205
+ saveSync(options?: EditableJsonSaveOptions): boolean;
206
+ /**
207
+ * Check if the JSON will be saved based on current changes.
208
+ * @param options - Save options to evaluate
209
+ */
210
+ willSave(options?: EditableJsonSaveOptions): boolean;
211
+ /**
212
+ * The full path to the JSON file.
213
+ * @readonly
214
+ */
215
+ readonly filename: string;
216
+ /**
217
+ * The directory path containing the JSON file.
218
+ * @readonly
219
+ */
220
+ readonly path: string | undefined;
221
+ }
222
+ /**
223
+ * EditableJson constructor interface.
224
+ */
225
+ export interface EditableJsonConstructor<T = Record<string, unknown>> {
226
+ new (): EditableJsonInstance<T>;
227
+ create(path: string, opts?: EditableJsonOptions<T>): Promise<EditableJsonInstance<T>>;
228
+ load(path: string, opts?: EditableJsonOptions<T>): Promise<EditableJsonInstance<T>>;
229
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") {
9
+ for (let key of __getOwnPropNames(from))
10
+ if (!__hasOwnProp.call(to, key) && key !== except)
11
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
+ }
13
+ return to;
14
+ };
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
package/dist/objects.d.ts CHANGED
@@ -55,33 +55,6 @@ type SortedObject<T> = {
55
55
  [key: PropertyKey]: T;
56
56
  };
57
57
  export type { GetterDefObj, LazyGetterStats, ConstantsObjectOptions, Remap };
58
- /**
59
- * Create a lazy getter function that memoizes its result.
60
- *
61
- * The returned function will only call the getter once, caching the result
62
- * for subsequent calls. This is useful for expensive computations or
63
- * operations that should only happen when needed.
64
- *
65
- * @param name - The property key name for the getter (used for debugging and stats)
66
- * @param getter - Function that computes the value on first access
67
- * @param stats - Optional stats object to track initialization
68
- * @returns A memoized getter function
69
- *
70
- * @example
71
- * ```ts
72
- * const stats = { initialized: new Set() }
73
- * const getLargeData = createLazyGetter('data', () => {
74
- * console.log('Computing expensive data...')
75
- * return { large: 'dataset' }
76
- * }, stats)
77
- *
78
- * getLargeData() // Logs "Computing expensive data..." and returns data
79
- * getLargeData() // Returns cached data without logging
80
- * console.log(stats.initialized.has('data')) // true
81
- * ```
82
- */
83
- /*@__NO_SIDE_EFFECTS__*/
84
- export declare function createLazyGetter<T>(name: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): () => T;
85
58
  /**
86
59
  * Create a frozen constants object with lazy getters and internal properties.
87
60
  *
@@ -120,6 +93,33 @@ export declare function createLazyGetter<T>(name: PropertyKey, getter: () => T,
120
93
  */
121
94
  /*@__NO_SIDE_EFFECTS__*/
122
95
  export declare function createConstantsObject(props: object, options_?: ConstantsObjectOptions | undefined): Readonly<object>;
96
+ /**
97
+ * Create a lazy getter function that memoizes its result.
98
+ *
99
+ * The returned function will only call the getter once, caching the result
100
+ * for subsequent calls. This is useful for expensive computations or
101
+ * operations that should only happen when needed.
102
+ *
103
+ * @param name - The property key name for the getter (used for debugging and stats)
104
+ * @param getter - Function that computes the value on first access
105
+ * @param stats - Optional stats object to track initialization
106
+ * @returns A memoized getter function
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const stats = { initialized: new Set() }
111
+ * const getLargeData = createLazyGetter('data', () => {
112
+ * console.log('Computing expensive data...')
113
+ * return { large: 'dataset' }
114
+ * }, stats)
115
+ *
116
+ * getLargeData() // Logs "Computing expensive data..." and returns data
117
+ * getLargeData() // Returns cached data without logging
118
+ * console.log(stats.initialized.has('data')) // true
119
+ * ```
120
+ */
121
+ /*@__NO_SIDE_EFFECTS__*/
122
+ export declare function createLazyGetter<T>(name: PropertyKey, getter: () => T, stats?: LazyGetterStats | undefined): () => T;
123
123
  /**
124
124
  * Define a getter property on an object.
125
125
  *
@@ -393,6 +393,40 @@ export declare const objectAssign: {
393
393
  <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
394
394
  (target: object, ...sources: any[]): any;
395
395
  };
396
+ /**
397
+ * Deep merge source object into target object.
398
+ *
399
+ * Recursively merges properties from `source` into `target`. Arrays in source
400
+ * completely replace arrays in target (no element-wise merging). Objects are
401
+ * merged recursively. Includes infinite loop detection for safety.
402
+ *
403
+ * @param target - The object to merge into (will be modified)
404
+ * @param source - The object to merge from
405
+ * @returns The modified target object
406
+ *
407
+ * @example
408
+ * ```ts
409
+ * const target = { a: { x: 1 }, b: [1, 2] }
410
+ * const source = { a: { y: 2 }, b: [3, 4, 5], c: 3 }
411
+ * merge(target, source)
412
+ * // { a: { x: 1, y: 2 }, b: [3, 4, 5], c: 3 }
413
+ * ```
414
+ *
415
+ * @example
416
+ * ```ts
417
+ * // Arrays are replaced, not merged
418
+ * merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }
419
+ *
420
+ * // Deep object merging
421
+ * merge(
422
+ * { config: { api: 'v1', timeout: 1000 } },
423
+ * { config: { api: 'v2', retries: 3 } }
424
+ * )
425
+ * // { config: { api: 'v2', timeout: 1000, retries: 3 } }
426
+ * ```
427
+ */
428
+ /*@__NO_SIDE_EFFECTS__*/
429
+ export declare function merge<T extends object, U extends object>(target: T, source: U): T & U;
396
430
  /**
397
431
  * Get all own property entries (key-value pairs) from an object.
398
432
  *
@@ -438,40 +472,6 @@ export declare const objectFreeze: {
438
472
  }, U extends string | number | bigint | symbol | boolean>(o: T): Readonly<T>;
439
473
  <T>(o: T): Readonly<T>;
440
474
  };
441
- /**
442
- * Deep merge source object into target object.
443
- *
444
- * Recursively merges properties from `source` into `target`. Arrays in source
445
- * completely replace arrays in target (no element-wise merging). Objects are
446
- * merged recursively. Includes infinite loop detection for safety.
447
- *
448
- * @param target - The object to merge into (will be modified)
449
- * @param source - The object to merge from
450
- * @returns The modified target object
451
- *
452
- * @example
453
- * ```ts
454
- * const target = { a: { x: 1 }, b: [1, 2] }
455
- * const source = { a: { y: 2 }, b: [3, 4, 5], c: 3 }
456
- * merge(target, source)
457
- * // { a: { x: 1, y: 2 }, b: [3, 4, 5], c: 3 }
458
- * ```
459
- *
460
- * @example
461
- * ```ts
462
- * // Arrays are replaced, not merged
463
- * merge({ arr: [1, 2] }, { arr: [3] }) // { arr: [3] }
464
- *
465
- * // Deep object merging
466
- * merge(
467
- * { config: { api: 'v1', timeout: 1000 } },
468
- * { config: { api: 'v2', retries: 3 } }
469
- * )
470
- * // { config: { api: 'v2', timeout: 1000, retries: 3 } }
471
- * ```
472
- */
473
- /*@__NO_SIDE_EFFECTS__*/
474
- export declare function merge<T extends object, U extends object>(target: T, source: U): T & U;
475
475
  /**
476
476
  * Convert an object to a new object with sorted keys.
477
477
  *
package/dist/objects.js CHANGED
@@ -56,20 +56,6 @@ const ObjectPrototype = Object.prototype;
56
56
  const ObjectSetPrototypeOf = Object.setPrototypeOf;
57
57
  const ReflectOwnKeys = Reflect.ownKeys;
58
58
  // @__NO_SIDE_EFFECTS__
59
- function createLazyGetter(name, getter, stats) {
60
- let lazyValue = import_core.UNDEFINED_TOKEN;
61
- const { [name]: lazyGetter } = {
62
- [name]() {
63
- if (lazyValue === import_core.UNDEFINED_TOKEN) {
64
- stats?.initialized?.add(name);
65
- lazyValue = getter();
66
- }
67
- return lazyValue;
68
- }
69
- };
70
- return lazyGetter;
71
- }
72
- // @__NO_SIDE_EFFECTS__
73
59
  function createConstantsObject(props, options_) {
74
60
  const options = { __proto__: null, ...options_ };
75
61
  const attributes = ObjectFreeze({
@@ -123,6 +109,20 @@ function createConstantsObject(props, options_) {
123
109
  }
124
110
  return ObjectFreeze(object);
125
111
  }
112
+ // @__NO_SIDE_EFFECTS__
113
+ function createLazyGetter(name, getter, stats) {
114
+ let lazyValue = import_core.UNDEFINED_TOKEN;
115
+ const { [name]: lazyGetter } = {
116
+ [name]() {
117
+ if (lazyValue === import_core.UNDEFINED_TOKEN) {
118
+ stats?.initialized?.add(name);
119
+ lazyValue = getter();
120
+ }
121
+ return lazyValue;
122
+ }
123
+ };
124
+ return lazyGetter;
125
+ }
126
126
  function defineGetter(object, propKey, getter) {
127
127
  ObjectDefineProperty(object, propKey, {
128
128
  get: getter,
@@ -209,22 +209,6 @@ function isObjectObject(value) {
209
209
  }
210
210
  const objectAssign = Object.assign;
211
211
  // @__NO_SIDE_EFFECTS__
212
- function objectEntries(obj) {
213
- if (obj === null || obj === void 0) {
214
- return [];
215
- }
216
- const keys = ReflectOwnKeys(obj);
217
- const { length } = keys;
218
- const entries = Array(length);
219
- const record = obj;
220
- for (let i = 0; i < length; i += 1) {
221
- const key = keys[i];
222
- entries[i] = [key, record[key]];
223
- }
224
- return entries;
225
- }
226
- const objectFreeze = Object.freeze;
227
- // @__NO_SIDE_EFFECTS__
228
212
  function merge(target, source) {
229
213
  if (!/* @__PURE__ */ isObject(target) || !/* @__PURE__ */ isObject(source)) {
230
214
  return target;
@@ -266,6 +250,22 @@ function merge(target, source) {
266
250
  return target;
267
251
  }
268
252
  // @__NO_SIDE_EFFECTS__
253
+ function objectEntries(obj) {
254
+ if (obj === null || obj === void 0) {
255
+ return [];
256
+ }
257
+ const keys = ReflectOwnKeys(obj);
258
+ const { length } = keys;
259
+ const entries = Array(length);
260
+ const record = obj;
261
+ for (let i = 0; i < length; i += 1) {
262
+ const key = keys[i];
263
+ entries[i] = [key, record[key]];
264
+ }
265
+ return entries;
266
+ }
267
+ const objectFreeze = Object.freeze;
268
+ // @__NO_SIDE_EFFECTS__
269
269
  function toSortedObject(obj) {
270
270
  return /* @__PURE__ */ toSortedObjectFromEntries(/* @__PURE__ */ objectEntries(obj));
271
271
  }
@@ -27,22 +27,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  mod
28
28
  ));
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var editable_exports = {};
31
- __export(editable_exports, {
30
+ var edit_exports = {};
31
+ __export(edit_exports, {
32
32
  getEditablePackageJsonClass: () => getEditablePackageJsonClass,
33
33
  pkgJsonToEditable: () => pkgJsonToEditable,
34
34
  toEditablePackageJson: () => toEditablePackageJson,
35
35
  toEditablePackageJsonSync: () => toEditablePackageJsonSync
36
36
  });
37
- module.exports = __toCommonJS(editable_exports);
37
+ module.exports = __toCommonJS(edit_exports);
38
38
  var import_package_json = __toESM(require("../external/@npmcli/package-json"));
39
39
  var import_read_package = require("../external/@npmcli/package-json/lib/read-package");
40
40
  var import_sort = require("../external/@npmcli/package-json/lib/sort");
41
+ var import_format = require("../json/format");
41
42
  var import_normalize = require("../paths/normalize");
42
43
  var import_normalize2 = require("./normalize");
43
44
  var import_packages = require("../paths/packages");
44
- const identSymbol = Symbol.for("indent");
45
- const newlineSymbol = Symbol.for("newline");
46
45
  let _EditablePackageJsonClass;
47
46
  let _fs;
48
47
  // @__NO_SIDE_EFFECTS__
@@ -193,35 +192,22 @@ function getEditablePackageJsonClass() {
193
192
  if (!this._canSave || this.content === void 0) {
194
193
  throw new Error("No package.json to save to");
195
194
  }
196
- const { ignoreWhitespace = false, sort = false } = {
197
- __proto__: null,
198
- ...options
199
- };
200
- const {
201
- [identSymbol]: indent,
202
- [newlineSymbol]: newline,
203
- ...rest
204
- } = this.content;
205
- const content = sort ? (0, import_sort.packageSort)(rest) : rest;
206
- const {
207
- [identSymbol]: _indent,
208
- [newlineSymbol]: _newline,
209
- ...origContent
210
- } = this._readFileJson || {};
211
- if (ignoreWhitespace && (/* @__PURE__ */ getUtil()).isDeepStrictEqual(content, origContent)) {
212
- return false;
213
- }
214
- const format = indent === void 0 || indent === null ? " " : indent;
215
- const eol = newline === void 0 || newline === null ? "\n" : newline;
216
- const fileContent = `${JSON.stringify(
217
- content,
218
- void 0,
219
- format
220
- )}
221
- `.replace(/\n/g, eol);
222
- if (!ignoreWhitespace && fileContent.trim() === this._readFileContent.trim()) {
195
+ if (!(0, import_format.shouldSave)(
196
+ this.content,
197
+ this._readFileJson,
198
+ this._readFileContent,
199
+ { ...options, sortFn: options?.sort ? import_sort.packageSort : void 0 }
200
+ )) {
223
201
  return false;
224
202
  }
203
+ const content = (0, import_format.stripFormattingSymbols)(
204
+ this.content
205
+ );
206
+ const sortedContent = options?.sort ? (0, import_sort.packageSort)(content) : content;
207
+ const formatting = (0, import_format.getFormattingFromContent)(
208
+ this.content
209
+ );
210
+ const fileContent = (0, import_format.stringifyWithFormatting)(sortedContent, formatting);
225
211
  const { promises: fsPromises } = /* @__PURE__ */ getFs();
226
212
  await fsPromises.writeFile(this.filename, fileContent);
227
213
  this._readFileContent = fileContent;
@@ -55,7 +55,7 @@ var import_objects = require("../objects");
55
55
  var import_normalize = require("./normalize");
56
56
  var import_packages2 = require("../paths/packages");
57
57
  var import_specs = require("./specs");
58
- var import_editable = require("./editable");
58
+ var import_edit = require("./edit");
59
59
  const abortSignal = (0, import_process.getAbortSignal)();
60
60
  const packageExtensions = (0, import_packages.getPackageExtensions)();
61
61
  const packumentCache = (0, import_packages.getPackumentCache)();
@@ -161,7 +161,7 @@ async function readPackageJson(filepath, options) {
161
161
  });
162
162
  if (pkgJson) {
163
163
  if (editable) {
164
- return await (0, import_editable.toEditablePackageJson)(pkgJson, {
164
+ return await (0, import_edit.toEditablePackageJson)(pkgJson, {
165
165
  path: filepath,
166
166
  normalize,
167
167
  ...normalizeOptions
@@ -180,7 +180,7 @@ function readPackageJsonSync(filepath, options) {
180
180
  const pkgJson = (0, import_fs.readJsonSync)((0, import_packages2.resolvePackageJsonPath)(filepath), { throws });
181
181
  if (pkgJson) {
182
182
  if (editable) {
183
- return (0, import_editable.toEditablePackageJsonSync)(pkgJson, {
183
+ return (0, import_edit.toEditablePackageJsonSync)(pkgJson, {
184
184
  path: filepath,
185
185
  normalize,
186
186
  ...normalizeOptions
@@ -3,7 +3,7 @@
3
3
  * Provides npm package analysis, dependency resolution, and registry operations.
4
4
  */
5
5
  import type { CategoryString } from './types';
6
- import { getEditablePackageJsonClass, pkgJsonToEditable, toEditablePackageJson, toEditablePackageJsonSync } from './packages/editable';
6
+ import { getEditablePackageJsonClass, pkgJsonToEditable, toEditablePackageJson, toEditablePackageJsonSync } from './packages/edit';
7
7
  import { findTypesForSubpath, getExportFilePaths, getSubpaths, isConditionalExports, isSubpathExports, resolvePackageJsonEntryExports } from './packages/exports';
8
8
  import { isolatePackage } from './packages/isolation';
9
9
  import { collectIncompatibleLicenses, collectLicenseWarnings, createAstNode, createBinaryOperationNode, createLicenseNode, parseSpdxExp, resolvePackageLicenses, visitLicenses } from './packages/licenses';
@@ -19,7 +19,7 @@ type PackageExports = {
19
19
  [path: string]: unknown;
20
20
  };
21
21
  // Re-export the EditablePackageJson instance type for convenient access
22
- export type EditablePackageJson = import('./packages/editable').EditablePackageJsonInstance;
22
+ export type EditablePackageJson = import('./packages/edit').EditablePackageJsonInstance;
23
23
  /**
24
24
  * Extended PackageJson type based on NPMCliPackageJson.Content with Socket-specific additions.
25
25
  * @extends NPMCliPackageJson.Content (from @npmcli/package-json)
package/dist/packages.js CHANGED
@@ -31,7 +31,7 @@ __export(packages_exports, {
31
31
  fetchPackageProvenance: () => import_provenance.fetchPackageProvenance,
32
32
  findPackageExtensions: () => import_operations.findPackageExtensions,
33
33
  findTypesForSubpath: () => import_exports.findTypesForSubpath,
34
- getEditablePackageJsonClass: () => import_editable.getEditablePackageJsonClass,
34
+ getEditablePackageJsonClass: () => import_edit.getEditablePackageJsonClass,
35
35
  getExportFilePaths: () => import_exports.getExportFilePaths,
36
36
  getProvenanceDetails: () => import_provenance.getProvenanceDetails,
37
37
  getReleaseTag: () => import_operations.getReleaseTag,
@@ -50,7 +50,7 @@ __export(packages_exports, {
50
50
  normalizePackageJson: () => import_normalize.normalizePackageJson,
51
51
  packPackage: () => import_operations.packPackage,
52
52
  parseSpdxExp: () => import_licenses.parseSpdxExp,
53
- pkgJsonToEditable: () => import_editable.pkgJsonToEditable,
53
+ pkgJsonToEditable: () => import_edit.pkgJsonToEditable,
54
54
  readPackageJson: () => import_operations.readPackageJson,
55
55
  readPackageJsonSync: () => import_operations.readPackageJsonSync,
56
56
  resolveEscapedScope: () => import_normalize.resolveEscapedScope,
@@ -62,13 +62,13 @@ __export(packages_exports, {
62
62
  resolvePackageLicenses: () => import_licenses.resolvePackageLicenses,
63
63
  resolvePackageName: () => import_operations.resolvePackageName,
64
64
  resolveRegistryPackageName: () => import_operations.resolveRegistryPackageName,
65
- toEditablePackageJson: () => import_editable.toEditablePackageJson,
66
- toEditablePackageJsonSync: () => import_editable.toEditablePackageJsonSync,
65
+ toEditablePackageJson: () => import_edit.toEditablePackageJson,
66
+ toEditablePackageJsonSync: () => import_edit.toEditablePackageJsonSync,
67
67
  unescapeScope: () => import_normalize.unescapeScope,
68
68
  visitLicenses: () => import_licenses.visitLicenses
69
69
  });
70
70
  module.exports = __toCommonJS(packages_exports);
71
- var import_editable = require("./packages/editable");
71
+ var import_edit = require("./packages/edit");
72
72
  var import_exports = require("./packages/exports");
73
73
  var import_isolation = require("./packages/isolation");
74
74
  var import_licenses = require("./packages/licenses");
@@ -208,25 +208,6 @@ export declare function normalizeIterationOptions(options?: number | IterationOp
208
208
  */
209
209
  /*@__NO_SIDE_EFFECTS__*/
210
210
  export declare function normalizeRetryOptions(options?: number | RetryOptions | undefined): RetryOptions;
211
- /**
212
- * Resolve retry options from various input formats.
213
- *
214
- * Converts shorthand and partial options into a base configuration that can be
215
- * further normalized. This is an internal helper for option processing.
216
- *
217
- * @param options - Retry count as number, or partial options object, or undefined
218
- * @returns Resolved retry options with defaults for basic properties
219
- *
220
- * @example
221
- * resolveRetryOptions(3)
222
- * // => { retries: 3, minTimeout: 200, maxTimeout: 10000, factor: 2 }
223
- *
224
- * @example
225
- * resolveRetryOptions({ retries: 5, maxTimeout: 5000 })
226
- * // => { retries: 5, minTimeout: 200, maxTimeout: 5000, factor: 2 }
227
- */
228
- /*@__NO_SIDE_EFFECTS__*/
229
- export declare function resolveRetryOptions(options?: number | RetryOptions | undefined): RetryOptions;
230
211
  /**
231
212
  * Execute an async function for each array element with concurrency control.
232
213
  *
@@ -455,3 +436,22 @@ export declare function pFilterChunk<T>(chunks: T[][], callbackFn: (value: T) =>
455
436
  */
456
437
  /*@__NO_SIDE_EFFECTS__*/
457
438
  export declare function pRetry<T>(callbackFn: (...args: unknown[]) => Promise<T>, options?: number | RetryOptions | undefined): Promise<T | undefined>;
439
+ /**
440
+ * Resolve retry options from various input formats.
441
+ *
442
+ * Converts shorthand and partial options into a base configuration that can be
443
+ * further normalized. This is an internal helper for option processing.
444
+ *
445
+ * @param options - Retry count as number, or partial options object, or undefined
446
+ * @returns Resolved retry options with defaults for basic properties
447
+ *
448
+ * @example
449
+ * resolveRetryOptions(3)
450
+ * // => { retries: 3, minTimeout: 200, maxTimeout: 10000, factor: 2 }
451
+ *
452
+ * @example
453
+ * resolveRetryOptions({ retries: 5, maxTimeout: 5000 })
454
+ * // => { retries: 5, minTimeout: 200, maxTimeout: 5000, factor: 2 }
455
+ */
456
+ /*@__NO_SIDE_EFFECTS__*/
457
+ export declare function resolveRetryOptions(options?: number | RetryOptions | undefined): RetryOptions;