resuxjs 0.4.0-beta.4 → 0.4.0-beta.6
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/cli.d.ts +2 -2
- package/dist/compiler/implementation.d.ts +2 -0
- package/dist/compiler/implementation.js +186 -31
- package/dist/compiler/index.js.map +1 -1
- package/dist/deploy/vercel.js +9 -0
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/fonts/index.js +67 -45
- package/dist/fonts/index.js.map +1 -1
- package/dist/icons/index.d.ts +4 -14
- package/dist/icons/index.js +26 -55
- package/dist/icons/index.js.map +1 -1
- package/dist/icons/registry.d.ts +22 -0
- package/dist/icons/registry.js +84 -0
- package/dist/icons/registry.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/runtime/index.d.ts +14 -5
- package/dist/runtime/index.js +120 -15
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { isReactive, isReadonly, reactive, readonly } from "./reactivity/reactiv
|
|
|
4
4
|
import { computed } from "./reactivity/computed.js";
|
|
5
5
|
import { watch, watchEffect } from "./reactivity/watch.js";
|
|
6
6
|
import { nextTick } from "./reactivity/scheduler.js";
|
|
7
|
-
import { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentStyle, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadEntry, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, PackageAdapterContext, PackageAdapterDefinition, PageMeta, RenderAppOptions, RenderDocumentOptions, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, abortNavigation, clearError, createError, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, navigateTo, parseUserAgent, readBody, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderTemplateNodesAsync, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig } from "./runtime/index.js";
|
|
7
|
+
import { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentStyle, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadAttributePrimitive, HeadAttributeStyle, HeadAttributeValue, HeadAttributes, HeadEntry, HeadInput, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, PackageAdapterContext, PackageAdapterDefinition, PageMeta, RenderAppOptions, RenderDocumentOptions, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, abortNavigation, clearError, createError, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, navigateTo, parseUserAgent, readBody, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderTemplateNodesAsync, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig } from "./runtime/index.js";
|
|
8
8
|
import { IncomingMessage, ServerResponse } from "node:http";
|
|
9
9
|
|
|
10
10
|
//#region src/cli.d.ts
|
|
@@ -16,5 +16,5 @@ interface ResuxNodeHandlerOptions {
|
|
|
16
16
|
declare function createResuxNodeHandler(options?: ResuxNodeHandlerOptions): (request: IncomingMessage, response: ServerResponse) => void;
|
|
17
17
|
declare function runResuxCli(args: string[]): Promise<void>;
|
|
18
18
|
//#endregion
|
|
19
|
-
export { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentStyle, ComputedRef, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadEntry, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, MaybeRef, MaybeRefOrGetter, PackageAdapterContext, PackageAdapterDefinition, PageMeta, ReactiveEffectOptions, ReactiveEffectRunner, Ref, RenderAppOptions, RenderDocumentOptions, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxNodeHandlerOptions, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, WatchCallback, WatchOptions, WatchSource, WatchStopHandle, abortNavigation, clearError, computed, createError, createResuxNodeHandler, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, isReactive, isReadonly, isRef, navigateTo, nextTick, parseUserAgent, reactive, readBody, readonly, ref, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderTemplateNodesAsync, runResuxCli, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, toRef, toRefs, unref, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig, watch, watchEffect };
|
|
19
|
+
export { AsyncDataError, AsyncDataHandlerContext, AsyncDataResource, AsyncResuxRenderer, AwaitedAsyncDataResource, ClientEnhancementContext, ClientEnhancementSetup, ClientEnhancementTrigger, ClientPluginManifestRecord, ClientRouteMiddlewareManifestRecord, ClientRuntimeSourceOptions, ComponentDefinition, ComponentStyle, ComputedRef, DeviceInfo, ElementTemplateNode, EventHandler, EventHandlerEvent, ForDirective, HeadAttributePrimitive, HeadAttributeStyle, HeadAttributeValue, HeadAttributes, HeadEntry, HeadInput, HtmlDirective, IfDirective, InterpolationTemplateNode, JsonValue, MaybeRef, MaybeRefOrGetter, PackageAdapterContext, PackageAdapterDefinition, PageMeta, ReactiveEffectOptions, ReactiveEffectRunner, Ref, RenderAppOptions, RenderDocumentOptions, RenderResult, ResuxAppInjections, ResuxAppLike, ResuxAppProvides, ResuxClientBootMode, ResuxClientBootPlan, ResuxClientPackageImportRegistry, ResuxConfigInput, ResuxDeployOptions, ResuxDeployTarget, ResuxError, ResuxImageBuilder, ResuxImageCacheInput, ResuxImageConfig, ResuxImageFit, ResuxImageModifiers, ResuxImageProviderConfig, ResuxLazyPackageLoader, ResuxLazyPackageOptions, ResuxModule, ResuxModuleContext, ResuxNodeHandlerOptions, ResuxPackageCssMap, ResuxPackageMode, ResuxPackageModeMap, ResuxPackagesConfig, ResuxPayload, ResuxPlugin, ResuxRouteMiddleware, ResuxRouter, ResuxSupportMode, RouteContext, RouteMiddlewareResult, RouteRecord, RuntimeConfig, SeoMetaInput, SeoMetaValue, SerializedAsyncData, SerializedScope, ServerMiddleware, ServerMiddlewareResult, SetupContext, TemplateAttribute, TemplateEvent, TemplateNode, TextTemplateNode, UseClientEnhancementOptions, UseResuxImageOptions, WatchCallback, WatchOptions, WatchSource, WatchStopHandle, abortNavigation, clearError, computed, createError, createResuxNodeHandler, createServerSetupContext, defineClientEnhancement, defineClientOnlyPackage, defineComponent, defineEventHandler, defineLazyPackage, definePackageAdapter, defineResuxConfig, defineResuxModule, defineResuxPlugin, defineResuxRouteMiddleware, defineServerMiddleware, disposeClientEnhancements, evaluateExpression, eventHandler, getClientEnhancement, getClientRuntimeBootPlan, getClientRuntimeSource, getQuery, hasClientEnhancement, isReactive, isReadonly, isRef, navigateTo, nextTick, parseUserAgent, reactive, readBody, readonly, ref, renderApp, renderAppAsync, renderClientPatches, renderDocument, renderTemplateNodesAsync, runResuxCli, scanClientEnhancements, setHeader, shouldLoadClientRuntime, showError, toRef, toRefs, unref, useClientEnhancement, useClientPackage, useDevice, useError, useLazyPackage, usePackageReady, useResuxApp, useResuxImage, useRoute, useRouter, useRuntimeConfig, watch, watchEffect };
|
|
20
20
|
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -120,11 +120,13 @@ declare function buildProject(appRoot: string, outDir?: string, options?: BuildO
|
|
|
120
120
|
declare function compileVueFile(file: string, options: {
|
|
121
121
|
id: string;
|
|
122
122
|
name?: string;
|
|
123
|
+
outDir?: string;
|
|
123
124
|
}): Promise<CompiledComponent>;
|
|
124
125
|
declare function compileVueSource(source: string, options: {
|
|
125
126
|
file: string;
|
|
126
127
|
id: string;
|
|
127
128
|
name: string;
|
|
129
|
+
outDir?: string;
|
|
128
130
|
}): CompiledComponent;
|
|
129
131
|
declare function createRouteManifest(root: string, files: string[], idByFile?: Map<string, string>, compiledByFile?: Map<string, CompiledComponent>): RouteManifestRecord[];
|
|
130
132
|
declare function resolveFileExtension(filePath: string): string;
|
|
@@ -342,7 +342,8 @@ async function buildProject(appRoot, outDir = path.join(appRoot, ".resux"), opti
|
|
|
342
342
|
for (const file of allFiles) {
|
|
343
343
|
const component = await compileVueFile(file, {
|
|
344
344
|
id: idByFile.get(file),
|
|
345
|
-
name: inferComponentName(absoluteRoot, file, componentDirs)
|
|
345
|
+
name: inferComponentName(absoluteRoot, file, componentDirs),
|
|
346
|
+
outDir: absoluteOut
|
|
346
347
|
});
|
|
347
348
|
compiledByFile.set(file, component);
|
|
348
349
|
await writeFile(path.join(absoluteOut, "server", `${component.id}.mjs`), component.serverSource, "utf8");
|
|
@@ -508,7 +509,7 @@ async function buildProject(appRoot, outDir = path.join(appRoot, ".resux"), opti
|
|
|
508
509
|
manifest: runtimeArtifacts.manifest,
|
|
509
510
|
outDir: absoluteOut
|
|
510
511
|
});
|
|
511
|
-
await writeFile(path.join(absoluteOut, "server", "manifest.mjs"), createServerManifestSource(routes, components, layouts, plugins, middleware, serverMiddleware, serverHandlers, vueIslands, app, error, runtimeConfig, buildOptions), "utf8");
|
|
512
|
+
await writeFile(path.join(absoluteOut, "server", "manifest.mjs"), createServerManifestSource(routes, components, layouts, plugins, middleware, serverMiddleware, serverHandlers, vueIslands, app, error, runtimeConfig, buildOptions, absoluteRoot), "utf8");
|
|
512
513
|
await writeGeneratedArtifacts(absoluteOut, runtimeArtifacts, buildOptions.vite === "dev");
|
|
513
514
|
await hooks.callHook("prepare:types", {
|
|
514
515
|
outDir: absoluteOut,
|
|
@@ -767,7 +768,8 @@ async function compileVueFile(file, options) {
|
|
|
767
768
|
return compileVueSource(await readFile(file, "utf8"), {
|
|
768
769
|
file,
|
|
769
770
|
id: options.id,
|
|
770
|
-
name: options.name ?? pascalCase(path.basename(file, ".vue"))
|
|
771
|
+
name: options.name ?? pascalCase(path.basename(file, ".vue")),
|
|
772
|
+
outDir: options.outDir
|
|
771
773
|
});
|
|
772
774
|
}
|
|
773
775
|
function compileVueSource(source, options) {
|
|
@@ -791,7 +793,8 @@ function compileVueSource(source, options) {
|
|
|
791
793
|
styles: compiledStyles.styles,
|
|
792
794
|
styleScopeId: compiledStyles.styleScopeId,
|
|
793
795
|
client: false,
|
|
794
|
-
expressions: template.expressions
|
|
796
|
+
expressions: template.expressions,
|
|
797
|
+
outDir: options.outDir
|
|
795
798
|
});
|
|
796
799
|
const clientSource = createComponentModuleSource({
|
|
797
800
|
id: options.id,
|
|
@@ -802,7 +805,8 @@ function compileVueSource(source, options) {
|
|
|
802
805
|
styles: compiledStyles.styles,
|
|
803
806
|
styleScopeId: compiledStyles.styleScopeId,
|
|
804
807
|
client: true,
|
|
805
|
-
expressions: template.expressions
|
|
808
|
+
expressions: template.expressions,
|
|
809
|
+
outDir: options.outDir
|
|
806
810
|
});
|
|
807
811
|
return {
|
|
808
812
|
id: options.id,
|
|
@@ -1453,8 +1457,8 @@ const STYLESHEET_EXTENSIONS = new Set([
|
|
|
1453
1457
|
".stylus"
|
|
1454
1458
|
]);
|
|
1455
1459
|
function ensureCompiledUserModule(resolvedFile, projectRoot, outDir, compiledSet = /* @__PURE__ */ new Set()) {
|
|
1456
|
-
const
|
|
1457
|
-
const targetJsFile = path.join(outDir, "server", "imported",
|
|
1460
|
+
const safeRelativePath = normalizePath(path.relative(projectRoot, resolvedFile)).split("/").map((segment) => segment.replace(/_/g, "__").replace(/[%#?]/g, (character) => `_${character.codePointAt(0).toString(16).toUpperCase()}_`)).join("/").replace(/\.[jt]sx?$/, ".mjs");
|
|
1461
|
+
const targetJsFile = path.join(outDir, "server", "imported", safeRelativePath);
|
|
1458
1462
|
if (compiledSet.has(resolvedFile)) return targetJsFile;
|
|
1459
1463
|
compiledSet.add(resolvedFile);
|
|
1460
1464
|
let sourceText = "";
|
|
@@ -1499,7 +1503,13 @@ function ensureCompiledUserModule(resolvedFile, projectRoot, outDir, compiledSet
|
|
|
1499
1503
|
writeFileSync(targetJsFile, transpiled, "utf8");
|
|
1500
1504
|
return targetJsFile;
|
|
1501
1505
|
}
|
|
1502
|
-
function
|
|
1506
|
+
function resolveServerUserModuleImport(resolvedPath, file, outDir) {
|
|
1507
|
+
const projectRoot = findProjectRoot(file);
|
|
1508
|
+
const buildOutDir = outDir ? path.resolve(outDir) : path.join(projectRoot, ".resux");
|
|
1509
|
+
const compiledTarget = ensureCompiledUserModule(resolvedPath, projectRoot, buildOutDir);
|
|
1510
|
+
return relativeImportPath(path.join(buildOutDir, "server"), compiledTarget);
|
|
1511
|
+
}
|
|
1512
|
+
function processImportDeclaration(statement, sourceFile, file, client, outDir) {
|
|
1503
1513
|
if (ts.isImportDeclaration(statement)) {
|
|
1504
1514
|
const specifier = statement.moduleSpecifier;
|
|
1505
1515
|
if (!ts.isStringLiteral(specifier)) return statement.getFullText(sourceFile);
|
|
@@ -1547,10 +1557,8 @@ function processImportDeclaration(statement, sourceFile, file, client) {
|
|
|
1547
1557
|
const resolvedPath = resolveFileExtension(path.resolve(path.dirname(file), importPath));
|
|
1548
1558
|
const resolvedExt = path.extname(resolvedPath).toLowerCase();
|
|
1549
1559
|
let normalized = "";
|
|
1550
|
-
if (!client && (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx"))
|
|
1551
|
-
|
|
1552
|
-
normalized = fileUrl(ensureCompiledUserModule(resolvedPath, projectRoot, path.join(projectRoot, ".resux")));
|
|
1553
|
-
} else normalized = fileUrl(resolvedPath);
|
|
1560
|
+
if (!client && (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx")) normalized = resolveServerUserModuleImport(resolvedPath, file, outDir);
|
|
1561
|
+
else normalized = fileUrl(resolvedPath);
|
|
1554
1562
|
const fullText = statement.getFullText(sourceFile);
|
|
1555
1563
|
const start = specifier.getStart(sourceFile) - statement.getFullStart();
|
|
1556
1564
|
const end = specifier.getEnd() - statement.getFullStart();
|
|
@@ -1561,7 +1569,7 @@ function processImportDeclaration(statement, sourceFile, file, client) {
|
|
|
1561
1569
|
const resolvedPath = resolveFileExtension(path.resolve(projectRoot, importPath.slice(2)));
|
|
1562
1570
|
const resolvedExt = path.extname(resolvedPath).toLowerCase();
|
|
1563
1571
|
let normalized = "";
|
|
1564
|
-
if (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx") normalized =
|
|
1572
|
+
if (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx") normalized = resolveServerUserModuleImport(resolvedPath, file, outDir);
|
|
1565
1573
|
else normalized = fileUrl(resolvedPath);
|
|
1566
1574
|
const fullText = statement.getFullText(sourceFile);
|
|
1567
1575
|
const start = specifier.getStart(sourceFile) - statement.getFullStart();
|
|
@@ -1610,10 +1618,8 @@ function processImportDeclaration(statement, sourceFile, file, client) {
|
|
|
1610
1618
|
const resolvedPath = resolveFileExtension(path.resolve(path.dirname(file), importPath));
|
|
1611
1619
|
const resolvedExt = path.extname(resolvedPath).toLowerCase();
|
|
1612
1620
|
let normalized = "";
|
|
1613
|
-
if (!client && (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx"))
|
|
1614
|
-
|
|
1615
|
-
normalized = fileUrl(ensureCompiledUserModule(resolvedPath, projectRoot, path.join(projectRoot, ".resux")));
|
|
1616
|
-
} else normalized = fileUrl(resolvedPath);
|
|
1621
|
+
if (!client && (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx")) normalized = resolveServerUserModuleImport(resolvedPath, file, outDir);
|
|
1622
|
+
else normalized = fileUrl(resolvedPath);
|
|
1617
1623
|
const fullText = statement.getFullText(sourceFile);
|
|
1618
1624
|
const start = specifier.getStart(sourceFile) - statement.getFullStart();
|
|
1619
1625
|
const end = specifier.getEnd() - statement.getFullStart();
|
|
@@ -1624,7 +1630,7 @@ function processImportDeclaration(statement, sourceFile, file, client) {
|
|
|
1624
1630
|
const resolvedPath = resolveFileExtension(path.resolve(projectRoot, importPath.slice(2)));
|
|
1625
1631
|
const resolvedExt = path.extname(resolvedPath).toLowerCase();
|
|
1626
1632
|
let normalized = "";
|
|
1627
|
-
if (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx") normalized =
|
|
1633
|
+
if (resolvedExt === ".ts" || resolvedExt === ".tsx" || resolvedExt === ".js" || resolvedExt === ".jsx") normalized = resolveServerUserModuleImport(resolvedPath, file, outDir);
|
|
1628
1634
|
else normalized = fileUrl(resolvedPath);
|
|
1629
1635
|
const fullText = statement.getFullText(sourceFile);
|
|
1630
1636
|
const start = specifier.getStart(sourceFile) - statement.getFullStart();
|
|
@@ -1934,7 +1940,7 @@ function createComponentModuleSource(options) {
|
|
|
1934
1940
|
},`;
|
|
1935
1941
|
}).join("\n");
|
|
1936
1942
|
const importsText = (options.analysis.importDeclarations ?? []).map((decl) => {
|
|
1937
|
-
return processImportDeclaration(decl, options.analysis.sourceFile, options.file, options.client);
|
|
1943
|
+
return processImportDeclaration(decl, options.analysis.sourceFile, options.file, options.client, options.outDir);
|
|
1938
1944
|
}).filter(Boolean).join("\n");
|
|
1939
1945
|
const source = [
|
|
1940
1946
|
`import { ${factory} } from ${JSON.stringify(importPath)};`,
|
|
@@ -1983,7 +1989,7 @@ function relativeImportPath(fromDir, file) {
|
|
|
1983
1989
|
const relative = normalizePath(path.relative(fromDir, file));
|
|
1984
1990
|
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
1985
1991
|
}
|
|
1986
|
-
function createServerManifestSource(routes, components, layouts, plugins, middleware, serverMiddleware, serverHandlers, vueIslands, app, error, runtimeConfig = {}, buildOptions = {}) {
|
|
1992
|
+
function createServerManifestSource(routes, components, layouts, plugins, middleware, serverMiddleware, serverHandlers, vueIslands, app, error, runtimeConfig = {}, buildOptions = {}, appRoot = process.cwd()) {
|
|
1987
1993
|
const importSuffix = buildOptions.vite === "dev" ? `?t=${Date.now()}` : "";
|
|
1988
1994
|
const serverPlugins = plugins.filter((entry) => entry.mode !== "client");
|
|
1989
1995
|
const clientPlugins = plugins.filter((entry) => entry.mode !== "server");
|
|
@@ -2046,7 +2052,7 @@ function createServerManifestSource(routes, components, layouts, plugins, middle
|
|
|
2046
2052
|
match: createMatcher(${JSON.stringify(route.path)})
|
|
2047
2053
|
}`;
|
|
2048
2054
|
}).join(",\n");
|
|
2049
|
-
const appHead = createAppHead(runtimeConfig);
|
|
2055
|
+
const appHead = createAppHead(runtimeConfig, appRoot, buildOptions.vite !== "dev");
|
|
2050
2056
|
const appRuntimeConfig = createRuntimeConfig(runtimeConfig);
|
|
2051
2057
|
const routeRules = createRouteRules(runtimeConfig);
|
|
2052
2058
|
return `${imports}
|
|
@@ -2133,18 +2139,153 @@ function createMatcher(pattern) {
|
|
|
2133
2139
|
}
|
|
2134
2140
|
`;
|
|
2135
2141
|
}
|
|
2136
|
-
function createAppHead(runtimeConfig) {
|
|
2142
|
+
function createAppHead(runtimeConfig, appRoot, optimizeCss) {
|
|
2137
2143
|
const config = runtimeConfig;
|
|
2138
2144
|
const head = typeof config.app === "object" && config.app && "head" in config.app ? config.app.head : {};
|
|
2139
|
-
const
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2145
|
+
const headObject = typeof head === "object" && head ? head : {};
|
|
2146
|
+
const performanceConfig = readPerformanceRuntimeConfig(config);
|
|
2147
|
+
const csp = readSecurityContentSecurityPolicy(config, headObject);
|
|
2148
|
+
const inlineCss = optimizeCss && performanceConfig !== null && performanceConfig.inlineCss !== false && allowsInlineStyleForCsp(csp);
|
|
2149
|
+
const inlineCssMaxBytes = performanceConfig && Number.isFinite(performanceConfig.inlineCssMaxBytes) ? Math.max(0, Math.floor(performanceConfig.inlineCssMaxBytes)) : 65536;
|
|
2150
|
+
const { links: cssLinks, styles: criticalStyles } = splitCssEntriesPreservingOrder(collectConfiguredCssEntries(config.css, appRoot, inlineCss ? inlineCssMaxBytes : 0));
|
|
2151
|
+
const configuredLinks = Array.isArray(headObject.link) ? headObject.link : [];
|
|
2152
|
+
const configuredScripts = Array.isArray(headObject.script) ? headObject.script : [];
|
|
2153
|
+
const inlineScriptAttributeAllowed = allowsInlineScriptAttributeForCsp(csp);
|
|
2154
|
+
const inlineScriptElementAllowed = allowsInlineScriptElementForCsp(csp);
|
|
2155
|
+
return {
|
|
2156
|
+
...headObject,
|
|
2157
|
+
link: [...normalizeFontLinksForCsp(configuredLinks, inlineScriptAttributeAllowed, inlineScriptElementAllowed), ...cssLinks],
|
|
2158
|
+
style: [...criticalStyles, ...Array.isArray(headObject.style) ? headObject.style : []],
|
|
2159
|
+
script: inlineScriptElementAllowed ? configuredScripts : configuredScripts.filter((entry) => !isResuxFontLoaderScript(entry))
|
|
2160
|
+
};
|
|
2161
|
+
}
|
|
2162
|
+
function collectConfiguredCssEntries(cssConfig, appRoot, inlineCssMaxBytes) {
|
|
2163
|
+
if (!Array.isArray(cssConfig)) return [];
|
|
2164
|
+
return cssConfig.map((cssEntry) => String(cssEntry ?? "").trim()).filter(Boolean).map((href) => ({
|
|
2165
|
+
href,
|
|
2166
|
+
css: inlineCssMaxBytes > 0 ? readInlinePublicCss(appRoot, href, inlineCssMaxBytes) : null
|
|
2167
|
+
}));
|
|
2168
|
+
}
|
|
2169
|
+
function splitCssEntriesPreservingOrder(entries) {
|
|
2170
|
+
const lastLinkedCssIndex = entries.reduce((lastIndex, entry, index) => entry.css === null ? index : lastIndex, -1);
|
|
2171
|
+
const links = [];
|
|
2172
|
+
const styles = [];
|
|
2173
|
+
entries.forEach((entry, index) => {
|
|
2174
|
+
if (entry.css !== null && index > lastLinkedCssIndex) {
|
|
2175
|
+
styles.push({
|
|
2176
|
+
id: `resux-critical-${createHash("sha256").update(entry.href).digest("hex").slice(0, 12)}`,
|
|
2177
|
+
css: entry.css
|
|
2178
|
+
});
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
links.push({
|
|
2182
|
+
rel: "stylesheet",
|
|
2183
|
+
href: entry.href
|
|
2184
|
+
});
|
|
2185
|
+
});
|
|
2143
2186
|
return {
|
|
2144
|
-
|
|
2145
|
-
|
|
2187
|
+
links,
|
|
2188
|
+
styles
|
|
2146
2189
|
};
|
|
2147
2190
|
}
|
|
2191
|
+
function readPerformanceRuntimeConfig(config) {
|
|
2192
|
+
const runtime = isPlainObject(config.runtimeConfig) ? config.runtimeConfig : {};
|
|
2193
|
+
const publicConfig = isPlainObject(runtime.public) ? runtime.public : {};
|
|
2194
|
+
return isPlainObject(publicConfig.performanceModule) ? publicConfig.performanceModule : null;
|
|
2195
|
+
}
|
|
2196
|
+
function readSecurityContentSecurityPolicy(config, head) {
|
|
2197
|
+
const runtime = isPlainObject(config.runtimeConfig) ? config.runtimeConfig : {};
|
|
2198
|
+
const configured = firstString((isPlainObject(runtime.resuxSecurity) ? runtime.resuxSecurity : {}).contentSecurityPolicy);
|
|
2199
|
+
if (configured) return configured;
|
|
2200
|
+
const meta = Array.isArray(head.meta) ? head.meta : [];
|
|
2201
|
+
for (const entry of meta) {
|
|
2202
|
+
if (!isPlainObject(entry)) continue;
|
|
2203
|
+
if (String(entry["http-equiv"] ?? entry.httpEquiv ?? "").trim().toLowerCase() !== "content-security-policy") continue;
|
|
2204
|
+
const content = firstString(entry.content);
|
|
2205
|
+
if (content) return content;
|
|
2206
|
+
}
|
|
2207
|
+
return "";
|
|
2208
|
+
}
|
|
2209
|
+
function cspDirectiveSources(csp, names) {
|
|
2210
|
+
if (!csp.trim()) return null;
|
|
2211
|
+
const directives = /* @__PURE__ */ new Map();
|
|
2212
|
+
for (const rawDirective of csp.split(";")) {
|
|
2213
|
+
const tokens = rawDirective.trim().split(/\s+/).filter(Boolean);
|
|
2214
|
+
if (!tokens.length) continue;
|
|
2215
|
+
directives.set(tokens[0].toLowerCase(), tokens.slice(1));
|
|
2216
|
+
}
|
|
2217
|
+
for (const name of names) {
|
|
2218
|
+
const sources = directives.get(name);
|
|
2219
|
+
if (sources) return sources;
|
|
2220
|
+
}
|
|
2221
|
+
return null;
|
|
2222
|
+
}
|
|
2223
|
+
function allowsInlineStyleForCsp(csp) {
|
|
2224
|
+
const sources = cspDirectiveSources(csp, [
|
|
2225
|
+
"style-src-elem",
|
|
2226
|
+
"style-src",
|
|
2227
|
+
"default-src"
|
|
2228
|
+
]);
|
|
2229
|
+
return sources === null || sources.includes("'unsafe-inline'");
|
|
2230
|
+
}
|
|
2231
|
+
function allowsInlineScriptAttributeForCsp(csp) {
|
|
2232
|
+
const sources = cspDirectiveSources(csp, [
|
|
2233
|
+
"script-src-attr",
|
|
2234
|
+
"script-src",
|
|
2235
|
+
"default-src"
|
|
2236
|
+
]);
|
|
2237
|
+
return sources === null || sources.includes("'unsafe-inline'");
|
|
2238
|
+
}
|
|
2239
|
+
function allowsInlineScriptElementForCsp(csp) {
|
|
2240
|
+
const sources = cspDirectiveSources(csp, [
|
|
2241
|
+
"script-src-elem",
|
|
2242
|
+
"script-src",
|
|
2243
|
+
"default-src"
|
|
2244
|
+
]);
|
|
2245
|
+
return sources === null || sources.includes("'unsafe-inline'");
|
|
2246
|
+
}
|
|
2247
|
+
function normalizeFontLinksForCsp(links, inlineScriptAttributeAllowed, inlineScriptElementAllowed) {
|
|
2248
|
+
return links.map((link) => {
|
|
2249
|
+
const next = { ...link };
|
|
2250
|
+
const needsInlineAttribute = next["data-resux-font-async"] === "true";
|
|
2251
|
+
const needsInlineScript = next["data-resux-font-lazy"] === "true";
|
|
2252
|
+
if (needsInlineAttribute && !inlineScriptAttributeAllowed || needsInlineScript && !inlineScriptElementAllowed) {
|
|
2253
|
+
delete next.media;
|
|
2254
|
+
delete next.onload;
|
|
2255
|
+
delete next["data-resux-font-async"];
|
|
2256
|
+
delete next["data-resux-font-lazy"];
|
|
2257
|
+
}
|
|
2258
|
+
return next;
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
function isResuxFontLoaderScript(entry) {
|
|
2262
|
+
return entry["data-resux-font-loader"] === "true";
|
|
2263
|
+
}
|
|
2264
|
+
function readInlinePublicCss(appRoot, href, maxBytes) {
|
|
2265
|
+
if (maxBytes <= 0 || !href.startsWith("/") || href.startsWith("//") || href.includes("..") || /^[a-z][a-z0-9+.-]*:/i.test(href)) return null;
|
|
2266
|
+
const pathname = href.split(/[?#]/, 1)[0];
|
|
2267
|
+
if (!pathname.toLowerCase().endsWith(".css")) return null;
|
|
2268
|
+
const publicRoot = path.resolve(appRoot, "public");
|
|
2269
|
+
const staticRoot = path.resolve(appRoot, "static");
|
|
2270
|
+
const relativePath = pathname.replace(/^\/+/, "");
|
|
2271
|
+
const candidates = [path.resolve(publicRoot, relativePath), path.resolve(staticRoot, relativePath)];
|
|
2272
|
+
for (const candidate of candidates) {
|
|
2273
|
+
if (!(candidate.startsWith(publicRoot + path.sep) ? publicRoot : candidate.startsWith(staticRoot + path.sep) ? staticRoot : null) || !existsSync(candidate)) continue;
|
|
2274
|
+
const css = ts.sys.readFile(candidate);
|
|
2275
|
+
if (typeof css !== "string" || Buffer.byteLength(css, "utf8") > maxBytes || hasRelativeCssReferences(css)) continue;
|
|
2276
|
+
return css;
|
|
2277
|
+
}
|
|
2278
|
+
return null;
|
|
2279
|
+
}
|
|
2280
|
+
function hasRelativeCssReferences(css) {
|
|
2281
|
+
for (const match of css.matchAll(/url\(\s*(?:"([^"]*)"|'([^']*)'|([^)"']+))\s*\)/gi)) if (isRelativeCssReference(String(match[1] ?? match[2] ?? match[3] ?? "").trim())) return true;
|
|
2282
|
+
for (const match of css.matchAll(/@import\s+(?:url\(\s*)?(?:"([^"]*)"|'([^']*)'|([^\s;)]+))/gi)) if (isRelativeCssReference(String(match[1] ?? match[2] ?? match[3] ?? "").trim())) return true;
|
|
2283
|
+
return false;
|
|
2284
|
+
}
|
|
2285
|
+
function isRelativeCssReference(value) {
|
|
2286
|
+
if (!value || value.startsWith("/") || value.startsWith("#") || value.startsWith("//")) return false;
|
|
2287
|
+
return !/^(?:data|blob|https?):/i.test(value);
|
|
2288
|
+
}
|
|
2148
2289
|
function scanRuntimeConfigForSecrets(config, halalConfig) {
|
|
2149
2290
|
const publicConfig = config.public;
|
|
2150
2291
|
if (!publicConfig || typeof publicConfig !== "object") return;
|
|
@@ -2509,17 +2650,27 @@ const builtinModules$1 = {
|
|
|
2509
2650
|
const csp = firstString(input.contentSecurityPolicy);
|
|
2510
2651
|
if (csp) headers["content-security-policy"] = csp;
|
|
2511
2652
|
resux.addRouteRule(routePath, { headers });
|
|
2512
|
-
resux.extendRuntimeConfig({
|
|
2653
|
+
resux.extendRuntimeConfig({
|
|
2654
|
+
public: { securityHeaders: true },
|
|
2655
|
+
resuxSecurity: {
|
|
2656
|
+
contentSecurityPolicy: csp ?? "",
|
|
2657
|
+
route: routePath
|
|
2658
|
+
}
|
|
2659
|
+
});
|
|
2513
2660
|
}
|
|
2514
2661
|
},
|
|
2515
2662
|
performance: {
|
|
2516
2663
|
defaults: {
|
|
2517
2664
|
assetMaxAge: 31536e3,
|
|
2518
|
-
routePayloadNoStore: true
|
|
2665
|
+
routePayloadNoStore: true,
|
|
2666
|
+
inlineCss: true,
|
|
2667
|
+
inlineCssMaxBytes: 65536
|
|
2519
2668
|
},
|
|
2520
2669
|
setup(options, resux) {
|
|
2521
2670
|
const input = isPlainObject(options) ? options : {};
|
|
2522
2671
|
const maxAge = Number.isFinite(input.assetMaxAge) ? Math.max(0, Math.floor(input.assetMaxAge)) : 31536e3;
|
|
2672
|
+
const inlineCss = input.inlineCss !== false;
|
|
2673
|
+
const inlineCssMaxBytes = Number.isFinite(input.inlineCssMaxBytes) ? Math.max(0, Math.floor(input.inlineCssMaxBytes)) : 65536;
|
|
2523
2674
|
const assetCache = { maxAge };
|
|
2524
2675
|
resux.addRouteRule("/__resux/runtime-client.mjs", { cache: assetCache });
|
|
2525
2676
|
resux.addRouteRule("/__resux/handlers/**", { cache: assetCache });
|
|
@@ -2527,7 +2678,11 @@ const builtinModules$1 = {
|
|
|
2527
2678
|
resux.addRouteRule("/__resux/image", { cache: assetCache });
|
|
2528
2679
|
resux.addRouteRule("/__resux/video", { cache: assetCache });
|
|
2529
2680
|
if (input.routePayloadNoStore !== false) resux.addRouteRule("/__resux/route", { cache: false });
|
|
2530
|
-
resux.extendRuntimeConfig({ public: { performanceModule: {
|
|
2681
|
+
resux.extendRuntimeConfig({ public: { performanceModule: {
|
|
2682
|
+
assetMaxAge: maxAge,
|
|
2683
|
+
inlineCss,
|
|
2684
|
+
inlineCssMaxBytes
|
|
2685
|
+
} } });
|
|
2531
2686
|
}
|
|
2532
2687
|
}
|
|
2533
2688
|
};
|