everything-dev 1.9.4 → 1.9.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { fetchBosConfigFromFastKv } from \"./fastkv\";\nimport { getNetworkIdForAccount } from \"./network\";\nimport type { BosConfig, BosConfigInput, RuntimeConfig, RuntimePluginConfig } from \"./types\";\nimport { BosConfigSchema } from \"./types\";\n\nconst LOCAL_PREFIX = \"local:\";\nconst DEFAULT_HOST_PORT = 3000;\n\ninterface RuntimeTarget {\n source: \"local\" | \"remote\";\n url: string;\n localPath?: string;\n port?: number;\n}\n\nlet cachedConfig: BosConfig | null = null;\nlet projectRoot: string | null = null;\n\nexport function clearConfigCache(): void {\n cachedConfig = null;\n projectRoot = null;\n}\n\nexport function findConfigPath(cwd?: string): string | null {\n let dir = cwd ?? process.cwd();\n while (dir !== \"/\") {\n const configPath = join(dir, \"bos.config.json\");\n if (existsSync(configPath)) {\n return configPath;\n }\n dir = dirname(dir);\n }\n return null;\n}\n\nexport function getConfig(): BosConfig | null {\n return cachedConfig;\n}\n\nexport function getProjectRoot(): string {\n if (!projectRoot) {\n throw new Error(\"Config not loaded. Call loadConfig() first.\");\n }\n return projectRoot;\n}\n\nexport interface ConfigResult {\n config: BosConfig;\n runtime: RuntimeConfig;\n source: {\n path: string;\n extended?: string[];\n remote?: boolean;\n };\n}\n\nexport async function loadConfig(options?: {\n cwd?: string;\n path?: string;\n env?: \"development\" | \"production\";\n}): Promise<ConfigResult | null> {\n const configPath = options?.path ?? findConfigPath(options?.cwd);\n if (!configPath) {\n projectRoot = options?.cwd ?? process.cwd();\n return null;\n }\n\n const baseDir = dirname(configPath);\n\n try {\n const extendedChain: string[] = [];\n const parsed = await resolveConfigWithExtends(configPath, baseDir, new Set(), extendedChain);\n const config = BosConfigSchema.parse(parsed);\n\n cachedConfig = config;\n projectRoot = baseDir;\n\n const pluginRuntime = await resolveRuntimePlugins(\n config.plugins ?? {},\n baseDir,\n options?.env ?? \"development\",\n );\n const runtime = buildRuntimeConfig(config, baseDir, options?.env ?? \"development\", {\n plugins: pluginRuntime,\n });\n\n return {\n config,\n runtime,\n source: {\n path: configPath,\n extended: extendedChain.length > 0 ? extendedChain : undefined,\n remote: extendedChain.some((entry) => entry.startsWith(\"bos://\")),\n },\n };\n } catch (error) {\n throw new Error(`Failed to load config from ${configPath}: ${error}`);\n }\n}\n\nexport async function loadBosConfig(options?: {\n cwd?: string;\n path?: string;\n env?: \"development\" | \"production\";\n}): Promise<RuntimeConfig> {\n const result = await loadConfig(options);\n if (!result) {\n throw new Error(\"No bos.config.json found\");\n }\n\n return result.runtime;\n}\n\nexport async function buildRuntimePluginsForConfig(\n config: BosConfig,\n baseDir: string,\n env: \"development\" | \"production\",\n): Promise<Record<string, RuntimePluginConfig> | undefined> {\n const plugins = await resolveRuntimePlugins(config.plugins ?? {}, baseDir, env);\n return Object.keys(plugins).length > 0 ? plugins : undefined;\n}\n\nfunction resolveDevelopmentTarget(\n development: string | undefined,\n production: string | undefined,\n baseDir: string,\n): RuntimeTarget {\n const devTarget = resolveRuntimeTarget(development, baseDir);\n if (devTarget.source === \"local\" && (!devTarget.localPath || !existsSync(devTarget.localPath))) {\n return resolveRuntimeTarget(production, baseDir, \"remote\");\n }\n return devTarget;\n}\n\nfunction buildRuntimeConfig(\n config: BosConfig,\n baseDir: string,\n env: \"development\" | \"production\",\n options?: { plugins?: Record<string, RuntimePluginConfig> },\n): RuntimeConfig {\n const uiConfig = config.app.ui;\n const apiConfig = config.app.api;\n const authConfig = config.app.auth;\n const uiRuntime =\n env === \"development\"\n ? resolveDevelopmentTarget(uiConfig.development, uiConfig.production, baseDir)\n : resolveRuntimeTarget(uiConfig.production, baseDir, \"remote\");\n const apiRuntime =\n env === \"development\"\n ? resolveDevelopmentTarget(apiConfig.development, apiConfig.production, baseDir)\n : resolveRuntimeTarget(apiConfig.production, baseDir, \"remote\");\n const authRuntime = authConfig\n ? env === \"development\"\n ? resolveDevelopmentTarget(authConfig.development, authConfig.production, baseDir)\n : resolveRuntimeTarget(authConfig.production, baseDir, \"remote\")\n : undefined;\n\n const hostConfig = config.app.host;\n const hostRuntime =\n env === \"development\"\n ? resolveDevelopmentTarget(hostConfig.development, hostConfig.production, baseDir)\n : resolveRuntimeTarget(hostConfig.production, baseDir, \"remote\");\n\n const hostListeningUrl = resolveDevelopmentHostUrl(hostConfig.development);\n\n return {\n env,\n account: config.account,\n domain: config.domain,\n networkId: getNetworkIdForAccount(config.account),\n repository: config.repository,\n host: {\n name: \"host\",\n url: hostListeningUrl,\n entry: `${hostListeningUrl}/mf-manifest.json`,\n localPath: hostRuntime.localPath,\n port: hostRuntime.port ?? DEFAULT_HOST_PORT,\n secrets: hostConfig.secrets,\n integrity: env === \"production\" ? hostConfig.integrity : undefined,\n source: hostRuntime.source,\n remoteUrl: hostRuntime.source === \"remote\" ? hostRuntime.url : undefined,\n },\n shared: config.shared,\n ui: {\n name: uiConfig.name,\n url: uiRuntime.url,\n entry: uiRuntime.url ? `${uiRuntime.url}/mf-manifest.json` : \"/mf-manifest.json\",\n localPath: uiRuntime.localPath,\n port: uiRuntime.port,\n ssrUrl: uiConfig.ssr,\n ssrIntegrity: env === \"production\" ? uiConfig.ssrIntegrity : undefined,\n integrity: env === \"production\" ? uiConfig.integrity : undefined,\n source: uiRuntime.source,\n },\n api: {\n name: apiConfig.name,\n url: apiRuntime.url,\n entry: apiRuntime.url ? `${apiRuntime.url}/mf-manifest.json` : \"/mf-manifest.json\",\n localPath: apiRuntime.localPath,\n port: apiRuntime.port,\n source: apiRuntime.source,\n proxy: apiConfig.proxy,\n variables: apiConfig.variables,\n secrets: apiConfig.secrets,\n integrity: env === \"production\" ? apiConfig.integrity : undefined,\n },\n auth: authConfig\n ? {\n name: resolvePluginRuntimeName(undefined, authRuntime!.localPath, authConfig.name),\n url: authRuntime!.url,\n entry: authRuntime!.url ? `${authRuntime!.url}/mf-manifest.json` : \"/mf-manifest.json\",\n localPath: authRuntime!.localPath,\n port: authRuntime!.port,\n source: authRuntime!.source,\n proxy: authConfig.proxy,\n variables: authConfig.variables,\n secrets: authConfig.secrets,\n integrity: env === \"production\" ? authConfig.integrity : undefined,\n }\n : undefined,\n plugins:\n options?.plugins && Object.keys(options.plugins).length > 0 ? options.plugins : undefined,\n };\n}\n\nasync function loadConfigFile(configPath: string, baseDir: string): Promise<BosConfigInput> {\n if (configPath.startsWith(\"bos://\")) {\n return fetchBosConfigFromFastKv<BosConfigInput>(configPath);\n }\n\n const resolvedPath = isAbsolute(configPath) ? configPath : resolve(baseDir, configPath);\n return JSON.parse(readFileSync(resolvedPath, \"utf-8\")) as BosConfigInput;\n}\n\nasync function resolveConfigWithExtends(\n configPath: string,\n baseDir: string,\n visited: Set<string>,\n chain: string[],\n): Promise<BosConfigInput> {\n if (visited.has(configPath)) {\n throw new Error(`Circular extends detected: ${[...visited, configPath].join(\" -> \")}`);\n }\n\n const config = await loadConfigFile(configPath, baseDir);\n if (configPath.startsWith(\"bos://\")) {\n chain.push(configPath);\n }\n\n if (!config.extends) {\n return config;\n }\n\n const nextVisited = new Set(visited);\n nextVisited.add(configPath);\n const parentPath = config.extends;\n const parentBaseDir = parentPath.startsWith(\"bos://\")\n ? baseDir\n : isAbsolute(parentPath)\n ? dirname(parentPath)\n : baseDir;\n const parent = await resolveConfigWithExtends(parentPath, parentBaseDir, nextVisited, chain);\n\n return mergeConfigs(parent, config);\n}\n\nfunction mergeConfigs(parent: BosConfigInput, child: BosConfigInput): BosConfigInput {\n const result = mergeValues(parent, child) as BosConfigInput;\n if (child.plugins !== undefined) {\n result.plugins = child.plugins;\n }\n return result;\n}\n\nasync function resolveRuntimePlugins(\n plugins: Record<string, BosConfigInput>,\n baseDir: string,\n env: \"development\" | \"production\",\n prefix: string[] = [],\n): Promise<Record<string, RuntimePluginConfig>> {\n const out: Record<string, RuntimePluginConfig> = {};\n\n for (const [pluginId, pluginInput] of Object.entries(plugins)) {\n const runtimeKey = [...prefix, pluginId].join(\"/\");\n const { config: resolvedConfig, baseDir: pluginBaseDir } = await resolveBosConfigInput(\n pluginInput,\n baseDir,\n new Set(),\n [],\n );\n\n const pluginRuntime = buildRuntimePluginConfig(\n runtimeKey,\n resolvedConfig,\n pluginBaseDir,\n env,\n pluginInput,\n );\n if (\n pluginInput.name &&\n typeof pluginInput.name === \"string\" &&\n !pluginRuntime.name.includes(\"/\")\n ) {\n pluginRuntime.name = pluginInput.name;\n }\n\n const integrity = pluginInput.integrity;\n if (env === \"production\" && integrity) {\n pluginRuntime.integrity = integrity;\n }\n\n if (\n pluginRuntime.source === \"remote\" &&\n pluginRuntime.url &&\n !pluginRuntime.localPath &&\n typeof resolvedConfig.app?.api?.name !== \"string\" &&\n !pluginInput.name\n ) {\n pluginRuntime.name = await resolveRemotePluginRuntimeName(\n pluginRuntime.url,\n pluginRuntime.name,\n );\n }\n\n out[runtimeKey] = pluginRuntime;\n\n if (resolvedConfig.plugins && Object.keys(resolvedConfig.plugins).length > 0) {\n const nested = await resolveRuntimePlugins(resolvedConfig.plugins, pluginBaseDir, env, [\n ...prefix,\n pluginId,\n ]);\n Object.assign(out, nested);\n }\n }\n\n return out;\n}\n\nasync function resolveRemotePluginRuntimeName(baseUrl: string, fallback: string): Promise<string> {\n try {\n const response = await fetch(`${baseUrl.replace(/\\/$/, \"\")}/plugin.manifest.json`);\n if (!response.ok) {\n return fallback;\n }\n\n const manifest = (await response.json()) as {\n plugin?: { name?: unknown };\n };\n\n return typeof manifest.plugin?.name === \"string\" && manifest.plugin.name.length > 0\n ? manifest.plugin.name\n : fallback;\n } catch {\n return fallback;\n }\n}\n\nfunction buildRuntimePluginConfig(\n pluginId: string,\n config: BosConfigInput,\n baseDir: string,\n env: \"development\" | \"production\",\n source: BosConfigInput,\n): RuntimePluginConfig {\n const apiConfig = config.app?.api ?? {};\n const apiDevelopment =\n typeof apiConfig.development === \"string\" ? apiConfig.development : undefined;\n const apiProduction = typeof apiConfig.production === \"string\" ? apiConfig.production : undefined;\n const sourceDevelopment = typeof source.development === \"string\" ? source.development : undefined;\n const sourceProduction = typeof source.production === \"string\" ? source.production : undefined;\n const proxy = typeof apiConfig.proxy === \"string\" ? apiConfig.proxy : undefined;\n const runtimeTarget =\n env === \"development\"\n ? resolveRuntimeTarget(apiDevelopment ?? sourceDevelopment, baseDir)\n : resolveRuntimeTarget(apiProduction ?? sourceProduction, baseDir, \"remote\");\n const apiName = resolvePluginRuntimeName(\n typeof apiConfig.name === \"string\" ? apiConfig.name : undefined,\n runtimeTarget.localPath,\n pluginId,\n );\n\n return {\n name: apiName,\n url: runtimeTarget.url,\n entry: runtimeTarget.url\n ? `${runtimeTarget.url.replace(/\\/$/, \"\")}/mf-manifest.json`\n : \"/mf-manifest.json\",\n source: runtimeTarget.source,\n localPath: runtimeTarget.localPath,\n port: runtimeTarget.port,\n proxy: proxy ?? (typeof source.proxy === \"string\" ? source.proxy : undefined),\n variables: normalizeStringRecord(apiConfig.variables ?? source.variables),\n secrets: normalizeStringArray(apiConfig.secrets ?? source.secrets),\n };\n}\n\nexport function resolvePluginRuntimeName(\n explicitName: string | undefined,\n localPath: string | undefined,\n fallback: string,\n): string {\n if (explicitName) {\n return explicitName;\n }\n\n if (!localPath) {\n return fallback;\n }\n\n try {\n const packageJsonPath = join(localPath, \"package.json\");\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf-8\")) as { name?: unknown };\n if (typeof packageJson.name === \"string\" && packageJson.name.length > 0) {\n return packageJson.name;\n }\n } catch {}\n\n return fallback;\n}\n\nasync function resolveBosConfigInput(\n input: BosConfigInput,\n baseDir: string,\n visited: Set<string>,\n chain: string[],\n): Promise<{ config: BosConfigInput; baseDir: string }> {\n if (input.extends) {\n const parentBaseDir = input.extends.startsWith(\"bos://\")\n ? baseDir\n : isAbsolute(input.extends)\n ? dirname(input.extends)\n : baseDir;\n const config = await resolveConfigWithExtends(input.extends, parentBaseDir, visited, chain);\n return { config: mergeConfigs(config, input), baseDir: parentBaseDir };\n }\n\n return { config: input, baseDir };\n}\n\nfunction mergeValues(parent: unknown, child: unknown): unknown {\n if (Array.isArray(parent) && Array.isArray(child)) {\n return child;\n }\n\n if (isPlainObject(parent) && isPlainObject(child)) {\n const merged: Record<string, unknown> = { ...parent };\n for (const [key, value] of Object.entries(child)) {\n merged[key] = key in merged ? mergeValues(merged[key], value) : value;\n }\n return merged;\n }\n\n return child ?? parent;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction normalizeStringRecord(value: unknown): Record<string, string> | undefined {\n if (!isPlainObject(value)) return undefined;\n const out: Record<string, string> = {};\n for (const [key, raw] of Object.entries(value)) {\n if (typeof raw === \"string\") {\n out[key] = raw;\n }\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const out = value.filter((item): item is string => typeof item === \"string\" && item.length > 0);\n return out.length > 0 ? out : undefined;\n}\n\nfunction resolveRuntimeTarget(\n value: string | undefined,\n baseDir: string,\n defaultSource: \"local\" | \"remote\" = \"remote\",\n): RuntimeTarget {\n if (!value) {\n return { source: defaultSource, url: \"\" };\n }\n\n if (value.startsWith(LOCAL_PREFIX)) {\n const localTarget = value.slice(LOCAL_PREFIX.length).trim();\n if (!localTarget) {\n throw new Error(`Invalid local development target: ${value}`);\n }\n\n const localPath = resolve(baseDir, localTarget);\n if (!existsSync(localPath)) {\n return { source: defaultSource, url: \"\" };\n }\n\n return {\n source: \"local\",\n url: \"\",\n localPath,\n };\n }\n\n return {\n source: defaultSource,\n url: value.replace(/\\/$/, \"\"),\n port: parsePort(value),\n };\n}\n\nexport function isLocalDevelopmentTarget(value: string | undefined): boolean {\n return typeof value === \"string\" && value.startsWith(LOCAL_PREFIX);\n}\n\nexport function resolveLocalDevelopmentPath(\n value: string | undefined,\n baseDir: string,\n): string | null {\n if (!isLocalDevelopmentTarget(value)) {\n return null;\n }\n\n const localTarget = value!.slice(LOCAL_PREFIX.length).trim();\n return localTarget ? resolve(baseDir, localTarget) : null;\n}\n\nexport function resolveDevelopmentHostUrl(value: string | undefined): string {\n if (!value || isLocalDevelopmentTarget(value)) {\n return `http://localhost:${DEFAULT_HOST_PORT}`;\n }\n\n return value.replace(/\\/$/, \"\");\n}\n\nexport function getHostDevelopmentPort(value: string | undefined): number {\n return parsePort(resolveDevelopmentHostUrl(value));\n}\n\nexport function parsePort(url: string): number {\n try {\n const parsed = new URL(url);\n return parsed.port ? parseInt(parsed.port, 10) : parsed.protocol === \"https:\" ? 443 : 80;\n } catch {\n return 3000;\n }\n}\n\nexport type { BosConfig, RuntimeConfig } from \"./types\";\nexport { BosConfigSchema } from \"./types\";\n"],"mappings":";;;;;;;AAOA,MAAM,eAAe;AACrB,MAAM,oBAAoB;AAS1B,IAAI,eAAiC;AACrC,IAAI,cAA6B;AAEjC,SAAgB,mBAAyB;AACvC,gBAAe;AACf,eAAc;;AAGhB,SAAgB,eAAe,KAA6B;CAC1D,IAAI,MAAM,OAAO,QAAQ,KAAK;AAC9B,QAAO,QAAQ,KAAK;EAClB,MAAM,aAAa,KAAK,KAAK,kBAAkB;AAC/C,MAAI,WAAW,WAAW,CACxB,QAAO;AAET,QAAM,QAAQ,IAAI;;AAEpB,QAAO;;AAGT,SAAgB,YAA8B;AAC5C,QAAO;;AAGT,SAAgB,iBAAyB;AACvC,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,8CAA8C;AAEhE,QAAO;;AAaT,eAAsB,WAAW,SAIA;CAC/B,MAAM,aAAa,SAAS,QAAQ,eAAe,SAAS,IAAI;AAChE,KAAI,CAAC,YAAY;AACf,gBAAc,SAAS,OAAO,QAAQ,KAAK;AAC3C,SAAO;;CAGT,MAAM,UAAU,Q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A,gBAAoC,UACrB;AACf,KAAI,CAAC,MACH,QAAO;EAAE,QAAQ;EAAe,KAAK;EAAI;AAG3C,KAAI,MAAM,WAAW,aAAa,EAAE;EAClC,MAAM,cAAc,MAAM,MAAM,EAAoB,CAAC,MAAM;AAC3D,MAAI,CAAC,YACH,OAAM,IAAI,MAAM,qCAAqC,QAAQ;EAG/D,MAAM,YAAY,QAAQ,SAAS,YAAY;AAC/C,MAAI,CAAC,WAAW,UAAU,CACxB,QAAO;GAAE,QAAQ;GAAe,KAAK;GAAI;AAG3C,SAAO;GACL,QAAQ;GACR,KAAK;GACL;GACD;;AAGH,QAAO;EACL,QAAQ;EACR,KAAK,MAAM,QAAQ,OAAO,GAAG;EAC7B,MAAM,UAAU,MAAM;EACvB;;AAGH,SAAgB,yBAAyB,OAAoC;AAC3E,QAAO,OAAO,UAAU,YAAY,MAAM,WAAW,aAAa;;AAGpE,SAAgB,4BACd,OACA,SACe;AACf,KAAI,CAAC,yBAAyB,MAAM,CAClC,QAAO;CAGT,MAAM,cAAc,MAAO,MAAM,EAAoB,CAAC,MAAM;AAC5D,QAAO,cAAc,QAAQ,SAAS,YAAY,GAAG;;AAGvD,SAAgB,0BAA0B,OAAmC;AAC3E,KAAI,CAAC,SAAS,yBAAyB,MAAM,CAC3C,QAAO,oBAAoB;AAG7B,QAAO,MAAM,QAAQ,OAAO,GAAG;;AAGjC,SAAgB,uBAAuB,OAAmC;AACxE,QAAO,UAAU,0BAA0B,MAAM,CAAC;;AAGpD,SAAgB,UAAU,KAAqB;AAC7C,KAAI;EACF,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,SAAO,OAAO,OAAO,SAAS,OAAO,MAAM,GAAG,GAAG,OAAO,aAAa,WAAW,MAAM;SAChF;AACN,SAAO"}
1
+ {"version":3,"file":"config.mjs","names":[],"sources":["../src/config.ts"],"sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, isAbsolute, join, resolve } from \"node:path\";\nimport { fetchBosConfigFromFastKv } from \"./fastkv\";\nimport { getNetworkIdForAccount } from \"./network\";\nimport type { BosConfig, BosConfigInput, RuntimeConfig, RuntimePluginConfig } from \"./types\";\nimport { BosConfigSchema } from \"./types\";\n\nconst LOCAL_PREFIX = \"local:\";\nconst DEFAULT_HOST_PORT = 3000;\n\ninterface RuntimeTarget {\n source: \"local\" | \"remote\";\n url: string;\n localPath?: string;\n port?: number;\n}\n\nlet cachedConfig: BosConfig | null = null;\nlet projectRoot: string | null = null;\n\nexport function clearConfigCache(): void {\n cachedConfig = null;\n projectRoot = null;\n}\n\nexport function findConfigPath(cwd?: string): string | null {\n let dir = cwd ?? process.cwd();\n while (dir !== \"/\") {\n const configPath = join(dir, \"bos.config.json\");\n if (existsSync(configPath)) {\n return configPath;\n }\n dir = dirname(dir);\n }\n return null;\n}\n\nexport function getConfig(): BosConfig | null {\n return cachedConfig;\n}\n\nexport function getProjectRoot(): string {\n if (!projectRoot) {\n throw new Error(\"Config not loaded. Call loadConfig() first.\");\n }\n return projectRoot;\n}\n\nexport interface ConfigResult {\n config: BosConfig;\n runtime: RuntimeConfig;\n source: {\n path: string;\n extended?: string[];\n remote?: boolean;\n };\n}\n\nexport async function loadConfig(options?: {\n cwd?: string;\n path?: string;\n env?: \"development\" | \"production\";\n}): Promise<ConfigResult | null> {\n const configPath = options?.path ?? findConfigPath(options?.cwd);\n if (!configPath) {\n projectRoot = options?.cwd ?? process.cwd();\n return null;\n }\n\n const baseDir = dirname(configPath);\n\n try {\n const extendedChain: string[] = [];\n const parsed = await resolveConfigWithExtends(configPath, baseDir, new Set(), extendedChain);\n const config = BosConfigSchema.parse(parsed);\n\n cachedConfig = config;\n projectRoot = baseDir;\n\n const pluginRuntime = await resolveRuntimePlugins(\n config.plugins ?? {},\n baseDir,\n options?.env ?? \"development\",\n );\n const runtime = buildRuntimeConfig(config, baseDir, options?.env ?? \"development\", {\n plugins: pluginRuntime,\n });\n\n return {\n config,\n runtime,\n source: {\n path: configPath,\n extended: extendedChain.length > 0 ? extendedChain : undefined,\n remote: extendedChain.some((entry) => entry.startsWith(\"bos://\")),\n },\n };\n } catch (error) {\n throw new Error(`Failed to load config from ${configPath}: ${error}`);\n }\n}\n\nexport async function loadBosConfig(options?: {\n cwd?: string;\n path?: string;\n env?: \"development\" | \"production\";\n}): Promise<RuntimeConfig> {\n const result = await loadConfig(options);\n if (!result) {\n throw new Error(\"No bos.config.json found\");\n }\n\n return result.runtime;\n}\n\nexport async function buildRuntimePluginsForConfig(\n config: BosConfig,\n baseDir: string,\n env: \"development\" | \"production\",\n): Promise<Record<string, RuntimePluginConfig> | undefined> {\n const plugins = await resolveRuntimePlugins(config.plugins ?? {}, baseDir, env);\n return Object.keys(plugins).length > 0 ? plugins : undefined;\n}\n\nfunction resolveDevelopmentTarget(\n development: string | undefined,\n production: string | undefined,\n baseDir: string,\n): RuntimeTarget {\n const devTarget = resolveRuntimeTarget(development, baseDir);\n if (devTarget.source === \"local\" && (!devTarget.localPath || !existsSync(devTarget.localPath))) {\n return resolveRuntimeTarget(production, baseDir, \"remote\");\n }\n return devTarget;\n}\n\nfunction buildRuntimeConfig(\n config: BosConfig,\n baseDir: string,\n env: \"development\" | \"production\",\n options?: { plugins?: Record<string, RuntimePluginConfig> },\n): RuntimeConfig {\n const uiConfig = config.app.ui;\n const apiConfig = config.app.api;\n const authConfig = config.app.auth;\n const uiRuntime =\n env === \"development\"\n ? resolveDevelopmentTarget(uiConfig.development, uiConfig.production, baseDir)\n : resolveRuntimeTarget(uiConfig.production, baseDir, \"remote\");\n const apiRuntime =\n env === \"development\"\n ? resolveDevelopmentTarget(apiConfig.development, apiConfig.production, baseDir)\n : resolveRuntimeTarget(apiConfig.production, baseDir, \"remote\");\n const authRuntime = authConfig\n ? env === \"development\"\n ? resolveDevelopmentTarget(authConfig.development, authConfig.production, baseDir)\n : resolveRuntimeTarget(authConfig.production, baseDir, \"remote\")\n : undefined;\n\n const hostConfig = config.app.host;\n const hostRuntime =\n env === \"development\"\n ? resolveDevelopmentTarget(hostConfig.development, hostConfig.production, baseDir)\n : resolveRuntimeTarget(hostConfig.production, baseDir, \"remote\");\n\n const hostListeningUrl = resolveDevelopmentHostUrl(hostConfig.development);\n\n return {\n env,\n account: config.account,\n domain: config.domain,\n networkId: getNetworkIdForAccount(config.account),\n repository: config.repository,\n host: {\n name: \"host\",\n url: hostListeningUrl,\n entry: `${hostListeningUrl}/mf-manifest.json`,\n localPath: hostRuntime.localPath,\n port: hostRuntime.port ?? DEFAULT_HOST_PORT,\n secrets: hostConfig.secrets,\n integrity: env === \"production\" ? hostConfig.integrity : undefined,\n source: hostRuntime.source,\n remoteUrl: hostRuntime.source === \"remote\" ? hostRuntime.url : undefined,\n },\n shared: config.shared,\n ui: {\n name: uiConfig.name,\n url: uiRuntime.url,\n entry: uiRuntime.url ? `${uiRuntime.url}/mf-manifest.json` : \"/mf-manifest.json\",\n localPath: uiRuntime.localPath,\n port: uiRuntime.port,\n ssrUrl: uiConfig.ssr,\n ssrIntegrity: env === \"production\" ? uiConfig.ssrIntegrity : undefined,\n integrity: env === \"production\" ? uiConfig.integrity : undefined,\n source: uiRuntime.source,\n },\n api: {\n name: apiConfig.name,\n url: apiRuntime.url,\n entry: apiRuntime.url ? `${apiRuntime.url}/mf-manifest.json` : \"/mf-manifest.json\",\n localPath: apiRuntime.localPath,\n port: apiRuntime.port,\n source: apiRuntime.source,\n proxy: apiConfig.proxy,\n variables: apiConfig.variables,\n secrets: apiConfig.secrets,\n integrity: env === \"production\" ? apiConfig.integrity : undefined,\n },\n auth: authConfig\n ? {\n name: resolvePluginRuntimeName(undefined, authRuntime!.localPath, authConfig.name),\n url: authRuntime!.url,\n entry: authRuntime!.url ? `${authRuntime!.url}/mf-manifest.json` : \"/mf-manifest.json\",\n localPath: authRuntime!.localPath,\n port: authRuntime!.port,\n source: authRuntime!.source,\n proxy: authConfig.proxy,\n variables: authConfig.variables,\n secrets: authConfig.secrets,\n integrity: env === \"production\" ? authConfig.integrity : undefined,\n }\n : undefined,\n plugins:\n options?.plugins && Object.keys(options.plugins).length > 0 ? options.plugins : undefined,\n };\n}\n\nasync function loadConfigFile(configPath: string, baseDir: string): Promise<BosConfigInput> {\n if (configPath.startsWith(\"bos://\")) {\n return fetchBosConfigFromFastKv<BosConfigInput>(configPath);\n }\n\n const resolvedPath = isAbsolute(configPath) ? configPath : resolve(baseDir, configPath);\n return JSON.parse(readFileSync(resolvedPath, \"utf-8\")) as BosConfigInput;\n}\n\nasync function resolveConfigWithExtends(\n configPath: string,\n baseDir: string,\n visited: Set<string>,\n chain: string[],\n): Promise<BosConfigInput> {\n if (visited.has(configPath)) {\n throw new Error(`Circular extends detected: ${[...visited, configPath].join(\" -> \")}`);\n }\n\n const config = await loadConfigFile(configPath, baseDir);\n if (configPath.startsWith(\"bos://\")) {\n chain.push(configPath);\n }\n\n if (!config.extends) {\n return config;\n }\n\n const nextVisited = new Set(visited);\n nextVisited.add(configPath);\n const parentPath = config.extends;\n const parentBaseDir = parentPath.startsWith(\"bos://\")\n ? baseDir\n : isAbsolute(parentPath)\n ? dirname(parentPath)\n : baseDir;\n const parent = await resolveConfigWithExtends(parentPath, parentBaseDir, nextVisited, chain);\n\n return mergeConfigs(parent, config);\n}\n\nfunction mergeConfigs(parent: BosConfigInput, child: BosConfigInput): BosConfigInput {\n const result = mergeValues(parent, child) as BosConfigInput;\n if (child.plugins !== undefined) {\n result.plugins = child.plugins;\n }\n return result;\n}\n\nasync function resolveRuntimePlugins(\n plugins: Record<string, BosConfigInput>,\n baseDir: string,\n env: \"development\" | \"production\",\n prefix: string[] = [],\n): Promise<Record<string, RuntimePluginConfig>> {\n const out: Record<string, RuntimePluginConfig> = {};\n\n for (const [pluginId, pluginInput] of Object.entries(plugins)) {\n const runtimeKey = [...prefix, pluginId].join(\"/\");\n const { config: resolvedConfig, baseDir: pluginBaseDir } = await resolveBosConfigInput(\n pluginInput,\n baseDir,\n new Set(),\n [],\n );\n\n const pluginRuntime = buildRuntimePluginConfig(\n runtimeKey,\n resolvedConfig,\n pluginBaseDir,\n env,\n pluginInput,\n );\n if (\n pluginInput.name &&\n typeof pluginInput.name === \"string\" &&\n !pluginRuntime.name.includes(\"/\")\n ) {\n pluginRuntime.name = pluginInput.name;\n }\n\n const integrity = pluginInput.integrity;\n if (env === \"production\" && integrity) {\n pluginRuntime.integrity = integrity;\n }\n\n if (\n pluginRuntime.source === \"remote\" &&\n pluginRuntime.url &&\n !pluginRuntime.localPath &&\n typeof resolvedConfig.app?.api?.name !== \"string\" &&\n !pluginInput.name\n ) {\n pluginRuntime.name = await resolveRemotePluginRuntimeName(\n pluginRuntime.url,\n pluginRuntime.name,\n );\n }\n\n out[runtimeKey] = pluginRuntime;\n\n if (resolvedConfig.plugins && Object.keys(resolvedConfig.plugins).length > 0) {\n const nested = await resolveRuntimePlugins(resolvedConfig.plugins, pluginBaseDir, env, [\n ...prefix,\n pluginId,\n ]);\n Object.assign(out, nested);\n }\n }\n\n return out;\n}\n\nasync function resolveRemotePluginRuntimeName(baseUrl: string, fallback: string): Promise<string> {\n try {\n const response = await fetch(`${baseUrl.replace(/\\/$/, \"\")}/plugin.manifest.json`);\n if (!response.ok) {\n return fallback;\n }\n\n const manifest = (await response.json()) as {\n plugin?: { name?: unknown };\n };\n\n return typeof manifest.plugin?.name === \"string\" && manifest.plugin.name.length > 0\n ? manifest.plugin.name\n : fallback;\n } catch {\n return fallback;\n }\n}\n\nfunction buildRuntimePluginConfig(\n pluginId: string,\n config: BosConfigInput,\n baseDir: string,\n env: \"development\" | \"production\",\n source: BosConfigInput,\n): RuntimePluginConfig {\n const apiConfig = config.app?.api ?? {};\n const apiDevelopment =\n typeof apiConfig.development === \"string\" ? apiConfig.development : undefined;\n const apiProduction = typeof apiConfig.production === \"string\" ? apiConfig.production : undefined;\n const sourceDevelopment = typeof source.development === \"string\" ? source.development : undefined;\n const sourceProduction = typeof source.production === \"string\" ? source.production : undefined;\n const proxy = typeof apiConfig.proxy === \"string\" ? apiConfig.proxy : undefined;\n const development = apiDevelopment ?? sourceDevelopment;\n const production = apiProduction ?? sourceProduction;\n const runtimeTarget =\n env === \"development\"\n ? resolveDevelopmentTarget(development, production, baseDir)\n : resolveRuntimeTarget(production, baseDir, \"remote\");\n const apiName = resolvePluginRuntimeName(\n typeof apiConfig.name === \"string\" ? apiConfig.name : undefined,\n runtimeTarget.localPath,\n pluginId,\n );\n\n return {\n name: apiName,\n url: runtimeTarget.url,\n entry: runtimeTarget.url\n ? `${runtimeTarget.url.replace(/\\/$/, \"\")}/mf-manifest.json`\n : \"/mf-manifest.json\",\n source: runtimeTarget.source,\n localPath: runtimeTarget.localPath,\n port: runtimeTarget.port,\n proxy: proxy ?? (typeof source.proxy === \"string\" ? source.proxy : undefined),\n variables: normalizeStringRecord(apiConfig.variables ?? source.variables),\n secrets: normalizeStringArray(apiConfig.secrets ?? source.secrets),\n };\n}\n\nexport function resolvePluginRuntimeName(\n explicitName: string | undefined,\n localPath: string | undefined,\n fallback: string,\n): string {\n if (explicitName) {\n return explicitName;\n }\n\n if (!localPath) {\n return fallback;\n }\n\n try {\n const packageJsonPath = join(localPath, \"package.json\");\n const packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf-8\")) as { name?: unknown };\n if (typeof packageJson.name === \"string\" && packageJson.name.length > 0) {\n return packageJson.name;\n }\n } catch {}\n\n return fallback;\n}\n\nasync function resolveBosConfigInput(\n input: BosConfigInput,\n baseDir: string,\n visited: Set<string>,\n chain: string[],\n): Promise<{ config: BosConfigInput; baseDir: string }> {\n if (input.extends) {\n const parentBaseDir = input.extends.startsWith(\"bos://\")\n ? baseDir\n : isAbsolute(input.extends)\n ? dirname(input.extends)\n : baseDir;\n const config = await resolveConfigWithExtends(input.extends, parentBaseDir, visited, chain);\n return { config: mergeConfigs(config, input), baseDir: parentBaseDir };\n }\n\n return { config: input, baseDir };\n}\n\nfunction mergeValues(parent: unknown, child: unknown): unknown {\n if (Array.isArray(parent) && Array.isArray(child)) {\n return child;\n }\n\n if (isPlainObject(parent) && isPlainObject(child)) {\n const merged: Record<string, unknown> = { ...parent };\n for (const [key, value] of Object.entries(child)) {\n merged[key] = key in merged ? mergeValues(merged[key], value) : value;\n }\n return merged;\n }\n\n return child ?? parent;\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nfunction normalizeStringRecord(value: unknown): Record<string, string> | undefined {\n if (!isPlainObject(value)) return undefined;\n const out: Record<string, string> = {};\n for (const [key, raw] of Object.entries(value)) {\n if (typeof raw === \"string\") {\n out[key] = raw;\n }\n }\n return Object.keys(out).length > 0 ? out : undefined;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n if (!Array.isArray(value)) return undefined;\n const out = value.filter((item): item is string => typeof item === \"string\" && item.length > 0);\n return out.length > 0 ? out : undefined;\n}\n\nfunction resolveRuntimeTarget(\n value: string | undefined,\n baseDir: string,\n defaultSource: \"local\" | \"remote\" = \"remote\",\n): RuntimeTarget {\n if (!value) {\n return { source: defaultSource, url: \"\" };\n }\n\n if (value.startsWith(LOCAL_PREFIX)) {\n const localTarget = value.slice(LOCAL_PREFIX.length).trim();\n if (!localTarget) {\n throw new Error(`Invalid local development target: ${value}`);\n }\n\n const localPath = resolve(baseDir, localTarget);\n if (!existsSync(localPath)) {\n return { source: \"local\", url: \"\" };\n }\n\n return {\n source: \"local\",\n url: \"\",\n localPath,\n };\n }\n\n return {\n source: defaultSource,\n url: value.replace(/\\/$/, \"\"),\n port: parsePort(value),\n };\n}\n\nexport function isLocalDevelopmentTarget(value: string | undefined): boolean {\n return typeof value === \"string\" && value.startsWith(LOCAL_PREFIX);\n}\n\nexport function resolveLocalDevelopmentPath(\n value: string | undefined,\n baseDir: string,\n): string | null {\n if (!isLocalDevelopmentTarget(value)) {\n return null;\n }\n\n const localTarget = value!.slice(LOCAL_PREFIX.length).trim();\n return localTarget ? resolve(baseDir, localTarget) : null;\n}\n\nexport function resolveDevelopmentHostUrl(value: string | undefined): string {\n if (!value || isLocalDevelopmentTarget(value)) {\n return `http://localhost:${DEFAULT_HOST_PORT}`;\n }\n\n return value.replace(/\\/$/, \"\");\n}\n\nexport function getHostDevelopmentPort(value: string | undefined): number {\n return parsePort(resolveDevelopmentHostUrl(value));\n}\n\nexport function parsePort(url: string): number {\n try {\n const parsed = new URL(url);\n return parsed.port ? parseInt(parsed.port, 10) : parsed.protocol === \"https:\" ? 443 : 80;\n } catch {\n return 3000;\n }\n}\n\nexport type { BosConfig, RuntimeConfig } from \"./types\";\nexport { BosConfigSchema } from \"./types\";\n"],"mappings":";;;;;;;AAOA,MAAM,eAAe;AACrB,MAAM,oBAAoB;AAS1B,IAAI,eAAiC;AACrC,IAAI,cAA6B;AAEjC,SAAgB,mBAAyB;AACvC,gBAAe;AACf,eAAc;;AAGhB,SAAgB,eAAe,KAA6B;CAC1D,IAAI,MAAM,OAAO,QAAQ,KAAK;AAC9B,QAAO,QAAQ,KAAK;EAClB,MAAM,aAAa,KAAK,KAAK,kBAAkB;AAC/C,MAAI,WAAW,WAAW,CACxB,QAAO;AAET,QAAM,QAAQ,IAAI;;AAEpB,QAAO;;AAGT,SAAgB,YAA8B;AAC5C,QAAO;;AAGT,SAAgB,iBAAyB;AACvC,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,8CAA8C;AAEhE,QAAO;;AAaT,eAAsB,WAAW,SAIA;CAC/B,MAAM,aAAa,SAAS,QAAQ,eAAe,SAAS,IAAI;AAChE,KAAI,CAAC,YAAY;AACf,gBAAc,SAAS,OAAO,QAAQ,KAAK;AAC3C,SAAO;;CAGT,MAAM,UAAU,QAAQ,WAAW;AAEnC,KAAI;EACF,MAAM,gBAA0B,EAAE;EAClC,MAAM,SAAS,MAAM,yBAAyB,YAAY,yBAAS,IAAI,KAAK,EAAE,cAAc;EAC5F,MAAM,SAAS,gBAAgB,MAAM,OAAO;AAE5C,iBAAe;AACf,gBAAc;EAEd,MAAM,gBAAgB,MAAM,sBAC1B,OAAO,WAAW,EAA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MAAM,qCAAqC,QAAQ;EAG/D,MAAM,YAAY,QAAQ,SAAS,YAAY;AAC/C,MAAI,CAAC,WAAW,UAAU,CACxB,QAAO;GAAE,QAAQ;GAAS,KAAK;GAAI;AAGrC,SAAO;GACL,QAAQ;GACR,KAAK;GACL;GACD;;AAGH,QAAO;EACL,QAAQ;EACR,KAAK,MAAM,QAAQ,OAAO,GAAG;EAC7B,MAAM,UAAU,MAAM;EACvB;;AAGH,SAAgB,yBAAyB,OAAoC;AAC3E,QAAO,OAAO,UAAU,YAAY,MAAM,WAAW,aAAa;;AAGpE,SAAgB,4BACd,OACA,SACe;AACf,KAAI,CAAC,yBAAyB,MAAM,CAClC,QAAO;CAGT,MAAM,cAAc,MAAO,MAAM,EAAoB,CAAC,MAAM;AAC5D,QAAO,cAAc,QAAQ,SAAS,YAAY,GAAG;;AAGvD,SAAgB,0BAA0B,OAAmC;AAC3E,KAAI,CAAC,SAAS,yBAAyB,MAAM,CAC3C,QAAO,oBAAoB;AAG7B,QAAO,MAAM,QAAQ,OAAO,GAAG;;AAGjC,SAAgB,uBAAuB,OAAmC;AACxE,QAAO,UAAU,0BAA0B,MAAM,CAAC;;AAGpD,SAAgB,UAAU,KAAqB;AAC7C,KAAI;EACF,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,SAAO,OAAO,OAAO,SAAS,OAAO,MAAM,GAAG,GAAG,OAAO,aAAa,WAAW,MAAM;SAChF;AACN,SAAO"}
@@ -22,7 +22,7 @@ function loadManifestNormalizationSpec(sourceRootDir) {
22
22
  for (const packageName of FRAMEWORK_PACKAGES) {
23
23
  const sourcePackagePath = (0, node_path.join)(sourceRootDir, "packages", packageName, "package.json");
24
24
  const localPackagePath = (0, node_path.join)(__dirname, "..", "..", packageName, "package.json");
25
- const packageVersion = (0, node_fs.existsSync)(sourcePackagePath) ? readJson(sourcePackagePath).version : (0, node_fs.existsSync)(localPackagePath) ? readJson(localPackagePath).version : extractExactVersion(rootCatalog[packageName]);
25
+ const packageVersion = (0, node_fs.existsSync)(localPackagePath) ? readJson(localPackagePath).version : (0, node_fs.existsSync)(sourcePackagePath) ? readJson(sourcePackagePath).version : extractExactVersion(rootCatalog[packageName]);
26
26
  if (!packageVersion) throw new Error(`Could not resolve version for ${packageName}`);
27
27
  frameworkVersions[packageName] = packageVersion;
28
28
  rootCatalog[packageName] = `^${packageVersion}`;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest-normalizer.cjs","names":[],"sources":["../../src/internal/manifest-normalizer.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { glob } from \"glob\";\n\nconst FRAMEWORK_PACKAGES = [\"every-plugin\", \"everything-dev\"] as const;\n\ntype PackageJson = Record<string, unknown>;\n\ntype NormalizationSpec = {\n rootCatalog: Record<string, string>;\n frameworkVersions: Record<string, string>;\n};\n\ntype NormalizeManifestOptions = {\n resolveCatalogRefs: boolean;\n excludeFrameworkWorkspaces?: boolean;\n removeWorkspaceDeps?: string[];\n removeWorkspaces?: boolean;\n removePublishScripts?: boolean;\n};\n\nexport type NormalizeTreeOptions = NormalizeManifestOptions & {\n sourceRootDir: string;\n targetDir: string;\n};\n\nfunction readJson<T>(filePath: string): T {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as T;\n}\n\nfunction extractExactVersion(input: string | undefined): string | null {\n if (!input) return null;\n const match = input.match(/\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?/);\n return match ? match[0] : null;\n}\n\nfunction writeJson(filePath: string, value: PackageJson) {\n writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {\n const rootPackage = readJson<PackageJson>(join(sourceRootDir, \"package.json\"));\n const rootCatalog = {\n ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??\n {}) as Record<string, string>),\n };\n const frameworkVersions: Record<string, string> = {};\n\n for (const packageName of FRAMEWORK_PACKAGES) {\n const sourcePackagePath = join(sourceRootDir, \"packages\", packageName, \"package.json\");\n const localPackagePath = join(import.meta.dirname, \"..\", \"..\", packageName, \"package.json\");\n const packageVersion = existsSync(sourcePackagePath)\n ? readJson<{ version: string }>(sourcePackagePath).version\n : existsSync(localPackagePath)\n ? readJson<{ version: string }>(localPackagePath).version\n : extractExactVersion(rootCatalog[packageName]);\n\n if (!packageVersion) {\n throw new Error(`Could not resolve version for ${packageName}`);\n }\n\n frameworkVersions[packageName] = packageVersion;\n rootCatalog[packageName] = `^${packageVersion}`;\n }\n\n return { rootCatalog, frameworkVersions };\n}\n\nfunction normalizeDependencyMap(\n map: Record<string, string>,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const [name, version] of Object.entries(map)) {\n if (version === \"workspace:*\") {\n const frameworkVersion = spec.frameworkVersions[name];\n if (frameworkVersion) {\n map[name] = `^${frameworkVersion}`;\n modified = true;\n continue;\n }\n\n if (options.removeWorkspaceDeps?.includes(name)) {\n delete map[name];\n modified = true;\n }\n continue;\n }\n\n if (options.resolveCatalogRefs && version.startsWith(\"catalog:\")) {\n const resolved = spec.rootCatalog[name];\n if (resolved) {\n map[name] = resolved;\n modified = true;\n }\n }\n }\n\n return modified;\n}\n\nexport function normalizePackageManifest(\n pkg: PackageJson,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const depField of [\"dependencies\", \"devDependencies\", \"peerDependencies\"]) {\n const deps = pkg[depField];\n if (!deps || typeof deps !== \"object\") continue;\n if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {\n modified = true;\n }\n }\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const workspaces = pkg.workspaces as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {\n const nextPackages = workspaces.packages.filter(\n (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),\n );\n if (nextPackages.length !== workspaces.packages.length) {\n workspaces.packages = nextPackages;\n modified = true;\n }\n }\n\n if (workspaces.catalog && typeof workspaces.catalog === \"object\") {\n for (const [name, version] of Object.entries(workspaces.catalog)) {\n const resolved = spec.rootCatalog[name];\n if (resolved && resolved !== version) {\n workspaces.catalog[name] = resolved;\n modified = true;\n continue;\n }\n\n if (version === \"workspace:*\" && spec.frameworkVersions[name]) {\n workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;\n modified = true;\n }\n }\n }\n }\n\n if (options.removeWorkspaces && \"workspaces\" in pkg) {\n delete pkg.workspaces;\n modified = true;\n }\n\n if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n let scriptsModified = false;\n for (const key of [\"prepublishOnly\", \"prepack\", \"prepare\", \"postpack\"]) {\n if (key in scripts) {\n delete scripts[key];\n scriptsModified = true;\n }\n }\n if (scriptsModified) {\n modified = true;\n if (Object.keys(scripts).length === 0) {\n delete pkg.scripts;\n }\n }\n }\n\n return modified;\n}\n\nexport async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {\n const spec = loadManifestNormalizationSpec(opts.sourceRootDir);\n const files = await glob(\"**/package.json\", {\n cwd: opts.targetDir,\n nodir: true,\n dot: false,\n absolute: true,\n ignore: [\"**/node_modules/**\"],\n });\n\n const updatedFiles: string[] = [];\n\n for (const filePath of files) {\n const pkg = readJson<PackageJson>(filePath);\n if (normalizePackageManifest(pkg, spec, opts)) {\n writeJson(filePath, pkg);\n updatedFiles.push(filePath);\n }\n }\n\n return updatedFiles;\n}\n\nfunction shouldCopyPackageFile(sourceDir: string, filePath: string) {\n const relPath = relative(sourceDir, filePath);\n if (!relPath) return true;\n const segments = relPath.split(sep);\n return !segments.includes(\"node_modules\") && !segments.includes(\"tests\");\n}\n\nfunction stripDevelopmentExports(pkg: PackageJson) {\n const exports = pkg.exports;\n if (!exports || typeof exports !== \"object\") return;\n\n for (const key of Object.keys(exports as Record<string, unknown>)) {\n const entry = (exports as Record<string, unknown>)[key];\n if (entry && typeof entry === \"object\") {\n delete (entry as Record<string, unknown>).development;\n }\n }\n}\n\nexport function stageReleasePackage(opts: {\n repoRoot: string;\n packageName: string;\n outDir: string;\n}) {\n const sourceDir = join(opts.repoRoot, \"packages\", opts.packageName);\n\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(dirname(opts.outDir), { recursive: true });\n cpSync(sourceDir, opts.outDir, {\n recursive: true,\n filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),\n });\n rmSync(join(opts.outDir, \"tests\"), { recursive: true, force: true });\n\n const packageJsonPath = join(opts.outDir, \"package.json\");\n const spec = loadManifestNormalizationSpec(opts.repoRoot);\n const pkg = readJson<PackageJson>(packageJsonPath);\n\n normalizePackageManifest(pkg, spec, {\n resolveCatalogRefs: true,\n removeWorkspaces: true,\n removePublishScripts: true,\n });\n\n stripDevelopmentExports(pkg);\n\n writeJson(packageJsonPath, pkg);\n}\n\nexport function stageReleasePackages(opts: {\n repoRoot: string;\n outDir: string;\n packageNames?: string[];\n}) {\n const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(opts.outDir, { recursive: true });\n\n for (const packageName of packageNames) {\n stageReleasePackage({\n repoRoot: opts.repoRoot,\n packageName,\n outDir: join(opts.outDir, packageName),\n });\n }\n}\n"],"mappings":";;;;;;AAIA,MAAM,qBAAqB,CAAC,gBAAgB,iBAAiB;AAsB7D,SAAS,SAAY,UAAqB;AACxC,QAAO,KAAK,gCAAmB,UAAU,QAAQ,CAAC;;AAGpD,SAAS,oBAAoB,OAA0C;AACrE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,oCAAoC;AAC9D,QAAO,QAAQ,MAAM,KAAK;;AAG5B,SAAS,UAAU,UAAkB,OAAoB;AAC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,OAAO;EACP,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,qBAAqB;EAC/B,CAAC;CAEF,MAAM,eAAyB,EAAE;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,MAAM,SAAsB,SAAS;AAC3C,MAAI,yBAAyB,KAAK,MAAM,KAAK,EAAE;AAC7C,aAAU,UAAU,IAAI;AACxB,gBAAa,KAAK,SAAS;;;AAI/B,QAAO"}
