@chuckcchen/vite-plugin 1.0.19 → 1.0.21
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/bundler.d.ts +5 -18
- package/dist/bundler.d.ts.map +1 -1
- package/dist/bundler.js +43 -30
- package/dist/bundler.js.map +1 -1
- package/dist/core.d.ts +2 -18
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +125 -248
- package/dist/core.js.map +1 -1
- package/dist/factory/detectors.d.ts +5 -15
- package/dist/factory/detectors.d.ts.map +1 -1
- package/dist/factory/detectors.js +8 -22
- package/dist/factory/detectors.js.map +1 -1
- package/dist/factory/hooks.d.ts +4 -59
- package/dist/factory/hooks.d.ts.map +1 -1
- package/dist/factory/hooks.js +18 -117
- package/dist/factory/hooks.js.map +1 -1
- package/dist/factory/index.d.ts +7 -51
- package/dist/factory/index.d.ts.map +1 -1
- package/dist/factory/index.js +10 -55
- package/dist/factory/index.js.map +1 -1
- package/dist/factory/presets.d.ts +16 -121
- package/dist/factory/presets.d.ts.map +1 -1
- package/dist/factory/presets.js +143 -174
- package/dist/factory/presets.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -35
- package/dist/index.js.map +1 -1
- package/dist/route/index.d.ts +1 -1
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +1 -3
- package/dist/route/index.js.map +1 -1
- package/dist/route/parser.d.ts +0 -37
- package/dist/route/parser.d.ts.map +1 -1
- package/dist/route/parser.js +11 -124
- package/dist/route/parser.js.map +1 -1
- package/dist/route/regex.d.ts +15 -80
- package/dist/route/regex.d.ts.map +1 -1
- package/dist/route/regex.js +65 -169
- package/dist/route/regex.js.map +1 -1
- package/dist/route/regex.test.d.ts +7 -0
- package/dist/route/regex.test.d.ts.map +1 -0
- package/dist/route/regex.test.js +662 -0
- package/dist/route/regex.test.js.map +1 -0
- package/dist/route/types.d.ts +0 -58
- package/dist/route/types.d.ts.map +1 -1
- package/dist/types.d.ts +36 -147
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +1 -78
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -144
- package/dist/utils.js.map +1 -1
- package/dist/vite-config-parser.d.ts +4 -141
- package/dist/vite-config-parser.d.ts.map +1 -1
- package/dist/vite-config-parser.js +25 -235
- package/dist/vite-config-parser.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,42 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Framework Detectors
|
|
3
|
-
*
|
|
4
|
-
* Utilities for detecting frameworks based on config files, build directories, and dependencies
|
|
2
|
+
* Framework Detectors - Utilities for detecting frameworks
|
|
5
3
|
*/
|
|
6
4
|
import path from "path";
|
|
7
|
-
import { pathExists, readFile, detectConfigFile, detectBuildDir
|
|
8
|
-
/**
|
|
9
|
-
* Combine multiple detector functions (returns true if any matches)
|
|
10
|
-
*/
|
|
5
|
+
import { pathExists, readFile, detectConfigFile, detectBuildDir } from "../utils.js";
|
|
6
|
+
/** Combine multiple detector functions (returns true if any matches) */
|
|
11
7
|
export function combineDetectors(...detectors) {
|
|
12
8
|
return async (context) => {
|
|
13
9
|
for (const detector of detectors) {
|
|
14
|
-
if (await detector(context))
|
|
10
|
+
if (await detector(context))
|
|
15
11
|
return true;
|
|
16
|
-
}
|
|
17
12
|
}
|
|
18
13
|
return false;
|
|
19
14
|
};
|
|
20
15
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Create detector based on config files
|
|
23
|
-
*/
|
|
16
|
+
/** Create detector based on config files */
|
|
24
17
|
export function createConfigDetector(configFiles) {
|
|
25
18
|
return async (context) => {
|
|
26
19
|
return (await detectConfigFile(context.projectRoot, configFiles)) !== null;
|
|
27
20
|
};
|
|
28
21
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Create detector based on build directories
|
|
31
|
-
*/
|
|
22
|
+
/** Create detector based on build directories */
|
|
32
23
|
export function createBuildDirDetector(buildDirs) {
|
|
33
24
|
return async (context) => {
|
|
34
25
|
return (await detectBuildDir(context.projectRoot, buildDirs)) !== null;
|
|
35
26
|
};
|
|
36
27
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Create detector based on package.json dependencies
|
|
39
|
-
*/
|
|
28
|
+
/** Create detector based on package.json dependencies */
|
|
40
29
|
export function createDependencyDetector(dependencies) {
|
|
41
30
|
return async (context) => {
|
|
42
31
|
const packageJsonPath = path.join(context.projectRoot, "package.json");
|
|
@@ -45,10 +34,7 @@ export function createDependencyDetector(dependencies) {
|
|
|
45
34
|
try {
|
|
46
35
|
const content = await readFile(packageJsonPath);
|
|
47
36
|
const packageJson = JSON.parse(content);
|
|
48
|
-
const deps = {
|
|
49
|
-
...packageJson.dependencies,
|
|
50
|
-
...packageJson.devDependencies,
|
|
51
|
-
};
|
|
37
|
+
const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
52
38
|
return dependencies.some((dep) => dep in deps);
|
|
53
39
|
}
|
|
54
40
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../src/factory/detectors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../src/factory/detectors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAErF,wEAAwE;AACxE,MAAM,UAAU,gBAAgB,CAC9B,GAAG,SAAoE;IAEvE,OAAO,KAAK,EAAE,OAAqB,EAAoB,EAAE;QACvD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,MAAM,QAAQ,CAAC,OAAO,CAAC;gBAAE,OAAO,IAAI,CAAC;QAC3C,CAAC;QACD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C,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACrH,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/factory/hooks.d.ts
CHANGED
|
@@ -1,84 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hook Creation Functions
|
|
3
|
-
*
|
|
4
|
-
* Internal functions for creating adapter hooks
|
|
2
|
+
* Hook Creation Functions - Internal functions for creating adapter hooks
|
|
5
3
|
*/
|
|
6
|
-
import type { BuildContext, BuildArtifacts, RouteInfo, MetaConfig, ServerWrapperConfig, ServerBundleConfig } from "../types.js";
|
|
4
|
+
import type { BuildContext, BuildArtifacts, RouteInfo, MetaConfig, ServerWrapperConfig, ServerBundleConfig, EsbuildConfig, ServerWrapperPreset } from "../types.js";
|
|
7
5
|
import { type RouteSource } from "../route/index.js";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Build directory configuration
|
|
11
|
-
*/
|
|
6
|
+
export type { EsbuildConfig, ServerWrapperPreset };
|
|
12
7
|
export interface BuildDirConfig {
|
|
13
8
|
client: string[];
|
|
14
9
|
server?: string[];
|
|
15
10
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Route source configuration for declarative route parsing
|
|
18
|
-
*/
|
|
19
11
|
export interface RouteSourceConfig {
|
|
20
|
-
/** Route sources to try in order */
|
|
21
12
|
sources?: RouteSource[];
|
|
22
|
-
/** Default routes if no sources match */
|
|
23
13
|
defaultRoutes?: string[];
|
|
24
|
-
/** Extra routes to add in SSR mode */
|
|
25
14
|
ssrExtraRoutes?: string[];
|
|
26
|
-
/** Transform function for parsed routes */
|
|
27
15
|
transform?: (routes: RouteInfo[], context: BuildContext) => RouteInfo[];
|
|
28
16
|
}
|
|
29
|
-
/**
|
|
30
|
-
* esbuild configuration for server bundling
|
|
31
|
-
*/
|
|
32
|
-
export interface EsbuildConfig {
|
|
33
|
-
/** Working directory for esbuild */
|
|
34
|
-
absWorkingDir?: string | ((context: BuildContext) => string);
|
|
35
|
-
/** External modules */
|
|
36
|
-
external?: string[];
|
|
37
|
-
/** Additional esbuild options */
|
|
38
|
-
options?: Record<string, unknown>;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Adapter factory options (runtime)
|
|
42
|
-
*/
|
|
43
17
|
export interface AdapterFactoryOptions {
|
|
44
18
|
clientBuildDir?: string;
|
|
45
19
|
serverBuildDir?: string;
|
|
46
20
|
serverEntry?: string;
|
|
47
21
|
routes?: string[];
|
|
48
22
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Create default detect function based on config files
|
|
51
|
-
*/
|
|
52
23
|
export declare function createDefaultDetector(configFiles: string[]): (context: BuildContext) => Promise<boolean>;
|
|
53
|
-
/**
|
|
54
|
-
* Create default getBuildArtifacts function
|
|
55
|
-
* Uses ViteConfigParser for comprehensive Vite config support:
|
|
56
|
-
* - build.outDir: custom output directory
|
|
57
|
-
* - build.assetsDir: static assets directory name
|
|
58
|
-
* - build.ssr: SSR entry point
|
|
59
|
-
* - build.manifest: manifest.json generation
|
|
60
|
-
* - base: public base path
|
|
61
|
-
* - rollupOptions.input: entry file(s)
|
|
62
|
-
* - rollupOptions.output.dir: output directory override
|
|
63
|
-
* - rollupOptions.output.entryFileNames: output filename pattern
|
|
64
|
-
* - rollupOptions.output.assetFileNames: asset filename pattern
|
|
65
|
-
* - rollupOptions.output.chunkFileNames: chunk filename pattern
|
|
66
|
-
*/
|
|
67
24
|
export declare function createDefaultBuildArtifactsGetter(name: string, buildDirs: BuildDirConfig, serverEntryFiles: string[], options: AdapterFactoryOptions): (context: BuildContext) => Promise<BuildArtifacts>;
|
|
68
|
-
/**
|
|
69
|
-
* Create generateRoutes hook
|
|
70
|
-
*/
|
|
71
25
|
export declare function createGenerateRoutesHook(effectiveRouteConfig: RouteSourceConfig, fallbackRoutes: string[]): (context: BuildContext) => Promise<RouteInfo[]>;
|
|
72
|
-
/**
|
|
73
|
-
* Create generateMeta hook
|
|
74
|
-
*/
|
|
75
26
|
export declare function createGenerateMetaHook(ssr404?: boolean | ((isSSR: boolean) => boolean)): (context: BuildContext, routeList: RouteInfo[]) => Promise<MetaConfig>;
|
|
76
|
-
|
|
77
|
-
* Create generateServerWrapper hook
|
|
78
|
-
*/
|
|
79
|
-
export declare function createGenerateServerWrapperHook(wrapperConfig: ServerWrapperPreset, htmlTemplatePaths: string[]): (context: BuildContext, wrapperCfg: ServerWrapperConfig) => Promise<string>;
|
|
80
|
-
/**
|
|
81
|
-
* Create beforeBundle hook if esbuildConfig is provided
|
|
82
|
-
*/
|
|
27
|
+
export declare function createGenerateServerWrapperHook(wrapperConfig: ServerWrapperPreset): (_context: BuildContext, wrapperCfg: ServerWrapperConfig) => Promise<string>;
|
|
83
28
|
export declare function createBeforeBundleHook(esbuildConfig: EsbuildConfig): (context: BuildContext, bundleConfig: ServerBundleConfig) => Promise<ServerBundleConfig>;
|
|
84
29
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/factory/hooks.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/factory/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAqD,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIxG,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,iB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YAAY,EAAE,cAAc,kBAAkB,KAAG,OAAO,CAAC,kBAAkB,CAAC,CAepG"}
|
package/dist/factory/hooks.js
CHANGED
|
@@ -1,73 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Hook Creation Functions
|
|
3
|
-
*
|
|
4
|
-
* Internal functions for creating adapter hooks
|
|
2
|
+
* Hook Creation Functions - Internal functions for creating adapter hooks
|
|
5
3
|
*/
|
|
6
4
|
import path from "path";
|
|
7
|
-
import { pathExists,
|
|
5
|
+
import { pathExists, detectConfigFile, detectBuildDir, detectServerEntry, generateServerWrapperCode, createDefaultMeta, logBuildArtifacts, } from "../utils.js";
|
|
8
6
|
import { ViteConfigParser } from "../vite-config-parser.js";
|
|
9
7
|
import { parseRoutesFromSources, convertRoutesToMetaFormat } from "../route/index.js";
|
|
10
|
-
|
|
11
|
-
// Hook Creation Functions
|
|
12
|
-
// ============================================================================
|
|
13
|
-
/**
|
|
14
|
-
* Create default detect function based on config files
|
|
15
|
-
*/
|
|
8
|
+
import { resolvePreset } from "./presets.js";
|
|
16
9
|
export function createDefaultDetector(configFiles) {
|
|
17
10
|
return async (context) => {
|
|
18
|
-
|
|
19
|
-
return configPath !== null;
|
|
11
|
+
return (await detectConfigFile(context.projectRoot, configFiles)) !== null;
|
|
20
12
|
};
|
|
21
13
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Create default getBuildArtifacts function
|
|
24
|
-
* Uses ViteConfigParser for comprehensive Vite config support:
|
|
25
|
-
* - build.outDir: custom output directory
|
|
26
|
-
* - build.assetsDir: static assets directory name
|
|
27
|
-
* - build.ssr: SSR entry point
|
|
28
|
-
* - build.manifest: manifest.json generation
|
|
29
|
-
* - base: public base path
|
|
30
|
-
* - rollupOptions.input: entry file(s)
|
|
31
|
-
* - rollupOptions.output.dir: output directory override
|
|
32
|
-
* - rollupOptions.output.entryFileNames: output filename pattern
|
|
33
|
-
* - rollupOptions.output.assetFileNames: asset filename pattern
|
|
34
|
-
* - rollupOptions.output.chunkFileNames: chunk filename pattern
|
|
35
|
-
*/
|
|
36
14
|
export function createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFiles, options) {
|
|
37
15
|
const { clientBuildDir, serverBuildDir, serverEntry } = options;
|
|
38
16
|
return async (context) => {
|
|
39
17
|
const { projectRoot, isSSR, logger, viteConfig } = context;
|
|
40
|
-
// Resolve client directory
|
|
41
18
|
let clientDir = null;
|
|
42
19
|
let serverDir = null;
|
|
43
20
|
let serverEntryPath = null;
|
|
44
|
-
// Create ViteConfigParser once if viteConfig is available
|
|
45
21
|
const configParser = viteConfig
|
|
46
|
-
? new ViteConfigParser(viteConfig, projectRoot, {
|
|
47
|
-
logger,
|
|
48
|
-
serverEntryCandidates: serverEntryFiles,
|
|
49
|
-
})
|
|
22
|
+
? new ViteConfigParser(viteConfig, projectRoot, { logger, serverEntryCandidates: serverEntryFiles })
|
|
50
23
|
: null;
|
|
51
24
|
if (clientBuildDir) {
|
|
52
25
|
clientDir = path.join(projectRoot, clientBuildDir);
|
|
53
26
|
}
|
|
54
27
|
else if (configParser) {
|
|
55
28
|
const configInfo = await configParser.parse();
|
|
56
|
-
// For SSR builds, client is typically in outDir/client or check buildDirs
|
|
57
29
|
if (isSSR) {
|
|
58
|
-
// Try outDir/client first (common SSR pattern)
|
|
59
30
|
const clientInOutDir = path.join(configInfo.absoluteOutDir, "client");
|
|
60
31
|
if (await pathExists(clientInOutDir)) {
|
|
61
32
|
clientDir = clientInOutDir;
|
|
62
33
|
logger.verbose(`Found client directory from Vite config: ${clientDir}`);
|
|
63
34
|
}
|
|
64
35
|
else {
|
|
65
|
-
// Fall back to buildDirs detection
|
|
66
36
|
clientDir = await detectBuildDir(projectRoot, buildDirs.client);
|
|
67
37
|
}
|
|
68
38
|
}
|
|
69
39
|
else {
|
|
70
|
-
// SPA mode - output dir is the client dir
|
|
71
40
|
if (await pathExists(configInfo.absoluteOutDir)) {
|
|
72
41
|
clientDir = configInfo.absoluteOutDir;
|
|
73
42
|
logger.verbose(`Found client directory (SPA) from Vite config: ${clientDir}`);
|
|
@@ -82,40 +51,29 @@ export function createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFi
|
|
|
82
51
|
}
|
|
83
52
|
if (isSSR && buildDirs.server) {
|
|
84
53
|
if (configParser) {
|
|
85
|
-
// Priority 1: Explicit serverBuildDir option
|
|
86
54
|
if (serverBuildDir) {
|
|
87
55
|
serverDir = path.join(projectRoot, serverBuildDir);
|
|
88
56
|
}
|
|
89
57
|
else {
|
|
90
|
-
// Priority 2: Get from Vite config using parser
|
|
91
58
|
serverDir = configParser.getServerDir();
|
|
92
59
|
}
|
|
93
|
-
// Priority 3: Fall back to predefined build directories
|
|
94
60
|
if (!serverDir) {
|
|
95
61
|
serverDir = await detectBuildDir(projectRoot, buildDirs.server);
|
|
96
62
|
}
|
|
97
|
-
// Find server entry
|
|
98
63
|
if (serverEntry) {
|
|
99
|
-
// Explicit server entry path provided
|
|
100
64
|
serverEntryPath = path.join(projectRoot, serverEntry);
|
|
101
65
|
}
|
|
102
66
|
else if (serverDir) {
|
|
103
|
-
// Priority 1: Try to get server entry from Vite config using parser
|
|
104
67
|
serverEntryPath = await configParser.findServerEntry(serverDir);
|
|
105
68
|
if (serverEntryPath) {
|
|
106
69
|
logger.verbose(`Using server entry from Vite config: ${serverEntryPath}`);
|
|
107
70
|
}
|
|
108
|
-
// Priority 2: Fall back to file detection with recursive search
|
|
109
71
|
if (!serverEntryPath) {
|
|
110
|
-
serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, {
|
|
111
|
-
recursive: true,
|
|
112
|
-
logger,
|
|
113
|
-
});
|
|
72
|
+
serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, { recursive: true, logger });
|
|
114
73
|
}
|
|
115
74
|
}
|
|
116
75
|
}
|
|
117
76
|
else {
|
|
118
|
-
// No Vite config available, use fallback detection
|
|
119
77
|
if (serverBuildDir) {
|
|
120
78
|
serverDir = path.join(projectRoot, serverBuildDir);
|
|
121
79
|
}
|
|
@@ -126,42 +84,23 @@ export function createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFi
|
|
|
126
84
|
serverEntryPath = path.join(projectRoot, serverEntry);
|
|
127
85
|
}
|
|
128
86
|
else if (serverDir) {
|
|
129
|
-
serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, {
|
|
130
|
-
recursive: true,
|
|
131
|
-
logger,
|
|
132
|
-
});
|
|
87
|
+
serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, { recursive: true, logger });
|
|
133
88
|
}
|
|
134
89
|
}
|
|
135
90
|
}
|
|
136
|
-
logBuildArtifacts(logger, name, {
|
|
137
|
-
|
|
138
|
-
serverDir,
|
|
139
|
-
serverEntry: serverEntryPath,
|
|
140
|
-
});
|
|
141
|
-
return {
|
|
142
|
-
clientDir,
|
|
143
|
-
serverDir,
|
|
144
|
-
serverEntry: serverEntryPath,
|
|
145
|
-
assetsDir: clientDir,
|
|
146
|
-
};
|
|
91
|
+
logBuildArtifacts(logger, name, { clientDir, serverDir, serverEntry: serverEntryPath });
|
|
92
|
+
return { clientDir, serverDir, serverEntry: serverEntryPath, assetsDir: clientDir };
|
|
147
93
|
};
|
|
148
94
|
}
|
|
149
|
-
/**
|
|
150
|
-
* Create generateRoutes hook
|
|
151
|
-
*/
|
|
152
95
|
export function createGenerateRoutesHook(effectiveRouteConfig, fallbackRoutes) {
|
|
153
96
|
return async (context) => {
|
|
154
97
|
const { projectRoot, isSSR, logger } = context;
|
|
155
|
-
|
|
156
|
-
if (effectiveRouteConfig.sources &&
|
|
157
|
-
effectiveRouteConfig.sources.length > 0) {
|
|
98
|
+
if (effectiveRouteConfig.sources && effectiveRouteConfig.sources.length > 0) {
|
|
158
99
|
let parsedRoutes = await parseRoutesFromSources(projectRoot, effectiveRouteConfig.sources, { isSSR, logger });
|
|
159
100
|
if (parsedRoutes.length > 0) {
|
|
160
|
-
// Apply transform if provided
|
|
161
101
|
if (effectiveRouteConfig.transform) {
|
|
162
102
|
parsedRoutes = effectiveRouteConfig.transform(parsedRoutes, context);
|
|
163
103
|
}
|
|
164
|
-
// Add SSR extra routes
|
|
165
104
|
if (isSSR && effectiveRouteConfig.ssrExtraRoutes) {
|
|
166
105
|
effectiveRouteConfig.ssrExtraRoutes.forEach((route) => {
|
|
167
106
|
parsedRoutes.push({ path: route, isStatic: false, srcRoute: route });
|
|
@@ -170,12 +109,7 @@ export function createGenerateRoutesHook(effectiveRouteConfig, fallbackRoutes) {
|
|
|
170
109
|
return parsedRoutes;
|
|
171
110
|
}
|
|
172
111
|
}
|
|
173
|
-
|
|
174
|
-
const routeList = fallbackRoutes.map((route) => ({
|
|
175
|
-
path: route,
|
|
176
|
-
isStatic: !isSSR,
|
|
177
|
-
srcRoute: route,
|
|
178
|
-
}));
|
|
112
|
+
const routeList = fallbackRoutes.map((route) => ({ path: route, isStatic: !isSSR, srcRoute: route }));
|
|
179
113
|
if (isSSR && effectiveRouteConfig.ssrExtraRoutes) {
|
|
180
114
|
effectiveRouteConfig.ssrExtraRoutes.forEach((route) => {
|
|
181
115
|
routeList.push({ path: route, isStatic: false, srcRoute: route });
|
|
@@ -184,60 +118,27 @@ export function createGenerateRoutesHook(effectiveRouteConfig, fallbackRoutes) {
|
|
|
184
118
|
return routeList;
|
|
185
119
|
};
|
|
186
120
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Create generateMeta hook
|
|
189
|
-
*/
|
|
190
121
|
export function createGenerateMetaHook(ssr404) {
|
|
191
122
|
return async (context, routeList) => {
|
|
192
|
-
// Convert routes to simplified meta format
|
|
193
123
|
const metaRoutes = convertRoutesToMetaFormat(routeList);
|
|
194
124
|
const meta = createDefaultMeta(metaRoutes, { isSSR: context.isSSR });
|
|
195
125
|
if (ssr404 !== undefined) {
|
|
196
|
-
meta.conf.ssr404 =
|
|
197
|
-
typeof ssr404 === "function" ? ssr404(context.isSSR) : ssr404;
|
|
126
|
+
meta.conf.ssr404 = typeof ssr404 === "function" ? ssr404(context.isSSR) : ssr404;
|
|
198
127
|
}
|
|
199
128
|
return meta;
|
|
200
129
|
};
|
|
201
130
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
export function createGenerateServerWrapperHook(wrapperConfig, htmlTemplatePaths) {
|
|
206
|
-
return async (context, wrapperCfg) => {
|
|
207
|
-
let handlerSetup = wrapperConfig.handlerSetup;
|
|
208
|
-
if (wrapperConfig.requiresHtmlTemplate) {
|
|
209
|
-
const { projectRoot, outputDir, logger } = context;
|
|
210
|
-
let htmlTemplate = "";
|
|
211
|
-
const templateCandidates = [
|
|
212
|
-
...htmlTemplatePaths.map((p) => path.join(projectRoot, p)),
|
|
213
|
-
path.join(projectRoot, outputDir, "assets/index.html"),
|
|
214
|
-
];
|
|
215
|
-
for (const templatePath of templateCandidates) {
|
|
216
|
-
if (await pathExists(templatePath)) {
|
|
217
|
-
htmlTemplate = await readFile(templatePath);
|
|
218
|
-
logger.verbose(`Found HTML template: ${templatePath}`);
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
if (!htmlTemplate) {
|
|
223
|
-
logger.warn("HTML template not found, using default template");
|
|
224
|
-
htmlTemplate =
|
|
225
|
-
'<!DOCTYPE html><html><head><!--app-head--></head><body><div id="app"><!--app-html--></div></body></html>';
|
|
226
|
-
}
|
|
227
|
-
const escapedTemplate = JSON.stringify(htmlTemplate);
|
|
228
|
-
handlerSetup = `const __HTML_TEMPLATE__ = ${escapedTemplate};\n\n${handlerSetup}`;
|
|
229
|
-
}
|
|
131
|
+
export function createGenerateServerWrapperHook(wrapperConfig) {
|
|
132
|
+
return async (_context, wrapperCfg) => {
|
|
133
|
+
const resolved = resolvePreset(wrapperConfig);
|
|
230
134
|
return generateServerWrapperCode({
|
|
231
135
|
serverEntryPath: wrapperCfg.serverEntryPath,
|
|
232
|
-
imports:
|
|
233
|
-
handlerSetup,
|
|
234
|
-
handlerCall:
|
|
136
|
+
imports: resolved.imports,
|
|
137
|
+
handlerSetup: resolved.setup,
|
|
138
|
+
handlerCall: resolved.invoke,
|
|
235
139
|
});
|
|
236
140
|
};
|
|
237
141
|
}
|
|
238
|
-
/**
|
|
239
|
-
* Create beforeBundle hook if esbuildConfig is provided
|
|
240
|
-
*/
|
|
241
142
|
export function createBeforeBundleHook(esbuildConfig) {
|
|
242
143
|
return async (context, bundleConfig) => {
|
|
243
144
|
const absWorkingDir = typeof esbuildConfig.absWorkingDir === "function"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/factory/hooks.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/factory/hooks.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAWxB,OAAO,EACL,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAoB,MAAM,mBAAmB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAwB7C,MAAM,UAAU,qBAAqB,CAAC,WAAqB;IACzD,OAAO,KAAK,EAAE,OAAqB,EAAoB,EAAE;QACvD,OAAO,CAAC,MAAM,gBAAgB,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,KAAK,IAAI,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,IAAY,EACZ,SAAyB,EACzB,gBAA0B,EAC1B,OAA8B;IAE9B,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAEhE,OAAO,KAAK,EAAE,OAAqB,EAA2B,EAAE;QAC9D,MAAM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adapter Factory - Simplifies framework adapter creation with declarative configuration
|
|
5
3
|
*/
|
|
6
|
-
import type { FrameworkAdapter } from "../types.js";
|
|
7
|
-
import { SERVER_WRAPPER_PRESETS
|
|
8
|
-
import { type BuildDirConfig, type RouteSourceConfig, type
|
|
9
|
-
export { SERVER_WRAPPER_PRESETS, createServerWrapperPreset, extendServerWrapperPresets, createWebHandlerPreset,
|
|
4
|
+
import type { FrameworkAdapter, ServerWrapperPreset } from "../types.js";
|
|
5
|
+
import { SERVER_WRAPPER_PRESETS } from "./presets.js";
|
|
6
|
+
import { type BuildDirConfig, type RouteSourceConfig, type AdapterFactoryOptions } from "./hooks.js";
|
|
7
|
+
export { SERVER_WRAPPER_PRESETS, createServerWrapperPreset, extendServerWrapperPresets, resolvePreset, createWebHandlerPreset, createSSRRenderPreset, createAutoDetectPreset, WEB_HANDLER_EXPORTS, SSR_RENDER_EXPORTS, type ExtendedPresetsResult, type PresetName, } from "./presets.js";
|
|
10
8
|
export { combineDetectors, createConfigDetector, createBuildDirDetector, createDependencyDetector, } from "./detectors.js";
|
|
11
|
-
export { type BuildDirConfig, type RouteSourceConfig, type
|
|
12
|
-
|
|
13
|
-
* Adapter factory configuration
|
|
14
|
-
*/
|
|
9
|
+
export { type BuildDirConfig, type RouteSourceConfig, type AdapterFactoryOptions, } from "./hooks.js";
|
|
10
|
+
export type { EsbuildConfig, ServerWrapperPreset, HandlerMode } from "../types.js";
|
|
15
11
|
export interface AdapterFactoryConfig {
|
|
16
12
|
name: string;
|
|
17
13
|
configFiles: string[];
|
|
18
14
|
buildDirs: BuildDirConfig;
|
|
19
15
|
serverEntryFiles?: string[];
|
|
20
16
|
serverWrapper?: keyof typeof SERVER_WRAPPER_PRESETS | ServerWrapperPreset;
|
|
21
|
-
/** Declarative route configuration */
|
|
22
17
|
routeConfig?: RouteSourceConfig;
|
|
23
|
-
/** Legacy: default routes (use routeConfig.defaultRoutes instead) */
|
|
24
18
|
defaultRoutes?: string[];
|
|
25
|
-
/** Legacy: SSR extra routes (use routeConfig.ssrExtraRoutes instead) */
|
|
26
19
|
ssrExtraRoutes?: string[];
|
|
27
20
|
ssr404?: boolean | ((isSSR: boolean) => boolean);
|
|
28
|
-
htmlTemplatePaths?: string[];
|
|
29
|
-
/** esbuild configuration */
|
|
30
|
-
esbuildConfig?: EsbuildConfig;
|
|
31
21
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Create a framework adapter
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```ts
|
|
37
|
-
* const adapter = createFrameworkAdapter({
|
|
38
|
-
* name: "my-framework",
|
|
39
|
-
* configFiles: ["my-framework.config.ts"],
|
|
40
|
-
* buildDirs: {
|
|
41
|
-
* client: ["dist/client"],
|
|
42
|
-
* server: ["dist/server"],
|
|
43
|
-
* },
|
|
44
|
-
* serverWrapper: "webHandler",
|
|
45
|
-
* });
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
22
|
export declare function createFrameworkAdapter(config: AdapterFactoryConfig, options?: AdapterFactoryOptions, overrides?: Partial<FrameworkAdapter>): FrameworkAdapter;
|
|
49
|
-
/**
|
|
50
|
-
* Create a stateful adapter (for complex adapters needing shared state)
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```ts
|
|
54
|
-
* const adapter = createStatefulAdapter(
|
|
55
|
-
* { isSSR: true, config: null },
|
|
56
|
-
* (state) => ({
|
|
57
|
-
* name: "my-framework",
|
|
58
|
-
* async detect(context) {
|
|
59
|
-
* state.config = await loadConfig();
|
|
60
|
-
* return !!state.config;
|
|
61
|
-
* },
|
|
62
|
-
* // ... other methods can access state
|
|
63
|
-
* })
|
|
64
|
-
* );
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
23
|
export declare function createStatefulAdapter<TState extends object>(initialState: TState, factory: (state: TState) => FrameworkAdapter): FrameworkAdapter;
|
|
68
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,sBAAsB,EAAiB,MAAM,cAAc,CAAC;AACrE,OAAO,EAOL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,aAAa,EACb,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,kBAAkB,EAClB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,GAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,YAAY,CAAC;AAGpB,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnF,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,EAAE,cAAc,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,OAAO,sBAAsB,GAAG,mBAAmB,CAAC;IAC1E,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;CAClD;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,GAAE,qBAA0B,EACnC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACpC,gBAAgB,CAqDlB;AAED,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,MAAM,EACzD,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,gBAAgB,GAC3C,gBAAgB,CAElB"}
|
package/dist/factory/index.js
CHANGED
|
@@ -1,50 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adapter Factory
|
|
3
|
-
*
|
|
4
|
-
* Simplifies the creation of framework adapters with declarative configuration
|
|
2
|
+
* Adapter Factory - Simplifies framework adapter creation with declarative configuration
|
|
5
3
|
*/
|
|
6
|
-
import { SERVER_WRAPPER_PRESETS, } from "./presets.js";
|
|
4
|
+
import { SERVER_WRAPPER_PRESETS, resolvePreset } from "./presets.js";
|
|
7
5
|
import { createDefaultDetector, createDefaultBuildArtifactsGetter, createGenerateRoutesHook, createGenerateMetaHook, createGenerateServerWrapperHook, createBeforeBundleHook, } from "./hooks.js";
|
|
8
|
-
|
|
9
|
-
export {
|
|
10
|
-
// Presets
|
|
11
|
-
SERVER_WRAPPER_PRESETS, createServerWrapperPreset, extendServerWrapperPresets, createWebHandlerPreset, DEFAULT_HANDLER_DETECT_PATHS, } from "./presets.js";
|
|
12
|
-
export {
|
|
13
|
-
// Detectors
|
|
14
|
-
combineDetectors, createConfigDetector, createBuildDirDetector, createDependencyDetector, } from "./detectors.js";
|
|
15
|
-
// ============================================================================
|
|
16
|
-
// Factory Functions
|
|
17
|
-
// ============================================================================
|
|
18
|
-
/**
|
|
19
|
-
* Create a framework adapter
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const adapter = createFrameworkAdapter({
|
|
24
|
-
* name: "my-framework",
|
|
25
|
-
* configFiles: ["my-framework.config.ts"],
|
|
26
|
-
* buildDirs: {
|
|
27
|
-
* client: ["dist/client"],
|
|
28
|
-
* server: ["dist/server"],
|
|
29
|
-
* },
|
|
30
|
-
* serverWrapper: "webHandler",
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
6
|
+
export { SERVER_WRAPPER_PRESETS, createServerWrapperPreset, extendServerWrapperPresets, resolvePreset, createWebHandlerPreset, createSSRRenderPreset, createAutoDetectPreset, WEB_HANDLER_EXPORTS, SSR_RENDER_EXPORTS, } from "./presets.js";
|
|
7
|
+
export { combineDetectors, createConfigDetector, createBuildDirDetector, createDependencyDetector, } from "./detectors.js";
|
|
34
8
|
export function createFrameworkAdapter(config, options = {}, overrides) {
|
|
35
|
-
const { name, configFiles, buildDirs, serverEntryFiles = ["index.js", "index.mjs", "entry.js", "main.js"], serverWrapper = "
|
|
9
|
+
const { name, configFiles, buildDirs, serverEntryFiles = ["index.js", "index.mjs", "entry.js", "main.js"], serverWrapper = "autoDetect", routeConfig, defaultRoutes = ["/"], ssrExtraRoutes = [], ssr404, } = config;
|
|
36
10
|
const { routes = routeConfig?.defaultRoutes || defaultRoutes } = options;
|
|
37
|
-
// Merge route config with legacy options
|
|
38
11
|
const effectiveRouteConfig = {
|
|
39
12
|
sources: routeConfig?.sources,
|
|
40
13
|
defaultRoutes: routeConfig?.defaultRoutes || defaultRoutes,
|
|
41
14
|
ssrExtraRoutes: routeConfig?.ssrExtraRoutes || ssrExtraRoutes,
|
|
42
15
|
transform: routeConfig?.transform,
|
|
43
16
|
};
|
|
17
|
+
// Resolve preset name to preset object
|
|
44
18
|
const wrapperConfig = typeof serverWrapper === "string"
|
|
45
19
|
? SERVER_WRAPPER_PRESETS[serverWrapper]
|
|
46
20
|
: serverWrapper;
|
|
47
|
-
//
|
|
21
|
+
// Resolve to normalized form for esbuildConfig check
|
|
22
|
+
const resolvedPreset = resolvePreset(wrapperConfig);
|
|
48
23
|
const baseAdapter = {
|
|
49
24
|
name,
|
|
50
25
|
detect: createDefaultDetector(configFiles),
|
|
@@ -52,10 +27,8 @@ export function createFrameworkAdapter(config, options = {}, overrides) {
|
|
|
52
27
|
hooks: {
|
|
53
28
|
generateRoutes: createGenerateRoutesHook(effectiveRouteConfig, routes),
|
|
54
29
|
generateMeta: createGenerateMetaHook(ssr404),
|
|
55
|
-
generateServerWrapper: createGenerateServerWrapperHook(wrapperConfig
|
|
56
|
-
...(esbuildConfig
|
|
57
|
-
? { beforeBundle: createBeforeBundleHook(esbuildConfig) }
|
|
58
|
-
: {}),
|
|
30
|
+
generateServerWrapper: createGenerateServerWrapperHook(wrapperConfig),
|
|
31
|
+
...(resolvedPreset.esbuildConfig ? { beforeBundle: createBeforeBundleHook(resolvedPreset.esbuildConfig) } : {}),
|
|
59
32
|
},
|
|
60
33
|
};
|
|
61
34
|
if (overrides) {
|
|
@@ -68,24 +41,6 @@ export function createFrameworkAdapter(config, options = {}, overrides) {
|
|
|
68
41
|
}
|
|
69
42
|
return baseAdapter;
|
|
70
43
|
}
|
|
71
|
-
/**
|
|
72
|
-
* Create a stateful adapter (for complex adapters needing shared state)
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* ```ts
|
|
76
|
-
* const adapter = createStatefulAdapter(
|
|
77
|
-
* { isSSR: true, config: null },
|
|
78
|
-
* (state) => ({
|
|
79
|
-
* name: "my-framework",
|
|
80
|
-
* async detect(context) {
|
|
81
|
-
* state.config = await loadConfig();
|
|
82
|
-
* return !!state.config;
|
|
83
|
-
* },
|
|
84
|
-
* // ... other methods can access state
|
|
85
|
-
* })
|
|
86
|
-
* );
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
44
|
export function createStatefulAdapter(initialState, factory) {
|
|
90
45
|
return factory({ ...initialState });
|
|
91
46
|
}
|