@socketsecurity/lib 5.25.1 → 5.26.1
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 +344 -1184
- package/README.md +1 -1
- package/dist/abort.js +7 -6
- package/dist/agent.js +16 -15
- package/dist/ansi.js +3 -2
- package/dist/archives.js +18 -17
- package/dist/argv/flags.js +29 -28
- package/dist/argv/parse.js +4 -3
- package/dist/arrays.js +3 -2
- package/dist/bin.js +12 -11
- package/dist/cacache.js +16 -11
- package/dist/cache-with-ttl.js +26 -21
- package/dist/colors.js +2 -1
- package/dist/constants/licenses.js +2 -1
- package/dist/constants/lifecycle-script-names.js +2 -1
- package/dist/constants/maintained-node-versions.js +2 -1
- package/dist/constants/node.js +4 -3
- package/dist/constants/package-default-socket-categories.js +2 -1
- package/dist/constants/packages.js +4 -3
- package/dist/constants/socket.js +1 -1
- package/dist/cover/code.js +9 -8
- package/dist/cover/formatters.js +12 -11
- package/dist/cover/type.js +5 -4
- package/dist/crypto.d.ts +36 -0
- package/dist/{effects/ultra.js → crypto.js} +33 -37
- package/dist/debug.js +12 -15
- package/dist/dlx/arborist.js +10 -9
- package/dist/dlx/binary.js +27 -24
- package/dist/dlx/cache.js +2 -10
- package/dist/dlx/detect.js +6 -5
- package/dist/dlx/integrity.js +13 -11
- package/dist/dlx/lockfile.js +7 -6
- package/dist/dlx/manifest.js +6 -5
- package/dist/dlx/package.js +17 -16
- package/dist/dlx/packages.js +6 -5
- package/dist/dlx/paths.d.ts +1 -1
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +4 -3
- package/dist/effects/shimmer-keyframes.d.ts +62 -0
- package/dist/effects/shimmer-keyframes.js +55 -0
- package/dist/effects/shimmer-terminal.d.ts +66 -0
- package/dist/effects/shimmer-terminal.js +57 -0
- package/dist/effects/shimmer.d.ts +293 -0
- package/dist/effects/shimmer.js +180 -0
- package/dist/env/rewire.js +4 -3
- package/dist/env.js +5 -4
- package/dist/errors.js +1 -1
- package/dist/external/@npmcli/package-json/lib/read-package.js +10 -10
- package/dist/external/@npmcli/package-json.js +372 -372
- package/dist/external/@npmcli/promise-spawn.js +24 -24
- package/dist/external/@socketregistry/packageurl-js.js +19 -18
- package/dist/external/@socketregistry/yocto-spinner.js +4 -3
- package/dist/external/@yarnpkg/extensions.js +2 -1
- package/dist/external/adm-zip.js +70 -70
- package/dist/external/debug.js +22 -22
- package/dist/external/external-pack.js +45 -45
- package/dist/external/fast-sort.js +5 -5
- package/dist/external/libnpmexec.js +4 -3
- package/dist/external/npm-pack.js +369 -369
- package/dist/external/p-map.js +9 -9
- package/dist/external/pico-pack.js +190 -190
- package/dist/external/pony-cause.js +2 -1
- package/dist/external/spdx-pack.js +11 -10
- package/dist/external/tar-fs.js +58 -58
- package/dist/external/which.js +13 -13
- package/dist/external/yargs-parser.js +71 -71
- package/dist/fs.js +19 -23
- package/dist/git.js +14 -13
- package/dist/github.d.ts +34 -0
- package/dist/github.js +248 -23
- package/dist/globs.d.ts +20 -0
- package/dist/globs.js +134 -25
- package/dist/http-request.d.ts +4 -3
- package/dist/http-request.js +39 -32
- package/dist/ipc-cli.js +2 -1
- package/dist/ipc.js +5 -4
- package/dist/json/edit.js +4 -3
- package/dist/json/format.js +3 -2
- package/dist/json/parse.js +7 -6
- package/dist/links.js +2 -1
- package/dist/logger.js +21 -14
- package/dist/memoization.js +16 -15
- package/dist/objects.js +2 -2
- package/dist/packages/edit.js +8 -7
- package/dist/packages/exports.js +17 -16
- package/dist/packages/isolation.js +20 -13
- package/dist/packages/licenses.js +6 -3
- package/dist/packages/manifest.js +2 -1
- package/dist/packages/normalize.js +8 -4
- package/dist/packages/operations.js +5 -4
- package/dist/packages/provenance.js +7 -6
- package/dist/packages/specs.js +2 -1
- package/dist/packages/validation.js +2 -1
- package/dist/paths/normalize.js +32 -40
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.js +3 -2
- package/dist/performance.js +19 -18
- package/dist/primordials.d.ts +9 -0
- package/dist/primordials.js +17 -0
- package/dist/process-lock.js +14 -13
- package/dist/promise-queue.js +17 -9
- package/dist/promises.d.ts +29 -6
- package/dist/promises.js +19 -15
- package/dist/regexps.js +9 -8
- package/dist/releases/github-api.d.ts +56 -0
- package/dist/releases/github-api.js +275 -0
- package/dist/releases/github-archives.d.ts +60 -0
- package/dist/releases/github-archives.js +136 -0
- package/dist/releases/github-assets.d.ts +21 -0
- package/dist/releases/github-assets.js +52 -0
- package/dist/releases/github-auth.d.ts +16 -0
- package/dist/releases/github-auth.js +51 -0
- package/dist/releases/github-downloads.d.ts +42 -0
- package/dist/releases/github-downloads.js +155 -0
- package/dist/releases/github-types.d.ts +66 -0
- package/dist/{effects/types.js → releases/github-types.js} +2 -2
- package/dist/releases/socket-btm.d.ts +1 -1
- package/dist/releases/socket-btm.js +17 -17
- package/dist/schema/parse.js +2 -1
- package/dist/schema/validate.js +6 -5
- package/dist/shadow.js +2 -1
- package/dist/signal-exit.js +2 -2
- package/dist/spawn.js +45 -35
- package/dist/spinner.d.ts +13 -6
- package/dist/spinner.js +75 -57
- package/dist/ssri.js +8 -7
- package/dist/stdio/footer.js +13 -12
- package/dist/stdio/header.js +5 -4
- package/dist/stdio/progress.js +13 -12
- package/dist/strings.js +19 -18
- package/dist/suppress-warnings.js +2 -2
- package/dist/tables.js +16 -13
- package/dist/temporary-executor.js +2 -1
- package/dist/themes/context.js +2 -1
- package/dist/themes/types.d.ts +1 -1
- package/dist/themes/utils.d.ts +8 -3
- package/dist/themes/utils.js +29 -5
- package/dist/url.js +4 -3
- package/package.json +44 -20
- package/dist/effects/text-shimmer.d.ts +0 -58
- package/dist/effects/text-shimmer.js +0 -192
- package/dist/effects/types.d.ts +0 -47
- package/dist/effects/ultra.d.ts +0 -22
- package/dist/releases/github.d.ts +0 -234
- package/dist/releases/github.js +0 -417
- package/dist/themes/index.d.ts +0 -49
- package/dist/themes/index.js +0 -60
package/dist/cache-with-ttl.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(cache_with_ttl_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(cache_with_ttl_exports);
|
|
36
36
|
var cacache = __toESM(require("./cacache"));
|
|
37
|
+
var import_primordials = require("./primordials");
|
|
37
38
|
const DEFAULT_TTL_MS = 5 * 60 * 1e3;
|
|
38
39
|
const DEFAULT_PREFIX = "ttl-cache";
|
|
39
40
|
const DEFAULT_MEMO_MAX_SIZE = 1e3;
|
|
@@ -47,12 +48,12 @@ function createTtlCache(options) {
|
|
|
47
48
|
...options
|
|
48
49
|
};
|
|
49
50
|
if (opts.prefix?.includes("*")) {
|
|
50
|
-
throw new
|
|
51
|
+
throw new import_primordials.TypeErrorCtor(
|
|
51
52
|
'Cache prefix cannot contain wildcards (*). Use clear({ prefix: "pattern*" }) for wildcard matching.'
|
|
52
53
|
);
|
|
53
54
|
}
|
|
54
|
-
const memoCache =
|
|
55
|
-
const memoMaxSize =
|
|
55
|
+
const memoCache = new import_primordials.MapCtor();
|
|
56
|
+
const memoMaxSize = (0, import_primordials.MathMax)(1, opts.memoMaxSize ?? DEFAULT_MEMO_MAX_SIZE);
|
|
56
57
|
function memoSet(fullKey, entry) {
|
|
57
58
|
if (memoCache.has(fullKey)) {
|
|
58
59
|
memoCache.delete(fullKey);
|
|
@@ -69,7 +70,7 @@ function createTtlCache(options) {
|
|
|
69
70
|
return `${opts.prefix}:${key}`;
|
|
70
71
|
}
|
|
71
72
|
function isExpired(entry) {
|
|
72
|
-
const now =
|
|
73
|
+
const now = (0, import_primordials.DateNow)();
|
|
73
74
|
const maxFutureMs = 1e4;
|
|
74
75
|
if (entry.expiresAt > now + ttl + maxFutureMs) {
|
|
75
76
|
return true;
|
|
@@ -80,16 +81,20 @@ function createTtlCache(options) {
|
|
|
80
81
|
const fullPattern = buildKey(pattern);
|
|
81
82
|
const hasWildcard = pattern.includes("*");
|
|
82
83
|
if (!hasWildcard) {
|
|
83
|
-
return (key) =>
|
|
84
|
+
return (key) => (0, import_primordials.StringPrototypeStartsWith)(key, fullPattern);
|
|
84
85
|
}
|
|
85
|
-
const escaped =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
const escaped = (0, import_primordials.StringPrototypeReplaceAll)(
|
|
87
|
+
fullPattern,
|
|
88
|
+
/[.+?^${}()|[\]\\]/g,
|
|
89
|
+
"\\$&"
|
|
90
|
+
);
|
|
91
|
+
const regexPattern = (0, import_primordials.StringPrototypeReplaceAll)(escaped, "*", ".*");
|
|
92
|
+
const regex = new import_primordials.RegExpCtor(`^${regexPattern}$`);
|
|
93
|
+
return (key) => (0, import_primordials.RegExpPrototypeTest)(regex, key);
|
|
89
94
|
}
|
|
90
95
|
async function get(key) {
|
|
91
|
-
if (
|
|
92
|
-
throw new
|
|
96
|
+
if ((0, import_primordials.StringPrototypeIncludes)(key, "*")) {
|
|
97
|
+
throw new import_primordials.TypeErrorCtor(
|
|
93
98
|
"Cache key cannot contain wildcards (*). Use getAll(pattern) to retrieve multiple entries."
|
|
94
99
|
);
|
|
95
100
|
}
|
|
@@ -108,7 +113,7 @@ function createTtlCache(options) {
|
|
|
108
113
|
if (cacheEntry) {
|
|
109
114
|
let entry;
|
|
110
115
|
try {
|
|
111
|
-
entry =
|
|
116
|
+
entry = (0, import_primordials.JSONParse)(cacheEntry.data.toString("utf8"));
|
|
112
117
|
} catch {
|
|
113
118
|
try {
|
|
114
119
|
await cacache.remove(fullKey);
|
|
@@ -130,7 +135,7 @@ function createTtlCache(options) {
|
|
|
130
135
|
return void 0;
|
|
131
136
|
}
|
|
132
137
|
async function getAll(pattern) {
|
|
133
|
-
const results =
|
|
138
|
+
const results = new import_primordials.MapCtor();
|
|
134
139
|
const matches = createMatcher(pattern);
|
|
135
140
|
if (opts.memoize) {
|
|
136
141
|
for (const [key, entry] of memoCache.entries()) {
|
|
@@ -141,7 +146,7 @@ function createTtlCache(options) {
|
|
|
141
146
|
memoCache.delete(key);
|
|
142
147
|
continue;
|
|
143
148
|
}
|
|
144
|
-
const originalKey = opts.prefix ?
|
|
149
|
+
const originalKey = opts.prefix ? (0, import_primordials.StringPrototypeSlice)(key, opts.prefix.length + 1) : key;
|
|
145
150
|
results.set(originalKey, entry.data);
|
|
146
151
|
}
|
|
147
152
|
}
|
|
@@ -164,7 +169,7 @@ function createTtlCache(options) {
|
|
|
164
169
|
if (!entry) {
|
|
165
170
|
continue;
|
|
166
171
|
}
|
|
167
|
-
const parsed =
|
|
172
|
+
const parsed = (0, import_primordials.JSONParse)(
|
|
168
173
|
entry.data.toString("utf8")
|
|
169
174
|
);
|
|
170
175
|
if (isExpired(parsed)) {
|
|
@@ -181,15 +186,15 @@ function createTtlCache(options) {
|
|
|
181
186
|
return results;
|
|
182
187
|
}
|
|
183
188
|
async function set(key, data) {
|
|
184
|
-
if (
|
|
185
|
-
throw new
|
|
189
|
+
if ((0, import_primordials.StringPrototypeIncludes)(key, "*")) {
|
|
190
|
+
throw new import_primordials.TypeErrorCtor(
|
|
186
191
|
'Cache key cannot contain wildcards (*). Wildcards are only supported in clear({ prefix: "pattern*" }).'
|
|
187
192
|
);
|
|
188
193
|
}
|
|
189
194
|
const fullKey = buildKey(key);
|
|
190
195
|
const entry = {
|
|
191
196
|
data,
|
|
192
|
-
expiresAt:
|
|
197
|
+
expiresAt: (0, import_primordials.DateNow)() + ttl
|
|
193
198
|
};
|
|
194
199
|
if (opts.memoize) {
|
|
195
200
|
memoSet(fullKey, entry);
|
|
@@ -201,7 +206,7 @@ function createTtlCache(options) {
|
|
|
201
206
|
} catch {
|
|
202
207
|
}
|
|
203
208
|
}
|
|
204
|
-
const inflightRequests =
|
|
209
|
+
const inflightRequests = new import_primordials.MapCtor();
|
|
205
210
|
async function getOrFetch(key, fetcher) {
|
|
206
211
|
const fullKey = buildKey(key);
|
|
207
212
|
const preexisting = inflightRequests.get(fullKey);
|
|
@@ -229,8 +234,8 @@ function createTtlCache(options) {
|
|
|
229
234
|
return await promise;
|
|
230
235
|
}
|
|
231
236
|
async function deleteEntry(key) {
|
|
232
|
-
if (
|
|
233
|
-
throw new
|
|
237
|
+
if ((0, import_primordials.StringPrototypeIncludes)(key, "*")) {
|
|
238
|
+
throw new import_primordials.TypeErrorCtor(
|
|
234
239
|
"Cache key cannot contain wildcards (*). Use deleteAll(pattern) to remove multiple entries."
|
|
235
240
|
);
|
|
236
241
|
}
|
package/dist/colors.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(colors_exports, {
|
|
|
24
24
|
toRgb: () => toRgb
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(colors_exports);
|
|
27
|
+
var import_primordials = require("./primordials");
|
|
27
28
|
const colorToRgb = {
|
|
28
29
|
__proto__: null,
|
|
29
30
|
black: [0, 0, 0],
|
|
@@ -44,7 +45,7 @@ const colorToRgb = {
|
|
|
44
45
|
yellowBright: [255, 255, 153]
|
|
45
46
|
};
|
|
46
47
|
function isRgbTuple(value) {
|
|
47
|
-
return
|
|
48
|
+
return (0, import_primordials.ArrayIsArray)(value);
|
|
48
49
|
}
|
|
49
50
|
function toRgb(color) {
|
|
50
51
|
if (isRgbTuple(color)) {
|
|
@@ -26,13 +26,14 @@ __export(licenses_exports, {
|
|
|
26
26
|
getCopyLeftLicenses: () => getCopyLeftLicenses
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(licenses_exports);
|
|
29
|
+
var import_primordials = require("../primordials");
|
|
29
30
|
const MIT = "MIT";
|
|
30
31
|
const UNLICENCED = "UNLICENCED";
|
|
31
32
|
const UNLICENSED = "UNLICENSED";
|
|
32
33
|
let _copyLeftLicenses;
|
|
33
34
|
function getCopyLeftLicenses() {
|
|
34
35
|
if (_copyLeftLicenses === void 0) {
|
|
35
|
-
_copyLeftLicenses =
|
|
36
|
+
_copyLeftLicenses = new import_primordials.SetCtor([
|
|
36
37
|
"AGPL-1.0",
|
|
37
38
|
"AGPL-1.0-only",
|
|
38
39
|
"AGPL-1.0-or-later",
|
|
@@ -23,7 +23,8 @@ __export(lifecycle_script_names_exports, {
|
|
|
23
23
|
lifecycleScriptNames: () => lifecycleScriptNames
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(lifecycle_script_names_exports);
|
|
26
|
-
|
|
26
|
+
var import_primordials = require("../primordials");
|
|
27
|
+
const lifecycleScriptNames = new import_primordials.SetCtor(
|
|
27
28
|
[
|
|
28
29
|
"dependencies",
|
|
29
30
|
"prepublishOnly",
|
|
@@ -23,13 +23,14 @@ __export(maintained_node_versions_exports, {
|
|
|
23
23
|
maintainedNodeVersions: () => maintainedNodeVersions
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(maintained_node_versions_exports);
|
|
26
|
+
var import_primordials = require("../primordials");
|
|
26
27
|
const ObjectFreeze = Object.freeze;
|
|
27
28
|
const next = "25.0.0";
|
|
28
29
|
const current = "22.20.0";
|
|
29
30
|
const previous = "20.19.5";
|
|
30
31
|
const last = "18.20.8";
|
|
31
32
|
const maintainedNodeVersions = ObjectFreeze(
|
|
32
|
-
|
|
33
|
+
(0, import_primordials.ObjectAssign)([last, previous, current, next], {
|
|
33
34
|
current,
|
|
34
35
|
last,
|
|
35
36
|
next,
|
package/dist/constants/node.js
CHANGED
|
@@ -54,6 +54,7 @@ __export(node_exports, {
|
|
|
54
54
|
module.exports = __toCommonJS(node_exports);
|
|
55
55
|
var import_node_process = __toESM(require("node:process"));
|
|
56
56
|
var import_maintained_node_versions = require("./maintained-node-versions");
|
|
57
|
+
var import_primordials = require("../primordials");
|
|
57
58
|
const NODE_VERSION = import_node_process.default.version;
|
|
58
59
|
let _nodeDisableSigusr1Flags;
|
|
59
60
|
let _nodeHardenFlags;
|
|
@@ -90,10 +91,10 @@ function getNodeHardenFlags() {
|
|
|
90
91
|
}
|
|
91
92
|
function getNodeMajorVersion() {
|
|
92
93
|
const major = NODE_VERSION.slice(1).split(".")[0] ?? "0";
|
|
93
|
-
return
|
|
94
|
+
return (0, import_primordials.NumberParseInt)(major, 10) || 0;
|
|
94
95
|
}
|
|
95
96
|
function getNodeMinorVersion() {
|
|
96
|
-
return
|
|
97
|
+
return (0, import_primordials.NumberParseInt)(NODE_VERSION.split(".")[1] ?? "0", 10);
|
|
97
98
|
}
|
|
98
99
|
function getNodeNoWarningsFlags() {
|
|
99
100
|
if (_nodeNoWarningsFlags === void 0) {
|
|
@@ -102,7 +103,7 @@ function getNodeNoWarningsFlags() {
|
|
|
102
103
|
return _nodeNoWarningsFlags;
|
|
103
104
|
}
|
|
104
105
|
function getNodePatchVersion() {
|
|
105
|
-
return
|
|
106
|
+
return (0, import_primordials.NumberParseInt)(NODE_VERSION.split(".")[2] ?? "0", 10);
|
|
106
107
|
}
|
|
107
108
|
function getNodePermissionFlags() {
|
|
108
109
|
if (_nodePermissionFlags === void 0) {
|
|
@@ -23,7 +23,8 @@ __export(package_default_socket_categories_exports, {
|
|
|
23
23
|
packageDefaultSocketCategories: () => packageDefaultSocketCategories
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(package_default_socket_categories_exports);
|
|
26
|
-
|
|
26
|
+
var import_primordials = require("../primordials");
|
|
27
|
+
const packageDefaultSocketCategories = (0, import_primordials.ObjectFreeze)(["cleanup"]);
|
|
27
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
29
|
0 && (module.exports = {
|
|
29
30
|
packageDefaultSocketCategories
|
|
@@ -49,6 +49,7 @@ var import_normalize = require("../paths/normalize");
|
|
|
49
49
|
var import_lifecycle_script_names = require("./lifecycle-script-names");
|
|
50
50
|
var import_package_default_node_range = require("./package-default-node-range");
|
|
51
51
|
var import_package_default_socket_categories = require("./package-default-socket-categories");
|
|
52
|
+
var import_primordials = require("../primordials");
|
|
52
53
|
let _lifecycleScriptNames;
|
|
53
54
|
let _packageDefaultNodeRange;
|
|
54
55
|
let _packageDefaultSocketCategories;
|
|
@@ -67,7 +68,7 @@ function clearPackumentCache() {
|
|
|
67
68
|
// @__NO_SIDE_EFFECTS__
|
|
68
69
|
function getLifecycleScriptNames() {
|
|
69
70
|
if (_lifecycleScriptNames === void 0) {
|
|
70
|
-
_lifecycleScriptNames =
|
|
71
|
+
_lifecycleScriptNames = (0, import_primordials.ArrayFrom)(import_lifecycle_script_names.lifecycleScriptNames);
|
|
71
72
|
}
|
|
72
73
|
return _lifecycleScriptNames;
|
|
73
74
|
}
|
|
@@ -88,7 +89,7 @@ function getPackageDefaultSocketCategories() {
|
|
|
88
89
|
// @__NO_SIDE_EFFECTS__
|
|
89
90
|
function getPackageExtensions() {
|
|
90
91
|
if (_packageExtensions === void 0) {
|
|
91
|
-
_packageExtensions =
|
|
92
|
+
_packageExtensions = (0, import_primordials.ObjectEntries)(import_package_extensions.packageExtensions);
|
|
92
93
|
}
|
|
93
94
|
return _packageExtensions;
|
|
94
95
|
}
|
|
@@ -117,7 +118,7 @@ function getPackumentCache() {
|
|
|
117
118
|
function getPacoteCachePath() {
|
|
118
119
|
if (_pacoteCachePath === void 0) {
|
|
119
120
|
try {
|
|
120
|
-
const proto =
|
|
121
|
+
const proto = (0, import_primordials.ReflectGetPrototypeOf)(
|
|
121
122
|
import_pacote.default.RegistryFetcher.prototype
|
|
122
123
|
);
|
|
123
124
|
const PacoteFetcherBase = proto?.constructor;
|
package/dist/constants/socket.js
CHANGED
|
@@ -77,7 +77,7 @@ const SOCKET_FIREWALL_APP_NAME = "sfw";
|
|
|
77
77
|
const SOCKET_REGISTRY_APP_NAME = "registry";
|
|
78
78
|
const SOCKET_APP_PREFIX = "_";
|
|
79
79
|
const SOCKET_LIB_NAME = "@socketsecurity/lib";
|
|
80
|
-
const SOCKET_LIB_VERSION = "5.
|
|
80
|
+
const SOCKET_LIB_VERSION = "5.26.1";
|
|
81
81
|
const SOCKET_LIB_URL = "https://github.com/SocketDev/socket-lib";
|
|
82
82
|
const SOCKET_LIB_USER_AGENT = `socketsecurity-lib/${SOCKET_LIB_VERSION} (${SOCKET_LIB_URL})`;
|
|
83
83
|
const SOCKET_IPC_HANDSHAKE = "SOCKET_IPC_HANDSHAKE";
|
package/dist/cover/code.js
CHANGED
|
@@ -37,6 +37,7 @@ var import_node_process = __toESM(require("node:process"));
|
|
|
37
37
|
var import_fs = require("../fs");
|
|
38
38
|
var import_objects = require("../objects");
|
|
39
39
|
var import_spawn = require("../spawn");
|
|
40
|
+
var import_primordials = require("../primordials");
|
|
40
41
|
let _fs;
|
|
41
42
|
let _path;
|
|
42
43
|
function calculateMetric(data) {
|
|
@@ -71,7 +72,7 @@ async function getCodeCoverage(options) {
|
|
|
71
72
|
};
|
|
72
73
|
const { coveragePath, generateIfMissing } = opts;
|
|
73
74
|
if (!coveragePath) {
|
|
74
|
-
throw new
|
|
75
|
+
throw new import_primordials.ErrorCtor("Coverage path is required");
|
|
75
76
|
}
|
|
76
77
|
const fs = /* @__PURE__ */ getFs();
|
|
77
78
|
if (!fs.existsSync(coveragePath)) {
|
|
@@ -81,14 +82,14 @@ async function getCodeCoverage(options) {
|
|
|
81
82
|
stdio: "inherit"
|
|
82
83
|
});
|
|
83
84
|
} else {
|
|
84
|
-
throw new
|
|
85
|
+
throw new import_primordials.ErrorCtor(
|
|
85
86
|
`Coverage file not found at "${coveragePath}". Run tests with coverage first.`
|
|
86
87
|
);
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
const coverageData = await (0, import_fs.readJson)(coveragePath);
|
|
90
91
|
if (!(0, import_objects.isObjectObject)(coverageData)) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new import_primordials.ErrorCtor(`Invalid coverage data format in "${coveragePath}"`);
|
|
92
93
|
}
|
|
93
94
|
const totals = {
|
|
94
95
|
__proto__: null,
|
|
@@ -98,13 +99,13 @@ async function getCodeCoverage(options) {
|
|
|
98
99
|
statements: { __proto__: null, covered: 0, total: 0 }
|
|
99
100
|
};
|
|
100
101
|
const v8Data = coverageData;
|
|
101
|
-
for (const fileCoverage of
|
|
102
|
+
for (const fileCoverage of (0, import_primordials.ObjectValues)(v8Data)) {
|
|
102
103
|
if (!(0, import_objects.isObjectObject)(fileCoverage)) {
|
|
103
104
|
continue;
|
|
104
105
|
}
|
|
105
106
|
const fc = fileCoverage;
|
|
106
107
|
if (fc.s && (0, import_objects.isObjectObject)(fc.s)) {
|
|
107
|
-
const statementCounts =
|
|
108
|
+
const statementCounts = (0, import_primordials.ObjectValues)(fc.s);
|
|
108
109
|
for (const count of statementCounts) {
|
|
109
110
|
if (typeof count === "number") {
|
|
110
111
|
totals.statements.total += 1;
|
|
@@ -115,9 +116,9 @@ async function getCodeCoverage(options) {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
if (fc.b && (0, import_objects.isObjectObject)(fc.b)) {
|
|
118
|
-
const branchCounts =
|
|
119
|
+
const branchCounts = (0, import_primordials.ObjectValues)(fc.b);
|
|
119
120
|
for (const branches of branchCounts) {
|
|
120
|
-
if (
|
|
121
|
+
if ((0, import_primordials.ArrayIsArray)(branches)) {
|
|
121
122
|
for (const count of branches) {
|
|
122
123
|
if (typeof count === "number") {
|
|
123
124
|
totals.branches.total += 1;
|
|
@@ -130,7 +131,7 @@ async function getCodeCoverage(options) {
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
if (fc.f && (0, import_objects.isObjectObject)(fc.f)) {
|
|
133
|
-
const functionCounts =
|
|
134
|
+
const functionCounts = (0, import_primordials.ObjectValues)(fc.f);
|
|
134
135
|
for (const count of functionCounts) {
|
|
135
136
|
if (typeof count === "number") {
|
|
136
137
|
totals.functions.total += 1;
|
package/dist/cover/formatters.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(formatters_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(formatters_exports);
|
|
27
27
|
var import_strings = require("../strings");
|
|
28
|
+
var import_primordials = require("../primordials");
|
|
28
29
|
const COVERAGE_EMOJI_THRESHOLDS = [
|
|
29
30
|
{ emoji: " \u{1F680}", threshold: 99 },
|
|
30
31
|
{ emoji: " \u{1F3AF}", threshold: 95 },
|
|
@@ -38,17 +39,17 @@ const COVERAGE_EMOJI_THRESHOLDS = [
|
|
|
38
39
|
];
|
|
39
40
|
function calculateOverall(code, type) {
|
|
40
41
|
const metrics = [
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
].map((val) =>
|
|
42
|
+
(0, import_primordials.NumberParseFloat)(code.statements.percent),
|
|
43
|
+
(0, import_primordials.NumberParseFloat)(code.branches.percent),
|
|
44
|
+
(0, import_primordials.NumberParseFloat)(code.functions.percent),
|
|
45
|
+
(0, import_primordials.NumberParseFloat)(code.lines.percent)
|
|
46
|
+
].map((val) => (0, import_primordials.NumberIsNaN)(val) ? 0 : val);
|
|
46
47
|
if (type) {
|
|
47
|
-
const typePercent =
|
|
48
|
-
metrics.push(
|
|
48
|
+
const typePercent = (0, import_primordials.NumberParseFloat)(type.percent);
|
|
49
|
+
metrics.push((0, import_primordials.NumberIsNaN)(typePercent) ? 0 : typePercent);
|
|
49
50
|
}
|
|
50
51
|
const average = metrics.reduce((sum, val) => sum + val, 0) / metrics.length;
|
|
51
|
-
return
|
|
52
|
+
return (0, import_primordials.NumberPrototypeToFixed)(average, 2);
|
|
52
53
|
}
|
|
53
54
|
function formatCoverage(options) {
|
|
54
55
|
const opts = {
|
|
@@ -58,7 +59,7 @@ function formatCoverage(options) {
|
|
|
58
59
|
};
|
|
59
60
|
const { code, format, type } = opts;
|
|
60
61
|
if (format === "json") {
|
|
61
|
-
return
|
|
62
|
+
return (0, import_primordials.JSONStringify)({ code, type }, null, 2);
|
|
62
63
|
}
|
|
63
64
|
const overall = calculateOverall(code, type);
|
|
64
65
|
if (format === "simple") {
|
|
@@ -86,8 +87,8 @@ function formatCoverage(options) {
|
|
|
86
87
|
{ count: 2 }
|
|
87
88
|
);
|
|
88
89
|
}
|
|
89
|
-
const overallValue =
|
|
90
|
-
const emoji = getCoverageEmoji(
|
|
90
|
+
const overallValue = (0, import_primordials.NumberParseFloat)(overall);
|
|
91
|
+
const emoji = getCoverageEmoji((0, import_primordials.NumberIsNaN)(overallValue) ? 0 : overallValue);
|
|
91
92
|
output += `
|
|
92
93
|
Overall: ${overall}%${emoji}
|
|
93
94
|
`;
|
package/dist/cover/type.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(type_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(type_exports);
|
|
36
36
|
var import_node_process = __toESM(require("node:process"));
|
|
37
37
|
var import_spawn = require("../spawn");
|
|
38
|
+
var import_primordials = require("../primordials");
|
|
38
39
|
async function getTypeCoverage(options) {
|
|
39
40
|
const opts = {
|
|
40
41
|
__proto__: null,
|
|
@@ -44,7 +45,7 @@ async function getTypeCoverage(options) {
|
|
|
44
45
|
};
|
|
45
46
|
const { cwd, generateIfMissing } = opts;
|
|
46
47
|
if (!cwd) {
|
|
47
|
-
throw new
|
|
48
|
+
throw new import_primordials.ErrorCtor("Working directory is required.");
|
|
48
49
|
}
|
|
49
50
|
try {
|
|
50
51
|
const result = await (0, import_spawn.spawn)("type-coverage", ["--detail"], {
|
|
@@ -57,13 +58,13 @@ async function getTypeCoverage(options) {
|
|
|
57
58
|
return null;
|
|
58
59
|
}
|
|
59
60
|
return {
|
|
60
|
-
covered:
|
|
61
|
+
covered: (0, import_primordials.NumberParseInt)(match[1], 10),
|
|
61
62
|
percent: match[3],
|
|
62
|
-
total:
|
|
63
|
+
total: (0, import_primordials.NumberParseInt)(match[2], 10)
|
|
63
64
|
};
|
|
64
65
|
} catch (e) {
|
|
65
66
|
if (generateIfMissing) {
|
|
66
|
-
throw new
|
|
67
|
+
throw new import_primordials.ErrorCtor(
|
|
67
68
|
"Unable to generate type coverage. Ensure type-coverage is installed.",
|
|
68
69
|
{ cause: e }
|
|
69
70
|
);
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Crypto helpers that prefer Node builtins where available.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Resolve `crypto.hash` (or `undefined` if the runtime predates it).
|
|
6
|
+
*
|
|
7
|
+
* Exported for unit tests; not part of the public API.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function getNativeHash(): typeof import('node:crypto').hash | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Compute a one-shot cryptographic hash.
|
|
14
|
+
*
|
|
15
|
+
* Prefers Node's `crypto.hash(algorithm, data, outputEncoding)` (added
|
|
16
|
+
* v21.7.0 / v20.12.0), which is ~30% faster than the
|
|
17
|
+
* `createHash().update().digest()` chain on small-to-medium inputs
|
|
18
|
+
* because it skips constructing the streaming `Hash` object. Falls
|
|
19
|
+
* back to that chain on older runtimes.
|
|
20
|
+
*
|
|
21
|
+
* Use this only for the one-shot case where the entire input is
|
|
22
|
+
* available as a single buffer or string; if you need to feed chunks,
|
|
23
|
+
* stay on `createHash()`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { hash } from '@socketsecurity/lib/crypto'
|
|
28
|
+
*
|
|
29
|
+
* hash('sha256', 'hello', 'hex')
|
|
30
|
+
* // '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
|
|
31
|
+
*
|
|
32
|
+
* hash('sha512', someBuffer, 'base64')
|
|
33
|
+
* // 'z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=='
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function hash(algorithm: string, data: string | NodeJS.ArrayBufferView, outputEncoding: 'hex' | 'base64' | 'base64url' | 'binary'): string;
|
|
@@ -18,47 +18,43 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
var crypto_exports = {};
|
|
22
|
+
__export(crypto_exports, {
|
|
23
|
+
getNativeHash: () => getNativeHash,
|
|
24
|
+
hash: () => hash
|
|
25
25
|
});
|
|
26
|
-
module.exports = __toCommonJS(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
[140, 120, 220],
|
|
44
|
-
// Pink/magenta.
|
|
45
|
-
[200, 100, 200],
|
|
46
|
-
// Red/pink.
|
|
47
|
-
[255, 100, 140]
|
|
48
|
-
];
|
|
49
|
-
function generateRainbowGradient(textLength) {
|
|
50
|
-
const colors = [];
|
|
51
|
-
for (let i = 0; i < textLength; i += 1) {
|
|
52
|
-
const colorIndex = i % RAINBOW_GRADIENT.length;
|
|
53
|
-
const color = RAINBOW_GRADIENT[colorIndex];
|
|
54
|
-
if (color) {
|
|
55
|
-
colors.push(color);
|
|
26
|
+
module.exports = __toCommonJS(crypto_exports);
|
|
27
|
+
let _crypto;
|
|
28
|
+
let _hash;
|
|
29
|
+
let _hashProbed = false;
|
|
30
|
+
// @__NO_SIDE_EFFECTS__
|
|
31
|
+
function getCrypto() {
|
|
32
|
+
if (_crypto === void 0) {
|
|
33
|
+
_crypto = require("node:crypto");
|
|
34
|
+
}
|
|
35
|
+
return _crypto;
|
|
36
|
+
}
|
|
37
|
+
// @__NO_SIDE_EFFECTS__
|
|
38
|
+
function getNativeHash() {
|
|
39
|
+
if (!_hashProbed) {
|
|
40
|
+
const fn = (/* @__PURE__ */ getCrypto()).hash;
|
|
41
|
+
if (typeof fn === "function") {
|
|
42
|
+
_hash = fn;
|
|
56
43
|
}
|
|
44
|
+
_hashProbed = true;
|
|
45
|
+
}
|
|
46
|
+
return _hash;
|
|
47
|
+
}
|
|
48
|
+
// @__NO_SIDE_EFFECTS__
|
|
49
|
+
function hash(algorithm, data, outputEncoding) {
|
|
50
|
+
const native = /* @__PURE__ */ getNativeHash();
|
|
51
|
+
if (native !== void 0) {
|
|
52
|
+
return native(algorithm, data, outputEncoding);
|
|
57
53
|
}
|
|
58
|
-
return
|
|
54
|
+
return (/* @__PURE__ */ getCrypto()).createHash(algorithm).update(data).digest(outputEncoding);
|
|
59
55
|
}
|
|
60
56
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
57
|
0 && (module.exports = {
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
getNativeHash,
|
|
59
|
+
hash
|
|
64
60
|
});
|
package/dist/debug.js
CHANGED
|
@@ -54,7 +54,7 @@ var import_primordials = require("./primordials");
|
|
|
54
54
|
var import_spinner = require("./spinner");
|
|
55
55
|
var import_strings = require("./strings");
|
|
56
56
|
const logger = (0, import_logger.getDefaultLogger)();
|
|
57
|
-
const debugByNamespace =
|
|
57
|
+
const debugByNamespace = new import_primordials.MapCtor();
|
|
58
58
|
let _util;
|
|
59
59
|
let pointingTriangle;
|
|
60
60
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -94,11 +94,8 @@ function getCallerInfo(stackOffset = 3) {
|
|
|
94
94
|
const match = /(?<=^at\s+).*?(?=\s+\(|$)/.exec(line)?.[0];
|
|
95
95
|
if (match) {
|
|
96
96
|
name = match.replace(/^(?:async|bound|get|new|set)\s+/, "");
|
|
97
|
-
if (
|
|
98
|
-
const afterDot =
|
|
99
|
-
7
|
|
100
|
-
/*'Object.'.length*/
|
|
101
|
-
);
|
|
97
|
+
if ((0, import_primordials.StringPrototypeStartsWith)(name, "Object.")) {
|
|
98
|
+
const afterDot = (0, import_primordials.StringPrototypeSlice)(name, 7);
|
|
102
99
|
if (!(0, import_objects.hasOwn)(Object, afterDot)) {
|
|
103
100
|
name = afterDot;
|
|
104
101
|
}
|
|
@@ -145,7 +142,7 @@ function isEnabled(namespaces) {
|
|
|
145
142
|
const names = [];
|
|
146
143
|
const skips = [];
|
|
147
144
|
for (const ns of split) {
|
|
148
|
-
if (
|
|
145
|
+
if ((0, import_primordials.StringPrototypeStartsWith)(ns, "-")) {
|
|
149
146
|
skips.push(ns.slice(1));
|
|
150
147
|
} else {
|
|
151
148
|
names.push(ns);
|
|
@@ -242,13 +239,13 @@ function debugLogNs(namespacesOrOpts, ...args) {
|
|
|
242
239
|
const supported = (0, import_is_unicode_supported.default)();
|
|
243
240
|
pointingTriangle = supported ? "\u25B8" : ">";
|
|
244
241
|
}
|
|
245
|
-
const text =
|
|
242
|
+
const text = (0, import_primordials.ArrayPrototypeAt)(args, 0);
|
|
246
243
|
const logArgs = typeof text === "string" ? [
|
|
247
244
|
(0, import_strings.applyLinePrefix)(
|
|
248
245
|
`${callerName ? `${callerName} ${pointingTriangle} ` : ""}${text}`,
|
|
249
246
|
{ prefix: "[DEBUG] " }
|
|
250
247
|
),
|
|
251
|
-
...
|
|
248
|
+
...(0, import_primordials.ArrayPrototypeSlice)(args, 1)
|
|
252
249
|
] : [`[DEBUG] ${callerName} ${pointingTriangle}`, ...args];
|
|
253
250
|
const spinnerInstance = options.spinner || (0, import_spinner.getDefaultSpinner)();
|
|
254
251
|
const wasSpinning = spinnerInstance?.isSpinning;
|
|
@@ -274,13 +271,13 @@ function debugNs(namespacesOrOpts, ...args) {
|
|
|
274
271
|
const supported = (0, import_is_unicode_supported.default)();
|
|
275
272
|
pointingTriangle = supported ? "\u25B8" : ">";
|
|
276
273
|
}
|
|
277
|
-
const text =
|
|
274
|
+
const text = (0, import_primordials.ArrayPrototypeAt)(args, 0);
|
|
278
275
|
const logArgs = typeof text === "string" ? [
|
|
279
276
|
(0, import_strings.applyLinePrefix)(
|
|
280
277
|
`${name ? `${name} ${pointingTriangle} ` : ""}${text}`,
|
|
281
278
|
{ prefix: "[DEBUG] " }
|
|
282
279
|
),
|
|
283
|
-
...
|
|
280
|
+
...(0, import_primordials.ArrayPrototypeSlice)(args, 1)
|
|
284
281
|
] : args;
|
|
285
282
|
const spinnerInstance = options.spinner || (0, import_spinner.getDefaultSpinner)();
|
|
286
283
|
const wasSpinning = spinnerInstance?.isSpinning;
|
|
@@ -296,19 +293,19 @@ function debugtime(label) {
|
|
|
296
293
|
let startTime;
|
|
297
294
|
const impl = () => {
|
|
298
295
|
if (startTime === void 0) {
|
|
299
|
-
startTime =
|
|
296
|
+
startTime = (0, import_primordials.DateNow)();
|
|
300
297
|
} else {
|
|
301
|
-
const duration =
|
|
298
|
+
const duration = (0, import_primordials.DateNow)() - startTime;
|
|
302
299
|
util.debuglog("time")(`${label}: ${duration}ms`);
|
|
303
300
|
startTime = void 0;
|
|
304
301
|
}
|
|
305
302
|
};
|
|
306
303
|
impl.start = () => {
|
|
307
|
-
startTime =
|
|
304
|
+
startTime = (0, import_primordials.DateNow)();
|
|
308
305
|
};
|
|
309
306
|
impl.end = () => {
|
|
310
307
|
if (startTime !== void 0) {
|
|
311
|
-
const duration =
|
|
308
|
+
const duration = (0, import_primordials.DateNow)() - startTime;
|
|
312
309
|
util.debuglog("time")(`${label}: ${duration}ms`);
|
|
313
310
|
startTime = void 0;
|
|
314
311
|
}
|