@chuckcchen/vite-plugin 0.0.3 → 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.
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Adapter Factory - Simplifies the creation of framework adapters
3
+ *
4
+ * Provides factory functions and preset configurations to reduce boilerplate code in adapter development
5
+ */
6
+ import type { BuildContext, FrameworkAdapter, AdapterHooks } from "./types.js";
7
+ /**
8
+ * Server wrapper preset configuration
9
+ */
10
+ export interface ServerWrapperPreset {
11
+ /** Additional import statements */
12
+ imports?: string;
13
+ /** Handler initialization code */
14
+ handlerSetup: string;
15
+ /** Handler call expression */
16
+ handlerCall: string;
17
+ }
18
+ /**
19
+ * Built-in server wrapper presets
20
+ */
21
+ export declare const SERVER_WRAPPER_PRESETS: {
22
+ /** Generic handler - detects default or handler export */
23
+ readonly generic: {
24
+ readonly handlerSetup: string;
25
+ readonly handlerCall: "handler(webRequest, ...args)";
26
+ };
27
+ /** Hono style - supports app.fetch */
28
+ readonly hono: {
29
+ readonly handlerSetup: string;
30
+ readonly handlerCall: "serverHandler(webRequest, ...args)";
31
+ };
32
+ /** React Router - uses createRequestHandler */
33
+ readonly reactRouter: {
34
+ readonly imports: "import { createRequestHandler } from \"react-router\";";
35
+ readonly handlerSetup: string;
36
+ readonly handlerCall: "requestHandler(webRequest, ...args)";
37
+ };
38
+ };
39
+ /**
40
+ * Build directory configuration
41
+ */
42
+ export interface BuildDirConfig {
43
+ /** Client directory candidates */
44
+ client: string[];
45
+ /** Server directory candidates (SSR mode) */
46
+ server?: string[];
47
+ }
48
+ /**
49
+ * Adapter factory configuration
50
+ */
51
+ export interface AdapterFactoryConfig {
52
+ /** Adapter name */
53
+ name: string;
54
+ /** Config file detection list */
55
+ configFiles: string[];
56
+ /** Build directory candidates configuration */
57
+ buildDirs: BuildDirConfig;
58
+ /** Server entry file candidates */
59
+ serverEntryFiles?: string[];
60
+ /** Server wrapper configuration (use preset name or custom config) */
61
+ serverWrapper?: keyof typeof SERVER_WRAPPER_PRESETS | ServerWrapperPreset;
62
+ /** Default routes list */
63
+ defaultRoutes?: string[];
64
+ /** Extra routes for SSR mode */
65
+ ssrExtraRoutes?: string[];
66
+ /** Custom ssr404 handling */
67
+ ssr404?: boolean | ((isSSR: boolean) => boolean);
68
+ }
69
+ /**
70
+ * Adapter factory runtime options
71
+ */
72
+ export interface AdapterFactoryOptions {
73
+ /** User-specified client directory */
74
+ clientBuildDir?: string;
75
+ /** User-specified server directory */
76
+ serverBuildDir?: string;
77
+ /** User-specified server entry */
78
+ serverEntry?: string;
79
+ /** User-specified routes */
80
+ routes?: string[];
81
+ }
82
+ /**
83
+ * 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
+ */
98
+ export declare function createFrameworkAdapter(config: AdapterFactoryConfig, options?: AdapterFactoryOptions, overrides?: Partial<FrameworkAdapter>): FrameworkAdapter;
99
+ /**
100
+ * Create a stateful adapter
101
+ * Used for complex adapters that need to share state between different hooks
102
+ */
103
+ export declare function createStatefulAdapter<TState extends object>(initialState: TState, factory: (state: TState) => FrameworkAdapter): FrameworkAdapter;
104
+ /**
105
+ * Compose multiple hooks
106
+ */
107
+ export declare function composeHooks(...hooksList: (AdapterHooks | undefined)[]): AdapterHooks;
108
+ /**
109
+ * Create a detector function - based on config files
110
+ */
111
+ export declare function createConfigDetector(configFiles: string[]): (context: BuildContext) => Promise<boolean>;
112
+ /**
113
+ * Create a detector function - based on build directories
114
+ */
115
+ export declare function createBuildDirDetector(buildDirs: string[]): (context: BuildContext) => Promise<boolean>;
116
+ /**
117
+ * Create a detector function - based on package.json dependencies
118
+ */
119
+ 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
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,YAAY,EAIZ,gBAAgB,EAChB,YAAY,EAEb,MAAM,YAAY,CAAC;AAWpB;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,8BAA8B;IAC9B,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;IACjC,0DAA0D;;;;;IAa1D,sCAAsC;;;;;IAatC,+CAA+C;;;;;;CAoBvC,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,+CAA+C;IAC/C,SAAS,EAAE,cAAc,CAAC;IAC1B,mCAAmC;IACnC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,OAAO,sBAAsB,GAAG,mBAAmB,CAAC;IAC1E,0BAA0B;IAC1B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,gCAAgC;IAChC,cAAc,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B,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"}
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Adapter Factory - Simplifies the creation of framework adapters
3
+ *
4
+ * Provides factory functions and preset configurations to reduce boilerplate code in adapter development
5
+ */
6
+ import path from "path";
7
+ import { detectConfigFile, detectBuildDir, detectServerEntry, generateServerWrapperCode, createDefaultMeta, logBuildArtifacts, } from "./helpers.js";
8
+ import { pathExists } from "./utils.js";
9
+ /**
10
+ * Built-in server wrapper presets
11
+ */
12
+ export const SERVER_WRAPPER_PRESETS = {
13
+ /** Generic handler - detects default or handler export */
14
+ generic: {
15
+ handlerSetup: `
16
+ const handler = typeof module.default === 'function'
17
+ ? module.default
18
+ : (typeof module.handler === 'function' ? module.handler : null);
19
+
20
+ if (!handler) {
21
+ throw new Error('No handler found in server build');
22
+ }`.trim(),
23
+ handlerCall: "handler(webRequest, ...args)",
24
+ },
25
+ /** Hono style - supports app.fetch */
26
+ hono: {
27
+ handlerSetup: `
28
+ const getHandler = () => {
29
+ if (typeof handler === 'function') return handler;
30
+ if (typeof fetch === 'function') return fetch;
31
+ if (typeof app === 'object' && typeof app.fetch === 'function') return app.fetch.bind(app);
32
+ throw new Error('No handler found in server build');
33
+ };
34
+ const serverHandler = getHandler();`.trim(),
35
+ handlerCall: "serverHandler(webRequest, ...args)",
36
+ },
37
+ /** React Router - uses createRequestHandler */
38
+ reactRouter: {
39
+ imports: `import { createRequestHandler } from "react-router";`,
40
+ handlerSetup: `
41
+ const buildConfig = {
42
+ assets: serverManifest,
43
+ assetsBuildDirectory,
44
+ basename,
45
+ entry,
46
+ future,
47
+ isSpaMode,
48
+ publicPath,
49
+ routes,
50
+ routeDiscovery,
51
+ ssr
52
+ };
53
+
54
+ const requestHandler = createRequestHandler(buildConfig);`.trim(),
55
+ handlerCall: "requestHandler(webRequest, ...args)",
56
+ },
57
+ };
58
+ /**
59
+ * Create a framework adapter
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const adapter = createFrameworkAdapter({
64
+ * name: "my-framework",
65
+ * configFiles: ["my-framework.config.ts", "my-framework.config.js"],
66
+ * buildDirs: {
67
+ * client: ["dist/client", "dist"],
68
+ * server: ["dist/server"],
69
+ * },
70
+ * serverWrapper: "generic",
71
+ * });
72
+ * ```
73
+ */
74
+ export function createFrameworkAdapter(config, options = {}, overrides) {
75
+ const { name, configFiles, buildDirs, serverEntryFiles = ["index.js", "index.mjs", "entry.js", "main.js"], serverWrapper = "generic", defaultRoutes = ["/"], ssrExtraRoutes = [], ssr404, } = config;
76
+ const { clientBuildDir, serverBuildDir, serverEntry, routes = defaultRoutes, } = options;
77
+ // Resolve server wrapper configuration
78
+ const wrapperConfig = typeof serverWrapper === "string"
79
+ ? SERVER_WRAPPER_PRESETS[serverWrapper]
80
+ : serverWrapper;
81
+ const baseAdapter = {
82
+ name,
83
+ async detect(context) {
84
+ const configPath = await detectConfigFile(context.projectRoot, configFiles);
85
+ return configPath !== null;
86
+ },
87
+ async getBuildArtifacts(context) {
88
+ const { projectRoot, isSSR, logger } = context;
89
+ // Detect client directory
90
+ let clientDir = null;
91
+ if (clientBuildDir) {
92
+ clientDir = path.join(projectRoot, clientBuildDir);
93
+ }
94
+ else {
95
+ const candidates = isSSR && buildDirs.server
96
+ ? buildDirs.client
97
+ : buildDirs.client;
98
+ clientDir = await detectBuildDir(projectRoot, candidates);
99
+ }
100
+ // Detect server directory and entry
101
+ let serverDir = null;
102
+ let serverEntryPath = null;
103
+ if (isSSR && buildDirs.server) {
104
+ if (serverBuildDir) {
105
+ serverDir = path.join(projectRoot, serverBuildDir);
106
+ }
107
+ else {
108
+ serverDir = await detectBuildDir(projectRoot, buildDirs.server);
109
+ }
110
+ if (serverEntry) {
111
+ serverEntryPath = path.join(projectRoot, serverEntry);
112
+ }
113
+ else if (serverDir) {
114
+ serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles);
115
+ }
116
+ }
117
+ logBuildArtifacts(logger, name, {
118
+ clientDir,
119
+ serverDir,
120
+ serverEntry: serverEntryPath,
121
+ });
122
+ return {
123
+ clientDir,
124
+ serverDir,
125
+ serverEntry: serverEntryPath,
126
+ assetsDir: clientDir,
127
+ };
128
+ },
129
+ hooks: {
130
+ async generateRoutes(context) {
131
+ const routeList = routes.map((route) => ({
132
+ path: route,
133
+ isStatic: !context.isSSR,
134
+ srcRoute: route,
135
+ }));
136
+ // Add extra routes for SSR mode
137
+ if (context.isSSR && ssrExtraRoutes.length > 0) {
138
+ ssrExtraRoutes.forEach((route) => {
139
+ routeList.push({ path: route, isStatic: false, srcRoute: route });
140
+ });
141
+ }
142
+ return routeList;
143
+ },
144
+ async generateMeta(context, routeList) {
145
+ const meta = createDefaultMeta(routeList, { isSSR: context.isSSR });
146
+ // Custom ssr404 handling
147
+ if (ssr404 !== undefined) {
148
+ meta.conf.ssr404 = typeof ssr404 === "function"
149
+ ? ssr404(context.isSSR)
150
+ : ssr404;
151
+ }
152
+ return meta;
153
+ },
154
+ async generateServerWrapper(_context, config) {
155
+ return generateServerWrapperCode({
156
+ serverEntryPath: config.serverEntryPath,
157
+ imports: wrapperConfig.imports,
158
+ handlerSetup: wrapperConfig.handlerSetup,
159
+ handlerCall: wrapperConfig.handlerCall,
160
+ });
161
+ },
162
+ },
163
+ };
164
+ // Merge user overrides
165
+ if (overrides) {
166
+ return mergeAdapter(baseAdapter, overrides);
167
+ }
168
+ return baseAdapter;
169
+ }
170
+ /**
171
+ * Merge adapter configurations
172
+ */
173
+ function mergeAdapter(base, overrides) {
174
+ const merged = {
175
+ ...base,
176
+ ...overrides,
177
+ name: overrides.name || base.name,
178
+ };
179
+ // Merge hooks
180
+ if (base.hooks || overrides.hooks) {
181
+ merged.hooks = {
182
+ ...base.hooks,
183
+ ...overrides.hooks,
184
+ };
185
+ }
186
+ return merged;
187
+ }
188
+ /**
189
+ * Create a stateful adapter
190
+ * Used for complex adapters that need to share state between different hooks
191
+ */
192
+ export function createStatefulAdapter(initialState, factory) {
193
+ const state = { ...initialState };
194
+ return factory(state);
195
+ }
196
+ /**
197
+ * Compose multiple hooks
198
+ */
199
+ export function composeHooks(...hooksList) {
200
+ const result = {};
201
+ for (const hooks of hooksList) {
202
+ if (!hooks)
203
+ continue;
204
+ Object.assign(result, hooks);
205
+ }
206
+ return result;
207
+ }
208
+ /**
209
+ * Create a detector function - based on config files
210
+ */
211
+ export function createConfigDetector(configFiles) {
212
+ return async (context) => {
213
+ const configPath = await detectConfigFile(context.projectRoot, configFiles);
214
+ return configPath !== null;
215
+ };
216
+ }
217
+ /**
218
+ * Create a detector function - based on build directories
219
+ */
220
+ export function createBuildDirDetector(buildDirs) {
221
+ return async (context) => {
222
+ for (const dir of buildDirs) {
223
+ if (await pathExists(path.join(context.projectRoot, dir))) {
224
+ return true;
225
+ }
226
+ }
227
+ return false;
228
+ };
229
+ }
230
+ /**
231
+ * Create a detector function - based on package.json dependencies
232
+ */
233
+ export function createDependencyDetector(dependencies) {
234
+ return async (context) => {
235
+ const packageJsonPath = path.join(context.projectRoot, "package.json");
236
+ if (!await pathExists(packageJsonPath)) {
237
+ return false;
238
+ }
239
+ try {
240
+ const { readFile } = await import("./utils.js");
241
+ const content = await readFile(packageJsonPath);
242
+ const packageJson = JSON.parse(content);
243
+ const deps = { ...packageJson.dependencies, ...packageJson.devDependencies };
244
+ return dependencies.some((dep) => dep in deps);
245
+ }
246
+ catch {
247
+ return false;
248
+ }
249
+ };
250
+ }
251
+ /**
252
+ * Combine multiple detector functions (returns true if any matches)
253
+ */
254
+ export function combineDetectors(...detectors) {
255
+ return async (context) => {
256
+ for (const detector of detectors) {
257
+ if (await detector(context)) {
258
+ return true;
259
+ }
260
+ }
261
+ return false;
262
+ };
263
+ }
264
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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AAM,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;YAE7E,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC;QACjD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,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,EAAE,CAAC;gBAC5B,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
package/dist/helpers.js CHANGED
@@ -48,7 +48,7 @@ function nodeRequestToWebRequest(nodeReq) {
48
48
  const host = nodeReq.headers.host || 'localhost';
49
49
  const url = \`\${protocol}://\${host}\${nodeReq.url}\`;
50
50
 
51
- // 转换请求头
51
+ // Convert request headers
52
52
  const headers = new Headers();
53
53
  for (const [key, value] of Object.entries(nodeReq.headers)) {
54
54
  if (value) {
@@ -65,7 +65,7 @@ function nodeRequestToWebRequest(nodeReq) {
65
65
  headers: headers,
66
66
  };
67
67
 
68
- // GET/HEAD 请求添加请求体
68
+ // Add request body for non-GET/HEAD requests
69
69
  if (nodeReq.method !== 'GET' && nodeReq.method !== 'HEAD') {
70
70
  init.body = nodeReq;
71
71
  }
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ export { createCoreAdapter, default } from "./core.js";
6
6
  export { bundleServerCode, createServerWrapper, cleanupWrapper, getBundleSize, } from "./bundler.js";
7
7
  export { createLogger, pathExists, findExistingPath, copyDirectory, cleanDirectory, ensureDirectory, readFile, writeFile, deleteFile, formatSize, waitFor, listFiles, countFiles, } from "./utils.js";
8
8
  export { detectConfigFile, loadConfigFile, createDefaultMeta, NODE_REQUEST_CONVERTER_CODE, generateServerWrapperCode, normalizeRoutePath, routePathToRegex, detectServerEntry, detectBuildDir, logBuildArtifacts, } from "./helpers.js";
9
+ export { createFrameworkAdapter, createStatefulAdapter, composeHooks, createConfigDetector, createBuildDirDetector, createDependencyDetector, combineDetectors, SERVER_WRAPPER_PRESETS, } from "./factory.js";
9
10
  export type { RouteInfo, MetaConfig, HeaderRule, RedirectRule, RewriteRule, CacheRule, BuildContext, Logger, BuildArtifacts, ServerWrapperConfig, ServerBundleConfig, BeforeBuildHook, AfterBuildHook, BeforeBundleHook, AfterBundleHook, GenerateRoutesHook, GenerateMetaHook, GenerateServerWrapperHook, AdapterHooks, FrameworkAdapter, CoreAdapterOptions, ViteAdapterOptions, ReactRouterAdapterOptions, TanStackStartAdapterOptions, CreateAdapterPlugin, } from "./types.js";
10
11
  export type { ServerWrapperGeneratorOptions } from "./helpers.js";
12
+ export type { ServerWrapperPreset, BuildDirConfig, AdapterFactoryConfig, AdapterFactoryOptions, } from "./factory.js";
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGvD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,MAAM,EACN,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGvD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,SAAS,EACT,UAAU,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EACZ,MAAM,EACN,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAElE,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,cAAc,CAAC"}
package/dist/index.js CHANGED
@@ -10,4 +10,6 @@ export { bundleServerCode, createServerWrapper, cleanupWrapper, getBundleSize, }
10
10
  export { createLogger, pathExists, findExistingPath, copyDirectory, cleanDirectory, ensureDirectory, readFile, writeFile, deleteFile, formatSize, waitFor, listFiles, countFiles, } from "./utils.js";
11
11
  // Helpers
12
12
  export { detectConfigFile, loadConfigFile, createDefaultMeta, NODE_REQUEST_CONVERTER_CODE, generateServerWrapperCode, normalizeRoutePath, routePathToRegex, detectServerEntry, detectBuildDir, logBuildArtifacts, } from "./helpers.js";
13
+ // Factory
14
+ export { createFrameworkAdapter, createStatefulAdapter, composeHooks, createConfigDetector, createBuildDirDetector, createDependencyDetector, combineDetectors, SERVER_WRAPPER_PRESETS, } from "./factory.js";
13
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO;AACP,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,UAAU;AACV,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,QAAQ;AACR,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,UAAU;AACV,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO;AACP,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEvD,UAAU;AACV,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,QAAQ;AACR,OAAO,EACL,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,SAAS,EACT,UAAU,EACV,UAAU,EACV,OAAO,EACP,SAAS,EACT,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,UAAU;AACV,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,2BAA2B,EAC3B,yBAAyB,EACzB,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAEtB,UAAU;AACV,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,cAAc,CAAC"}