@socketsecurity/lib 6.0.0 → 6.0.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 +71 -0
- package/README.md +26 -17
- package/dist/ai/discover.js +2 -2
- package/dist/ai/spawn.js +3 -3
- package/dist/ai/worktree.js +3 -3
- package/dist/argv/parse-args-string.d.ts +30 -0
- package/dist/argv/parse-args-string.js +42 -0
- package/dist/bin/check-primordials.js +15 -10
- package/dist/bin/check.js +2 -2
- package/dist/bin/exec.d.ts +1 -1
- package/dist/bin/exec.js +2 -2
- package/dist/bin/socket-lib.js +2 -2
- package/dist/{ttl-cache/cache.js → cache/ttl/store.js} +15 -15
- package/dist/{ttl-cache → cache/ttl}/types.d.ts +1 -1
- package/dist/checks/primordials-defaults.d.ts +20 -0
- package/dist/checks/primordials-defaults.js +92 -0
- package/dist/colors/socket-palette.d.ts +69 -0
- package/dist/colors/socket-palette.js +91 -0
- package/dist/constants/socket.js +1 -1
- package/dist/cover/code.js +2 -2
- package/dist/cover/type.js +2 -2
- package/dist/debug/_internal.d.ts +1 -1
- package/dist/debug/_internal.js +2 -2
- package/dist/debug/output.js +5 -5
- package/dist/dlx/binary-types.d.ts +2 -2
- package/dist/dlx/binary.d.ts +2 -2
- package/dist/dlx/binary.js +3 -3
- package/dist/dlx/manifest.js +2 -2
- package/dist/dlx/package.d.ts +2 -2
- package/dist/dlx/package.js +2 -2
- package/dist/dlx/types.d.ts +2 -2
- package/dist/eco/npm/npm/exec.d.ts +2 -2
- package/dist/eco/npm/npm/exec.js +2 -2
- package/dist/eco/npm/pnpm/exec.d.ts +1 -1
- package/dist/eco/npm/script.d.ts +1 -1
- package/dist/eco/npm/script.js +3 -3
- package/dist/eco/npm/yarnpkg/yarn/exec.d.ts +1 -1
- package/dist/{signal-exit → events/exit}/_internal.d.ts +1 -1
- package/dist/{signal-exit/register.js → events/exit/handler.js} +4 -4
- package/dist/{signal-exit → events/exit}/intercept.js +2 -2
- package/dist/{signal-exit → events/exit}/types.d.ts +1 -1
- package/dist/{warnings/event-target.d.ts → events/warning/handler.d.ts} +1 -1
- package/dist/{warnings/event-target.js → events/warning/handler.js} +4 -4
- package/dist/{warnings → events/warning}/suppress.d.ts +3 -3
- package/dist/{warnings → events/warning}/suppress.js +2 -2
- package/dist/external-tools/janus/asset-names.d.ts +7 -0
- package/dist/external-tools/janus/asset-names.js +5 -0
- package/dist/external-tools/janus/from-download.d.ts +1 -1
- package/dist/external-tools/janus/from-download.js +12 -4
- package/dist/fs/read-json-cache.d.ts +83 -0
- package/dist/fs/read-json-cache.js +156 -0
- package/dist/fs/read-json.d.ts +6 -1
- package/dist/fs/read-json.js +80 -8
- package/dist/fs/types.d.ts +14 -0
- package/dist/git/_internal.js +3 -3
- package/dist/github/refs-cache.d.ts +1 -1
- package/dist/github/refs-cache.js +2 -2
- package/dist/github/token.d.ts +1 -1
- package/dist/github/token.js +2 -2
- package/dist/globs/{glob.js → match.js} +3 -3
- package/dist/http-request/browser-fetch.d.ts +10 -0
- package/dist/http-request/browser-fetch.js +32 -0
- package/dist/http-request/browser.d.ts +190 -0
- package/dist/http-request/browser.js +224 -0
- package/dist/http-request/download-types.d.ts +2 -2
- package/dist/http-request/request-attempt.js +4 -0
- package/dist/http-request/request-types.d.ts +15 -0
- package/dist/http-request/request.js +5 -0
- package/dist/links/{link.d.ts → create.d.ts} +2 -2
- package/dist/links/{link.js → create.js} +3 -3
- package/dist/logger/_internal.d.ts +1 -1
- package/dist/logger/browser.d.ts +16 -0
- package/dist/logger/browser.js +65 -0
- package/dist/logger/console.js +3 -3
- package/dist/logger/{logger.js → default.js} +3 -3
- package/dist/logger/symbols-builder.d.ts +1 -1
- package/dist/logger/types.d.ts +1 -1
- package/dist/packages/isolation.js +3 -3
- package/dist/packages/types.d.ts +2 -0
- package/dist/primordials/globals.d.ts +6 -3
- package/dist/primordials/globals.js +15 -9
- package/dist/primordials/url.d.ts +1 -1
- package/dist/process/lock-manager.js +4 -4
- package/dist/{spawn → process/spawn}/_internal.js +3 -3
- package/dist/{spawn/spawn.js → process/spawn/child.js} +13 -13
- package/dist/{spawn → process/spawn}/errors.js +5 -5
- package/dist/{spawn → process/spawn}/stdio.js +1 -1
- package/dist/{spawn → process/spawn}/types.d.ts +3 -3
- package/dist/promises/types.d.ts +15 -2
- package/dist/releases/github-archives.js +2 -2
- package/dist/releases/github-downloads.js +4 -4
- package/dist/spinner/{registry.d.ts → default.d.ts} +1 -1
- package/dist/spinner/{registry.js → default.js} +3 -3
- package/dist/spinner/spinner.js +4 -4
- package/dist/spinner/with.d.ts +1 -1
- package/dist/stdio/divider.js +2 -2
- package/dist/stdio/footer.js +2 -2
- package/dist/stdio/header.js +2 -2
- package/dist/stdio/prompts.js +2 -2
- package/package.json +328 -98
- package/dist/promise-queue/types.d.ts +0 -10
- package/dist/ttl-cache/types.js +0 -18
- /package/dist/{ttl-cache/cache.d.ts → cache/ttl/store.d.ts} +0 -0
- /package/dist/{promise-queue → cache/ttl}/types.js +0 -0
- /package/dist/{signal-exit → events/exit}/_internal.js +0 -0
- /package/dist/{signal-exit/register.d.ts → events/exit/handler.d.ts} +0 -0
- /package/dist/{signal-exit → events/exit}/intercept.d.ts +0 -0
- /package/dist/{signal-exit → events/exit}/lifecycle.d.ts +0 -0
- /package/dist/{signal-exit → events/exit}/lifecycle.js +0 -0
- /package/dist/{signal-exit → events/exit}/signals.d.ts +0 -0
- /package/dist/{signal-exit → events/exit}/signals.js +0 -0
- /package/dist/{signal-exit → events/exit}/types.js +0 -0
- /package/dist/globs/{glob.d.ts → match.d.ts} +0 -0
- /package/dist/logger/{logger.d.ts → default.d.ts} +0 -0
- /package/dist/{spawn → process/spawn}/_internal.d.ts +0 -0
- /package/dist/{spawn/spawn.d.ts → process/spawn/child.d.ts} +0 -0
- /package/dist/{spawn → process/spawn}/errors.d.ts +0 -0
- /package/dist/{spawn → process/spawn}/stdio.d.ts +0 -0
- /package/dist/{spawn → process/spawn}/types.js +0 -0
- /package/dist/{promise-queue → promises}/queue.d.ts +0 -0
- /package/dist/{promise-queue → promises}/queue.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,77 @@ 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
|
+
## [6.0.1](https://github.com/SocketDev/socket-lib/releases/tag/v6.0.1) - 2026-05-25
|
|
9
|
+
|
|
10
|
+
Five additive features plus public-surface polish on top of 6.0.0. The path renames drop doubled-name leaves (`spawn/spawn`, `ttl-cache/cache`, `globs/glob`, `links/link`, `promise-queue/queue`) and regroup three top-level directories whose contents were the same concept (process events) under a new `events/` umbrella. Renames are path-only; no symbol renames or behavior changes.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`colors/socket-palette`** — Socket-branded 24-bit ANSI palette. Three themes (`'light' | 'dark' | 'synthwave'`) expose status colors (`success` / `warning` / `alert` / `error` / `info`) plus the Socket brand constants (`socketPurple` `#8c50ff`, `socketPink` `#ff00aa`). Each helper emits `\x1b[38;2;R;G;Bm` directly rather than rounding to the legacy 8-color palette, so truecolor terminals render the brand hex byte-for-byte. Hex values exposed via `palette.hex.*` for callers building their own escapes. Default theme is `'dark'`.
|
|
15
|
+
- **`logger/browser`** — minimal `console`-backed `Logger` mirroring the public `success` / `fail` / `warn` / `error` / `info` / `log` surface, with no `node:process` / `node:console` / `node:os` imports. Usable from Chrome MV3 service workers, content scripts, and popups. Importing `@socketsecurity/lib/logger` in a bundler that resolves the `'browser'` export condition (rolldown, vite, esbuild) automatically picks up this shim; Node consumers continue to get the full `Logger` class.
|
|
16
|
+
- **`'browser'` export condition** on 40 leaf modules. 35 zero-Node leaf utilities (`arrays`, `colors`, `errors`, `objects`, `regexps`, `strings`, `url`, `versions`, `words` families) carry a `'browser'` condition signalling browser-safety to bundlers. Five leaves with dedicated browser implementations (`logger/browser`, `http-request/browser`, `http-request/browser-fetch`) route to the alternate file. Browser-incompatible modules (`fs`, `archives`, `bin`, subprocess / TTY / OS-secrets surfaces) deliberately omit the condition. Full compatibility matrix in [`docs/browser-compatibility.md`](./docs/browser-compatibility.md).
|
|
17
|
+
- **`http-request` `signal` option (Node-side parity).** `HttpRequestOptions.signal?: AbortSignal | undefined` is now plumbed through `request-attempt` → `httpModule.request()`. An aborted signal short-circuits the retry loop (caller cancel is not retryable). Brings the Node side to parity with the browser side, which already exposes `signal` via `AbortController` on `fetch()`.
|
|
18
|
+
- **Default-on read-result cache for `fs/read-json` `readJson` / `readJsonSync`.** Process-scoped LRU cache keyed on `path + ino + size + mtimeMs`. Safe by four guards: stat-validated keys (re-read on stat mismatch), defensive clone on both insert and hit (caller mutations can't poison the entry), reviver opt-out (function identity isn't safely hashable), and per-call `cache: false` escape hatch. Cap defaults to 256 entries (env `SOCKET_LIB_READ_JSON_CACHE_MAX` or `setReadJsonCacheMax()`); TTL defaults to 5 min (env `SOCKET_LIB_READ_JSON_CACHE_TTL_MS` or `setReadJsonCacheTtlMs()`; set to `0` to disable TTL). `clearReadJsonCache()` + `getReadJsonCacheStats()` exported for tests and long-running daemons.
|
|
19
|
+
- **`argv/parse-args-string`** — `parseArgsString(cmd)` tokenizes a shell-style command string into an argv array. Recognizes bare tokens, single + double quoted tokens, and mixed `key="value"` tokens. Use for turning a string representation of a command (from config, a `bin` field, a test fixture) into argv that `child_process.spawn` / `execFileSync` accepts directly, bypassing platform shell quoting differences (`cmd.exe` vs `bash`).
|
|
20
|
+
|
|
21
|
+
### Changed (breaking)
|
|
22
|
+
|
|
23
|
+
- **`spawn/*` → `process/spawn/*`.** Directory moved under `process/` (which already housed `process/abort`); the function leaf renames from `spawn/spawn` to `process/spawn/child` (the spawned child is what `spawn()` returns). Sibling files keep their names: `process/spawn/{errors,stdio,types,_internal}`.
|
|
24
|
+
- **`signal-exit/*` → `events/exit/*`.** Directory merged into a new `events/` umbrella. Entry leaf renames from `signal-exit/register` to `events/exit/handler`. Sibling files unchanged: `events/exit/{intercept,lifecycle,signals,types,_internal}`.
|
|
25
|
+
- **`warnings/*` → `events/warning/*`.** Sibling of `events/exit/` under the new `events/` umbrella. Entry leaf renames from `warnings/event-target` to `events/warning/handler`; `warnings/suppress` becomes `events/warning/suppress`.
|
|
26
|
+
- **`ttl-cache/*` → `cache/ttl/*`.** Directory renamed; entry leaf renames from `ttl-cache/cache` to `cache/ttl/store`. `ttl-cache/types` becomes `cache/ttl/types`.
|
|
27
|
+
- **`promise-queue/*` folded into existing `promises/`.** `promise-queue/queue` becomes `promises/queue`; `promise-queue/types` merges into the existing `promises/types`.
|
|
28
|
+
- **`spinner/registry` → `spinner/default`.** Matches the `getDefaultSpinner()` naming pattern — the leaf is "the default spinner", not "the registry of spinners".
|
|
29
|
+
- **`logger/logger` → `logger/default`.** Matches the `getDefaultLogger()` naming pattern; drops the doubled segment.
|
|
30
|
+
- **`globs/glob` → `globs/match`.** Drops the doubled segment; `match` describes what the function does (pattern-match files), not what type the file is.
|
|
31
|
+
- **`links/link` → `links/create`.** Drops the doubled segment; `create` describes the verb (`createSymlink`).
|
|
32
|
+
- **`exports` map refreshed** for all renamed/moved leaves. The `./promises/types` entry stays unchanged — `promise-queue/types` content was folded into it.
|
|
33
|
+
|
|
34
|
+
### Removed (breaking)
|
|
35
|
+
|
|
36
|
+
- **Top-level directories `spawn/`, `signal-exit/`, `warnings/`, `ttl-cache/`, `promise-queue/`.** All five disappear in favor of the regrouped layouts above. No backcompat aliases.
|
|
37
|
+
|
|
38
|
+
### Migration
|
|
39
|
+
|
|
40
|
+
```diff
|
|
41
|
+
- import { spawn, spawnSync } from '@socketsecurity/lib/spawn/spawn'
|
|
42
|
+
- import { isSpawnError, SpawnError } from '@socketsecurity/lib/spawn/errors'
|
|
43
|
+
- import type { SpawnOptions } from '@socketsecurity/lib/spawn/types'
|
|
44
|
+
+ import {
|
|
45
|
+
+ spawn,
|
|
46
|
+
+ spawnSync,
|
|
47
|
+
+ isSpawnError,
|
|
48
|
+
+ SpawnError,
|
|
49
|
+
+ } from '@socketsecurity/lib/process/spawn/child'
|
|
50
|
+
+ import type { SpawnOptions } from '@socketsecurity/lib/process/spawn/types'
|
|
51
|
+
|
|
52
|
+
- import { onExit } from '@socketsecurity/lib/signal-exit/register'
|
|
53
|
+
+ import { onExit } from '@socketsecurity/lib/events/exit/handler'
|
|
54
|
+
|
|
55
|
+
- import { suppressDeprecationWarnings } from '@socketsecurity/lib/warnings/suppress'
|
|
56
|
+
+ import { suppressDeprecationWarnings } from '@socketsecurity/lib/events/warning/suppress'
|
|
57
|
+
|
|
58
|
+
- import { createTtlCache, TtlCache } from '@socketsecurity/lib/ttl-cache/cache'
|
|
59
|
+
+ import { createTtlCache, TtlCache } from '@socketsecurity/lib/cache/ttl/store'
|
|
60
|
+
|
|
61
|
+
- import { getDefaultSpinner } from '@socketsecurity/lib/spinner/registry'
|
|
62
|
+
+ import { getDefaultSpinner } from '@socketsecurity/lib/spinner/default'
|
|
63
|
+
|
|
64
|
+
- import { getDefaultLogger } from '@socketsecurity/lib/logger/logger'
|
|
65
|
+
+ import { getDefaultLogger } from '@socketsecurity/lib/logger/default'
|
|
66
|
+
|
|
67
|
+
- import { PromiseQueue } from '@socketsecurity/lib/promise-queue/queue'
|
|
68
|
+
+ import { PromiseQueue } from '@socketsecurity/lib/promises/queue'
|
|
69
|
+
|
|
70
|
+
- import { glob } from '@socketsecurity/lib/globs/glob'
|
|
71
|
+
+ import { glob } from '@socketsecurity/lib/globs/match'
|
|
72
|
+
|
|
73
|
+
- import { createSymlink } from '@socketsecurity/lib/links/link'
|
|
74
|
+
+ import { createSymlink } from '@socketsecurity/lib/links/create'
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
No symbol names changed. No behavior changes.
|
|
78
|
+
|
|
8
79
|
## [6.0.0](https://github.com/SocketDev/socket-lib/releases/tag/v6.0.0) - 2026-05-20
|
|
9
80
|
|
|
10
81
|
Public-surface reshape. All top-level barrels are gone; import from named leaf subpaths instead. `@socketsecurity/lib/logger` and `@socketsecurity/lib/errors` stay as aliases.
|
package/README.md
CHANGED
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://socket.dev/npm/package/@socketsecurity/lib)
|
|
4
4
|
[](https://github.com/SocketDev/socket-lib/actions/workflows/ci.yml)
|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
[](https://twitter.com/SocketSecurity)
|
|
8
8
|
[](https://bsky.app/profile/socket.dev)
|
|
9
9
|
|
|
10
10
|
Core utilities for [Socket.dev](https://socket.dev/) tools: file system, processes, HTTP, env detection, logging, spinners, and more. Tree-shakeable, TypeScript-first, cross-platform.
|
|
11
11
|
|
|
12
|
+
## Why this repo exists
|
|
13
|
+
|
|
14
|
+
`@socketsecurity/lib` is the shared utility layer for every Socket.dev tool (the CLI, SDK, registry, MCP server, build infrastructure). It exists so we ship one battle-tested implementation of "spawn a child", "fetch JSON with retries", "delete a path safely on Windows + POSIX", etc. — rather than ten subtly different ones across the fleet. Every export is reachable via a subpath import, so tree-shaking keeps your bundle lean.
|
|
15
|
+
|
|
12
16
|
## Install
|
|
13
17
|
|
|
14
|
-
```
|
|
18
|
+
```sh
|
|
15
19
|
pnpm add @socketsecurity/lib
|
|
16
20
|
```
|
|
17
21
|
|
|
18
|
-
##
|
|
22
|
+
## Usage
|
|
19
23
|
|
|
20
24
|
```typescript
|
|
21
25
|
import { Spinner } from '@socketsecurity/lib/spinner'
|
|
@@ -35,24 +39,14 @@ import { httpJson } from '@socketsecurity/lib/http-request'
|
|
|
35
39
|
import { safeDelete } from '@socketsecurity/lib/fs'
|
|
36
40
|
```
|
|
37
41
|
|
|
38
|
-
## Documentation
|
|
39
|
-
|
|
40
42
|
Start with the [API Index](./docs/api-index.md) — every subpath export with a one-line description.
|
|
41
43
|
|
|
42
|
-
- [Getting Started](./docs/getting-started.md) – install + first examples
|
|
43
|
-
- [Visual Effects](./docs/visual-effects.md) – spinners, loggers, themes
|
|
44
|
-
- [File System](./docs/file-system.md) – files, globs, paths, safe deletion
|
|
45
|
-
- [HTTP Utilities](./docs/http-utilities.md) – requests, downloads, retries
|
|
46
|
-
- [Process Utilities](./docs/process-utilities.md) – spawn, IPC, locks
|
|
47
|
-
- [Package Management](./docs/package-management.md) – npm/pnpm/yarn detection
|
|
48
|
-
- [Environment](./docs/environment.md) – CI/platform detection, env getters
|
|
49
|
-
- [Constants](./docs/constants.md) – Node versions, npm URLs, platform values
|
|
50
|
-
- [Examples](./docs/examples.md) – real-world patterns
|
|
51
|
-
- [Troubleshooting](./docs/troubleshooting.md) – common issues
|
|
52
|
-
|
|
53
44
|
## Development
|
|
54
45
|
|
|
55
|
-
|
|
46
|
+
<details>
|
|
47
|
+
<summary>Contributor commands</summary>
|
|
48
|
+
|
|
49
|
+
```sh
|
|
56
50
|
pnpm install # install
|
|
57
51
|
pnpm build # build
|
|
58
52
|
pnpm test # run tests
|
|
@@ -64,6 +58,21 @@ pnpm run fix # auto-fix formatting
|
|
|
64
58
|
|
|
65
59
|
See [CLAUDE.md](./CLAUDE.md) for contributor guidelines.
|
|
66
60
|
|
|
61
|
+
### Documentation map
|
|
62
|
+
|
|
63
|
+
- [Getting Started](./docs/getting-started.md) – install + first examples
|
|
64
|
+
- [Visual Effects](./docs/visual-effects.md) – spinners, loggers, themes
|
|
65
|
+
- [File System](./docs/file-system.md) – files, globs, paths, safe deletion
|
|
66
|
+
- [HTTP Utilities](./docs/http-utilities.md) – requests, downloads, retries
|
|
67
|
+
- [Process Utilities](./docs/process-utilities.md) – spawn, IPC, locks
|
|
68
|
+
- [Package Management](./docs/package-management.md) – npm/pnpm/yarn detection
|
|
69
|
+
- [Environment](./docs/environment.md) – CI/platform detection, env getters
|
|
70
|
+
- [Constants](./docs/constants.md) – Node versions, npm URLs, platform values
|
|
71
|
+
- [Examples](./docs/examples.md) – real-world patterns
|
|
72
|
+
- [Troubleshooting](./docs/troubleshooting.md) – common issues
|
|
73
|
+
|
|
74
|
+
</details>
|
|
75
|
+
|
|
67
76
|
## License
|
|
68
77
|
|
|
69
78
|
MIT
|
package/dist/ai/discover.js
CHANGED
|
@@ -44,9 +44,9 @@ var import_promises = require("node:fs/promises");
|
|
|
44
44
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
45
45
|
var import_which = require("../bin/which");
|
|
46
46
|
var import_message = require("../errors/message");
|
|
47
|
-
var
|
|
47
|
+
var import_default = require("../logger/default");
|
|
48
48
|
var import_json = require("../primordials/json");
|
|
49
|
-
const logger = (0,
|
|
49
|
+
const logger = (0, import_default.getDefaultLogger)();
|
|
50
50
|
const KNOWN_AGENTS = [
|
|
51
51
|
"claude",
|
|
52
52
|
"codex",
|
package/dist/ai/spawn.js
CHANGED
|
@@ -29,8 +29,8 @@ __export(spawn_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(spawn_exports);
|
|
30
30
|
var import_message = require("../errors/message");
|
|
31
31
|
var import_object = require("../primordials/object");
|
|
32
|
-
var
|
|
33
|
-
var import_errors = require("../spawn/errors");
|
|
32
|
+
var import_child = require("../process/spawn/child");
|
|
33
|
+
var import_errors = require("../process/spawn/errors");
|
|
34
34
|
var import_discover = require("./discover");
|
|
35
35
|
const MAX_ATTEMPTS = 3;
|
|
36
36
|
const BACKOFF_BASE_MS = 5e3;
|
|
@@ -163,7 +163,7 @@ async function spawnAiAgent(opts) {
|
|
|
163
163
|
stderr = "";
|
|
164
164
|
exitCode = 0;
|
|
165
165
|
try {
|
|
166
|
-
const child = (0,
|
|
166
|
+
const child = (0, import_child.spawn)(agent, args, {
|
|
167
167
|
cwd: opts.cwd,
|
|
168
168
|
stdio: "pipe",
|
|
169
169
|
stdioString: true,
|
package/dist/ai/worktree.js
CHANGED
|
@@ -42,15 +42,15 @@ module.exports = __toCommonJS(worktree_exports);
|
|
|
42
42
|
var import_node_fs = require("node:fs");
|
|
43
43
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
44
44
|
var import_message = require("../errors/message");
|
|
45
|
-
var
|
|
46
|
-
var import_errors = require("../spawn/errors");
|
|
45
|
+
var import_child = require("../process/spawn/child");
|
|
46
|
+
var import_errors = require("../process/spawn/errors");
|
|
47
47
|
const DEFAULT_CONCURRENCY = 4;
|
|
48
48
|
const MAX_CONCURRENCY = 8;
|
|
49
49
|
function currentBranch(repo) {
|
|
50
50
|
return git(repo, "symbolic-ref", "--short", "HEAD");
|
|
51
51
|
}
|
|
52
52
|
function git(cwd, ...args) {
|
|
53
|
-
const result = (0,
|
|
53
|
+
const result = (0, import_child.spawnSync)("git", args, {
|
|
54
54
|
cwd,
|
|
55
55
|
stdio: "pipe",
|
|
56
56
|
stdioString: true
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Tokenize a shell-style command string into an argv array. Modernized
|
|
3
|
+
* port of the `string-argv` npm package (MIT) — same regex-driven recognizer,
|
|
4
|
+
* native ES module shape, typed signature, no env/file prepend baggage.
|
|
5
|
+
* Supports bare tokens, single + double quoted tokens, and mixed tokens like
|
|
6
|
+
* `key="value"`. No backslash-escape processing — `\"` inside a double-quoted
|
|
7
|
+
* segment is two literal characters, not an escaped quote. No env-var
|
|
8
|
+
* expansion, no command substitution, no pipes / redirects / `&&` chains;
|
|
9
|
+
* this is purely a tokenizer. Common use case: turning a `string`
|
|
10
|
+
* representation of a command (e.g. from a config file, a `bin` field, or a
|
|
11
|
+
* shellout test fixture) into an argv array that `execFileSync` /
|
|
12
|
+
* `child_process.spawn` accepts directly — bypassing the platform shell + its
|
|
13
|
+
* quoting differences (`cmd.exe` vs `bash`).
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Tokenize a shell-style command string into argv. Single + double quote pairs
|
|
17
|
+
* are recognized; the quote characters are stripped from the resulting token.
|
|
18
|
+
* Whitespace outside of quotes separates tokens.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* parseArgsString('git commit -m "hello world"')
|
|
22
|
+
* // → ['git', 'commit', '-m', 'hello world']
|
|
23
|
+
*
|
|
24
|
+
* parseArgsString('foo --bar="x y" baz')
|
|
25
|
+
* // → ['foo', '--bar=x y', 'baz']
|
|
26
|
+
*
|
|
27
|
+
* parseArgsString("echo 'one two' three")
|
|
28
|
+
* // → ['echo', 'one two', 'three']
|
|
29
|
+
*/
|
|
30
|
+
export declare function parseArgsString(cmd: string): string[];
|
|
@@ -0,0 +1,42 @@
|
|
|
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 parse_args_string_exports = {};
|
|
22
|
+
__export(parse_args_string_exports, {
|
|
23
|
+
parseArgsString: () => parseArgsString
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(parse_args_string_exports);
|
|
26
|
+
const TOKEN_REGEXP = /([^\s'"]([^\s'"]*(['"])([^]*?)\3)+[^\s'"]*)|[^\s'"]+|(['"])([^]*?)\5/g;
|
|
27
|
+
function parseArgsString(cmd) {
|
|
28
|
+
const argv = [];
|
|
29
|
+
let match;
|
|
30
|
+
TOKEN_REGEXP.lastIndex = 0;
|
|
31
|
+
while ((match = TOKEN_REGEXP.exec(cmd)) !== null) {
|
|
32
|
+
const token = match[1] ?? match[6] ?? match[0];
|
|
33
|
+
if (typeof token === "string") {
|
|
34
|
+
argv.push(token);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return argv;
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
parseArgsString
|
|
42
|
+
});
|
|
@@ -43,14 +43,15 @@ var import_node_fs = require("node:fs");
|
|
|
43
43
|
var import_node_path = __toESM(require("node:path"));
|
|
44
44
|
var import_node_process = __toESM(require("node:process"));
|
|
45
45
|
var import_message = require("../errors/message");
|
|
46
|
-
var
|
|
46
|
+
var import_default = require("../logger/default");
|
|
47
47
|
var import_array = require("../primordials/array");
|
|
48
48
|
var import_error = require("../primordials/error");
|
|
49
49
|
var import_json = require("../primordials/json");
|
|
50
50
|
var import_object = require("../primordials/object");
|
|
51
|
+
var import_primordials_defaults = require("../checks/primordials-defaults");
|
|
51
52
|
var import_primordials = require("../checks/primordials");
|
|
52
53
|
var import_parse = require("../argv/parse");
|
|
53
|
-
const logger = (0,
|
|
54
|
+
const logger = (0, import_default.getDefaultLogger)();
|
|
54
55
|
const DEFAULT_CONFIG_PATH = ".socket-lib.json";
|
|
55
56
|
const FALLBACK_CONFIG_PATHS = [
|
|
56
57
|
".socket-lib.json",
|
|
@@ -109,14 +110,16 @@ function printHelp() {
|
|
|
109
110
|
logger.log("Config (.socket-lib.json \u2014 primordials section):");
|
|
110
111
|
logger.log(" {");
|
|
111
112
|
logger.log(' "primordials": {');
|
|
112
|
-
logger.log(' "aliasMap": { "Array": "ArrayCtor" },');
|
|
113
|
-
logger.log(' "nodeInternalOnly": ["SafeMap", "SafeSet"],');
|
|
114
113
|
logger.log(
|
|
115
114
|
' "scanDirs": ["src", "additions/source-patched/lib"]'
|
|
116
115
|
);
|
|
117
116
|
logger.log(" }");
|
|
118
117
|
logger.log(" }");
|
|
119
118
|
logger.log("");
|
|
119
|
+
logger.log("Only `scanDirs` is required. `aliasMap` and `nodeInternalOnly`");
|
|
120
|
+
logger.log("default to the fleet-canonical sets and only need entries when");
|
|
121
|
+
logger.log("your repo extends or overrides them.");
|
|
122
|
+
logger.log("");
|
|
120
123
|
logger.log("A bare object (no `primordials` section) is also accepted for");
|
|
121
124
|
logger.log("repos that only run this one check.");
|
|
122
125
|
}
|
|
@@ -152,14 +155,16 @@ function loadConfig(configPath) {
|
|
|
152
155
|
if (raw.nodeInternalOnly !== void 0 && !(0, import_array.ArrayIsArray)(raw.nodeInternalOnly)) {
|
|
153
156
|
throw new import_error.ErrorCtor("config.nodeInternalOnly must be an array of strings");
|
|
154
157
|
}
|
|
155
|
-
const aliasMap = new Map(
|
|
156
|
-
(0, import_object.ObjectEntries)(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
const aliasMap = new Map([
|
|
159
|
+
...(0, import_object.ObjectEntries)(import_primordials_defaults.DEFAULT_ALIAS_MAP),
|
|
160
|
+
...(0, import_object.ObjectEntries)(raw.aliasMap ?? {})
|
|
161
|
+
]);
|
|
162
|
+
const nodeInternalOnly = /* @__PURE__ */ new Set([
|
|
163
|
+
...import_primordials_defaults.DEFAULT_NODE_INTERNAL_ONLY,
|
|
164
|
+
...(raw.nodeInternalOnly ?? []).filter(
|
|
160
165
|
(x) => typeof x === "string"
|
|
161
166
|
)
|
|
162
|
-
);
|
|
167
|
+
]);
|
|
163
168
|
return {
|
|
164
169
|
scanDirs: raw.scanDirs,
|
|
165
170
|
aliasMap,
|
package/dist/bin/check.js
CHANGED
|
@@ -24,9 +24,9 @@ __export(check_exports, {
|
|
|
24
24
|
runCheck: () => runCheck
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(check_exports);
|
|
27
|
-
var
|
|
27
|
+
var import_default = require("../logger/default");
|
|
28
28
|
var import_check_primordials = require("./check-primordials");
|
|
29
|
-
const logger = (0,
|
|
29
|
+
const logger = (0, import_default.getDefaultLogger)();
|
|
30
30
|
const CHECKS = /* @__PURE__ */ new Map([
|
|
31
31
|
["primordials", "primordials"],
|
|
32
32
|
["prim", "primordials"]
|
package/dist/bin/exec.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* 4. On not-found, throw a typed `ENOENT` error with operator guidance — far
|
|
18
18
|
* more useful than a bare "command not found".
|
|
19
19
|
*/
|
|
20
|
-
import type { SpawnOptions } from '../spawn/types';
|
|
20
|
+
import type { SpawnOptions } from '../process/spawn/types';
|
|
21
21
|
/**
|
|
22
22
|
* Execute a binary with the given arguments.
|
|
23
23
|
*
|
package/dist/bin/exec.js
CHANGED
|
@@ -27,7 +27,7 @@ var import_platform = require("../constants/platform");
|
|
|
27
27
|
var import_normalize = require("../paths/normalize");
|
|
28
28
|
var import_array = require("../primordials/array");
|
|
29
29
|
var import_error = require("../primordials/error");
|
|
30
|
-
var
|
|
30
|
+
var import_child = require("../process/spawn/child");
|
|
31
31
|
var import_internal = require("./_internal");
|
|
32
32
|
var import_resolve = require("./resolve");
|
|
33
33
|
var import_which = require("./which");
|
|
@@ -68,7 +68,7 @@ To resolve:
|
|
|
68
68
|
throw error;
|
|
69
69
|
}
|
|
70
70
|
const binCommand = (0, import_array.ArrayIsArray)(resolvedPath) ? resolvedPath[0] : resolvedPath;
|
|
71
|
-
return await (0,
|
|
71
|
+
return await (0, import_child.spawn)(binCommand, args ?? [], {
|
|
72
72
|
shell: import_platform.WIN32,
|
|
73
73
|
...options
|
|
74
74
|
});
|
package/dist/bin/socket-lib.js
CHANGED
|
@@ -36,9 +36,9 @@ __export(socket_lib_exports, {
|
|
|
36
36
|
});
|
|
37
37
|
module.exports = __toCommonJS(socket_lib_exports);
|
|
38
38
|
var import_node_process = __toESM(require("node:process"));
|
|
39
|
-
var
|
|
39
|
+
var import_default = require("../logger/default");
|
|
40
40
|
var import_check = require("./check");
|
|
41
|
-
const logger = (0,
|
|
41
|
+
const logger = (0, import_default.getDefaultLogger)();
|
|
42
42
|
function printHelp() {
|
|
43
43
|
logger.log("socket-lib \u2014 fleet-wide static-analysis CLI");
|
|
44
44
|
logger.log("");
|
|
@@ -28,21 +28,21 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
mod
|
|
29
29
|
));
|
|
30
30
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var store_exports = {};
|
|
32
|
+
__export(store_exports, {
|
|
33
33
|
createTtlCache: () => createTtlCache
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
36
|
-
var import_clear = require("
|
|
37
|
-
var import_read = require("
|
|
38
|
-
var import_write = require("
|
|
39
|
-
var import_date = require("
|
|
40
|
-
var import_error = require("
|
|
41
|
-
var import_json = require("
|
|
42
|
-
var import_map_set = require("
|
|
43
|
-
var import_math = require("
|
|
44
|
-
var import_regexp = require("
|
|
45
|
-
var import_string = require("
|
|
35
|
+
module.exports = __toCommonJS(store_exports);
|
|
36
|
+
var import_clear = require("../../cacache/clear");
|
|
37
|
+
var import_read = require("../../cacache/read");
|
|
38
|
+
var import_write = require("../../cacache/write");
|
|
39
|
+
var import_date = require("../../primordials/date");
|
|
40
|
+
var import_error = require("../../primordials/error");
|
|
41
|
+
var import_json = require("../../primordials/json");
|
|
42
|
+
var import_map_set = require("../../primordials/map-set");
|
|
43
|
+
var import_math = require("../../primordials/math");
|
|
44
|
+
var import_regexp = require("../../primordials/regexp");
|
|
45
|
+
var import_string = require("../../primordials/string");
|
|
46
46
|
const DEFAULT_TTL_MS = 5 * 60 * 1e3;
|
|
47
47
|
const DEFAULT_PREFIX = "ttl-cache";
|
|
48
48
|
const DEFAULT_MEMO_MAX_SIZE = 1e3;
|
|
@@ -158,8 +158,8 @@ function createTtlCache(options) {
|
|
|
158
158
|
results.set(originalKey, entry.data);
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
const cacheDir = (await import("
|
|
162
|
-
const cacacheModule = await import("
|
|
161
|
+
const cacheDir = (await import("../../paths/socket")).getSocketCacacheDir();
|
|
162
|
+
const cacacheModule = await import("../../cacache/_internal");
|
|
163
163
|
const stream = cacacheModule.getCacache().ls.stream(cacheDir);
|
|
164
164
|
for await (const cacheEntry of stream) {
|
|
165
165
|
if (!cacheEntry.key.startsWith(`${opts.prefix}:`)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file Public type surface for `ttl
|
|
2
|
+
* @file Public type surface for `cache/ttl/*` modules — the `TtlCache`
|
|
3
3
|
* interface (the seven-method API returned by `createTtlCache`), the
|
|
4
4
|
* `TtlCacheEntry` storage shape, and the `TtlCacheOptions` / `ClearOptions`
|
|
5
5
|
* configuration records. Pure types, no runtime side effects.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file GENERATED — do not edit by hand. Run `node
|
|
3
|
+
* scripts/fix/generate-primordials-defaults.mts` (also runs as part of `pnpm
|
|
4
|
+
* run build`) to regenerate from the `globals` npm package's globals.json
|
|
5
|
+
* crossed against src/primordials/*.ts `Ctor` exports. Source:
|
|
6
|
+
* globals@<bumped via taze>, env = builtin ∪ node. Filter: identifiers
|
|
7
|
+
* socket-lib exports as `<name>Ctor`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Fleet-canonical alias map: socket-lib mirrors standard JS + Node globals with
|
|
11
|
+
* a `Ctor` suffix. Downstream repos that destructure raw `primordials` use this
|
|
12
|
+
* map to resolve the source-side name to socket-lib's export.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_ALIAS_MAP: Readonly<Record<string, string>>;
|
|
15
|
+
/**
|
|
16
|
+
* Names that exist in Node's internal `primordials` but are intentionally NOT
|
|
17
|
+
* mirrored to socket-lib (mostly Safe* wrappers and prototype-method aliases).
|
|
18
|
+
* Adding to this set is a per-name decision; the list is hand-maintained.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_NODE_INTERNAL_ONLY: readonly string[];
|
|
@@ -0,0 +1,92 @@
|
|
|
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 primordials_defaults_exports = {};
|
|
22
|
+
__export(primordials_defaults_exports, {
|
|
23
|
+
DEFAULT_ALIAS_MAP: () => DEFAULT_ALIAS_MAP,
|
|
24
|
+
DEFAULT_NODE_INTERNAL_ONLY: () => DEFAULT_NODE_INTERNAL_ONLY
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(primordials_defaults_exports);
|
|
27
|
+
var import_object = require("../primordials/object");
|
|
28
|
+
const DEFAULT_ALIAS_MAP = (0, import_object.ObjectFreeze)(
|
|
29
|
+
{
|
|
30
|
+
__proto__: null,
|
|
31
|
+
AggregateError: "AggregateErrorCtor",
|
|
32
|
+
Array: "ArrayCtor",
|
|
33
|
+
ArrayBuffer: "ArrayBufferCtor",
|
|
34
|
+
BigInt: "BigIntCtor",
|
|
35
|
+
Boolean: "BooleanCtor",
|
|
36
|
+
Buffer: "BufferCtor",
|
|
37
|
+
DataView: "DataViewCtor",
|
|
38
|
+
Date: "DateCtor",
|
|
39
|
+
Error: "ErrorCtor",
|
|
40
|
+
EvalError: "EvalErrorCtor",
|
|
41
|
+
Float32Array: "Float32ArrayCtor",
|
|
42
|
+
Float64Array: "Float64ArrayCtor",
|
|
43
|
+
Int16Array: "Int16ArrayCtor",
|
|
44
|
+
Int32Array: "Int32ArrayCtor",
|
|
45
|
+
Int8Array: "Int8ArrayCtor",
|
|
46
|
+
Map: "MapCtor",
|
|
47
|
+
Number: "NumberCtor",
|
|
48
|
+
Object: "ObjectCtor",
|
|
49
|
+
Promise: "PromiseCtor",
|
|
50
|
+
Proxy: "ProxyCtor",
|
|
51
|
+
RangeError: "RangeErrorCtor",
|
|
52
|
+
ReferenceError: "ReferenceErrorCtor",
|
|
53
|
+
RegExp: "RegExpCtor",
|
|
54
|
+
Set: "SetCtor",
|
|
55
|
+
SharedArrayBuffer: "SharedArrayBufferCtor",
|
|
56
|
+
String: "StringCtor",
|
|
57
|
+
Symbol: "SymbolCtor",
|
|
58
|
+
SyntaxError: "SyntaxErrorCtor",
|
|
59
|
+
TypeError: "TypeErrorCtor",
|
|
60
|
+
URIError: "URIErrorCtor",
|
|
61
|
+
URL: "URLCtor",
|
|
62
|
+
URLSearchParams: "URLSearchParamsCtor",
|
|
63
|
+
Uint16Array: "Uint16ArrayCtor",
|
|
64
|
+
Uint32Array: "Uint32ArrayCtor",
|
|
65
|
+
Uint8Array: "Uint8ArrayCtor",
|
|
66
|
+
Uint8ClampedArray: "Uint8ClampedArrayCtor",
|
|
67
|
+
WeakMap: "WeakMapCtor",
|
|
68
|
+
WeakRef: "WeakRefCtor",
|
|
69
|
+
WeakSet: "WeakSetCtor",
|
|
70
|
+
atob: "GlobalAtob",
|
|
71
|
+
btoa: "GlobalBtoa",
|
|
72
|
+
decodeURIComponent: "GlobalDecodeURIComponent",
|
|
73
|
+
encodeURIComponent: "GlobalEncodeURIComponent",
|
|
74
|
+
globalThis: "GlobalThis"
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
const DEFAULT_NODE_INTERNAL_ONLY = (0, import_object.ObjectFreeze)([
|
|
78
|
+
"DataViewPrototypeGetInt32",
|
|
79
|
+
"DataViewPrototypeGetUint32",
|
|
80
|
+
"SafeMap",
|
|
81
|
+
"SafePromise",
|
|
82
|
+
"SafePromiseAllReturnVoid",
|
|
83
|
+
"SafePromiseAllSettled",
|
|
84
|
+
"SafeSet",
|
|
85
|
+
"SafeWeakMap",
|
|
86
|
+
"SafeWeakSet"
|
|
87
|
+
]);
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
DEFAULT_ALIAS_MAP,
|
|
91
|
+
DEFAULT_NODE_INTERNAL_ONLY
|
|
92
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Socket terminal-color palette — mirrors the CSS design tokens defined
|
|
3
|
+
* in the fleet's `template/styles/tokens.css` (light / dark / synthwave
|
|
4
|
+
* themes). Each helper returns the input string wrapped in a 24-bit ANSI
|
|
5
|
+
* escape sequence so the rendered hex matches the brand exactly; no rounding
|
|
6
|
+
* to the legacy 8-color palette. Picocolors / yoctocolors only ship a fixed
|
|
7
|
+
* 8-color ANSI set, which would collapse `#8c50ff` to a generic "magenta".
|
|
8
|
+
* This module sidesteps that by emitting `\x1b[38;2;R;G;Bm…\x1b[39m`
|
|
9
|
+
* directly. Zero runtime dependencies. Usage: import { getPalette } from
|
|
10
|
+
* '@socketsecurity/lib/colors/socket-palette' const palette =
|
|
11
|
+
* getPalette('dark') console.log(palette.success('Done')) // Or read raw hex
|
|
12
|
+
* values for callers building their own escape codes.
|
|
13
|
+
* console.log(palette.hex.socketPurple) // "#8c50ff" Pick a theme by passing
|
|
14
|
+
* `'light' | 'dark' | 'synthwave'`. Defaults to `'dark'` since terminals are
|
|
15
|
+
* dark-on-light far less often than the opposite.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Available palette themes — kept in sync with the CSS theme blocks in
|
|
19
|
+
* template/styles/tokens.css.
|
|
20
|
+
*/
|
|
21
|
+
export type SocketPaletteTheme = 'dark' | 'light' | 'synthwave';
|
|
22
|
+
/**
|
|
23
|
+
* Hex-color value for each named slot. Exposed so callers can build their own
|
|
24
|
+
* ANSI escapes (e.g. for backgrounds, which this module doesn't wrap).
|
|
25
|
+
*/
|
|
26
|
+
export interface SocketPaletteHex {
|
|
27
|
+
alert: string;
|
|
28
|
+
error: string;
|
|
29
|
+
info: string;
|
|
30
|
+
socketPink: string;
|
|
31
|
+
socketPurple: string;
|
|
32
|
+
success: string;
|
|
33
|
+
warning: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Color-application helpers. Each takes a string and returns it wrapped in the
|
|
37
|
+
* matching 24-bit ANSI escape.
|
|
38
|
+
*/
|
|
39
|
+
export interface SocketPalette {
|
|
40
|
+
alert: (s: string) => string;
|
|
41
|
+
error: (s: string) => string;
|
|
42
|
+
hex: SocketPaletteHex;
|
|
43
|
+
info: (s: string) => string;
|
|
44
|
+
socketPink: (s: string) => string;
|
|
45
|
+
socketPurple: (s: string) => string;
|
|
46
|
+
success: (s: string) => string;
|
|
47
|
+
warning: (s: string) => string;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build an ANSI-wrapping function for a single hex color. Emits the 24-bit
|
|
51
|
+
* sequence rather than rounding to the legacy 8-color palette so the rendered
|
|
52
|
+
* output matches the CSS token byte-for-byte (modulo terminal gamut).
|
|
53
|
+
* `\x1b[39m` resets fg to the terminal default — using `[0m` would also clear
|
|
54
|
+
* bg / styles, which the caller may have set deliberately.
|
|
55
|
+
*/
|
|
56
|
+
export declare function colorizer(hex: string): (s: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve a Socket palette for the requested theme. Defaults to `'dark'` — the
|
|
59
|
+
* common case for terminal output.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ;```typescript
|
|
63
|
+
* import { getPalette } from '@socketsecurity/lib/colors/socket-palette'
|
|
64
|
+
*
|
|
65
|
+
* const palette = getPalette('dark')
|
|
66
|
+
* process.stdout.write(palette.success('Build complete\n'))
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export declare function getPalette(theme?: SocketPaletteTheme): SocketPalette;
|