@socketsecurity/lib 5.14.0 → 5.16.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.
Files changed (85) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +2 -2
  3. package/dist/abort.d.ts +13 -0
  4. package/dist/agent.d.ts +81 -0
  5. package/dist/ansi.d.ts +13 -0
  6. package/dist/archives.d.ts +31 -0
  7. package/dist/argv/flags.d.ts +91 -0
  8. package/dist/argv/parse.d.ts +31 -0
  9. package/dist/bin.d.ts +54 -0
  10. package/dist/cacache.d.ts +38 -0
  11. package/dist/cache-with-ttl.d.ts +7 -0
  12. package/dist/colors.d.ts +12 -0
  13. package/dist/cover/formatters.d.ts +18 -0
  14. package/dist/debug.d.ts +6 -0
  15. package/dist/dlx/binary.d.ts +84 -0
  16. package/dist/dlx/cache.d.ts +6 -0
  17. package/dist/dlx/detect.d.ts +33 -0
  18. package/dist/dlx/dir.d.ts +34 -0
  19. package/dist/dlx/manifest.d.ts +16 -0
  20. package/dist/dlx/package.d.ts +43 -0
  21. package/dist/dlx/packages.d.ts +36 -0
  22. package/dist/dlx/paths.d.ts +20 -0
  23. package/dist/dlx/paths.js +1 -1
  24. package/dist/effects/pulse-frames.d.ts +6 -0
  25. package/dist/effects/text-shimmer.d.ts +9 -0
  26. package/dist/effects/ultra.d.ts +6 -0
  27. package/dist/env/ci.d.ts +14 -0
  28. package/dist/env/debug.d.ts +13 -0
  29. package/dist/env/github.d.ts +80 -0
  30. package/dist/env/helpers.d.ts +45 -0
  31. package/dist/env/home.d.ts +13 -0
  32. package/dist/env/locale.d.ts +30 -0
  33. package/dist/env/node-auth-token.d.ts +13 -0
  34. package/dist/env/node-env.d.ts +13 -0
  35. package/dist/env/npm.d.ts +50 -0
  36. package/dist/env/path.d.ts +13 -0
  37. package/dist/env/pre-commit.d.ts +14 -0
  38. package/dist/env/rewire.d.ts +38 -0
  39. package/dist/env/shell.d.ts +13 -0
  40. package/dist/env/socket-cli-shadow.d.ts +43 -0
  41. package/dist/env/socket-cli.d.ts +116 -0
  42. package/dist/env/socket.d.ts +153 -0
  43. package/dist/env/temp-dir.d.ts +30 -0
  44. package/dist/env/term.d.ts +13 -0
  45. package/dist/env/test.d.ts +32 -0
  46. package/dist/env/windows.d.ts +40 -0
  47. package/dist/env/xdg.d.ts +30 -0
  48. package/dist/env.d.ts +40 -0
  49. package/dist/external/npm-pack.js +202 -291
  50. package/dist/external/tar-fs.js +27 -7
  51. package/dist/fs.d.ts +13 -0
  52. package/dist/functions.d.ts +30 -0
  53. package/dist/globs.d.ts +27 -0
  54. package/dist/http-request.d.ts +40 -18
  55. package/dist/http-request.js +84 -129
  56. package/dist/json/format.d.ts +18 -0
  57. package/dist/memoization.d.ts +5 -0
  58. package/dist/packages/edit.d.ts +28 -0
  59. package/dist/packages/exports.d.ts +40 -0
  60. package/dist/packages/licenses.d.ts +59 -0
  61. package/dist/packages/manifest.d.ts +18 -0
  62. package/dist/packages/normalize.d.ts +22 -0
  63. package/dist/packages/operations.d.ts +51 -0
  64. package/dist/packages/provenance.d.ts +11 -0
  65. package/dist/packages/specs.d.ts +30 -0
  66. package/dist/packages/validation.d.ts +18 -0
  67. package/dist/paths/normalize.d.ts +49 -5
  68. package/dist/paths/normalize.js +13 -0
  69. package/dist/paths/rewire.js +12 -3
  70. package/dist/regexps.d.ts +7 -0
  71. package/dist/releases/github.d.ts +63 -0
  72. package/dist/releases/socket-btm.d.ts +31 -0
  73. package/dist/sea.d.ts +15 -0
  74. package/dist/shadow.d.ts +7 -0
  75. package/dist/signal-exit.d.ts +27 -0
  76. package/dist/sorts.d.ts +33 -0
  77. package/dist/spawn.d.ts +9 -0
  78. package/dist/stdio/mask.d.ts +26 -0
  79. package/dist/streams.d.ts +28 -0
  80. package/dist/suppress-warnings.d.ts +7 -0
  81. package/dist/temporary-executor.d.ts +7 -0
  82. package/dist/url.d.ts +59 -0
  83. package/dist/versions.d.ts +119 -0
  84. package/dist/words.d.ts +20 -0
  85. package/package.json +8 -58
