@wolfstar/vite-server 0.2.1 → 0.2.2
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
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-Dr5xkZB9.js";
|
|
2
2
|
import { toNodeHandler } from "srvx/node";
|
|
3
3
|
|
|
4
4
|
//#region \0@oxc-project+runtime@0.150.0/helpers/esm/classPrivateMethodInitSpec.js
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","names":[],"sources":["../../src/plugins.ts","../../src/logger.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","names":[],"sources":["../../src/plugins.ts","../../src/logger.ts"],"mappings":";;;;;;;wBAgBgB,oBAAoB,QAAQ;;;wBCd5B,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 pluginRegistrations, n as ServerBuilder, o as toArray, s as defaultBuilderContext, t as createBuildLogger } from "./logger-
|
|
1
|
+
import { c as pluginRegistrations, n as ServerBuilder, o as toArray, s as defaultBuilderContext, t as createBuildLogger } from "./logger-Dr5xkZB9.js";
|
|
2
2
|
|
|
3
3
|
export { ServerBuilder, createBuildLogger, defaultBuilderContext, pluginRegistrations, toArray };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { basename, join, resolve } from "node:path";
|
|
2
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import { EventEmitter } from "node:events";
|
|
@@ -26,7 +26,42 @@ function pluginRegistrations(config) {
|
|
|
26
26
|
}
|
|
27
27
|
function findPluginDependencies(root) {
|
|
28
28
|
const packageJson = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
29
|
-
return [.../* @__PURE__ */ new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.optionalDependencies ?? {})])].filter((name) => PLUGIN_PACKAGE.test(name)).sort();
|
|
29
|
+
return [.../* @__PURE__ */ new Set([...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.optionalDependencies ?? {})])].filter((name) => PLUGIN_PACKAGE.test(name) && mayExportRegister(root, name)).sort();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Not every `@wolfstar/plugin-*` package is activated through a `/register` entrypoint: some (`plugin-cache`,
|
|
33
|
+
* `plugin-gateway`, `plugin-sharder`) are libraries used directly, and injecting an import of a subpath they do not
|
|
34
|
+
* export breaks the build. Only a package whose `exports` map is known and has no `./register` subpath is skipped —
|
|
35
|
+
* one that is not installed, or declares no `exports`, keeps being injected so a missing install still surfaces as a
|
|
36
|
+
* resolution error.
|
|
37
|
+
*/
|
|
38
|
+
function mayExportRegister(root, name) {
|
|
39
|
+
const packageJson = readInstalledPackageJson(root, name);
|
|
40
|
+
if (packageJson?.exports === void 0 || packageJson.exports === null) return true;
|
|
41
|
+
return exportsSubpath(packageJson.exports, "./register");
|
|
42
|
+
}
|
|
43
|
+
function readInstalledPackageJson(root, name) {
|
|
44
|
+
let directory = resolve(root);
|
|
45
|
+
while (true) try {
|
|
46
|
+
return JSON.parse(readFileSync(join(directory, "node_modules", name, "package.json"), "utf8"));
|
|
47
|
+
} catch {
|
|
48
|
+
const parent = dirname(directory);
|
|
49
|
+
if (parent === directory) return null;
|
|
50
|
+
directory = parent;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function exportsSubpath(exports, subpath) {
|
|
54
|
+
if (typeof exports !== "object" || exports === null || Array.isArray(exports)) return false;
|
|
55
|
+
const keys = Object.keys(exports);
|
|
56
|
+
if (!keys.some((key) => key.startsWith("."))) return false;
|
|
57
|
+
if (Object.hasOwn(exports, subpath)) return exports[subpath] !== null;
|
|
58
|
+
return keys.some((key) => {
|
|
59
|
+
const star = key.indexOf("*");
|
|
60
|
+
if (star === -1) return false;
|
|
61
|
+
const prefix = key.slice(0, star);
|
|
62
|
+
const suffix = key.slice(star + 1);
|
|
63
|
+
return subpath.length >= key.length && subpath.startsWith(prefix) && subpath.endsWith(suffix);
|
|
64
|
+
});
|
|
30
65
|
}
|
|
31
66
|
function cleanId(id) {
|
|
32
67
|
return resolve(id.replace(/^\0/, "").split("?", 1)[0]);
|
|
@@ -260,4 +295,4 @@ function createBuildLogger(vite, log) {
|
|
|
260
295
|
|
|
261
296
|
//#endregion
|
|
262
297
|
export { createViteConfig as a, pluginRegistrations as c, _checkPrivateRedeclaration as i, ServerBuilder as n, toArray as o, _assertClassBrand as r, defaultBuilderContext as s, createBuildLogger as t };
|
|
263
|
-
//# sourceMappingURL=logger-
|
|
298
|
+
//# sourceMappingURL=logger-Dr5xkZB9.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-Dr5xkZB9.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 } 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 * Activates installed WolfStar plugins without making applications maintain a list\n * of side-effect-only plugin registration imports in their entry point.\n */\nexport function pluginRegistrations(config: ResolvedStarsConfig): object {\n\tconst plugins = findPluginDependencies(config.root);\n\tconst entry = resolve(config.entry);\n\n\treturn {\n\t\tname: 'stars:plugin-registrations',\n\t\ttransform(code: string, id: string) {\n\t\t\tif (plugins.length === 0 || cleanId(id) !== entry) return null;\n\n\t\t\tconst registrations = plugins.map((name) => `import ${JSON.stringify(`${name}/register`)};`).join('\\n');\n\t\t\treturn { code: `${registrations}\\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;;;;;AAMvB,SAAgB,oBAAoB,QAAqC;CACxE,MAAM,UAAU,uBAAuB,OAAO,IAAI;CAClD,MAAM,QAAQ,QAAQ,OAAO,KAAK;CAElC,OAAO;EACN,MAAM;EACN,UAAU,MAAc,IAAY;GACnC,IAAI,QAAQ,WAAW,KAAK,QAAQ,EAAE,MAAM,OAAO,OAAO;GAG1D,OAAO;IAAE,MAAM,GADO,QAAQ,KAAK,SAAS,UAAU,KAAK,UAAU,GAAG,KAAK,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK,IACpE,EAAE,IAAI;IAAQ,KAAK;GAAK;EACvD;CACD;AACD;AAEA,SAAS,uBAAuB,MAAwB;CACvD,MAAM,cAAc,KAAK,MAAM,aAAa,KAAK,MAAM,cAAc,GAAG,MAAM,CAAC;CAC/E,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,YAAY,gBAAgB,CAAC,CAAC,GAAG,GAAG,OAAO,KAAK,YAAY,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3H,QAAQ,SAAS,eAAe,KAAK,IAAI,KAAK,kBAAkB,MAAM,IAAI,CAAC,CAAC,CAC5E,KAAK;AACR;;;;;;;;AASA,SAAS,kBAAkB,MAAc,MAAuB;CAC/D,MAAM,cAAc,yBAAyB,MAAM,IAAI;CACvD,IAAI,aAAa,YAAY,UAAa,Y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,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger-DbLG6z_o.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 { join, resolve } from 'node:path';\nimport type { ResolvedStarsConfig } from '@wolfstar/schema';\n\ninterface PackageJson {\n\tdependencies?: Record<string, string>;\n\toptionalDependencies?: Record<string, string>;\n}\n\nconst PLUGIN_PACKAGE = /^@wolfstar\\/plugin-[^/]+$/;\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.\n */\nexport function pluginRegistrations(config: ResolvedStarsConfig): object {\n\tconst plugins = findPluginDependencies(config.root);\n\tconst entry = resolve(config.entry);\n\n\treturn {\n\t\tname: 'stars:plugin-registrations',\n\t\ttransform(code: string, id: string) {\n\t\t\tif (plugins.length === 0 || cleanId(id) !== entry) return null;\n\n\t\t\tconst registrations = plugins.map((name) => `import ${JSON.stringify(`${name}/register`)};`).join('\\n');\n\t\t\treturn { code: `${registrations}\\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))\n\t\t.sort();\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":";;;;;;;AASA,MAAM,iBAAiB;;;;;AAMvB,SAAgB,oBAAoB,QAAqC;CACxE,MAAM,UAAU,uBAAuB,OAAO,IAAI;CAClD,MAAM,QAAQ,QAAQ,OAAO,KAAK;CAElC,OAAO;EACN,MAAM;EACN,UAAU,MAAc,IAAY;GACnC,IAAI,QAAQ,WAAW,KAAK,QAAQ,EAAE,MAAM,OAAO,OAAO;GAG1D,OAAO;IAAE,MAAM,GADO,QAAQ,KAAK,SAAS,UAAU,KAAK,UAAU,GAAG,KAAK,UAAU,EAAE,EAAE,CAAC,CAAC,KAAK,IACpE,EAAE,IAAI;IAAQ,KAAK;GAAK;EACvD;CACD;AACD;AAEA,SAAS,uBAAuB,MAAwB;CACvD,MAAM,cAAc,KAAK,MAAM,aAAa,KAAK,MAAM,cAAc,GAAG,MAAM,CAAC;CAC/E,OAAO,CAAC,mBAAG,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,YAAY,gBAAgB,CAAC,CAAC,GAAG,GAAG,OAAO,KAAK,YAAY,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3H,QAAQ,SAAS,eAAe,KAAK,IAAI,CAAC,CAAC,CAC3C,KAAK;AACR;AAEA,SAAS,QAAQ,IAAoB;CACpC,OAAO,QAAQ,GAAG,QAAQ,OAAO,EAAE,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,EAAG;AACvD;;;;;AChCA,MAAa,wBAAwC;CACpD;CACA,MAAM,kBAAqB,MAAc,IAAY,MAA0B;EAC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