veryfront 0.1.834 → 0.1.835
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/esm/deno.js +1 -1
- package/esm/src/modules/server/module-response-cache.d.ts +27 -0
- package/esm/src/modules/server/module-response-cache.d.ts.map +1 -0
- package/esm/src/modules/server/module-response-cache.js +105 -0
- package/esm/src/modules/server/module-server.d.ts.map +1 -1
- package/esm/src/modules/server/module-server.js +56 -5
- package/esm/src/release-assets/module-consumption.d.ts +8 -0
- package/esm/src/release-assets/module-consumption.d.ts.map +1 -1
- package/esm/src/release-assets/module-consumption.js +16 -2
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
package/esm/deno.js
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CacheBackend } from "../../cache/types.js";
|
|
2
|
+
export interface ReleaseModuleResponseCacheEntry {
|
|
3
|
+
body: string;
|
|
4
|
+
status: number;
|
|
5
|
+
headers: Array<[string, string]>;
|
|
6
|
+
}
|
|
7
|
+
export interface ReleaseModuleResponseCacheKeyOptions {
|
|
8
|
+
projectIdentity: string;
|
|
9
|
+
projectDir: string;
|
|
10
|
+
projectSlug?: string | null;
|
|
11
|
+
branch?: string | null;
|
|
12
|
+
releaseId: string;
|
|
13
|
+
runtimeVersion: string;
|
|
14
|
+
reactVersion?: string;
|
|
15
|
+
releaseDependencyManifestVersion?: number | null;
|
|
16
|
+
modulePath: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ReleaseModuleResponseCacheHit {
|
|
19
|
+
entry: ReleaseModuleResponseCacheEntry;
|
|
20
|
+
source: "memory" | "distributed";
|
|
21
|
+
}
|
|
22
|
+
export declare function buildReleaseModuleResponseCacheKey(options: ReleaseModuleResponseCacheKeyOptions): string;
|
|
23
|
+
export declare function getReleaseModuleResponse(cacheKey: string): Promise<ReleaseModuleResponseCacheHit | undefined>;
|
|
24
|
+
export declare function rememberReleaseModuleResponse(cacheKey: string, entry: ReleaseModuleResponseCacheEntry): Promise<void>;
|
|
25
|
+
export declare function clearReleaseModuleResponseCache(): void;
|
|
26
|
+
export declare function __setReleaseModuleResponseDistributedCacheForTests(cache: CacheBackend | null | undefined): void;
|
|
27
|
+
//# sourceMappingURL=module-response-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-response-cache.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-response-cache.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQzD,MAAM,WAAW,+BAA+B;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,oCAAoC;IACnD,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,+BAA+B,CAAC;IACvC,MAAM,EAAE,QAAQ,GAAG,aAAa,CAAC;CAClC;AAiDD,wBAAgB,kCAAkC,CAChD,OAAO,EAAE,oCAAoC,GAC5C,MAAM,CAmBR;AAED,wBAAsB,wBAAwB,CAC5C,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,6BAA6B,GAAG,SAAS,CAAC,CAqBpD;AAED,wBAAsB,6BAA6B,CACjD,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,IAAI,CAAC,CAef;AAED,wBAAgB,+BAA+B,IAAI,IAAI,CAEtD;AAED,wBAAgB,kDAAkD,CAChE,KAAK,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,GACrC,IAAI,CAEN"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { registerLRUCache } from "../../cache/index.js";
|
|
2
|
+
import { CacheBackends, createDistributedCacheAccessor } from "../../cache/backend.js";
|
|
3
|
+
import { hashString } from "../../cache/hash.js";
|
|
4
|
+
import { LRUCache } from "../../utils/lru-wrapper.js";
|
|
5
|
+
import { TRANSFORM_DISTRIBUTED_TTL_SEC } from "../../utils/constants/cache.js";
|
|
6
|
+
const RELEASE_MODULE_RESPONSE_CACHE_MAX_ENTRIES = 10_000;
|
|
7
|
+
const RELEASE_MODULE_RESPONSE_CACHE_MAX_BYTES = 64 * 1024 * 1024;
|
|
8
|
+
const RELEASE_MODULE_RESPONSE_DISTRIBUTED_TTL_SEC = TRANSFORM_DISTRIBUTED_TTL_SEC;
|
|
9
|
+
const releaseModuleResponseCache = new LRUCache({
|
|
10
|
+
maxEntries: RELEASE_MODULE_RESPONSE_CACHE_MAX_ENTRIES,
|
|
11
|
+
maxSizeBytes: RELEASE_MODULE_RESPONSE_CACHE_MAX_BYTES,
|
|
12
|
+
});
|
|
13
|
+
registerLRUCache("module-server-release-response-cache", releaseModuleResponseCache);
|
|
14
|
+
const getDistributedModuleResponseCache = createDistributedCacheAccessor(() => CacheBackends.module(), "MODULE-RESPONSE-CACHE");
|
|
15
|
+
let injectedDistributedCache;
|
|
16
|
+
function parseDistributedEntry(raw) {
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(raw);
|
|
19
|
+
if (typeof parsed.body !== "string")
|
|
20
|
+
return null;
|
|
21
|
+
if (typeof parsed.status !== "number")
|
|
22
|
+
return null;
|
|
23
|
+
if (!Array.isArray(parsed.headers) ||
|
|
24
|
+
!parsed.headers.every((entry) => Array.isArray(entry) &&
|
|
25
|
+
entry.length === 2 &&
|
|
26
|
+
typeof entry[0] === "string" &&
|
|
27
|
+
typeof entry[1] === "string"))
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
body: parsed.body,
|
|
31
|
+
status: parsed.status,
|
|
32
|
+
headers: parsed.headers,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function getDistributedCache() {
|
|
40
|
+
const cache = injectedDistributedCache !== undefined
|
|
41
|
+
? injectedDistributedCache
|
|
42
|
+
: await getDistributedModuleResponseCache();
|
|
43
|
+
if (!cache)
|
|
44
|
+
return null;
|
|
45
|
+
return cache.type === "api" || cache.type === "redis" ? cache : null;
|
|
46
|
+
}
|
|
47
|
+
export function buildReleaseModuleResponseCacheKey(options) {
|
|
48
|
+
const projectScope = [
|
|
49
|
+
options.projectIdentity,
|
|
50
|
+
options.projectDir,
|
|
51
|
+
options.projectSlug ?? "",
|
|
52
|
+
options.branch ?? "",
|
|
53
|
+
].join("\0");
|
|
54
|
+
return [
|
|
55
|
+
"module-server-release-response",
|
|
56
|
+
hashString(projectScope),
|
|
57
|
+
options.releaseId,
|
|
58
|
+
options.runtimeVersion,
|
|
59
|
+
options.reactVersion ?? "",
|
|
60
|
+
options.releaseDependencyManifestVersion == null
|
|
61
|
+
? ""
|
|
62
|
+
: `release-dependency-manifest:${options.releaseDependencyManifestVersion}`,
|
|
63
|
+
options.modulePath,
|
|
64
|
+
].join("\0");
|
|
65
|
+
}
|
|
66
|
+
export async function getReleaseModuleResponse(cacheKey) {
|
|
67
|
+
const localEntry = releaseModuleResponseCache.get(cacheKey);
|
|
68
|
+
if (localEntry) {
|
|
69
|
+
return { entry: localEntry, source: "memory" };
|
|
70
|
+
}
|
|
71
|
+
const distributedCache = await getDistributedCache();
|
|
72
|
+
if (!distributedCache)
|
|
73
|
+
return undefined;
|
|
74
|
+
try {
|
|
75
|
+
const raw = await distributedCache.get(cacheKey);
|
|
76
|
+
if (!raw)
|
|
77
|
+
return undefined;
|
|
78
|
+
const entry = parseDistributedEntry(raw);
|
|
79
|
+
if (!entry)
|
|
80
|
+
return undefined;
|
|
81
|
+
releaseModuleResponseCache.set(cacheKey, entry);
|
|
82
|
+
return { entry, source: "distributed" };
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export async function rememberReleaseModuleResponse(cacheKey, entry) {
|
|
89
|
+
releaseModuleResponseCache.set(cacheKey, entry);
|
|
90
|
+
const distributedCache = await getDistributedCache();
|
|
91
|
+
if (!distributedCache)
|
|
92
|
+
return;
|
|
93
|
+
try {
|
|
94
|
+
await distributedCache.set(cacheKey, JSON.stringify(entry), RELEASE_MODULE_RESPONSE_DISTRIBUTED_TTL_SEC);
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
/* best-effort shared cache */
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function clearReleaseModuleResponseCache() {
|
|
101
|
+
releaseModuleResponseCache.clear();
|
|
102
|
+
}
|
|
103
|
+
export function __setReleaseModuleResponseDistributedCacheForTests(cache) {
|
|
104
|
+
injectedDistributedCache = cache;
|
|
105
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-server.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-server.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAG5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"module-server.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-server.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAG5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAyDtE;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwDrD,CAAC;AA6DF,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,cAAc,CAAC;IACxB,uBAAuB;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAubzF;AAwWD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGrD"}
|
|
@@ -8,7 +8,7 @@ import { getContentTypeForPath } from "../../server/handlers/utils/content-types
|
|
|
8
8
|
import { createSecureFs } from "../../security/index.js";
|
|
9
9
|
import { getErrorMessage } from "../../errors/veryfront-error.js";
|
|
10
10
|
import { getApiBaseUrlEnv } from "../../config/env.js";
|
|
11
|
-
import { profilePhase } from "../../observability/request-profiler.js";
|
|
11
|
+
import { markRequestProfilePhase, profilePhase, } from "../../observability/request-profiler.js";
|
|
12
12
|
import { metrics } from "../../observability/simple-metrics/index.js";
|
|
13
13
|
import { injectContext, withSpan } from "../../observability/tracing/otlp-setup.js";
|
|
14
14
|
import { injectNodePositions } from "../../transforms/plugins/babel-node-positions.js";
|
|
@@ -20,9 +20,10 @@ import { FRAMEWORK_ROOT, resolveFrameworkSourcePath, } from "../../platform/comp
|
|
|
20
20
|
import { getReactUrls, REACT_DEFAULT_VERSION } from "../../utils/constants/cdn.js";
|
|
21
21
|
import { readLimitedCrossProjectSource } from "./cross-project-source-limit.js";
|
|
22
22
|
import { sha256Short } from "../../cache/hash.js";
|
|
23
|
-
import { rewriteReleaseDependencyImportsForModule } from "../../release-assets/module-consumption.js";
|
|
23
|
+
import { getReleaseDependencyRewriteManifestState, rewriteReleaseDependencyImportsForModule, } from "../../release-assets/module-consumption.js";
|
|
24
24
|
import { RELEASE_ASSET_IMMUTABLE_MAX_AGE_SECONDS, RELEASE_MODULE_RUNTIME_VERSION_PARAM, RELEASE_MODULE_VERSION_PARAM, } from "../../release-assets/constants.js";
|
|
25
25
|
import { buildSourceMissCacheKey, hasSourceMiss, rememberSourceMiss, } from "./module-source-resolution-cache.js";
|
|
26
|
+
import { buildReleaseModuleResponseCacheKey, getReleaseModuleResponse, rememberReleaseModuleResponse, } from "./module-response-cache.js";
|
|
26
27
|
import { ensureFilenameDefaultExport } from "../loader-shared/filename-default-export.js";
|
|
27
28
|
const logger = serverLogger.component("module-server");
|
|
28
29
|
const PROJECT_FALLBACK_EMBEDDED_POLYFILLS = new Set(["deno"]);
|
|
@@ -111,7 +112,9 @@ function appendReleaseModuleVersion(url, releaseId) {
|
|
|
111
112
|
return `${url}${separator}${params.toString()}`;
|
|
112
113
|
}
|
|
113
114
|
function shouldCacheReleaseVersionedModule(url, options, isSSR) {
|
|
114
|
-
if (options.dev || isSSR || !options.releaseId)
|
|
115
|
+
if (options.dev || options.mode === "preview" || isSSR || !options.releaseId)
|
|
116
|
+
return false;
|
|
117
|
+
if (url.searchParams.get("studio_embed") === "true" || url.searchParams.has("t"))
|
|
115
118
|
return false;
|
|
116
119
|
return url.searchParams.get(RELEASE_MODULE_VERSION_PARAM) === options.releaseId &&
|
|
117
120
|
url.searchParams.get(RELEASE_MODULE_RUNTIME_VERSION_PARAM) === VERSION;
|
|
@@ -319,6 +322,46 @@ export function serveModule(req, options) {
|
|
|
319
322
|
projectSlug = parsedHost.slug;
|
|
320
323
|
branch ??= parsedHost.branch;
|
|
321
324
|
}
|
|
325
|
+
const isSSR = isSSRModuleRequest(req, url);
|
|
326
|
+
const canUseReleaseModuleResponseCache = method === "GET" || method === "HEAD";
|
|
327
|
+
const canCacheReleaseVersionedModule = canUseReleaseModuleResponseCache &&
|
|
328
|
+
shouldCacheReleaseVersionedModule(url, options, isSSR);
|
|
329
|
+
let releaseDependencyManifest = null;
|
|
330
|
+
let releaseDependencyManifestVersion = null;
|
|
331
|
+
let releaseDependencyManifestReady = true;
|
|
332
|
+
if (canCacheReleaseVersionedModule) {
|
|
333
|
+
const manifestState = await getReleaseDependencyRewriteManifestState(options.releaseId);
|
|
334
|
+
if (manifestState.enabled) {
|
|
335
|
+
releaseDependencyManifest = manifestState.manifest;
|
|
336
|
+
releaseDependencyManifestVersion = manifestState.manifest?.manifestVersion ?? null;
|
|
337
|
+
releaseDependencyManifestReady = manifestState.manifest !== null;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
const releaseModuleResponseCacheKey = canCacheReleaseVersionedModule &&
|
|
341
|
+
releaseDependencyManifestReady
|
|
342
|
+
? buildReleaseModuleResponseCacheKey({
|
|
343
|
+
projectIdentity: effectiveProjectId,
|
|
344
|
+
projectDir,
|
|
345
|
+
projectSlug,
|
|
346
|
+
branch,
|
|
347
|
+
releaseId: options.releaseId,
|
|
348
|
+
runtimeVersion: VERSION,
|
|
349
|
+
reactVersion,
|
|
350
|
+
releaseDependencyManifestVersion,
|
|
351
|
+
modulePath,
|
|
352
|
+
})
|
|
353
|
+
: null;
|
|
354
|
+
if (releaseModuleResponseCacheKey) {
|
|
355
|
+
const cachedResponse = await getReleaseModuleResponse(releaseModuleResponseCacheKey);
|
|
356
|
+
if (cachedResponse?.entry) {
|
|
357
|
+
markRequestProfilePhase("module.response_cache_hit");
|
|
358
|
+
if (cachedResponse.source === "distributed") {
|
|
359
|
+
markRequestProfilePhase("module.response_cache_distributed_hit");
|
|
360
|
+
}
|
|
361
|
+
return createModuleResponse(method, cachedResponse.entry.body, cachedResponse.entry.status, Object.fromEntries(cachedResponse.entry.headers));
|
|
362
|
+
}
|
|
363
|
+
markRequestProfilePhase("module.response_cache_miss");
|
|
364
|
+
}
|
|
322
365
|
try {
|
|
323
366
|
const findResult = await profilePhase("module.source_lookup", () => findSourceFile(secureFs, projectDir, filePathWithoutExt, {
|
|
324
367
|
projectId: effectiveProjectId,
|
|
@@ -356,7 +399,6 @@ export function serveModule(req, options) {
|
|
|
356
399
|
: await secureFs.readFile(sourceFile);
|
|
357
400
|
}
|
|
358
401
|
const userAgent = req.headers.get("user-agent") ?? "";
|
|
359
|
-
const isSSR = isSSRModuleRequest(req, url);
|
|
360
402
|
const studioEmbed = url.searchParams.get("studio_embed") === "true";
|
|
361
403
|
const shouldInjectPositions = dev || options.mode === "preview";
|
|
362
404
|
const isJsxFile = /\.(tsx|jsx)$/i.test(sourceFile);
|
|
@@ -408,18 +450,27 @@ export function serveModule(req, options) {
|
|
|
408
450
|
if (!isSSR) {
|
|
409
451
|
code = await rewriteReleaseDependencyImportsForModule(code, {
|
|
410
452
|
releaseId: options.releaseId,
|
|
453
|
+
manifest: releaseDependencyManifest ?? undefined,
|
|
411
454
|
readDependencySource: (path) => platformFs.readTextFile(path),
|
|
412
455
|
});
|
|
413
456
|
code = await addReleaseVersionToFallbackImports(code, options.releaseId);
|
|
414
457
|
}
|
|
415
458
|
}
|
|
416
459
|
const headers = getModuleHeaders(modulePath, {
|
|
417
|
-
cacheable:
|
|
460
|
+
cacheable: releaseModuleResponseCacheKey !== null,
|
|
418
461
|
});
|
|
419
462
|
logger.debug("Request complete", {
|
|
420
463
|
path: modulePath,
|
|
421
464
|
durationMs: (performance.now() - startTime).toFixed(1),
|
|
422
465
|
});
|
|
466
|
+
if (releaseModuleResponseCacheKey && method === "GET") {
|
|
467
|
+
void rememberReleaseModuleResponse(releaseModuleResponseCacheKey, {
|
|
468
|
+
body: code,
|
|
469
|
+
status: HTTP_OK,
|
|
470
|
+
headers: Object.entries(headers),
|
|
471
|
+
});
|
|
472
|
+
markRequestProfilePhase("module.response_cache_store");
|
|
473
|
+
}
|
|
423
474
|
return createModuleResponse(method, code, HTTP_OK, headers);
|
|
424
475
|
}
|
|
425
476
|
catch (error) {
|
|
@@ -8,9 +8,17 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module release-assets/module-consumption
|
|
10
10
|
*/
|
|
11
|
+
import type { ReleaseAssetManifest } from "./manifest-schema.js";
|
|
11
12
|
export interface RewriteReleaseDependencyImportsOptions {
|
|
12
13
|
releaseId?: string | null;
|
|
13
14
|
readDependencySource: (path: string) => Promise<string>;
|
|
15
|
+
manifest?: ReleaseAssetManifest | null;
|
|
14
16
|
}
|
|
17
|
+
export interface ReleaseDependencyRewriteManifestState {
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
manifest: ReleaseAssetManifest | null;
|
|
20
|
+
}
|
|
21
|
+
export declare function isReleaseDependencyImportMapRewriteEnabled(): boolean;
|
|
22
|
+
export declare function getReleaseDependencyRewriteManifestState(releaseId: string | null | undefined): Promise<ReleaseDependencyRewriteManifestState>;
|
|
15
23
|
export declare function rewriteReleaseDependencyImportsForModule(code: string, options: RewriteReleaseDependencyImportsOptions): Promise<string>;
|
|
16
24
|
//# sourceMappingURL=module-consumption.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-consumption.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/module-consumption.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"module-consumption.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/module-consumption.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,MAAM,WAAW,sCAAsC;IACrD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,oBAAoB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,qCAAqC;IACpD,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAAC;CACvC;AAED,wBAAgB,0CAA0C,IAAI,OAAO,CAEpE;AAED,wBAAsB,wCAAwC,CAC5D,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GACnC,OAAO,CAAC,qCAAqC,CAAC,CAShD;AAmDD,wBAAsB,wCAAwC,CAC5D,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,sCAAsC,GAC9C,OAAO,CAAC,MAAM,CAAC,CA6BjB"}
|
|
@@ -14,6 +14,18 @@ import { parseImports, replaceSpecifiers } from "../transforms/esm/lexer.js";
|
|
|
14
14
|
import { extractSourceUrl } from "../transforms/esm/source-url-embed.js";
|
|
15
15
|
import { RELEASE_ASSET_DEPENDENCY_IMPORT_MAP_ENV_FLAG, releaseAssetUrl } from "./constants.js";
|
|
16
16
|
import { getReadyManifestForRenderAsync } from "./manifest-cache.js";
|
|
17
|
+
export function isReleaseDependencyImportMapRewriteEnabled() {
|
|
18
|
+
return getHostEnv(RELEASE_ASSET_DEPENDENCY_IMPORT_MAP_ENV_FLAG) === "1";
|
|
19
|
+
}
|
|
20
|
+
export async function getReleaseDependencyRewriteManifestState(releaseId) {
|
|
21
|
+
if (!releaseId || !isReleaseDependencyImportMapRewriteEnabled()) {
|
|
22
|
+
return { enabled: false, manifest: null };
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
enabled: true,
|
|
26
|
+
manifest: await getReadyManifestForRenderAsync(releaseId),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
17
29
|
function dependencyAssetUrl(manifest, specifier) {
|
|
18
30
|
const direct = manifest.dependencies[specifier] ??
|
|
19
31
|
manifest.dependencies[specifier.replace(/[?#].*$/, "")];
|
|
@@ -63,11 +75,13 @@ async function sourceUrlForLocalHttpBundle(specifier, readDependencySource) {
|
|
|
63
75
|
export async function rewriteReleaseDependencyImportsForModule(code, options) {
|
|
64
76
|
if (!options.releaseId)
|
|
65
77
|
return code;
|
|
66
|
-
if (
|
|
78
|
+
if (!isReleaseDependencyImportMapRewriteEnabled())
|
|
67
79
|
return code;
|
|
68
80
|
if (!code.includes("http") && !code.includes("veryfront-http-bundle"))
|
|
69
81
|
return code;
|
|
70
|
-
const manifest =
|
|
82
|
+
const manifest = options.manifest !== undefined
|
|
83
|
+
? options.manifest
|
|
84
|
+
: await getReadyManifestForRenderAsync(options.releaseId);
|
|
71
85
|
if (!manifest || Object.keys(manifest.dependencies).length === 0)
|
|
72
86
|
return code;
|
|
73
87
|
const replacements = new Map();
|