@hyperframes/parsers 0.9.54 → 0.9.55

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.
@@ -2,8 +2,12 @@
2
2
  declare function isTrustedDirectory(dir: string): boolean;
3
3
  /** Whether `file` is an absolute path in a folder {@link isTrustedDirectory} accepts. */
4
4
  declare function isTrustedExecutablePath(file: string): boolean;
5
- /** The PATH folders a helper program may come from, in PATH order. */
6
- declare function trustedPathDirs(pathValue?: string): string[];
5
+ /** PATH entries as the program search reads them: Windows allows quotes, shells expand a leading `~`. */
6
+ declare function pathEntries(pathValue: string, platform?: NodeJS.Platform): string[];
7
+ /** The PATH folders a helper program may come from, in PATH order. Windows always keeps its system folders. */
8
+ declare function trustedPathDirs(pathValue?: string, platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): string[];
9
+ /** The program `name` in `dir`, trying the Windows program extensions there. */
10
+ declare function executableIn(dir: string, name: string): string | undefined;
7
11
  declare function findTrustedExecutable(name: string): string | undefined;
8
12
 
9
13
  /**
@@ -43,4 +47,4 @@ declare function requireFfBinary(name: FfBinaryName): string;
43
47
  /** Test hook: drop cached system lookups so resolution can be re-exercised. */
44
48
  declare function clearFfBinaryLookupCache(): void;
45
49
 
46
- export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, clearFfBinaryLookupCache, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, requireFfBinary, trustedPathDirs };
50
+ export { FFMPEG_PATH_ENV, FFPROBE_PATH_ENV, type FfBinaryName, type FindFfBinaryOptions, clearFfBinaryLookupCache, executableIn, findFfBinary, findTrustedExecutable, getSkippedX86Binary, isTrustedDirectory, isTrustedExecutablePath, isX86OnlyMachO, pathEntries, requireFfBinary, trustedPathDirs };
@@ -14,7 +14,17 @@ import { basename as basename2, dirname as dirname2, join as join2, resolve as r
14
14
  // src/trustedExecutable.ts
15
15
  import { accessSync, constants, existsSync, realpathSync, statSync } from "fs";
16
16
  import { homedir } from "os";
17
- import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from "path";
17
+ import {
18
+ basename,
19
+ delimiter,
20
+ dirname,
21
+ isAbsolute,
22
+ join,
23
+ relative,
24
+ resolve,
25
+ sep,
26
+ win32
27
+ } from "path";
18
28
  function comparable(path) {
19
29
  const full = resolve(path);
20
30
  const missing = [];
@@ -67,13 +77,37 @@ function isTrustedExecutablePath(file) {
67
77
  return isAbsolute(file) && isTrustedDirectory(dirname(file));
68
78
  }
69
79
  function expandHome(dir) {
70
- if (process.platform === "win32" || !(dir === "~" || dir.startsWith("~/"))) return dir;
80
+ if (!(dir === "~" || dir.startsWith("~/"))) return dir;
71
81
  return join(homedir(), dir.slice(1));
72
82
  }
73
- function trustedPathDirs(pathValue = process.env.PATH ?? "") {
74
- const entries = pathValue.split(delimiter).map(expandHome);
83
+ function unquoted(dir) {
84
+ return dir.length > 1 && dir.startsWith('"') && dir.endsWith('"') ? dir.slice(1, -1) : dir;
85
+ }
86
+ function pathEntries(pathValue, platform = process.platform) {
87
+ if (platform === "win32") return pathValue.split(win32.delimiter).map(unquoted);
88
+ return pathValue.split(delimiter).map(expandHome);
89
+ }
90
+ function windowsFolderKey(dir) {
91
+ return dir.replaceAll("/", "\\").replace(/\\+$/, "").toLowerCase();
92
+ }
93
+ function windowsSystemFolders(env) {
94
+ const rootKey = Object.keys(env).find((key) => key.toUpperCase() === "SYSTEMROOT");
95
+ const root = rootKey && env[rootKey] || "C:\\Windows";
96
+ const system32 = win32.join(root, "System32");
97
+ return new Set(
98
+ [
99
+ root,
100
+ system32,
101
+ win32.join(system32, "Wbem"),
102
+ win32.join(system32, "WindowsPowerShell", "v1.0")
103
+ ].map(windowsFolderKey)
104
+ );
105
+ }
106
+ function trustedPathDirs(pathValue = process.env.PATH ?? "", platform = process.platform, env = process.env) {
107
+ const system = platform === "win32" ? windowsSystemFolders(env) : /* @__PURE__ */ new Set();
108
+ const entries = pathEntries(pathValue, platform);
75
109
  const trusted = trustRule();
76
- return [...new Set(entries.filter((dir) => trusted(dir)))];
110
+ return [...new Set(entries.filter((dir) => system.has(windowsFolderKey(dir)) || trusted(dir)))];
77
111
  }
78
112
  function windowsExtensions() {
79
113
  const listed = (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((ext) => ext.trim().toLowerCase()).filter(Boolean);
@@ -88,13 +122,18 @@ function isExecutableFile(file) {
88
122
  return false;
89
123
  }
90
124
  }
91
- function findTrustedExecutable(name) {
125
+ function executableIn(dir, name) {
92
126
  const extensions = process.platform === "win32" ? windowsExtensions() : [""];
127
+ for (const ext of extensions) {
128
+ const candidate = join(dir, `${name}${ext}`);
129
+ if (isExecutableFile(candidate)) return candidate;
130
+ }
131
+ return void 0;
132
+ }
133
+ function findTrustedExecutable(name) {
93
134
  for (const dir of trustedPathDirs()) {
94
- for (const ext of extensions) {
95
- const candidate = join(dir, `${name}${ext}`);
96
- if (isExecutableFile(candidate)) return candidate;
97
- }
135
+ const found = executableIn(dir, name);
136
+ if (found) return found;
98
137
  }
99
138
  return void 0;
100
139
  }
@@ -240,12 +279,14 @@ export {
240
279
  FFMPEG_PATH_ENV,
241
280
  FFPROBE_PATH_ENV,
242
281
  clearFfBinaryLookupCache,
282
+ executableIn,
243
283
  findFfBinary,
244
284
  findTrustedExecutable,
245
285
  getSkippedX86Binary,
246
286
  isTrustedDirectory,
247
287
  isTrustedExecutablePath,
248
288
  isX86OnlyMachO,
289
+ pathEntries,
249
290
  requireFfBinary,
250
291
  trustedPathDirs
251
292
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/parsers",
3
- "version": "0.9.54",
3
+ "version": "0.9.55",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -143,7 +143,7 @@
143
143
  "tsx": "^4.21.0",
144
144
  "typescript": "^5.0.0",
145
145
  "vitest": "^4.1.12",
146
- "@hyperframes/core": "0.9.54"
146
+ "@hyperframes/core": "0.9.55"
147
147
  },
148
148
  "scripts": {
149
149
  "build": "tsup",