@@ -83,21 +83,49 @@ export interface EditablePackageJsonInstance {
83
83
  }
84
84
  /**
85
85
  * Get the EditablePackageJson class for package.json manipulation.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * const EditablePackageJson = getEditablePackageJsonClass()
90
+ * const pkg = await EditablePackageJson.load('/tmp/my-project')
91
+ * console.log(pkg.content.name)
92
+ * ```
86
93
  */
87
94
  /*@__NO_SIDE_EFFECTS__*/
88
95
  export declare function getEditablePackageJsonClass(): EditablePackageJsonConstructor;
89
96
  /**
90
97
  * Convert a package.json object to an editable instance.
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const editable = pkgJsonToEditable({ name: 'my-pkg', version: '1.0.0' })
102
+ * ```
91
103
  */
92
104
  /*@__NO_SIDE_EFFECTS__*/
93
105
  export declare function pkgJsonToEditable(pkgJson: PackageJson, options?: EditablePackageJsonOptions): unknown;
94
106
  /**
95
107
  * Convert package.json to editable instance with file persistence.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const editable = await toEditablePackageJson(
112
+ * { name: 'my-pkg', version: '1.0.0' },
113
+ * { path: '/tmp/my-project' }
114
+ * )
115
+ * ```
96
116
  */
97
117
  /*@__NO_SIDE_EFFECTS__*/
98
118
  export declare function toEditablePackageJson(pkgJson: PackageJson, options?: EditablePackageJsonOptions): Promise<unknown>;
99
119
  /**
100
120
  * Convert package.json to editable instance with file persistence synchronously.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * const editable = toEditablePackageJsonSync(
125
+ * { name: 'my-pkg', version: '1.0.0' },
126
+ * { path: '/tmp/my-project' }
127
+ * )
128
+ * ```
101
129
  */
102
130
  /*@__NO_SIDE_EFFECTS__*/
103
131
  export declare function toEditablePackageJsonSync(pkgJson: PackageJson, options?: EditablePackageJsonOptions): unknown;
@@ -1,30 +1,70 @@
1
1
  /**
2
2
  * Find types definition for a specific subpath in package exports.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * const exports = { '.': { types: './dist/index.d.ts', import: './dist/index.js' } }
7
+ * const types = findTypesForSubpath(exports, './dist/index.js')
8
+ * // types === './dist/index.d.ts'
9
+ * ```
3
10
  */
4
11
  /*@__NO_SIDE_EFFECTS__*/
5
12
  export declare function findTypesForSubpath(entryExports: unknown, subpath: string): string | undefined;
6
13
  /**
7
14
  * Get subpaths from package exports.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const exports = { '.': './index.js', './utils': './utils.js' }
19
+ * getSubpaths(exports) // ['.', './utils']
20
+ * ```
8
21
  */
9
22
  /*@__NO_SIDE_EFFECTS__*/
10
23
  export declare function getSubpaths(entryExports: unknown): string[];
11
24
  /**
12
25
  * Get file paths from package exports.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const exports = { '.': './dist/index.js', './utils': './dist/utils.js' }
30
+ * getExportFilePaths(exports) // ['./dist/index.js', './dist/utils.js']
31
+ * ```
13
32
  */
14
33
  /*@__NO_SIDE_EFFECTS__*/
