veryfront 0.1.823 → 0.1.825
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/loader-shared/filename-default-export.d.ts +2 -0
- package/esm/src/modules/loader-shared/filename-default-export.d.ts.map +1 -0
- package/esm/src/modules/loader-shared/filename-default-export.js +57 -0
- package/esm/src/modules/server/module-server.d.ts.map +1 -1
- package/esm/src/modules/server/module-server.js +2 -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 +2 -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 -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 @@
|
|
|
1
|
+
{"version":3,"file":"filename-default-export.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/loader-shared/filename-default-export.ts"],"names":[],"mappings":"AA8DA,wBAAgB,2BAA2B,CAAC,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAa9F"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const IDENTIFIER_PATTERN = /^[A-Za-z_$][\w$]*$/;
|
|
2
|
+
const DEFAULT_EXPORT_PATTERN = /\bexport\s+default\b|\bexport\s*\{[^}]*\bas\s+default\b[^}]*\}/;
|
|
3
|
+
function escapeRegex(value) {
|
|
4
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
|
+
}
|
|
6
|
+
function getModuleIdentifier(normalizedPath) {
|
|
7
|
+
const fileName = normalizedPath.replace(/\?.*$/, "").split("/").pop();
|
|
8
|
+
const identifier = fileName?.replace(/\.(?:[cm]?[jt]sx?|mdx)$/i, "");
|
|
9
|
+
if (!identifier || !IDENTIFIER_PATTERN.test(identifier))
|
|
10
|
+
return null;
|
|
11
|
+
return identifier;
|
|
12
|
+
}
|
|
13
|
+
function findExportMatch(moduleCode, exportName) {
|
|
14
|
+
const declarationPattern = new RegExp(`\\bexport\\s+(?:const|let|var|function|class)\\s+${escapeRegex(exportName)}\\b`);
|
|
15
|
+
if (declarationPattern.test(moduleCode))
|
|
16
|
+
return { localName: exportName, sourceClause: "" };
|
|
17
|
+
const exportListPattern = /\bexport\s*\{([^}]*)\}\s*(from\s*["'][^"']+["'])?\s*(?:;|$)/gm;
|
|
18
|
+
let match;
|
|
19
|
+
while ((match = exportListPattern.exec(moduleCode)) !== null) {
|
|
20
|
+
const specifiers = match[1]?.split(",") ?? [];
|
|
21
|
+
const sourceClause = match[2] ? ` ${match[2]}` : "";
|
|
22
|
+
for (const rawSpecifier of specifiers) {
|
|
23
|
+
const specifier = rawSpecifier.trim();
|
|
24
|
+
if (specifier === exportName)
|
|
25
|
+
return { localName: exportName, sourceClause };
|
|
26
|
+
const alias = specifier.match(/^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/);
|
|
27
|
+
if (alias?.[2] === exportName && alias[1]) {
|
|
28
|
+
return { localName: alias[1], sourceClause };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function appendExportBeforeSourceMap(moduleCode, exportStatement) {
|
|
35
|
+
const sourceMapMarker = "//# sourceMappingURL=";
|
|
36
|
+
let sourceMapIndex = moduleCode.lastIndexOf(`\n${sourceMapMarker}`);
|
|
37
|
+
if (sourceMapIndex < 0 && moduleCode.startsWith(sourceMapMarker)) {
|
|
38
|
+
sourceMapIndex = 0;
|
|
39
|
+
}
|
|
40
|
+
if (sourceMapIndex < 0) {
|
|
41
|
+
return `${moduleCode.trimEnd()}\n${exportStatement}\n`;
|
|
42
|
+
}
|
|
43
|
+
const beforeSourceMap = moduleCode.slice(0, sourceMapIndex).trimEnd();
|
|
44
|
+
const sourceMap = moduleCode.slice(sourceMapIndex);
|
|
45
|
+
return `${beforeSourceMap}\n${exportStatement}${sourceMap.endsWith("\n") ? sourceMap : `${sourceMap}\n`}`;
|
|
46
|
+
}
|
|
47
|
+
export function ensureFilenameDefaultExport(normalizedPath, moduleCode) {
|
|
48
|
+
if (DEFAULT_EXPORT_PATTERN.test(moduleCode))
|
|
49
|
+
return moduleCode;
|
|
50
|
+
const exportName = getModuleIdentifier(normalizedPath);
|
|
51
|
+
if (!exportName)
|
|
52
|
+
return moduleCode;
|
|
53
|
+
const exportMatch = findExportMatch(moduleCode, exportName);
|
|
54
|
+
if (!exportMatch)
|
|
55
|
+
return moduleCode;
|
|
56
|
+
return appendExportBeforeSourceMap(moduleCode, `export { ${exportMatch.localName} as default }${exportMatch.sourceClause};`);
|
|
57
|
+
}
|
|
@@ -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;AAuCtE;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAwDrD,CAAC;AAiBF,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,CA8XzF;AAwWD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGrD"}
|
|
@@ -21,6 +21,7 @@ import { readLimitedCrossProjectSource } from "./cross-project-source-limit.js";
|
|
|
21
21
|
import { sha256Short } from "../../cache/hash.js";
|
|
22
22
|
import { rewriteReleaseDependencyImportsForModule } from "../../release-assets/module-consumption.js";
|
|
23
23
|
import { buildSourceMissCacheKey, hasSourceMiss, rememberSourceMiss, } from "./module-source-resolution-cache.js";
|
|
24
|
+
import { ensureFilenameDefaultExport } from "../loader-shared/filename-default-export.js";
|
|
24
25
|
const logger = serverLogger.component("module-server");
|
|
25
26
|
const PROJECT_FALLBACK_EMBEDDED_POLYFILLS = new Set(["deno"]);
|
|
26
27
|
/**
|
|
@@ -348,6 +349,7 @@ export function serveModule(req, options) {
|
|
|
348
349
|
reactVersion,
|
|
349
350
|
};
|
|
350
351
|
code = await profileModuleTransform(() => transformToESM(source, sourceFile, projectDir, adapter, transformOpts));
|
|
352
|
+
code = ensureFilenameDefaultExport(modulePath, code);
|
|
351
353
|
if (isSSR) {
|
|
352
354
|
code = await applySSRImportRewritesAsync(code, {
|
|
353
355
|
projectSlug,
|
|
@@ -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;AAUjE;;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,7 @@ 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
|
+
import { ensureFilenameDefaultExport } from "../../../../modules/loader-shared/filename-default-export.js";
|
|
18
19
|
/**
|
|
19
20
|
* Normalize a module path, resolving relative paths if a parent is provided.
|
|
20
21
|
*/
|
|
@@ -40,6 +41,7 @@ export function normalizePath(modulePath, parentModulePath) {
|
|
|
40
41
|
* and updates the path cache map.
|
|
41
42
|
*/
|
|
42
43
|
export async function cacheModule(normalizedPath, moduleCode, esmCacheDir, pathCache, log, reactVersion = REACT_DEFAULT_VERSION) {
|
|
44
|
+
moduleCode = ensureFilenameDefaultExport(normalizedPath, moduleCode);
|
|
43
45
|
const unresolved = hasUnresolvedImports(moduleCode);
|
|
44
46
|
if (unresolved.count > 0) {
|
|
45
47
|
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;
|
|
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;AAGjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,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,6 +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 { ensureFilenameDefaultExport } from "../../../../modules/loader-shared/filename-default-export.js";
|
|
7
8
|
import { cacheModule } from "./module-cache.js";
|
|
8
9
|
import { writeDistributedCache } from "./distributed-cache.js";
|
|
9
10
|
/**
|
|
@@ -12,15 +13,16 @@ import { writeDistributedCache } from "./distributed-cache.js";
|
|
|
12
13
|
export async function persistResolvedModule(input) {
|
|
13
14
|
const writeToDistributedCache = input.writeToDistributedCache ?? writeDistributedCache;
|
|
14
15
|
const cacheLocalModule = input.cacheLocalModule ?? cacheModule;
|
|
16
|
+
const moduleCode = ensureFilenameDefaultExport(input.normalizedPath, input.moduleCode);
|
|
15
17
|
if (input.distributedCacheWrite) {
|
|
16
|
-
writeToDistributedCache(input.distributedCacheWrite.distributedCache, input.distributedCacheWrite.transformCacheKey, input.distributedCacheWrite.projectId, input.distributedCacheWrite.contentSourceId,
|
|
18
|
+
writeToDistributedCache(input.distributedCacheWrite.distributedCache, input.distributedCacheWrite.transformCacheKey, input.distributedCacheWrite.projectId, input.distributedCacheWrite.contentSourceId, moduleCode, input.normalizedPath, input.log);
|
|
17
19
|
}
|
|
18
20
|
input.log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule START`, {
|
|
19
21
|
projectSlug: input.projectSlug,
|
|
20
22
|
normalizedPath: input.normalizedPath,
|
|
21
23
|
});
|
|
22
24
|
const cacheStart = performance.now();
|
|
23
|
-
const finalCachedPath = await cacheLocalModule(input.normalizedPath,
|
|
25
|
+
const finalCachedPath = await cacheLocalModule(input.normalizedPath, moduleCode, input.esmCacheDir, input.pathCache, input.log, input.reactVersion);
|
|
24
26
|
input.log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule DONE`, {
|
|
25
27
|
projectSlug: input.projectSlug,
|
|
26
28
|
normalizedPath: input.normalizedPath,
|