@edgeone/vite-core 1.0.0

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.
Files changed (73) hide show
  1. package/dist/bundler.d.ts +13 -0
  2. package/dist/bundler.d.ts.map +1 -0
  3. package/dist/bundler.js +101 -0
  4. package/dist/bundler.js.map +1 -0
  5. package/dist/core.d.ts +11 -0
  6. package/dist/core.d.ts.map +1 -0
  7. package/dist/core.js +330 -0
  8. package/dist/core.js.map +1 -0
  9. package/dist/factory/detectors.d.ts +13 -0
  10. package/dist/factory/detectors.d.ts.map +1 -0
  11. package/dist/factory/detectors.js +46 -0
  12. package/dist/factory/detectors.js.map +1 -0
  13. package/dist/factory/hooks.d.ts +29 -0
  14. package/dist/factory/hooks.d.ts.map +1 -0
  15. package/dist/factory/hooks.js +158 -0
  16. package/dist/factory/hooks.js.map +1 -0
  17. package/dist/factory/index.d.ts +24 -0
  18. package/dist/factory/index.d.ts.map +1 -0
  19. package/dist/factory/index.js +47 -0
  20. package/dist/factory/index.js.map +1 -0
  21. package/dist/factory/presets.d.ts +27 -0
  22. package/dist/factory/presets.d.ts.map +1 -0
  23. package/dist/factory/presets.js +186 -0
  24. package/dist/factory/presets.js.map +1 -0
  25. package/dist/factory.d.ts +183 -0
  26. package/dist/factory.d.ts.map +1 -0
  27. package/dist/factory.js +482 -0
  28. package/dist/factory.js.map +1 -0
  29. package/dist/helpers.d.ts +53 -0
  30. package/dist/helpers.d.ts.map +1 -0
  31. package/dist/helpers.js +177 -0
  32. package/dist/helpers.js.map +1 -0
  33. package/dist/index.d.ts +16 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +12 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/route/index.d.ts +7 -0
  38. package/dist/route/index.d.ts.map +1 -0
  39. package/dist/route/index.js +6 -0
  40. package/dist/route/index.js.map +1 -0
  41. package/dist/route/parser.d.ts +18 -0
  42. package/dist/route/parser.d.ts.map +1 -0
  43. package/dist/route/parser.js +187 -0
  44. package/dist/route/parser.js.map +1 -0
  45. package/dist/route/regex.d.ts +31 -0
  46. package/dist/route/regex.d.ts.map +1 -0
  47. package/dist/route/regex.js +140 -0
  48. package/dist/route/regex.js.map +1 -0
  49. package/dist/route/regex.test.d.ts +7 -0
  50. package/dist/route/regex.test.d.ts.map +1 -0
  51. package/dist/route/regex.test.js +662 -0
  52. package/dist/route/regex.test.js.map +1 -0
  53. package/dist/route/types.d.ts +58 -0
  54. package/dist/route/types.d.ts.map +1 -0
  55. package/dist/route/types.js +5 -0
  56. package/dist/route/types.js.map +1 -0
  57. package/dist/route-parser.d.ts +8 -0
  58. package/dist/route-parser.d.ts.map +1 -0
  59. package/dist/route-parser.js +8 -0
  60. package/dist/route-parser.js.map +1 -0
  61. package/dist/types.d.ts +160 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +5 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/utils.d.ts +40 -0
  66. package/dist/utils.d.ts.map +1 -0
  67. package/dist/utils.js +242 -0
  68. package/dist/utils.js.map +1 -0
  69. package/dist/vite-config-parser.d.ts +62 -0
  70. package/dist/vite-config-parser.d.ts.map +1 -0
  71. package/dist/vite-config-parser.js +229 -0
  72. package/dist/vite-config-parser.js.map +1 -0
  73. package/package.json +51 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,YAAY,EAEZ,SAAS,EAET,gBAAgB,EAGjB,MAAM,YAAY,CAAC;AAcpB,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAE3B;;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;CA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B,GAC1B,mBAAmB,CAarB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,EACnD,aAAa,EAAE,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAwCxD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,EAAE,IAEzD,SAAS,YAAY,KAAG,OAAO,CAAC,OAAO,CAAC,CAQvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,EAAE,IAC1C,SAAS,YAAY,KAAG,OAAO,CAAC,OAAO,CAAC,CAGvD;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,IAC1C,SAAS,YAAY,KAAG,OAAO,CAAC,OAAO,CAAC,CAGvD;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,MAAM,EAAE,IAC/C,SAAS,YAAY,KAAG,OAAO,CAAC,OAAO,CAAC,CAcvD"}
