@hyperframes/parsers 0.9.53 → 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.
- package/dist/ffBinaries.d.ts +7 -3
- package/dist/ffBinaries.js +93 -23
- package/package.json +2 -2
package/dist/ffBinaries.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
6
|
-
declare function
|
|
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 };
|
package/dist/ffBinaries.js
CHANGED
|
@@ -9,42 +9,105 @@ import {
|
|
|
9
9
|
statSync as statSync2
|
|
10
10
|
} from "fs";
|
|
11
11
|
import { createRequire } from "module";
|
|
12
|
-
import { basename, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
12
|
+
import { basename as basename2, dirname as dirname2, join as join2, resolve as resolve2 } from "path";
|
|
13
13
|
|
|
14
14
|
// src/trustedExecutable.ts
|
|
15
15
|
import { accessSync, constants, existsSync, realpathSync, statSync } from "fs";
|
|
16
16
|
import { homedir } from "os";
|
|
17
|
-
import {
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
const full = resolve(path);
|
|
30
|
+
const missing = [];
|
|
31
|
+
for (let dir = full; ; dir = dirname(dir)) {
|
|
32
|
+
try {
|
|
33
|
+
const real = join(realpathSync.native(dir), ...missing.reverse());
|
|
34
|
+
return process.platform === "win32" ? real.toLowerCase() : real;
|
|
35
|
+
} catch {
|
|
36
|
+
if (dirname(dir) === dir) return process.platform === "win32" ? full.toLowerCase() : full;
|
|
37
|
+
missing.push(basename(dir));
|
|
38
|
+
}
|
|
24
39
|
}
|
|
25
|
-
return process.platform === "win32" ? full.toLowerCase() : full;
|
|
26
40
|
}
|
|
27
41
|
function contains(parent, child) {
|
|
28
42
|
const rel = relative(parent, child);
|
|
29
43
|
return rel === "" || rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel);
|
|
30
44
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
var PROJECT_MARKERS = [".git", "package.json", "node_modules", "hyperframes.json"];
|
|
46
|
+
function projectRoot(cwd, home) {
|
|
47
|
+
let root = cwd;
|
|
48
|
+
for (let dir = cwd; dirname(dir) !== dir && !contains(dir, home); dir = dirname(dir)) {
|
|
49
|
+
if (PROJECT_MARKERS.some((marker) => existsSync(join(dir, marker)))) root = dir;
|
|
50
|
+
}
|
|
51
|
+
return root;
|
|
52
|
+
}
|
|
53
|
+
function ancestorNodeModules(cwd) {
|
|
54
|
+
const folders = [];
|
|
55
|
+
for (let dir = dirname(cwd); ; dir = dirname(dir)) {
|
|
56
|
+
folders.push(comparable(join(dir, "node_modules")));
|
|
57
|
+
if (dirname(dir) === dir) return folders;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function trustRule() {
|
|
34
61
|
const cwd = comparable(process.cwd());
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
const home = comparable(homedir());
|
|
63
|
+
const fromHome = contains(cwd, home);
|
|
64
|
+
const project = fromHome ? cwd : projectRoot(cwd, home);
|
|
65
|
+
const nodeModules = ancestorNodeModules(cwd);
|
|
66
|
+
return (dir) => {
|
|
67
|
+
if (!dir || !isAbsolute(dir)) return false;
|
|
68
|
+
const target = comparable(dir);
|
|
69
|
+
if (target === cwd || nodeModules.some((folder) => contains(folder, target))) return false;
|
|
70
|
+
return fromHome || !contains(project, target);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function isTrustedDirectory(dir) {
|
|
74
|
+
return trustRule()(dir);
|
|
37
75
|
}
|
|
38
76
|
function isTrustedExecutablePath(file) {
|
|
39
77
|
return isAbsolute(file) && isTrustedDirectory(dirname(file));
|
|
40
78
|
}
|
|
41
79
|
function expandHome(dir) {
|
|
42
|
-
if (
|
|
80
|
+
if (!(dir === "~" || dir.startsWith("~/"))) return dir;
|
|
43
81
|
return join(homedir(), dir.slice(1));
|
|
44
82
|
}
|
|
45
|
-
function
|
|
46
|
-
|
|
47
|
-
|
|
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);
|
|
109
|
+
const trusted = trustRule();
|
|
110
|
+
return [...new Set(entries.filter((dir) => system.has(windowsFolderKey(dir)) || trusted(dir)))];
|
|
48
111
|
}
|
|
49
112
|
function windowsExtensions() {
|
|
50
113
|
const listed = (process.env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((ext) => ext.trim().toLowerCase()).filter(Boolean);
|
|
@@ -59,13 +122,18 @@ function isExecutableFile(file) {
|
|
|
59
122
|
return false;
|
|
60
123
|
}
|
|
61
124
|
}
|
|
62
|
-
function
|
|
125
|
+
function executableIn(dir, name) {
|
|
63
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) {
|
|
64
134
|
for (const dir of trustedPathDirs()) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (isExecutableFile(candidate)) return candidate;
|
|
68
|
-
}
|
|
135
|
+
const found = executableIn(dir, name);
|
|
136
|
+
if (found) return found;
|
|
69
137
|
}
|
|
70
138
|
return void 0;
|
|
71
139
|
}
|
|
@@ -108,7 +176,7 @@ function runsOnThisMac(candidate) {
|
|
|
108
176
|
return true;
|
|
109
177
|
}
|
|
110
178
|
if (!isX86OnlyMachO(candidate)) return true;
|
|
111
|
-
const name =
|
|
179
|
+
const name = basename2(candidate);
|
|
112
180
|
if (!skippedX86Binaries.has(name)) skippedX86Binaries.set(name, candidate);
|
|
113
181
|
return false;
|
|
114
182
|
}
|
|
@@ -211,12 +279,14 @@ export {
|
|
|
211
279
|
FFMPEG_PATH_ENV,
|
|
212
280
|
FFPROBE_PATH_ENV,
|
|
213
281
|
clearFfBinaryLookupCache,
|
|
282
|
+
executableIn,
|
|
214
283
|
findFfBinary,
|
|
215
284
|
findTrustedExecutable,
|
|
216
285
|
getSkippedX86Binary,
|
|
217
286
|
isTrustedDirectory,
|
|
218
287
|
isTrustedExecutablePath,
|
|
219
288
|
isX86OnlyMachO,
|
|
289
|
+
pathEntries,
|
|
220
290
|
requireFfBinary,
|
|
221
291
|
trustedPathDirs
|
|
222
292
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/parsers",
|
|
3
|
-
"version": "0.9.
|
|
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.
|
|
146
|
+
"@hyperframes/core": "0.9.55"
|
|
147
147
|
},
|
|
148
148
|
"scripts": {
|
|
149
149
|
"build": "tsup",
|