@socketsecurity/lib 5.16.0 → 5.17.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 +11 -0
- package/dist/paths/normalize.d.ts +58 -26
- package/dist/paths/normalize.js +20 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,17 @@ 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.17.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.17.0) - 2026-04-14
|
|
9
|
+
|
|
10
|
+
### Added — paths
|
|
11
|
+
|
|
12
|
+
- `isUnixPath()` — detect MSYS/Git Bash drive letter notation (`/c/...`)
|
|
13
|
+
|
|
14
|
+
### Changed — paths
|
|
15
|
+
|
|
16
|
+
- `normalizePath()` now converts MSYS drive letters on Windows (`/c/path` → `C:/path`)
|
|
17
|
+
- `fromUnixPath()` now produces native Windows paths with backslashes (`/c/path` → `C:\path`), making it the true inverse of `toUnixPath()`
|
|
18
|
+
|
|
8
19
|
## [5.16.0](https://github.com/SocketDev/socket-lib/releases/tag/v5.16.0) - 2026-04-14
|
|
9
20
|
|
|
10
21
|
### Added — paths
|
|
@@ -142,43 +142,70 @@ export declare function isPath(pathLike: string | Buffer | URL): boolean;
|
|
|
142
142
|
/*@__NO_SIDE_EFFECTS__*/
|
|
143
143
|
export declare function isRelative(pathLike: string | Buffer | URL): boolean;
|
|
144
144
|
/**
|
|
145
|
-
*
|
|
145
|
+
* Check if a path uses MSYS/Git Bash Unix-style drive letter notation.
|
|
146
146
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
147
|
+
* Detects paths in the format `/c/...` where a single letter after the leading
|
|
148
|
+
* slash represents a Windows drive letter. These paths are produced by MSYS2,
|
|
149
|
+
* Git Bash, and `command -v` on Windows.
|
|
150
|
+
*
|
|
151
|
+
* Detection rules:
|
|
152
|
+
* - Must start with `/` followed by a single ASCII letter (a-z, A-Z)
|
|
153
|
+
* - The letter must be followed by `/` or be at the end of the string
|
|
154
|
+
* - Examples: `/c/tools/bin`, `/d/projects`, `/c`
|
|
155
|
+
* - Non-matches: `/tmp`, `/usr/local`, `C:/Windows`
|
|
156
|
+
*
|
|
157
|
+
* @param {string | Buffer | URL} pathLike - The path to check
|
|
158
|
+
* @returns {boolean} `true` if the path uses MSYS drive letter notation
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* // MSYS drive letter paths
|
|
163
|
+
* isUnixPath('/c/tools/bin') // true
|
|
164
|
+
* isUnixPath('/d/projects/app') // true
|
|
165
|
+
* isUnixPath('/c') // true
|
|
166
|
+
* isUnixPath('/C/Windows') // true
|
|
167
|
+
*
|
|
168
|
+
* // Not MSYS drive paths
|
|
169
|
+
* isUnixPath('/tmp/build') // false
|
|
170
|
+
* isUnixPath('/usr/local/bin') // false
|
|
171
|
+
* isUnixPath('C:/Windows') // false
|
|
172
|
+
* isUnixPath('./relative') // false
|
|
173
|
+
* isUnixPath('') // false
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
177
|
+
export declare function isUnixPath(pathLike: string | Buffer | URL): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Convert Unix-style POSIX paths to native Windows paths.
|
|
180
|
+
*
|
|
181
|
+
* This is the inverse of {@link toUnixPath}. On Windows, MSYS-style paths use
|
|
182
|
+
* `/c/` notation for drive letters and forward slashes, which PowerShell and
|
|
183
|
+
* cmd.exe cannot resolve. This function converts them to native Windows format
|
|
184
|
+
* with backslashes and proper drive letters.
|
|
150
185
|
*
|
|
151
186
|
* Conversion rules:
|
|
152
|
-
* - On Windows: Converts
|
|
153
|
-
* - `/c/path/to/file` becomes `C
|
|
154
|
-
* - `/d/projects/app` becomes `D
|
|
187
|
+
* - On Windows: Converts drive notation and separators to native format
|
|
188
|
+
* - `/c/path/to/file` becomes `C:\path\to\file`
|
|
189
|
+
* - `/d/projects/app` becomes `D:\projects\app`
|
|
190
|
+
* - Forward slashes become backslashes
|
|
155
191
|
* - Drive letters are always uppercase in the output
|
|
156
|
-
* - On Unix: Returns the path unchanged (
|
|
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
|
|
192
|
+
* - On Unix: Returns the normalized path unchanged (forward slashes preserved)
|
|
162
193
|
*
|
|
163
194
|
* @param {string | Buffer | URL} pathLike - The MSYS/Unix-style path to convert
|
|
164
|
-
* @returns {string} Native Windows path (e.g., `C
|
|
195
|
+
* @returns {string} Native Windows path (e.g., `C:\path\to\file`) or normalized Unix path
|
|
165
196
|
*
|
|
166
197
|
* @example
|
|
167
198
|
* ```typescript
|
|
168
|
-
* // MSYS drive letter paths
|
|
169
|
-
* fromUnixPath('/c/projects/app/file.txt') // 'C
|
|
170
|
-
* fromUnixPath('/d/projects/foo/bar') // 'D
|
|
199
|
+
* // MSYS drive letter paths (Windows)
|
|
200
|
+
* fromUnixPath('/c/projects/app/file.txt') // 'C:\\projects\\app\\file.txt'
|
|
201
|
+
* fromUnixPath('/d/projects/foo/bar') // 'D:\\projects\\foo\\bar'
|
|
202
|
+
* fromUnixPath('/c') // 'C:\\'
|
|
171
203
|
*
|
|
172
|
-
* //
|
|
173
|
-
* fromUnixPath('/
|
|
174
|
-
* fromUnixPath('/usr/local/bin') // '/usr/local/bin'
|
|
175
|
-
*
|
|
176
|
-
* // Already Windows paths (unchanged)
|
|
177
|
-
* fromUnixPath('C:/Windows/System32') // 'C:/Windows/System32'
|
|
204
|
+
* // Forward-slash paths (Windows)
|
|
205
|
+
* fromUnixPath('C:/Windows/System32') // 'C:\\Windows\\System32'
|
|
178
206
|
*
|
|
179
|
-
* //
|
|
180
|
-
* fromUnixPath('/
|
|
181
|
-
* fromUnixPath('') // '.'
|
|
207
|
+
* // Unix (unchanged, forward slashes preserved)
|
|
208
|
+
* fromUnixPath('/tmp/build/output') // '/tmp/build/output'
|
|
182
209
|
* ```
|
|
183
210
|
*/
|
|
184
211
|
/*@__NO_SIDE_EFFECTS__*/
|
|
@@ -196,6 +223,7 @@ export declare function fromUnixPath(pathLike: string | Buffer | URL): string;
|
|
|
196
223
|
* - Returns `.` for empty or collapsed paths
|
|
197
224
|
*
|
|
198
225
|
* Special handling:
|
|
226
|
+
* - MSYS drive letters (Windows only): `/c/path` becomes `C:/path`
|
|
199
227
|
* - UNC paths: Maintains double leading slashes for `//server/share` format
|
|
200
228
|
* - Windows namespaces: Preserves `//./` and `//?/` prefixes
|
|
201
229
|
* - Leading `..` segments: Preserved in relative paths without prefix
|
|
@@ -222,6 +250,10 @@ export declare function fromUnixPath(pathLike: string | Buffer | URL): string;
|
|
|
222
250
|
* normalizePath('C:\\Users\\username\\file.txt') // 'C:/Users/username/file.txt'
|
|
223
251
|
* normalizePath('foo\\bar\\baz') // 'foo/bar/baz'
|
|
224
252
|
*
|
|
253
|
+
* // MSYS drive letters (Windows only)
|
|
254
|
+
* normalizePath('/c/projects/app') // 'C:/projects/app' (on Windows)
|
|
255
|
+
* normalizePath('/d/tools/bin') // 'D:/tools/bin' (on Windows)
|
|
256
|
+
*
|
|
225
257
|
* // UNC paths
|
|
226
258
|
* normalizePath('\\\\server\\share\\file') // '//server/share/file'
|
|
227
259
|
*
|
package/dist/paths/normalize.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(normalize_exports, {
|
|
|
24
24
|
isNodeModules: () => isNodeModules,
|
|
25
25
|
isPath: () => isPath,
|
|
26
26
|
isRelative: () => isRelative,
|
|
27
|
+
isUnixPath: () => isUnixPath,
|
|
27
28
|
normalizePath: () => normalizePath,
|
|
28
29
|
pathLikeToString: () => pathLikeToString,
|
|
29
30
|
relativeResolve: () => relativeResolve,
|
|
@@ -41,6 +42,7 @@ const CHAR_LOWERCASE_A = 97;
|
|
|
41
42
|
const CHAR_LOWERCASE_Z = 122;
|
|
42
43
|
const CHAR_UPPERCASE_A = 65;
|
|
43
44
|
const CHAR_UPPERCASE_Z = 90;
|
|
45
|
+
const msysDriveRegExp = /^\/([a-zA-Z])(\/|$)/;
|
|
44
46
|
const slashRegExp = /[/\\]/;
|
|
45
47
|
const nodeModulesPathRegExp = /(?:^|[/\\])node_modules(?:[/\\]|$)/;
|
|
46
48
|
// @__NO_SIDE_EFFECTS__
|
|
@@ -67,6 +69,15 @@ function getUrl() {
|
|
|
67
69
|
}
|
|
68
70
|
return _url;
|
|
69
71
|
}
|
|
72
|
+
function msysDriveToNative(normalized) {
|
|
73
|
+
if (import_platform.WIN32) {
|
|
74
|
+
return normalized.replace(
|
|
75
|
+
msysDriveRegExp,
|
|
76
|
+
(_, letter, sep) => `${letter.toUpperCase()}:${sep || "/"}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
70
81
|
// @__NO_SIDE_EFFECTS__
|
|
71
82
|
function isNodeModules(pathLike) {
|
|
72
83
|
const filepath = /* @__PURE__ */ pathLikeToString(pathLike);
|
|
@@ -131,13 +142,15 @@ function isRelative(pathLike) {
|
|
|
131
142
|
return !/* @__PURE__ */ isAbsolute(filepath);
|
|
132
143
|
}
|
|
133
144
|
// @__NO_SIDE_EFFECTS__
|
|
145
|
+
function isUnixPath(pathLike) {
|
|
146
|
+
const filepath = /* @__PURE__ */ pathLikeToString(pathLike);
|
|
147
|
+
return typeof filepath === "string" && msysDriveRegExp.test(filepath);
|
|
148
|
+
}
|
|
149
|
+
// @__NO_SIDE_EFFECTS__
|
|
134
150
|
function fromUnixPath(pathLike) {
|
|
135
151
|
const normalized = /* @__PURE__ */ normalizePath(pathLike);
|
|
136
152
|
if (import_platform.WIN32) {
|
|
137
|
-
return normalized.replace(
|
|
138
|
-
/^\/([a-zA-Z])(\/|$)/,
|
|
139
|
-
(_, letter, sep) => `${letter.toUpperCase()}:${sep || "/"}`
|
|
140
|
-
);
|
|
153
|
+
return normalized.replace(/\//g, "\\");
|
|
141
154
|
}
|
|
142
155
|
return normalized;
|
|
143
156
|
}
|
|
@@ -219,7 +232,7 @@ function normalizePath(pathLike) {
|
|
|
219
232
|
if (segment === "..") {
|
|
220
233
|
return prefix ? prefix.slice(0, -1) || "/" : "..";
|
|
221
234
|
}
|
|
222
|
-
return prefix + segment;
|
|
235
|
+
return msysDriveToNative(prefix + segment);
|
|
223
236
|
}
|
|
224
237
|
let collapsed = "";
|
|
225
238
|
let segmentCount = 0;
|
|
@@ -300,7 +313,7 @@ function normalizePath(pathLike) {
|
|
|
300
313
|
if (collapsed.length === 0) {
|
|
301
314
|
return prefix || ".";
|
|
302
315
|
}
|
|
303
|
-
return prefix + collapsed;
|
|
316
|
+
return msysDriveToNative(prefix + collapsed);
|
|
304
317
|
}
|
|
305
318
|
// @__NO_SIDE_EFFECTS__
|
|
306
319
|
function pathLikeToString(pathLike) {
|
|
@@ -465,6 +478,7 @@ function toUnixPath(pathLike) {
|
|
|
465
478
|
isNodeModules,
|
|
466
479
|
isPath,
|
|
467
480
|
isRelative,
|
|
481
|
+
isUnixPath,
|
|
468
482
|
normalizePath,
|
|
469
483
|
pathLikeToString,
|
|
470
484
|
relativeResolve,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/lib",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.17.0",
|
|
4
4
|
"packageManager": "pnpm@11.0.0-rc.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Core utilities and infrastructure for Socket.dev security tools",
|
|
@@ -737,7 +737,7 @@
|
|
|
737
737
|
"@socketregistry/is-unicode-supported": "1.0.5",
|
|
738
738
|
"@socketregistry/packageurl-js": "1.4.1",
|
|
739
739
|
"@socketregistry/yocto-spinner": "1.0.25",
|
|
740
|
-
"@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.
|
|
740
|
+
"@socketsecurity/lib-stable": "npm:@socketsecurity/lib@5.16.0",
|
|
741
741
|
"@types/node": "24.9.2",
|
|
742
742
|
"@typescript/native-preview": "7.0.0-dev.20250920.1",
|
|
743
743
|
"@vitest/coverage-v8": "4.0.3",
|