veryfront 0.1.823 → 0.1.824
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/transforms/mdx/esm-module-loader/module-fetcher/module-cache.d.ts +1 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/module-cache.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/module-cache.js +54 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.js +4 -3
- 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
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* @module transforms/mdx/esm-module-loader/module-fetcher/module-cache
|
|
8
8
|
*/
|
|
9
9
|
import type { Logger } from "../../../../utils/logger/logger.js";
|
|
10
|
+
export declare function ensureFilenameDefaultExport(normalizedPath: string, moduleCode: string): string;
|
|
10
11
|
/**
|
|
11
12
|
* Normalize a module path, resolving relative paths if a parent is provided.
|
|
12
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-cache.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/module-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"module-cache.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/module-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAkEjE,wBAAgB,2BAA2B,CAAC,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAa9F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAanF;AAED;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,MAAM,EACX,YAAY,SAAwB,GACnC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqCxB"}
|
|
@@ -15,6 +15,59 @@ import { hashString } from "../utils/hash.js";
|
|
|
15
15
|
import { buildMdxEsmModuleFileName, buildMdxEsmPathCacheKey } from "../cache-format.js";
|
|
16
16
|
import { hasUnresolvedImports } from "./nested-imports.js";
|
|
17
17
|
import { recordModuleToSession } from "./render-sessions.js";
|
|
18
|
+
const IDENTIFIER_PATTERN = /^[A-Za-z_$][\w$]*$/;
|
|
19
|
+
const DEFAULT_EXPORT_PATTERN = /\bexport\s+default\b|\bexport\s*\{[^}]*\bas\s+default\b[^}]*\}/;
|
|
20
|
+
function escapeRegex(value) {
|
|
21
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22
|
+
}
|
|
23
|
+
function getModuleIdentifier(normalizedPath) {
|
|
24
|
+
const fileName = normalizedPath.replace(/\?.*$/, "").split("/").pop();
|
|
25
|
+
const identifier = fileName?.replace(/\.(?:[cm]?[jt]sx?|mdx)$/i, "");
|
|
26
|
+
if (!identifier || !IDENTIFIER_PATTERN.test(identifier))
|
|
27
|
+
return null;
|
|
28
|
+
return identifier;
|
|
29
|
+
}
|
|
30
|
+
function findExportMatch(moduleCode, exportName) {
|
|
31
|
+
const declarationPattern = new RegExp(`\\bexport\\s+(?:const|let|var|function|class)\\s+${escapeRegex(exportName)}\\b`);
|
|
32
|
+
if (declarationPattern.test(moduleCode))
|
|
33
|
+
return { localName: exportName, sourceClause: "" };
|
|
34
|
+
const exportListPattern = /\bexport\s*\{([^}]*)\}\s*(from\s*["'][^"']+["'])?\s*(?:;|$)/gm;
|
|
35
|
+
let match;
|
|
36
|
+
while ((match = exportListPattern.exec(moduleCode)) !== null) {
|
|
37
|
+
const specifiers = match[1]?.split(",") ?? [];
|
|
38
|
+
const sourceClause = match[2] ? ` ${match[2]}` : "";
|
|
39
|
+
for (const rawSpecifier of specifiers) {
|
|
40
|
+
const specifier = rawSpecifier.trim();
|
|
41
|
+
if (specifier === exportName)
|
|
42
|
+
return { localName: exportName, sourceClause };
|
|
43
|
+
const alias = specifier.match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);
|
|
44
|
+
if (alias?.[2] === exportName && alias[1]) {
|
|
45
|
+
return { localName: alias[1], sourceClause };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
function appendExportBeforeSourceMap(moduleCode, exportStatement) {
|
|
52
|
+
const sourceMapMatch = moduleCode.match(/\n\/\/# sourceMappingURL=.*$/);
|
|
53
|
+
if (sourceMapMatch?.index === undefined) {
|
|
54
|
+
return `${moduleCode.trimEnd()}\n${exportStatement}\n`;
|
|
55
|
+
}
|
|
56
|
+
const beforeSourceMap = moduleCode.slice(0, sourceMapMatch.index).trimEnd();
|
|
57
|
+
const sourceMap = moduleCode.slice(sourceMapMatch.index);
|
|
58
|
+
return `${beforeSourceMap}\n${exportStatement}${sourceMap.endsWith("\n") ? sourceMap : `${sourceMap}\n`}`;
|
|
59
|
+
}
|
|
60
|
+
export function ensureFilenameDefaultExport(normalizedPath, moduleCode) {
|
|
61
|
+
if (DEFAULT_EXPORT_PATTERN.test(moduleCode))
|
|
62
|
+
return moduleCode;
|
|
63
|
+
const exportName = getModuleIdentifier(normalizedPath);
|
|
64
|
+
if (!exportName)
|
|
65
|
+
return moduleCode;
|
|
66
|
+
const exportMatch = findExportMatch(moduleCode, exportName);
|
|
67
|
+
if (!exportMatch)
|
|
68
|
+
return moduleCode;
|
|
69
|
+
return appendExportBeforeSourceMap(moduleCode, `export { ${exportMatch.localName} as default }${exportMatch.sourceClause};`);
|
|
70
|
+
}
|
|
18
71
|
/**
|
|
19
72
|
* Normalize a module path, resolving relative paths if a parent is provided.
|
|
20
73
|
*/
|
|
@@ -40,6 +93,7 @@ export function normalizePath(modulePath, parentModulePath) {
|
|
|
40
93
|
* and updates the path cache map.
|
|
41
94
|
*/
|
|
42
95
|
export async function cacheModule(normalizedPath, moduleCode, esmCacheDir, pathCache, log, reactVersion = REACT_DEFAULT_VERSION) {
|
|
96
|
+
moduleCode = ensureFilenameDefaultExport(normalizedPath, moduleCode);
|
|
43
97
|
const unresolved = hasUnresolvedImports(moduleCode);
|
|
44
98
|
if (unresolved.count > 0) {
|
|
45
99
|
log.warn(`${LOG_PREFIX_MDX_LOADER} Module has ${unresolved.count} unresolved imports, skipping cache`, { path: normalizedPath, unresolved: unresolved.paths });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,WAAW,EAA+B,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,KAAK,kBAAkB,GAAG,OAAO,WAAW,CAAC;AAC7C,KAAK,uBAAuB,GAAG,OAAO,qBAAqB,CAAC;AAC5D,KAAK,gBAAgB,GAAG,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE;QACtB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,iBAAiB,EAAE,MAAM,CAAC;QAC1B,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IACtC,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;CACnD;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqCxB"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module transforms/mdx/esm-module-loader/module-fetcher/persistence
|
|
5
5
|
*/
|
|
6
6
|
import { LOG_PREFIX_MDX_LOADER } from "../constants.js";
|
|
7
|
-
import { cacheModule } from "./module-cache.js";
|
|
7
|
+
import { cacheModule, ensureFilenameDefaultExport } from "./module-cache.js";
|
|
8
8
|
import { writeDistributedCache } from "./distributed-cache.js";
|
|
9
9
|
/**
|
|
10
10
|
* Persist fully resolved module code to distributed and local caches.
|
|
@@ -12,15 +12,16 @@ import { writeDistributedCache } from "./distributed-cache.js";
|
|
|
12
12
|
export async function persistResolvedModule(input) {
|
|
13
13
|
const writeToDistributedCache = input.writeToDistributedCache ?? writeDistributedCache;
|
|
14
14
|
const cacheLocalModule = input.cacheLocalModule ?? cacheModule;
|
|
15
|
+
const moduleCode = ensureFilenameDefaultExport(input.normalizedPath, input.moduleCode);
|
|
15
16
|
if (input.distributedCacheWrite) {
|
|
16
|
-
writeToDistributedCache(input.distributedCacheWrite.distributedCache, input.distributedCacheWrite.transformCacheKey, input.distributedCacheWrite.projectId, input.distributedCacheWrite.contentSourceId,
|
|
17
|
+
writeToDistributedCache(input.distributedCacheWrite.distributedCache, input.distributedCacheWrite.transformCacheKey, input.distributedCacheWrite.projectId, input.distributedCacheWrite.contentSourceId, moduleCode, input.normalizedPath, input.log);
|
|
17
18
|
}
|
|
18
19
|
input.log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule START`, {
|
|
19
20
|
projectSlug: input.projectSlug,
|
|
20
21
|
normalizedPath: input.normalizedPath,
|
|
21
22
|
});
|
|
22
23
|
const cacheStart = performance.now();
|
|
23
|
-
const finalCachedPath = await cacheLocalModule(input.normalizedPath,
|
|
24
|
+
const finalCachedPath = await cacheLocalModule(input.normalizedPath, moduleCode, input.esmCacheDir, input.pathCache, input.log, input.reactVersion);
|
|
24
25
|
input.log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule DONE`, {
|
|
25
26
|
projectSlug: input.projectSlug,
|
|
26
27
|
normalizedPath: input.normalizedPath,
|