15
34
  export declare function getExportFilePaths(entryExports: unknown): string[];
16
35
  /**
17
36
  * Check if package exports use conditional patterns (e.g., import/require).
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * isConditionalExports({ import: './index.mjs', require: './index.cjs' }) // true
41
+ * isConditionalExports({ '.': './index.js' }) // false
42
+ * ```
18
43
  */
19
44
  /*@__NO_SIDE_EFFECTS__*/
20
45
  export declare function isConditionalExports(entryExports: unknown): boolean;
21
46
  /**
22
47
  * Check if package exports use subpath patterns (keys starting with '.').
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * isSubpathExports({ '.': './index.js', './utils': './utils.js' }) // true
52
+ * isSubpathExports({ import: './index.mjs' }) // false
53
+ * ```
23
54
  */
24
55
  /*@__NO_SIDE_EFFECTS__*/
25
56
  export declare function isSubpathExports(entryExports: unknown): boolean;
26
57
  /**
27
58
  * Normalize package.json exports field to canonical format.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * resolvePackageJsonEntryExports('./index.js')
63
+ * // { '.': './index.js' }
64
+ *
65
+ * resolvePackageJsonEntryExports({ '.': './index.js' })
66
+ * // { '.': './index.js' }
67
+ * ```
28
68
  */
29
69
  /*@__NO_SIDE_EFFECTS__*/
30
70
  export declare function resolvePackageJsonEntryExports(entryExports: unknown): unknown;
@@ -28,41 +28,100 @@ export interface LicenseVisitor {
28
28
  }
29
29
  /**
30
30
  * Collect licenses that are incompatible (copyleft).
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const nodes = [{ license: 'MIT' }, { license: 'GPL-3.0' }]
35
+ * const incompatible = collectIncompatibleLicenses(nodes)
36
+ * // incompatible contains only the GPL-3.0 node
37
+ * ```
31
38
  */
32
39
  /*@__NO_SIDE_EFFECTS__*/
33
40
  export declare function collectIncompatibleLicenses(licenseNodes: LicenseNode[]): LicenseNode[];
34
41
  /**
35
42
  * Collect warnings from license nodes.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const nodes = [{ license: 'UNLICENSED' }]
47
+ * collectLicenseWarnings(nodes) // ['Package is unlicensed']
48
+ * ```
36
49
  */
37
50
  /*@__NO_SIDE_EFFECTS__*/
38
51
  export declare function collectLicenseWarnings(licenseNodes: LicenseNode[]): string[];
39
52
  /**
40
53
  * Create an AST node from a raw node.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const raw = { license: 'MIT' }
58
+ * const node = createAstNode(raw)
59
+ * // node.type === 'License'
60
+ * ```
41
61
  */
42
62
  /*@__NO_SIDE_EFFECTS__*/
43
63
  export declare function createAstNode(rawNode: SpdxAstNode): InternalAstNode;
44
64
  /**
45
65
  * Create a binary operation AST node.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const raw = {
70
+ * left: { license: 'MIT' },
71
+ * conjunction: 'OR' as const,
72
+ * right: { license: 'Apache-2.0' }
73
+ * }
74
+ * const node = createBinaryOperationNode(raw)
75
+ * // node.type === 'BinaryOperation'
76
+ * ```
46
77
  */
47
78
  /*@__NO_SIDE_EFFECTS__*/
48
79
  export declare function createBinaryOperationNode(rawNodeParam: SpdxBinaryOperationNode): InternalBinaryOperationNode;
49
80
  /**
50
81
  * Create a license AST node.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const node = createLicenseNode({ license: 'MIT' })
86
+ * // node.type === 'License' && node.license === 'MIT'
87
+ * ```
51
88
  */
52
89
  /*@__NO_SIDE_EFFECTS__*/
53
90
  export declare function createLicenseNode(rawNode: SpdxLicenseNode): InternalLicenseNode;
54
91
  /**
55
92
  * Parse an SPDX license expression into an AST.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const ast = parseSpdxExp('MIT OR Apache-2.0')
97
+ * // ast is a BinaryOperation node with MIT and Apache-2.0 leaves
98
+ * ```
56
99
  */