1
+ {"version":3,"file":"manifest-normalizer.cjs","names":[],"sources":["../../src/internal/manifest-normalizer.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { glob } from \"glob\";\n\nconst FRAMEWORK_PACKAGES = [\"every-plugin\", \"everything-dev\"] as const;\n\ntype PackageJson = Record<string, unknown>;\n\ntype NormalizationSpec = {\n rootCatalog: Record<string, string>;\n frameworkVersions: Record<string, string>;\n};\n\ntype NormalizeManifestOptions = {\n resolveCatalogRefs: boolean;\n excludeFrameworkWorkspaces?: boolean;\n removeWorkspaceDeps?: string[];\n removeWorkspaces?: boolean;\n removePublishScripts?: boolean;\n};\n\nexport type NormalizeTreeOptions = NormalizeManifestOptions & {\n sourceRootDir: string;\n targetDir: string;\n};\n\nfunction readJson<T>(filePath: string): T {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as T;\n}\n\nfunction extractExactVersion(input: string | undefined): string | null {\n if (!input) return null;\n const match = input.match(/\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?/);\n return match ? match[0] : null;\n}\n\nfunction writeJson(filePath: string, value: PackageJson) {\n writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {\n const rootPackage = readJson<PackageJson>(join(sourceRootDir, \"package.json\"));\n const rootCatalog = {\n ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??\n {}) as Record<string, string>),\n };\n const frameworkVersions: Record<string, string> = {};\n\n for (const packageName of FRAMEWORK_PACKAGES) {\n const sourcePackagePath = join(sourceRootDir, \"packages\", packageName, \"package.json\");\n const localPackagePath = join(import.meta.dirname, \"..\", \"..\", packageName, \"package.json\");\n const packageVersion = existsSync(localPackagePath)\n ? readJson<{ version: string }>(localPackagePath).version\n : existsSync(sourcePackagePath)\n ? readJson<{ version: string }>(sourcePackagePath).version\n : extractExactVersion(rootCatalog[packageName]);\n\n if (!packageVersion) {\n throw new Error(`Could not resolve version for ${packageName}`);\n }\n\n frameworkVersions[packageName] = packageVersion;\n rootCatalog[packageName] = `^${packageVersion}`;\n }\n\n return { rootCatalog, frameworkVersions };\n}\n\nfunction normalizeDependencyMap(\n map: Record<string, string>,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const [name, version] of Object.entries(map)) {\n if (version === \"workspace:*\") {\n const frameworkVersion = spec.frameworkVersions[name];\n if (frameworkVersion) {\n map[name] = `^${frameworkVersion}`;\n modified = true;\n continue;\n }\n\n if (options.removeWorkspaceDeps?.includes(name)) {\n delete map[name];\n modified = true;\n }\n continue;\n }\n\n if (options.resolveCatalogRefs && version.startsWith(\"catalog:\")) {\n const resolved = spec.rootCatalog[name];\n if (resolved) {\n map[name] = resolved;\n modified = true;\n }\n }\n }\n\n return modified;\n}\n\nexport function normalizePackageManifest(\n pkg: PackageJson,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const depField of [\"dependencies\", \"devDependencies\", \"peerDependencies\"]) {\n const deps = pkg[depField];\n if (!deps || typeof deps !== \"object\") continue;\n if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {\n modified = true;\n }\n }\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const workspaces = pkg.workspaces as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {\n const nextPackages = workspaces.packages.filter(\n (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),\n );\n if (nextPackages.length !== workspaces.packages.length) {\n workspaces.packages = nextPackages;\n modified = true;\n }\n }\n\n if (workspaces.catalog && typeof workspaces.catalog === \"object\") {\n for (const [name, version] of Object.entries(workspaces.catalog)) {\n const resolved = spec.rootCatalog[name];\n if (resolved && resolved !== version) {\n workspaces.catalog[name] = resolved;\n modified = true;\n continue;\n }\n\n if (version === \"workspace:*\" && spec.frameworkVersions[name]) {\n workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;\n modified = true;\n }\n }\n }\n }\n\n if (options.removeWorkspaces && \"workspaces\" in pkg) {\n delete pkg.workspaces;\n modified = true;\n }\n\n if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n let scriptsModified = false;\n for (const key of [\"prepublishOnly\", \"prepack\", \"prepare\", \"postpack\"]) {\n if (key in scripts) {\n delete scripts[key];\n scriptsModified = true;\n }\n }\n if (scriptsModified) {\n modified = true;\n if (Object.keys(scripts).length === 0) {\n delete pkg.scripts;\n }\n }\n }\n\n return modified;\n}\n\nexport async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {\n const spec = loadManifestNormalizationSpec(opts.sourceRootDir);\n const files = await glob(\"**/package.json\", {\n cwd: opts.targetDir,\n nodir: true,\n dot: false,\n absolute: true,\n ignore: [\"**/node_modules/**\"],\n });\n\n const updatedFiles: string[] = [];\n\n for (const filePath of files) {\n const pkg = readJson<PackageJson>(filePath);\n if (normalizePackageManifest(pkg, spec, opts)) {\n writeJson(filePath, pkg);\n updatedFiles.push(filePath);\n }\n }\n\n return updatedFiles;\n}\n\nfunction shouldCopyPackageFile(sourceDir: string, filePath: string) {\n const relPath = relative(sourceDir, filePath);\n if (!relPath) return true;\n const segments = relPath.split(sep);\n return !segments.includes(\"node_modules\") && !segments.includes(\"tests\");\n}\n\nfunction stripDevelopmentExports(pkg: PackageJson) {\n const exports = pkg.exports;\n if (!exports || typeof exports !== \"object\") return;\n\n for (const key of Object.keys(exports as Record<string, unknown>)) {\n const entry = (exports as Record<string, unknown>)[key];\n if (entry && typeof entry === \"object\") {\n delete (entry as Record<string, unknown>).development;\n }\n }\n}\n\nexport function stageReleasePackage(opts: {\n repoRoot: string;\n packageName: string;\n outDir: string;\n}) {\n const sourceDir = join(opts.repoRoot, \"packages\", opts.packageName);\n\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(dirname(opts.outDir), { recursive: true });\n cpSync(sourceDir, opts.outDir, {\n recursive: true,\n filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),\n });\n rmSync(join(opts.outDir, \"tests\"), { recursive: true, force: true });\n\n const packageJsonPath = join(opts.outDir, \"package.json\");\n const spec = loadManifestNormalizationSpec(opts.repoRoot);\n const pkg = readJson<PackageJson>(packageJsonPath);\n\n normalizePackageManifest(pkg, spec, {\n resolveCatalogRefs: true,\n removeWorkspaces: true,\n removePublishScripts: true,\n });\n\n stripDevelopmentExports(pkg);\n\n writeJson(packageJsonPath, pkg);\n}\n\nexport function stageReleasePackages(opts: {\n repoRoot: string;\n outDir: string;\n packageNames?: string[];\n}) {\n const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(opts.outDir, { recursive: true });\n\n for (const packageName of packageNames) {\n stageReleasePackage({\n repoRoot: opts.repoRoot,\n packageName,\n outDir: join(opts.outDir, packageName),\n });\n }\n}\n"],"mappings":";;;;;;AAIA,MAAM,qBAAqB,CAAC,gBAAgB,iBAAiB;AAsB7D,SAAS,SAAY,UAAqB;AACxC,QAAO,KAAK,gCAAmB,UAAU,QAAQ,CAAC;;AAGpD,SAAS,oBAAoB,OAA0C;AACrE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,oCAAoC;AAC9D,QAAO,QAAQ,MAAM,KAAK;;AAG5B,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BAAmB;EAC1C,KAAK,KAAK;EACV,OAAO;EACP,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,qBAAqB;EAC/B,CAAC;CAEF,MAAM,eAAyB,EAAE;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,MAAM,SAAsB,SAAS;AAC3C,MAAI,yBAAyB,KAAK,MAAM,KAAK,EAAE;AAC7C,aAAU,UAAU,IAAI;AACxB,gBAAa,KAAK,SAAS;;;AAI/B,QAAO"}
@@ -21,7 +21,7 @@ function loadManifestNormalizationSpec(sourceRootDir) {
21
21
  for (const packageName of FRAMEWORK_PACKAGES) {
22
22
  const sourcePackagePath = join(sourceRootDir, "packages", packageName, "package.json");
23
23
  const localPackagePath = join(import.meta.dirname, "..", "..", packageName, "package.json");
24
- const packageVersion = existsSync(sourcePackagePath) ? readJson(sourcePackagePath).version : existsSync(localPackagePath) ? readJson(localPackagePath).version : extractExactVersion(rootCatalog[packageName]);
24
+ const packageVersion = existsSync(localPackagePath) ? readJson(localPackagePath).version : existsSync(sourcePackagePath) ? readJson(sourcePackagePath).version : extractExactVersion(rootCatalog[packageName]);
25
25
  if (!packageVersion) throw new Error(`Could not resolve version for ${packageName}`);
26
26
  frameworkVersions[packageName] = packageVersion;
27
27
  rootCatalog[packageName] = `^${packageVersion}`;
@@ -1 +1 @@
1
- {"version":3,"file":"manifest-normalizer.mjs","names":[],"sources":["../../src/internal/manifest-normalizer.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { glob } from \"glob\";\n\nconst FRAMEWORK_PACKAGES = [\"every-plugin\", \"everything-dev\"] as const;\n\ntype PackageJson = Record<string, unknown>;\n\ntype NormalizationSpec = {\n rootCatalog: Record<string, string>;\n frameworkVersions: Record<string, string>;\n};\n\ntype NormalizeManifestOptions = {\n resolveCatalogRefs: boolean;\n excludeFrameworkWorkspaces?: boolean;\n removeWorkspaceDeps?: string[];\n removeWorkspaces?: boolean;\n removePublishScripts?: boolean;\n};\n\nexport type NormalizeTreeOptions = NormalizeManifestOptions & {\n sourceRootDir: string;\n targetDir: string;\n};\n\nfunction readJson<T>(filePath: string): T {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as T;\n}\n\nfunction extractExactVersion(input: string | undefined): string | null {\n if (!input) return null;\n const match = input.match(/\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?/);\n return match ? match[0] : null;\n}\n\nfunction writeJson(filePath: string, value: PackageJson) {\n writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {\n const rootPackage = readJson<PackageJson>(join(sourceRootDir, \"package.json\"));\n const rootCatalog = {\n ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??\n {}) as Record<string, string>),\n };\n const frameworkVersions: Record<string, string> = {};\n\n for (const packageName of FRAMEWORK_PACKAGES) {\n const sourcePackagePath = join(sourceRootDir, \"packages\", packageName, \"package.json\");\n const localPackagePath = join(import.meta.dirname, \"..\", \"..\", packageName, \"package.json\");\n const packageVersion = existsSync(sourcePackagePath)\n ? readJson<{ version: string }>(sourcePackagePath).version\n : existsSync(localPackagePath)\n ? readJson<{ version: string }>(localPackagePath).version\n : extractExactVersion(rootCatalog[packageName]);\n\n if (!packageVersion) {\n throw new Error(`Could not resolve version for ${packageName}`);\n }\n\n frameworkVersions[packageName] = packageVersion;\n rootCatalog[packageName] = `^${packageVersion}`;\n }\n\n return { rootCatalog, frameworkVersions };\n}\n\nfunction normalizeDependencyMap(\n map: Record<string, string>,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const [name, version] of Object.entries(map)) {\n if (version === \"workspace:*\") {\n const frameworkVersion = spec.frameworkVersions[name];\n if (frameworkVersion) {\n map[name] = `^${frameworkVersion}`;\n modified = true;\n continue;\n }\n\n if (options.removeWorkspaceDeps?.includes(name)) {\n delete map[name];\n modified = true;\n }\n continue;\n }\n\n if (options.resolveCatalogRefs && version.startsWith(\"catalog:\")) {\n const resolved = spec.rootCatalog[name];\n if (resolved) {\n map[name] = resolved;\n modified = true;\n }\n }\n }\n\n return modified;\n}\n\nexport function normalizePackageManifest(\n pkg: PackageJson,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const depField of [\"dependencies\", \"devDependencies\", \"peerDependencies\"]) {\n const deps = pkg[depField];\n if (!deps || typeof deps !== \"object\") continue;\n if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {\n modified = true;\n }\n }\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const workspaces = pkg.workspaces as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {\n const nextPackages = workspaces.packages.filter(\n (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),\n );\n if (nextPackages.length !== workspaces.packages.length) {\n workspaces.packages = nextPackages;\n modified = true;\n }\n }\n\n if (workspaces.catalog && typeof workspaces.catalog === \"object\") {\n for (const [name, version] of Object.entries(workspaces.catalog)) {\n const resolved = spec.rootCatalog[name];\n if (resolved && resolved !== version) {\n workspaces.catalog[name] = resolved;\n modified = true;\n continue;\n }\n\n if (version === \"workspace:*\" && spec.frameworkVersions[name]) {\n workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;\n modified = true;\n }\n }\n }\n }\n\n if (options.removeWorkspaces && \"workspaces\" in pkg) {\n delete pkg.workspaces;\n modified = true;\n }\n\n if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n let scriptsModified = false;\n for (const key of [\"prepublishOnly\", \"prepack\", \"prepare\", \"postpack\"]) {\n if (key in scripts) {\n delete scripts[key];\n scriptsModified = true;\n }\n }\n if (scriptsModified) {\n modified = true;\n if (Object.keys(scripts).length === 0) {\n delete pkg.scripts;\n }\n }\n }\n\n return modified;\n}\n\nexport async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {\n const spec = loadManifestNormalizationSpec(opts.sourceRootDir);\n const files = await glob(\"**/package.json\", {\n cwd: opts.targetDir,\n nodir: true,\n dot: false,\n absolute: true,\n ignore: [\"**/node_modules/**\"],\n });\n\n const updatedFiles: string[] = [];\n\n for (const filePath of files) {\n const pkg = readJson<PackageJson>(filePath);\n if (normalizePackageManifest(pkg, spec, opts)) {\n writeJson(filePath, pkg);\n updatedFiles.push(filePath);\n }\n }\n\n return updatedFiles;\n}\n\nfunction shouldCopyPackageFile(sourceDir: string, filePath: string) {\n const relPath = relative(sourceDir, filePath);\n if (!relPath) return true;\n const segments = relPath.split(sep);\n return !segments.includes(\"node_modules\") && !segments.includes(\"tests\");\n}\n\nfunction stripDevelopmentExports(pkg: PackageJson) {\n const exports = pkg.exports;\n if (!exports || typeof exports !== \"object\") return;\n\n for (const key of Object.keys(exports as Record<string, unknown>)) {\n const entry = (exports as Record<string, unknown>)[key];\n if (entry && typeof entry === \"object\") {\n delete (entry as Record<string, unknown>).development;\n }\n }\n}\n\nexport function stageReleasePackage(opts: {\n repoRoot: string;\n packageName: string;\n outDir: string;\n}) {\n const sourceDir = join(opts.repoRoot, \"packages\", opts.packageName);\n\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(dirname(opts.outDir), { recursive: true });\n cpSync(sourceDir, opts.outDir, {\n recursive: true,\n filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),\n });\n rmSync(join(opts.outDir, \"tests\"), { recursive: true, force: true });\n\n const packageJsonPath = join(opts.outDir, \"package.json\");\n const spec = loadManifestNormalizationSpec(opts.repoRoot);\n const pkg = readJson<PackageJson>(packageJsonPath);\n\n normalizePackageManifest(pkg, spec, {\n resolveCatalogRefs: true,\n removeWorkspaces: true,\n removePublishScripts: true,\n });\n\n stripDevelopmentExports(pkg);\n\n writeJson(packageJsonPath, pkg);\n}\n\nexport function stageReleasePackages(opts: {\n repoRoot: string;\n outDir: string;\n packageNames?: string[];\n}) {\n const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(opts.outDir, { recursive: true });\n\n for (const packageName of packageNames) {\n stageReleasePackage({\n repoRoot: opts.repoRoot,\n packageName,\n outDir: join(opts.outDir, packageName),\n });\n }\n}\n"],"mappings":";;;;;AAIA,MAAM,qBAAqB,CAAC,gBAAgB,iBAAiB;AAsB7D,SAAS,SAAY,UAAqB;AACxC,QAAO,KAAK,MAAM,aAAa,UAAU,QAAQ,CAAC;;AAGpD,SAAS,oBAAoB,OAA0C;AACrE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,oCAAoC;AAC9D,QAAO,QAAQ,MAAM,KAAK;;AAG5B,SAAS,UAAU,UAAkB,OAAoB;AACvD,eAAc,UAAU,GAAG,KAAK,UAAU,OAAO,MAAM,EAAE,CAAC,IAAI;;AAGhE,SAAgB,8BAA8B,eAA0C;CAEtF,MAAM,cAAc,EAClB,GAFkB,SAAsB,KAAK,eAAe,eAAe,CAAC,CAE1D,YAAiE,WACjF,EAAE,EACL;CACD,MAAM,oBAA4C,EAAE;AAEpD,MAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,oBAAoB,KAAK,eAAe,YAAY,aAAa,eAAe;EACtF,MAAM,mBAAmB,KAAK,OAAO,KAAK,SAAS,MAAM,MAAM,aAAa,eAAe;EAC3F,MAAM,iBAAiB,WAAW,kBAAkB,GAChD,SAA8B,kBAAkB,CAAC,UACjD,WAAW,iBAAiB,GAC1B,SAA8B,iBAAiB,CAAC,UAChD,oBAAoB,YAAY,aAAa;AAEnD,MAAI,CAAC,eACH,OAAM,IAAI,MAAM,iCAAiC,cAAc;AAGjE,oBAAkB,eAAe;AACjC,cAAY,eAAe,IAAI;;AAGjC,QAAO;EAAE;EAAa;EAAmB;;AAG3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,iBAAiB,KAAK,kBAAkB,OAAO;AAC7D,eAAW,QAAQ,QAAQ,IAAI,KAAK,kBAAkB;AACtD,eAAW;;;;AAMnB,KAAI,QAAQ,oBAAoB,gBAAgB,KAAK;AACnD,SAAO,IAAI;AACX,aAAW;;AAGb,KAAI,QAAQ,wBAAwB,IAAI,WAAW,OAAO,IAAI,YAAY,UAAU;EAClF,MAAM,UAAU,IAAI;EACpB,IAAI,kBAAkB;AACtB,OAAK,MAAM,OAAO;GAAC;GAAkB;GAAW;GAAW;GAAW,CACpE,KAAI,OAAO,SAAS;AAClB,UAAO,QAAQ;AACf,qBAAkB;;AAGtB,MAAI,iBAAiB;AACnB,cAAW;AACX,OAAI,OAAO,KAAK,QAAQ,CAAC,WAAW,EAClC,QAAO,IAAI;;;AAKjB,QAAO;;AAGT,eAAsB,gCAAgC,MAA4B;CAChF,MAAM,OAAO,8BAA8B,KAAK,cAAc;CAC9D,MAAM,QAAQ,MAAM,KAAK,mBAAmB;EAC1C,KAAK,KAAK;EACV,OAAO;EACP,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,qBAAqB;EAC/B,CAAC;CAEF,MAAM,eAAyB,EAAE;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,MAAM,SAAsB,SAAS;AAC3C,MAAI,yBAAyB,KAAK,MAAM,KAAK,EAAE;AAC7C,aAAU,UAAU,IAAI;AACxB,gBAAa,KAAK,SAAS;;;AAI/B,QAAO"}
1
+ {"version":3,"file":"manifest-normalizer.mjs","names":[],"sources":["../../src/internal/manifest-normalizer.ts"],"sourcesContent":["import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join, relative, sep } from \"node:path\";\nimport { glob } from \"glob\";\n\nconst FRAMEWORK_PACKAGES = [\"every-plugin\", \"everything-dev\"] as const;\n\ntype PackageJson = Record<string, unknown>;\n\ntype NormalizationSpec = {\n rootCatalog: Record<string, string>;\n frameworkVersions: Record<string, string>;\n};\n\ntype NormalizeManifestOptions = {\n resolveCatalogRefs: boolean;\n excludeFrameworkWorkspaces?: boolean;\n removeWorkspaceDeps?: string[];\n removeWorkspaces?: boolean;\n removePublishScripts?: boolean;\n};\n\nexport type NormalizeTreeOptions = NormalizeManifestOptions & {\n sourceRootDir: string;\n targetDir: string;\n};\n\nfunction readJson<T>(filePath: string): T {\n return JSON.parse(readFileSync(filePath, \"utf-8\")) as T;\n}\n\nfunction extractExactVersion(input: string | undefined): string | null {\n if (!input) return null;\n const match = input.match(/\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?/);\n return match ? match[0] : null;\n}\n\nfunction writeJson(filePath: string, value: PackageJson) {\n writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\\n`);\n}\n\nexport function loadManifestNormalizationSpec(sourceRootDir: string): NormalizationSpec {\n const rootPackage = readJson<PackageJson>(join(sourceRootDir, \"package.json\"));\n const rootCatalog = {\n ...(((rootPackage.workspaces as { catalog?: Record<string, string> } | undefined)?.catalog ??\n {}) as Record<string, string>),\n };\n const frameworkVersions: Record<string, string> = {};\n\n for (const packageName of FRAMEWORK_PACKAGES) {\n const sourcePackagePath = join(sourceRootDir, \"packages\", packageName, \"package.json\");\n const localPackagePath = join(import.meta.dirname, \"..\", \"..\", packageName, \"package.json\");\n const packageVersion = existsSync(localPackagePath)\n ? readJson<{ version: string }>(localPackagePath).version\n : existsSync(sourcePackagePath)\n ? readJson<{ version: string }>(sourcePackagePath).version\n : extractExactVersion(rootCatalog[packageName]);\n\n if (!packageVersion) {\n throw new Error(`Could not resolve version for ${packageName}`);\n }\n\n frameworkVersions[packageName] = packageVersion;\n rootCatalog[packageName] = `^${packageVersion}`;\n }\n\n return { rootCatalog, frameworkVersions };\n}\n\nfunction normalizeDependencyMap(\n map: Record<string, string>,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const [name, version] of Object.entries(map)) {\n if (version === \"workspace:*\") {\n const frameworkVersion = spec.frameworkVersions[name];\n if (frameworkVersion) {\n map[name] = `^${frameworkVersion}`;\n modified = true;\n continue;\n }\n\n if (options.removeWorkspaceDeps?.includes(name)) {\n delete map[name];\n modified = true;\n }\n continue;\n }\n\n if (options.resolveCatalogRefs && version.startsWith(\"catalog:\")) {\n const resolved = spec.rootCatalog[name];\n if (resolved) {\n map[name] = resolved;\n modified = true;\n }\n }\n }\n\n return modified;\n}\n\nexport function normalizePackageManifest(\n pkg: PackageJson,\n spec: NormalizationSpec,\n options: NormalizeManifestOptions,\n) {\n let modified = false;\n\n for (const depField of [\"dependencies\", \"devDependencies\", \"peerDependencies\"]) {\n const deps = pkg[depField];\n if (!deps || typeof deps !== \"object\") continue;\n if (normalizeDependencyMap(deps as Record<string, string>, spec, options)) {\n modified = true;\n }\n }\n\n if (pkg.workspaces && typeof pkg.workspaces === \"object\") {\n const workspaces = pkg.workspaces as {\n packages?: string[];\n catalog?: Record<string, string>;\n };\n\n if (options.excludeFrameworkWorkspaces && Array.isArray(workspaces.packages)) {\n const nextPackages = workspaces.packages.filter(\n (entry) => !FRAMEWORK_PACKAGES.some((name) => entry === `packages/${name}`),\n );\n if (nextPackages.length !== workspaces.packages.length) {\n workspaces.packages = nextPackages;\n modified = true;\n }\n }\n\n if (workspaces.catalog && typeof workspaces.catalog === \"object\") {\n for (const [name, version] of Object.entries(workspaces.catalog)) {\n const resolved = spec.rootCatalog[name];\n if (resolved && resolved !== version) {\n workspaces.catalog[name] = resolved;\n modified = true;\n continue;\n }\n\n if (version === \"workspace:*\" && spec.frameworkVersions[name]) {\n workspaces.catalog[name] = `^${spec.frameworkVersions[name]}`;\n modified = true;\n }\n }\n }\n }\n\n if (options.removeWorkspaces && \"workspaces\" in pkg) {\n delete pkg.workspaces;\n modified = true;\n }\n\n if (options.removePublishScripts && pkg.scripts && typeof pkg.scripts === \"object\") {\n const scripts = pkg.scripts as Record<string, string>;\n let scriptsModified = false;\n for (const key of [\"prepublishOnly\", \"prepack\", \"prepare\", \"postpack\"]) {\n if (key in scripts) {\n delete scripts[key];\n scriptsModified = true;\n }\n }\n if (scriptsModified) {\n modified = true;\n if (Object.keys(scripts).length === 0) {\n delete pkg.scripts;\n }\n }\n }\n\n return modified;\n}\n\nexport async function normalizePackageManifestsInTree(opts: NormalizeTreeOptions) {\n const spec = loadManifestNormalizationSpec(opts.sourceRootDir);\n const files = await glob(\"**/package.json\", {\n cwd: opts.targetDir,\n nodir: true,\n dot: false,\n absolute: true,\n ignore: [\"**/node_modules/**\"],\n });\n\n const updatedFiles: string[] = [];\n\n for (const filePath of files) {\n const pkg = readJson<PackageJson>(filePath);\n if (normalizePackageManifest(pkg, spec, opts)) {\n writeJson(filePath, pkg);\n updatedFiles.push(filePath);\n }\n }\n\n return updatedFiles;\n}\n\nfunction shouldCopyPackageFile(sourceDir: string, filePath: string) {\n const relPath = relative(sourceDir, filePath);\n if (!relPath) return true;\n const segments = relPath.split(sep);\n return !segments.includes(\"node_modules\") && !segments.includes(\"tests\");\n}\n\nfunction stripDevelopmentExports(pkg: PackageJson) {\n const exports = pkg.exports;\n if (!exports || typeof exports !== \"object\") return;\n\n for (const key of Object.keys(exports as Record<string, unknown>)) {\n const entry = (exports as Record<string, unknown>)[key];\n if (entry && typeof entry === \"object\") {\n delete (entry as Record<string, unknown>).development;\n }\n }\n}\n\nexport function stageReleasePackage(opts: {\n repoRoot: string;\n packageName: string;\n outDir: string;\n}) {\n const sourceDir = join(opts.repoRoot, \"packages\", opts.packageName);\n\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(dirname(opts.outDir), { recursive: true });\n cpSync(sourceDir, opts.outDir, {\n recursive: true,\n filter: (filePath) => shouldCopyPackageFile(sourceDir, filePath),\n });\n rmSync(join(opts.outDir, \"tests\"), { recursive: true, force: true });\n\n const packageJsonPath = join(opts.outDir, \"package.json\");\n const spec = loadManifestNormalizationSpec(opts.repoRoot);\n const pkg = readJson<PackageJson>(packageJsonPath);\n\n normalizePackageManifest(pkg, spec, {\n resolveCatalogRefs: true,\n removeWorkspaces: true,\n removePublishScripts: true,\n });\n\n stripDevelopmentExports(pkg);\n\n writeJson(packageJsonPath, pkg);\n}\n\nexport function stageReleasePackages(opts: {\n repoRoot: string;\n outDir: string;\n packageNames?: string[];\n}) {\n const packageNames = opts.packageNames ?? [...FRAMEWORK_PACKAGES];\n rmSync(opts.outDir, { recursive: true, force: true });\n mkdirSync(opts.outDir, { recursive: true });\n\n for (const packageName of packageNames) {\n stageReleasePackage({\n repoRoot: opts.repoRoot,\n packageName,\n outDir: join(opts.outDir, packageName),\n });\n }\n}\n"],"mappings":";;;;;AAIA,MAAM,qBAAqB,CAAC,gBAAgB,iBAAiB;AAsB7D,SAAS,SAAY,UAAqB;AACxC,QAAO,KAAK,MAAM,aAAa,UAAU,QAAQ,CAAC;;AAGpD,SAAS,oBAAoB,OAA0C;AACrE,KAAI,CAAC,MAAO,QAAO;CACnB,MAAM,QAAQ,MAAM,MAAM,oCAAoC;AAC9D,QAAO,QAAQ,MAAM,KAAK;;AAG5B,SAAS,UAAU,UAAkB,OAAoB;AACvD,eAAc,UAAU,GAAG,KAAK,UAAU,OAAO,MAAM,EAAE,CAAC,IAAI;;AAGhE,SAAgB,8BAA8B,eAA0C;CAEtF,MAAM,cAAc,EAClB,GAFkB,SAAsB,KAAK,eAAe,eAAe,CAAC,CAE1D,YAAiE,WACjF,EAAE,EACL;CACD,MAAM,oBAA4C,EAAE;AAEpD,MAAK,MAAM,eAAe,oBAAoB;EAC5C,MAAM,oBAAoB,KAAK,eAAe,YAAY,aAAa,eAAe;EACtF,MAAM,mBAAmB,KAAK,OAAO,KAAK,SAAS,MAAM,MAAM,aAAa,eAAe;EAC3F,MAAM,iBAAiB,WAAW,iBAAiB,GAC/C,SAA8B,iBAAiB,CAAC,UAChD,WAAW,kBAAkB,GAC3B,SAA8B,kBAAkB,CAAC,UACjD,oBAAoB,YAAY,aAAa;AAEnD,MAAI,CAAC,eACH,OAAM,IAAI,MAAM,iCAAiC,cAAc;AAG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,YAAY,aAAa,SAAS;AACpC,eAAW,QAAQ,QAAQ;AAC3B,eAAW;AACX;;AAGF,OAAI,YAAY,iBAAiB,KAAK,kBAAkB,OAAO;AAC7D,eAAW,QAAQ,QAAQ,IAAI,KAAK,kBAAkB;AACtD,eAAW;;;;AAMnB,KAAI,QAAQ,oBAAoB,gBAAgB,KAAK;AACnD,SAAO,IAAI;AACX,aAAW;;AAGb,KAAI,QAAQ,wBAAwB,IAAI,WAAW,OAAO,IAAI,YAAY,UAAU;EAClF,MAAM,UAAU,IAAI;EACpB,IAAI,kBAAkB;AACtB,OAAK,MAAM,OAAO;GAAC;GAAkB;GAAW;GAAW;GAAW,CACpE,KAAI,OAAO,SAAS;AAClB,UAAO,QAAQ;AACf,qBAAkB;;AAGtB,MAAI,iBAAiB;AACnB,cAAW;AACX,OAAI,OAAO,KAAK,QAAQ,CAAC,WAAW,EAClC,QAAO,IAAI;;;AAKjB,QAAO;;AAGT,eAAsB,gCAAgC,MAA4B;CAChF,MAAM,OAAO,8BAA8B,KAAK,cAAc;CAC9D,MAAM,QAAQ,MAAM,KAAK,mBAAmB;EAC1C,KAAK,KAAK;EACV,OAAO;EACP,KAAK;EACL,UAAU;EACV,QAAQ,CAAC,qBAAqB;EAC/B,CAAC;CAEF,MAAM,eAAyB,EAAE;AAEjC,MAAK,MAAM,YAAY,OAAO;EAC5B,MAAM,MAAM,SAAsB,SAAS;AAC3C,MAAI,yBAAyB,KAAK,MAAM,KAAK,EAAE;AAC7C,aAAU,UAAU,IAAI;AACxB,gBAAa,KAAK,SAAS;;;AAI/B,QAAO"}
package/dist/plugin.cjs CHANGED
@@ -37,7 +37,6 @@ function ensureEnvFile(configDir) {
37
37
  const secret = (0, node_crypto.randomBytes)(32).toString("base64url");
38
38
  (0, node_fs.writeFileSync)(envPath, lines.map((line) => {
39
39
  if (/^BETTER_AUTH_SECRET=/.test(line)) return `BETTER_AUTH_SECRET=${secret}`;
40
- if (/^BETTER_AUTH_URL=/.test(line)) return `BETTER_AUTH_URL=http://localhost:3000`;
41
40
  return line;
42
41
  }).join("\n"));
43
42
  _clack_prompts.log.info(`Created .env from .env.example with generated BETTER_AUTH_SECRET`);
@@ -932,7 +931,10 @@ var plugin_default = (0, every_plugin.createPlugin)({
932
931
  plugins,
933
932
  pluginRoutes
934
933
  });
935
- if (!input.noInstall) await require_cli_init.runBunInstall(directory);
934
+ if (!input.noInstall) {
935
+ await require_cli_init.runBunInstall(directory);
936
+ await require_cli_init.generateDatabaseMigrations(directory);
937
+ }
936
938
  ensureEnvFile(directory);
937
939
  s.stop("Project initialized");
938
940
  return {
@@ -1041,8 +1043,7 @@ var plugin_default = (0, every_plugin.createPlugin)({
1041
1043
  generated: [
1042
1044
  "ui/src/api-contract.gen.ts",
1043
1045
  "ui/src/auth-types.gen.ts",
1044
- "api/src/plugins-client.gen.ts",
1045
- "api/src/auth-client.gen.ts"
1046
+ "api/src/plugins-client.gen.ts"
1046
1047
  ],
1047
1048
  fetched,
1048
1049
  skipped,
@@ -1055,11 +1056,7 @@ var plugin_default = (0, every_plugin.createPlugin)({
1055
1056
  runtimeConfig: refreshed.runtime,
1056
1057
  apiBaseUrl: refreshed.runtime.api.url
1057
1058
  });
1058
- const generated = [
1059
- "ui/src/api-contract.gen.ts",
1060
- "api/src/plugins-client.gen.ts",
1061
- "api/src/auth-client.gen.ts"
1062
- ];
1059
+ const generated = ["ui/src/api-contract.gen.ts", "api/src/plugins-client.gen.ts"];
1063
1060
  if (refreshed.runtime.auth && (refreshed.runtime.auth.source !== "local" || refreshed.runtime.auth.localPath)) generated.push("ui/src/auth-types.gen.ts");
1064
1061
  return {
1065
1062
  status: "success",