@socketsecurity/lib 5.18.2 → 5.19.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 +43 -0
- package/README.md +6 -5
- package/dist/abort.d.ts +3 -0
- package/dist/abort.js +1 -0
- package/dist/agent.d.ts +66 -49
- package/dist/agent.js +51 -50
- package/dist/ansi.d.ts +2 -5
- package/dist/ansi.js +3 -2
- package/dist/archives.d.ts +25 -21
- package/dist/archives.js +35 -34
- package/dist/argv/flags.d.ts +100 -91
- package/dist/argv/flags.js +88 -87
- package/dist/argv/parse.d.ts +30 -40
- package/dist/argv/parse.js +33 -32
- package/dist/arrays.d.ts +4 -8
- package/dist/arrays.js +1 -0
- package/dist/bin.d.ts +7 -5
- package/dist/bin.js +52 -29
- package/dist/cacache.d.ts +13 -12
- package/dist/cacache.js +9 -8
- package/dist/cache-with-ttl.d.ts +53 -35
- package/dist/cache-with-ttl.js +1 -0
- package/dist/colors.d.ts +5 -5
- package/dist/colors.js +1 -0
- package/dist/constants/agents.d.ts +5 -9
- package/dist/constants/agents.js +3 -2
- package/dist/constants/core.d.ts +5 -10
- package/dist/constants/core.js +2 -1
- package/dist/constants/encoding.d.ts +3 -3
- package/dist/constants/encoding.js +1 -0
- package/dist/constants/github.d.ts +3 -3
- package/dist/constants/github.js +1 -0
- package/dist/constants/licenses.d.ts +9 -2
- package/dist/constants/licenses.js +1 -0
- package/dist/constants/lifecycle-script-names.js +1 -0
- package/dist/constants/maintained-node-versions.d.ts +3 -0
- package/dist/constants/maintained-node-versions.js +1 -0
- package/dist/constants/node.d.ts +125 -16
- package/dist/constants/node.js +74 -73
- package/dist/constants/package-default-node-range.d.ts +3 -1
- package/dist/constants/package-default-node-range.js +2 -1
- package/dist/constants/package-default-socket-categories.d.ts +0 -1
- package/dist/constants/package-default-socket-categories.js +1 -0
- package/dist/constants/packages.d.ts +12 -17
- package/dist/constants/packages.js +31 -16
- package/dist/constants/platform.d.ts +1 -2
- package/dist/constants/platform.js +2 -1
- package/dist/constants/process.d.ts +18 -0
- package/dist/constants/process.js +1 -0
- package/dist/constants/socket.d.ts +4 -10
- package/dist/constants/socket.js +2 -1
- package/dist/constants/testing.d.ts +3 -3
- package/dist/constants/testing.js +1 -0
- package/dist/constants/time.d.ts +3 -4
- package/dist/constants/time.js +1 -0
- package/dist/constants/typescript.d.ts +10 -3
- package/dist/constants/typescript.js +5 -4
- package/dist/cover/code.d.ts +3 -0
- package/dist/cover/code.js +12 -12
- package/dist/cover/formatters.d.ts +12 -9
- package/dist/cover/formatters.js +19 -18
- package/dist/cover/type.d.ts +3 -0
- package/dist/cover/type.js +1 -0
- package/dist/cover/types.js +1 -0
- package/dist/debug.d.ts +32 -47
- package/dist/debug.js +97 -96
- package/dist/dlx/arborist.d.ts +134 -0
- package/dist/dlx/arborist.js +177 -0
- package/dist/dlx/binary.d.ts +25 -9
- package/dist/dlx/binary.js +34 -12
- package/dist/dlx/cache.d.ts +1 -0
- package/dist/dlx/cache.js +2 -1
- package/dist/dlx/detect.d.ts +15 -0
- package/dist/dlx/detect.js +28 -20
- package/dist/dlx/dir.d.ts +1 -11
- package/dist/dlx/dir.js +2 -12
- package/dist/dlx/integrity.d.ts +86 -0
- package/dist/dlx/integrity.js +112 -0
- package/dist/dlx/lockfile.d.ts +115 -0
- package/dist/dlx/lockfile.js +139 -0
- package/dist/dlx/manifest.d.ts +26 -1
- package/dist/dlx/manifest.js +9 -6
- package/dist/dlx/package.d.ts +58 -3
- package/dist/dlx/package.js +101 -74
- package/dist/dlx/packages.d.ts +1 -11
- package/dist/dlx/packages.js +3 -14
- package/dist/dlx/paths.d.ts +1 -0
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +1 -0
- package/dist/effects/text-shimmer.d.ts +13 -2
- package/dist/effects/text-shimmer.js +50 -46
- package/dist/effects/types.js +1 -0
- package/dist/effects/ultra.js +1 -0
- package/dist/env/ci.d.ts +6 -1
- package/dist/env/ci.js +1 -0
- package/dist/env/debug.d.ts +5 -1
- package/dist/env/debug.js +1 -0
- package/dist/env/github.d.ts +19 -23
- package/dist/env/github.js +5 -4
- package/dist/env/helpers.d.ts +21 -9
- package/dist/env/helpers.js +5 -11
- package/dist/env/home.d.ts +17 -4
- package/dist/env/home.js +2 -1
- package/dist/env/locale.d.ts +4 -3
- package/dist/env/locale.js +1 -0
- package/dist/env/node-auth-token.d.ts +5 -1
- package/dist/env/node-auth-token.js +1 -0
- package/dist/env/node-env.d.ts +5 -1
- package/dist/env/node-env.js +1 -0
- package/dist/env/npm.d.ts +4 -5
- package/dist/env/npm.js +1 -0
- package/dist/env/package-manager.d.ts +4 -3
- package/dist/env/package-manager.js +2 -1
- package/dist/env/path.d.ts +5 -1
- package/dist/env/path.js +1 -0
- package/dist/env/pre-commit.d.ts +5 -1
- package/dist/env/pre-commit.js +1 -0
- package/dist/env/rewire.d.ts +10 -0
- package/dist/env/rewire.js +7 -5
- package/dist/env/shell.d.ts +5 -1
- package/dist/env/shell.js +1 -0
- package/dist/env/socket-cli-shadow.d.ts +4 -5
- package/dist/env/socket-cli-shadow.js +1 -0
- package/dist/env/socket-cli.d.ts +4 -14
- package/dist/env/socket-cli.js +1 -0
- package/dist/env/socket.d.ts +6 -18
- package/dist/env/socket.js +4 -3
- package/dist/env/temp-dir.d.ts +4 -3
- package/dist/env/temp-dir.js +1 -0
- package/dist/env/term.d.ts +5 -1
- package/dist/env/term.js +1 -0
- package/dist/env/test.d.ts +4 -3
- package/dist/env/test.js +1 -0
- package/dist/env/windows.d.ts +4 -4
- package/dist/env/windows.js +1 -0
- package/dist/env/xdg.d.ts +4 -3
- package/dist/env/xdg.js +1 -0
- package/dist/env.d.ts +83 -23
- package/dist/env.js +112 -80
- package/dist/errors.js +1 -0
- package/dist/external/@npmcli/package-json.js +9 -3968
- package/dist/external/@socketregistry/packageurl-js.js +2 -2
- package/dist/external/debug.js +162 -328
- package/dist/external/external-pack.js +3 -2835
- package/dist/external/npm-pack.js +13939 -33342
- package/dist/external/zod.js +160 -7558
- package/dist/fs.d.ts +92 -113
- package/dist/fs.js +35 -35
- package/dist/git.d.ts +170 -164
- package/dist/git.js +113 -87
- package/dist/github.d.ts +249 -227
- package/dist/github.js +82 -81
- package/dist/globs.d.ts +31 -17
- package/dist/globs.js +51 -58
- package/dist/http-request.d.ts +99 -99
- package/dist/http-request.js +182 -156
- package/dist/ipc-cli.d.ts +28 -0
- package/dist/{utils/get-ipc.js → ipc-cli.js} +4 -3
- package/dist/ipc.d.ts +9 -299
- package/dist/ipc.js +18 -204
- package/dist/json/edit.d.ts +3 -1
- package/dist/json/edit.js +30 -30
- package/dist/json/format.d.ts +36 -36
- package/dist/json/format.js +22 -21
- package/dist/json/parse.d.ts +4 -2
- package/dist/json/parse.js +1 -0
- package/dist/json/types.js +1 -0
- package/dist/{links/index.d.ts → links.d.ts} +6 -2
- package/dist/{links/index.js → links.js} +5 -4
- package/dist/logger.d.ts +4 -6
- package/dist/logger.js +61 -53
- package/dist/memoization.d.ts +52 -49
- package/dist/memoization.js +55 -33
- package/dist/objects.d.ts +25 -44
- package/dist/objects.js +2 -1
- package/dist/package-extensions.d.ts +6 -0
- package/dist/package-extensions.js +2 -1
- package/dist/packages/edit.d.ts +3 -5
- package/dist/packages/edit.js +4 -3
- package/dist/packages/exports.d.ts +11 -14
- package/dist/packages/exports.js +11 -10
- package/dist/packages/isolation.d.ts +4 -0
- package/dist/packages/isolation.js +20 -19
- package/dist/packages/licenses.d.ts +3 -10
- package/dist/packages/licenses.js +2 -1
- package/dist/packages/manifest.d.ts +3 -3
- package/dist/packages/manifest.js +1 -0
- package/dist/packages/normalize.d.ts +3 -4
- package/dist/packages/normalize.js +1 -0
- package/dist/packages/operations.d.ts +3 -10
- package/dist/packages/operations.js +1 -0
- package/dist/packages/provenance.d.ts +10 -8
- package/dist/packages/provenance.js +55 -54
- package/dist/packages/specs.d.ts +3 -5
- package/dist/packages/specs.js +1 -0
- package/dist/packages/validation.d.ts +3 -3
- package/dist/packages/validation.js +1 -0
- package/dist/packages.d.ts +2 -17
- package/dist/packages.js +2 -1
- package/dist/paths/dirnames.d.ts +0 -2
- package/dist/paths/dirnames.js +1 -0
- package/dist/paths/exts.d.ts +0 -1
- package/dist/paths/exts.js +1 -0
- package/dist/paths/filenames.d.ts +0 -1
- package/dist/paths/filenames.js +1 -0
- package/dist/paths/globs.d.ts +0 -1
- package/dist/paths/globs.js +1 -0
- package/dist/paths/normalize.d.ts +115 -123
- package/dist/paths/normalize.js +128 -127
- package/dist/paths/packages.d.ts +3 -2
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.d.ts +9 -0
- package/dist/paths/rewire.js +5 -3
- package/dist/paths/socket.d.ts +37 -23
- package/dist/paths/socket.js +26 -25
- package/dist/performance.d.ts +87 -84
- package/dist/performance.js +97 -96
- package/dist/process-lock.d.ts +41 -1
- package/dist/process-lock.js +24 -17
- package/dist/promise-queue.d.ts +6 -0
- package/dist/promise-queue.js +1 -0
- package/dist/promises.d.ts +40 -55
- package/dist/promises.js +12 -11
- package/dist/regexps.d.ts +0 -5
- package/dist/regexps.js +1 -0
- package/dist/releases/github.d.ts +59 -63
- package/dist/releases/github.js +95 -100
- package/dist/releases/socket-btm.d.ts +9 -2
- package/dist/releases/socket-btm.js +32 -25
- package/dist/sea.d.ts +5 -0
- package/dist/sea.js +1 -0
- package/dist/shadow.d.ts +4 -0
- package/dist/shadow.js +1 -0
- package/dist/signal-exit.d.ts +7 -7
- package/dist/signal-exit.js +46 -45
- package/dist/sorts.d.ts +5 -7
- package/dist/sorts.js +11 -10
- package/dist/spawn.d.ts +96 -77
- package/dist/spawn.js +39 -38
- package/dist/spinner.d.ts +21 -22
- package/dist/spinner.js +15 -11
- package/dist/ssri.d.ts +31 -36
- package/dist/ssri.js +15 -14
- package/dist/stdio/_stream.d.ts +31 -0
- package/dist/stdio/_stream.js +57 -0
- package/dist/stdio/divider.d.ts +40 -36
- package/dist/stdio/divider.js +10 -9
- package/dist/stdio/footer.d.ts +20 -0
- package/dist/stdio/footer.js +12 -2
- package/dist/stdio/header.d.ts +4 -16
- package/dist/stdio/header.js +1 -9
- package/dist/stdio/stderr.d.ts +51 -39
- package/dist/stdio/stderr.js +19 -22
- package/dist/stdio/stdout.d.ts +54 -52
- package/dist/stdio/stdout.js +35 -33
- package/dist/streams.d.ts +4 -3
- package/dist/streams.js +1 -0
- package/dist/strings.d.ts +31 -85
- package/dist/strings.js +5 -49
- package/dist/suppress-warnings.d.ts +32 -15
- package/dist/suppress-warnings.js +14 -13
- package/dist/tables.d.ts +30 -26
- package/dist/tables.js +24 -23
- package/dist/temporary-executor.d.ts +4 -0
- package/dist/temporary-executor.js +1 -0
- package/dist/themes/context.d.ts +30 -26
- package/dist/themes/context.js +19 -18
- package/dist/themes/index.d.ts +0 -4
- package/dist/themes/index.js +1 -0
- package/dist/themes/themes.d.ts +1 -1
- package/dist/themes/themes.js +1 -0
- package/dist/themes/types.js +1 -0
- package/dist/themes/utils.d.ts +46 -43
- package/dist/themes/utils.js +45 -44
- package/dist/types.d.ts +48 -52
- package/dist/types.js +35 -35
- package/dist/url.d.ts +48 -53
- package/dist/url.js +38 -37
- package/dist/validation/json-parser.d.ts +19 -190
- package/dist/validation/json-parser.js +5 -69
- package/dist/validation/types.d.ts +9 -33
- package/dist/validation/types.js +1 -0
- package/dist/versions.d.ts +1 -0
- package/dist/versions.js +2 -1
- package/dist/words.d.ts +3 -6
- package/dist/words.js +1 -0
- package/dist/zod.js +1 -0
- package/package.json +34 -66
- package/dist/external/@inquirer/checkbox.js +0 -5
- package/dist/external/@inquirer/confirm.js +0 -5
- package/dist/external/@inquirer/input.js +0 -5
- package/dist/external/@inquirer/password.js +0 -5
- package/dist/external/@inquirer/search.js +0 -5
- package/dist/external/@inquirer/select.js +0 -5
- package/dist/functions.d.ts +0 -57
- package/dist/functions.js +0 -70
- package/dist/stdio/clear.d.ts +0 -140
- package/dist/stdio/clear.js +0 -95
- package/dist/stdio/mask.d.ts +0 -151
- package/dist/stdio/mask.js +0 -224
- package/dist/stdio/progress.d.ts +0 -148
- package/dist/stdio/progress.js +0 -212
- package/dist/stdio/prompts.d.ts +0 -195
- package/dist/stdio/prompts.js +0 -176
- package/dist/utils/get-ipc.d.ts +0 -15
package/dist/performance.d.ts
CHANGED
|
@@ -1,28 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Performance monitoring utilities for profiling and optimization.
|
|
3
|
+
* Provides timing, profiling, and performance metric collection for identifying bottlenecks.
|
|
4
|
+
*/
|
|
1
5
|
/**
|
|
2
6
|
* Performance metrics collected during execution.
|
|
3
7
|
*/
|
|
4
|
-
type PerformanceMetrics = {
|
|
8
|
+
export type PerformanceMetrics = {
|
|
5
9
|
operation: string;
|
|
6
10
|
duration: number;
|
|
7
11
|
timestamp: number;
|
|
8
12
|
metadata?: Record<string, unknown>;
|
|
9
13
|
};
|
|
10
14
|
/**
|
|
11
|
-
*
|
|
12
|
-
* Returns a stop function that records the duration.
|
|
15
|
+
* Clear all collected performance metrics.
|
|
13
16
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { clearPerformanceMetrics } from '@socketsecurity/lib/performance'
|
|
19
|
+
*
|
|
20
|
+
* clearPerformanceMetrics()
|
|
21
|
+
*/
|
|
22
|
+
export declare function clearPerformanceMetrics(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Create a performance report for the current execution.
|
|
25
|
+
* Only available when DEBUG=perf is enabled.
|
|
26
|
+
*
|
|
27
|
+
* @returns Formatted performance report
|
|
17
28
|
*
|
|
18
29
|
* @example
|
|
19
|
-
* import {
|
|
30
|
+
* import { generatePerformanceReport } from '@socketsecurity/lib/performance'
|
|
20
31
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
32
|
+
* console.log(generatePerformanceReport())
|
|
33
|
+
* // ╔═══════════════════════════════════════════════╗
|
|
34
|
+
* // ║ Performance Report ║
|
|
35
|
+
* // ╚═══════════════════════════════════════════════╝
|
|
36
|
+
* //
|
|
37
|
+
* // api-call:
|
|
38
|
+
* // Calls: 5
|
|
39
|
+
* // Avg: 246.8ms
|
|
40
|
+
* // Min: 100ms
|
|
41
|
+
* // Max: 500ms
|
|
42
|
+
* // Total: 1234ms
|
|
24
43
|
*/
|
|
25
|
-
export declare function
|
|
44
|
+
export declare function generatePerformanceReport(): string;
|
|
45
|
+
/**
|
|
46
|
+
* Get all collected performance metrics.
|
|
47
|
+
* Only available when DEBUG=perf is enabled.
|
|
48
|
+
*
|
|
49
|
+
* @returns Array of performance metrics
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* import { getPerformanceMetrics } from '@socketsecurity/lib/performance'
|
|
53
|
+
*
|
|
54
|
+
* const metrics = getPerformanceMetrics()
|
|
55
|
+
* console.log(metrics)
|
|
56
|
+
*/
|
|
57
|
+
export declare function getPerformanceMetrics(): PerformanceMetrics[];
|
|
58
|
+
/**
|
|
59
|
+
* Get performance summary statistics.
|
|
60
|
+
*
|
|
61
|
+
* @returns Summary of metrics grouped by operation
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* import { getPerformanceSummary } from '@socketsecurity/lib/performance'
|
|
65
|
+
*
|
|
66
|
+
* const summary = getPerformanceSummary()
|
|
67
|
+
* console.log(summary)
|
|
68
|
+
* // {
|
|
69
|
+
* // 'api-call': { count: 5, total: 1234, avg: 246.8, min: 100, max: 500 },
|
|
70
|
+
* // 'file-read': { count: 10, total: 50, avg: 5, min: 2, max: 15 }
|
|
71
|
+
* // }
|
|
72
|
+
*/
|
|
73
|
+
export declare function getPerformanceSummary(): Record<string, {
|
|
74
|
+
count: number;
|
|
75
|
+
total: number;
|
|
76
|
+
avg: number;
|
|
77
|
+
min: number;
|
|
78
|
+
max: number;
|
|
79
|
+
}>;
|
|
26
80
|
/**
|
|
27
81
|
* Measure execution time of an async function.
|
|
28
82
|
*
|
|
@@ -63,49 +117,39 @@ export declare function measureSync<T>(operation: string, fn: () => T, metadata?
|
|
|
63
117
|
duration: number;
|
|
64
118
|
};
|
|
65
119
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* @returns Array of performance metrics
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* import { getPerformanceMetrics } from '@socketsecurity/lib/performance'
|
|
120
|
+
* Mark a checkpoint in performance tracking.
|
|
121
|
+
* Useful for tracking progress through complex operations.
|
|
73
122
|
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*/
|
|
77
|
-
export declare function getPerformanceMetrics(): PerformanceMetrics[];
|
|
78
|
-
/**
|
|
79
|
-
* Clear all collected performance metrics.
|
|
123
|
+
* @param checkpoint - Name of the checkpoint
|
|
124
|
+
* @param metadata - Optional metadata
|
|
80
125
|
*
|
|
81
126
|
* @example
|
|
82
|
-
* import {
|
|
127
|
+
* import { perfCheckpoint } from '@socketsecurity/lib/performance'
|
|
83
128
|
*
|
|
84
|
-
*
|
|
129
|
+
* perfCheckpoint('start-scan')
|
|
130
|
+
* // ... do work ...
|
|
131
|
+
* perfCheckpoint('fetch-packages', { count: 50 })
|
|
132
|
+
* // ... do work ...
|
|
133
|
+
* perfCheckpoint('analyze-issues', { issueCount: 10 })
|
|
134
|
+
* perfCheckpoint('end-scan')
|
|
85
135
|
*/
|
|
86
|
-
export declare function
|
|
136
|
+
export declare function perfCheckpoint(checkpoint: string, metadata?: Record<string, unknown>): void;
|
|
87
137
|
/**
|
|
88
|
-
*
|
|
138
|
+
* Start a performance timer for an operation.
|
|
139
|
+
* Returns a stop function that records the duration.
|
|
89
140
|
*
|
|
90
|
-
* @
|
|
141
|
+
* @param operation - Name of the operation being timed
|
|
142
|
+
* @param metadata - Optional metadata to attach to the metric
|
|
143
|
+
* @returns Stop function that completes the timing
|
|
91
144
|
*
|
|
92
145
|
* @example
|
|
93
|
-
* import {
|
|
146
|
+
* import { perfTimer } from '@socketsecurity/lib/performance'
|
|
94
147
|
*
|
|
95
|
-
* const
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* // 'api-call': { count: 5, total: 1234, avg: 246.8, min: 100, max: 500 },
|
|
99
|
-
* // 'file-read': { count: 10, total: 50, avg: 5, min: 2, max: 15 }
|
|
100
|
-
* // }
|
|
148
|
+
* const stop = perfTimer('api-call')
|
|
149
|
+
* await fetchData()
|
|
150
|
+
* stop({ endpoint: '/npm/lodash/score' })
|
|
101
151
|
*/
|
|
102
|
-
export declare function
|
|
103
|
-
count: number;
|
|
104
|
-
total: number;
|
|
105
|
-
avg: number;
|
|
106
|
-
min: number;
|
|
107
|
-
max: number;
|
|
108
|
-
}>;
|
|
152
|
+
export declare function perfTimer(operation: string, metadata?: Record<string, unknown>): (additionalMetadata?: Record<string, unknown>) => void;
|
|
109
153
|
/**
|
|
110
154
|
* Print performance summary to console.
|
|
111
155
|
* Only prints when DEBUG=perf is enabled.
|
|
@@ -119,24 +163,6 @@ export declare function getPerformanceSummary(): Record<string, {
|
|
|
119
163
|
* // file-read: 10 calls, avg 5ms (min 2ms, max 15ms, total 50ms)
|
|
120
164
|
*/
|
|
121
165
|
export declare function printPerformanceSummary(): void;
|
|
122
|
-
/**
|
|
123
|
-
* Mark a checkpoint in performance tracking.
|
|
124
|
-
* Useful for tracking progress through complex operations.
|
|
125
|
-
*
|
|
126
|
-
* @param checkpoint - Name of the checkpoint
|
|
127
|
-
* @param metadata - Optional metadata
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* import { perfCheckpoint } from '@socketsecurity/lib/performance'
|
|
131
|
-
*
|
|
132
|
-
* perfCheckpoint('start-scan')
|
|
133
|
-
* // ... do work ...
|
|
134
|
-
* perfCheckpoint('fetch-packages', { count: 50 })
|
|
135
|
-
* // ... do work ...
|
|
136
|
-
* perfCheckpoint('analyze-issues', { issueCount: 10 })
|
|
137
|
-
* perfCheckpoint('end-scan')
|
|
138
|
-
*/
|
|
139
|
-
export declare function perfCheckpoint(checkpoint: string, metadata?: Record<string, unknown>): void;
|
|
140
166
|
/**
|
|
141
167
|
* Track memory usage at a specific point.
|
|
142
168
|
* Only available when DEBUG=perf is enabled.
|
|
@@ -153,26 +179,3 @@ export declare function perfCheckpoint(checkpoint: string, metadata?: Record<str
|
|
|
153
179
|
* console.log(`Memory increased by ${memAfter - memBefore}MB`)
|
|
154
180
|
*/
|
|
155
181
|
export declare function trackMemory(label: string): number;
|
|
156
|
-
/**
|
|
157
|
-
* Create a performance report for the current execution.
|
|
158
|
-
* Only available when DEBUG=perf is enabled.
|
|
159
|
-
*
|
|
160
|
-
* @returns Formatted performance report
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* import { generatePerformanceReport } from '@socketsecurity/lib/performance'
|
|
164
|
-
*
|
|
165
|
-
* console.log(generatePerformanceReport())
|
|
166
|
-
* // ╔═══════════════════════════════════════════════╗
|
|
167
|
-
* // ║ Performance Report ║
|
|
168
|
-
* // ╚═══════════════════════════════════════════════╝
|
|
169
|
-
* //
|
|
170
|
-
* // api-call:
|
|
171
|
-
* // Calls: 5
|
|
172
|
-
* // Avg: 246.8ms
|
|
173
|
-
* // Min: 100ms
|
|
174
|
-
* // Max: 500ms
|
|
175
|
-
* // Total: 1234ms
|
|
176
|
-
*/
|
|
177
|
-
export declare function generatePerformanceReport(): string;
|
|
178
|
-
export {};
|
package/dist/performance.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -47,25 +48,75 @@ const performanceMetrics = [];
|
|
|
47
48
|
function isPerfEnabled() {
|
|
48
49
|
return import_node_process.default.env["DEBUG"]?.includes("perf") || false;
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
function clearPerformanceMetrics() {
|
|
52
|
+
performanceMetrics.length = 0;
|
|
53
|
+
(0, import_debug.debugLog)("[perf] Cleared performance metrics");
|
|
54
|
+
}
|
|
55
|
+
function generatePerformanceReport() {
|
|
56
|
+
if (!isPerfEnabled() || performanceMetrics.length === 0) {
|
|
57
|
+
return "(no performance data collected - enable with DEBUG=perf)";
|
|
54
58
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const summary = getPerformanceSummary();
|
|
60
|
+
const operations = Object.keys(summary).sort();
|
|
61
|
+
let report = "\n\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\n";
|
|
62
|
+
report += "\u2551 Performance Report \u2551\n";
|
|
63
|
+
report += "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n\n";
|
|
64
|
+
for (const operation of operations) {
|
|
65
|
+
const stats = summary[operation];
|
|
66
|
+
report += `${operation}:
|
|
67
|
+
`;
|
|
68
|
+
report += ` Calls: ${stats.count}
|
|
69
|
+
`;
|
|
70
|
+
report += ` Avg: ${stats.avg}ms
|
|
71
|
+
`;
|
|
72
|
+
report += ` Min: ${stats.min}ms
|
|
73
|
+
`;
|
|
74
|
+
report += ` Max: ${stats.max}ms
|
|
75
|
+
`;
|
|
76
|
+
report += ` Total: ${stats.total}ms
|
|
77
|
+
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
const totalDuration = Object.values(summary).reduce(
|
|
81
|
+
(sum, s) => sum + s.total,
|
|
82
|
+
0
|
|
83
|
+
);
|
|
84
|
+
report += `Total measured time: ${Math.round(totalDuration * 100) / 100}ms
|
|
85
|
+
`;
|
|
86
|
+
return report;
|
|
87
|
+
}
|
|
88
|
+
function getPerformanceMetrics() {
|
|
89
|
+
return [...performanceMetrics];
|
|
90
|
+
}
|
|
91
|
+
function getPerformanceSummary() {
|
|
92
|
+
const summary = { __proto__: null };
|
|
93
|
+
for (const metric of performanceMetrics) {
|
|
94
|
+
const { duration, operation } = metric;
|
|
95
|
+
if (!summary[operation]) {
|
|
96
|
+
summary[operation] = {
|
|
97
|
+
count: 0,
|
|
98
|
+
total: 0,
|
|
99
|
+
min: Number.POSITIVE_INFINITY,
|
|
100
|
+
max: Number.NEGATIVE_INFINITY
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const stats = summary[operation];
|
|
104
|
+
stats.count++;
|
|
105
|
+
stats.total += duration;
|
|
106
|
+
stats.min = Math.min(stats.min, duration);
|
|
107
|
+
stats.max = Math.max(stats.max, duration);
|
|
108
|
+
}
|
|
109
|
+
const result = { __proto__: null };
|
|
110
|
+
for (const { 0: operation, 1: stats } of Object.entries(summary)) {
|
|
111
|
+
result[operation] = {
|
|
112
|
+
count: stats.count,
|
|
113
|
+
total: Math.round(stats.total * 100) / 100,
|
|
114
|
+
avg: Math.round(stats.total / stats.count * 100) / 100,
|
|
115
|
+
min: Math.round(stats.min * 100) / 100,
|
|
116
|
+
max: Math.round(stats.max * 100) / 100
|
|
65
117
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
};
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
69
120
|
}
|
|
70
121
|
async function measure(operation, fn, metadata) {
|
|
71
122
|
const stop = perfTimer(operation, metadata);
|
|
@@ -97,42 +148,38 @@ function measureSync(operation, fn, metadata) {
|
|
|
97
148
|
throw e;
|
|
98
149
|
}
|
|
99
150
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
function clearPerformanceMetrics() {
|
|
104
|
-
performanceMetrics.length = 0;
|
|
105
|
-
(0, import_debug.debugLog)("[perf] Cleared performance metrics");
|
|
106
|
-
}
|
|
107
|
-
function getPerformanceSummary() {
|
|
108
|
-
const summary = /* @__PURE__ */ Object.create(null);
|
|
109
|
-
for (const metric of performanceMetrics) {
|
|
110
|
-
const { duration, operation } = metric;
|
|
111
|
-
if (!summary[operation]) {
|
|
112
|
-
summary[operation] = {
|
|
113
|
-
count: 0,
|
|
114
|
-
total: 0,
|
|
115
|
-
min: Number.POSITIVE_INFINITY,
|
|
116
|
-
max: Number.NEGATIVE_INFINITY
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
const stats = summary[operation];
|
|
120
|
-
stats.count++;
|
|
121
|
-
stats.total += duration;
|
|
122
|
-
stats.min = Math.min(stats.min, duration);
|
|
123
|
-
stats.max = Math.max(stats.max, duration);
|
|
151
|
+
function perfCheckpoint(checkpoint, metadata) {
|
|
152
|
+
if (!isPerfEnabled()) {
|
|
153
|
+
return;
|
|
124
154
|
}
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
const metric = {
|
|
156
|
+
operation: `checkpoint:${checkpoint}`,
|
|
157
|
+
duration: 0,
|
|
158
|
+
timestamp: Date.now(),
|
|
159
|
+
...metadata ? { metadata } : {}
|
|
160
|
+
};
|
|
161
|
+
performanceMetrics.push(metric);
|
|
162
|
+
(0, import_debug.debugLog)(`[perf] [CHECKPOINT] ${checkpoint}`);
|
|
163
|
+
}
|
|
164
|
+
function perfTimer(operation, metadata) {
|
|
165
|
+
if (!isPerfEnabled()) {
|
|
166
|
+
return () => {
|
|
133
167
|
};
|
|
134
168
|
}
|
|
135
|
-
|
|
169
|
+
const start = performance.now();
|
|
170
|
+
(0, import_debug.debugLog)(`[perf] [START] ${operation}`);
|
|
171
|
+
return (additionalMetadata) => {
|
|
172
|
+
const duration = performance.now() - start;
|
|
173
|
+
const metric = {
|
|
174
|
+
operation,
|
|
175
|
+
// Round to 2 decimals
|
|
176
|
+
duration: Math.round(duration * 100) / 100,
|
|
177
|
+
timestamp: Date.now(),
|
|
178
|
+
metadata: { ...metadata, ...additionalMetadata }
|
|
179
|
+
};
|
|
180
|
+
performanceMetrics.push(metric);
|
|
181
|
+
(0, import_debug.debugLog)(`[perf] [END] ${operation} - ${metric.duration}ms`);
|
|
182
|
+
};
|
|
136
183
|
}
|
|
137
184
|
function printPerformanceSummary() {
|
|
138
185
|
if (!isPerfEnabled() || performanceMetrics.length === 0) {
|
|
@@ -149,19 +196,6 @@ function printPerformanceSummary() {
|
|
|
149
196
|
}
|
|
150
197
|
(0, import_debug.debugLog)("[perf] =========================\n");
|
|
151
198
|
}
|
|
152
|
-
function perfCheckpoint(checkpoint, metadata) {
|
|
153
|
-
if (!isPerfEnabled()) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
const metric = {
|
|
157
|
-
operation: `checkpoint:${checkpoint}`,
|
|
158
|
-
duration: 0,
|
|
159
|
-
timestamp: Date.now(),
|
|
160
|
-
...metadata ? { metadata } : {}
|
|
161
|
-
};
|
|
162
|
-
performanceMetrics.push(metric);
|
|
163
|
-
(0, import_debug.debugLog)(`[perf] [CHECKPOINT] ${checkpoint}`);
|
|
164
|
-
}
|
|
165
199
|
function trackMemory(label) {
|
|
166
200
|
if (!isPerfEnabled()) {
|
|
167
201
|
return 0;
|
|
@@ -182,39 +216,6 @@ function trackMemory(label) {
|
|
|
182
216
|
performanceMetrics.push(metric);
|
|
183
217
|
return heapUsedMB;
|
|
184
218
|
}
|
|
185
|
-
function generatePerformanceReport() {
|
|
186
|
-
if (!isPerfEnabled() || performanceMetrics.length === 0) {
|
|
187
|
-
return "(no performance data collected - enable with DEBUG=perf)";
|
|
188
|
-
}
|
|
189
|
-
const summary = getPerformanceSummary();
|
|
190
|
-
const operations = Object.keys(summary).sort();
|
|
191
|
-
let report = "\n\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557\n";
|
|
192
|
-
report += "\u2551 Performance Report \u2551\n";
|
|
193
|
-
report += "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D\n\n";
|
|
194
|
-
for (const operation of operations) {
|
|
195
|
-
const stats = summary[operation];
|
|
196
|
-
report += `${operation}:
|
|
197
|
-
`;
|
|
198
|
-
report += ` Calls: ${stats.count}
|
|
199
|
-
`;
|
|
200
|
-
report += ` Avg: ${stats.avg}ms
|
|
201
|
-
`;
|
|
202
|
-
report += ` Min: ${stats.min}ms
|
|
203
|
-
`;
|
|
204
|
-
report += ` Max: ${stats.max}ms
|
|
205
|
-
`;
|
|
206
|
-
report += ` Total: ${stats.total}ms
|
|
207
|
-
|
|
208
|
-
`;
|
|
209
|
-
}
|
|
210
|
-
const totalDuration = Object.values(summary).reduce(
|
|
211
|
-
(sum, s) => sum + s.total,
|
|
212
|
-
0
|
|
213
|
-
);
|
|
214
|
-
report += `Total measured time: ${Math.round(totalDuration * 100) / 100}ms
|
|
215
|
-
`;
|
|
216
|
-
return report;
|
|
217
|
-
}
|
|
218
219
|
// Annotate the CommonJS export names for ESM import in node:
|
|
219
220
|
0 && (module.exports = {
|
|
220
221
|
clearPerformanceMetrics,
|
package/dist/process-lock.d.ts
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Process locking utilities with stale detection and exit cleanup.
|
|
3
|
+
* Provides cross-platform inter-process synchronization using directory-based locks.
|
|
4
|
+
* Aligned with npm's npx locking strategy (5-second stale timeout, periodic touching).
|
|
5
|
+
*
|
|
6
|
+
* ## Why directories instead of files?
|
|
7
|
+
*
|
|
8
|
+
* This implementation uses `mkdir()` to create lock directories (not files) because:
|
|
9
|
+
*
|
|
10
|
+
* 1. **Atomic guarantee**: `mkdir()` is guaranteed atomic across ALL filesystems,
|
|
11
|
+
* including NFS. Only ONE process can successfully create the directory. If it
|
|
12
|
+
* exists, `mkdir()` fails with EEXIST instantly with no race conditions.
|
|
13
|
+
*
|
|
14
|
+
* 2. **File-based locking issues**:
|
|
15
|
+
* - `writeFile()` with `flag: 'wx'` - atomicity can fail on NFS
|
|
16
|
+
* - `open()` with `O_EXCL` - not guaranteed atomic on older NFS
|
|
17
|
+
* - Traditional lockfiles - can have race conditions on network filesystems
|
|
18
|
+
*
|
|
19
|
+
* 3. **Simplicity**: No need to write/read file content, track PIDs, or manage
|
|
20
|
+
* file descriptors. Just create/delete directory and check mtime.
|
|
21
|
+
*
|
|
22
|
+
* 4. **Historical precedent**: Well-known Unix locking pattern used by package
|
|
23
|
+
* managers for decades. Git uses similar approach for `.git/index.lock`.
|
|
24
|
+
*
|
|
25
|
+
* ## The mtime trick
|
|
26
|
+
*
|
|
27
|
+
* We periodically update the lock directory's mtime (modification time) by
|
|
28
|
+
* "touching" it to signal "I'm still actively working". This prevents other
|
|
29
|
+
* processes from treating the lock as stale and removing it.
|
|
30
|
+
*
|
|
31
|
+
* **The lock directory remains empty** - it's just a sentinel that signals
|
|
32
|
+
* "locked". The mtime is the only data needed to track lock freshness.
|
|
33
|
+
*
|
|
34
|
+
* ## npm npx compatibility
|
|
35
|
+
*
|
|
36
|
+
* This implementation matches npm npx's concurrency.lock approach:
|
|
37
|
+
* - Lock created via `mkdir(path.join(installDir, 'concurrency.lock'))`
|
|
38
|
+
* - 5-second stale timeout (if mtime is older than 5s, lock is stale)
|
|
39
|
+
* - 2-second touching interval (updates mtime every 2s to keep lock fresh)
|
|
40
|
+
* - Automatic cleanup on process exit
|
|
41
|
+
*/
|
|
1
42
|
/**
|
|
2
43
|
* Lock acquisition options.
|
|
3
44
|
*/
|
|
@@ -135,6 +176,5 @@ declare class ProcessLockManager {
|
|
|
135
176
|
*/
|
|
136
177
|
withLock<T>(lockPath: string, fn: () => Promise<T>, options?: ProcessLockOptions): Promise<T>;
|
|
137
178
|
}
|
|
138
|
-
// Export singleton instance.
|
|
139
179
|
export declare const processLock: ProcessLockManager;
|
|
140
180
|
export {};
|
package/dist/process-lock.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -30,12 +31,18 @@ let _fs;
|
|
|
30
31
|
// @__NO_SIDE_EFFECTS__
|
|
31
32
|
function getFs() {
|
|
32
33
|
if (_fs === void 0) {
|
|
33
|
-
_fs = require("fs");
|
|
34
|
+
_fs = require("node:fs");
|
|
34
35
|
}
|
|
35
36
|
return _fs;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
let _path;
|
|
39
|
+
// @__NO_SIDE_EFFECTS__
|
|
40
|
+
function getPath() {
|
|
41
|
+
if (_path === void 0) {
|
|
42
|
+
_path = require("node:path");
|
|
43
|
+
}
|
|
44
|
+
return _path;
|
|
45
|
+
}
|
|
39
46
|
const logger = (0, import_logger.getDefaultLogger)();
|
|
40
47
|
class ProcessLockManager {
|
|
41
48
|
activeLocks = /* @__PURE__ */ new Set();
|
|
@@ -54,9 +61,10 @@ class ProcessLockManager {
|
|
|
54
61
|
clearInterval(timer);
|
|
55
62
|
}
|
|
56
63
|
this.touchTimers.clear();
|
|
64
|
+
const fs = /* @__PURE__ */ getFs();
|
|
57
65
|
for (const lockPath of this.activeLocks) {
|
|
58
66
|
try {
|
|
59
|
-
if (existsSync(lockPath)) {
|
|
67
|
+
if (fs.existsSync(lockPath)) {
|
|
60
68
|
(0, import_fs.safeDeleteSync)(lockPath, { recursive: true });
|
|
61
69
|
}
|
|
62
70
|
} catch {
|
|
@@ -73,9 +81,10 @@ class ProcessLockManager {
|
|
|
73
81
|
*/
|
|
74
82
|
touchLock(lockPath) {
|
|
75
83
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
const fs = /* @__PURE__ */ getFs();
|
|
85
|
+
if (fs.existsSync(lockPath)) {
|
|
86
|
+
const now = Date.now() / 1e3;
|
|
87
|
+
fs.utimesSync(lockPath, now, now);
|
|
79
88
|
}
|
|
80
89
|
} catch (error) {
|
|
81
90
|
logger.warn(
|
|
@@ -123,7 +132,7 @@ class ProcessLockManager {
|
|
|
123
132
|
*/
|
|
124
133
|
isStale(lockPath, staleMs) {
|
|
125
134
|
try {
|
|
126
|
-
const stats = statSync(lockPath, { throwIfNoEntry: false });
|
|
135
|
+
const stats = (/* @__PURE__ */ getFs()).statSync(lockPath, { throwIfNoEntry: false });
|
|
127
136
|
if (!stats) {
|
|
128
137
|
return false;
|
|
129
138
|
}
|
|
@@ -176,17 +185,15 @@ class ProcessLockManager {
|
|
|
176
185
|
} catch {
|
|
177
186
|
}
|
|
178
187
|
}
|
|
179
|
-
|
|
188
|
+
const fs = /* @__PURE__ */ getFs();
|
|
189
|
+
if (fs.existsSync(lockPath)) {
|
|
180
190
|
throw new Error(`Lock already exists: ${lockPath}`);
|
|
181
191
|
}
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
);
|
|
186
|
-
if (lastSlash > 0) {
|
|
187
|
-
mkdirSync(lockPath.slice(0, lastSlash), { recursive: true });
|
|
192
|
+
const parent = (/* @__PURE__ */ getPath()).dirname(lockPath);
|
|
193
|
+
if (parent && parent !== "." && parent !== lockPath) {
|
|
194
|
+
fs.mkdirSync(parent, { recursive: true });
|
|
188
195
|
}
|
|
189
|
-
mkdirSync(lockPath);
|
|
196
|
+
fs.mkdirSync(lockPath);
|
|
190
197
|
this.activeLocks.add(lockPath);
|
|
191
198
|
this.startTouchTimer(lockPath, touchIntervalMs);
|
|
192
199
|
return () => this.release(lockPath);
|
|
@@ -270,7 +277,7 @@ To resolve:
|
|
|
270
277
|
release(lockPath) {
|
|
271
278
|
this.stopTouchTimer(lockPath);
|
|
272
279
|
try {
|
|
273
|
-
if (existsSync(lockPath)) {
|
|
280
|
+
if ((/* @__PURE__ */ getFs()).existsSync(lockPath)) {
|
|
274
281
|
(0, import_fs.safeDeleteSync)(lockPath, { recursive: true });
|
|
275
282
|
}
|
|
276
283
|
this.activeLocks.delete(lockPath);
|
package/dist/promise-queue.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Bounded concurrency promise queue.
|
|
3
|
+
* Exports the `PromiseQueue` class, which limits how many async tasks run
|
|
4
|
+
* simultaneously, supports an optional max queue length (dropping the oldest
|
|
5
|
+
* pending task when exceeded), and exposes an idle-wait helper.
|
|
6
|
+
*/
|
|
1
7
|
export declare class PromiseQueue {
|
|
2
8
|
private queue;
|
|
3
9
|
private running;
|