pathprobe 0.4.3 → 0.5.4
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/README.md +77 -74
- package/dist/index.mjs +120 -58
- package/dist/index.mjs.map +1 -1
- package/dist/native-loader.cjs +16 -0
- package/dist/types/src/native/unc.d.ts +1 -0
- package/package.json +8 -3
- package/dist/types/src/unc.d.ts +0 -1
package/README.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
# pathprobe
|
|
2
2
|
|
|
3
|
-
`pathprobe`
|
|
3
|
+
`pathprobe` 用于从一段文本中找出其中提到的、真实存在于文件系统中的文件或目录路径。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install pathprobe
|
|
9
|
+
```
|
|
4
10
|
|
|
5
11
|
## 基本用法
|
|
6
12
|
|
|
@@ -9,8 +15,8 @@ import { findExistingPaths } from "pathprobe";
|
|
|
9
15
|
|
|
10
16
|
const matches = await findExistingPaths(
|
|
11
17
|
`
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
请检查 src/index.ts:12
|
|
19
|
+
以及 "./config/settings.json"
|
|
14
20
|
`,
|
|
15
21
|
2,
|
|
16
22
|
[process.cwd()],
|
|
@@ -27,20 +33,16 @@ console.log(matches);
|
|
|
27
33
|
kind: "file",
|
|
28
34
|
path: "/project/src/index.ts",
|
|
29
35
|
position: {
|
|
30
|
-
start:
|
|
31
|
-
end:
|
|
36
|
+
start: 8,
|
|
37
|
+
end: 20,
|
|
38
|
+
},
|
|
39
|
+
location: {
|
|
40
|
+
line: 12,
|
|
32
41
|
},
|
|
33
42
|
},
|
|
34
43
|
];
|
|
35
44
|
```
|
|
36
45
|
|
|
37
|
-
每个匹配项包含:
|
|
38
|
-
|
|
39
|
-
- `path`:解析后的绝对路径
|
|
40
|
-
- `kind`:`"file"` 或 `"directory"`
|
|
41
|
-
- `position`:路径在原始文本中的字符范围
|
|
42
|
-
- `location`:可选的行号、列号信息
|
|
43
|
-
|
|
44
46
|
## API
|
|
45
47
|
|
|
46
48
|
```ts
|
|
@@ -54,100 +56,101 @@ findExistingPaths(
|
|
|
54
56
|
): Promise<PathMatch[]>
|
|
55
57
|
```
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
参数说明:
|
|
60
|
+
|
|
61
|
+
- `text`:需要扫描的文本。
|
|
62
|
+
- `level`:搜索强度,值越高,识别越宽松。
|
|
63
|
+
- `directories`:解析相对路径时使用的搜索目录。
|
|
64
|
+
- `variables`:可选的变量值。
|
|
65
|
+
- `respectIgnore`:是否遵守 `.gitignore` 等忽略规则。
|
|
66
|
+
- `searchHidden`:是否搜索隐藏文件和目录。
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
`directories` 中的目录必须真实存在。
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
## 搜索级别
|
|
62
71
|
|
|
63
|
-
|
|
72
|
+
级别越高,能够识别更多自然文本中的路径,也可能产生更多文件系统检查。
|
|
64
73
|
|
|
65
|
-
|
|
74
|
+
可通过:
|
|
66
75
|
|
|
67
76
|
```ts
|
|
68
77
|
import { MAX_LEVEL } from "pathprobe";
|
|
69
78
|
```
|
|
70
79
|
|
|
71
|
-
|
|
80
|
+
获取当前最高级别。
|
|
72
81
|
|
|
73
|
-
|
|
82
|
+
## 路径位置
|
|
74
83
|
|
|
75
|
-
|
|
76
|
-
await findExistingPaths(text, 2, [process.cwd(), "/another/project"]);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### `variables`
|
|
84
|
+
路径后可以附带行号或行列号:
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
await findExistingPaths("$PROJECT/src/index.ts", 2, [process.cwd()], {
|
|
85
|
-
PROJECT: "/home/user/project",
|
|
86
|
-
});
|
|
86
|
+
```text
|
|
87
|
+
src/index.ts:42
|
|
88
|
+
src/index.ts:42:8
|
|
87
89
|
```
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
匹配结果会包含:
|
|
90
92
|
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
${{ env.HOME }}/project
|
|
99
|
-
$(HOME)/project
|
|
100
|
-
@HOME@/project
|
|
93
|
+
```ts
|
|
94
|
+
{
|
|
95
|
+
location: {
|
|
96
|
+
line: 42,
|
|
97
|
+
column: 8,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
101
100
|
```
|
|
102
101
|
|
|
103
|
-
|
|
102
|
+
同时,`position.start` 和 `position.end` 表示路径在原始文本中的字符范围。
|
|
104
103
|
|
|
105
|
-
|
|
104
|
+
## 变量展开
|
|
106
105
|
|
|
107
|
-
|
|
106
|
+
可以在文本中使用常见的变量表达式:
|
|
108
107
|
|
|
109
|
-
|
|
108
|
+
```text
|
|
109
|
+
$HOME/project/file.txt
|
|
110
|
+
${HOME}/project/file.txt
|
|
111
|
+
$env:HOME/project/file.txt
|
|
112
|
+
%HOME%\project\file.txt
|
|
113
|
+
{{ HOME }}/project/file.txt
|
|
114
|
+
${{ env.HOME }}/project/file.txt
|
|
115
|
+
```
|
|
110
116
|
|
|
111
|
-
|
|
117
|
+
也可以自行提供变量:
|
|
112
118
|
|
|
113
|
-
|
|
119
|
+
```ts
|
|
120
|
+
await findExistingPaths("$PROJECT_ROOT/src/index.ts", 2, [process.cwd()], {
|
|
121
|
+
PROJECT_ROOT: "/projects/demo",
|
|
122
|
+
});
|
|
123
|
+
```
|
|
114
124
|
|
|
115
|
-
|
|
125
|
+
未显式提供的变量会尝试从 `process.env` 中读取。
|
|
116
126
|
|
|
117
|
-
##
|
|
127
|
+
## Windows / UNC
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
在 Windows 上,`pathprobe` 可以处理:
|
|
120
130
|
|
|
121
131
|
```text
|
|
122
|
-
|
|
123
|
-
../config/settings.json
|
|
124
|
-
~/Documents/test.txt
|
|
125
|
-
/usr/local/bin/tool
|
|
126
|
-
C:\Users\me\project\README.md
|
|
127
|
-
\\localhost\share\file.txt
|
|
128
|
-
file:///tmp/example.txt
|
|
129
|
-
src/index.ts:42
|
|
130
|
-
src/index.ts:42:8
|
|
131
|
-
"$HOME/My Project/file.txt"
|
|
132
|
+
\\server\share\project\file.txt
|
|
132
133
|
```
|
|
133
134
|
|
|
134
|
-
|
|
135
|
+
对于映射到本机盘符的网络共享,以及本机管理共享(如 `\\localhost\C$\...`),会尽可能转换成可由本机文件系统验证的路径。
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
无法映射为本地可访问路径的 UNC 地址会被忽略。
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
## 返回类型
|
|
139
140
|
|
|
140
141
|
```ts
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
142
|
+
interface PathMatch {
|
|
143
|
+
kind: "file" | "directory";
|
|
144
|
+
path: string;
|
|
145
|
+
position: {
|
|
146
|
+
start: number;
|
|
147
|
+
end: number;
|
|
148
|
+
};
|
|
149
|
+
location?: {
|
|
150
|
+
line: number;
|
|
151
|
+
column?: number;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
149
154
|
```
|
|
150
155
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
在 Windows 上,UNC 路径仅会解析指向本机的共享路径,以避免意外访问远程网络位置。
|
|
156
|
+
`pathprobe` 只返回经过文件系统验证、当前真实存在的文件或目录。
|
package/dist/index.mjs
CHANGED
|
@@ -14,11 +14,7 @@ const settings = {
|
|
|
14
14
|
locationSuffixPattern: /:(?<line>\d+)(?::(?<column>\d+))?$/u,
|
|
15
15
|
respectIgnoreByDefault: true,
|
|
16
16
|
searchHiddenByDefault: false,
|
|
17
|
-
spanWordLimits: [
|
|
18
|
-
3,
|
|
19
|
-
8,
|
|
20
|
-
24
|
|
21
|
-
],
|
|
17
|
+
spanWordLimits: [3, 24],
|
|
22
18
|
trailingPunctuation: ".,;:!?,。;:!?、",
|
|
23
19
|
validationConcurrency: 32
|
|
24
20
|
};
|
|
@@ -213,6 +209,119 @@ async function classifyExistingPaths(paths, roots) {
|
|
|
213
209
|
return found;
|
|
214
210
|
}
|
|
215
211
|
//#endregion
|
|
212
|
+
//#region src/native/unc.ts
|
|
213
|
+
const runtimeRequire = globalThis.process.getBuiltinModule("node:module").createRequire(import.meta.url);
|
|
214
|
+
const native = process.platform === "win32" ? runtimeRequire("pathprobe/native-loader") : void 0;
|
|
215
|
+
const uncServerSegmentPattern = /^[^\\/:*?"<>|]+$/u;
|
|
216
|
+
const unmappedDriveErrors = /* @__PURE__ */ new Set([
|
|
217
|
+
1200,
|
|
218
|
+
1201,
|
|
219
|
+
1203,
|
|
220
|
+
1222,
|
|
221
|
+
2250
|
|
222
|
+
]);
|
|
223
|
+
const errorMoreData = 234;
|
|
224
|
+
const mappingBufferChars = 32768;
|
|
225
|
+
function normalizeServerName(value) {
|
|
226
|
+
return value.replace(/\.+$/u, "").toLowerCase();
|
|
227
|
+
}
|
|
228
|
+
function addLocalServerName(names, value) {
|
|
229
|
+
if (value !== void 0 && uncServerSegmentPattern.test(value)) names.add(normalizeServerName(value));
|
|
230
|
+
}
|
|
231
|
+
function addIpv6LiteralName(names, value) {
|
|
232
|
+
const zoneIndex = value.indexOf("%");
|
|
233
|
+
const address = zoneIndex === -1 ? value : value.slice(0, zoneIndex);
|
|
234
|
+
const zone = zoneIndex === -1 ? "" : `s${value.slice(zoneIndex + 1)}`;
|
|
235
|
+
addLocalServerName(names, `${address.replaceAll(":", "-")}${zone}.ipv6-literal.net`);
|
|
236
|
+
}
|
|
237
|
+
function collectLocalServerNames() {
|
|
238
|
+
const names = /* @__PURE__ */ new Set(["localhost"]);
|
|
239
|
+
const computerName = process.env.COMPUTERNAME;
|
|
240
|
+
addLocalServerName(names, hostname());
|
|
241
|
+
addLocalServerName(names, computerName);
|
|
242
|
+
if (computerName !== void 0 && process.env.USERDNSDOMAIN !== void 0) addLocalServerName(names, `${computerName}.${process.env.USERDNSDOMAIN}`);
|
|
243
|
+
for (const addresses of Object.values(networkInterfaces())) for (const address of addresses ?? []) if (isIP(address.address) === 4) addLocalServerName(names, address.address);
|
|
244
|
+
else if (isIP(address.address) === 6) addIpv6LiteralName(names, address.address);
|
|
245
|
+
addLocalServerName(names, "--1.ipv6-literal.net");
|
|
246
|
+
return names;
|
|
247
|
+
}
|
|
248
|
+
const localServerNames = process.platform === "win32" ? collectLocalServerNames() : /* @__PURE__ */ new Set();
|
|
249
|
+
let driveMappings;
|
|
250
|
+
function containsControlCharacter(value) {
|
|
251
|
+
return [...value].some((character) => character.charCodeAt(0) < 32);
|
|
252
|
+
}
|
|
253
|
+
function normalizeUncRoot(value) {
|
|
254
|
+
return value.replaceAll("/", "\\").replace(/\\+$/u, "").toLowerCase();
|
|
255
|
+
}
|
|
256
|
+
function parseUncPath(value) {
|
|
257
|
+
const normalized = value.replaceAll("/", "\\");
|
|
258
|
+
const extended = normalized.slice(0, 8).toLowerCase() === "\\\\?\\unc\\";
|
|
259
|
+
if (normalized.startsWith("\\\\.\\") || normalized.startsWith("\\\\?\\") && !extended) return;
|
|
260
|
+
const serverStart = extended ? 8 : 2;
|
|
261
|
+
const serverSeparator = normalized.slice(serverStart).indexOf("\\");
|
|
262
|
+
if (serverSeparator <= 0) return;
|
|
263
|
+
const serverEnd = serverStart + serverSeparator;
|
|
264
|
+
const shareStart = serverEnd + 1;
|
|
265
|
+
const shareSeparator = normalized.slice(shareStart).indexOf("\\");
|
|
266
|
+
const shareEnd = shareSeparator === -1 ? normalized.length : shareStart + shareSeparator;
|
|
267
|
+
const server = normalized.slice(serverStart, serverEnd);
|
|
268
|
+
const share = normalized.slice(shareStart, shareEnd);
|
|
269
|
+
if (share.length === 0 || !uncServerSegmentPattern.test(server) || !uncServerSegmentPattern.test(share)) return;
|
|
270
|
+
const suffix = normalized.slice(shareEnd);
|
|
271
|
+
return {
|
|
272
|
+
canonical: `\\\\${server}\\${share}${suffix}`,
|
|
273
|
+
server,
|
|
274
|
+
share,
|
|
275
|
+
suffix
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function queryDriveMapping(drive) {
|
|
279
|
+
if (native === void 0) return;
|
|
280
|
+
const { remote, status } = native.getDriveConnection(drive, mappingBufferChars);
|
|
281
|
+
if (status === errorMoreData) throw new Error(`WNetGetConnectionW returned an oversized mapping for ${drive}`);
|
|
282
|
+
if (unmappedDriveErrors.has(status)) return;
|
|
283
|
+
if (status !== 0) throw new Error(`WNetGetConnectionW failed for ${drive} with error ${status}`);
|
|
284
|
+
if (typeof remote !== "string" || !remote.startsWith("\\\\")) throw new TypeError(`WNetGetConnectionW returned an invalid mapping for ${drive}`);
|
|
285
|
+
return normalizeUncRoot(remote);
|
|
286
|
+
}
|
|
287
|
+
function queryDriveMappings() {
|
|
288
|
+
if (driveMappings !== void 0) return driveMappings;
|
|
289
|
+
const result = [];
|
|
290
|
+
for (let code = "A".charCodeAt(0); code <= "Z".charCodeAt(0); code += 1) {
|
|
291
|
+
const drive = `${String.fromCharCode(code)}:`;
|
|
292
|
+
const remote = queryDriveMapping(drive);
|
|
293
|
+
if (remote !== void 0) result.push({
|
|
294
|
+
drive,
|
|
295
|
+
remote
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
driveMappings = result.toSorted((left, right) => right.remote.length - left.remote.length);
|
|
299
|
+
return driveMappings;
|
|
300
|
+
}
|
|
301
|
+
function resolveMappedUncPath(path) {
|
|
302
|
+
const canonical = normalizeUncRoot(path.canonical);
|
|
303
|
+
const mapping = queryDriveMappings().find(({ remote }) => canonical === remote || canonical.startsWith(`${remote}\\`));
|
|
304
|
+
if (mapping === void 0) return;
|
|
305
|
+
const relative = path.canonical.slice(mapping.remote.length);
|
|
306
|
+
return nodePath.win32.normalize(`${mapping.drive}${relative}`);
|
|
307
|
+
}
|
|
308
|
+
function isLocalServer(value) {
|
|
309
|
+
const normalized = normalizeServerName(value);
|
|
310
|
+
return localServerNames.has(normalized) || isIP(value) === 4 && value.split(".")[0] === "127" || normalized === "--1.ipv6-literal.net";
|
|
311
|
+
}
|
|
312
|
+
function resolveLocalAdministrativeShare(path) {
|
|
313
|
+
const match = /^([A-Za-z])\$$/u.exec(path.share);
|
|
314
|
+
if (match === null || !isLocalServer(path.server)) return;
|
|
315
|
+
return nodePath.win32.normalize(`${match[1]}:${path.suffix || "\\"}`);
|
|
316
|
+
}
|
|
317
|
+
function resolveUncPath(value) {
|
|
318
|
+
if (process.platform !== "win32" || !value.startsWith("\\\\") && !value.startsWith("//")) return value;
|
|
319
|
+
if (containsControlCharacter(value)) return;
|
|
320
|
+
const path = parseUncPath(value);
|
|
321
|
+
if (path === void 0) return;
|
|
322
|
+
return resolveMappedUncPath(path) ?? resolveLocalAdministrativeShare(path);
|
|
323
|
+
}
|
|
324
|
+
//#endregion
|
|
216
325
|
//#region src/policy.ts
|
|
217
326
|
function pathKey$1(value) {
|
|
218
327
|
return process.platform === "win32" ? value.toLowerCase() : value;
|
|
@@ -249,7 +358,9 @@ async function resolveSearchDirectories(directories) {
|
|
|
249
358
|
const unique = /* @__PURE__ */ new Map();
|
|
250
359
|
for (const directory of directories) {
|
|
251
360
|
if (typeof directory !== "string" || directory.length === 0) throw new TypeError("every directory must be a non-empty string");
|
|
252
|
-
const
|
|
361
|
+
const resolvedUnc = resolveUncPath(directory);
|
|
362
|
+
if (resolvedUnc === void 0 || resolvedUnc.length === 0) throw new TypeError(`${directory} cannot be represented as a drive-based path`);
|
|
363
|
+
const resolved = nodePath.resolve(resolvedUnc);
|
|
253
364
|
unique.set(pathKey$1(resolved), resolved);
|
|
254
365
|
}
|
|
255
366
|
await Promise.all([...unique.values()].map(async (directory) => {
|
|
@@ -293,55 +404,6 @@ async function filterSearchablePaths(paths, roots, respectIgnore, searchHidden)
|
|
|
293
404
|
return allowed;
|
|
294
405
|
}
|
|
295
406
|
//#endregion
|
|
296
|
-
//#region src/unc.ts
|
|
297
|
-
const uncServerSegmentPattern = /^[^\\/:*?"<>|]+$/u;
|
|
298
|
-
function normalizeServerName(value) {
|
|
299
|
-
return value.replace(/\.+$/u, "").toLowerCase();
|
|
300
|
-
}
|
|
301
|
-
function addLocalServerName(names, value) {
|
|
302
|
-
if (value !== void 0 && uncServerSegmentPattern.test(value)) names.add(normalizeServerName(value));
|
|
303
|
-
}
|
|
304
|
-
function addIpv6LiteralName(names, value) {
|
|
305
|
-
const zoneIndex = value.indexOf("%");
|
|
306
|
-
const address = zoneIndex === -1 ? value : value.slice(0, zoneIndex);
|
|
307
|
-
const zone = zoneIndex === -1 ? "" : `s${value.slice(zoneIndex + 1)}`;
|
|
308
|
-
addLocalServerName(names, `${address.replaceAll(":", "-")}${zone}.ipv6-literal.net`);
|
|
309
|
-
}
|
|
310
|
-
function collectLocalServerNames() {
|
|
311
|
-
const names = /* @__PURE__ */ new Set(["localhost"]);
|
|
312
|
-
const computerName = process.env.COMPUTERNAME;
|
|
313
|
-
addLocalServerName(names, hostname());
|
|
314
|
-
addLocalServerName(names, computerName);
|
|
315
|
-
if (computerName !== void 0 && process.env.USERDNSDOMAIN !== void 0) addLocalServerName(names, `${computerName}.${process.env.USERDNSDOMAIN}`);
|
|
316
|
-
for (const addresses of Object.values(networkInterfaces())) for (const address of addresses ?? []) if (isIP(address.address) === 4) addLocalServerName(names, address.address);
|
|
317
|
-
else if (isIP(address.address) === 6) addIpv6LiteralName(names, address.address);
|
|
318
|
-
addLocalServerName(names, "--1.ipv6-literal.net");
|
|
319
|
-
return names;
|
|
320
|
-
}
|
|
321
|
-
const localServerNames = collectLocalServerNames();
|
|
322
|
-
function containsControlCharacter(value) {
|
|
323
|
-
return [...value].some((character) => character.charCodeAt(0) < 32);
|
|
324
|
-
}
|
|
325
|
-
function resolveLocalUncPath(value) {
|
|
326
|
-
if (process.platform !== "win32" || !value.startsWith("\\\\")) return value;
|
|
327
|
-
if (containsControlCharacter(value)) return;
|
|
328
|
-
const extended = value.slice(0, 8).toLowerCase() === "\\\\?\\unc\\";
|
|
329
|
-
if (value.startsWith("\\\\.\\") || value.startsWith("\\\\?\\") && !extended) return;
|
|
330
|
-
const serverStart = extended ? 8 : 2;
|
|
331
|
-
const serverSeparator = value.slice(serverStart).search(/[\\/]/u);
|
|
332
|
-
if (serverSeparator <= 0) return;
|
|
333
|
-
const serverEnd = serverStart + serverSeparator;
|
|
334
|
-
const shareStart = serverEnd + 1;
|
|
335
|
-
const shareSeparator = value.slice(shareStart).search(/[\\/]/u);
|
|
336
|
-
const shareEnd = shareSeparator === -1 ? value.length : shareStart + shareSeparator;
|
|
337
|
-
const server = value.slice(serverStart, serverEnd);
|
|
338
|
-
const share = value.slice(shareStart, shareEnd);
|
|
339
|
-
if (share.length === 0 || !uncServerSegmentPattern.test(server) || !uncServerSegmentPattern.test(share)) return;
|
|
340
|
-
const normalizedServer = normalizeServerName(server);
|
|
341
|
-
if (!(isIP(server) === 4 && server.split(".")[0] === "127" || normalizedServer === "--1.ipv6-literal.net") && !localServerNames.has(normalizedServer)) return;
|
|
342
|
-
return `${extended ? "\\\\?\\UNC\\" : "\\\\"}localhost${value.slice(serverEnd)}`;
|
|
343
|
-
}
|
|
344
|
-
//#endregion
|
|
345
407
|
//#region src/filesystem.ts
|
|
346
408
|
function pathKey(value) {
|
|
347
409
|
return process.platform === "win32" ? value.toLowerCase() : value;
|
|
@@ -425,9 +487,9 @@ function toPaths(value, roots, variables) {
|
|
|
425
487
|
expanded = unescape(expanded);
|
|
426
488
|
if (expanded === "~" || /^~[\\/]/u.test(expanded)) expanded = nodePath.join(variables.HOME ?? variables.USERPROFILE ?? process.env.HOME ?? process.env.USERPROFILE ?? "", expanded.slice(2));
|
|
427
489
|
}
|
|
428
|
-
const
|
|
429
|
-
if (
|
|
430
|
-
expanded =
|
|
490
|
+
const resolvedPath = resolveUncPath(expanded);
|
|
491
|
+
if (resolvedPath === void 0 || resolvedPath.length === 0) return [];
|
|
492
|
+
expanded = resolvedPath;
|
|
431
493
|
if (nodePath.isAbsolute(expanded)) return [nodePath.normalize(expanded)];
|
|
432
494
|
return uniquePaths(roots.map((root) => nodePath.resolve(root, expanded)));
|
|
433
495
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["pathKey","pathKey"],"sources":["../config/settings.ts","../src/variables/index.ts","../src/candidates.ts","../src/existence.ts","../src/policy.ts","../src/unc.ts","../src/filesystem.ts","../src/inventory.ts","../src/index.ts"],"sourcesContent":["import type { SearchSettings } from \"../src/types.js\";\n\nexport const settings: SearchSettings = {\n batchValidationThreshold: 48,\n directoryScanThreshold: 2,\n ignoreFilePatterns: [\"**/.ignore\", \"**/.rgignore\"],\n locationSuffixPattern: /:(?<line>\\d+)(?::(?<column>\\d+))?$/u,\n respectIgnoreByDefault: true,\n searchHiddenByDefault: false,\n spanWordLimits: [3, 8, 24],\n trailingPunctuation: \".,;:!?,。;:!?、\",\n validationConcurrency: 32,\n};\n","import type { Variables } from \"../types.js\";\n\nconst nameSource = String.raw`[A-Za-z_][A-Za-z0-9_.-]*`;\nexport const variableReferenceSource = String.raw`(?:\\$\\{\\{\\s*(?:(?:env|vars|variables)[.:])?${nameSource}\\s*\\}\\}|\\{\\{\\s*${nameSource}\\s*\\}\\}|\\$\\{(?:env[.:])?${nameSource}\\}|\\$env:${nameSource}|\\$[A-Za-z_][A-Za-z0-9_]*|%${nameSource}%|!${nameSource}!|\\$\\(\\s*${nameSource}\\s*\\)|@${nameSource}@)`;\nconst expressionPatterns = [\n new RegExp(String.raw`\\$\\{\\{\\s*(?:(?:env|vars|variables)[.:])?(${nameSource})\\s*\\}\\}`, \"giu\"),\n new RegExp(String.raw`\\{\\{\\s*(${nameSource})\\s*\\}\\}`, \"gu\"),\n new RegExp(String.raw`\\$\\{(?:env[.:])?(${nameSource})\\}`, \"giu\"),\n new RegExp(String.raw`\\$env:(${nameSource})`, \"giu\"),\n new RegExp(String.raw`\\$(?!env:)([A-Za-z_][A-Za-z0-9_]*)`, \"giu\"),\n new RegExp(String.raw`%(${nameSource})%`, \"gu\"),\n new RegExp(String.raw`!(${nameSource})!`, \"gu\"),\n new RegExp(String.raw`\\$\\(\\s*(${nameSource})\\s*\\)`, \"gu\"),\n new RegExp(String.raw`@(${nameSource})@`, \"gu\"),\n];\nfunction resolveVariable(name: string, variables: Variables): string | undefined {\n const direct = variables[name] ?? process.env[name];\n if (direct !== undefined) {\n return direct;\n }\n const unscoped = /^(?:env|vars|variables)[.:](.+)$/iu.exec(name)?.[1];\n return unscoped === undefined ? undefined : (variables[unscoped] ?? process.env[unscoped]);\n}\nexport function expandVariables(value: string, variables: Variables): string {\n let result = value;\n for (const pattern of expressionPatterns) {\n result = result.replace(pattern, (match, name: string) => {\n const replacement = resolveVariable(name, variables);\n return replacement === undefined ? match : replacement;\n });\n }\n return result;\n}\n","import type { Candidate, SearchLevel } from \"./types.js\";\nimport { settings } from \"../config/settings.js\";\nimport { variableReferenceSource } from \"./variables/index.js\";\n\nconst explicitPattern =\n /(?:file:\\/\\/\\/?|[A-Za-z]:[\\\\/]|\\\\\\\\|\\/|(?:\\.{1,2}|~)[\\\\/])[^\"'`<>()[\\]{}\\s]+/gu;\nconst quotedPattern = /([\"'`])(?<value>[^\"'`\\r\\n]+)\\1/gu;\nconst tokenPattern = /[^\\s]+/gu;\nconst pathTokenPattern =\n /(?:(?:[\\p{L}\\p{N}_@%$+~.#[\\],-]+[\\\\/])+(?:[\\p{L}\\p{N}_@%$+~.#[\\],-]+)|[\\p{L}\\p{N}_@%$+~.#[\\],-]+\\.[\\p{L}\\p{N}_@%$-]{1,16})(?::\\d+){0,2}/gu;\nconst unquotedPathCharacterSource = \"[^\\\"'`<>()[\\\\]{}\\\\s]\";\nconst variablePathPattern = new RegExp(\n `${variableReferenceSource}(?:[\\\\\\\\/]${unquotedPathCharacterSource}+)+`,\n \"giu\",\n);\nconst clausePattern = /[^\\r\\n!?!?;;。]+/gu;\nconst pathHintPattern =\n /[\\\\/]|(?:^|[\\s\"'`])(?:\\.{1,2}|~|%[A-Za-z_][A-Za-z0-9_]*%|\\$\\{?[A-Za-z_][A-Za-z0-9_]*\\}?)(?:[\\\\/]|$)|\\.[\\p{L}\\p{N}]{1,16}(?::\\d+){0,2}(?:$|[\\s,.;:!?,。;:!?、])/u;\nconst variableHintPattern = new RegExp(String.raw`${variableReferenceSource}(?:[\\\\/]|$)`, \"iu\");\nfunction add(\n result: Candidate[],\n seen: Set<string>,\n value: string,\n start: number,\n end: number,\n kind: Candidate[\"kind\"],\n): void {\n if (value.length === 0) {\n return;\n }\n const key = `${start}:${end}:${value}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push({ end, kind, start, value });\n }\n}\nfunction addMatches(\n result: Candidate[],\n seen: Set<string>,\n text: string,\n pattern: RegExp,\n kind: Candidate[\"kind\"],\n): void {\n for (const match of text.matchAll(pattern)) {\n const value = match[0];\n const start = match.index ?? 0;\n add(result, seen, value, start, start + value.length, kind);\n }\n}\nfunction addQuotedMatches(result: Candidate[], seen: Set<string>, text: string): void {\n for (const match of text.matchAll(quotedPattern)) {\n const value = match.groups?.value;\n if (value === undefined) {\n continue;\n }\n const start = (match.index ?? 0) + match[0].indexOf(value);\n add(result, seen, value, start, start + value.length, \"quoted\");\n }\n}\nfunction addSpanMatches(\n result: Candidate[],\n seen: Set<string>,\n text: string,\n maximumWords: number,\n): void {\n for (const clause of text.matchAll(clausePattern)) {\n const clauseStart = clause.index ?? 0;\n const clauseText = clause[0];\n const tokens = [...clauseText.matchAll(tokenPattern)].map((token) => ({\n end: clauseStart + (token.index ?? 0) + token[0].length,\n hint: Number(pathHintPattern.test(token[0]) || variableHintPattern.test(token[0])),\n start: clauseStart + (token.index ?? 0),\n value: token[0],\n }));\n const hintCounts = [0];\n for (const token of tokens) {\n hintCounts.push((hintCounts.at(-1) ?? 0) + token.hint);\n }\n for (let start = 0; start < tokens.length; start += 1) {\n const last = Math.min(tokens.length, start + maximumWords);\n for (let end = start + 1; end <= last; end += 1) {\n const firstToken = tokens[start];\n const lastToken = tokens[end - 1];\n const hintsBefore = hintCounts[start];\n const hintsAfter = hintCounts[end];\n if (\n firstToken === undefined ||\n lastToken === undefined ||\n hintsBefore === undefined ||\n hintsAfter === undefined ||\n hintsBefore === hintsAfter\n ) {\n continue;\n }\n const value = text.slice(firstToken.start, lastToken.end);\n if (pathHintPattern.test(value)) {\n add(result, seen, value, firstToken.start, lastToken.end, \"span\");\n }\n }\n }\n }\n}\nexport function extractCandidates(text: string, level: SearchLevel): Candidate[] {\n const result: Candidate[] = [];\n const seen = new Set<string>();\n addQuotedMatches(result, seen, text);\n addMatches(result, seen, text, explicitPattern, \"explicit\");\n if (level >= 2) {\n addMatches(result, seen, text, variablePathPattern, \"heuristic\");\n addMatches(result, seen, text, pathTokenPattern, \"heuristic\");\n }\n if (level >= 3) {\n const maximumWords =\n settings.spanWordLimits[Math.min(level - 3, settings.spanWordLimits.length - 1)];\n if (maximumWords === undefined) {\n throw new RangeError(\"No text-span level is configured\");\n }\n addSpanMatches(result, seen, text, maximumWords);\n }\n return result;\n}\n","import { readdir, stat } from \"node:fs/promises\";\nimport nodePath from \"node:path\";\nimport pLimit from \"p-limit\";\nimport { settings } from \"../config/settings.js\";\nimport type { PathKind } from \"./types.js\";\n\nconst knownFileErrors = new Set([\n \"EACCES\",\n \"ELOOP\",\n \"ENAMETOOLONG\",\n \"ENOTDIR\",\n \"ENOENT\",\n \"EPERM\",\n \"EINVAL\",\n]);\nconst unverifiableUncErrors = new Set([\"UNKNOWN\", \"EUNKNOWN\"]);\nfunction pathKey(value: string): string {\n return process.platform === \"win32\" ? value.toLowerCase() : value;\n}\nfunction fileErrorCode(error: unknown): string | undefined {\n if (error instanceof Error && \"code\" in error && typeof error.code === \"string\") {\n return error.code;\n }\n return undefined;\n}\nfunction isKnownFileError(error: unknown, filePath?: string): boolean {\n const code = fileErrorCode(error);\n return (\n code !== undefined &&\n (knownFileErrors.has(code) ||\n (filePath?.startsWith(\"\\\\\\\\\") === true && unverifiableUncErrors.has(code)))\n );\n}\nasync function classifyPath(filePath: string): Promise<PathKind | undefined> {\n try {\n const pathStats = await stat(filePath);\n if (pathStats.isFile()) {\n return \"file\";\n }\n return pathStats.isDirectory() ? \"directory\" : undefined;\n } catch (error) {\n if (isKnownFileError(error, filePath)) {\n return undefined;\n }\n throw error;\n }\n}\nasync function classifyAndAdd(found: Map<string, PathKind>, filePath: string): Promise<void> {\n const kind = await classifyPath(filePath);\n if (kind !== undefined) {\n found.set(filePath, kind);\n }\n}\nexport async function classifyExistingPaths(\n paths: readonly string[],\n roots: readonly string[],\n): Promise<Map<string, PathKind>> {\n const found = new Map<string, PathKind>();\n const limit = pLimit(settings.validationConcurrency);\n if (paths.length < settings.batchValidationThreshold) {\n await Promise.all(paths.map((filePath) => limit(() => classifyAndAdd(found, filePath))));\n return found;\n }\n const rootKeys = new Set(roots.map(pathKey));\n const pathsByParent = new Map<string, { parent: string; paths: string[] }>();\n for (const filePath of paths) {\n if (rootKeys.has(pathKey(filePath))) {\n found.set(filePath, \"directory\");\n continue;\n }\n const parent = nodePath.dirname(filePath);\n const key = pathKey(parent);\n const group = pathsByParent.get(key) ?? { parent, paths: [] };\n group.paths.push(filePath);\n pathsByParent.set(key, group);\n }\n const directPaths: string[] = [];\n const scannedGroups: { parent: string; paths: string[] }[] = [];\n for (const group of pathsByParent.values()) {\n if (group.paths.length < settings.directoryScanThreshold) {\n directPaths.push(...group.paths);\n } else {\n scannedGroups.push(group);\n }\n }\n await Promise.all([\n ...directPaths.map((filePath) => limit(() => classifyAndAdd(found, filePath))),\n ...scannedGroups.map(({ parent, paths: groupPaths }) =>\n limit(async () => {\n let entries;\n try {\n entries = await readdir(parent, { withFileTypes: true });\n } catch (error) {\n if (isKnownFileError(error, parent)) {\n return;\n }\n throw error;\n }\n const entriesByName = new Map(entries.map((entry) => [pathKey(entry.name), entry]));\n await Promise.all(\n groupPaths.map(async (filePath) => {\n const name = nodePath.basename(filePath);\n const entry = entriesByName.get(pathKey(name));\n if (entry?.isFile()) {\n found.set(filePath, \"file\");\n } else if (entry?.isDirectory()) {\n found.set(filePath, \"directory\");\n } else if (\n entry !== undefined ||\n (process.platform === \"win32\" && name.includes(\":\"))\n ) {\n await classifyAndAdd(found, filePath);\n }\n }),\n );\n }),\n ),\n ]);\n return found;\n}\n","import { stat } from \"node:fs/promises\";\nimport nodePath from \"node:path\";\nimport fastGlob from \"fast-glob\";\nimport { convertPathToPattern, globby } from \"globby\";\nimport { settings } from \"../config/settings.js\";\n\nfunction pathKey(value: string): string {\n return process.platform === \"win32\" ? value.toLowerCase() : value;\n}\nfunction isWithinRoot(filePath: string, root: string): boolean {\n const relative = nodePath.relative(root, filePath);\n return (\n relative === \"\" ||\n (relative !== \"..\" &&\n !relative.startsWith(`..${nodePath.sep}`) &&\n !nodePath.isAbsolute(relative))\n );\n}\nfunction isHidden(relativePath: string): boolean {\n return relativePath.split(/[\\\\/]/u).some((part) => part.length > 1 && part.startsWith(\".\"));\n}\nfunction traversalOptions(root: string, searchHidden: boolean) {\n return {\n caseSensitiveMatch: process.platform !== \"win32\",\n cwd: root,\n dot: searchHidden,\n followSymbolicLinks: false,\n onlyFiles: false,\n unique: true,\n } as const;\n}\nfunction globbyOptions(root: string, respectIgnore: boolean, searchHidden: boolean) {\n return {\n ...traversalOptions(root, searchHidden),\n expandDirectories: false,\n gitignore: respectIgnore,\n globalGitignore: respectIgnore,\n ...(respectIgnore ? { ignoreFiles: settings.ignoreFilePatterns } : {}),\n } as const;\n}\nexport async function resolveSearchDirectories(directories: readonly string[]): Promise<string[]> {\n if (!Array.isArray(directories)) {\n throw new TypeError(\"directories must be an array\");\n }\n if (directories.length === 0) {\n throw new RangeError(\"directories must not be empty\");\n }\n const unique = new Map<string, string>();\n for (const directory of directories) {\n if (typeof directory !== \"string\" || directory.length === 0) {\n throw new TypeError(\"every directory must be a non-empty string\");\n }\n const resolved = nodePath.resolve(directory);\n unique.set(pathKey(resolved), resolved);\n }\n await Promise.all(\n [...unique.values()].map(async (directory) => {\n if (!(await stat(directory)).isDirectory()) {\n throw new TypeError(`${directory} is not a directory`);\n }\n }),\n );\n return [...unique.values()];\n}\nexport async function listSearchEntries(\n root: string,\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<string[]> {\n if (!respectIgnore) {\n return fastGlob(\"**/*\", traversalOptions(root, searchHidden));\n }\n return globby(\"**/*\", globbyOptions(root, respectIgnore, searchHidden));\n}\nexport async function filterSearchablePaths(\n paths: readonly string[],\n roots: readonly string[],\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<Set<string>> {\n const allowed = new Set<string>();\n const pathsByRoot = new Map<string, string[]>();\n for (const filePath of paths) {\n let hasSearchRoot = false;\n for (const root of roots) {\n if (!isWithinRoot(filePath, root)) {\n continue;\n }\n hasSearchRoot = true;\n const relative = nodePath.relative(root, filePath);\n if (!searchHidden && isHidden(relative)) {\n continue;\n }\n if (relative === \"\" || !respectIgnore) {\n allowed.add(filePath);\n } else {\n const grouped = pathsByRoot.get(root) ?? [];\n grouped.push(relative);\n pathsByRoot.set(root, grouped);\n }\n }\n if (hasSearchRoot) {\n continue;\n }\n const filesystemRelative = nodePath.relative(nodePath.parse(filePath).root, filePath);\n if (searchHidden || !isHidden(filesystemRelative)) {\n allowed.add(filePath);\n }\n }\n await Promise.all(\n [...pathsByRoot].map(async ([root, relativePaths]) => {\n const patterns = relativePaths.map(convertPathToPattern);\n const matches = await globby(patterns, {\n ...globbyOptions(root, true, true),\n absolute: true,\n });\n for (const match of matches) {\n allowed.add(nodePath.normalize(match));\n }\n }),\n );\n return allowed;\n}\n","import { isIP } from \"node:net\";\nimport { hostname, networkInterfaces } from \"node:os\";\n\nconst uncServerSegmentPattern = /^[^\\\\/:*?\"<>|]+$/u;\nfunction normalizeServerName(value: string): string {\n return value.replace(/\\.+$/u, \"\").toLowerCase();\n}\nfunction addLocalServerName(names: Set<string>, value: string | undefined): void {\n if (value !== undefined && uncServerSegmentPattern.test(value)) {\n names.add(normalizeServerName(value));\n }\n}\nfunction addIpv6LiteralName(names: Set<string>, value: string): void {\n const zoneIndex = value.indexOf(\"%\");\n const address = zoneIndex === -1 ? value : value.slice(0, zoneIndex);\n const zone = zoneIndex === -1 ? \"\" : `s${value.slice(zoneIndex + 1)}`;\n addLocalServerName(names, `${address.replaceAll(\":\", \"-\")}${zone}.ipv6-literal.net`);\n}\nfunction collectLocalServerNames(): Set<string> {\n const names = new Set<string>([\"localhost\"]);\n const computerName = process.env.COMPUTERNAME;\n addLocalServerName(names, hostname());\n addLocalServerName(names, computerName);\n if (computerName !== undefined && process.env.USERDNSDOMAIN !== undefined) {\n addLocalServerName(names, `${computerName}.${process.env.USERDNSDOMAIN}`);\n }\n for (const addresses of Object.values(networkInterfaces())) {\n for (const address of addresses ?? []) {\n if (isIP(address.address) === 4) {\n addLocalServerName(names, address.address);\n } else if (isIP(address.address) === 6) {\n addIpv6LiteralName(names, address.address);\n }\n }\n }\n addLocalServerName(names, \"--1.ipv6-literal.net\");\n return names;\n}\nconst localServerNames = collectLocalServerNames();\nfunction containsControlCharacter(value: string): boolean {\n return [...value].some((character) => character.charCodeAt(0) < 32);\n}\nexport function resolveLocalUncPath(value: string): string | undefined {\n if (process.platform !== \"win32\" || !value.startsWith(\"\\\\\\\\\")) {\n return value;\n }\n if (containsControlCharacter(value)) {\n return undefined;\n }\n const extended = value.slice(0, 8).toLowerCase() === \"\\\\\\\\?\\\\unc\\\\\";\n if (value.startsWith(\"\\\\\\\\.\\\\\") || (value.startsWith(\"\\\\\\\\?\\\\\") && !extended)) {\n return undefined;\n }\n const serverStart = extended ? 8 : 2;\n const serverSeparator = value.slice(serverStart).search(/[\\\\/]/u);\n if (serverSeparator <= 0) {\n return undefined;\n }\n const serverEnd = serverStart + serverSeparator;\n const shareStart = serverEnd + 1;\n const shareSeparator = value.slice(shareStart).search(/[\\\\/]/u);\n const shareEnd = shareSeparator === -1 ? value.length : shareStart + shareSeparator;\n const server = value.slice(serverStart, serverEnd);\n const share = value.slice(shareStart, shareEnd);\n if (\n share.length === 0 ||\n !uncServerSegmentPattern.test(server) ||\n !uncServerSegmentPattern.test(share)\n ) {\n return undefined;\n }\n const normalizedServer = normalizeServerName(server);\n const isLoopback =\n (isIP(server) === 4 && server.split(\".\")[0] === \"127\") ||\n normalizedServer === \"--1.ipv6-literal.net\";\n if (!isLoopback && !localServerNames.has(normalizedServer)) {\n return undefined;\n }\n const prefix = extended ? \"\\\\\\\\?\\\\UNC\\\\\" : \"\\\\\\\\\";\n return `${prefix}localhost${value.slice(serverEnd)}`;\n}\n","import { fileURLToPath } from \"node:url\";\nimport nodePath from \"node:path\";\nimport { classifyExistingPaths } from \"./existence.js\";\nimport { filterSearchablePaths } from \"./policy.js\";\nimport { expandVariables } from \"./variables/index.js\";\nimport { resolveLocalUncPath } from \"./unc.js\";\nimport { settings } from \"../config/settings.js\";\nimport type { Candidate, PathLocation, PathMatch, PathPosition, Variables } from \"./types.js\";\n\ninterface ResolvedCandidate {\n location?: PathLocation;\n path: string;\n position: PathPosition;\n}\ninterface PreparedCandidate {\n location?: PathLocation;\n position: PathPosition;\n value: string;\n}\nfunction pathKey(value: string): string {\n return process.platform === \"win32\" ? value.toLowerCase() : value;\n}\nfunction uniquePaths(values: Iterable<string>): string[] {\n const paths = new Map<string, string>();\n for (const value of values) {\n paths.set(pathKey(value), value);\n }\n return [...paths.values()];\n}\nfunction parseLocationPart(value: string, name: string): number {\n const result = Number(value);\n if (!Number.isSafeInteger(result)) {\n throw new RangeError(`${name} must be a safe integer`);\n }\n return result;\n}\nfunction prepareCandidate(candidate: Candidate): PreparedCandidate {\n let end = candidate.end;\n let start = candidate.start;\n let value = candidate.value;\n if (candidate.kind !== \"inventory\" && candidate.kind !== \"quoted\") {\n const startTrimmed = value.trimStart();\n start += value.length - startTrimmed.length;\n value = startTrimmed;\n const endTrimmed = value.trimEnd();\n end -= value.length - endTrimmed.length;\n value = endTrimmed;\n if (\n value.length >= 2 &&\n ((value[0] === '\"' && value.at(-1) === '\"') ||\n (value[0] === \"'\" && value.at(-1) === \"'\") ||\n (value[0] === \"`\" && value.at(-1) === \"`\"))\n ) {\n start += 1;\n end -= 1;\n value = value.slice(1, -1);\n }\n while (value.length > 0 && settings.trailingPunctuation.includes(value.at(-1) ?? \"\")) {\n end -= 1;\n value = value.slice(0, -1);\n }\n }\n if (candidate.kind === \"inventory\") {\n return { position: { end, start }, value };\n }\n const match = settings.locationSuffixPattern.exec(value);\n if (match === null) {\n return { position: { end, start }, value };\n }\n const lineValue = match.groups?.line;\n if (lineValue === undefined) {\n throw new TypeError(\"locationSuffixPattern must capture a line\");\n }\n const columnValue = match.groups?.column;\n const location: PathLocation =\n columnValue === undefined\n ? { line: parseLocationPart(lineValue, \"line\") }\n : {\n column: parseLocationPart(columnValue, \"column\"),\n line: parseLocationPart(lineValue, \"line\"),\n };\n end -= match[0].length;\n return {\n location,\n position: { end, start },\n value: value.slice(0, match.index),\n };\n}\nfunction unescape(value: string): string {\n if (value.startsWith(\"\\\\\\\\\") && !value.startsWith(\"\\\\\\\\\\\\\\\\\")) {\n return value;\n }\n return value.replace(/\\\\([\"'`\\\\])/gu, \"$1\").replace(/\\\\\\\\/gu, \"\\\\\");\n}\nfunction toPaths(value: string, roots: readonly string[], variables: Variables): string[] {\n let expanded = expandVariables(value, variables);\n if (expanded.startsWith(\"file://\")) {\n try {\n expanded = fileURLToPath(expanded);\n } catch (error) {\n if (error instanceof TypeError) {\n return [];\n }\n throw error;\n }\n } else {\n expanded = unescape(expanded);\n if (expanded === \"~\" || /^~[\\\\/]/u.test(expanded)) {\n expanded = nodePath.join(\n variables.HOME ??\n variables.USERPROFILE ??\n process.env.HOME ??\n process.env.USERPROFILE ??\n \"\",\n expanded.slice(2),\n );\n }\n }\n const localUncPath = resolveLocalUncPath(expanded);\n if (localUncPath === undefined || localUncPath.length === 0) {\n return [];\n }\n expanded = localUncPath;\n if (nodePath.isAbsolute(expanded)) {\n return [nodePath.normalize(expanded)];\n }\n return uniquePaths(roots.map((root) => nodePath.resolve(root, expanded)));\n}\nfunction mergeLocation(match: PathMatch, location: PathLocation | undefined): void {\n if (location === undefined) {\n return;\n }\n if (match.location === undefined) {\n match.location = location;\n return;\n }\n if (match.location.line !== location.line || match.location.column !== location.column) {\n throw new Error(\"Candidates for the same path and position have conflicting locations\");\n }\n}\nexport async function validateCandidates(\n candidates: Candidate[],\n roots: readonly string[],\n variables: Variables,\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<PathMatch[]> {\n const resolvedCandidates: ResolvedCandidate[] = [];\n const validationPaths = new Map<string, string>();\n for (const candidate of candidates) {\n const prepared = prepareCandidate(candidate);\n const paths = toPaths(prepared.value, roots, variables);\n for (const filePath of paths) {\n resolvedCandidates.push({\n ...(prepared.location === undefined ? {} : { location: prepared.location }),\n path: filePath,\n position: prepared.position,\n });\n validationPaths.set(pathKey(filePath), filePath);\n }\n }\n let searchablePaths = [...validationPaths.values()];\n if (respectIgnore || !searchHidden) {\n searchablePaths = [\n ...(await filterSearchablePaths(searchablePaths, roots, respectIgnore, searchHidden)),\n ];\n }\n const classifiedPaths = await classifyExistingPaths(searchablePaths, roots);\n const kindsByPath = new Map(\n [...classifiedPaths].map(([filePath, kind]) => [pathKey(filePath), kind]),\n );\n const matches = new Map<string, PathMatch>();\n for (const { location, path, position } of resolvedCandidates) {\n const kind = kindsByPath.get(pathKey(path));\n if (kind === undefined) {\n continue;\n }\n const key = `${pathKey(path)}\\0${position.start}\\0${position.end}`;\n const existing = matches.get(key);\n if (existing !== undefined) {\n mergeLocation(existing, location);\n continue;\n }\n matches.set(key, {\n kind,\n ...(location === undefined ? {} : { location }),\n path,\n position,\n });\n }\n return [...matches.values()];\n}\n","import nodePath from \"node:path\";\nimport { listSearchEntries } from \"./policy.js\";\nimport type { Candidate } from \"./types.js\";\n\nfunction isBoundary(value: string | undefined, following: string | undefined): boolean {\n if (value === \".\") {\n return following === undefined || !/[\\p{L}\\p{N}_-]/u.test(following);\n }\n return value === undefined || !/[\\p{L}\\p{N}_/\\\\-]/u.test(value);\n}\nfunction addOccurrences(\n result: Candidate[],\n seen: Set<string>,\n source: string,\n text: string,\n value: string,\n): void {\n const target = process.platform === \"win32\" ? value.toLowerCase() : value;\n let offset = source.indexOf(target);\n while (offset !== -1) {\n const end = offset + target.length;\n if (isBoundary(text[offset - 1], text[offset]) && isBoundary(text[end], text[end + 1])) {\n const key = `${offset}:${end}:${text.slice(offset, end)}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push({\n end,\n kind: \"inventory\",\n start: offset,\n value,\n });\n }\n }\n offset = source.indexOf(target, offset + 1);\n }\n}\nexport async function inventoryCandidates(\n text: string,\n roots: readonly string[],\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<Candidate[]> {\n const entries = await Promise.all(\n roots.map((root) => listSearchEntries(root, respectIgnore, searchHidden)),\n );\n const result: Candidate[] = [];\n const seen = new Set<string>();\n const scanned = new Set<string>();\n const source = process.platform === \"win32\" ? text.toLowerCase() : text;\n for (const [rootIndex, relativeEntries] of entries.entries()) {\n const root = roots[rootIndex];\n if (root === undefined) {\n continue;\n }\n for (const relativeEntry of relativeEntries) {\n const absoluteEntry = nodePath.resolve(root, relativeEntry);\n const variants = [\n relativeEntry,\n relativeEntry.replaceAll(\"/\", nodePath.sep),\n absoluteEntry,\n absoluteEntry.replaceAll(nodePath.sep, \"/\"),\n ];\n for (const value of variants) {\n const key = process.platform === \"win32\" ? value.toLowerCase() : value;\n if (!scanned.has(key)) {\n scanned.add(key);\n addOccurrences(result, seen, source, text, value);\n }\n }\n }\n }\n return result;\n}\n","import { extractCandidates } from \"./candidates.js\";\nimport { validateCandidates } from \"./filesystem.js\";\nimport { inventoryCandidates } from \"./inventory.js\";\nimport { resolveSearchDirectories } from \"./policy.js\";\nimport { settings } from \"../config/settings.js\";\nimport type { PathMatch, SearchLevel, Variables } from \"./types.js\";\n\nexport const MAX_LEVEL = settings.spanWordLimits.length + 3;\nfunction validateVariables(value: unknown): asserts value is Variables {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n Object.values(value).some((item) => typeof item !== \"string\")\n ) {\n throw new TypeError(\"variables must be an object of string values\");\n }\n}\nexport async function findExistingPaths(\n text: string,\n level: SearchLevel,\n directories: readonly string[],\n variables: Variables = {},\n respectIgnore: boolean = settings.respectIgnoreByDefault,\n searchHidden: boolean = settings.searchHiddenByDefault,\n): Promise<PathMatch[]> {\n if (typeof text !== \"string\") {\n throw new TypeError(\"text must be a string\");\n }\n if (!Number.isInteger(level) || level < 1 || level > MAX_LEVEL) {\n throw new RangeError(`level must be an integer from 1 to ${MAX_LEVEL}`);\n }\n validateVariables(variables);\n if (typeof respectIgnore !== \"boolean\") {\n throw new TypeError(\"respectIgnore must be a boolean\");\n }\n if (typeof searchHidden !== \"boolean\") {\n throw new TypeError(\"searchHidden must be a boolean\");\n }\n const roots = await resolveSearchDirectories(directories);\n const candidates = extractCandidates(text, level);\n if (level === MAX_LEVEL) {\n candidates.push(...(await inventoryCandidates(text, roots, respectIgnore, searchHidden)));\n }\n return validateCandidates(candidates, roots, variables, respectIgnore, searchHidden);\n}\nexport type {\n PathKind,\n PathLocation,\n PathMatch,\n PathPosition,\n SearchLevel,\n Variables,\n} from \"./types.js\";\n"],"mappings":";;;;;;;;;AAEA,MAAa,WAA2B;CACtC,0BAA0B;CAC1B,wBAAwB;CACxB,oBAAoB,CAAC,cAAc,cAAc;CACjD,uBAAuB;CACvB,wBAAwB;CACxB,uBAAuB;CACvB,gBAAgB;EAAC;EAAG;EAAG;CAAE;CACzB,qBAAqB;CACrB,uBAAuB;AACzB;;;ACVA,MAAM,aAAa,OAAO,GAAG;AAC7B,MAAa,0BAA0B,OAAO,GAAG,8CAA8C,WAAW,iBAAiB,WAAW,0BAA0B,WAAW,WAAW,WAAW,6BAA6B,WAAW,KAAK,WAAW,WAAW,WAAW,SAAS,WAAW;AACnS,MAAM,qBAAqB;CACzB,IAA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OAAO,mBAAmB,YAAY,OAAO,WAAW,eAAe,YAAY;AACrF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["pathKey","pathKey"],"sources":["../config/settings.ts","../src/variables/index.ts","../src/candidates.ts","../src/existence.ts","../src/native/unc.ts","../src/policy.ts","../src/filesystem.ts","../src/inventory.ts","../src/index.ts"],"sourcesContent":["import type { SearchSettings } from \"../src/types.js\";\n\nexport const settings: SearchSettings = {\n batchValidationThreshold: 48,\n directoryScanThreshold: 2,\n ignoreFilePatterns: [\"**/.ignore\", \"**/.rgignore\"],\n locationSuffixPattern: /:(?<line>\\d+)(?::(?<column>\\d+))?$/u,\n respectIgnoreByDefault: true,\n searchHiddenByDefault: false,\n spanWordLimits: [3, 24],\n trailingPunctuation: \".,;:!?,。;:!?、\",\n validationConcurrency: 32,\n};\n","import type { Variables } from \"../types.js\";\n\nconst nameSource = String.raw`[A-Za-z_][A-Za-z0-9_.-]*`;\nexport const variableReferenceSource = String.raw`(?:\\$\\{\\{\\s*(?:(?:env|vars|variables)[.:])?${nameSource}\\s*\\}\\}|\\{\\{\\s*${nameSource}\\s*\\}\\}|\\$\\{(?:env[.:])?${nameSource}\\}|\\$env:${nameSource}|\\$[A-Za-z_][A-Za-z0-9_]*|%${nameSource}%|!${nameSource}!|\\$\\(\\s*${nameSource}\\s*\\)|@${nameSource}@)`;\nconst expressionPatterns = [\n new RegExp(String.raw`\\$\\{\\{\\s*(?:(?:env|vars|variables)[.:])?(${nameSource})\\s*\\}\\}`, \"giu\"),\n new RegExp(String.raw`\\{\\{\\s*(${nameSource})\\s*\\}\\}`, \"gu\"),\n new RegExp(String.raw`\\$\\{(?:env[.:])?(${nameSource})\\}`, \"giu\"),\n new RegExp(String.raw`\\$env:(${nameSource})`, \"giu\"),\n new RegExp(String.raw`\\$(?!env:)([A-Za-z_][A-Za-z0-9_]*)`, \"giu\"),\n new RegExp(String.raw`%(${nameSource})%`, \"gu\"),\n new RegExp(String.raw`!(${nameSource})!`, \"gu\"),\n new RegExp(String.raw`\\$\\(\\s*(${nameSource})\\s*\\)`, \"gu\"),\n new RegExp(String.raw`@(${nameSource})@`, \"gu\"),\n];\nfunction resolveVariable(name: string, variables: Variables): string | undefined {\n const direct = variables[name] ?? process.env[name];\n if (direct !== undefined) {\n return direct;\n }\n const unscoped = /^(?:env|vars|variables)[.:](.+)$/iu.exec(name)?.[1];\n return unscoped === undefined ? undefined : (variables[unscoped] ?? process.env[unscoped]);\n}\nexport function expandVariables(value: string, variables: Variables): string {\n let result = value;\n for (const pattern of expressionPatterns) {\n result = result.replace(pattern, (match, name: string) => {\n const replacement = resolveVariable(name, variables);\n return replacement === undefined ? match : replacement;\n });\n }\n return result;\n}\n","import type { Candidate, SearchLevel } from \"./types.js\";\nimport { settings } from \"../config/settings.js\";\nimport { variableReferenceSource } from \"./variables/index.js\";\n\nconst explicitPattern =\n /(?:file:\\/\\/\\/?|[A-Za-z]:[\\\\/]|\\\\\\\\|\\/|(?:\\.{1,2}|~)[\\\\/])[^\"'`<>()[\\]{}\\s]+/gu;\nconst quotedPattern = /([\"'`])(?<value>[^\"'`\\r\\n]+)\\1/gu;\nconst tokenPattern = /[^\\s]+/gu;\nconst pathTokenPattern =\n /(?:(?:[\\p{L}\\p{N}_@%$+~.#[\\],-]+[\\\\/])+(?:[\\p{L}\\p{N}_@%$+~.#[\\],-]+)|[\\p{L}\\p{N}_@%$+~.#[\\],-]+\\.[\\p{L}\\p{N}_@%$-]{1,16})(?::\\d+){0,2}/gu;\nconst unquotedPathCharacterSource = \"[^\\\"'`<>()[\\\\]{}\\\\s]\";\nconst variablePathPattern = new RegExp(\n `${variableReferenceSource}(?:[\\\\\\\\/]${unquotedPathCharacterSource}+)+`,\n \"giu\",\n);\nconst clausePattern = /[^\\r\\n!?!?;;。]+/gu;\nconst pathHintPattern =\n /[\\\\/]|(?:^|[\\s\"'`])(?:\\.{1,2}|~|%[A-Za-z_][A-Za-z0-9_]*%|\\$\\{?[A-Za-z_][A-Za-z0-9_]*\\}?)(?:[\\\\/]|$)|\\.[\\p{L}\\p{N}]{1,16}(?::\\d+){0,2}(?:$|[\\s,.;:!?,。;:!?、])/u;\nconst variableHintPattern = new RegExp(String.raw`${variableReferenceSource}(?:[\\\\/]|$)`, \"iu\");\nfunction add(\n result: Candidate[],\n seen: Set<string>,\n value: string,\n start: number,\n end: number,\n kind: Candidate[\"kind\"],\n): void {\n if (value.length === 0) {\n return;\n }\n const key = `${start}:${end}:${value}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push({ end, kind, start, value });\n }\n}\nfunction addMatches(\n result: Candidate[],\n seen: Set<string>,\n text: string,\n pattern: RegExp,\n kind: Candidate[\"kind\"],\n): void {\n for (const match of text.matchAll(pattern)) {\n const value = match[0];\n const start = match.index ?? 0;\n add(result, seen, value, start, start + value.length, kind);\n }\n}\nfunction addQuotedMatches(result: Candidate[], seen: Set<string>, text: string): void {\n for (const match of text.matchAll(quotedPattern)) {\n const value = match.groups?.value;\n if (value === undefined) {\n continue;\n }\n const start = (match.index ?? 0) + match[0].indexOf(value);\n add(result, seen, value, start, start + value.length, \"quoted\");\n }\n}\nfunction addSpanMatches(\n result: Candidate[],\n seen: Set<string>,\n text: string,\n maximumWords: number,\n): void {\n for (const clause of text.matchAll(clausePattern)) {\n const clauseStart = clause.index ?? 0;\n const clauseText = clause[0];\n const tokens = [...clauseText.matchAll(tokenPattern)].map((token) => ({\n end: clauseStart + (token.index ?? 0) + token[0].length,\n hint: Number(pathHintPattern.test(token[0]) || variableHintPattern.test(token[0])),\n start: clauseStart + (token.index ?? 0),\n value: token[0],\n }));\n const hintCounts = [0];\n for (const token of tokens) {\n hintCounts.push((hintCounts.at(-1) ?? 0) + token.hint);\n }\n for (let start = 0; start < tokens.length; start += 1) {\n const last = Math.min(tokens.length, start + maximumWords);\n for (let end = start + 1; end <= last; end += 1) {\n const firstToken = tokens[start];\n const lastToken = tokens[end - 1];\n const hintsBefore = hintCounts[start];\n const hintsAfter = hintCounts[end];\n if (\n firstToken === undefined ||\n lastToken === undefined ||\n hintsBefore === undefined ||\n hintsAfter === undefined ||\n hintsBefore === hintsAfter\n ) {\n continue;\n }\n const value = text.slice(firstToken.start, lastToken.end);\n if (pathHintPattern.test(value)) {\n add(result, seen, value, firstToken.start, lastToken.end, \"span\");\n }\n }\n }\n }\n}\nexport function extractCandidates(text: string, level: SearchLevel): Candidate[] {\n const result: Candidate[] = [];\n const seen = new Set<string>();\n addQuotedMatches(result, seen, text);\n addMatches(result, seen, text, explicitPattern, \"explicit\");\n if (level >= 2) {\n addMatches(result, seen, text, variablePathPattern, \"heuristic\");\n addMatches(result, seen, text, pathTokenPattern, \"heuristic\");\n }\n if (level >= 3) {\n const maximumWords =\n settings.spanWordLimits[Math.min(level - 3, settings.spanWordLimits.length - 1)];\n if (maximumWords === undefined) {\n throw new RangeError(\"No text-span level is configured\");\n }\n addSpanMatches(result, seen, text, maximumWords);\n }\n return result;\n}\n","import { readdir, stat } from \"node:fs/promises\";\nimport nodePath from \"node:path\";\nimport pLimit from \"p-limit\";\nimport { settings } from \"../config/settings.js\";\nimport type { PathKind } from \"./types.js\";\n\nconst knownFileErrors = new Set([\n \"EACCES\",\n \"ELOOP\",\n \"ENAMETOOLONG\",\n \"ENOTDIR\",\n \"ENOENT\",\n \"EPERM\",\n \"EINVAL\",\n]);\nconst unverifiableUncErrors = new Set([\"UNKNOWN\", \"EUNKNOWN\"]);\nfunction pathKey(value: string): string {\n return process.platform === \"win32\" ? value.toLowerCase() : value;\n}\nfunction fileErrorCode(error: unknown): string | undefined {\n if (error instanceof Error && \"code\" in error && typeof error.code === \"string\") {\n return error.code;\n }\n return undefined;\n}\nfunction isKnownFileError(error: unknown, filePath?: string): boolean {\n const code = fileErrorCode(error);\n return (\n code !== undefined &&\n (knownFileErrors.has(code) ||\n (filePath?.startsWith(\"\\\\\\\\\") === true && unverifiableUncErrors.has(code)))\n );\n}\nasync function classifyPath(filePath: string): Promise<PathKind | undefined> {\n try {\n const pathStats = await stat(filePath);\n if (pathStats.isFile()) {\n return \"file\";\n }\n return pathStats.isDirectory() ? \"directory\" : undefined;\n } catch (error) {\n if (isKnownFileError(error, filePath)) {\n return undefined;\n }\n throw error;\n }\n}\nasync function classifyAndAdd(found: Map<string, PathKind>, filePath: string): Promise<void> {\n const kind = await classifyPath(filePath);\n if (kind !== undefined) {\n found.set(filePath, kind);\n }\n}\nexport async function classifyExistingPaths(\n paths: readonly string[],\n roots: readonly string[],\n): Promise<Map<string, PathKind>> {\n const found = new Map<string, PathKind>();\n const limit = pLimit(settings.validationConcurrency);\n if (paths.length < settings.batchValidationThreshold) {\n await Promise.all(paths.map((filePath) => limit(() => classifyAndAdd(found, filePath))));\n return found;\n }\n const rootKeys = new Set(roots.map(pathKey));\n const pathsByParent = new Map<string, { parent: string; paths: string[] }>();\n for (const filePath of paths) {\n if (rootKeys.has(pathKey(filePath))) {\n found.set(filePath, \"directory\");\n continue;\n }\n const parent = nodePath.dirname(filePath);\n const key = pathKey(parent);\n const group = pathsByParent.get(key) ?? { parent, paths: [] };\n group.paths.push(filePath);\n pathsByParent.set(key, group);\n }\n const directPaths: string[] = [];\n const scannedGroups: { parent: string; paths: string[] }[] = [];\n for (const group of pathsByParent.values()) {\n if (group.paths.length < settings.directoryScanThreshold) {\n directPaths.push(...group.paths);\n } else {\n scannedGroups.push(group);\n }\n }\n await Promise.all([\n ...directPaths.map((filePath) => limit(() => classifyAndAdd(found, filePath))),\n ...scannedGroups.map(({ parent, paths: groupPaths }) =>\n limit(async () => {\n let entries;\n try {\n entries = await readdir(parent, { withFileTypes: true });\n } catch (error) {\n if (isKnownFileError(error, parent)) {\n return;\n }\n throw error;\n }\n const entriesByName = new Map(entries.map((entry) => [pathKey(entry.name), entry]));\n await Promise.all(\n groupPaths.map(async (filePath) => {\n const name = nodePath.basename(filePath);\n const entry = entriesByName.get(pathKey(name));\n if (entry?.isFile()) {\n found.set(filePath, \"file\");\n } else if (entry?.isDirectory()) {\n found.set(filePath, \"directory\");\n } else if (\n entry !== undefined ||\n (process.platform === \"win32\" && name.includes(\":\"))\n ) {\n await classifyAndAdd(found, filePath);\n }\n }),\n );\n }),\n ),\n ]);\n return found;\n}\n","import { isIP } from \"node:net\";\nimport { hostname, networkInterfaces } from \"node:os\";\nimport nodePath from \"node:path\";\n\ninterface DriveConnection {\n remote: unknown;\n status: number;\n}\ninterface NativeBridge {\n getDriveConnection(drive: string, bufferChars: number): DriveConnection;\n}\nconst moduleApi = globalThis.process.getBuiltinModule(\"node:module\");\nconst runtimeRequire = moduleApi.createRequire(import.meta.url);\nconst native =\n process.platform === \"win32\"\n ? (runtimeRequire(\"pathprobe/native-loader\") as NativeBridge)\n : undefined;\nconst uncServerSegmentPattern = /^[^\\\\/:*?\"<>|]+$/u;\nconst unmappedDriveErrors = new Set([1200, 1201, 1203, 1222, 2250]);\nconst errorMoreData = 234;\nconst mappingBufferChars = 32_768;\ninterface UncPath {\n canonical: string;\n server: string;\n share: string;\n suffix: string;\n}\ninterface DriveMapping {\n drive: string;\n remote: string;\n}\nfunction normalizeServerName(value: string): string {\n return value.replace(/\\.+$/u, \"\").toLowerCase();\n}\nfunction addLocalServerName(names: Set<string>, value: string | undefined): void {\n if (value !== undefined && uncServerSegmentPattern.test(value)) {\n names.add(normalizeServerName(value));\n }\n}\nfunction addIpv6LiteralName(names: Set<string>, value: string): void {\n const zoneIndex = value.indexOf(\"%\");\n const address = zoneIndex === -1 ? value : value.slice(0, zoneIndex);\n const zone = zoneIndex === -1 ? \"\" : `s${value.slice(zoneIndex + 1)}`;\n addLocalServerName(names, `${address.replaceAll(\":\", \"-\")}${zone}.ipv6-literal.net`);\n}\nfunction collectLocalServerNames(): Set<string> {\n const names = new Set<string>([\"localhost\"]);\n const computerName = process.env.COMPUTERNAME;\n addLocalServerName(names, hostname());\n addLocalServerName(names, computerName);\n if (computerName !== undefined && process.env.USERDNSDOMAIN !== undefined) {\n addLocalServerName(names, `${computerName}.${process.env.USERDNSDOMAIN}`);\n }\n for (const addresses of Object.values(networkInterfaces())) {\n for (const address of addresses ?? []) {\n if (isIP(address.address) === 4) {\n addLocalServerName(names, address.address);\n } else if (isIP(address.address) === 6) {\n addIpv6LiteralName(names, address.address);\n }\n }\n }\n addLocalServerName(names, \"--1.ipv6-literal.net\");\n return names;\n}\nconst localServerNames =\n process.platform === \"win32\" ? collectLocalServerNames() : new Set<string>();\nlet driveMappings: DriveMapping[] | undefined;\nfunction containsControlCharacter(value: string): boolean {\n return [...value].some((character) => character.charCodeAt(0) < 32);\n}\nfunction normalizeUncRoot(value: string): string {\n return value.replaceAll(\"/\", \"\\\\\").replace(/\\\\+$/u, \"\").toLowerCase();\n}\nfunction parseUncPath(value: string): UncPath | undefined {\n const normalized = value.replaceAll(\"/\", \"\\\\\");\n const extended = normalized.slice(0, 8).toLowerCase() === \"\\\\\\\\?\\\\unc\\\\\";\n if (normalized.startsWith(\"\\\\\\\\.\\\\\") || (normalized.startsWith(\"\\\\\\\\?\\\\\") && !extended)) {\n return undefined;\n }\n const serverStart = extended ? 8 : 2;\n const serverSeparator = normalized.slice(serverStart).indexOf(\"\\\\\");\n if (serverSeparator <= 0) {\n return undefined;\n }\n const serverEnd = serverStart + serverSeparator;\n const shareStart = serverEnd + 1;\n const shareSeparator = normalized.slice(shareStart).indexOf(\"\\\\\");\n const shareEnd = shareSeparator === -1 ? normalized.length : shareStart + shareSeparator;\n const server = normalized.slice(serverStart, serverEnd);\n const share = normalized.slice(shareStart, shareEnd);\n if (\n share.length === 0 ||\n !uncServerSegmentPattern.test(server) ||\n !uncServerSegmentPattern.test(share)\n ) {\n return undefined;\n }\n const suffix = normalized.slice(shareEnd);\n return {\n canonical: `\\\\\\\\${server}\\\\${share}${suffix}`,\n server,\n share,\n suffix,\n };\n}\nfunction queryDriveMapping(drive: string): string | undefined {\n if (native === undefined) {\n return undefined;\n }\n const { remote, status } = native.getDriveConnection(drive, mappingBufferChars);\n if (status === errorMoreData) {\n throw new Error(`WNetGetConnectionW returned an oversized mapping for ${drive}`);\n }\n if (unmappedDriveErrors.has(status)) {\n return undefined;\n }\n if (status !== 0) {\n throw new Error(`WNetGetConnectionW failed for ${drive} with error ${status}`);\n }\n if (typeof remote !== \"string\" || !remote.startsWith(\"\\\\\\\\\")) {\n throw new TypeError(`WNetGetConnectionW returned an invalid mapping for ${drive}`);\n }\n return normalizeUncRoot(remote);\n}\nfunction queryDriveMappings(): DriveMapping[] {\n if (driveMappings !== undefined) {\n return driveMappings;\n }\n const result: DriveMapping[] = [];\n for (let code = \"A\".charCodeAt(0); code <= \"Z\".charCodeAt(0); code += 1) {\n const drive = `${String.fromCharCode(code)}:`;\n const remote = queryDriveMapping(drive);\n if (remote !== undefined) {\n result.push({ drive, remote });\n }\n }\n driveMappings = result.toSorted((left, right) => right.remote.length - left.remote.length);\n return driveMappings;\n}\nfunction resolveMappedUncPath(path: UncPath): string | undefined {\n const canonical = normalizeUncRoot(path.canonical);\n const mapping = queryDriveMappings().find(\n ({ remote }) => canonical === remote || canonical.startsWith(`${remote}\\\\`),\n );\n if (mapping === undefined) {\n return undefined;\n }\n const relative = path.canonical.slice(mapping.remote.length);\n return nodePath.win32.normalize(`${mapping.drive}${relative}`);\n}\nfunction isLocalServer(value: string): boolean {\n const normalized = normalizeServerName(value);\n return (\n localServerNames.has(normalized) ||\n (isIP(value) === 4 && value.split(\".\")[0] === \"127\") ||\n normalized === \"--1.ipv6-literal.net\"\n );\n}\nfunction resolveLocalAdministrativeShare(path: UncPath): string | undefined {\n const match = /^([A-Za-z])\\$$/u.exec(path.share);\n if (match === null || !isLocalServer(path.server)) {\n return undefined;\n }\n return nodePath.win32.normalize(`${match[1]}:${path.suffix || \"\\\\\"}`);\n}\nexport function resolveUncPath(value: string): string | undefined {\n if (process.platform !== \"win32\" || (!value.startsWith(\"\\\\\\\\\") && !value.startsWith(\"//\"))) {\n return value;\n }\n if (containsControlCharacter(value)) {\n return undefined;\n }\n const path = parseUncPath(value);\n if (path === undefined) {\n return undefined;\n }\n return resolveMappedUncPath(path) ?? resolveLocalAdministrativeShare(path);\n}\n","import { stat } from \"node:fs/promises\";\nimport nodePath from \"node:path\";\nimport fastGlob from \"fast-glob\";\nimport { convertPathToPattern, globby } from \"globby\";\nimport { settings } from \"../config/settings.js\";\nimport { resolveUncPath } from \"./native/unc.js\";\n\nfunction pathKey(value: string): string {\n return process.platform === \"win32\" ? value.toLowerCase() : value;\n}\nfunction isWithinRoot(filePath: string, root: string): boolean {\n const relative = nodePath.relative(root, filePath);\n return (\n relative === \"\" ||\n (relative !== \"..\" &&\n !relative.startsWith(`..${nodePath.sep}`) &&\n !nodePath.isAbsolute(relative))\n );\n}\nfunction isHidden(relativePath: string): boolean {\n return relativePath.split(/[\\\\/]/u).some((part) => part.length > 1 && part.startsWith(\".\"));\n}\nfunction traversalOptions(root: string, searchHidden: boolean) {\n return {\n caseSensitiveMatch: process.platform !== \"win32\",\n cwd: root,\n dot: searchHidden,\n followSymbolicLinks: false,\n onlyFiles: false,\n unique: true,\n } as const;\n}\nfunction globbyOptions(root: string, respectIgnore: boolean, searchHidden: boolean) {\n return {\n ...traversalOptions(root, searchHidden),\n expandDirectories: false,\n gitignore: respectIgnore,\n globalGitignore: respectIgnore,\n ...(respectIgnore ? { ignoreFiles: settings.ignoreFilePatterns } : {}),\n } as const;\n}\nexport async function resolveSearchDirectories(directories: readonly string[]): Promise<string[]> {\n if (!Array.isArray(directories)) {\n throw new TypeError(\"directories must be an array\");\n }\n if (directories.length === 0) {\n throw new RangeError(\"directories must not be empty\");\n }\n const unique = new Map<string, string>();\n for (const directory of directories) {\n if (typeof directory !== \"string\" || directory.length === 0) {\n throw new TypeError(\"every directory must be a non-empty string\");\n }\n const resolvedUnc = resolveUncPath(directory);\n if (resolvedUnc === undefined || resolvedUnc.length === 0) {\n throw new TypeError(`${directory} cannot be represented as a drive-based path`);\n }\n const resolved = nodePath.resolve(resolvedUnc);\n unique.set(pathKey(resolved), resolved);\n }\n await Promise.all(\n [...unique.values()].map(async (directory) => {\n if (!(await stat(directory)).isDirectory()) {\n throw new TypeError(`${directory} is not a directory`);\n }\n }),\n );\n return [...unique.values()];\n}\nexport async function listSearchEntries(\n root: string,\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<string[]> {\n if (!respectIgnore) {\n return fastGlob(\"**/*\", traversalOptions(root, searchHidden));\n }\n return globby(\"**/*\", globbyOptions(root, respectIgnore, searchHidden));\n}\nexport async function filterSearchablePaths(\n paths: readonly string[],\n roots: readonly string[],\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<Set<string>> {\n const allowed = new Set<string>();\n const pathsByRoot = new Map<string, string[]>();\n for (const filePath of paths) {\n let hasSearchRoot = false;\n for (const root of roots) {\n if (!isWithinRoot(filePath, root)) {\n continue;\n }\n hasSearchRoot = true;\n const relative = nodePath.relative(root, filePath);\n if (!searchHidden && isHidden(relative)) {\n continue;\n }\n if (relative === \"\" || !respectIgnore) {\n allowed.add(filePath);\n } else {\n const grouped = pathsByRoot.get(root) ?? [];\n grouped.push(relative);\n pathsByRoot.set(root, grouped);\n }\n }\n if (hasSearchRoot) {\n continue;\n }\n const filesystemRelative = nodePath.relative(nodePath.parse(filePath).root, filePath);\n if (searchHidden || !isHidden(filesystemRelative)) {\n allowed.add(filePath);\n }\n }\n await Promise.all(\n [...pathsByRoot].map(async ([root, relativePaths]) => {\n const patterns = relativePaths.map(convertPathToPattern);\n const matches = await globby(patterns, {\n ...globbyOptions(root, true, true),\n absolute: true,\n });\n for (const match of matches) {\n allowed.add(nodePath.normalize(match));\n }\n }),\n );\n return allowed;\n}\n","import { fileURLToPath } from \"node:url\";\nimport nodePath from \"node:path\";\nimport { classifyExistingPaths } from \"./existence.js\";\nimport { filterSearchablePaths } from \"./policy.js\";\nimport { expandVariables } from \"./variables/index.js\";\nimport { resolveUncPath } from \"./native/unc.js\";\nimport { settings } from \"../config/settings.js\";\nimport type { Candidate, PathLocation, PathMatch, PathPosition, Variables } from \"./types.js\";\n\ninterface ResolvedCandidate {\n location?: PathLocation;\n path: string;\n position: PathPosition;\n}\ninterface PreparedCandidate {\n location?: PathLocation;\n position: PathPosition;\n value: string;\n}\nfunction pathKey(value: string): string {\n return process.platform === \"win32\" ? value.toLowerCase() : value;\n}\nfunction uniquePaths(values: Iterable<string>): string[] {\n const paths = new Map<string, string>();\n for (const value of values) {\n paths.set(pathKey(value), value);\n }\n return [...paths.values()];\n}\nfunction parseLocationPart(value: string, name: string): number {\n const result = Number(value);\n if (!Number.isSafeInteger(result)) {\n throw new RangeError(`${name} must be a safe integer`);\n }\n return result;\n}\nfunction prepareCandidate(candidate: Candidate): PreparedCandidate {\n let end = candidate.end;\n let start = candidate.start;\n let value = candidate.value;\n if (candidate.kind !== \"inventory\" && candidate.kind !== \"quoted\") {\n const startTrimmed = value.trimStart();\n start += value.length - startTrimmed.length;\n value = startTrimmed;\n const endTrimmed = value.trimEnd();\n end -= value.length - endTrimmed.length;\n value = endTrimmed;\n if (\n value.length >= 2 &&\n ((value[0] === '\"' && value.at(-1) === '\"') ||\n (value[0] === \"'\" && value.at(-1) === \"'\") ||\n (value[0] === \"`\" && value.at(-1) === \"`\"))\n ) {\n start += 1;\n end -= 1;\n value = value.slice(1, -1);\n }\n while (value.length > 0 && settings.trailingPunctuation.includes(value.at(-1) ?? \"\")) {\n end -= 1;\n value = value.slice(0, -1);\n }\n }\n if (candidate.kind === \"inventory\") {\n return { position: { end, start }, value };\n }\n const match = settings.locationSuffixPattern.exec(value);\n if (match === null) {\n return { position: { end, start }, value };\n }\n const lineValue = match.groups?.line;\n if (lineValue === undefined) {\n throw new TypeError(\"locationSuffixPattern must capture a line\");\n }\n const columnValue = match.groups?.column;\n const location: PathLocation =\n columnValue === undefined\n ? { line: parseLocationPart(lineValue, \"line\") }\n : {\n column: parseLocationPart(columnValue, \"column\"),\n line: parseLocationPart(lineValue, \"line\"),\n };\n end -= match[0].length;\n return {\n location,\n position: { end, start },\n value: value.slice(0, match.index),\n };\n}\nfunction unescape(value: string): string {\n if (value.startsWith(\"\\\\\\\\\") && !value.startsWith(\"\\\\\\\\\\\\\\\\\")) {\n return value;\n }\n return value.replace(/\\\\([\"'`\\\\])/gu, \"$1\").replace(/\\\\\\\\/gu, \"\\\\\");\n}\nfunction toPaths(value: string, roots: readonly string[], variables: Variables): string[] {\n let expanded = expandVariables(value, variables);\n if (expanded.startsWith(\"file://\")) {\n try {\n expanded = fileURLToPath(expanded);\n } catch (error) {\n if (error instanceof TypeError) {\n return [];\n }\n throw error;\n }\n } else {\n expanded = unescape(expanded);\n if (expanded === \"~\" || /^~[\\\\/]/u.test(expanded)) {\n expanded = nodePath.join(\n variables.HOME ??\n variables.USERPROFILE ??\n process.env.HOME ??\n process.env.USERPROFILE ??\n \"\",\n expanded.slice(2),\n );\n }\n }\n const resolvedPath = resolveUncPath(expanded);\n if (resolvedPath === undefined || resolvedPath.length === 0) {\n return [];\n }\n expanded = resolvedPath;\n if (nodePath.isAbsolute(expanded)) {\n return [nodePath.normalize(expanded)];\n }\n return uniquePaths(roots.map((root) => nodePath.resolve(root, expanded)));\n}\nfunction mergeLocation(match: PathMatch, location: PathLocation | undefined): void {\n if (location === undefined) {\n return;\n }\n if (match.location === undefined) {\n match.location = location;\n return;\n }\n if (match.location.line !== location.line || match.location.column !== location.column) {\n throw new Error(\"Candidates for the same path and position have conflicting locations\");\n }\n}\nexport async function validateCandidates(\n candidates: Candidate[],\n roots: readonly string[],\n variables: Variables,\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<PathMatch[]> {\n const resolvedCandidates: ResolvedCandidate[] = [];\n const validationPaths = new Map<string, string>();\n for (const candidate of candidates) {\n const prepared = prepareCandidate(candidate);\n const paths = toPaths(prepared.value, roots, variables);\n for (const filePath of paths) {\n resolvedCandidates.push({\n ...(prepared.location === undefined ? {} : { location: prepared.location }),\n path: filePath,\n position: prepared.position,\n });\n validationPaths.set(pathKey(filePath), filePath);\n }\n }\n let searchablePaths = [...validationPaths.values()];\n if (respectIgnore || !searchHidden) {\n searchablePaths = [\n ...(await filterSearchablePaths(searchablePaths, roots, respectIgnore, searchHidden)),\n ];\n }\n const classifiedPaths = await classifyExistingPaths(searchablePaths, roots);\n const kindsByPath = new Map(\n [...classifiedPaths].map(([filePath, kind]) => [pathKey(filePath), kind]),\n );\n const matches = new Map<string, PathMatch>();\n for (const { location, path, position } of resolvedCandidates) {\n const kind = kindsByPath.get(pathKey(path));\n if (kind === undefined) {\n continue;\n }\n const key = `${pathKey(path)}\\0${position.start}\\0${position.end}`;\n const existing = matches.get(key);\n if (existing !== undefined) {\n mergeLocation(existing, location);\n continue;\n }\n matches.set(key, {\n kind,\n ...(location === undefined ? {} : { location }),\n path,\n position,\n });\n }\n return [...matches.values()];\n}\n","import nodePath from \"node:path\";\nimport { listSearchEntries } from \"./policy.js\";\nimport type { Candidate } from \"./types.js\";\n\nfunction isBoundary(value: string | undefined, following: string | undefined): boolean {\n if (value === \".\") {\n return following === undefined || !/[\\p{L}\\p{N}_-]/u.test(following);\n }\n return value === undefined || !/[\\p{L}\\p{N}_/\\\\-]/u.test(value);\n}\nfunction addOccurrences(\n result: Candidate[],\n seen: Set<string>,\n source: string,\n text: string,\n value: string,\n): void {\n const target = process.platform === \"win32\" ? value.toLowerCase() : value;\n let offset = source.indexOf(target);\n while (offset !== -1) {\n const end = offset + target.length;\n if (isBoundary(text[offset - 1], text[offset]) && isBoundary(text[end], text[end + 1])) {\n const key = `${offset}:${end}:${text.slice(offset, end)}`;\n if (!seen.has(key)) {\n seen.add(key);\n result.push({\n end,\n kind: \"inventory\",\n start: offset,\n value,\n });\n }\n }\n offset = source.indexOf(target, offset + 1);\n }\n}\nexport async function inventoryCandidates(\n text: string,\n roots: readonly string[],\n respectIgnore: boolean,\n searchHidden: boolean,\n): Promise<Candidate[]> {\n const entries = await Promise.all(\n roots.map((root) => listSearchEntries(root, respectIgnore, searchHidden)),\n );\n const result: Candidate[] = [];\n const seen = new Set<string>();\n const scanned = new Set<string>();\n const source = process.platform === \"win32\" ? text.toLowerCase() : text;\n for (const [rootIndex, relativeEntries] of entries.entries()) {\n const root = roots[rootIndex];\n if (root === undefined) {\n continue;\n }\n for (const relativeEntry of relativeEntries) {\n const absoluteEntry = nodePath.resolve(root, relativeEntry);\n const variants = [\n relativeEntry,\n relativeEntry.replaceAll(\"/\", nodePath.sep),\n absoluteEntry,\n absoluteEntry.replaceAll(nodePath.sep, \"/\"),\n ];\n for (const value of variants) {\n const key = process.platform === \"win32\" ? value.toLowerCase() : value;\n if (!scanned.has(key)) {\n scanned.add(key);\n addOccurrences(result, seen, source, text, value);\n }\n }\n }\n }\n return result;\n}\n","import { extractCandidates } from \"./candidates.js\";\nimport { validateCandidates } from \"./filesystem.js\";\nimport { inventoryCandidates } from \"./inventory.js\";\nimport { resolveSearchDirectories } from \"./policy.js\";\nimport { settings } from \"../config/settings.js\";\nimport type { PathMatch, SearchLevel, Variables } from \"./types.js\";\n\nexport const MAX_LEVEL = settings.spanWordLimits.length + 3;\nfunction validateVariables(value: unknown): asserts value is Variables {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n Object.values(value).some((item) => typeof item !== \"string\")\n ) {\n throw new TypeError(\"variables must be an object of string values\");\n }\n}\nexport async function findExistingPaths(\n text: string,\n level: SearchLevel,\n directories: readonly string[],\n variables: Variables = {},\n respectIgnore: boolean = settings.respectIgnoreByDefault,\n searchHidden: boolean = settings.searchHiddenByDefault,\n): Promise<PathMatch[]> {\n if (typeof text !== \"string\") {\n throw new TypeError(\"text must be a string\");\n }\n if (!Number.isInteger(level) || level < 1 || level > MAX_LEVEL) {\n throw new RangeError(`level must be an integer from 1 to ${MAX_LEVEL}`);\n }\n validateVariables(variables);\n if (typeof respectIgnore !== \"boolean\") {\n throw new TypeError(\"respectIgnore must be a boolean\");\n }\n if (typeof searchHidden !== \"boolean\") {\n throw new TypeError(\"searchHidden must be a boolean\");\n }\n const roots = await resolveSearchDirectories(directories);\n const candidates = extractCandidates(text, level);\n if (level === MAX_LEVEL) {\n candidates.push(...(await inventoryCandidates(text, roots, respectIgnore, searchHidden)));\n }\n return validateCandidates(candidates, roots, variables, respectIgnore, searchHidden);\n}\nexport type {\n PathKind,\n PathLocation,\n PathMatch,\n PathPosition,\n SearchLevel,\n Variables,\n} from \"./types.js\";\n"],"mappings":";;;;;;;;;AAEA,MAAa,WAA2B;CACtC,0BAA0B;CAC1B,wBAAwB;CACxB,oBAAoB,CAAC,cAAc,cAAc;CACjD,uBAAuB;CACvB,wBAAwB;CACxB,uBAAuB;CACvB,gBAAgB,CAAC,GAAG,EAAE;CACtB,qBAAqB;CACrB,uBAAuB;AACzB;;;ACVA,MAAM,aAAa,OAAO,GAAG;AAC7B,MAAa,0BAA0B,OAAO,GAAG,8CAA8C,WAAW,iBAAiB,WAAW,0BAA0B,WAAW,WAAW,WAAW,6BAA6B,WAAW,KAAK,WAAW,WAAW,WAAW,SAAS,WAAW;AACnS,MAAM,qBAAqB;CACzB,IAAI,OAAO,OAAO,GAAG,4CAA4C,WAAW,WAAW,KAAK;CAC5F,IAAI,OAAO,OAAO,GAAG,WAAW,WAAW,WAAW,IAAI;CAC1D,IAAI,OAAO,OAAO,GAAG,oBAAoB,WAAW,MAAM,KAAK;CAC/D,IAAI,OAAO,OAAO,GAAG,UAAU,WAAW,IAAI,KAAK;CACnD,IAAI,OAAO,OAAO,GAAG,sCAAsC,KAAK;CAChE,IAAI,OAAO,OAAO,GAAG,KAAK,WAAW,KAAK,IAAI;CAC9C,IAAI,OAAO,OAAO,GAAG,KAAK,WAAW,KAAK,IAAI;CAC9C,IAAI,OAAO,OAAO,GAAG,WAAW,WAAW,SAAS,IAAI;CACxD,IAAI,OAAO,OAAO,GAAG,KAAK,WAAW,KAAK,IAAI;AAChD;AACA,SAAS,gBAAgB,MAAc,WAA0C;CAC/E,MAAM,SAAS,UAAU,SAAS,QAAQ,IAAI;CAC9C,IAAI,WAAW,KAAA,GACb,OAAO;CAET,MAAM,WAAW,qCAAqC,KAAK,IAAI,CAAC,GAAG;CACnE,OAAO,aAA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,WAC3B,MAAM,IAAI,UAAU,iCAAiC;CAEvD,IAAI,OAAO,iBAAiB,WAC1B,MAAM,IAAI,UAAU,gCAAgC;CAEtD,MAAM,QAAQ,MAAM,yBAAyB,WAAW;CACxD,MAAM,aAAa,kBAAkB,MAAM,KAAK;CAChD,IAAI,UAAU,WACZ,WAAW,KAAK,GAAI,MAAM,oBAAoB,MAAM,OAAO,eAAe,YAAY,CAAE;CAE1F,OAAO,mBAAmB,YAAY,OAAO,WAAW,eAAe,YAAY;AACrF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const { Buffer } = require("node:buffer");
|
|
2
|
+
const koffi = require("koffi");
|
|
3
|
+
|
|
4
|
+
const getConnectionW = koffi
|
|
5
|
+
.load("mpr.dll")
|
|
6
|
+
.func(
|
|
7
|
+
"uint32_t WNetGetConnectionW(const char16_t *lpLocalName, _Out_ char16_t *lpRemoteName, _Inout_ uint32_t *lpnLength)",
|
|
8
|
+
);
|
|
9
|
+
function getDriveConnection(drive, bufferChars) {
|
|
10
|
+
const buffer = Buffer.alloc(bufferChars * 2);
|
|
11
|
+
const length = [bufferChars];
|
|
12
|
+
const status = getConnectionW(drive, buffer, length);
|
|
13
|
+
const remote = status === 0 ? koffi.decode(buffer, "char16_t", bufferChars) : undefined;
|
|
14
|
+
return { remote, status };
|
|
15
|
+
}
|
|
16
|
+
module.exports = { getDriveConnection };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function resolveUncPath(value: string): string | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pathprobe",
|
|
3
|
-
"version": "0.4
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Extract, resolve, and validate file and directory paths mentioned in text, with variable expansion, ignore rules, hidden-file control, and configurable search roots.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -15,10 +15,13 @@
|
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/types/src/index.d.ts",
|
|
17
17
|
"import": "./dist/index.mjs"
|
|
18
|
+
},
|
|
19
|
+
"./native-loader": {
|
|
20
|
+
"require": "./dist/native-loader.cjs"
|
|
18
21
|
}
|
|
19
22
|
},
|
|
20
23
|
"scripts": {
|
|
21
|
-
"build": "tsdown
|
|
24
|
+
"build": "tsdown --config config/tsdown.config.ts && tsc --project config/tsconfig.build.json",
|
|
22
25
|
"format": "oxfmt --config config/oxfmt.json .",
|
|
23
26
|
"lint": "oxlint --config config/oxlint.json --tsconfig tsconfig.json .",
|
|
24
27
|
"prepack": "bun run build",
|
|
@@ -29,6 +32,7 @@
|
|
|
29
32
|
"dependencies": {
|
|
30
33
|
"fast-glob": "latest",
|
|
31
34
|
"globby": "latest",
|
|
35
|
+
"koffi": "latest",
|
|
32
36
|
"p-limit": "latest"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
@@ -40,6 +44,7 @@
|
|
|
40
44
|
"typescript": "next"
|
|
41
45
|
},
|
|
42
46
|
"engines": {
|
|
43
|
-
"
|
|
47
|
+
"bun": ">=1.2.6",
|
|
48
|
+
"node": ">=20.16.0"
|
|
44
49
|
}
|
|
45
50
|
}
|
package/dist/types/src/unc.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function resolveLocalUncPath(value: string): string | undefined;
|