@@ -0,0 +1,482 @@
1
+ /**
2
+ * Adapter Factory - Simplifies the creation of framework adapters
3
+ *
4
+ * Provides factory functions and preset configurations to reduce boilerplate code
5
+ */
6
+ import path from "path";
7
+ import { pathExists, readFile, detectConfigFile, detectBuildDir, detectServerEntry, generateServerWrapperCode, createDefaultMeta, logBuildArtifacts, } from "./utils.js";
8
+ import { ViteConfigParser, } from "./vite-config-parser.js";
9
+ import { parseRoutesFromSources, } from "./route-parser.js";
10
+ /**
11
+ * Built-in server wrapper presets (generic, framework-agnostic)
12
+ *
13
+ * Note: All presets use `serverBuild` (namespace import) and `serverExports` (rest exports)
14
+ * which are automatically provided by generateServerWrapperCode()
15
+ *
16
+ * Framework-specific presets should be defined in their respective adapter packages.
17
+ */
18
+ export const SERVER_WRAPPER_PRESETS = {
19
+ /** Generic handler - detects default or handler export */
20
+ generic: {
21
+ handlerSetup: `
22
+ const handler = typeof defaultExport === 'function'
23
+ ? defaultExport
24
+ : (typeof serverExports.handler === 'function' ? serverExports.handler : null);
25
+
26
+ if (!handler) {
27
+ throw new Error('No handler found in server build');
28
+ }`.trim(),
29
+ handlerCall: "handler(webRequest, ...args)",
30
+ },
31
+ /** Hono style - supports app.fetch */
32
+ hono: {
33
+ handlerSetup: `
34
+ const getHandler = () => {
35
+ if (typeof defaultExport === 'function') return defaultExport;
36
+ if (typeof serverExports.fetch === 'function') return serverExports.fetch;
37
+ if (typeof serverExports.app === 'object' && typeof serverExports.app.fetch === 'function') {
38
+ return serverExports.app.fetch.bind(serverExports.app);
39
+ }
40
+ throw new Error('No handler found in server build');
41
+ };
42
+ const serverHandler = getHandler();`.trim(),
43
+ handlerCall: "serverHandler(webRequest, ...args)",
44
+ },
45
+ /** Vite SSR - standard Vite SSR with render function */
46
+ viteSSR: {
47
+ requiresHtmlTemplate: true,
48
+ handlerSetup: `
49
+ const renderFn = typeof serverExports.render === 'function'
50
+ ? serverExports.render
51
+ : (typeof defaultExport === 'function' ? defaultExport : null);
52
+
53
+ if (!renderFn) {
54
+ throw new Error('No render function found in server build. Expected export: render(url)');
55
+ }
56
+
57
+ async function handleSSRRequest(request) {
58
+ const url = new URL(request.url);
59
+ const pathname = url.pathname;
60
+
61
+ try {
62
+ const rendered = await renderFn(pathname);
63
+ let html = __HTML_TEMPLATE__
64
+ .replace('<!--app-head-->', rendered.head ?? '')
65
+ .replace('<!--app-html-->', rendered.html ?? '');
66
+
67
+ return new Response(html, {
68
+ status: 200,
69
+ headers: { 'Content-Type': 'text/html; charset=utf-8' }
70
+ });
71
+ } catch (error) {
72
+ console.error('SSR render error:', error);
73
+ return new Response('Internal Server Error: ' + error.message, {
74
+ status: 500,
75
+ headers: { 'Content-Type': 'text/plain' }
76
+ });
77
+ }
78
+ }`.trim(),
79
+ handlerCall: "handleSSRRequest(webRequest)",
80
+ },
81
+ };
82
+ // ============================================================================
83
+ // Internal Helper Functions
84
+ // ============================================================================
85
+ /**
86
+ * Create default detect function based on config files
87
+ */
88
+ function createDefaultDetector(configFiles) {
89
+ return async (context) => {
90
+ const configPath = await detectConfigFile(context.projectRoot, configFiles);
91
+ return configPath !== null;
92
+ };
93
+ }
94
+ /**
95
+ * Create default getBuildArtifacts function
96
+ * Uses ViteConfigParser for comprehensive Vite config support:
97
+ * - build.outDir: custom output directory
98
+ * - build.assetsDir: static assets directory name
99
+ * - build.ssr: SSR entry point
100
+ * - build.manifest: manifest.json generation
101
+ * - base: public base path
102
+ * - rollupOptions.input: entry file(s)
103
+ * - rollupOptions.output.dir: output directory override
104
+ * - rollupOptions.output.entryFileNames: output filename pattern
105
+ * - rollupOptions.output.assetFileNames: asset filename pattern
106
+ * - rollupOptions.output.chunkFileNames: chunk filename pattern
107
+ */
108
+ function createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFiles, options) {
109
+ const { clientBuildDir, serverBuildDir, serverEntry } = options;
110
+ return async (context) => {
111
+ const { projectRoot, isSSR, logger, viteConfig } = context;
112
+ // Resolve client directory
113
+ let clientDir = null;
114
+ if (clientBuildDir) {
115
+ clientDir = path.join(projectRoot, clientBuildDir);
116
+ }
117
+ else {
118
+ clientDir = await detectBuildDir(projectRoot, buildDirs.client);
119
+ }
120
+ let serverDir = null;
121
+ let serverEntryPath = null;
122
+ if (isSSR && buildDirs.server) {
123
+ // Use ViteConfigParser for comprehensive config support
124
+ if (viteConfig) {
125
+ const configParser = new ViteConfigParser(viteConfig, projectRoot, {
126
+ logger,
127
+ serverEntryCandidates: serverEntryFiles,
128
+ });
129
+ // Priority 1: Explicit serverBuildDir option
130
+ if (serverBuildDir) {
131
+ serverDir = path.join(projectRoot, serverBuildDir);
132
+ }
133
+ else {
134
+ // Priority 2: Get from Vite config using parser
135
+ serverDir = configParser.getServerDir();
136
+ }
137
+ // Priority 3: Fall back to predefined build directories
138
+ if (!serverDir) {
139
+ serverDir = await detectBuildDir(projectRoot, buildDirs.server);
140
+ }
141
+ // Find server entry
142
+ if (serverEntry) {
143
+ // Explicit server entry path provided
144
+ serverEntryPath = path.join(projectRoot, serverEntry);
145
+ }
146
+ else if (serverDir) {
147
+ // Priority 1: Try to get server entry from Vite config using parser
148
+ serverEntryPath = await configParser.findServerEntry(serverDir);
149
+ if (serverEntryPath) {
150
+ logger.verbose(`Using server entry from Vite config: ${serverEntryPath}`);
151
+ }
152
+ // Priority 2: Fall back to file detection with recursive search
153
+ if (!serverEntryPath) {
154
+ serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, {
155
+ recursive: true,
156
+ logger,
157
+ });
158
+ }
159
+ }
160
+ }
161
+ else {
162
+ // No Vite config available, use fallback detection
163
+ if (serverBuildDir) {
164
+ serverDir = path.join(projectRoot, serverBuildDir);
165
+ }
166
+ else {
167
+ serverDir = await detectBuildDir(projectRoot, buildDirs.server);
168
+ }
169
+ if (serverEntry) {
170
+ serverEntryPath = path.join(projectRoot, serverEntry);
171
+ }
172
+ else if (serverDir) {
173
+ serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, {
174
+ recursive: true,
175
+ logger,
176
+ });
177
+ }
178
+ }
179
+ }
180
+ logBuildArtifacts(logger, name, {
181
+ clientDir,
182
+ serverDir,
183
+ serverEntry: serverEntryPath,
184
+ });
185
+ return {
186
+ clientDir,
187
+ serverDir,
188
+ serverEntry: serverEntryPath,
189
+ assetsDir: clientDir,
190
+ };
191
+ };
192
+ }
193
+ /**
194
+ * Create generateRoutes hook
195
+ */
196
+ function createGenerateRoutesHook(effectiveRouteConfig, fallbackRoutes) {
197
+ return async (context) => {
198
+ const { projectRoot, isSSR, logger } = context;
199
+ // Try declarative route sources first
200
+ if (effectiveRouteConfig.sources && effectiveRouteConfig.sources.length > 0) {
201
+ let parsedRoutes = await parseRoutesFromSources(projectRoot, effectiveRouteConfig.sources, { isSSR, logger });
202
+ if (parsedRoutes.length > 0) {
203
+ // Apply transform if provided
204
+ if (effectiveRouteConfig.transform) {
205
+ parsedRoutes = effectiveRouteConfig.transform(parsedRoutes, context);
206
+ }
207
+ // Add SSR extra routes
208
+ if (isSSR && effectiveRouteConfig.ssrExtraRoutes) {
209
+ effectiveRouteConfig.ssrExtraRoutes.forEach((route) => {
210
+ parsedRoutes.push({ path: route, isStatic: false, srcRoute: route });
211
+ });
212
+ }
213
+ return parsedRoutes;
214
+ }
215
+ }
216
+ // Fallback to static route list
217
+ const routeList = fallbackRoutes.map((route) => ({
218
+ path: route,
219
+ isStatic: !isSSR,
220
+ srcRoute: route,
221
+ }));
222
+ if (isSSR && effectiveRouteConfig.ssrExtraRoutes) {
223
+ effectiveRouteConfig.ssrExtraRoutes.forEach((route) => {
224
+ routeList.push({ path: route, isStatic: false, srcRoute: route });
225
+ });
226
+ }
227
+ return routeList;
228
+ };
229
+ }
230
+ /**
231
+ * Create generateMeta hook
232
+ */
233
+ function createGenerateMetaHook(ssr404) {
234
+ return async (context, routeList) => {
235
+ const meta = createDefaultMeta(routeList, { isSSR: context.isSSR });
236
+ if (ssr404 !== undefined) {
237
+ meta.conf.ssr404 = typeof ssr404 === "function"
238
+ ? ssr404(context.isSSR)
239
+ : ssr404;
240
+ }
241
+ return meta;
242
+ };
243
+ }
244
+ /**
245
+ * Create generateServerWrapper hook
246
+ */
247
+ function createGenerateServerWrapperHook(wrapperConfig, htmlTemplatePaths) {
248
+ return async (context, wrapperCfg) => {
249
+ let handlerSetup = wrapperConfig.handlerSetup;
250
+ if (wrapperConfig.requiresHtmlTemplate) {
251
+ const { projectRoot, outputDir, logger } = context;
252
+ let htmlTemplate = "";
253
+ const templateCandidates = [
254
+ ...htmlTemplatePaths.map(p => path.join(projectRoot, p)),
255
+ path.join(projectRoot, outputDir, "assets/index.html"),
256
+ ];
257
+ for (const templatePath of templateCandidates) {
258
+ if (await pathExists(templatePath)) {
259
+ htmlTemplate = await readFile(templatePath);
260
+ logger.verbose(`Found HTML template: ${templatePath}`);
261
+ break;
262
+ }
263
+ }
264
+ if (!htmlTemplate) {
265
+ logger.warn("HTML template not found, using default template");
266
+ htmlTemplate = "<!DOCTYPE html><html><head><!--app-head--></head><body><div id=\"app\"><!--app-html--></div></body></html>";
267
+ }
268
+ const escapedTemplate = JSON.stringify(htmlTemplate);
269
+ handlerSetup = `const __HTML_TEMPLATE__ = ${escapedTemplate};\n\n${handlerSetup}`;
270
+ }
271
+ return generateServerWrapperCode({
272
+ serverEntryPath: wrapperCfg.serverEntryPath,
273
+ imports: wrapperConfig.imports,
274
+ handlerSetup,
275
+ handlerCall: wrapperConfig.handlerCall,
276
+ });
277
+ };
278
+ }
279
+ /**
280
+ * Create beforeBundle hook if esbuildConfig is provided
281
+ */
282
+ function createBeforeBundleHook(esbuildConfig) {
283
+ return async (context, bundleConfig) => {
284
+ const absWorkingDir = typeof esbuildConfig.absWorkingDir === "function"
285
+ ? esbuildConfig.absWorkingDir(context)
286
+ : esbuildConfig.absWorkingDir;
287
+ return {
288
+ ...bundleConfig,
289
+ external: esbuildConfig.external || bundleConfig.external,
290
+ esbuildOptions: {
291
+ ...bundleConfig.esbuildOptions,
292
+ ...esbuildConfig.options,
293
+ ...(absWorkingDir ? { absWorkingDir } : {}),
294
+ },
295
+ };
296
+ };
297
+ }
298
+ // ============================================================================
299
+ // Main Factory Function
300
+ // ============================================================================
301
+ /**
302
+ * Create a framework adapter
303
+ */
304
+ export function createFrameworkAdapter(config, options = {}, overrides) {
305
+ const { name, configFiles, buildDirs, serverEntryFiles = ["index.js", "index.mjs", "entry.js", "main.js"], serverWrapper = "generic", routeConfig, defaultRoutes = ["/"], ssrExtraRoutes = [], ssr404, htmlTemplatePaths = ["dist/client/index.html", "dist/index.html"], esbuildConfig, } = config;
306
+ const { routes = routeConfig?.defaultRoutes || defaultRoutes } = options;
307
+ // Merge route config with legacy options
308
+ const effectiveRouteConfig = {
309
+ sources: routeConfig?.sources,
310
+ defaultRoutes: routeConfig?.defaultRoutes || defaultRoutes,
311
+ ssrExtraRoutes: routeConfig?.ssrExtraRoutes || ssrExtraRoutes,
312
+ transform: routeConfig?.transform,
313
+ };
314
+ const wrapperConfig = typeof serverWrapper === "string"
315
+ ? SERVER_WRAPPER_PRESETS[serverWrapper]
316
+ : serverWrapper;
317
+ // Build adapter using helper functions
318
+ const baseAdapter = {
319
+ name,
320
+ detect: createDefaultDetector(configFiles),
321
+ getBuildArtifacts: createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFiles, options),
322
+ hooks: {
323
+ generateRoutes: createGenerateRoutesHook(effectiveRouteConfig, routes),
324
+ generateMeta: createGenerateMetaHook(ssr404),
325
+ generateServerWrapper: createGenerateServerWrapperHook(wrapperConfig, htmlTemplatePaths),
326
+ ...(esbuildConfig ? { beforeBundle: createBeforeBundleHook(esbuildConfig) } : {}),
327
+ },
328
+ };
329
+ if (overrides) {
330
+ return {
331
+ ...baseAdapter,
332
+ ...overrides,
333
+ name: overrides.name || baseAdapter.name,
334
+ hooks: { ...baseAdapter.hooks, ...overrides.hooks },
335
+ };
336
+ }
337
+ return baseAdapter;
338
+ }
339
+ /**
340
+ * Create a stateful adapter (for complex adapters needing shared state)
341
+ */
342
+ export function createStatefulAdapter(initialState, factory) {
343
+ return factory({ ...initialState });
344
+ }
345
+ /**
346
+ * Create a server wrapper preset
347
+ *
348
+ * Helper function to create a properly typed preset with validation and normalization.
349
+ * Automatically trims handlerSetup and validates required fields.
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * const myPreset = createServerWrapperPreset({
354
+ * imports: `import { handler } from 'my-framework';`,
355
+ * handlerSetup: `const requestHandler = handler(serverExports);`,
356
+ * handlerCall: "requestHandler(webRequest)",
357
+ * });
358
+ * ```
359
+ */
360
+ export function createServerWrapperPreset(config) {
361
+ if (!config.handlerSetup) {
362
+ throw new Error("Server wrapper preset must have handlerSetup");
363
+ }
364
+ if (!config.handlerCall) {
365
+ throw new Error("Server wrapper preset must have handlerCall");
366
+ }
367
+ return {
368
+ imports: config.imports,
369
+ handlerSetup: config.handlerSetup.trim(),
370
+ handlerCall: config.handlerCall,
371
+ requiresHtmlTemplate: config.requiresHtmlTemplate,
372
+ };
373
+ }
374
+ /**
375
+ * Extend core server wrapper presets with custom presets
376
+ *
377
+ * This utility provides a standardized way for adapters to:
378
+ * 1. Add framework-specific presets while keeping core presets
379
+ * 2. Get a type-safe resolver function
380
+ * 3. Export extended presets for external use
381
+ *
382
+ * Custom presets are automatically validated and normalized using createServerWrapperPreset().
383
+ *
384
+ * @example
385
+ * ```ts
386
+ * // In vite-adapter - can pass raw config, will be validated automatically
387
+ * const { presets, resolvePreset } = extendServerWrapperPresets({
388
+ * vike: {
389
+ * imports: `import { renderPage } from 'vike/server';`,
390
+ * handlerSetup: `...`,
391
+ * handlerCall: "handleVikeRequest(webRequest)",
392
+ * },
393
+ * });
394
+ *
395
+ * export const SERVER_WRAPPER_PRESETS = presets;
396
+ * export type ServerWrapperPresetName = keyof typeof presets;
397
+ *
398
+ * // Use in adapter
399
+ * const resolved = resolvePreset(options.serverWrapper || "viteSSR");
400
+ * ```
401
+ */
402
+ export function extendServerWrapperPresets(customPresets) {
403
+ // Validate and normalize all custom presets
404
+ const normalizedCustomPresets = {};
405
+ for (const [key, preset] of Object.entries(customPresets)) {
406
+ normalizedCustomPresets[key] =
407
+ createServerWrapperPreset(preset);
408
+ }
409
+ const extendedPresets = {
410
+ ...SERVER_WRAPPER_PRESETS,
411
+ ...normalizedCustomPresets,
412
+ };
413
+ function resolvePreset(preset) {
414
+ if (typeof preset === "string") {
415
+ const resolved = extendedPresets[preset];
416
+ if (!resolved) {
417
+ throw new Error(`Unknown server wrapper preset: "${preset}". Available presets: ${Object.keys(extendedPresets).join(", ")}`);
418
+ }
419
+ return resolved;
420
+ }
421
+ // Validate and normalize inline preset
422
+ return createServerWrapperPreset(preset);
423
+ }
424
+ function getPresetNames() {
425
+ return Object.keys(extendedPresets);
426
+ }
427
+ return {
428
+ presets: extendedPresets,
429
+ resolvePreset,
430
+ getPresetNames,
431
+ };
432
+ }
433
+ /**
434
+ * Combine multiple detector functions (returns true if any matches)
435
+ */
436
+ export function combineDetectors(...detectors) {
437
+ return async (context) => {
438
+ for (const detector of detectors) {
439
+ if (await detector(context)) {
440
+ return true;
441
+ }
442
+ }
443
+ return false;
444
+ };
445
+ }
446
+ /**
447
+ * Create detector based on config files
448
+ */
449
+ export function createConfigDetector(configFiles) {
450
+ return async (context) => {
451
+ return (await detectConfigFile(context.projectRoot, configFiles)) !== null;
452
+ };
453
+ }
454
+ /**
455
+ * Create detector based on build directories
456
+ */
457
+ export function createBuildDirDetector(buildDirs) {
458
+ return async (context) => {
459
+ return (await detectBuildDir(context.projectRoot, buildDirs)) !== null;
460
+ };
461
+ }
462
+ /**
463
+ * Create detector based on package.json dependencies
464
+ */
465
+ export function createDependencyDetector(dependencies) {
466
+ return async (context) => {
467
+ const packageJsonPath = path.join(context.projectRoot, "package.json");
468
+ if (!await pathExists(packageJsonPath))
469
+ return false;
470
+ try {
471
+ const content = await readFile(packageJsonPath);
472
+ const packageJson = JSON.parse(content);
473
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
474
+ return dependencies.some((dep) => dep in deps);
475
+ }
476
+ catch (error) {
477
+ context.logger?.verbose?.(`Failed to parse package.json: ${error instanceof Error ? error.message : String(error)}`);
478
+ return false;
479
+ }
480
+ };
481
+ }
482
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB,OAAO,EACL,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,GACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,E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AAM,UAAU,sBAAsB,CAAC,SAAmB;IACxD,OAAO,KAAK,EAAE,OAAqB,EAAoB,EAAE;QACvD,OAAO,CAAC,MAAM,cAAc,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC;IACzE,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,YAAsB;IAC7D,OAAO,KAAK,EAAE,OAAqB,EAAoB,EAAE;QACvD,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QACvE,IAAI,CAAC,MAAM,UAAU,CAAC,eAAe,CAAC;YAAE,OAAO,KAAK,CAAC;QAErD,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,eAAe,CAAC,CAAC;YAChD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACxC,MAAM,IAAI,GAAG,EAAE,GAAG,WAAW,CAAC,YAAY,EAAE,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC;YAC7E,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACjD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,iCAAiC,KAAK,YAAY,KAAK,CAAC,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"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Shared helper functions for EdgeOne adapters
3
+ */
4
+ import type { RouteInfo, MetaConfig, Logger } from "./types.js";
5
+ /** Detect config file from candidate list */
6
+ export declare function detectConfigFile(projectRoot: string, patterns: string[]): Promise<string | null>;
7
+ /** Dynamically import config file */
8
+ export declare function loadConfigFile<T = unknown>(configPath: string): Promise<T | null>;
9
+ /** Create default meta configuration */
10
+ export declare function createDefaultMeta(routes: RouteInfo[], options?: {
11
+ isSSR?: boolean;
12
+ has404?: boolean;
13
+ }): MetaConfig;
14
+ /** Node.js IncomingMessage to Web Request converter code */
15
+ export declare const NODE_REQUEST_CONVERTER_CODE: string;
16
+ /** Server wrapper generator options */
17
+ export interface ServerWrapperGeneratorOptions {
18
+ /** Path to server entry file */
19
+ serverEntryPath: string;
20
+ /** Handler setup code (e.g., create request handler) */
21
+ handlerSetup?: string;
22
+ /** Handler call expression (e.g., "handler(webRequest, ...args)") */
23
+ handlerCall: string;
24
+ /** Additional import statements */
25
+ imports?: string;
26
+ /** Whether to add Node.js to Web Request conversion code */
27
+ needsNodeRequestConversion?: boolean;
28
+ /**
29
+ * Server entry loading mode:
30
+ * - "inline": Read and inline server entry content (default, for React Router)
31
+ * - "import": Use import statement to load server entry (for TanStack Start)
32
+ */
33
+ mode?: "inline" | "import";
34
+ /** Additional exports (only used in "import" mode) */
35
+ additionalExports?: string[];
36
+ }
37
+ /** Generate server wrapper code */
38
+ export declare function generateServerWrapperCode(options: ServerWrapperGeneratorOptions): Promise<string>;
39
+ /** Normalize route path */
40
+ export declare function normalizeRoutePath(routePath: string): string;
41
+ /** Convert route path to regex format */
42
+ export declare function routePathToRegex(routePath: string): string;
43
+ /** Detect server entry file */
44
+ export declare function detectServerEntry(serverDir: string, candidates?: string[]): Promise<string | null>;
45
+ /** Detect build directory */
46
+ export declare function detectBuildDir(projectRoot: string, candidates: string[]): Promise<string | null>;
47
+ /** Log build artifacts info */
48
+ export declare function logBuildArtifacts(logger: Logger, adapterName: string, artifacts: {
49
+ clientDir?: string | null;
50
+ serverDir?: string | null;
51
+ serverEntry?: string | null;
52
+ }): void;
53
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d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