57
100
  /*@__NO_SIDE_EFFECTS__*/
58
101
  export declare function parseSpdxExp(spdxExp: string): SpdxAstNode | undefined;
59
102
  /**
60
103
  * Parse package license field into structured license nodes.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const nodes = resolvePackageLicenses('MIT', '/tmp/my-project')
108
+ * // [{ license: 'MIT' }]
109
+ * ```
61
110
  */
62
111
  /*@__NO_SIDE_EFFECTS__*/
63
112
  export declare function resolvePackageLicenses(licenseFieldValue: string, where: string): LicenseNode[];
64
113
  /**
65
114
  * Traverse SPDX license AST and invoke visitor callbacks for each node.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const ast = parseSpdxExp('MIT OR Apache-2.0')
119
+ * const licenses: string[] = []
120
+ * if (ast) {
121
+ * visitLicenses(ast, { License(node) { licenses.push(node.license) } })
122
+ * }
123
+ * // licenses === ['MIT', 'Apache-2.0']
124
+ * ```
66
125
  */
67
126
  /*@__NO_SIDE_EFFECTS__*/
68
127
  export declare function visitLicenses(ast: SpdxAstNode, visitor: LicenseVisitor): void;
@@ -1,16 +1,34 @@
1
1
  import type { PackageJson, PacoteOptions } from '../packages';
2
2
  /**
3
3
  * Create a package.json object for a Socket registry package.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const pkgJson = createPackageJson('is-number', 'packages/npm/is-number', {
8
+ * version: '1.0.0',
9
+ * description: 'Check if a value is a number'
10
+ * })
11
+ * ```
4
12
  */
5
13
  /*@__NO_SIDE_EFFECTS__*/
6
14
  export declare function createPackageJson(sockRegPkgName: string, directory: string, options?: PackageJson | undefined): PackageJson;
7
15
  /**
8
16
  * Fetch the manifest for a package.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const manifest = await fetchPackageManifest('lodash@4.17.21')
21
+ * ```
9
22
  */
10
23
  /*@__NO_SIDE_EFFECTS__*/
11
24
  export declare function fetchPackageManifest(pkgNameOrId: string, options?: PacoteOptions): Promise<unknown>;
12
25
  /**
13
26
  * Fetch the packument (package document) for a package.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const packument = await fetchPackagePackument('lodash')
31
+ * ```
14
32
  */
15
33
  /*@__NO_SIDE_EFFECTS__*/
16
34
  export declare function fetchPackagePackument(pkgNameOrId: string, options?: PacoteOptions): Promise<unknown>;
@@ -1,21 +1,43 @@
1
1
  import type { NormalizeOptions, PackageJson } from '../packages';
2
2
  /**
3
3
  * Normalize a package.json object with standard npm package normalization.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const pkgJson = { name: 'my-pkg', version: '1.0.0' }
8
+ * const normalized = normalizePackageJson(pkgJson)
9
+ * ```
4
10
  */
5
11
  /*@__NO_SIDE_EFFECTS__*/
6
12
  export declare function normalizePackageJson(pkgJson: PackageJson, options?: NormalizeOptions): PackageJson;
7
13
  /**
8
14
  * Extract escaped scope from a Socket registry package name.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * resolveEscapedScope('babel__core') // 'babel__'
19
+ * resolveEscapedScope('lodash') // undefined
20
+ * ```
9
21
  */
10
22
  /*@__NO_SIDE_EFFECTS__*/
11
23
  export declare function resolveEscapedScope(sockRegPkgName: string): string | undefined;
12
24
  /**
13
25
  * Resolve original package name from Socket registry package name.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * resolveOriginalPackageName('@socketregistry/is-number') // 'is-number'
30
+ * ```
14
31
  */
15
32
  /*@__NO_SIDE_EFFECTS__*/
16
33
  export declare function resolveOriginalPackageName(sockRegPkgName: string): string;
17
34
  /**
18
35
  * Convert escaped scope to standard npm scope format.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * unescapeScope('babel__') // '@babel'
40
+ * ```
19
41
  */
20
42
  /*@__NO_SIDE_EFFECTS__*/
