@wolfstar/vite-server 0.3.0 → 0.4.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.
- package/dist/esm/index.js +1 -1
- package/dist/esm/internal.d.ts +26 -2
- package/dist/esm/internal.d.ts.map +1 -1
- package/dist/esm/internal.js +2 -2
- package/dist/esm/{logger-BgqD-3--.js → logger-0lZ1o_wJ.js} +45 -7
- package/dist/esm/logger-0lZ1o_wJ.js.map +1 -0
- package/package.json +2 -2
- package/dist/esm/logger-BgqD-3--.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as createViteConfig, i as _checkPrivateRedeclaration, n as ServerBuilder, r as _assertClassBrand, s as defaultBuilderContext, t as createBuildLogger } from "./logger-
|
|
1
|
+
import { a as createViteConfig, i as _checkPrivateRedeclaration, n as ServerBuilder, r as _assertClassBrand, s as defaultBuilderContext, t as createBuildLogger } from "./logger-0lZ1o_wJ.js";
|
|
2
2
|
import { toNodeHandler } from "srvx/node";
|
|
3
3
|
|
|
4
4
|
//#region \0@oxc-project+runtime@0.151.0/helpers/esm/classPrivateMethodInitSpec.js
|
package/dist/esm/internal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as ViteModule, i as ViteHooks, n as ServerBuilder, r as ServerHooks, s as toArray, t as defaultBuilderContext } from "./context-VAAA2m2X.js";
|
|
2
|
-
import { BuilderLogLevel, ResolvedStarsConfig, StarsEnvSetupOptions } from "@wolfstar/schema";
|
|
2
|
+
import { BuilderLogLevel, ResolvedStarsConfig, RuntimePluginRegistration, StarsEnvSetupOptions } from "@wolfstar/schema";
|
|
3
3
|
//#region src/plugins.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The module that loads the project's environment (`env` in `stars.config`). It is virtual so its import can come
|
|
@@ -12,6 +12,30 @@ export declare const STARS_ENV_MODULE = "\0stars:env";
|
|
|
12
12
|
* `specifier` lets a host that cannot resolve bare specifiers (a `data:` URL preload) point at the file itself.
|
|
13
13
|
*/
|
|
14
14
|
export declare function envModuleSource(options: Readonly<StarsEnvSetupOptions>, specifier?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* The module that registers the runtime plugins installed modules added with `ctx.addPlugin` (`modules` in
|
|
17
|
+
* `stars.config`). It comes right after {@link STARS_ENV_MODULE} and before the `/register` imports, so a plugin sees
|
|
18
|
+
* the environment and is in place before the legacy registrations.
|
|
19
|
+
*/
|
|
20
|
+
export declare const STARS_MODULES_MODULE = "\0stars:modules";
|
|
21
|
+
/**
|
|
22
|
+
* How the modules module hands a plugin to `Client.use`: a plugin object, or a legacy `Plugin` class, as it is, and a
|
|
23
|
+
* factory function called with the plugin's options. A `class` is told from a factory by its source, because both are
|
|
24
|
+
* functions and calling a class without `new` throws.
|
|
25
|
+
*/
|
|
26
|
+
export declare const REGISTER_PLUGIN_SOURCE = "const __stars_register = (plugin, options) => Client.use(typeof plugin === \"function\" && !/^class[\\s{]/.test(Function.prototype.toString.call(plugin)) ? plugin(options) : plugin);";
|
|
27
|
+
interface ModulesModuleSourceOptions {
|
|
28
|
+
/** Where `Client` is imported from. `resolve` and this let a host that cannot resolve bare specifiers point at files. */
|
|
29
|
+
framework?: string;
|
|
30
|
+
/** Maps a plugin's `from` to what the generated `import` uses. */
|
|
31
|
+
resolve?: (from: string) => string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The source of the modules module: every runtime plugin is imported from its `from` and handed to `Client.use`. A
|
|
35
|
+
* function export is a factory called with the plugin's options (`definePlugin((options) => ({ … }))`), anything else
|
|
36
|
+
* is the plugin itself (see {@link REGISTER_PLUGIN_SOURCE}).
|
|
37
|
+
*/
|
|
38
|
+
export declare function modulesModuleSource(plugins: readonly RuntimePluginRegistration[], options?: ModulesModuleSourceOptions): string;
|
|
15
39
|
/**
|
|
16
40
|
* Activates installed WolfStar plugins without making applications maintain a list
|
|
17
41
|
* of side-effect-only plugin registration imports in their entry point, and registers the project's environment
|
|
@@ -30,5 +54,5 @@ export declare function createBuildLogger(vite: ViteModule, log: (level: Builder
|
|
|
30
54
|
error: (text: string) => void;
|
|
31
55
|
};
|
|
32
56
|
//#endregion
|
|
33
|
-
export { ServerBuilder, type ServerHooks, type ViteHooks, type ViteModule, defaultBuilderContext, toArray };
|
|
57
|
+
export { type ModulesModuleSourceOptions, ServerBuilder, type ServerHooks, type ViteHooks, type ViteModule, defaultBuilderContext, toArray };
|
|
34
58
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","names":[],"sources":["../../src/plugins.ts","../../src/logger.ts"],"mappings":";;;;;;;;qBAiBa;;;;;wBAMG,gBAAgB,SAAS,SAAS,uBAAuB;;;;;;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","names":[],"sources":["../../src/plugins.ts","../../src/logger.ts"],"mappings":";;;;;;;;qBAiBa;;;;;wBAMG,gBAAgB,SAAS,SAAS,uBAAuB;;;;;;qBAS5D;;;;;;qBAOA;UAGI;;EAEhB;;EAEA,WAAW;;;;;;;wBAQI,oBAAoB,kBAAkB,6BAA6B,UAAS;;;;;;wBAwB5E,oBAAoB,QAAQ;;;wBC5E5B,kBAAkB,MAAM,YAAY,MAAM,OAAO,iBAAiB;;;;EAKnE,OAAA;EACA,OAAA;EACE,SAAA;EAMD,QAAA"}
|
package/dist/esm/internal.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { c as REGISTER_PLUGIN_SOURCE, d as envModuleSource, f as modulesModuleSource, l as STARS_ENV_MODULE, n as ServerBuilder, o as toArray, p as pluginRegistrations, s as defaultBuilderContext, t as createBuildLogger, u as STARS_MODULES_MODULE } from "./logger-0lZ1o_wJ.js";
|
|
2
2
|
|
|
3
|
-
export { STARS_ENV_MODULE, ServerBuilder, createBuildLogger, defaultBuilderContext, envModuleSource, pluginRegistrations, toArray };
|
|
3
|
+
export { REGISTER_PLUGIN_SOURCE, STARS_ENV_MODULE, STARS_MODULES_MODULE, ServerBuilder, createBuildLogger, defaultBuilderContext, envModuleSource, modulesModuleSource, pluginRegistrations, toArray };
|
|
@@ -20,26 +20,64 @@ function envModuleSource(options, specifier = "@wolfstar/env-utilities") {
|
|
|
20
20
|
return `import { setup } from ${JSON.stringify(specifier)};\nsetup(${JSON.stringify(options)});\n`;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
+
* The module that registers the runtime plugins installed modules added with `ctx.addPlugin` (`modules` in
|
|
24
|
+
* `stars.config`). It comes right after {@link STARS_ENV_MODULE} and before the `/register` imports, so a plugin sees
|
|
25
|
+
* the environment and is in place before the legacy registrations.
|
|
26
|
+
*/
|
|
27
|
+
const STARS_MODULES_MODULE = "\0stars:modules";
|
|
28
|
+
/**
|
|
29
|
+
* How the modules module hands a plugin to `Client.use`: a plugin object, or a legacy `Plugin` class, as it is, and a
|
|
30
|
+
* factory function called with the plugin's options. A `class` is told from a factory by its source, because both are
|
|
31
|
+
* functions and calling a class without `new` throws.
|
|
32
|
+
*/
|
|
33
|
+
const REGISTER_PLUGIN_SOURCE = "const __stars_register = (plugin, options) => Client.use(typeof plugin === \"function\" && !/^class[\\s{]/.test(Function.prototype.toString.call(plugin)) ? plugin(options) : plugin);";
|
|
34
|
+
/**
|
|
35
|
+
* The source of the modules module: every runtime plugin is imported from its `from` and handed to `Client.use`. A
|
|
36
|
+
* function export is a factory called with the plugin's options (`definePlugin((options) => ({ … }))`), anything else
|
|
37
|
+
* is the plugin itself (see {@link REGISTER_PLUGIN_SOURCE}).
|
|
38
|
+
*/
|
|
39
|
+
function modulesModuleSource(plugins, options = {}) {
|
|
40
|
+
const { framework = "@wolfstar/http-framework", resolve: resolveFrom = (from) => from } = options;
|
|
41
|
+
const lines = [`import { Client } from ${JSON.stringify(framework)};`];
|
|
42
|
+
for (const [index, plugin] of plugins.entries()) {
|
|
43
|
+
const from = JSON.stringify(resolveFrom(plugin.from));
|
|
44
|
+
const local = `__stars_plugin_${index}`;
|
|
45
|
+
lines.push(plugin.export === "default" ? `import ${local} from ${from};` : `import { ${JSON.stringify(plugin.export)} as ${local} } from ${from};`);
|
|
46
|
+
}
|
|
47
|
+
lines.push(REGISTER_PLUGIN_SOURCE);
|
|
48
|
+
for (const [index, plugin] of plugins.entries()) lines.push(`__stars_register(__stars_plugin_${index}, ${plugin.options === void 0 ? "undefined" : JSON.stringify(plugin.options)});`);
|
|
49
|
+
return `${lines.join("\n")}\n`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
23
52
|
* Activates installed WolfStar plugins without making applications maintain a list
|
|
24
53
|
* of side-effect-only plugin registration imports in their entry point, and registers the project's environment
|
|
25
54
|
* ahead of them.
|
|
26
55
|
*/
|
|
27
56
|
function pluginRegistrations(config) {
|
|
28
|
-
const
|
|
57
|
+
const listed = /* @__PURE__ */ new Set([...(config.modules ?? []).map((module) => module.specifier), ...(config.runtime?.modules ?? []).map((module) => module.name)]);
|
|
58
|
+
const plugins = findPluginDependencies(config.root).filter((name) => !listed.has(name));
|
|
29
59
|
const entry = resolve(config.entry);
|
|
30
60
|
const env = config.env?.enabled ? config.env.options : null;
|
|
61
|
+
const runtimePlugins = config.runtime?.plugins ?? [];
|
|
62
|
+
const hasModules = runtimePlugins.length > 0;
|
|
31
63
|
return {
|
|
32
64
|
name: "stars:plugin-registrations",
|
|
33
65
|
resolveId(id) {
|
|
34
|
-
|
|
66
|
+
if (env !== null && id === "\0stars:env") return STARS_ENV_MODULE;
|
|
67
|
+
return hasModules && id === "\0stars:modules" ? STARS_MODULES_MODULE : null;
|
|
35
68
|
},
|
|
36
69
|
load(id) {
|
|
37
|
-
|
|
70
|
+
if (env !== null && id === "\0stars:env") return envModuleSource(env);
|
|
71
|
+
return hasModules && id === "\0stars:modules" ? modulesModuleSource(runtimePlugins) : null;
|
|
38
72
|
},
|
|
39
73
|
transform(code, id) {
|
|
40
|
-
if (plugins.length === 0 && env === null || cleanId(id) !== entry) return null;
|
|
74
|
+
if (plugins.length === 0 && env === null && !hasModules || cleanId(id) !== entry) return null;
|
|
41
75
|
return {
|
|
42
|
-
code: `${[
|
|
76
|
+
code: `${[
|
|
77
|
+
...env === null ? [] : [STARS_ENV_MODULE],
|
|
78
|
+
...hasModules ? [STARS_MODULES_MODULE] : [],
|
|
79
|
+
...plugins.map((name) => `${name}/register`)
|
|
80
|
+
].map((specifier) => `import ${JSON.stringify(specifier)};`).join("\n")}\n${code}`,
|
|
43
81
|
map: null
|
|
44
82
|
};
|
|
45
83
|
}
|
|
@@ -315,5 +353,5 @@ function createBuildLogger(vite, log) {
|
|
|
315
353
|
}
|
|
316
354
|
|
|
317
355
|
//#endregion
|
|
318
|
-
export { createViteConfig as a,
|
|
319
|
-
//# sourceMappingURL=logger-
|
|
356
|
+
export { createViteConfig as a, REGISTER_PLUGIN_SOURCE as c, envModuleSource as d, modulesModuleSource as f, _checkPrivateRedeclaration as i, STARS_ENV_MODULE as l, ServerBuilder as n, toArray as o, pluginRegistrations as p, _assertClassBrand as r, defaultBuilderContext as s, createBuildLogger as t, STARS_MODULES_MODULE as u };
|
|
357
|
+
//# sourceMappingURL=logger-0lZ1o_wJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-0lZ1o_wJ.js","names":[],"sources":["../../src/plugins.ts","../../src/context.ts","../../src/config.ts","../../src/lifecycle.ts","../../src/logger.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport type { ResolvedStarsConfig, RuntimePluginRegistration, StarsEnvSetupOptions } from '@wolfstar/schema';\n\ninterface PackageJson {\n\tdependencies?: Record<string, string>;\n\toptionalDependencies?: Record<string, string>;\n\texports?: unknown;\n}\n\nconst PLUGIN_PACKAGE = /^@wolfstar\\/plugin-[^/]+$/;\n\n/**\n * The module that loads the project's environment (`env` in `stars.config`). It is virtual so its import can come\n * first in the entry: ES modules evaluate their imports in order, and every `@wolfstar/plugin-*` registration (and the\n * bot's own modules) may read `process.env` as soon as it is evaluated.\n */\nexport const STARS_ENV_MODULE = '\\0stars:env';\n\n/**\n * The source of the env module: `setup()` from `@wolfstar/env-utilities` called with the resolved options.\n * `specifier` lets a host that cannot resolve bare specifiers (a `data:` URL preload) point at the file itself.\n */\nexport function envModuleSource(options: Readonly<StarsEnvSetupOptions>, specifier = '@wolfstar/env-utilities'): string {\n\treturn `import { setup } from ${JSON.stringify(specifier)};\\nsetup(${JSON.stringify(options)});\\n`;\n}\n\n/**\n * The module that registers the runtime plugins installed modules added with `ctx.addPlugin` (`modules` in\n * `stars.config`). It comes right after {@link STARS_ENV_MODULE} and before the `/register` imports, so a plugin sees\n * the environment and is in place before the legacy registrations.\n */\nexport const STARS_MODULES_MODULE = '\\0stars:modules';\n\n/**\n * How the modules module hands a plugin to `Client.use`: a plugin object, or a legacy `Plugin` class, as it is, and a\n * factory function called with the plugin's options. A `class` is told from a factory by its source, because both are\n * functions and calling a class without `new` throws.\n */\nexport const REGISTER_PLUGIN_SOURCE =\n\t'const __stars_register = (plugin, options) => Client.use(typeof plugin === \"function\" && !/^class[\\\\s{]/.test(Function.prototype.toString.call(plugin)) ? plugin(options) : plugin);';\n\nexport interface ModulesModuleSourceOptions {\n\t/** Where `Client` is imported from. `resolve` and this let a host that cannot resolve bare specifiers point at files. */\n\tframework?: string;\n\t/** Maps a plugin's `from` to what the generated `import` uses. */\n\tresolve?: (from: string) => string;\n}\n\n/**\n * The source of the modules module: every runtime plugin is imported from its `from` and handed to `Client.use`. A\n * function export is a factory called with the plugin's options (`definePlugin((options) => ({ … }))`), anything else\n * is the plugin itself (see {@link REGISTER_PLUGIN_SOURCE}).\n */\nexport function modulesModuleSource(plugins: readonly RuntimePluginRegistration[], options: ModulesModuleSourceOptions = {}): string {\n\tconst { framework = '@wolfstar/http-framework', resolve: resolveFrom = (from: string) => from } = options;\n\tconst lines = [`import { Client } from ${JSON.stringify(framework)};`];\n\tfor (const [index, plugin] of plugins.entries()) {\n\t\tconst from = JSON.stringify(resolveFrom(plugin.from));\n\t\tconst local = `__stars_plugin_${index}`;\n\t\tlines.push(\n\t\t\tplugin.export === 'default' ? `import ${local} from ${from};` : `import { ${JSON.stringify(plugin.export)} as ${local} } from ${from};`\n\t\t);\n\t}\n\n\tlines.push(REGISTER_PLUGIN_SOURCE);\n\tfor (const [index, plugin] of plugins.entries()) {\n\t\tlines.push(`__stars_register(__stars_plugin_${index}, ${plugin.options === undefined ? 'undefined' : JSON.stringify(plugin.options)});`);\n\t}\n\n\treturn `${lines.join('\\n')}\\n`;\n}\n\n/**\n * Activates installed WolfStar plugins without making applications maintain a list\n * of side-effect-only plugin registration imports in their entry point, and registers the project's environment\n * ahead of them.\n */\nexport function pluginRegistrations(config: ResolvedStarsConfig): object {\n\t// A package that is a module — listed in `modules`, or installed by one that is — was installed because the project\n\t// says so: it is not also activated by its name, which would register its plugins twice.\n\tconst listed = new Set([\n\t\t...(config.modules ?? []).map((module) => module.specifier),\n\t\t...(config.runtime?.modules ?? []).map((module) => module.name)\n\t]);\n\tconst plugins = findPluginDependencies(config.root).filter((name) => !listed.has(name));\n\tconst entry = resolve(config.entry);\n\t// Optional: hosts and tests may hand over a configuration resolved before `env` existed.\n\tconst env = config.env?.enabled ? config.env.options : null;\n\tconst runtimePlugins = config.runtime?.plugins ?? [];\n\tconst hasModules = runtimePlugins.length > 0;\n\n\treturn {\n\t\tname: 'stars:plugin-registrations',\n\t\tresolveId(id: string) {\n\t\t\tif (env !== null && id === STARS_ENV_MODULE) return STARS_ENV_MODULE;\n\t\t\treturn hasModules && id === STARS_MODULES_MODULE ? STARS_MODULES_MODULE : null;\n\t\t},\n\t\tload(id: string) {\n\t\t\tif (env !== null && id === STARS_ENV_MODULE) return envModuleSource(env);\n\t\t\treturn hasModules && id === STARS_MODULES_MODULE ? modulesModuleSource(runtimePlugins) : null;\n\t\t},\n\t\ttransform(code: string, id: string) {\n\t\t\tif ((plugins.length === 0 && env === null && !hasModules) || cleanId(id) !== entry) return null;\n\n\t\t\tconst specifiers = [\n\t\t\t\t...(env === null ? [] : [STARS_ENV_MODULE]),\n\t\t\t\t...(hasModules ? [STARS_MODULES_MODULE] : []),\n\t\t\t\t...plugins.map((name) => `${name}/register`)\n\t\t\t];\n\t\t\treturn { code: `${specifiers.map((specifier) => `import ${JSON.stringify(specifier)};`).join('\\n')}\\n${code}`, map: null };\n\t\t}\n\t};\n}\n\nfunction findPluginDependencies(root: string): string[] {\n\tconst packageJson = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as PackageJson;\n\treturn [...new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.optionalDependencies ?? {})])]\n\t\t.filter((name) => PLUGIN_PACKAGE.test(name) && mayExportRegister(root, name))\n\t\t.sort();\n}\n\n/**\n * Not every `@wolfstar/plugin-*` package is activated through a `/register` entrypoint: some (`plugin-cache`,\n * `plugin-gateway`, `plugin-sharder`) are libraries used directly, and injecting an import of a subpath they do not\n * export breaks the build. Only a package whose `exports` map is known and has no `./register` subpath is skipped —\n * one that is not installed, or declares no `exports`, keeps being injected so a missing install still surfaces as a\n * resolution error.\n */\nfunction mayExportRegister(root: string, name: string): boolean {\n\tconst packageJson = readInstalledPackageJson(root, name);\n\tif (packageJson?.exports === undefined || packageJson.exports === null) return true;\n\treturn exportsSubpath(packageJson.exports, './register');\n}\n\nfunction readInstalledPackageJson(root: string, name: string): PackageJson | null {\n\tlet directory = resolve(root);\n\twhile (true) {\n\t\ttry {\n\t\t\treturn JSON.parse(readFileSync(join(directory, 'node_modules', name, 'package.json'), 'utf8')) as PackageJson;\n\t\t} catch {\n\t\t\tconst parent = dirname(directory);\n\t\t\tif (parent === directory) return null;\n\t\t\tdirectory = parent;\n\t\t}\n\t}\n}\n\nfunction exportsSubpath(exports: unknown, subpath: string): boolean {\n\t// A string, an array, or an object of conditions only is the sugar for the `\".\"` subpath alone.\n\tif (typeof exports !== 'object' || exports === null || Array.isArray(exports)) return false;\n\n\tconst keys = Object.keys(exports);\n\tif (!keys.some((key) => key.startsWith('.'))) return false;\n\tif (Object.hasOwn(exports, subpath)) return (exports as Record<string, unknown>)[subpath] !== null;\n\n\treturn keys.some((key) => {\n\t\tconst star = key.indexOf('*');\n\t\tif (star === -1) return false;\n\t\tconst prefix = key.slice(0, star);\n\t\tconst suffix = key.slice(star + 1);\n\t\treturn subpath.length >= key.length && subpath.startsWith(prefix) && subpath.endsWith(suffix);\n\t});\n}\n\nfunction cleanId(id: string): string {\n\treturn resolve(id.replace(/^\\0/, '').split('?', 1)[0]!);\n}\n","import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { BuilderContext } from '@wolfstar/schema';\nimport { pluginRegistrations } from './plugins.js';\n\n/** Default host for standalone use. Dependencies always resolve from the application. */\nexport const defaultBuilderContext: BuilderContext = {\n\tpluginRegistrations,\n\tasync importFromProject<T>(root: string, id: string, hint: string): Promise<T> {\n\t\tlet entry: string;\n\t\ttry {\n\t\t\tentry = createRequire(join(root, 'package.json')).resolve(id);\n\t\t} catch (cause) {\n\t\t\tthrow new Error(`Cannot resolve ${id} from ${root}. ${hint}`, { cause });\n\t\t}\n\t\treturn (await import(pathToFileURL(entry).href)) as T;\n\t}\n};\n","import { basename } from 'node:path';\nimport type { BuilderContext, ResolvedStarsConfig } from '@wolfstar/schema';\nimport type { InlineConfig, Plugin, UserConfig } from 'vite';\nimport { defaultBuilderContext } from './context.js';\n\nexport type ViteModule = typeof import('vite');\nexport interface ViteHooks {\n\tconfigure?(options: InlineConfig, command: 'build' | 'serve'): void | Promise<void>;\n}\n\n/** Defaults are applied after Vite loads its config, so explicit project options win. */\nexport function createViteConfig(config: ResolvedStarsConfig, context: BuilderContext = defaultBuilderContext): InlineConfig {\n\tconst defaults: Plugin = {\n\t\tname: 'stars:server-defaults',\n\t\tenforce: 'pre',\n\t\tconfig(options) {\n\t\t\toptions.build ??= {};\n\t\t\toptions.build.ssr ??= config.entry;\n\t\t\toptions.build.outDir ??= config.build.outDir;\n\t\t\toptions.build.sourcemap ??= true;\n\t\t\toptions.build.rollupOptions ??= {};\n\t\t\tconst output = options.build.rollupOptions.output;\n\t\t\tif (!Array.isArray(output)) options.build.rollupOptions.output = { entryFileNames: basename(config.build.output), ...output };\n\t\t\toptions.resolve ??= {};\n\t\t\toptions.resolve.tsconfigPaths ??= true;\n\t\t}\n\t};\n\tconst inline = config.vite as UserConfig;\n\treturn {\n\t\t...inline,\n\t\troot: config.root,\n\t\tconfigFile: config.build.configFile ?? false,\n\t\tplugins: [defaults, context.pluginRegistrations(config) as Plugin, ...toArray(inline.plugins)]\n\t};\n}\n\nexport function toArray<T>(value: T | T[] | undefined): T[] {\n\treturn value === undefined ? [] : Array.isArray(value) ? value : [value];\n}\n","import { EventEmitter } from 'node:events';\nimport type { Builder, BuilderContext, BuilderEvents, BuildOutcome, ResolvedStarsConfig } from '@wolfstar/schema';\nimport { defaultBuilderContext } from './context.js';\n\nexport interface ServerHooks {\n\tbeforeBuild?(config: ResolvedStarsConfig): void | Promise<void>;\n\tafterBuild?(outcome: BuildOutcome): void | Promise<void>;\n\tclose?(): void | Promise<void>;\n}\n\n/** Shared lifecycle: coalesce concurrent builds, report failures and drain work before close. */\nexport abstract class ServerBuilder extends EventEmitter<BuilderEvents> implements Builder {\n\tpublic readonly tool = 'vite' as const;\n\tprotected closed = false;\n\tprotected active: Promise<BuildOutcome> | null = null;\n\tprotected watching: Promise<void> | null = null;\n\tprotected stopWatching: (() => Promise<void>) | null = null;\n\t#closing: Promise<void> | null = null;\n\tprotected constructor(\n\t\tprotected readonly config: ResolvedStarsConfig,\n\t\tprotected readonly context: BuilderContext = defaultBuilderContext,\n\t\tprotected readonly hooks: ServerHooks = {}\n\t) {\n\t\tsuper();\n\t}\n\tpublic build(): Promise<BuildOutcome> {\n\t\tif (this.closed) return Promise.reject(new Error('The server builder is closed. Create a new builder to restart.'));\n\t\tif (this.active) return this.active;\n\t\tthis.active = this.runBuild().finally(() => {\n\t\t\tthis.active = null;\n\t\t});\n\t\treturn this.active;\n\t}\n\tprivate async runBuild(): Promise<BuildOutcome> {\n\t\tconst started = performance.now();\n\t\tthis.emit('start');\n\t\tlet message: string | null = null;\n\t\ttry {\n\t\t\tawait this.hooks.beforeBuild?.(this.config);\n\t\t\tawait this.compile();\n\t\t} catch (error) {\n\t\t\tmessage = error instanceof Error ? error.message : String(error);\n\t\t}\n\t\tconst outcome = { ok: message === null, durationMs: Math.round(performance.now() - started), message };\n\t\ttry {\n\t\t\tawait this.hooks.afterBuild?.(outcome);\n\t\t} catch (error) {\n\t\t\toutcome.ok = false;\n\t\t\toutcome.message = error instanceof Error ? error.message : String(error);\n\t\t}\n\t\tif (!this.closed) this.emit(outcome.ok ? 'success' : 'failure', outcome);\n\t\treturn outcome;\n\t}\n\tprotected abstract compile(): Promise<void>;\n\tprotected abstract startWatching(): Promise<void>;\n\tpublic watch(): Promise<void> {\n\t\tif (this.closed) return Promise.reject(new Error('The server builder is closed.'));\n\t\tthis.watching ??= this.startWatching().catch(async (error: unknown) => {\n\t\t\tconst stop = this.stopWatching;\n\t\t\tthis.stopWatching = null;\n\t\t\tawait stop?.();\n\t\t\tthis.watching = null;\n\t\t\tthrow error;\n\t\t});\n\t\treturn this.watching;\n\t}\n\tpublic close(): Promise<void> {\n\t\tthis.closed = true;\n\t\tthis.#closing ??= (async () => {\n\t\t\ttry {\n\t\t\t\tawait this.watching?.catch(() => {});\n\t\t\t\tconst stop = this.stopWatching;\n\t\t\t\tthis.stopWatching = null;\n\t\t\t\ttry {\n\t\t\t\t\tawait stop?.();\n\t\t\t\t} finally {\n\t\t\t\t\tawait this.active;\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait this.hooks.close?.();\n\t\t\t}\n\t\t})();\n\t\treturn this.#closing;\n\t}\n}\n","import type { BuilderLogLevel } from '@wolfstar/schema';\nimport type { ViteModule } from './config.js';\nexport function createBuildLogger(vite: ViteModule, log: (level: BuilderLogLevel, text: string) => void) {\n\tconst logger = vite.createLogger('warn', { allowClearScreen: false });\n\tconst warned = new Set<string>();\n\treturn {\n\t\t...logger,\n\t\tinfo: (text: string) => log('info', text),\n\t\twarn: (text: string) => log('warn', text),\n\t\twarnOnce(text: string) {\n\t\t\tif (!warned.has(text)) {\n\t\t\t\twarned.add(text);\n\t\t\t\tlog('warn', text);\n\t\t\t}\n\t\t},\n\t\terror: (text: string) => log('error', text)\n\t};\n}\n"],"mappings":";;;;;;;AAUA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,mBAAmB;;;;;AAMhC,SAAgB,gBAAgB,SAAyC,YAAY,2BAAmC;CACvH,OAAO,yBAAyB,KAAK,UAAU,SAAS,EAAE,WAAW,KAAK,UAAU,OAAO,EAAE;AAC9F;;;;;;AAOA,MAAa,uBAAuB;;;;;;AAOpC,MAAa,yBACZ;;;;;;AAcD,SAAgB,oBAAoB,SAA+C,UAAsC,CAAC,GAAW;CACpI,MAAM,EAAE,YAAY,4BAA4B,SAAS,eAAe,SAAiB,SAAS;CAClG,MAAM,QAAQ,CAAC,0BAA0B,KAAK,UAAU,SAAS,EAAE,EAAE;CACrE,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,QAAQ,GAAG;EAChD,MAAM,OAAO,KAAK,UAAU,YAAY,OAAO,IAAI,CAAC;EACpD,MAAM,QAAQ,kBAAkB;EAChC,MAAM,KACL,OAAO,WAAW,YAAY,UAAU,MAAM,QAAQ,KAAK,KAAK,YAAY,KAAK,UAAU,OAAO,MAAM,EAAE,MAAM,MAAM,UAAU,KAAK,EACtI;CACD;CAEA,MAAM,KAAK,sBAAsB;CACjC,KAAK,MAAM,CAAC,OAAO,WAAW,QAAQ,QAAQ,GAC7C,MAAM,KAAK,mCAAmC,MAAM,IAAI,OAAO,YAAY,SAAY,cAAc,KAAK,UAAU,OAAO,OAAO,EAAE,GAAG;CAGxI,OAAO,GAAG,MAAM,KAAK,IAAI,EAAE;AAC5B;;;;;;AAOA,SAAgB,oBA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AAQ,OAAO,QAAQ,uBAAO,IAAI,MAAM,+BAA+B,CAAC;EACjF,KAAK,aAAa,KAAK,cAAc,CAAC,CAAC,MAAM,OAAO,UAAmB;GACtE,MAAM,OAAO,KAAK;GAClB,KAAK,eAAe;GACpB,MAAM,OAAO;GACb,KAAK,WAAW;GAChB,MAAM;EACP,CAAC;EACD,OAAO,KAAK;CACb;CACA,AAAO,QAAuB;EAC7B,KAAK,SAAS;EACd,kFAAmB,YAAY;GAC9B,IAAI;IACH,MAAM,KAAK,UAAU,YAAY,CAAC,CAAC;IACnC,MAAM,OAAO,KAAK;IAClB,KAAK,eAAe;IACpB,IAAI;KACH,MAAM,OAAO;IACd,UAAU;KACT,MAAM,KAAK;IACZ;GACD,UAAU;IACT,MAAM,KAAK,MAAM,QAAQ;GAC1B;EACD,EAAC,CAAE;EACH,wCAAO;CACR;AACD;;;;AClFA,SAAgB,kBAAkB,MAAkB,KAAqD;CACxG,MAAM,SAAS,KAAK,aAAa,QAAQ,EAAE,kBAAkB,MAAM,CAAC;CACpE,MAAM,yBAAS,IAAI,IAAY;CAC/B,OAAO;EACN,GAAG;EACH,OAAO,SAAiB,IAAI,QAAQ,IAAI;EACxC,OAAO,SAAiB,IAAI,QAAQ,IAAI;EACxC,SAAS,MAAc;GACtB,IAAI,CAAC,OAAO,IAAI,IAAI,GAAG;IACtB,OAAO,IAAI,IAAI;IACf,IAAI,QAAQ,IAAI;GACjB;EACD;EACA,QAAQ,SAAiB,IAAI,SAAS,IAAI;CAC3C;AACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wolfstar/vite-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Vite build and watch integration for Stars projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"provenance": true
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@wolfstar/schema": "^0.
|
|
54
|
+
"@wolfstar/schema": "^0.5.0",
|
|
55
55
|
"srvx": "^1.0.5"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger-BgqD-3--.js","names":[],"sources":["../../src/plugins.ts","../../src/context.ts","../../src/config.ts","../../src/lifecycle.ts","../../src/logger.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport type { ResolvedStarsConfig, StarsEnvSetupOptions } from '@wolfstar/schema';\n\ninterface PackageJson {\n\tdependencies?: Record<string, string>;\n\toptionalDependencies?: Record<string, string>;\n\texports?: unknown;\n}\n\nconst PLUGIN_PACKAGE = /^@wolfstar\\/plugin-[^/]+$/;\n\n/**\n * The module that loads the project's environment (`env` in `stars.config`). It is virtual so its import can come\n * first in the entry: ES modules evaluate their imports in order, and every `@wolfstar/plugin-*` registration (and the\n * bot's own modules) may read `process.env` as soon as it is evaluated.\n */\nexport const STARS_ENV_MODULE = '\\0stars:env';\n\n/**\n * The source of the env module: `setup()` from `@wolfstar/env-utilities` called with the resolved options.\n * `specifier` lets a host that cannot resolve bare specifiers (a `data:` URL preload) point at the file itself.\n */\nexport function envModuleSource(options: Readonly<StarsEnvSetupOptions>, specifier = '@wolfstar/env-utilities'): string {\n\treturn `import { setup } from ${JSON.stringify(specifier)};\\nsetup(${JSON.stringify(options)});\\n`;\n}\n\n/**\n * Activates installed WolfStar plugins without making applications maintain a list\n * of side-effect-only plugin registration imports in their entry point, and registers the project's environment\n * ahead of them.\n */\nexport function pluginRegistrations(config: ResolvedStarsConfig): object {\n\tconst plugins = findPluginDependencies(config.root);\n\tconst entry = resolve(config.entry);\n\t// Optional: hosts and tests may hand over a configuration resolved before `env` existed.\n\tconst env = config.env?.enabled ? config.env.options : null;\n\n\treturn {\n\t\tname: 'stars:plugin-registrations',\n\t\tresolveId(id: string) {\n\t\t\treturn env !== null && id === STARS_ENV_MODULE ? STARS_ENV_MODULE : null;\n\t\t},\n\t\tload(id: string) {\n\t\t\treturn env !== null && id === STARS_ENV_MODULE ? envModuleSource(env) : null;\n\t\t},\n\t\ttransform(code: string, id: string) {\n\t\t\tif ((plugins.length === 0 && env === null) || cleanId(id) !== entry) return null;\n\n\t\t\tconst specifiers = [...(env === null ? [] : [STARS_ENV_MODULE]), ...plugins.map((name) => `${name}/register`)];\n\t\t\treturn { code: `${specifiers.map((specifier) => `import ${JSON.stringify(specifier)};`).join('\\n')}\\n${code}`, map: null };\n\t\t}\n\t};\n}\n\nfunction findPluginDependencies(root: string): string[] {\n\tconst packageJson = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as PackageJson;\n\treturn [...new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.optionalDependencies ?? {})])]\n\t\t.filter((name) => PLUGIN_PACKAGE.test(name) && mayExportRegister(root, name))\n\t\t.sort();\n}\n\n/**\n * Not every `@wolfstar/plugin-*` package is activated through a `/register` entrypoint: some (`plugin-cache`,\n * `plugin-gateway`, `plugin-sharder`) are libraries used directly, and injecting an import of a subpath they do not\n * export breaks the build. Only a package whose `exports` map is known and has no `./register` subpath is skipped —\n * one that is not installed, or declares no `exports`, keeps being injected so a missing install still surfaces as a\n * resolution error.\n */\nfunction mayExportRegister(root: string, name: string): boolean {\n\tconst packageJson = readInstalledPackageJson(root, name);\n\tif (packageJson?.exports === undefined || packageJson.exports === null) return true;\n\treturn exportsSubpath(packageJson.exports, './register');\n}\n\nfunction readInstalledPackageJson(root: string, name: string): PackageJson | null {\n\tlet directory = resolve(root);\n\twhile (true) {\n\t\ttry {\n\t\t\treturn JSON.parse(readFileSync(join(directory, 'node_modules', name, 'package.json'), 'utf8')) as PackageJson;\n\t\t} catch {\n\t\t\tconst parent = dirname(directory);\n\t\t\tif (parent === directory) return null;\n\t\t\tdirectory = parent;\n\t\t}\n\t}\n}\n\nfunction exportsSubpath(exports: unknown, subpath: string): boolean {\n\t// A string, an array, or an object of conditions only is the sugar for the `\".\"` subpath alone.\n\tif (typeof exports !== 'object' || exports === null || Array.isArray(exports)) return false;\n\n\tconst keys = Object.keys(exports);\n\tif (!keys.some((key) => key.startsWith('.'))) return false;\n\tif (Object.hasOwn(exports, subpath)) return (exports as Record<string, unknown>)[subpath] !== null;\n\n\treturn keys.some((key) => {\n\t\tconst star = key.indexOf('*');\n\t\tif (star === -1) return false;\n\t\tconst prefix = key.slice(0, star);\n\t\tconst suffix = key.slice(star + 1);\n\t\treturn subpath.length >= key.length && subpath.startsWith(prefix) && subpath.endsWith(suffix);\n\t});\n}\n\nfunction cleanId(id: string): string {\n\treturn resolve(id.replace(/^\\0/, '').split('?', 1)[0]!);\n}\n","import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { BuilderContext } from '@wolfstar/schema';\nimport { pluginRegistrations } from './plugins.js';\n\n/** Default host for standalone use. Dependencies always resolve from the application. */\nexport const defaultBuilderContext: BuilderContext = {\n\tpluginRegistrations,\n\tasync importFromProject<T>(root: string, id: string, hint: string): Promise<T> {\n\t\tlet entry: string;\n\t\ttry {\n\t\t\tentry = createRequire(join(root, 'package.json')).resolve(id);\n\t\t} catch (cause) {\n\t\t\tthrow new Error(`Cannot resolve ${id} from ${root}. ${hint}`, { cause });\n\t\t}\n\t\treturn (await import(pathToFileURL(entry).href)) as T;\n\t}\n};\n","import { basename } from 'node:path';\nimport type { BuilderContext, ResolvedStarsConfig } from '@wolfstar/schema';\nimport type { InlineConfig, Plugin, UserConfig } from 'vite';\nimport { defaultBuilderContext } from './context.js';\n\nexport type ViteModule = typeof import('vite');\nexport interface ViteHooks {\n\tconfigure?(options: InlineConfig, command: 'build' | 'serve'): void | Promise<void>;\n}\n\n/** Defaults are applied after Vite loads its config, so explicit project options win. */\nexport function createViteConfig(config: ResolvedStarsConfig, context: BuilderContext = defaultBuilderContext): InlineConfig {\n\tconst defaults: Plugin = {\n\t\tname: 'stars:server-defaults',\n\t\tenforce: 'pre',\n\t\tconfig(options) {\n\t\t\toptions.build ??= {};\n\t\t\toptions.build.ssr ??= config.entry;\n\t\t\toptions.build.outDir ??= config.build.outDir;\n\t\t\toptions.build.sourcemap ??= true;\n\t\t\toptions.build.rollupOptions ??= {};\n\t\t\tconst output = options.build.rollupOptions.output;\n\t\t\tif (!Array.isArray(output)) options.build.rollupOptions.output = { entryFileNames: basename(config.build.output), ...output };\n\t\t\toptions.resolve ??= {};\n\t\t\toptions.resolve.tsconfigPaths ??= true;\n\t\t}\n\t};\n\tconst inline = config.vite as UserConfig;\n\treturn {\n\t\t...inline,\n\t\troot: config.root,\n\t\tconfigFile: config.build.configFile ?? false,\n\t\tplugins: [defaults, context.pluginRegistrations(config) as Plugin, ...toArray(inline.plugins)]\n\t};\n}\n\nexport function toArray<T>(value: T | T[] | undefined): T[] {\n\treturn value === undefined ? [] : Array.isArray(value) ? value : [value];\n}\n","import { EventEmitter } from 'node:events';\nimport type { Builder, BuilderContext, BuilderEvents, BuildOutcome, ResolvedStarsConfig } from '@wolfstar/schema';\nimport { defaultBuilderContext } from './context.js';\n\nexport interface ServerHooks {\n\tbeforeBuild?(config: ResolvedStarsConfig): void | Promise<void>;\n\tafterBuild?(outcome: BuildOutcome): void | Promise<void>;\n\tclose?(): void | Promise<void>;\n}\n\n/** Shared lifecycle: coalesce concurrent builds, report failures and drain work before close. */\nexport abstract class ServerBuilder extends EventEmitter<BuilderEvents> implements Builder {\n\tpublic readonly tool = 'vite' as const;\n\tprotected closed = false;\n\tprotected active: Promise<BuildOutcome> | null = null;\n\tprotected watching: Promise<void> | null = null;\n\tprotected stopWatching: (() => Promise<void>) | null = null;\n\t#closing: Promise<void> | null = null;\n\tprotected constructor(\n\t\tprotected readonly config: ResolvedStarsConfig,\n\t\tprotected readonly context: BuilderContext = defaultBuilderContext,\n\t\tprotected readonly hooks: ServerHooks = {}\n\t) {\n\t\tsuper();\n\t}\n\tpublic build(): Promise<BuildOutcome> {\n\t\tif (this.closed) return Promise.reject(new Error('The server builder is closed. Create a new builder to restart.'));\n\t\tif (this.active) return this.active;\n\t\tthis.active = this.runBuild().finally(() => {\n\t\t\tthis.active = null;\n\t\t});\n\t\treturn this.active;\n\t}\n\tprivate async runBuild(): Promise<BuildOutcome> {\n\t\tconst started = performance.now();\n\t\tthis.emit('start');\n\t\tlet message: string | null = null;\n\t\ttry {\n\t\t\tawait this.hooks.beforeBuild?.(this.config);\n\t\t\tawait this.compile();\n\t\t} catch (error) {\n\t\t\tmessage = error instanceof Error ? error.message : String(error);\n\t\t}\n\t\tconst outcome = { ok: message === null, durationMs: Math.round(performance.now() - started), message };\n\t\ttry {\n\t\t\tawait this.hooks.afterBuild?.(outcome);\n\t\t} catch (error) {\n\t\t\toutcome.ok = false;\n\t\t\toutcome.message = error instanceof Error ? error.message : String(error);\n\t\t}\n\t\tif (!this.closed) this.emit(outcome.ok ? 'success' : 'failure', outcome);\n\t\treturn outcome;\n\t}\n\tprotected abstract compile(): Promise<void>;\n\tprotected abstract startWatching(): Promise<void>;\n\tpublic watch(): Promise<void> {\n\t\tif (this.closed) return Promise.reject(new Error('The server builder is closed.'));\n\t\tthis.watching ??= this.startWatching().catch(async (error: unknown) => {\n\t\t\tconst stop = this.stopWatching;\n\t\t\tthis.stopWatching = null;\n\t\t\tawait stop?.();\n\t\t\tthis.watching = null;\n\t\t\tthrow error;\n\t\t});\n\t\treturn this.watching;\n\t}\n\tpublic close(): Promise<void> {\n\t\tthis.closed = true;\n\t\tthis.#closing ??= (async () => {\n\t\t\ttry {\n\t\t\t\tawait this.watching?.catch(() => {});\n\t\t\t\tconst stop = this.stopWatching;\n\t\t\t\tthis.stopWatching = null;\n\t\t\t\ttry {\n\t\t\t\t\tawait stop?.();\n\t\t\t\t} finally {\n\t\t\t\t\tawait this.active;\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\tawait this.hooks.close?.();\n\t\t\t}\n\t\t})();\n\t\treturn this.#closing;\n\t}\n}\n","import type { BuilderLogLevel } from '@wolfstar/schema';\nimport type { ViteModule } from './config.js';\nexport function createBuildLogger(vite: ViteModule, log: (level: BuilderLogLevel, text: string) => void) {\n\tconst logger = vite.createLogger('warn', { allowClearScreen: false });\n\tconst warned = new Set<string>();\n\treturn {\n\t\t...logger,\n\t\tinfo: (text: string) => log('info', text),\n\t\twarn: (text: string) => log('warn', text),\n\t\twarnOnce(text: string) {\n\t\t\tif (!warned.has(text)) {\n\t\t\t\twarned.add(text);\n\t\t\t\tlog('warn', text);\n\t\t\t}\n\t\t},\n\t\terror: (text: string) => log('error', text)\n\t};\n}\n"],"mappings":";;;;;;;AAUA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,mBAAmB;;;;;AAMhC,SAAgB,gBAAgB,SAAyC,YAAY,2BAAmC;CACvH,OAAO,yBAAyB,KAAK,UAAU,SAAS,EAAE,WAAW,KAAK,UAAU,OAAO,EAAE;AAC9F;;;;;;AAOA,SAAgB,oBAAoB,QAAqC;CACxE,MAAM,UAAU,uBAAuB,OAAO,IAAI;CAClD,MAAM,QAAQ,QAAQ,OAAO,KAAK;CAElC,MAAM,MAAM,OAAO,KAAK,UAAU,OAAO,IAAI,UAAU;CAEvD,OAAO;EACN,MAAM;EACN,UAAU,IAAY;GACrB,OAAO,QAAQ,QAAQ,uBAA0B,mBAAmB;EACrE;EACA,KAAK,IAAY;GAChB,OAAO,QAAQ,QAAQ,uBAA0B,gBAAgB,GAAG,IAAI;EACzE;EACA,UAAU,MAAc,IAAY;GACnC,IAAK,QAAQ,WAAW,KAAK,QAAQ,QAAS,QAAQ,EAAE,MAAM,OAAO,OAAO;GAG5E,OAAO;IAAE,MAAM,GAAG,CADE,GAAI,QAAQ,OAAO,CAAC,IAAI,CAAC,gBAAgB,GAAI,GAAG,QAAQ,KAAK,SAAS,GAAG,KAAK,UAAU,CACjF,CAAC,CAAC,KAAK,cAAc,UAAU,KAAK,UAAU,SAAS,EAAE,EAAE,CAAC,CAAC,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