@chuckcchen/vite-plugin 1.0.2 → 1.0.4
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 +2 -44
- package/dist/bundler.d.ts.map +1 -1
- package/dist/bundler.js +29 -170
- package/dist/bundler.js.map +1 -1
- package/dist/factory.d.ts +16 -43
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +89 -89
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +57 -125
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +182 -170
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/bundler.d.ts
CHANGED
|
@@ -1,66 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EdgeOne Vite Plugin Adapter - Server Bundling Module
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Handles server-side code bundling using esbuild:
|
|
5
5
|
* - Bundle framework's server build artifacts into a single file
|
|
6
6
|
* - Generate HTTP request handling wrapper code
|
|
7
|
-
* - Handle Node.js request to Web API Request conversion
|
|
8
7
|
*/
|
|
9
8
|
import * as esbuild from "esbuild";
|
|
10
9
|
import type { BuildContext, ServerBundleConfig, ServerWrapperConfig } from "./types.js";
|
|
11
10
|
/**
|
|
12
11
|
* Bundle server code using esbuild
|
|
13
|
-
*
|
|
14
|
-
* Bundle server entry file and all dependencies into a single JavaScript file
|
|
15
|
-
* for running in EdgeOne edge function environment
|
|
16
|
-
*
|
|
17
|
-
* @param context - Build context containing project root and logger
|
|
18
|
-
* @param config - Bundle configuration including entry points, output path, etc.
|
|
19
|
-
* @returns esbuild build result containing metadata info
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* await bundleServerCode(context, {
|
|
23
|
-
* entryPoints: ['server-wrapper.temp.js'],
|
|
24
|
-
* outfile: '.edgeone/server-handler/handler.js'
|
|
25
|
-
* });
|
|
26
12
|
*/
|
|
27
13
|
export declare function bundleServerCode(context: BuildContext, config: ServerBundleConfig): Promise<esbuild.BuildResult>;
|
|
28
14
|
/**
|
|
29
15
|
* Create server wrapper file
|
|
30
16
|
*
|
|
31
|
-
*
|
|
32
|
-
* The wrapper is responsible for:
|
|
33
|
-
* 1. Converting Node.js IncomingMessage to Web API Request object
|
|
34
|
-
* 2. Calling framework's request handler function
|
|
35
|
-
* 3. Exporting unified request handling interface
|
|
36
|
-
*
|
|
37
|
-
* @param context - Build context
|
|
38
|
-
* @param config - Wrapper configuration
|
|
39
|
-
* @returns Path to generated temporary wrapper file
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const wrapperPath = await createServerWrapper(context, {
|
|
43
|
-
* serverEntryPath: 'build/server/index.js'
|
|
44
|
-
* });
|
|
17
|
+
* Wraps framework's server build into a unified HTTP request handler.
|
|
45
18
|
*/
|
|
46
19
|
export declare function createServerWrapper(context: BuildContext, config: ServerWrapperConfig): Promise<string>;
|
|
47
20
|
/**
|
|
48
21
|
* Cleanup temporary wrapper file
|
|
49
|
-
* Delete temporarily generated wrapper file after bundling completes
|
|
50
|
-
*
|
|
51
|
-
* @param wrapperPath - Wrapper file path
|
|
52
22
|
*/
|
|
53
23
|
export declare function cleanupWrapper(wrapperPath: string): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Get bundle result file size
|
|
56
|
-
*
|
|
57
|
-
* @param result - esbuild build result
|
|
58
|
-
* @returns Bundled file size in bytes, returns 0 if unavailable
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* const result = await bundleServerCode(context, config);
|
|
62
|
-
* const size = getBundleSize(result);
|
|
63
|
-
* console.log(`Bundle size: ${formatSize(size)}`);
|
|
64
|
-
*/
|
|
65
|
-
export declare function getBundleSize(result: esbuild.BuildResult): number;
|
|
66
24
|
//# sourceMappingURL=bundler.d.ts.map
|
package/dist/bundler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAYxF;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CA6B9B;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAgCjB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvE"}
|
package/dist/bundler.js
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* EdgeOne Vite Plugin Adapter - Server Bundling Module
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Handles server-side code bundling using esbuild:
|
|
5
5
|
* - Bundle framework's server build artifacts into a single file
|
|
6
6
|
* - Generate HTTP request handling wrapper code
|
|
7
|
-
* - Handle Node.js request to Web API Request conversion
|
|
8
7
|
*/
|
|
9
8
|
import * as esbuild from "esbuild";
|
|
10
9
|
import path from "path";
|
|
11
|
-
import {
|
|
10
|
+
import { writeFile, deleteFile, ensureDirectory, generateServerWrapperCode } from "./utils.js";
|
|
12
11
|
/**
|
|
13
12
|
* Default ESM compatibility banner code
|
|
14
13
|
* Provides CommonJS require, __filename, __dirname support in ESM modules
|
|
15
|
-
* This is because some dependencies may still use CommonJS syntax
|
|
16
14
|
*/
|
|
17
15
|
const DEFAULT_BANNER = `import { createRequire } from 'node:module';
|
|
18
16
|
const require = createRequire(import.meta.url);
|
|
@@ -20,43 +18,28 @@ const __filename = new URL('', import.meta.url).pathname;
|
|
|
20
18
|
const __dirname = new URL('.', import.meta.url).pathname;`;
|
|
21
19
|
/**
|
|
22
20
|
* Bundle server code using esbuild
|
|
23
|
-
*
|
|
24
|
-
* Bundle server entry file and all dependencies into a single JavaScript file
|
|
25
|
-
* for running in EdgeOne edge function environment
|
|
26
|
-
*
|
|
27
|
-
* @param context - Build context containing project root and logger
|
|
28
|
-
* @param config - Bundle configuration including entry points, output path, etc.
|
|
29
|
-
* @returns esbuild build result containing metadata info
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* await bundleServerCode(context, {
|
|
33
|
-
* entryPoints: ['server-wrapper.temp.js'],
|
|
34
|
-
* outfile: '.edgeone/server-handler/handler.js'
|
|
35
|
-
* });
|
|
36
21
|
*/
|
|
37
22
|
export async function bundleServerCode(context, config) {
|
|
38
23
|
const { projectRoot, logger } = context;
|
|
39
24
|
logger.verbose("Bundling server code...");
|
|
40
|
-
// Ensure output directory exists
|
|
41
25
|
await ensureDirectory(path.dirname(config.outfile));
|
|
42
|
-
// Bundle using esbuild
|
|
43
26
|
const result = await esbuild.build({
|
|
44
|
-
entryPoints: config.entryPoints,
|
|
45
|
-
bundle: true,
|
|
46
|
-
platform: "node",
|
|
47
|
-
target: "node18",
|
|
48
|
-
format: "esm",
|
|
49
|
-
outfile: config.outfile,
|
|
50
|
-
minify: false,
|
|
51
|
-
treeShaking: true,
|
|
52
|
-
external: ["node:*", ...(config.external || [])],
|
|
53
|
-
metafile: true,
|
|
54
|
-
logLevel: "warning",
|
|
55
|
-
absWorkingDir: projectRoot,
|
|
27
|
+
entryPoints: config.entryPoints,
|
|
28
|
+
bundle: true,
|
|
29
|
+
platform: "node",
|
|
30
|
+
target: "node18",
|
|
31
|
+
format: "esm",
|
|
32
|
+
outfile: config.outfile,
|
|
33
|
+
minify: false,
|
|
34
|
+
treeShaking: true,
|
|
35
|
+
external: ["node:*", ...(config.external || [])],
|
|
36
|
+
metafile: true,
|
|
37
|
+
logLevel: "warning",
|
|
38
|
+
absWorkingDir: projectRoot,
|
|
56
39
|
banner: {
|
|
57
|
-
js: DEFAULT_BANNER,
|
|
40
|
+
js: DEFAULT_BANNER,
|
|
58
41
|
},
|
|
59
|
-
...config.esbuildOptions,
|
|
42
|
+
...config.esbuildOptions,
|
|
60
43
|
});
|
|
61
44
|
logger.verbose(`Server code bundled to: ${config.outfile}`);
|
|
62
45
|
return result;
|
|
@@ -64,37 +47,28 @@ export async function bundleServerCode(context, config) {
|
|
|
64
47
|
/**
|
|
65
48
|
* Create server wrapper file
|
|
66
49
|
*
|
|
67
|
-
*
|
|
68
|
-
* The wrapper is responsible for:
|
|
69
|
-
* 1. Converting Node.js IncomingMessage to Web API Request object
|
|
70
|
-
* 2. Calling framework's request handler function
|
|
71
|
-
* 3. Exporting unified request handling interface
|
|
72
|
-
*
|
|
73
|
-
* @param context - Build context
|
|
74
|
-
* @param config - Wrapper configuration
|
|
75
|
-
* @returns Path to generated temporary wrapper file
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* const wrapperPath = await createServerWrapper(context, {
|
|
79
|
-
* serverEntryPath: 'build/server/index.js'
|
|
80
|
-
* });
|
|
50
|
+
* Wraps framework's server build into a unified HTTP request handler.
|
|
81
51
|
*/
|
|
82
52
|
export async function createServerWrapper(context, config) {
|
|
83
53
|
const { projectRoot, logger } = context;
|
|
84
54
|
logger.verbose("Creating server wrapper...");
|
|
85
|
-
// Read original server build content
|
|
86
|
-
const serverBuildContent = await readFile(config.serverEntryPath);
|
|
87
|
-
// Generate wrapper content
|
|
88
55
|
let wrapperContent;
|
|
89
56
|
if (config.wrapperTemplate) {
|
|
90
|
-
// Use custom template
|
|
57
|
+
// Use custom template
|
|
58
|
+
const { readFile } = await import("./utils.js");
|
|
59
|
+
const serverBuildContent = await readFile(config.serverEntryPath);
|
|
91
60
|
wrapperContent = config.wrapperTemplate.replace("{{SERVER_BUILD_CONTENT}}", serverBuildContent);
|
|
92
61
|
}
|
|
93
62
|
else {
|
|
94
|
-
// Use
|
|
95
|
-
wrapperContent =
|
|
63
|
+
// Use generateServerWrapperCode from utils
|
|
64
|
+
wrapperContent = await generateServerWrapperCode({
|
|
65
|
+
serverEntryPath: config.serverEntryPath,
|
|
66
|
+
handlerSetup: config.banner || "",
|
|
67
|
+
handlerCall: "handler(webRequest, ...args)",
|
|
68
|
+
mode: "inline",
|
|
69
|
+
additionalExports: config.exports,
|
|
70
|
+
});
|
|
96
71
|
}
|
|
97
|
-
// Write to temporary file
|
|
98
72
|
const tempPath = path.join(projectRoot, "server-wrapper.temp.js");
|
|
99
73
|
await writeFile(tempPath, wrapperContent);
|
|
100
74
|
logger.verbose("Server wrapper created");
|
|
@@ -102,128 +76,13 @@ export async function createServerWrapper(context, config) {
|
|
|
102
76
|
}
|
|
103
77
|
/**
|
|
104
78
|
* Cleanup temporary wrapper file
|
|
105
|
-
* Delete temporarily generated wrapper file after bundling completes
|
|
106
|
-
*
|
|
107
|
-
* @param wrapperPath - Wrapper file path
|
|
108
79
|
*/
|
|
109
80
|
export async function cleanupWrapper(wrapperPath) {
|
|
110
81
|
try {
|
|
111
82
|
await deleteFile(wrapperPath);
|
|
112
83
|
}
|
|
113
84
|
catch {
|
|
114
|
-
// Ignore delete errors
|
|
85
|
+
// Ignore delete errors
|
|
115
86
|
}
|
|
116
87
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Generate default server wrapper code
|
|
119
|
-
*
|
|
120
|
-
* Wrapper code contains:
|
|
121
|
-
* 1. Original server build content
|
|
122
|
-
* 2. Node.js request to Web Request conversion function
|
|
123
|
-
* 3. Unified request handler export
|
|
124
|
-
*
|
|
125
|
-
* @param serverBuildContent - Original server build code content
|
|
126
|
-
* @param config - Wrapper configuration
|
|
127
|
-
* @returns Generated wrapper code string
|
|
128
|
-
*/
|
|
129
|
-
function generateDefaultWrapper(serverBuildContent, config) {
|
|
130
|
-
const banner = config.banner || "";
|
|
131
|
-
const exports = config.exports || [];
|
|
132
|
-
// Build export statement
|
|
133
|
-
const exportsStr = exports.length > 0
|
|
134
|
-
? exports.join(", ")
|
|
135
|
-
: "default as handler";
|
|
136
|
-
return `// ========== Server Build Content ==========
|
|
137
|
-
${serverBuildContent}
|
|
138
|
-
|
|
139
|
-
// ========== HTTP Server Wrapper ==========
|
|
140
|
-
${banner}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Convert Node.js IncomingMessage to Web API Request
|
|
144
|
-
*
|
|
145
|
-
* EdgeOne edge functions use Web API standard Request/Response,
|
|
146
|
-
* but some framework server builds may expect Node.js style request objects.
|
|
147
|
-
* This function handles the conversion.
|
|
148
|
-
*
|
|
149
|
-
* @param nodeReq - Node.js IncomingMessage object
|
|
150
|
-
* @returns Web API Request object
|
|
151
|
-
*/
|
|
152
|
-
function nodeRequestToWebRequest(nodeReq) {
|
|
153
|
-
// Build complete URL
|
|
154
|
-
// Determine protocol based on whether connection is encrypted
|
|
155
|
-
const protocol = nodeReq.connection?.encrypted ? 'https' : 'http';
|
|
156
|
-
const host = nodeReq.headers.host || 'localhost';
|
|
157
|
-
const url = \`\${protocol}://\${host}\${nodeReq.url}\`;
|
|
158
|
-
|
|
159
|
-
// Convert request headers
|
|
160
|
-
// Node.js headers are plain objects, need to convert to Headers instance
|
|
161
|
-
const headers = new Headers();
|
|
162
|
-
for (const [key, value] of Object.entries(nodeReq.headers)) {
|
|
163
|
-
if (value) {
|
|
164
|
-
if (Array.isArray(value)) {
|
|
165
|
-
// Multi-value headers (like Set-Cookie) need multiple appends
|
|
166
|
-
value.forEach(v => headers.append(key, v));
|
|
167
|
-
} else {
|
|
168
|
-
headers.set(key, value);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Build Request init options
|
|
174
|
-
const init = {
|
|
175
|
-
method: nodeReq.method,
|
|
176
|
-
headers: headers,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// Add request body for non-GET/HEAD requests
|
|
180
|
-
// GET and HEAD requests should not have body
|
|
181
|
-
if (nodeReq.method !== 'GET' && nodeReq.method !== 'HEAD') {
|
|
182
|
-
init.body = nodeReq;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
return new Request(url, init);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Node.js request handler wrapper function
|
|
190
|
-
*
|
|
191
|
-
* This is the main entry exported for EdgeOne edge functions to call.
|
|
192
|
-
* Responsible for converting Node.js request before passing to framework handler.
|
|
193
|
-
*
|
|
194
|
-
* @param nodeReq - Node.js request object
|
|
195
|
-
* @param args - Other arguments (e.g. env variables, context, etc.)
|
|
196
|
-
* @returns Framework handler return value (usually Response object)
|
|
197
|
-
*/
|
|
198
|
-
async function nodeRequestHandler(nodeReq, ...args) {
|
|
199
|
-
const webRequest = nodeRequestToWebRequest(nodeReq);
|
|
200
|
-
return handler(webRequest, ...args);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export default nodeRequestHandler;
|
|
204
|
-
export { ${exportsStr} };
|
|
205
|
-
`;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Get bundle result file size
|
|
209
|
-
*
|
|
210
|
-
* @param result - esbuild build result
|
|
211
|
-
* @returns Bundled file size in bytes, returns 0 if unavailable
|
|
212
|
-
*
|
|
213
|
-
* @example
|
|
214
|
-
* const result = await bundleServerCode(context, config);
|
|
215
|
-
* const size = getBundleSize(result);
|
|
216
|
-
* console.log(`Bundle size: ${formatSize(size)}`);
|
|
217
|
-
*/
|
|
218
|
-
export function getBundleSize(result) {
|
|
219
|
-
// Need metafile to get size info
|
|
220
|
-
if (!result.metafile)
|
|
221
|
-
return 0;
|
|
222
|
-
const outputs = result.metafile.outputs;
|
|
223
|
-
const outputKeys = Object.keys(outputs);
|
|
224
|
-
if (outputKeys.length === 0)
|
|
225
|
-
return 0;
|
|
226
|
-
// Return size of first output file
|
|
227
|
-
return outputs[outputKeys[0]].bytes;
|
|
228
|
-
}
|
|
229
88
|
//# sourceMappingURL=bundler.js.map
|
package/dist/bundler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE/F;;;GAGG;AACH,MAAM,cAAc,GAAG;;;0DAGmC,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAqB,EACrB,MAA0B;IAE1B,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAExC,MAAM,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAE1C,MAAM,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IAEpD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC;QACjC,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,IAAI;QACjB,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,QAAQ,IAA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C;IAE1C,MAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAEzC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,WAAmB;IACtD,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,WAAW,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,uBAAuB;IACzB,CAAC;AACH,CAAC"}
|
package/dist/factory.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adapter Factory - Simplifies the creation of framework adapters
|
|
3
3
|
*
|
|
4
|
-
* Provides factory functions and preset configurations to reduce boilerplate code
|
|
4
|
+
* Provides factory functions and preset configurations to reduce boilerplate code
|
|
5
5
|
*/
|
|
6
|
-
import type { BuildContext, FrameworkAdapter
|
|
6
|
+
import type { BuildContext, FrameworkAdapter } from "./types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Server wrapper preset configuration
|
|
9
9
|
*/
|
|
10
10
|
export interface ServerWrapperPreset {
|
|
11
|
-
/** Additional import statements */
|
|
12
11
|
imports?: string;
|
|
13
|
-
/** Handler initialization code */
|
|
14
12
|
handlerSetup: string;
|
|
15
|
-
/** Handler call expression */
|
|
16
13
|
handlerCall: string;
|
|
14
|
+
requiresHtmlTemplate?: boolean;
|
|
17
15
|
}
|
|
18
16
|
/**
|
|
19
17
|
* Built-in server wrapper presets
|
|
@@ -35,90 +33,65 @@ export declare const SERVER_WRAPPER_PRESETS: {
|
|
|
35
33
|
readonly handlerSetup: string;
|
|
36
34
|
readonly handlerCall: "requestHandler(webRequest, ...args)";
|
|
37
35
|
};
|
|
36
|
+
/** Vite SSR - standard Vite SSR with render function */
|
|
37
|
+
readonly viteSSR: {
|
|
38
|
+
readonly requiresHtmlTemplate: true;
|
|
39
|
+
readonly handlerSetup: string;
|
|
40
|
+
readonly handlerCall: "handleSSRRequest(webRequest)";
|
|
41
|
+
};
|
|
38
42
|
};
|
|
39
43
|
/**
|
|
40
44
|
* Build directory configuration
|
|
41
45
|
*/
|
|
42
46
|
export interface BuildDirConfig {
|
|
43
|
-
/** Client directory candidates */
|
|
44
47
|
client: string[];
|
|
45
|
-
/** Server directory candidates (SSR mode) */
|
|
46
48
|
server?: string[];
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Adapter factory configuration
|
|
50
52
|
*/
|
|
51
53
|
export interface AdapterFactoryConfig {
|
|
52
|
-
/** Adapter name */
|
|
53
54
|
name: string;
|
|
54
|
-
/** Config file detection list */
|
|
55
55
|
configFiles: string[];
|
|
56
|
-
/** Build directory candidates configuration */
|
|
57
56
|
buildDirs: BuildDirConfig;
|
|
58
|
-
/** Server entry file candidates */
|
|
59
57
|
serverEntryFiles?: string[];
|
|
60
|
-
/** Server wrapper configuration (use preset name or custom config) */
|
|
61
58
|
serverWrapper?: keyof typeof SERVER_WRAPPER_PRESETS | ServerWrapperPreset;
|
|
62
|
-
/** Default routes list */
|
|
63
59
|
defaultRoutes?: string[];
|
|
64
|
-
/** Extra routes for SSR mode */
|
|
65
60
|
ssrExtraRoutes?: string[];
|
|
66
|
-
/** Custom ssr404 handling */
|
|
67
61
|
ssr404?: boolean | ((isSSR: boolean) => boolean);
|
|
62
|
+
htmlTemplatePaths?: string[];
|
|
68
63
|
}
|
|
69
64
|
/**
|
|
70
65
|
* Adapter factory runtime options
|
|
71
66
|
*/
|
|
72
67
|
export interface AdapterFactoryOptions {
|
|
73
|
-
/** User-specified client directory */
|
|
74
68
|
clientBuildDir?: string;
|
|
75
|
-
/** User-specified server directory */
|
|
76
69
|
serverBuildDir?: string;
|
|
77
|
-
/** User-specified server entry */
|
|
78
70
|
serverEntry?: string;
|
|
79
|
-
/** User-specified routes */
|
|
80
71
|
routes?: string[];
|
|
81
72
|
}
|
|
82
73
|
/**
|
|
83
74
|
* Create a framework adapter
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```ts
|
|
87
|
-
* const adapter = createFrameworkAdapter({
|
|
88
|
-
* name: "my-framework",
|
|
89
|
-
* configFiles: ["my-framework.config.ts", "my-framework.config.js"],
|
|
90
|
-
* buildDirs: {
|
|
91
|
-
* client: ["dist/client", "dist"],
|
|
92
|
-
* server: ["dist/server"],
|
|
93
|
-
* },
|
|
94
|
-
* serverWrapper: "generic",
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
97
75
|
*/
|
|
98
76
|
export declare function createFrameworkAdapter(config: AdapterFactoryConfig, options?: AdapterFactoryOptions, overrides?: Partial<FrameworkAdapter>): FrameworkAdapter;
|
|
99
77
|
/**
|
|
100
|
-
* Create a stateful adapter
|
|
101
|
-
* Used for complex adapters that need to share state between different hooks
|
|
78
|
+
* Create a stateful adapter (for complex adapters needing shared state)
|
|
102
79
|
*/
|
|
103
80
|
export declare function createStatefulAdapter<TState extends object>(initialState: TState, factory: (state: TState) => FrameworkAdapter): FrameworkAdapter;
|
|
104
81
|
/**
|
|
105
|
-
*
|
|
82
|
+
* Combine multiple detector functions (returns true if any matches)
|
|
106
83
|
*/
|
|
107
|
-
export declare function
|
|
84
|
+
export declare function combineDetectors(...detectors: ((context: BuildContext) => Promise<boolean> | boolean)[]): (context: BuildContext) => Promise<boolean>;
|
|
108
85
|
/**
|
|
109
|
-
* Create
|
|
86
|
+
* Create detector based on config files
|
|
110
87
|
*/
|
|
111
88
|
export declare function createConfigDetector(configFiles: string[]): (context: BuildContext) => Promise<boolean>;
|
|
112
89
|
/**
|
|
113
|
-
* Create
|
|
90
|
+
* Create detector based on build directories
|
|
114
91
|
*/
|
|
115
92
|
export declare function createBuildDirDetector(buildDirs: string[]): (context: BuildContext) => Promise<boolean>;
|
|
116
93
|
/**
|
|
117
|
-
* Create
|
|
94
|
+
* Create detector based on package.json dependencies
|
|
118
95
|
*/
|
|
119
96
|
export declare function createDependencyDetector(dependencies: string[]): (context: BuildContext) => Promise<boolean>;
|
|
120
|
-
/**
|
|
121
|
-
* Combine multiple detector functions (returns true if any matches)
|
|
122
|
-
*/
|
|
123
|
-
export declare function combineDetectors(...detectors: ((context: BuildContext) => Promise<boolean> | boolean)[]): (context: BuildContext) => Promise<boolean>;
|
|
124
97
|
//# sourceMappingURL=factory.d.ts.map
|
package/dist/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,YAAY,EAIZ,gBAAgB,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,YAAY,EAIZ,gBAAgB,EAEjB,MAAM,YAAY,CAAC;AAYpB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;IACjC,0DAA0D;;;;;IAa1D,sCAAsC;;;;;IAatC,+CAA+C;;;;;;IAqB/C,wDAAwD;;;;;;CAoChD,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,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,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,cAAc,CAA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