@socketsecurity/lib 5.27.0 → 5.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [5.28.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.28.0) - 2026-05-06
9
+
10
+ ### Added
11
+
12
+ - **`compression` (new export)** — brotli + gzip helpers with three calling shapes (in-memory `Buffer`, file-to-file, raw streams) and a single `{ inPlace: true }` option for compress/decompress-in-place. 28 named exports total:
13
+ - In-memory: `compressBrotli`, `decompressBrotli`, `compressGzip`, `decompressGzip`
14
+ - File-to-file: `compressBrotliFile`, `decompressBrotliFile`, `compressGzipFile`, `decompressGzipFile` — each with three overloads (explicit dest, in-place, options object). The gzip in-place path follows `.tgz` → `.tar` convention so a round-trip is lossless
15
+ - Streams: `createBrotliCompressor`, `createBrotliDecompressor`, `createGzipCompressor`, `createGzipDecompressor`
16
+ - Detection: `isBrotliCompressed(buffer)` / `isGzipCompressed(buffer)` (magic-byte sniffing)
17
+ - Path classification: `hasBrotliExt(filePath)` / `hasGzipExt(filePath)` — case-insensitive `path.extname` match against `.br` / `.brotli` / `.gz` / `.gzip` / `.tgz`
18
+ - Helpers: `BROTLI_EXTS` / `GZIP_EXTS` `ReadonlySet<string>` constants; `stripExt(filePath, exts)` for trimming a recognized extension from a path; `resolveBrotliOptions` / `resolveGzipOptions` for translating `CompressOptions` into the underlying zlib option shapes
19
+ - `CompressOptions` / `CompressFileOptions` interfaces
20
+ - **`socket-lib` CLI (new `bin` entry)** — fleet-wide static-analysis dispatcher invoked via `pnpm exec socket-lib <command>`. Initial subcommand: `check primordials` (alias `check prim`) — diffs every name destructured from `primordials` in scanned source against `@socketsecurity/lib`'s exposed primordials set, emitting unmapped or missing-from-lib findings. Reads sectional config from `.socket-lib.json` (with `.config/socket-lib.json` as a fallback) or a bare object for single-check setups. Flags: `--config / -c <path>` (defaults to `.socket-lib.json`, falls back to `.config/socket-lib.json`), `--explain`, `--json`, `--silent`, `--help`. Lifted from socket-btm's `scripts/check-primordials-coverage.mts` so the same drift gate now ships to every consumer.
21
+ - **`dlx/package` `installRoot` option** — new `EnsurePackageInstallOptions` (and `DlxPackageOptions`) field overriding the install root passed to Arborist. Default remains `~/.socket/_dlx/<cacheKey>/`; when set, the value is used verbatim. Lets build pipelines colocate the install with their own gitignored outputs (e.g. ink-builder bundling ink via esbuild). Caller owns per-spec separation; see JSDoc for the full contract.
22
+
8
23
  ## [5.27.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.27.0) - 2026-05-04
9
24
 
