@socketsecurity/lib 4.4.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.
- package/CHANGELOG.md +67 -0
- package/dist/constants/node.js +1 -1
- package/dist/{package-default-node-range.js → constants/package-default-node-range.js} +1 -1
- package/dist/constants/packages.js +3 -3
- package/dist/{dlx-binary.d.ts → dlx/binary.d.ts} +2 -2
- package/dist/{dlx-binary.js → dlx/binary.js} +17 -17
- package/dist/dlx/cache.d.ts +25 -0
- package/dist/dlx/cache.js +32 -0
- package/dist/dlx/dir.d.ts +24 -0
- package/dist/dlx/dir.js +79 -0
- package/dist/{dlx-manifest.js → dlx/manifest.js} +7 -7
- package/dist/{dlx-package.d.ts → dlx/package.d.ts} +2 -2
- package/dist/{dlx-package.js → dlx/package.js} +16 -16
- package/dist/dlx/packages.d.ts +24 -0
- package/dist/dlx/packages.js +125 -0
- package/dist/dlx/paths.d.ts +31 -0
- package/dist/dlx/paths.js +75 -0
- package/dist/fs.d.ts +3 -3
- package/dist/fs.js +3 -3
- package/dist/json/edit.d.ts +16 -0
- package/dist/json/edit.js +217 -0
- package/dist/json/format.d.ts +140 -0
- package/dist/json/format.js +121 -0
- package/dist/json/parse.d.ts +76 -0
- package/dist/{json.js → json/parse.js} +4 -4
- package/dist/json/types.d.ts +229 -0
- package/dist/json/types.js +17 -0
- package/dist/packages/{editable.js → edit.js} +18 -32
- package/dist/packages/operations.js +3 -3
- package/dist/packages.d.ts +2 -2
- package/dist/packages.js +5 -5
- package/package.json +58 -34
- package/dist/dlx.d.ts +0 -104
- package/dist/dlx.js +0 -220
- package/dist/json.d.ts +0 -196
- /package/dist/{lifecycle-script-names.d.ts → constants/lifecycle-script-names.d.ts} +0 -0
- /package/dist/{lifecycle-script-names.js → constants/lifecycle-script-names.js} +0 -0
- /package/dist/{maintained-node-versions.d.ts → constants/maintained-node-versions.d.ts} +0 -0
- /package/dist/{maintained-node-versions.js → constants/maintained-node-versions.js} +0 -0
- /package/dist/{package-default-node-range.d.ts → constants/package-default-node-range.d.ts} +0 -0
- /package/dist/{package-default-socket-categories.d.ts → constants/package-default-socket-categories.d.ts} +0 -0
- /package/dist/{package-default-socket-categories.js → constants/package-default-socket-categories.js} +0 -0
- /package/dist/{dlx-manifest.d.ts → dlx/manifest.d.ts} +0 -0
- /package/dist/packages/{editable.d.ts → edit.d.ts} +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { JsonParseOptions, JsonPrimitive, JsonValue } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a value is a JSON primitive type.
|
|
4
|
+
* JSON primitives are: `null`, `boolean`, `number`, or `string`.
|
|
5
|
+
*
|
|
6
|
+
* @param value - Value to check
|
|
7
|
+
* @returns `true` if value is a JSON primitive, `false` otherwise
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* isJsonPrimitive(null) // => true
|
|
12
|
+
* isJsonPrimitive(true) // => true
|
|
13
|
+
* isJsonPrimitive(42) // => true
|
|
14
|
+
* isJsonPrimitive('hello') // => true
|
|
15
|
+
* isJsonPrimitive({}) // => false
|
|
16
|
+
* isJsonPrimitive([]) // => false
|
|
17
|
+
* isJsonPrimitive(undefined) // => false
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
21
|
+
export declare function isJsonPrimitive(value: unknown): value is JsonPrimitive;
|
|
22
|
+
/**
|
|
23
|
+
* Parse JSON content with automatic Buffer handling and BOM stripping.
|
|
24
|
+
* Provides safer JSON parsing with helpful error messages and optional error suppression.
|
|
25
|
+
*
|
|
26
|
+
* Features:
|
|
27
|
+
* - Automatic UTF-8 Buffer conversion
|
|
28
|
+
* - BOM (Byte Order Mark) stripping for cross-platform compatibility
|
|
29
|
+
* - Enhanced error messages with filepath context
|
|
30
|
+
* - Optional error suppression (returns `undefined` instead of throwing)
|
|
31
|
+
* - Optional reviver for transforming parsed values
|
|
32
|
+
*
|
|
33
|
+
* @param content - JSON string or Buffer to parse
|
|
34
|
+
* @param options - Optional parsing configuration
|
|
35
|
+
* @returns Parsed JSON value, or `undefined` if parsing fails and `throws` is `false`
|
|
36
|
+
*
|
|
37
|
+
* @throws {SyntaxError} When JSON is invalid and `throws` is `true` (default)
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* // Basic usage
|
|
42
|
+
* const data = jsonParse('{"name":"example"}')
|
|
43
|
+
* console.log(data.name) // => 'example'
|
|
44
|
+
*
|
|
45
|
+
* // Parse Buffer with UTF-8 BOM
|
|
46
|
+
* const buffer = Buffer.from('\uFEFF{"value":42}')
|
|
47
|
+
* const data = jsonParse(buffer)
|
|
48
|
+
* console.log(data.value) // => 42
|
|
49
|
+
*
|
|
50
|
+
* // Enhanced error messages with filepath
|
|
51
|
+
* try {
|
|
52
|
+
* jsonParse('invalid', { filepath: 'config.json' })
|
|
53
|
+
* } catch (err) {
|
|
54
|
+
* console.error(err.message)
|
|
55
|
+
* // => "config.json: Unexpected token i in JSON at position 0"
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* // Suppress errors
|
|
59
|
+
* const result = jsonParse('invalid', { throws: false })
|
|
60
|
+
* console.log(result) // => undefined
|
|
61
|
+
*
|
|
62
|
+
* // Transform values with reviver
|
|
63
|
+
* const json = '{"created":"2024-01-15T10:30:00Z"}'
|
|
64
|
+
* const data = jsonParse(json, {
|
|
65
|
+
* reviver: (key, value) => {
|
|
66
|
+
* if (key === 'created' && typeof value === 'string') {
|
|
67
|
+
* return new Date(value)
|
|
68
|
+
* }
|
|
69
|
+
* return value
|
|
70
|
+
* }
|
|
71
|
+
* })
|
|
72
|
+
* console.log(data.created instanceof Date) // => true
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
76
|
+
export declare function jsonParse(content: string | Buffer, options?: JsonParseOptions | undefined): JsonValue | undefined;
|
|
@@ -17,13 +17,13 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
20
|
+
var parse_exports = {};
|
|
21
|
+
__export(parse_exports, {
|
|
22
22
|
isJsonPrimitive: () => isJsonPrimitive,
|
|
23
23
|
jsonParse: () => jsonParse
|
|
24
24
|
});
|
|
25
|
-
module.exports = __toCommonJS(
|
|
26
|
-
var import_strings = require("
|
|
25
|
+
module.exports = __toCommonJS(parse_exports);
|
|
26
|
+
var import_strings = require("../strings");
|
|
27
27
|
const JSONParse = JSON.parse;
|
|
28
28
|
// @__NO_SIDE_EFFECTS__
|
|
29
29
|
function isBuffer(x) {
|
|
@@ -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);
|
|
@@ -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
|
|
31
|
-
__export(
|
|
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(
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
|
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,
|
|
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,
|
|
183
|
+
return (0, import_edit.toEditablePackageJsonSync)(pkgJson, {
|
|
184
184
|
path: filepath,
|
|
185
185
|
normalize,
|
|
186
186
|
...normalizeOptions
|
package/dist/packages.d.ts
CHANGED
|
@@ -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/
|
|
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/
|
|
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: () =>
|
|
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: () =>
|
|
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: () =>
|
|
66
|
-
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
|
|
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");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"packageManager": "pnpm@10.22.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Core utilities and infrastructure for Socket.dev security tools",
|
|
@@ -151,10 +151,26 @@
|
|
|
151
151
|
"types": "./dist/constants/licenses.d.ts",
|
|
152
152
|
"default": "./dist/constants/licenses.js"
|
|
153
153
|
},
|
|
154
|
+
"./constants/lifecycle-script-names": {
|
|
155
|
+
"types": "./dist/constants/lifecycle-script-names.d.ts",
|
|
156
|
+
"default": "./dist/constants/lifecycle-script-names.js"
|
|
157
|
+
},
|
|
158
|
+
"./constants/maintained-node-versions": {
|
|
159
|
+
"types": "./dist/constants/maintained-node-versions.d.ts",
|
|
160
|
+
"default": "./dist/constants/maintained-node-versions.js"
|
|
161
|
+
},
|
|
154
162
|
"./constants/node": {
|
|
155
163
|
"types": "./dist/constants/node.d.ts",
|
|
156
164
|
"default": "./dist/constants/node.js"
|
|
157
165
|
},
|
|
166
|
+
"./constants/package-default-node-range": {
|
|
167
|
+
"types": "./dist/constants/package-default-node-range.d.ts",
|
|
168
|
+
"default": "./dist/constants/package-default-node-range.js"
|
|
169
|
+
},
|
|
170
|
+
"./constants/package-default-socket-categories": {
|
|
171
|
+
"types": "./dist/constants/package-default-socket-categories.d.ts",
|
|
172
|
+
"default": "./dist/constants/package-default-socket-categories.js"
|
|
173
|
+
},
|
|
158
174
|
"./constants/packages": {
|
|
159
175
|
"types": "./dist/constants/packages.d.ts",
|
|
160
176
|
"default": "./dist/constants/packages.js"
|
|
@@ -203,21 +219,33 @@
|
|
|
203
219
|
"types": "./dist/debug.d.ts",
|
|
204
220
|
"default": "./dist/debug.js"
|
|
205
221
|
},
|
|
206
|
-
"./dlx": {
|
|
207
|
-
"types": "./dist/dlx.d.ts",
|
|
208
|
-
"default": "./dist/dlx.js"
|
|
222
|
+
"./dlx/binary": {
|
|
223
|
+
"types": "./dist/dlx/binary.d.ts",
|
|
224
|
+
"default": "./dist/dlx/binary.js"
|
|
225
|
+
},
|
|
226
|
+
"./dlx/cache": {
|
|
227
|
+
"types": "./dist/dlx/cache.d.ts",
|
|
228
|
+
"default": "./dist/dlx/cache.js"
|
|
229
|
+
},
|
|
230
|
+
"./dlx/dir": {
|
|
231
|
+
"types": "./dist/dlx/dir.d.ts",
|
|
232
|
+
"default": "./dist/dlx/dir.js"
|
|
209
233
|
},
|
|
210
|
-
"./dlx
|
|
211
|
-
"types": "./dist/dlx
|
|
212
|
-
"default": "./dist/dlx
|
|
234
|
+
"./dlx/manifest": {
|
|
235
|
+
"types": "./dist/dlx/manifest.d.ts",
|
|
236
|
+
"default": "./dist/dlx/manifest.js"
|
|
213
237
|
},
|
|
214
|
-
"./dlx
|
|
215
|
-
"types": "./dist/dlx
|
|
216
|
-
"default": "./dist/dlx
|
|
238
|
+
"./dlx/package": {
|
|
239
|
+
"types": "./dist/dlx/package.d.ts",
|
|
240
|
+
"default": "./dist/dlx/package.js"
|
|
217
241
|
},
|
|
218
|
-
"./dlx
|
|
219
|
-
"types": "./dist/dlx
|
|
220
|
-
"default": "./dist/dlx
|
|
242
|
+
"./dlx/packages": {
|
|
243
|
+
"types": "./dist/dlx/packages.d.ts",
|
|
244
|
+
"default": "./dist/dlx/packages.js"
|
|
245
|
+
},
|
|
246
|
+
"./dlx/paths": {
|
|
247
|
+
"types": "./dist/dlx/paths.d.ts",
|
|
248
|
+
"default": "./dist/dlx/paths.js"
|
|
221
249
|
},
|
|
222
250
|
"./effects/pulse-frames": {
|
|
223
251
|
"types": "./dist/effects/pulse-frames.d.ts",
|
|
@@ -355,13 +383,21 @@
|
|
|
355
383
|
"types": "./dist/ipc.d.ts",
|
|
356
384
|
"default": "./dist/ipc.js"
|
|
357
385
|
},
|
|
358
|
-
"./json": {
|
|
359
|
-
"types": "./dist/json.d.ts",
|
|
360
|
-
"default": "./dist/json.js"
|
|
386
|
+
"./json/edit": {
|
|
387
|
+
"types": "./dist/json/edit.d.ts",
|
|
388
|
+
"default": "./dist/json/edit.js"
|
|
389
|
+
},
|
|
390
|
+
"./json/format": {
|
|
391
|
+
"types": "./dist/json/format.d.ts",
|
|
392
|
+
"default": "./dist/json/format.js"
|
|
393
|
+
},
|
|
394
|
+
"./json/parse": {
|
|
395
|
+
"types": "./dist/json/parse.d.ts",
|
|
396
|
+
"default": "./dist/json/parse.js"
|
|
361
397
|
},
|
|
362
|
-
"./
|
|
363
|
-
"types": "./dist/
|
|
364
|
-
"default": "./dist/
|
|
398
|
+
"./json/types": {
|
|
399
|
+
"types": "./dist/json/types.d.ts",
|
|
400
|
+
"default": "./dist/json/types.js"
|
|
365
401
|
},
|
|
366
402
|
"./links": {
|
|
367
403
|
"types": "./dist/links/index.d.ts",
|
|
@@ -375,10 +411,6 @@
|
|
|
375
411
|
"types": "./dist/logger.d.ts",
|
|
376
412
|
"default": "./dist/logger.js"
|
|
377
413
|
},
|
|
378
|
-
"./maintained-node-versions": {
|
|
379
|
-
"types": "./dist/maintained-node-versions.d.ts",
|
|
380
|
-
"default": "./dist/maintained-node-versions.js"
|
|
381
|
-
},
|
|
382
414
|
"./memoization": {
|
|
383
415
|
"types": "./dist/memoization.d.ts",
|
|
384
416
|
"default": "./dist/memoization.js"
|
|
@@ -387,14 +419,6 @@
|
|
|
387
419
|
"types": "./dist/objects.d.ts",
|
|
388
420
|
"default": "./dist/objects.js"
|
|
389
421
|
},
|
|
390
|
-
"./package-default-node-range": {
|
|
391
|
-
"types": "./dist/package-default-node-range.d.ts",
|
|
392
|
-
"default": "./dist/package-default-node-range.js"
|
|
393
|
-
},
|
|
394
|
-
"./package-default-socket-categories": {
|
|
395
|
-
"types": "./dist/package-default-socket-categories.d.ts",
|
|
396
|
-
"default": "./dist/package-default-socket-categories.js"
|
|
397
|
-
},
|
|
398
422
|
"./package-extensions": {
|
|
399
423
|
"types": "./dist/package-extensions.d.ts",
|
|
400
424
|
"default": "./dist/package-extensions.js"
|
|
@@ -403,9 +427,9 @@
|
|
|
403
427
|
"types": "./dist/packages.d.ts",
|
|
404
428
|
"default": "./dist/packages.js"
|
|
405
429
|
},
|
|
406
|
-
"./packages/
|
|
407
|
-
"types": "./dist/packages/
|
|
408
|
-
"default": "./dist/packages/
|
|
430
|
+
"./packages/edit": {
|
|
431
|
+
"types": "./dist/packages/edit.d.ts",
|
|
432
|
+
"default": "./dist/packages/edit.js"
|
|
409
433
|
},
|
|
410
434
|
"./packages/exports": {
|
|
411
435
|
"types": "./dist/packages/exports.d.ts",
|