21
43
  export declare function unescapeScope(escapedScope: string): string;
@@ -1,31 +1,65 @@
1
1
  import type { ExtractOptions, NormalizeOptions, PackageJson, PacoteOptions, ReadPackageJsonOptions } from '../packages';
2
2
  /**
3
3
  * Extract a package to a destination directory.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * await extractPackage('lodash@4.17.21', { dest: '/tmp/lodash' })
8
+ * ```
4
9
  */
5
10
  /*@__NO_SIDE_EFFECTS__*/
6
11
  export declare function extractPackage(pkgNameOrId: string, options?: ExtractOptions, callback?: (destPath: string) => Promise<unknown>): Promise<void>;
7
12
  /**
8
13
  * Find package extensions for a given package.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const extensions = findPackageExtensions('my-pkg', '1.0.0')
18
+ * ```
9
19
  */
10
20
  /*@__NO_SIDE_EFFECTS__*/
11
21
  export declare function findPackageExtensions(pkgName: string, pkgVer: string): unknown;
12
22
  /**
13
23
  * Get the release tag for a version.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * getReleaseTag('lodash@latest') // 'latest'
28
+ * getReleaseTag('@scope/pkg@beta') // 'beta'
29
+ * getReleaseTag('lodash') // ''
30
+ * ```
14
31
  */
15
32
  /*@__NO_SIDE_EFFECTS__*/
16
33
  export declare function getReleaseTag(spec: string): string;
17
34
  /**
18
35
  * Pack a package tarball using pacote.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const tarball = await packPackage('lodash@4.17.21')
40
+ * ```
19
41
  */
20
42
  /*@__NO_SIDE_EFFECTS__*/
21
43
  export declare function packPackage(spec: string, options?: PacoteOptions): Promise<unknown>;
22
44
  /**
23
45
  * Read and parse a package.json file asynchronously.
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const pkgJson = await readPackageJson('/tmp/my-project')
50
+ * console.log(pkgJson?.name)
51
+ * ```
24
52
  */
25
53
  /*@__NO_SIDE_EFFECTS__*/
26
54
  export declare function readPackageJson(filepath: string, options?: ReadPackageJsonOptions): Promise<PackageJson | undefined>;
27
55
  /**
28
56
  * Read and parse package.json from a file path synchronously.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const pkgJson = readPackageJsonSync('/tmp/my-project')
61
+ * console.log(pkgJson?.name)
62
+ * ```
29
63
  */
30
64
  /*@__NO_SIDE_EFFECTS__*/