10
25
  ### Added
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Socket Badge](https://socket.dev/api/badge/npm/package/@socketsecurity/lib)](https://socket.dev/npm/package/@socketsecurity/lib)
4
4
  [![CI](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml/badge.svg)](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml)
5
- ![Coverage](https://img.shields.io/badge/coverage-84%25-brightgreen)
5
+ ![Coverage](https://img.shields.io/badge/coverage-85%25-brightgreen)
6
6
 
7
7
  [![Follow @SocketSecurity](https://img.shields.io/twitter/follow/SocketSecurity?style=social)](https://twitter.com/SocketSecurity)
8
8
  [![Follow @socket.dev on Bluesky](https://img.shields.io/badge/Follow-@socket.dev-1DA1F2?style=social&logo=bluesky)](https://bsky.app/profile/socket.dev)
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview `socket-lib check primordials` handler.
3
+ *
4
+ * Loads a JSON config from disk (default
5
+ * `primordials-coverage.config.json` at the repo root, override with
6
+ * `--config <path>`), runs the drift check, and renders the result.
7
+ *
8
+ * socket-lib check primordials
9
+ * socket-lib check primordials --config ./primordials.config.json
10
+ * socket-lib check primordials --json # machine-readable output
11
+ * socket-lib check primordials --explain # one detailed line per finding
12
+ * socket-lib check primordials --silent # silent on success
13
+ *
14
+ * Exit codes:
15
+ * 0 — no drift
16
+ * 1 — drift detected (or config / lookup error)
17
+ */
18
+ export declare function runCheckPrimordials(argv: readonly string[]): Promise<number>;
@@ -0,0 +1,229 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+ var check_primordials_exports = {};
32
+ __export(check_primordials_exports, {
33
+ runCheckPrimordials: () => runCheckPrimordials
34
+ });
35
+ module.exports = __toCommonJS(check_primordials_exports);
36
+ var import_node_fs = require("node:fs");
37
+ var import_node_path = __toESM(require("node:path"));
38
+ var import_node_process = __toESM(require("node:process"));
39
+ var import_errors = require("../errors");
40
+ var import_logger = require("../logger");
41
+ var import_primordials = require("../checks/primordials");
42
+ var import_parse = require("../argv/parse");
43
+ const logger = (0, import_logger.getDefaultLogger)();
44
+ const DEFAULT_CONFIG_PATH = ".socket-lib.json";
45
+ const FALLBACK_CONFIG_PATHS = [
46
+ ".socket-lib.json",
47
+ ".config/socket-lib.json"
48
+ ];
49
+ const CONFIG_SECTION = "primordials";
50
+ function parseArgs(argv) {
51
+ const { values } = (0, import_parse.parseArgs)({
52
+ args: argv,
53
+ strict: false,
54
+ options: {
55
+ config: { type: "string", short: "c" },
56
+ explain: { type: "boolean" },
57
+ help: { type: "boolean", short: "h" },
58
+ json: { type: "boolean" },
59
+ silent: { type: "boolean" }
60
+ }
61
+ });
62
+ const explicitConfig = values["config"];
63
+ return {
64
+ config: typeof explicitConfig === "string" ? explicitConfig : void 0,
65
+ json: Boolean(values["json"]),
66
+ explain: Boolean(values["explain"]),
67
+ silent: Boolean(values["silent"]),
68
+ help: Boolean(values["help"])
69
+ };
70
+ }
71
+ function resolveConfigPath(explicit) {
72
+ if (explicit !== void 0) {
73
+ return explicit;
74
+ }
75
+ for (const candidate of FALLBACK_CONFIG_PATHS) {
76
+ if ((0, import_node_fs.existsSync)(import_node_path.default.resolve(candidate))) {
77
+ return candidate;
78
+ }
79
+ }
80
+ return FALLBACK_CONFIG_PATHS[0];
81
+ }
82
+ function printHelp() {
83
+ logger.log("socket-lib check primordials \u2014 primordials drift check");
84
+ logger.log("");
85
+ logger.log("Usage:");
86
+ logger.log(" socket-lib check primordials [opts]");
87
+ logger.log(" socket-lib check prim [opts] # short alias");
88
+ logger.log("");
89
+ logger.log("Options:");
90
+ logger.log(
91
+ ` --config, -c <path> Config file. Default: ${DEFAULT_CONFIG_PATH}`
92
+ );
93
+ logger.log(` (falls back to .config/socket-lib.json)`);
94
+ logger.log(" --explain Print one detailed line per finding.");
95
+ logger.log(" --json Machine-readable JSON output.");
96
+ logger.log(" --silent Silent on success.");
97
+ logger.log(" --help, -h Print this help.");
98
+ logger.log("");
99
+ logger.log("Config (.socket-lib.json \u2014 primordials section):");
100
+ logger.log(" {");
101
+ logger.log(' "primordials": {');
102
+ logger.log(' "aliasMap": { "Array": "ArrayCtor" },');
103
+ logger.log(' "nodeInternalOnly": ["SafeMap", "SafeSet"],');
104
+ logger.log(
105
+ ' "scanDirs": ["src", "additions/source-patched/lib"]'
106
+ );
107
+ logger.log(" }");
108
+ logger.log(" }");
109
+ logger.log("");
110
+ logger.log("A bare object (no `primordials` section) is also accepted for");
111
+ logger.log("repos that only run this one check.");
112
+ }
113
+ function loadConfig(configPath) {
114
+ if (!(0, import_node_fs.existsSync)(configPath)) {
115
+ throw new Error(`config file not found: ${configPath}`);
116
+ }
117
+ let parsed;
118
+ try {
119
+ parsed = JSON.parse((0, import_node_fs.readFileSync)(configPath, "utf8"));
120
+ } catch (e) {
121
+ throw new Error(`config file is not valid JSON: ${(0, import_errors.errorMessage)(e)}`);
122
+ }
123
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
124
+ throw new Error("config root must be an object");
125
+ }
126
+ const root = parsed;
127
+ const sectional = root[CONFIG_SECTION];
128
+ const raw = sectional !== void 0 ? sectional : root;
129
+ if (!Array.isArray(raw.scanDirs)) {
130
+ throw new Error(
131
+ `config.scanDirs must be an array of strings (got ${typeof raw.scanDirs})`
132
+ );
133
+ }
134
+ for (const [i, v] of raw.scanDirs.entries()) {
135
+ if (typeof v !== "string") {
136
+ throw new Error(`config.scanDirs[${i}] must be a string`);
137
+ }
138
+ }
139
+ if (raw.aliasMap !== void 0 && (typeof raw.aliasMap !== "object" || raw.aliasMap === null || Array.isArray(raw.aliasMap))) {
140
+ throw new Error("config.aliasMap must be an object of source\u2192target");
141
+ }
142
+ if (raw.nodeInternalOnly !== void 0 && !Array.isArray(raw.nodeInternalOnly)) {
143
+ throw new Error("config.nodeInternalOnly must be an array of strings");
144
+ }
145
+ const aliasMap = new Map(
146
+ Object.entries(raw.aliasMap ?? {})
147
+ );
148
+ const nodeInternalOnly = new Set(
149
+ (raw.nodeInternalOnly ?? []).filter(
150
+ (x) => typeof x === "string"
151
+ )
152
+ );
153
+ return {
154
+ scanDirs: raw.scanDirs,
155
+ aliasMap,
156
+ nodeInternalOnly,
157
+ socketLibPrimordialsPath: typeof raw.socketLibPrimordialsPath === "string" ? raw.socketLibPrimordialsPath : void 0,
158
+ repoRoot: import_node_process.default.cwd()
159
+ };
160
+ }
161
+ function serialize(result) {
162
+ return {
163
+ ok: result.findings.length === 0,
164
+ used: result.used.size,
165
+ findings: result.findings.map((f) => ({
166
+ kind: f.kind,
167
+ name: f.name,
168
+ files: f.files,
169
+ hint: f.hint
170
+ }))
171
+ };
172
+ }
173
+ function renderHuman(result, args) {
174
+ if (result.findings.length === 0) {
175
+ if (!args.silent) {
176
+ logger.success(
177
+ `Primordials coverage OK \u2014 ${result.used.size} names used, all accounted for.`
178
+ );
179
+ }
180
+ return;
181
+ }
182
+ logger.error(
183
+ `Primordials drift detected \u2014 ${result.findings.length} unaccounted name(s):`
184
+ );
185
+ for (const f of result.findings) {
186
+ logger.error(` ${f.name}`);
187
+ if (args.explain) {
188
+ logger.error(` ${f.hint}`);
189
+ if (f.files.length > 0) {
190
+ logger.error(` files: ${f.files.join(", ")}`);
191
+ }
192
+ }
193
+ }
194
+ if (!args.explain) {
195
+ logger.error("");
196
+ logger.error("Run with --explain for fix instructions and file references.");
197
+ }
198
+ }
199
+ async function runCheckPrimordials(argv) {
200
+ const args = parseArgs(argv);
201
+ if (args.help) {
202
+ printHelp();
203
+ return 0;
204
+ }
205
+ let config;
206
+ try {
207
+ config = loadConfig(import_node_path.default.resolve(resolveConfigPath(args.config)));
208
+ } catch (e) {
209
+ logger.error(`socket-lib check primordials: ${(0, import_errors.errorMessage)(e)}`);
210
+ return 1;
211
+ }
212
+ let result;
213
+ try {
214
+ result = (0, import_primordials.checkPrimordials)(config);
215
+ } catch (e) {
216
+ logger.error(`socket-lib check primordials: ${(0, import_errors.errorMessage)(e)}`);
217
+ return 1;
218
+ }
219
+ if (args.json) {
220
+ logger.log(JSON.stringify(serialize(result), null, 2));
221
+ } else {
222
+ renderHuman(result, args);
223
+ }
224
+ return result.findings.length === 0 ? 0 : 1;
225
+ }
226
+ // Annotate the CommonJS export names for ESM import in node:
227
+ 0 && (module.exports = {
228
+ runCheckPrimordials
229
+ });
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @fileoverview `socket-lib check <name>` subcommand group.
3
+ *
4
+ * Routes to per-check handlers by name. Each check resolves its
5
+ * config file and runs its check; the group itself just dispatches
6
+ * and prints help.
7
+ *
8
+ * Available checks:
9
+ * primordials Drift between a repo's `primordials` destructures
10
+ * and socket-lib's userland mirror.
11
+ *
12
+ * Aliases let callers shorten the common ones:
13
+ * prim → primordials
14
+ */
15
+ export declare function runCheck(args: readonly string[]): Promise<number>;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /* Socket Lib - Built with esbuild */
3
+ "use strict";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var check_exports = {};
22
+ __export(check_exports, {
23
+ runCheck: () => runCheck
24
+ });
25
+ module.exports = __toCommonJS(check_exports);
26
+ var import_logger = require("../logger");
27
+ var import_check_primordials = require("./check-primordials");
28
+ const logger = (0, import_logger.getDefaultLogger)();
29
+ const CHECKS = /* @__PURE__ */ new Map([
30
+ ["primordials", "primordials"],
31
+ ["prim", "primordials"]
32
+ ]);
33
+ const ALIASES = /* @__PURE__ */ new Map([
34
+ ["primordials", ["prim"]]
35
+ ]);
36
+ function printHelp() {
37
+ logger.log("socket-lib check \u2014 fleet-wide static-analysis checks");
38
+ logger.log("");
39
+ logger.log("Usage:");
40
+ logger.log(" socket-lib check <name> [...opts]");
41
+ logger.log("");
42
+ logger.log("Checks:");
43
+ for (const [canonical, aliases] of ALIASES) {
44
+ const aliasStr = aliases.length > 0 ? ` (alias: ${aliases.join(", ")})` : "";
45
+ logger.log(` ${canonical}${aliasStr}`);
46
+ }
47
+ logger.log("");
48
+ logger.log("Run `socket-lib check <name> --help` for check-specific options.");
49
+ }
50
+ async function runCheck(args) {
51
+ const name = args[0];
52
+ if (!name || name === "--help" || name === "-h") {
53
+ printHelp();
54
+ return 0;
55
+ }
56
+ const canonical = CHECKS.get(name);
57
+ if (!canonical) {
58
+ logger.error(`socket-lib check: unknown check '${name}'`);
59
+ logger.error("Run `socket-lib check --help` for the list of checks.");
60
+ return 1;
61
+ }
62
+ switch (canonical) {
63
+ case "primordials":
64
+ return await (0, import_check_primordials.runCheckPrimordials)(args.slice(1));
65
+ default:
66
+ logger.error(`socket-lib check: missing handler for '${canonical}'`);
67
+ return 1;
68
+ }
69
+ }
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ runCheck
73
+ });
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @fileoverview `socket-lib` CLI entry point — top-level dispatcher.
4
+ *
5
+ * socket-lib — print help, list commands
6
+ * socket-lib check <name> [opts...] — run a fleet-wide check
7
+ *
8
+ * Subcommands live as siblings under `src/bin/`; each is its own
9
+ * file so a misbehaving check can't crash other commands at parse
10
+ * time. The dispatcher just routes; subcommands own their own arg
11
+ * parsing.
12
+ *
13
+ * The CLI is shipped via the `bin` field in package.json and
14
+ * intended to be invoked as `pnpm exec socket-lib <command>` from
15
+ * any consumer that has `@socketsecurity/lib` as a (dev)dependency.
16
+ */
17
+ export {};
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /* Socket Lib - Built with esbuild */
4
+ "use strict";
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var import_node_process = __toESM(require("node:process"));
28
+ var import_logger = require("../logger");
29
+ var import_check = require("./check");
30
+ const logger = (0, import_logger.getDefaultLogger)();
31
+ function printHelp() {
32
+ logger.log("socket-lib \u2014 fleet-wide static-analysis CLI");
33
+ logger.log("");
34
+ logger.log("Usage:");
35
+ logger.log(" socket-lib <command> [...args]");
36
+ logger.log("");
37
+ logger.log("Commands:");
38
+ logger.log(" check <name> Run a fleet-wide check (primordials, ...).");
39
+ logger.log("");
40
+ logger.log("Run `socket-lib check --help` for the list of checks.");
41
+ }
42
+ async function main() {
43
+ const args = import_node_process.default.argv.slice(2);
44
+ const command = args[0];
45
+ if (!command || command === "--help" || command === "-h") {
46
+ printHelp();
47
+ return 0;
48
+ }
49
+ switch (command) {
50
+ case "check": {
51
+ return await (0, import_check.runCheck)(args.slice(1));
52
+ }
53
+ default: {
54
+ logger.error(`socket-lib: unknown command '${command}'`);
55
+ logger.error("Run `socket-lib --help` for the list of commands.");
56
+ return 1;
57
+ }
58
+ }
59
+ }
60
+ if (typeof require !== "undefined" && require.main === module) {
61
+ void main().then((code) => {
62
+ import_node_process.default.exit(code);
63
+ });
64
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @fileoverview Primordials drift check — generic core.
3
+ *
4
+ * Each fleet repo that destructures from Node's internal `primordials`
5
+ * global needs to keep its usage shape-aligned with socket-lib's
6
+ * userland mirror (`@socketsecurity/lib/primordials`). This module is
7
+ * the parser + diff engine; per-repo policy (which dirs to scan,
8
+ * naming aliases, allowlist) lives in a config the caller supplies.
9
+ *
10
+ * Used by the `socket-lib check primordials` CLI subcommand. Kept
11
+ * importable as a library so repos with bespoke needs can compose it
12
+ * directly without going through the CLI.
13
+ *
14
+ * The flow:
15
+ *
16
+ * 1. Walk the configured `scanDirs` for `*.js` files.
17
+ * 2. From each file, extract names from every
18
+ * `const { Foo, Bar } = primordials` destructure.
19
+ * 3. Read socket-lib's `primordials.ts` (sibling clone) or
20
+ * `primordials.d.ts` (installed `node_modules`) and pull every
21
+ * exported name.
22
+ * 4. Diff: every destructured name must be either (a) in socket-lib
23
+ * verbatim, (b) in socket-lib via the configured alias map, or
24
+ * (c) in the configured node-internal-only allowlist.
25
+ *
26
+ * Findings come back classified so callers can render or fail-CI on
27
+ * specific kinds.
28
+ */
29
+ export interface PrimordialsCheckConfig {
30
+ /**
31
+ * Repo-relative directories to scan recursively for `*.js` files
32
+ * containing `primordials` destructures. Each entry is resolved
33
+ * against `repoRoot`.
34
+ */
35
+ readonly scanDirs: readonly string[];
36
+ /**
37
+ * Map from the source name a repo destructures (e.g. `Array`) to
38
+ * the socket-lib export name it should resolve to (e.g.
39
+ * `ArrayCtor`). socket-lib uses the `Ctor` suffix to avoid
40
+ * shadowing globals; repos that need the original name go through
41
+ * the alias.
42
+ */
43
+ readonly aliasMap: ReadonlyMap<string, string>;
44
+ /**
45
+ * Names that exist only in Node's internal `primordials` and are
46
+ * intentionally NOT mirrored to socket-lib. Adding to this set is
47
+ * a deliberate decision per name.
48
+ */
49
+ readonly nodeInternalOnly: ReadonlySet<string>;
50
+ /**
51
+ * Override the auto-resolution of socket-lib's primordials source.
52
+ * Useful for tests; production callers should leave this undefined
53
+ * so the resolver picks sibling clone → installed `node_modules`.
54
+ */
55
+ readonly socketLibPrimordialsPath?: string | undefined;
56
+ /**
57
+ * Repo root used to resolve `scanDirs` and to anchor the
58
+ * sibling-clone fallback (`<repoRoot>/../socket-lib/...`). Defaults
59
+ * to `process.cwd()`.
60
+ */
61
+ readonly repoRoot?: string | undefined;
62
+ }
63
+ export interface PrimordialsFinding {
64
+ readonly kind: 'unmapped' | 'missing-from-socket-lib';
65
+ readonly name: string;
66
+ readonly files: readonly string[];
67
+ readonly hint: string;
68
+ }
69
+ export interface PrimordialsCheckResult {
70
+ readonly used: ReadonlySet<string>;
71
+ readonly usedToFiles: ReadonlyMap<string, readonly string[]>;
72
+ readonly socketLibNames: ReadonlySet<string>;
73
+ readonly findings: readonly PrimordialsFinding[];
74
+ }
75
+ /**
76
+ * Pull every `const { … } = primordials` destructure body out of
77
+ * `src`. Comments are stripped first so commentary inside a
78
+ * destructure doesn't leak into captured names. The body regex
79
+ * disallows nested `}`, which is safe after the comment-strip pass —
80
+ * destructures themselves don't contain `}`.
81
+ */
82
+ export declare function extractPrimordialsNames(src: string): string[];
83
+ /**
84
+ * Pull every `export const Foo` / `export function Foo` /
85
+ * `export { Foo }` from a TS file. Also matches `.d.ts` declaration
86
+ * forms (`export declare const Foo`, `export declare function Foo`)
87
+ * since the fallback path reads `primordials.d.ts` from
88
+ * `node_modules` when no sibling clone is present.
89
+ */
90
+ export declare function extractTsExports(src: string): string[];
91
+ /**
92
+ * Locate socket-lib's primordials source. Search order:
93
+ *
94
+ * 1. `config.socketLibPrimordialsPath` if explicitly set.
95
+ * 2. Sibling clone — `<repoRoot>/../socket-lib/src/primordials.ts`.
96
+ * Preferred for the dev-loop case where a developer is editing
97
+ * socket-lib and a consumer in parallel.
98
+ * 3. Installed copy — `<repoRoot>/node_modules/@socketsecurity/lib/
99
+ * dist/primordials.d.ts`. The CI fallback.
100
+ *
101
+ * Throws when none of the candidates exist.
102
+ */
103
+ export declare function resolveSocketLibPrimordials(config: PrimordialsCheckConfig): string;
104
+ /**
105
+ * Run the primordials drift check against the configured repo.
106
+ * Returns the full result including raw inputs (used names, lib
107
+ * exports) so renderers can show context, plus a sorted list of
108
+ * findings classified by kind.
109
+ */
110
+ export declare function checkPrimordials(config: PrimordialsCheckConfig): PrimordialsCheckResult;