@chuckcchen/vite-plugin 1.0.3 → 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 CHANGED
@@ -1,66 +1,24 @@
1
1
  /**
2
2
  * EdgeOne Vite Plugin Adapter - Server Bundling Module
3
3
  *
4
- * This module handles server-side code bundling using esbuild, main features include:
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
- * Wrap framework's server build artifacts into a unified HTTP request handler.
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
@@ -1 +1 @@
1
- {"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAaxF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CA+B9B;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvE;AAkGD;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,GAAG,MAAM,CAWjE"}
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
- * This module handles server-side code bundling using esbuild, main features include:
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 { readFile, writeFile, deleteFile, ensureDirectory } from "./utils.js";
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, // Entry file list
45
- bundle: true, // Enable bundling, pack all dependencies together
46
- platform: "node", // Target platform is Node.js
47
- target: "node18", // Target Node.js version
48
- format: "esm", // Output format is ESM
49
- outfile: config.outfile, // Output file path
50
- minify: false, // Don't minify for easier debugging
51
- treeShaking: true, // Enable tree shaking to remove unused code
52
- external: ["node:*", ...(config.external || [])], // Exclude Node.js built-in modules
53
- metafile: true, // Generate metafile for bundle analysis
54
- logLevel: "warning", // Log level
55
- absWorkingDir: projectRoot, // Working directory
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, // Add ESM compatibility banner
40
+ js: DEFAULT_BANNER,
58
41
  },
59
- ...config.esbuildOptions, // Merge additional esbuild options
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
- * Wrap framework's server build artifacts into a unified HTTP request handler.
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, replace placeholders
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 default wrapper template
95
- wrapperContent = generateDefaultWrapper(serverBuildContent, config);
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 (file may not exist)
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
@@ -1 +1 @@
1
- {"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE9E;;;;GAIG;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,iCAAiC;IACjC,M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CAAC,CAAC;IACL,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC;IAClE,MAAM,SAAS,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;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,20 +1,16 @@
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 in adapter development
4
+ * Provides factory functions and preset configurations to reduce boilerplate code
5
5
  */
6
- import type { BuildContext, FrameworkAdapter, AdapterHooks } from "./types.js";
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;
17
- /** Whether this preset requires HTML template injection */
18
14
  requiresHtmlTemplate?: boolean;
19
15
  }
20
16
  /**
@@ -48,87 +44,54 @@ export declare const SERVER_WRAPPER_PRESETS: {
48
44
  * Build directory configuration
49
45
  */
50
46
  export interface BuildDirConfig {
51
- /** Client directory candidates */
52
47
  client: string[];
53
- /** Server directory candidates (SSR mode) */
54
48
  server?: string[];
55
49
  }
56
50
  /**
57
51
  * Adapter factory configuration
58
52
  */
59
53
  export interface AdapterFactoryConfig {
60
- /** Adapter name */
61
54
  name: string;
62
- /** Config file detection list */
63
55
  configFiles: string[];
64
- /** Build directory candidates configuration */
65
56
  buildDirs: BuildDirConfig;
66
- /** Server entry file candidates */
67
57
  serverEntryFiles?: string[];
68
- /** Server wrapper configuration (use preset name or custom config) */
69
58
  serverWrapper?: keyof typeof SERVER_WRAPPER_PRESETS | ServerWrapperPreset;
70
- /** Default routes list */
71
59
  defaultRoutes?: string[];
72
- /** Extra routes for SSR mode */
73
60
  ssrExtraRoutes?: string[];
74
- /** Custom ssr404 handling */
75
61
  ssr404?: boolean | ((isSSR: boolean) => boolean);
76
- /** HTML template path candidates (for viteSSR preset) */
77
62
  htmlTemplatePaths?: string[];
78
63
  }
79
64
  /**
80
65
  * Adapter factory runtime options
81
66
  */
82
67
  export interface AdapterFactoryOptions {
83
- /** User-specified client directory */
84
68
  clientBuildDir?: string;
85
- /** User-specified server directory */
86
69
  serverBuildDir?: string;
87
- /** User-specified server entry */
88
70
  serverEntry?: string;
89
- /** User-specified routes */
90
71
  routes?: string[];
91
72
  }
92
73
  /**
93
74
  * Create a framework adapter
94
- *
95
- * @example
96
- * ```ts
97
- * const adapter = createFrameworkAdapter({
98
- * name: "my-framework",
99
- * configFiles: ["my-framework.config.ts", "my-framework.config.js"],
100
- * buildDirs: {
101
- * client: ["dist/client", "dist"],
102
- * server: ["dist/server"],
103
- * },
104
- * serverWrapper: "generic",
105
- * });
106
- * ```
107
75
  */
108
76
  export declare function createFrameworkAdapter(config: AdapterFactoryConfig, options?: AdapterFactoryOptions, overrides?: Partial<FrameworkAdapter>): FrameworkAdapter;
109
77
  /**
110
- * Create a stateful adapter
111
- * Used for complex adapters that need to share state between different hooks
78
+ * Create a stateful adapter (for complex adapters needing shared state)
112
79
  */
113
80
  export declare function createStatefulAdapter<TState extends object>(initialState: TState, factory: (state: TState) => FrameworkAdapter): FrameworkAdapter;
114
81
  /**
115
- * Compose multiple hooks
82
+ * Combine multiple detector functions (returns true if any matches)
116
83
  */
117
- export declare function composeHooks(...hooksList: (AdapterHooks | undefined)[]): AdapterHooks;
84
+ export declare function combineDetectors(...detectors: ((context: BuildContext) => Promise<boolean> | boolean)[]): (context: BuildContext) => Promise<boolean>;
118
85
  /**
119
- * Create a detector function - based on config files
86
+ * Create detector based on config files
120
87
  */
121
88
  export declare function createConfigDetector(configFiles: string[]): (context: BuildContext) => Promise<boolean>;
122
89
  /**
123
- * Create a detector function - based on build directories
90
+ * Create detector based on build directories
124
91
  */
125
92
  export declare function createBuildDirDetector(buildDirs: string[]): (context: BuildContext) => Promise<boolean>;
126
93
  /**
127
- * Create a detector function - based on package.json dependencies
94
+ * Create detector based on package.json dependencies
128
95
  */
129
96
  export declare function createDependencyDetector(dependencies: string[]): (context: BuildContext) => Promise<boolean>;
130
- /**
131
- * Combine multiple detector functions (returns true if any matches)
132
- */
133
- export declare function combineDetectors(...detectors: ((context: BuildContext) => Promise<boolean> | boolean)[]): (context: BuildContext) => Promise<boolean>;
134
97
  //# sourceMappingURL=factory.d.ts.map
@@ -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,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;IACpB,2DAA2D;IAC3D,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB;IACjC,0DAA0D;;;;;IAa1D,sCAAsC;;;;;IAatC,+CAA+C;;;;;;IAqB/C,wDAAwD;;;;;;CAwChD,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,6CAA6C;IAC7C,MAAM,CA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