31
65
  export declare function readPackageJsonSync(filepath: string, options?: NormalizeOptions & {
@@ -34,11 +68,22 @@ export declare function readPackageJsonSync(filepath: string, options?: Normaliz
34
68
  }): PackageJson | undefined;
35
69
  /**
36
70
  * Resolve GitHub tarball URL for a package specifier.
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const url = await resolveGitHubTgzUrl('my-pkg@1.0.0', '/tmp/my-project')
75
+ * ```
37
76
  */
38
77
  /*@__NO_SIDE_EFFECTS__*/
39
78
  export declare function resolveGitHubTgzUrl(pkgNameOrId: string, where?: unknown): Promise<string>;
40
79
  /**
41
80
  * Resolve full package name from a PURL object with custom delimiter.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * resolvePackageName({ name: 'core', namespace: '@babel' }) // '@babel/core'
85
+ * resolvePackageName({ name: 'lodash' }) // 'lodash'
86
+ * ```
42
87
  */
43
88
  /*@__NO_SIDE_EFFECTS__*/
44
89
  export declare function resolvePackageName(purlObj: {
@@ -47,6 +92,12 @@ export declare function resolvePackageName(purlObj: {
47
92
  }, delimiter?: string): string;
48
93
  /**
49
94
  * Convert npm package name to Socket registry format with delimiter.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * resolveRegistryPackageName('@babel/core') // 'babel__core'
99
+ * resolveRegistryPackageName('lodash') // 'lodash'
100
+ * ```
50
101
  */
51
102
  /*@__NO_SIDE_EFFECTS__*/
52
103
  export declare function resolveRegistryPackageName(pkgName: string): string;
@@ -1,10 +1,21 @@
1
1
  import type { ProvenanceOptions } from '../packages';
2
2
  /**
3
3
  * Convert raw attestation data to user-friendly provenance details.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * const details = getProvenanceDetails(attestationData)
8
+ * // { level: 'trusted', repository: '...', commitSha: '...' }
9
+ * ```
4
10
  */
5
11
  export declare function getProvenanceDetails(attestationData: unknown): unknown;
6
12
  /**
7
13
  * Fetch package provenance information from npm registry.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const provenance = await fetchPackageProvenance('lodash', '4.17.21')
18
+ * ```
8
19
  */
9
20
  /*@__NO_SIDE_EFFECTS__*/
10
21
  export declare function fetchPackageProvenance(pkgName: string, pkgVersion: string, options?: ProvenanceOptions): Promise<unknown>;
@@ -1,5 +1,11 @@
1
1
  /**
2
2
  * Extract user and project from GitHub repository URL.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * getRepoUrlDetails('https://github.com/lodash/lodash.git')
7
+ * // { user: 'lodash', project: 'lodash' }
8
+ * ```
3
9
  */
4
10
  /*@__NO_SIDE_EFFECTS__*/
5
11
  export declare function getRepoUrlDetails(repoUrl?: string): {
@@ -8,21 +14,45 @@ export declare function getRepoUrlDetails(repoUrl?: string): {
8
14
  };
9
15
  /**
10
16
  * Generate GitHub API URL for a tag reference.
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * gitHubTagRefUrl('lodash', 'lodash', 'v4.17.21')
21
+ * // 'https://api.github.com/repos/lodash/lodash/git/ref/tags/v4.17.21'
22
+ * ```
11
23
  */
12
24
  /*@__NO_SIDE_EFFECTS__*/
13
25
  export declare function gitHubTagRefUrl(user: string, project: string, tag: string): string;
14
26
  /**
15
27
  * Generate GitHub tarball download URL for a commit SHA.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * gitHubTgzUrl('lodash', 'lodash', 'abc123')
32
+ * // 'https://github.com/lodash/lodash/archive/abc123.tar.gz'
33
+ * ```
16
34
  */
17
35
  /*@__NO_SIDE_EFFECTS__*/
18
36
  export declare function gitHubTgzUrl(user: string, project: string, sha: string): string;
19
37
  /**
20
38
  * Check if a package specifier is a GitHub tarball URL.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * isGitHubTgzSpec('https://github.com/user/repo/archive/abc123.tar.gz') // true
43
+ * isGitHubTgzSpec('lodash@4.17.21') // false
44
+ * ```
21
45
  */
22
46
  /*@__NO_SIDE_EFFECTS__*/
23
47
  export declare function isGitHubTgzSpec(spec: unknown, where?: string): boolean;
24
48
  /**
25
49
  * Check if a package specifier is a GitHub URL with committish.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * isGitHubUrlSpec('github:user/repo#v1.0.0') // true
54
+ * isGitHubUrlSpec('lodash@4.17.21') // false
55
+ * ```
26
56
  */
27
57
  /*@__NO_SIDE_EFFECTS__*/
28
58
  export declare function isGitHubUrlSpec(spec: unknown, where?: string): boolean;
@@ -1,15 +1,33 @@
1
1
  /**
2
2
  * Check if package name is a blessed Socket.dev package.
3
+ *
4
+ * @example
5
+ * ```typescript
6
+ * isBlessedPackageName('@socketregistry/is-number') // true
7
+ * isBlessedPackageName('lodash') // false
8
+ * ```
3
9
  */
4
10
  /*@__NO_SIDE_EFFECTS__*/
5
11
  export declare function isBlessedPackageName(name: unknown): boolean;
6
12
  /**
7
13
  * Check if a type string represents a registry fetcher type.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * isRegistryFetcherType('range') // true
18
+ * isRegistryFetcherType('git') // false
19
+ * ```
8
20
  */
9
21
  /*@__NO_SIDE_EFFECTS__*/
10
22
  export declare function isRegistryFetcherType(type: string): boolean;
11
23
  /**
12
24
  * Check if a package name is valid according to npm naming rules.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * isValidPackageName('my-package') // true
29
+ * isValidPackageName('.invalid') // false
30
+ * ```
13
31
  */
14
32
  /*@__NO_SIDE_EFFECTS__*/
15
33
  export declare function isValidPackageName(name: string): boolean;
@@ -141,6 +141,48 @@ export declare function isPath(pathLike: string | Buffer | URL): boolean;
141
141
  */
142
142
  /*@__NO_SIDE_EFFECTS__*/
143
143
  export declare function isRelative(pathLike: string | Buffer | URL): boolean;
144
+ /**
145
+ * Convert Unix-style POSIX paths (MSYS/Git Bash format) back to native Windows paths.
146
+ *
147
+ * This is the inverse of {@link toUnixPath}. MSYS-style paths use `/c/` notation
148
+ * for drive letters, which PowerShell and cmd.exe cannot resolve. This function
149
+ * converts them back to native Windows format.
150
+ *
151
+ * Conversion rules:
152
+ * - On Windows: Converts Unix drive notation to Windows drive letters
153
+ * - `/c/path/to/file` becomes `C:/path/to/file`
154
+ * - `/d/projects/app` becomes `D:/projects/app`
155
+ * - Drive letters are always uppercase in the output
156
+ * - On Unix: Returns the path unchanged (passes through normalization)
157
+ *
158
+ * This is particularly important for:
159
+ * - GitHub Actions runners where `command -v` returns MSYS paths
160
+ * - Tools like sfw that need to resolve real binary paths on Windows
161
+ * - Scripts that receive paths from Git Bash but need to pass them to native Windows tools
162
+ *
163
+ * @param {string | Buffer | URL} pathLike - The MSYS/Unix-style path to convert
164
+ * @returns {string} Native Windows path (e.g., `C:/path/to/file`) or normalized Unix path
165
+ *
166
+ * @example
167
+ * ```typescript
168
+ * // MSYS drive letter paths
169
+ * fromUnixPath('/c/projects/app/file.txt') // 'C:/projects/app/file.txt'
170
+ * fromUnixPath('/d/projects/foo/bar') // 'D:/projects/foo/bar'
171
+ *
172
+ * // Non-drive Unix paths (unchanged)
173
+ * fromUnixPath('/tmp/build/output') // '/tmp/build/output'
174
+ * fromUnixPath('/usr/local/bin') // '/usr/local/bin'
175
+ *
176
+ * // Already Windows paths (unchanged)
177
+ * fromUnixPath('C:/Windows/System32') // 'C:/Windows/System32'
178
+ *
179
+ * // Edge cases
180
+ * fromUnixPath('/c') // 'C:/'
181
+ * fromUnixPath('') // '.'
182
+ * ```
183
+ */
184
+ /*@__NO_SIDE_EFFECTS__*/
185
+ export declare function fromUnixPath(pathLike: string | Buffer | URL): string;
144
186
  /**
145
187
  * Normalize a path by converting backslashes to forward slashes and collapsing segments.
146
188
  *
@@ -348,21 +390,23 @@ export declare function trimLeadingDotSlash(pathLike: string | Buffer | URL): st
348
390
  /*@__NO_SIDE_EFFECTS__*/
349
391
  export declare function relativeResolve(from: string, to: string): string;
350
392
  /**
351
- * Convert Windows paths to Unix-style POSIX paths for Git Bash tools.
393
+ * Convert Windows paths to MSYS/Unix-style POSIX paths for Git Bash tools.
352
394
  *
353
- * Git for Windows tools (like tar, git, etc.) expect POSIX-style paths with
354
- * forward slashes and Unix drive letter notation (/c/ instead of C:\).
395
+ * Git for Windows and MSYS2 tools (like tar, git, etc.) expect POSIX-style
396
+ * paths with forward slashes and Unix drive letter notation (/c/ instead of C:\).
355
397
  * This function handles the conversion for cross-platform compatibility.
356
398
  *
399
+ * This is the inverse of {@link fromUnixPath}.
400
+ *
357
401
  * Conversion rules:
358
402
  * - On Windows: Normalizes separators and converts drive letters
359
403
  * - `C:\path\to\file` becomes `/c/path/to/file`
360
- * - `D:/Users/name` becomes `/d/Users/name`
404
+ * - `D:/projects/app` becomes `/d/projects/app`
361
405
  * - Drive letters are always lowercase in the output
362
406
  * - On Unix: Returns the path unchanged (passes through normalization)
363
407
  *
364
408
  * This is particularly important for:
365
- * - Git Bash tools that interpret `D:\` as a remote hostname
409
+ * - MSYS2/Git Bash tools that interpret `D:\` as a remote hostname
366
410
  * - Cross-platform build scripts using tar, git archive, etc.
367
411
  * - CI/CD environments where Git for Windows is used
368
412
  *
@@ -19,6 +19,7 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var normalize_exports = {};
21
21
  __export(normalize_exports, {
22
+ fromUnixPath: () => fromUnixPath,
22
23
  isAbsolute: () => isAbsolute,
23
24
  isNodeModules: () => isNodeModules,
24
25
  isPath: () => isPath,
@@ -130,6 +131,17 @@ function isRelative(pathLike) {
130
131
  return !/* @__PURE__ */ isAbsolute(filepath);
131
132
  }
132
133
  // @__NO_SIDE_EFFECTS__
134
+ function fromUnixPath(pathLike) {
135
+ const normalized = /* @__PURE__ */ normalizePath(pathLike);
136
+ if (import_platform.WIN32) {
137
+ return normalized.replace(
138
+ /^\/([a-zA-Z])(\/|$)/,
139
+ (_, letter, sep) => `${letter.toUpperCase()}:${sep || "/"}`
140
+ );
141
+ }
142
+ return normalized;
143
+ }
144
+ // @__NO_SIDE_EFFECTS__
133
145
  function normalizePath(pathLike) {
134
146
  const filepath = /* @__PURE__ */ pathLikeToString(pathLike);
135
147
  const { length } = filepath;
@@ -448,6 +460,7 @@ function toUnixPath(pathLike) {
448
460
  }
449
461
  // Annotate the CommonJS export names for ESM import in node:
450
462
  0 && (module.exports = {
463
+ fromUnixPath,
451
464
  isAbsolute,
452
465
  isNodeModules,
453
466
  isPath,
@@ -28,9 +28,18 @@ __export(rewire_exports, {
28
28
  setPath: () => setPath
29
29
  });
30
30
  module.exports = __toCommonJS(rewire_exports);
31
- const testOverrides = /* @__PURE__ */ new Map();
32
- const valueCache = /* @__PURE__ */ new Map();
33
- const cacheInvalidationCallbacks = [];
31
+ const stateSymbol = Symbol.for("@socketsecurity/lib/paths/rewire/state");
32
+ if (!globalThis[stateSymbol]) {
33
+ globalThis[stateSymbol] = {
34
+ testOverrides: /* @__PURE__ */ new Map(),
35
+ valueCache: /* @__PURE__ */ new Map(),
36
+ cacheInvalidationCallbacks: []
37
+ };
38
+ }
39
+ const sharedState = globalThis[stateSymbol];
40
+ const testOverrides = sharedState.testOverrides;
41
+ const valueCache = sharedState.valueCache;
42
+ const cacheInvalidationCallbacks = sharedState.cacheInvalidationCallbacks;
34
43
  function clearPath(key) {
35
44
  testOverrides.delete(key);
36
45
  invalidateCaches();
package/dist/regexps.d.ts CHANGED
@@ -8,6 +8,13 @@
8
8
  // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
9
9
  /**
10
10
  * Escape special characters in a string for use in a regular expression.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * escapeRegExp('foo.bar') // 'foo\\.bar'
15
+ * escapeRegExp('a+b*c?') // 'a\\+b\\*c\\?'
16
+ * new RegExp(escapeRegExp('[test]')) // /\[test\]/
17
+ * ```
11
18
  */
12
19
  /*@__NO_SIDE_EFFECTS__*/
13
20
  export declare function escapeRegExp(str: string): string;