@hyperframes/parsers 0.9.32 → 0.9.33
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/assetResolution.d.ts +5 -1
- package/dist/assetResolution.js +37 -9
- package/package.json +2 -2
|
@@ -49,6 +49,10 @@ declare function cleanAssetUrl(url: string): string;
|
|
|
49
49
|
*/
|
|
50
50
|
declare function isWithinProjectRoot(projectDir: string, candidate: string, pathModule?: PathModuleLike): boolean;
|
|
51
51
|
declare function resolveLocalAssetCandidates(projectDir: string, url: string): string[];
|
|
52
|
+
declare function namesAnotherNetworkRoot(base: string, target: string): boolean;
|
|
53
|
+
/** The project file a data-composition-src names, as the preview reads it; null when it leaves the project. */
|
|
54
|
+
declare function resolveCompositionSrc(projectDir: string, src: string): string | null;
|
|
55
|
+
declare function localAbsoluteAssetFile(projectDir: string, src: string): string | null;
|
|
52
56
|
declare function resolveExistingLocalAsset(projectDir: string, url: string): {
|
|
53
57
|
resolved: string;
|
|
54
58
|
rootRelativePath: string;
|
|
@@ -73,4 +77,4 @@ declare const readTextFile: (path: string) => string;
|
|
|
73
77
|
/** Reads through one descriptor, so the file-type check and the read see the same file. */
|
|
74
78
|
declare function readProjectFile(path: string): ProjectFileRead;
|
|
75
79
|
|
|
76
|
-
export { type ProjectFileRead, cleanAssetUrl, collectSubCompositionSrcs, decodeTextHonoringBom, hasUnresolvedTemplatingToken, isRemoteOrInlineUrl, isUnresolvedAssetPlaceholder, isWithinProjectRoot, maskNonScannableRanges, readProjectFile, readTextFile, resolveAuthoredAssetFile, resolveExistingLocalAsset, resolveLocalAssetCandidates, resolveProjectRelativeSrc };
|
|
80
|
+
export { type ProjectFileRead, cleanAssetUrl, collectSubCompositionSrcs, decodeTextHonoringBom, hasUnresolvedTemplatingToken, isRemoteOrInlineUrl, isUnresolvedAssetPlaceholder, isWithinProjectRoot, localAbsoluteAssetFile, maskNonScannableRanges, namesAnotherNetworkRoot, readProjectFile, readTextFile, resolveAuthoredAssetFile, resolveCompositionSrc, resolveExistingLocalAsset, resolveLocalAssetCandidates, resolveProjectRelativeSrc };
|
package/dist/assetResolution.js
CHANGED
|
@@ -88,9 +88,12 @@ function decodeAuthoredAttribute(value) {
|
|
|
88
88
|
|
|
89
89
|
// src/assetResolution.ts
|
|
90
90
|
import { closeSync, constants, existsSync, fstatSync, openSync, readFileSync } from "fs";
|
|
91
|
-
import { isAbsolute as isAbsolute2, join as join2, posix as posix2, relative as relative2, resolve as resolve3, sep } from "path";
|
|
91
|
+
import { isAbsolute as isAbsolute2, join as join2, parse, posix as posix2, relative as relative2, resolve as resolve3, sep } from "path";
|
|
92
92
|
import { fileURLToPath } from "url";
|
|
93
93
|
|
|
94
|
+
// src/assetPaths.ts
|
|
95
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
96
|
+
|
|
94
97
|
// src/utils/urlPath.ts
|
|
95
98
|
function decodeUrlPathVariants(path) {
|
|
96
99
|
const decoded = decodeWellFormedEscapes(path);
|
|
@@ -114,21 +117,21 @@ function splitUrlSuffix(urlValue) {
|
|
|
114
117
|
if (hashIdx >= 0) cutIdx = Math.min(cutIdx, hashIdx);
|
|
115
118
|
return { basePath: urlValue.slice(0, cutIdx), suffix: urlValue.slice(cutIdx) };
|
|
116
119
|
}
|
|
120
|
+
function decodedUrlPath(url) {
|
|
121
|
+
return decodeWellFormedEscapes(splitUrlSuffix(url).basePath);
|
|
122
|
+
}
|
|
117
123
|
function encodeUrlPath(path) {
|
|
118
124
|
return encodeURIComponent(path).replace(/%2F/g, "/").replace(/['()]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
119
125
|
}
|
|
120
126
|
|
|
121
|
-
// src/rewriteSubCompPaths.ts
|
|
122
|
-
import { posix } from "path";
|
|
123
|
-
|
|
124
127
|
// src/assetPaths.ts
|
|
125
|
-
import { isAbsolute, relative, resolve } from "path";
|
|
126
128
|
var URL_SCHEME_OF_TWO_OR_MORE_CHARS_RE = /^[a-z][a-z0-9+.-]+:/i;
|
|
127
129
|
function isNonRelativeUrl(val) {
|
|
128
130
|
return !val || val.startsWith("http://") || val.startsWith("https://") || val.startsWith("//") || val.startsWith("data:") || val.startsWith("#") || val.startsWith("/") || URL_SCHEME_OF_TWO_OR_MORE_CHARS_RE.test(val);
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
// src/rewriteSubCompPaths.ts
|
|
134
|
+
import { posix } from "path";
|
|
132
135
|
var { join, resolve: resolve2, dirname } = posix;
|
|
133
136
|
var isAbsoluteOrSpecial = isNonRelativeUrl;
|
|
134
137
|
function needsRewrite(val) {
|
|
@@ -197,12 +200,34 @@ function resolveLocalAssetCandidates(projectDir, url) {
|
|
|
197
200
|
}
|
|
198
201
|
const normalized = posix2.normalize(projectRelative.replace(/\\/g, "/"));
|
|
199
202
|
const clamped = normalized.replace(/^(\.\.\/)+/, "");
|
|
200
|
-
if (clamped
|
|
201
|
-
|
|
202
|
-
|
|
203
|
+
if (!clamped || clamped.startsWith("..")) continue;
|
|
204
|
+
const reanchored = resolve3(projectRoot, clamped);
|
|
205
|
+
if (isWithinProjectRoot(projectRoot, reanchored)) addCandidate(candidates, reanchored);
|
|
203
206
|
}
|
|
204
207
|
return candidates;
|
|
205
208
|
}
|
|
209
|
+
function namesAnotherNetworkRoot(base, target) {
|
|
210
|
+
const root = parse(resolve3(target)).root;
|
|
211
|
+
return /^[\\/]{2}/.test(root) && root.toLowerCase() !== parse(resolve3(base)).root.toLowerCase();
|
|
212
|
+
}
|
|
213
|
+
var LEADING_PARENT_SEGMENT = /^\.\.(?:[\\/]|$)/;
|
|
214
|
+
function staysInsideProject(projectDir, path) {
|
|
215
|
+
const relativePath = relative2(resolve3(projectDir), path);
|
|
216
|
+
return !LEADING_PARENT_SEGMENT.test(relativePath) && !isAbsolute2(relativePath);
|
|
217
|
+
}
|
|
218
|
+
function resolveCompositionSrc(projectDir, src) {
|
|
219
|
+
const rooted = (value) => resolve3(projectDir, value.replace(/^(?:\.?[\\/])+/, ""));
|
|
220
|
+
const decoded = rooted(decodedUrlPath(src));
|
|
221
|
+
if (!staysInsideProject(projectDir, decoded)) return null;
|
|
222
|
+
const raw = rooted(src);
|
|
223
|
+
return !existsSync(decoded) && staysInsideProject(projectDir, raw) && existsSync(raw) ? raw : decoded;
|
|
224
|
+
}
|
|
225
|
+
function localAbsoluteAssetFile(projectDir, src) {
|
|
226
|
+
const path = cleanAssetUrl(src);
|
|
227
|
+
if (isNonRelativeUrl(path) || !isAbsolute2(path)) return null;
|
|
228
|
+
const file = resolve3(projectDir, path);
|
|
229
|
+
return !namesAnotherNetworkRoot(projectDir, file) && existsSync(file) ? file : null;
|
|
230
|
+
}
|
|
206
231
|
function resolveExistingLocalAsset(projectDir, url) {
|
|
207
232
|
const projectRoot = resolve3(projectDir);
|
|
208
233
|
const resolved = resolveLocalAssetCandidates(projectRoot, url).find(existsSync);
|
|
@@ -213,7 +238,7 @@ function resolveAuthoredAssetFile(projectDir, compositionFile, src) {
|
|
|
213
238
|
const cleanSrc = cleanAssetUrl(src.trim());
|
|
214
239
|
if (!cleanSrc) return null;
|
|
215
240
|
const rootRelative = cleanSrc.startsWith("/") ? cleanSrc : rewriteAssetPath(compositionFile, cleanSrc, (path) => existsSync(join2(projectDir, path)));
|
|
216
|
-
return resolveExistingLocalAsset(projectDir, rootRelative)?.resolved ??
|
|
241
|
+
return resolveExistingLocalAsset(projectDir, rootRelative)?.resolved ?? localAbsoluteAssetFile(projectDir, cleanSrc);
|
|
217
242
|
}
|
|
218
243
|
function reanchoredCandidates(variant, baseDir, compiledDir) {
|
|
219
244
|
const baseAbs = resolve3(baseDir);
|
|
@@ -304,10 +329,13 @@ export {
|
|
|
304
329
|
isRemoteOrInlineUrl,
|
|
305
330
|
isUnresolvedAssetPlaceholder,
|
|
306
331
|
isWithinProjectRoot,
|
|
332
|
+
localAbsoluteAssetFile,
|
|
307
333
|
maskNonScannableRanges,
|
|
334
|
+
namesAnotherNetworkRoot,
|
|
308
335
|
readProjectFile,
|
|
309
336
|
readTextFile,
|
|
310
337
|
resolveAuthoredAssetFile,
|
|
338
|
+
resolveCompositionSrc,
|
|
311
339
|
resolveExistingLocalAsset,
|
|
312
340
|
resolveLocalAssetCandidates,
|
|
313
341
|
resolveProjectRelativeSrc
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/parsers",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.33",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/heygen-com/hyperframes",
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"tsx": "^4.21.0",
|
|
140
140
|
"typescript": "^5.0.0",
|
|
141
141
|
"vitest": "^4.1.11",
|
|
142
|
-
"@hyperframes/core": "0.9.
|
|
142
|
+
"@hyperframes/core": "0.9.33"
|
|
143
143
|
},
|
|
144
144
|
"scripts": {
|
|
145
145
|
"build": "tsup",
|