@chuckcchen/vite-plugin 1.0.12 → 1.0.13
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/factory/detectors.d.ts +23 -0
- package/dist/factory/detectors.d.ts.map +1 -0
- package/dist/factory/detectors.js +60 -0
- package/dist/factory/detectors.js.map +1 -0
- package/dist/factory/hooks.d.ts +84 -0
- package/dist/factory/hooks.d.ts.map +1 -0
- package/dist/factory/hooks.js +227 -0
- package/dist/factory/hooks.js.map +1 -0
- package/dist/factory/index.d.ts +68 -0
- package/dist/factory/index.d.ts.map +1 -0
- package/dist/factory/index.js +92 -0
- package/dist/factory/index.js.map +1 -0
- package/dist/factory/presets.d.ts +105 -0
- package/dist/factory/presets.d.ts.map +1 -0
- package/dist/factory/presets.js +172 -0
- package/dist/factory/presets.js.map +1 -0
- package/dist/factory.d.ts +56 -0
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +155 -10
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +9 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +35 -1
- package/dist/utils.js.map +1 -1
- package/dist/vite-config-parser.d.ts +203 -0
- package/dist/vite-config-parser.d.ts.map +1 -0
- package/dist/vite-config-parser.js +465 -0
- package/dist/vite-config-parser.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework Detectors
|
|
3
|
+
*
|
|
4
|
+
* Utilities for detecting frameworks based on config files, build directories, and dependencies
|
|
5
|
+
*/
|
|
6
|
+
import type { BuildContext } from "../types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Combine multiple detector functions (returns true if any matches)
|
|
9
|
+
*/
|
|
10
|
+
export declare function combineDetectors(...detectors: ((context: BuildContext) => Promise<boolean> | boolean)[]): (context: BuildContext) => Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* Create detector based on config files
|
|
13
|
+
*/
|
|
14
|
+
export declare function createConfigDetector(configFiles: string[]): (context: BuildContext) => Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Create detector based on build directories
|
|
17
|
+
*/
|
|
18
|
+
export declare function createBuildDirDetector(buildDirs: string[]): (context: BuildContext) => Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Create detector based on package.json dependencies
|
|
21
|
+
*/
|
|
22
|
+
export declare function createDependencyDetector(dependencies: string[]): (context: BuildContext) => Promise<boolean>;
|
|
23
|
+
//# sourceMappingURL=detectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectors.d.ts","sourceRoot":"","sources":["../../src/factory/detectors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAQhD;;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,CAmBvD"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework Detectors
|
|
3
|
+
*
|
|
4
|
+
* Utilities for detecting frameworks based on config files, build directories, and dependencies
|
|
5
|
+
*/
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { pathExists, readFile, detectConfigFile, detectBuildDir, } from "../utils.js";
|
|
8
|
+
/**
|
|
9
|
+
* Combine multiple detector functions (returns true if any matches)
|
|
10
|
+
*/
|
|
11
|
+
export function combineDetectors(...detectors) {
|
|
12
|
+
return async (context) => {
|
|
13
|
+
for (const detector of detectors) {
|
|
14
|
+
if (await detector(context)) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create detector based on config files
|
|
23
|
+
*/
|
|
24
|
+
export function createConfigDetector(configFiles) {
|
|
25
|
+
return async (context) => {
|
|
26
|
+
return (await detectConfigFile(context.projectRoot, configFiles)) !== null;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create detector based on build directories
|
|
31
|
+
*/
|
|
32
|
+
export function createBuildDirDetector(buildDirs) {
|
|
33
|
+
return async (context) => {
|
|
34
|
+
return (await detectBuildDir(context.projectRoot, buildDirs)) !== null;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create detector based on package.json dependencies
|
|
39
|
+
*/
|
|
40
|
+
export function createDependencyDetector(dependencies) {
|
|
41
|
+
return async (context) => {
|
|
42
|
+
const packageJsonPath = path.join(context.projectRoot, "package.json");
|
|
43
|
+
if (!(await pathExists(packageJsonPath)))
|
|
44
|
+
return false;
|
|
45
|
+
try {
|
|
46
|
+
const content = await readFile(packageJsonPath);
|
|
47
|
+
const packageJson = JSON.parse(content);
|
|
48
|
+
const deps = {
|
|
49
|
+
...packageJson.dependencies,
|
|
50
|
+
...packageJson.devDependencies,
|
|
51
|
+
};
|
|
52
|
+
return dependencies.some((dep) => dep in deps);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
context.logger?.verbose?.(`Failed to parse package.json: ${error instanceof Error ? error.message : String(error)}`);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=detectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detectors.js","sourceRoot":"","sources":["../../src/factory/detectors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EACL,UAAU,EACV,QAAQ,EACR,gBAAgB,EAChB,cAAc,GACf,MAAM,aAAa,CAAC;AAErB;;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;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,WAAqB;IACxD,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;;GAEG;AACH,MAAM,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,CAAC,MAAM,UAAU,CAAC,eAAe,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QAEvD,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;gBACX,GAAG,WAAW,CAAC,YAAY;gBAC3B,GAAG,WAAW,CAAC,eAAe;aAC/B,CAAC;YACF,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,CACvB,iCAAiC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAC1F,CAAC;YACF,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook Creation Functions
|
|
3
|
+
*
|
|
4
|
+
* Internal functions for creating adapter hooks
|
|
5
|
+
*/
|
|
6
|
+
import type { BuildContext, BuildArtifacts, RouteInfo, MetaConfig, ServerWrapperConfig, ServerBundleConfig } from "../types.js";
|
|
7
|
+
import { type RouteSource } from "../route-parser.js";
|
|
8
|
+
import type { ServerWrapperPreset } from "./presets.js";
|
|
9
|
+
/**
|
|
10
|
+
* Build directory configuration
|
|
11
|
+
*/
|
|
12
|
+
export interface BuildDirConfig {
|
|
13
|
+
client: string[];
|
|
14
|
+
server?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Route source configuration for declarative route parsing
|
|
18
|
+
*/
|
|
19
|
+
export interface RouteSourceConfig {
|
|
20
|
+
/** Route sources to try in order */
|
|
21
|
+
sources?: RouteSource[];
|
|
22
|
+
/** Default routes if no sources match */
|
|
23
|
+
defaultRoutes?: string[];
|
|
24
|
+
/** Extra routes to add in SSR mode */
|
|
25
|
+
ssrExtraRoutes?: string[];
|
|
26
|
+
/** Transform function for parsed routes */
|
|
27
|
+
transform?: (routes: RouteInfo[], context: BuildContext) => RouteInfo[];
|
|
28
|
+
}
|
|
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
|
+
export interface AdapterFactoryOptions {
|
|
44
|
+
clientBuildDir?: string;
|
|
45
|
+
serverBuildDir?: string;
|
|
46
|
+
serverEntry?: string;
|
|
47
|
+
routes?: string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Create default detect function based on config files
|
|
51
|
+
*/
|
|
52
|
+
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
|
+
export declare function createDefaultBuildArtifactsGetter(name: string, buildDirs: BuildDirConfig, serverEntryFiles: string[], options: AdapterFactoryOptions): (context: BuildContext) => Promise<BuildArtifacts>;
|
|
68
|
+
/**
|
|
69
|
+
* Create generateRoutes hook
|
|
70
|
+
*/
|
|
71
|
+
export declare function createGenerateRoutesHook(effectiveRouteConfig: RouteSourceConfig, fallbackRoutes: string[]): (context: BuildContext) => Promise<RouteInfo[]>;
|
|
72
|
+
/**
|
|
73
|
+
* Create generateMeta hook
|
|
74
|
+
*/
|
|
75
|
+
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
|
+
*/
|
|
83
|
+
export declare function createBeforeBundleHook(esbuildConfig: EsbuildConfig): (context: BuildContext, bundleConfig: ServerBundleConfig) => Promise<ServerBundleConfig>;
|
|
84
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/factory/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,kBAAk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AAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,cAAc,EACzB,gBAAgB,EAAE,MAAM,EAAE,EAC1B,OAAO,EAAE,qBAAqB,IAIhB,SAAS,YAAY,KAAG,OAAO,CAAC,cAAc,CAAC,CAgG9D;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,oBAAoB,EAAE,iBAAiB,EACvC,cAAc,EAAE,MAAM,EAAE,IAEV,SAAS,YAAY,KAAG,OAAO,CAAC,SAAS,EAAE,CAAC,CA8C3D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,IAG9C,SAAS,YAAY,EACrB,WAAW,SAAS,EAAE,KACrB,OAAO,CAAC,UAAU,CAAC,CAUvB;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,aAAa,EAAE,mBAAmB,EAClC,iBAAiB,EAAE,MAAM,EAAE,IAGzB,SAAS,YAAY,EACrB,YAAY,mBAAmB,KAC9B,OAAO,CAAC,MAAM,CAAC,CAqCnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,aAAa,IAE/D,SAAS,YAAY,EACrB,cAAc,kBAAkB,KAC/B,OAAO,CAAC,kBAAkB,CAAC,CAgB/B"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook Creation Functions
|
|
3
|
+
*
|
|
4
|
+
* Internal functions for creating adapter hooks
|
|
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
|
+
// Hook Creation Functions
|
|
12
|
+
// ============================================================================
|
|
13
|
+
/**
|
|
14
|
+
* Create default detect function based on config files
|
|
15
|
+
*/
|
|
16
|
+
export function createDefaultDetector(configFiles) {
|
|
17
|
+
return async (context) => {
|
|
18
|
+
const configPath = await detectConfigFile(context.projectRoot, configFiles);
|
|
19
|
+
return configPath !== null;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
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
|
+
export function createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFiles, options) {
|
|
37
|
+
const { clientBuildDir, serverBuildDir, serverEntry } = options;
|
|
38
|
+
return async (context) => {
|
|
39
|
+
const { projectRoot, isSSR, logger, viteConfig } = context;
|
|
40
|
+
// Resolve client directory
|
|
41
|
+
let clientDir = null;
|
|
42
|
+
if (clientBuildDir) {
|
|
43
|
+
clientDir = path.join(projectRoot, clientBuildDir);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
clientDir = await detectBuildDir(projectRoot, buildDirs.client);
|
|
47
|
+
}
|
|
48
|
+
let serverDir = null;
|
|
49
|
+
let serverEntryPath = null;
|
|
50
|
+
if (isSSR && buildDirs.server) {
|
|
51
|
+
// Use ViteConfigParser for comprehensive config support
|
|
52
|
+
if (viteConfig) {
|
|
53
|
+
const configParser = new ViteConfigParser(viteConfig, projectRoot, {
|
|
54
|
+
logger,
|
|
55
|
+
serverEntryCandidates: serverEntryFiles,
|
|
56
|
+
});
|
|
57
|
+
// Priority 1: Explicit serverBuildDir option
|
|
58
|
+
if (serverBuildDir) {
|
|
59
|
+
serverDir = path.join(projectRoot, serverBuildDir);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// Priority 2: Get from Vite config using parser
|
|
63
|
+
serverDir = configParser.getServerDir();
|
|
64
|
+
}
|
|
65
|
+
// Priority 3: Fall back to predefined build directories
|
|
66
|
+
if (!serverDir) {
|
|
67
|
+
serverDir = await detectBuildDir(projectRoot, buildDirs.server);
|
|
68
|
+
}
|
|
69
|
+
// Find server entry
|
|
70
|
+
if (serverEntry) {
|
|
71
|
+
// Explicit server entry path provided
|
|
72
|
+
serverEntryPath = path.join(projectRoot, serverEntry);
|
|
73
|
+
}
|
|
74
|
+
else if (serverDir) {
|
|
75
|
+
// Priority 1: Try to get server entry from Vite config using parser
|
|
76
|
+
serverEntryPath = await configParser.findServerEntry(serverDir);
|
|
77
|
+
if (serverEntryPath) {
|
|
78
|
+
logger.verbose(`Using server entry from Vite config: ${serverEntryPath}`);
|
|
79
|
+
}
|
|
80
|
+
// Priority 2: Fall back to file detection with recursive search
|
|
81
|
+
if (!serverEntryPath) {
|
|
82
|
+
serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, {
|
|
83
|
+
recursive: true,
|
|
84
|
+
logger,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// No Vite config available, use fallback detection
|
|
91
|
+
if (serverBuildDir) {
|
|
92
|
+
serverDir = path.join(projectRoot, serverBuildDir);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
serverDir = await detectBuildDir(projectRoot, buildDirs.server);
|
|
96
|
+
}
|
|
97
|
+
if (serverEntry) {
|
|
98
|
+
serverEntryPath = path.join(projectRoot, serverEntry);
|
|
99
|
+
}
|
|
100
|
+
else if (serverDir) {
|
|
101
|
+
serverEntryPath = await detectServerEntry(serverDir, serverEntryFiles, {
|
|
102
|
+
recursive: true,
|
|
103
|
+
logger,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
logBuildArtifacts(logger, name, {
|
|
109
|
+
clientDir,
|
|
110
|
+
serverDir,
|
|
111
|
+
serverEntry: serverEntryPath,
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
clientDir,
|
|
115
|
+
serverDir,
|
|
116
|
+
serverEntry: serverEntryPath,
|
|
117
|
+
assetsDir: clientDir,
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create generateRoutes hook
|
|
123
|
+
*/
|
|
124
|
+
export function createGenerateRoutesHook(effectiveRouteConfig, fallbackRoutes) {
|
|
125
|
+
return async (context) => {
|
|
126
|
+
const { projectRoot, isSSR, logger } = context;
|
|
127
|
+
// Try declarative route sources first
|
|
128
|
+
if (effectiveRouteConfig.sources &&
|
|
129
|
+
effectiveRouteConfig.sources.length > 0) {
|
|
130
|
+
let parsedRoutes = await parseRoutesFromSources(projectRoot, effectiveRouteConfig.sources, { isSSR, logger });
|
|
131
|
+
if (parsedRoutes.length > 0) {
|
|
132
|
+
// Apply transform if provided
|
|
133
|
+
if (effectiveRouteConfig.transform) {
|
|
134
|
+
parsedRoutes = effectiveRouteConfig.transform(parsedRoutes, context);
|
|
135
|
+
}
|
|
136
|
+
// Add SSR extra routes
|
|
137
|
+
if (isSSR && effectiveRouteConfig.ssrExtraRoutes) {
|
|
138
|
+
effectiveRouteConfig.ssrExtraRoutes.forEach((route) => {
|
|
139
|
+
parsedRoutes.push({ path: route, isStatic: false, srcRoute: route });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
return parsedRoutes;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Fallback to static route list
|
|
146
|
+
const routeList = fallbackRoutes.map((route) => ({
|
|
147
|
+
path: route,
|
|
148
|
+
isStatic: !isSSR,
|
|
149
|
+
srcRoute: route,
|
|
150
|
+
}));
|
|
151
|
+
if (isSSR && effectiveRouteConfig.ssrExtraRoutes) {
|
|
152
|
+
effectiveRouteConfig.ssrExtraRoutes.forEach((route) => {
|
|
153
|
+
routeList.push({ path: route, isStatic: false, srcRoute: route });
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return routeList;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Create generateMeta hook
|
|
161
|
+
*/
|
|
162
|
+
export function createGenerateMetaHook(ssr404) {
|
|
163
|
+
return async (context, routeList) => {
|
|
164
|
+
const meta = createDefaultMeta(routeList, { isSSR: context.isSSR });
|
|
165
|
+
if (ssr404 !== undefined) {
|
|
166
|
+
meta.conf.ssr404 =
|
|
167
|
+
typeof ssr404 === "function" ? ssr404(context.isSSR) : ssr404;
|
|
168
|
+
}
|
|
169
|
+
return meta;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Create generateServerWrapper hook
|
|
174
|
+
*/
|
|
175
|
+
export function createGenerateServerWrapperHook(wrapperConfig, htmlTemplatePaths) {
|
|
176
|
+
return async (context, wrapperCfg) => {
|
|
177
|
+
let handlerSetup = wrapperConfig.handlerSetup;
|
|
178
|
+
if (wrapperConfig.requiresHtmlTemplate) {
|
|
179
|
+
const { projectRoot, outputDir, logger } = context;
|
|
180
|
+
let htmlTemplate = "";
|
|
181
|
+
const templateCandidates = [
|
|
182
|
+
...htmlTemplatePaths.map((p) => path.join(projectRoot, p)),
|
|
183
|
+
path.join(projectRoot, outputDir, "assets/index.html"),
|
|
184
|
+
];
|
|
185
|
+
for (const templatePath of templateCandidates) {
|
|
186
|
+
if (await pathExists(templatePath)) {
|
|
187
|
+
htmlTemplate = await readFile(templatePath);
|
|
188
|
+
logger.verbose(`Found HTML template: ${templatePath}`);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (!htmlTemplate) {
|
|
193
|
+
logger.warn("HTML template not found, using default template");
|
|
194
|
+
htmlTemplate =
|
|
195
|
+
'<!DOCTYPE html><html><head><!--app-head--></head><body><div id="app"><!--app-html--></div></body></html>';
|
|
196
|
+
}
|
|
197
|
+
const escapedTemplate = JSON.stringify(htmlTemplate);
|
|
198
|
+
handlerSetup = `const __HTML_TEMPLATE__ = ${escapedTemplate};\n\n${handlerSetup}`;
|
|
199
|
+
}
|
|
200
|
+
return generateServerWrapperCode({
|
|
201
|
+
serverEntryPath: wrapperCfg.serverEntryPath,
|
|
202
|
+
imports: wrapperConfig.imports,
|
|
203
|
+
handlerSetup,
|
|
204
|
+
handlerCall: wrapperConfig.handlerCall,
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create beforeBundle hook if esbuildConfig is provided
|
|
210
|
+
*/
|
|
211
|
+
export function createBeforeBundleHook(esbuildConfig) {
|
|
212
|
+
return async (context, bundleConfig) => {
|
|
213
|
+
const absWorkingDir = typeof esbuildConfig.absWorkingDir === "function"
|
|
214
|
+
? esbuildConfig.absWorkingDir(context)
|
|
215
|
+
: esbuildConfig.absWorkingDir;
|
|
216
|
+
return {
|
|
217
|
+
...bundleConfig,
|
|
218
|
+
external: esbuildConfig.external || bundleConfig.external,
|
|
219
|
+
esbuildOptions: {
|
|
220
|
+
...bundleConfig.esbuildOptions,
|
|
221
|
+
...esbuildConfig.options,
|
|
222
|
+
...(absWorkingDir ? { absWorkingDir } : {}),
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/factory/hooks.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IA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AC,SAAS,CAAC,YAAY,CAAC,CAAC;YACrD,YAAY,GAAG,6BAA6B,eAAe,QAAQ,YAAY,EAAE,CAAC;QACpF,CAAC;QAED,OAAO,yBAAyB,CAAC;YAC/B,eAAe,EAAE,UAAU,CAAC,eAAe;YAC3C,OAAO,EAAE,aAAa,CAAC,OAAO;YAC9B,YAAY;YACZ,WAAW,EAAE,aAAa,CAAC,WAAW;SACvC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,aAA4B;IACjE,OAAO,KAAK,EACV,OAAqB,EACrB,YAAgC,EACH,EAAE;QAC/B,MAAM,aAAa,GACjB,OAAO,aAAa,CAAC,aAAa,KAAK,UAAU;YAC/C,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,OAAO,CAAC;YACtC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC;QAElC,OAAO;YACL,GAAG,YAAY;YACf,QAAQ,EAAE,aAAa,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ;YACzD,cAAc,EAAE;gBACd,GAAG,YAAY,CAAC,cAAc;gBAC9B,GAAG,aAAa,CAAC,OAAO;gBACxB,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC5C;SACF,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Factory
|
|
3
|
+
*
|
|
4
|
+
* Simplifies the creation of framework adapters with declarative configuration
|
|
5
|
+
*/
|
|
6
|
+
import type { FrameworkAdapter } from "../types.js";
|
|
7
|
+
import { SERVER_WRAPPER_PRESETS, type ServerWrapperPreset } from "./presets.js";
|
|
8
|
+
import { type BuildDirConfig, type RouteSourceConfig, type EsbuildConfig, type AdapterFactoryOptions } from "./hooks.js";
|
|
9
|
+
export { SERVER_WRAPPER_PRESETS, createServerWrapperPreset, extendServerWrapperPresets, type ServerWrapperPreset, type ExtendedPresetsResult, } from "./presets.js";
|
|
10
|
+
export { combineDetectors, createConfigDetector, createBuildDirDetector, createDependencyDetector, } from "./detectors.js";
|
|
11
|
+
export { type BuildDirConfig, type RouteSourceConfig, type EsbuildConfig, type AdapterFactoryOptions, } from "./hooks.js";
|
|
12
|
+
/**
|
|
13
|
+
* Adapter factory configuration
|
|
14
|
+
*/
|
|
15
|
+
export interface AdapterFactoryConfig {
|
|
16
|
+
name: string;
|
|
17
|
+
configFiles: string[];
|
|
18
|
+
buildDirs: BuildDirConfig;
|
|
19
|
+
serverEntryFiles?: string[];
|
|
20
|
+
serverWrapper?: keyof typeof SERVER_WRAPPER_PRESETS | ServerWrapperPreset;
|
|
21
|
+
/** Declarative route configuration */
|
|
22
|
+
routeConfig?: RouteSourceConfig;
|
|
23
|
+
/** Legacy: default routes (use routeConfig.defaultRoutes instead) */
|
|
24
|
+
defaultRoutes?: string[];
|
|
25
|
+
/** Legacy: SSR extra routes (use routeConfig.ssrExtraRoutes instead) */
|
|
26
|
+
ssrExtraRoutes?: string[];
|
|
27
|
+
ssr404?: boolean | ((isSSR: boolean) => boolean);
|
|
28
|
+
htmlTemplatePaths?: string[];
|
|
29
|
+
/** esbuild configuration */
|
|
30
|
+
esbuildConfig?: EsbuildConfig;
|
|
31
|
+
}
|
|
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
|
+
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
|
+
export declare function createStatefulAdapter<TState extends object>(initialState: TState, factory: (state: TState) => FrameworkAdapter): FrameworkAdapter;
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,sBAAsB,EACtB,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAOL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC3B,MAAM,YAAY,CAAC;AAGpB,OAAO,EAEL,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,GAC3B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAEL,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,qBAAqB,GAC3B,MAAM,YAAY,CAAC;AAMpB;;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,sCAAsC;IACtC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,wEAAwE;IACxE,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;IACjD,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,4BAA4B;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAMD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,GAAE,qBAA0B,EACnC,SAAS,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,GACpC,gBAAgB,CA+DlB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,SAAS,MAAM,EACzD,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,gBAAgB,GAC3C,gBAAgB,CAElB"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter Factory
|
|
3
|
+
*
|
|
4
|
+
* Simplifies the creation of framework adapters with declarative configuration
|
|
5
|
+
*/
|
|
6
|
+
import { SERVER_WRAPPER_PRESETS, } from "./presets.js";
|
|
7
|
+
import { createDefaultDetector, createDefaultBuildArtifactsGetter, createGenerateRoutesHook, createGenerateMetaHook, createGenerateServerWrapperHook, createBeforeBundleHook, } from "./hooks.js";
|
|
8
|
+
// Re-export all public APIs
|
|
9
|
+
export {
|
|
10
|
+
// Presets
|
|
11
|
+
SERVER_WRAPPER_PRESETS, createServerWrapperPreset, extendServerWrapperPresets, } 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
|
+
*/
|
|
34
|
+
export function createFrameworkAdapter(config, options = {}, overrides) {
|
|
35
|
+
const { name, configFiles, buildDirs, serverEntryFiles = ["index.js", "index.mjs", "entry.js", "main.js"], serverWrapper = "webHandler", routeConfig, defaultRoutes = ["/"], ssrExtraRoutes = [], ssr404, htmlTemplatePaths = ["dist/client/index.html", "dist/index.html"], esbuildConfig, } = config;
|
|
36
|
+
const { routes = routeConfig?.defaultRoutes || defaultRoutes } = options;
|
|
37
|
+
// Merge route config with legacy options
|
|
38
|
+
const effectiveRouteConfig = {
|
|
39
|
+
sources: routeConfig?.sources,
|
|
40
|
+
defaultRoutes: routeConfig?.defaultRoutes || defaultRoutes,
|
|
41
|
+
ssrExtraRoutes: routeConfig?.ssrExtraRoutes || ssrExtraRoutes,
|
|
42
|
+
transform: routeConfig?.transform,
|
|
43
|
+
};
|
|
44
|
+
const wrapperConfig = typeof serverWrapper === "string"
|
|
45
|
+
? SERVER_WRAPPER_PRESETS[serverWrapper]
|
|
46
|
+
: serverWrapper;
|
|
47
|
+
// Build adapter using helper functions
|
|
48
|
+
const baseAdapter = {
|
|
49
|
+
name,
|
|
50
|
+
detect: createDefaultDetector(configFiles),
|
|
51
|
+
getBuildArtifacts: createDefaultBuildArtifactsGetter(name, buildDirs, serverEntryFiles, options),
|
|
52
|
+
hooks: {
|
|
53
|
+
generateRoutes: createGenerateRoutesHook(effectiveRouteConfig, routes),
|
|
54
|
+
generateMeta: createGenerateMetaHook(ssr404),
|
|
55
|
+
generateServerWrapper: createGenerateServerWrapperHook(wrapperConfig, htmlTemplatePaths),
|
|
56
|
+
...(esbuildConfig
|
|
57
|
+
? { beforeBundle: createBeforeBundleHook(esbuildConfig) }
|
|
58
|
+
: {}),
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
if (overrides) {
|
|
62
|
+
return {
|
|
63
|
+
...baseAdapter,
|
|
64
|
+
...overrides,
|
|
65
|
+
name: overrides.name || baseAdapter.name,
|
|
66
|
+
hooks: { ...baseAdapter.hooks, ...overrides.hooks },
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return baseAdapter;
|
|
70
|
+
}
|
|
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
|
+
export function createStatefulAdapter(initialState, factory) {
|
|
90
|
+
return factory({ ...initialState });
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/factory/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,sBAAsB,GAEvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,qBAAqB,EACrB,iCAAiC,EACjC,wBAAwB,EACxB,sBAAsB,EACtB,+BAA+B,EAC/B,sBAAsB,GAKvB,MAAM,YAAY,CAAC;AAEpB,4BAA4B;AAC5B,OAAO;AACL,UAAU;AACV,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,GAG3B,MAAM,cAAc,CAAC;AAEtB,OAAO;AACL,YAAY;AACZ,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AAmCxB,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,sBAAsB,CACpC,MAA4B,EAC5B,UAAiC,EAAE,EACnC,SAAqC;IAErC,MAAM,EACJ,IAAI,EACJ,WAAW,EACX,SAAS,EACT,gBAAgB,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,CAAC,EACnE,aAAa,GAAG,YAAY,EAC5B,WAAW,EACX,aAAa,GAAG,CAAC,GAAG,CAAC,EACrB,cAAc,GAAG,EAAE,EACnB,MAAM,EACN,iBAAiB,GAAG,CAAC,wBAAwB,EAAE,iBAAiB,CAAC,EACjE,aAAa,GACd,GAAG,MAAM,CAAC;IAEX,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,aAAa,IAAI,aAAa,EAAE,GAAG,OAAO,CAAC;IAEzE,yCAAyC;IACzC,MAAM,oBAAoB,GAAsB;QAC9C,OAAO,EAAE,WAAW,EAAE,OAAO;QAC7B,aAAa,EAAE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