@mongez/pkgist 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -13
- package/builder.ts +2 -22
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/src/publish/npm-publisher.ts +1 -1
- package/src/build/family-builder.ts +0 -76
- package/src/build/index.ts +0 -4
- package/src/build/package-builder.ts +0 -155
- package/src/build/parallel-builder.ts +0 -36
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/config/define-config.ts","../src/config/load-config.ts","../src/utils/paths.ts","../src/utils/errors.ts","../src/files/file-manager.ts","../src/files/package-json.ts","../src/files/clone-files.ts","../src/utils/logger.ts","../src/compile/tsdown-compiler.ts","../src/version/increment.ts","../src/git/operations.ts","../src/utils/exec.ts","../src/publish/npm-publisher.ts","../src/build/package-builder.ts","../src/build/family-builder.ts","../src/build/parallel-builder.ts"],"sourcesContent":["import type { BundlerConfig } from \"../types/index.js\";\n\n/**\n * Type-safe config factory.\n * Simply returns the config object unchanged — used purely for IDE autocomplete and type checking.\n */\nexport function defineConfig(config: BundlerConfig): BundlerConfig {\n return config;\n}\n","import path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport fs from \"fs\";\nimport type { BundlerConfig } from \"../types/index.js\";\nimport { resolvePath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\n\nexport interface LoadedConfig {\n config: BundlerConfig;\n /** Absolute, forward-slash normalised path to the config file */\n configPath: string;\n /** Directory containing the config file — used to resolve relative roots */\n configDir: string;\n}\n\n/**\n * Register tsx as a Node loader so TypeScript config files can be imported\n * directly via dynamic import(). Safe to call multiple times — tsx is only\n * registered once. No-ops when tsx is not installed (JS-only config still works).\n */\nasync function ensureTsxRegistered(): Promise<void> {\n try {\n const { register } = await import(\"node:module\");\n let tsxUrl: string | null = null;\n try {\n tsxUrl = import.meta.resolve(\"tsx/esm\");\n } catch {\n // tsx not installed — JS-only configs still work fine\n }\n if (register && tsxUrl) {\n register(tsxUrl, import.meta.url);\n }\n } catch {\n // node:module unavailable (old Node) — fall through silently\n }\n}\n\n/** Load and validate a pkgist config file (TypeScript or JavaScript). */\nexport async function loadConfig(configFilePath: string): Promise<LoadedConfig> {\n const absolute = resolvePath(configFilePath);\n\n if (!fs.existsSync(absolute)) {\n throw new Error(`Config file not found: ${absolute}`);\n }\n\n let mod: { default?: BundlerConfig };\n\n try {\n // Register tsx so .ts config files import without the user needing\n // to prefix the command with `node --import tsx/esm`.\n if (absolute.endsWith(\".ts\")) {\n await ensureTsxRegistered();\n }\n\n // Convert to a file:// URL so dynamic import works correctly on Windows.\n const fileUrl = pathToFileURL(absolute).href;\n mod = await import(fileUrl);\n } catch (err) {\n throw wrapError(\"load-config\", absolute, err);\n }\n\n const config = mod.default;\n\n if (!config || typeof config !== \"object\") {\n throw new Error(\n `Config file ${absolute} must export a default object from defineConfig(). Got: ${typeof config}`,\n );\n }\n\n validateConfig(config, absolute);\n\n return {\n config,\n configPath: absolute,\n configDir: resolvePath(path.dirname(absolute)),\n };\n}\n\nfunction validateConfig(config: BundlerConfig, filePath: string): void {\n if (!config.settings) {\n throw new Error(`Config \"${filePath}\" must have a \"settings\" object.`);\n }\n if (!config.settings.buildDir) {\n throw new Error(`Config \"${filePath}\" settings.buildDir is required.`);\n }\n\n const names = new Set<string>();\n\n for (const pkg of config.standalone ?? []) {\n if (!pkg.name) throw new Error(`Standalone package is missing \"name\" in ${filePath}`);\n if (!pkg.root) throw new Error(`Standalone package \"${pkg.name}\" is missing \"root\"`);\n if (names.has(pkg.name)) throw new Error(`Duplicate package name: \"${pkg.name}\"`);\n names.add(pkg.name);\n }\n\n for (const family of config.families ?? []) {\n if (!family.name) throw new Error(`A family is missing \"name\" in ${filePath}`);\n for (const pkg of family.packages) {\n if (!pkg.name) throw new Error(`Package inside family \"${family.name}\" is missing \"name\"`);\n if (!pkg.root) throw new Error(`Package \"${pkg.name}\" in family \"${family.name}\" is missing \"root\"`);\n if (names.has(pkg.name)) throw new Error(`Duplicate package name: \"${pkg.name}\"`);\n names.add(pkg.name);\n }\n }\n}\n\n/**\n * Attempt to find the default config file in the working directory.\n * Tries: builder.ts, builder.js, mongez.ts, mongez.js\n */\nexport function findDefaultConfigPath(cwd: string): string {\n const candidates = [\"pkgist.config.ts\", \"pkgist.config.js\", \"builder.ts\", \"builder.js\", \"mongez.ts\", \"mongez.js\"];\n for (const candidate of candidates) {\n const full = path.join(cwd, candidate);\n if (fs.existsSync(full)) return full;\n }\n throw new Error(\n `No config file found in ${cwd}. Tried: ${candidates.join(\", \")}. ` +\n `Use --config <path> to specify a custom location.`,\n );\n}\n","import path from \"path\";\n\n/** Normalise any path to forward-slash form (Windows-safe). */\nexport function toForwardSlash(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\n/** Join path segments and normalise the result to forward slashes. */\nexport function joinPath(...segments: string[]): string {\n return toForwardSlash(path.join(...segments));\n}\n\n/** Resolve an absolute path from segments and normalise to forward slashes. */\nexport function resolvePath(...segments: string[]): string {\n return toForwardSlash(path.resolve(...segments));\n}\n\n/**\n * Given a package name like \"@mongez/reinforcements\",\n * return just the scoped part without the scope prefix: \"reinforcements\".\n */\nexport function scopelessName(packageName: string): string {\n const slash = packageName.indexOf(\"/\");\n return slash === -1 ? packageName : packageName.slice(slash + 1);\n}\n\n/**\n * Build the versioned build output path:\n * <buildDir>/<scopeless-name>/<version>/\n */\nexport function buildOutputPath(\n buildDir: string,\n packageName: string,\n version: string,\n): string {\n return joinPath(buildDir, scopelessName(packageName), version);\n}\n\n/**\n * Build the sources snapshot path:\n * <sourcesDir>/<scopeless-name>/\n */\nexport function sourceSnapshotPath(\n sourcesDir: string,\n packageName: string,\n): string {\n return joinPath(sourcesDir, scopelessName(packageName));\n}\n","/** Base error class for all bundler errors. Carries a step name for structured logging. */\nexport class BundlerError extends Error {\n constructor(\n public readonly step: string,\n public readonly packageName: string,\n message: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"BundlerError\";\n if (cause instanceof Error && cause.stack) {\n this.stack = `${this.stack}\\nCaused by: ${cause.stack}`;\n }\n }\n}\n\n/** Wrap any thrown value into a BundlerError with context. */\nexport function wrapError(\n step: string,\n packageName: string,\n error: unknown,\n): BundlerError {\n if (error instanceof BundlerError) return error;\n const msg =\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : JSON.stringify(error);\n return new BundlerError(step, packageName, `[${step}] ${packageName}: ${msg}`, error);\n}\n\n/** Throw a wrapped error immediately. */\nexport function failWith(\n step: string,\n packageName: string,\n error: unknown,\n): never {\n throw wrapError(step, packageName, error);\n}\n","import fs from \"fs\";\nimport path from \"path\";\nimport { resolvePath, joinPath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\n\n/**\n * Ensure a directory exists, creating all intermediate directories as needed.\n */\nexport function ensureDir(dir: string): void {\n try {\n fs.mkdirSync(dir, { recursive: true });\n } catch (err) {\n throw wrapError(\"ensure-dir\", dir, err);\n }\n}\n\n/**\n * Copy a single file from src to dest.\n * Creates the destination directory if it does not exist.\n */\nexport function copyFile(src: string, dest: string): void {\n ensureDir(path.dirname(dest));\n try {\n fs.copyFileSync(src, dest);\n } catch (err) {\n throw wrapError(\"copy-file\", src, err);\n }\n}\n\n/** Directories that are never copied in any directory tree operation. */\nconst COPY_EXCLUDES = new Set([\".git\", \"node_modules\", \"dist\", \".turbo\", \".cache\"]);\n\n/**\n * Copy an entire directory tree recursively, skipping .git and node_modules.\n */\nexport function copyDir(src: string, dest: string): void {\n ensureDir(dest);\n const entries = fs.readdirSync(src, { withFileTypes: true });\n for (const entry of entries) {\n if (COPY_EXCLUDES.has(entry.name)) continue;\n const srcPath = joinPath(src, entry.name);\n const destPath = joinPath(dest, entry.name);\n if (entry.isDirectory()) {\n copyDir(srcPath, destPath);\n } else {\n copyFile(srcPath, destPath);\n }\n }\n}\n\n/**\n * Read a file as a UTF-8 string, or throw a BundlerError with context.\n */\nexport function readFile(filePath: string, packageName = filePath): string {\n try {\n return fs.readFileSync(filePath, \"utf-8\");\n } catch (err) {\n throw wrapError(\"read-file\", packageName, err);\n }\n}\n\n/**\n * Write a UTF-8 string to a file, creating intermediate directories.\n */\nexport function writeFile(filePath: string, content: string, packageName = filePath): void {\n ensureDir(path.dirname(filePath));\n try {\n fs.writeFileSync(filePath, content, \"utf-8\");\n } catch (err) {\n throw wrapError(\"write-file\", packageName, err);\n }\n}\n\n/**\n * Move all files matching a glob-like condition.\n * Actually does a rename — works only within the same filesystem volume.\n */\nexport function moveFile(src: string, dest: string, packageName = src): void {\n ensureDir(path.dirname(dest));\n try {\n fs.renameSync(src, dest);\n } catch (err) {\n // rename across devices fails — fall back to copy+unlink\n try {\n fs.copyFileSync(src, dest);\n fs.unlinkSync(src);\n } catch (fallbackErr) {\n throw wrapError(\"move-file\", packageName, fallbackErr);\n }\n }\n}\n\n/**\n * Check whether a path exists on the filesystem.\n */\nexport function pathExists(p: string): boolean {\n return fs.existsSync(p);\n}\n\n/**\n * List all file paths inside a directory (non-recursive).\n */\nexport function listFiles(dir: string): string[] {\n if (!fs.existsSync(dir)) return [];\n return fs\n .readdirSync(dir, { withFileTypes: true })\n .filter((e) => e.isFile())\n .map((e) => joinPath(dir, e.name));\n}\n","import path from \"path\";\nimport { readFile, writeFile } from \"./file-manager.js\";\nimport { joinPath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport type { PackageBase } from \"../types/index.js\";\n\n// Fields kept verbatim from the source package.json into the build package.json.\nconst KEPT_FIELDS = [\n \"name\",\n \"description\",\n \"keywords\",\n \"author\",\n \"license\",\n \"repository\",\n \"homepage\",\n \"bugs\",\n \"dependencies\",\n \"peerDependencies\",\n \"sideEffects\",\n \"bin\",\n \"engines\",\n] as const;\n\nexport type SourcePackageJson = Record<string, unknown> & {\n version: string;\n dependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n};\n\n/**\n * Read and parse the package.json at <packageRoot>/package.json.\n * Throws a BundlerError if the file is missing or malformed.\n */\nexport function readSourcePackageJson(\n packageRoot: string,\n packageName: string,\n): SourcePackageJson {\n const pkgPath = joinPath(packageRoot, \"package.json\");\n let raw: string;\n try {\n raw = readFile(pkgPath, packageName);\n } catch {\n throw wrapError(\n \"read-package-json\",\n packageName,\n new Error(`package.json not found at ${pkgPath}`),\n );\n }\n\n try {\n const parsed = JSON.parse(raw) as SourcePackageJson;\n if (!parsed.version) {\n throw new Error(`package.json at ${pkgPath} is missing \"version\" field`);\n }\n return parsed;\n } catch (err) {\n throw wrapError(\"parse-package-json\", packageName, err);\n }\n}\n\n/**\n * Write the new version back into the source package.json.\n */\nexport function writeSourceVersion(\n packageRoot: string,\n packageName: string,\n newVersion: string,\n): void {\n const pkgPath = joinPath(packageRoot, \"package.json\");\n const raw = readFile(pkgPath, packageName);\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n parsed.version = newVersion;\n writeFile(pkgPath, JSON.stringify(parsed, null, 2) + \"\\n\", packageName);\n}\n\n/**\n * Build and write the clean package.json for the build output directory.\n */\nexport function writeBuildPackageJson(\n pkg: PackageBase,\n sourceJson: SourcePackageJson,\n buildPath: string,\n newVersion: string,\n): void {\n const formats = pkg.formats ?? [\"esm\", \"cjs\"];\n const hasEsm = formats.includes(\"esm\");\n const hasCjs = formats.includes(\"cjs\");\n const esmOnly = hasEsm && !hasCjs;\n\n // When preserveModules is on (the default), tsdown keeps one file per source\n // module and uses native extensions (.mjs/.cjs) so internal cross-file imports\n // resolve correctly. When bundling, everything is renamed to .js for simplicity.\n const preserve = pkg.preserveModules !== false;\n const esmExt = preserve ? \".mjs\" : \".js\";\n const cjsExt = preserve ? \".cjs\" : \".js\";\n const esmDts = preserve ? \".d.mts\" : \".d.ts\";\n const cjsDts = preserve ? \".d.cts\" : \".d.ts\";\n\n // Determine entry base names from entries config\n const rawEntries = pkg.entries ?? [\"index.ts\"];\n const entryList = Array.isArray(rawEntries) ? rawEntries : [rawEntries];\n\n /**\n * Convert an entry path (relative to srcDir) into:\n * basePath — path without extension, used to build file paths (e.g. \"cli/index\")\n * exportPath — the key in the exports map (e.g. \"./cli\")\n *\n * When the basename is \"index\" the directory becomes the export path so that\n * `cli/index.ts` maps to `\"./cli\"` and `index.ts` maps to `\".\"`.\n */\n function entryPaths(entry: string): { basePath: string; exportPath: string } {\n const basePath = entry.replace(/\\.tsx?$/, \"\");\n const parts = basePath.split(\"/\");\n const last = parts[parts.length - 1];\n let exportPath: string;\n if (last === \"index\") {\n const dir = parts.slice(0, -1).join(\"/\");\n exportPath = dir ? `./${dir}` : \".\";\n } else {\n exportPath = `./${basePath}`;\n }\n return { basePath, exportPath };\n }\n\n // Primary entry drives `main` / `module` / `types` fields.\n const { basePath: primaryBase } = entryPaths(entryList[0]!);\n\n // Build the full exports map — one condition block per entry.\n const exportsMap: Record<string, unknown> = {};\n\n for (const entry of entryList) {\n const { basePath, exportPath } = entryPaths(entry);\n const conditions: Record<string, unknown> = {};\n\n if (hasEsm) {\n conditions[\"import\"] = {\n types: `./esm/${basePath}${esmDts}`,\n default: `./esm/${basePath}${esmExt}`,\n };\n }\n if (hasCjs) {\n // When preserveModules is on, CJS is built without DTS to avoid a rolldown bug.\n // TypeScript resolves types correctly from the ESM declarations via the exports map.\n const cjsTypes = preserve && hasEsm\n ? `./esm/${basePath}${esmDts}`\n : `./cjs/${basePath}${cjsDts}`;\n conditions[\"require\"] = {\n types: cjsTypes,\n default: `./cjs/${basePath}${cjsExt}`,\n };\n }\n\n exportsMap[exportPath] = conditions;\n }\n\n const output: Record<string, unknown> = {};\n\n // Copy allowed fields from source\n for (const field of KEPT_FIELDS) {\n if (field in sourceJson && sourceJson[field] !== undefined) {\n output[field] = sourceJson[field];\n }\n }\n\n // Override name / version\n output[\"name\"] = pkg.name;\n output[\"version\"] = newVersion;\n\n if (esmOnly) {\n output[\"type\"] = \"module\";\n }\n\n // Entry points\n const mainType = pkg.mainType ?? \"cjs\";\n if (mainType === \"esm\" || esmOnly) {\n output[\"main\"] = `./esm/${primaryBase}${esmExt}`;\n } else {\n output[\"main\"] = `./cjs/${primaryBase}${cjsExt}`;\n }\n\n if (hasEsm) {\n output[\"module\"] = `./esm/${primaryBase}${esmExt}`;\n }\n\n output[\"types\"] = `./esm/${primaryBase}${esmDts}`;\n\n output[\"exports\"] = exportsMap;\n\n const pkgPath = joinPath(buildPath, \"package.json\");\n writeFile(pkgPath, JSON.stringify(output, null, 2) + \"\\n\", pkg.name);\n}\n","import fs from \"fs\";\nimport { copyFile, copyDir, pathExists } from \"./file-manager.js\";\nimport { joinPath } from \"../utils/paths.js\";\nimport { logger } from \"../utils/logger.js\";\n\n/**\n * Clone extra files (README, license, etc.) from the package root into the build directory.\n *\n * Each entry in the `clone` array can be:\n * - a plain string: copied from `<packageRoot>/<str>` to `<buildDir>/<str>`\n * - a tuple [src, dest]: copied from `<packageRoot>/<src>` to `<buildDir>/<dest>`\n */\nexport function cloneFiles(\n packageRoot: string,\n buildDir: string,\n cloneList: (string | [string, string])[],\n packageName: string,\n dryRun: boolean,\n): void {\n for (const entry of cloneList) {\n const [srcRel, destRel] =\n typeof entry === \"string\" ? [entry, entry] : entry;\n\n const src = joinPath(packageRoot, srcRel);\n const dest = joinPath(buildDir, destRel);\n\n if (!pathExists(src)) {\n logger.warn(`[clone-files] ${packageName}: source file not found, skipping — ${src}`);\n continue;\n }\n\n if (dryRun) {\n logger.info(`[dry-run] clone ${src} → ${dest}`);\n continue;\n }\n\n const stat = fs.statSync(src);\n if (stat.isDirectory()) {\n copyDir(src, dest);\n } else {\n copyFile(src, dest);\n }\n logger.debug(`Cloned ${src} → ${dest}`);\n }\n}\n","import chalk from \"chalk\";\n\nexport type LogLevel = \"info\" | \"success\" | \"warn\" | \"error\" | \"debug\" | \"step\";\n\nlet _verbose = false;\n\nexport function setVerbose(v: boolean): void {\n _verbose = v;\n}\n\nexport function log(level: LogLevel, message: string): void {\n const ts = new Date().toISOString().replace(\"T\", \" \").replace(\"Z\", \"\");\n switch (level) {\n case \"info\":\n console.log(chalk.cyan(`[${ts}] INFO ${message}`));\n break;\n case \"success\":\n console.log(chalk.green(`[${ts}] OK ${message}`));\n break;\n case \"warn\":\n console.warn(chalk.yellow(`[${ts}] WARN ${message}`));\n break;\n case \"error\":\n console.error(chalk.red(`[${ts}] ERROR ${message}`));\n break;\n case \"step\":\n console.log(chalk.blueBright(`[${ts}] STEP ${message}`));\n break;\n case \"debug\":\n if (_verbose) {\n console.log(chalk.gray(`[${ts}] DEBUG ${message}`));\n }\n break;\n }\n}\n\nexport const logger = {\n info: (msg: string) => log(\"info\", msg),\n success: (msg: string) => log(\"success\", msg),\n warn: (msg: string) => log(\"warn\", msg),\n error: (msg: string) => log(\"error\", msg),\n step: (msg: string) => log(\"step\", msg),\n debug: (msg: string) => log(\"debug\", msg),\n};\n","import path from \"path\";\nimport fs from \"fs\";\nimport { build } from \"tsdown\";\nimport type { InputOptions } from \"rolldown\";\nimport type { PackageBase } from \"../types/index.js\";\nimport { joinPath, toForwardSlash, resolvePath } from \"../utils/paths.js\";\nimport { ensureDir, moveFile, listFiles, pathExists } from \"../files/file-manager.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\n\n// ─── Helpers ───────────────────────────────────────────────────────────────\n\n/**\n * Collect all dependency names that should be treated as external.\n * Both `dependencies` and `peerDependencies` must never be bundled.\n */\nfunction collectExternals(sourceJson: Record<string, unknown>): string[] {\n const deps = Object.keys((sourceJson[\"dependencies\"] as Record<string, string> | undefined) ?? {});\n const peers = Object.keys((sourceJson[\"peerDependencies\"] as Record<string, string> | undefined) ?? {});\n return [...new Set([...deps, ...peers])];\n}\n\n/**\n * Resolve entry file paths to absolute forward-slash paths.\n */\nfunction resolveEntries(pkg: PackageBase, packageRoot: string): string[] {\n const srcDir = pkg.srcDir ?? \"src\";\n const rawEntries = pkg.entries ?? [\"index.ts\"];\n const entryList = Array.isArray(rawEntries) ? rawEntries : [rawEntries];\n return entryList.map((e) => toForwardSlash(resolvePath(packageRoot, srcDir, e)));\n}\n\n/**\n * Return the path to the tsconfig.json inside the package root, if it exists.\n */\nfunction findTsconfig(packageRoot: string): string | undefined {\n const local = joinPath(packageRoot, \"tsconfig.json\");\n return pathExists(local) ? local : undefined;\n}\n\n// ─── Main compiler ──────────────────────────────────────────────────────────\n\n/**\n * Compile a single package using tsdown.\n *\n * When `preserveModules` is on (the default), we run two separate tsdown builds\n * in parallel so that each format's output options are fully independent:\n *\n * ESM build — preserveModules: true, dts: true → _tmp_esm/ → esm/*.mjs + *.d.mts\n * CJS build — preserveModules: false, dts: false → _tmp_cjs/ → cjs/*.cjs\n *\n * CJS skips DTS because rolldown has a bug in CJS preserveModules mode where\n * `export { default as X }` assigns the whole module object to exports.X instead\n * of unwrapping .default. Bundled CJS has no such issue. Types are shared from\n * the ESM declarations (TypeScript resolves them correctly via the exports map).\n *\n * When `preserveModules` is false, a single combined build is used.\n */\nexport async function compilePackage(\n pkg: PackageBase,\n packageRoot: string,\n buildPath: string,\n sourceJson: Record<string, unknown>,\n dryRun: boolean,\n): Promise<void> {\n if (dryRun) {\n logger.info(`[dry-run] compile ${pkg.name} → ${buildPath}`);\n return;\n }\n\n const entries = resolveEntries(pkg, packageRoot);\n const formats = pkg.formats ?? [\"esm\", \"cjs\"];\n const externals = collectExternals(sourceJson);\n const tsconfig = findTsconfig(packageRoot);\n const shouldPreserveModules = pkg.preserveModules !== false;\n const srcDir = toForwardSlash(resolvePath(packageRoot, pkg.srcDir ?? \"src\"));\n\n logger.step(`Compiling ${pkg.name} (${formats.join(\", \")}) → ${buildPath}`);\n logger.debug(` entries: ${entries.join(\", \")}`);\n logger.debug(` externals: ${externals.slice(0, 8).join(\", \")}${externals.length > 8 ? \"…\" : \"\"}`);\n\n // Wipe any previous esm/ and cjs/ output so re-runs of the same version don't\n // leave stale files from a different build mode.\n for (const subDir of [\"esm\", \"cjs\"]) {\n const dir = resolvePath(buildPath, subDir);\n if (fs.existsSync(dir)) {\n fs.rmSync(dir, { recursive: true, force: true });\n }\n }\n\n // Build inputOptions for rolldown — used to set the JSX transform for React packages.\n const rolldownInputOptions: InputOptions | undefined =\n pkg.type === \"react\"\n ? {\n transform: {\n jsx: \"react-jsx\", // automatic runtime — works with React 17+\n },\n }\n : undefined;\n\n // Common options shared across all tsdown invocations.\n const sharedOptions = {\n entry: entries,\n deps: { neverBundle: externals },\n sourcemap: pkg.sourcemap !== false,\n clean: true,\n minify: pkg.minify ?? false,\n tsconfig: tsconfig ?? true,\n ...(rolldownInputOptions ? { inputOptions: rolldownInputOptions } : {}),\n } as const;\n\n try {\n if (shouldPreserveModules && formats.includes(\"esm\") && formats.includes(\"cjs\")) {\n // Two parallel builds: ESM with preserveModules + DTS, CJS bundled without DTS.\n const tmpEsm = toForwardSlash(resolvePath(buildPath, \"_tmp_esm\"));\n const tmpCjs = toForwardSlash(resolvePath(buildPath, \"_tmp_cjs\"));\n ensureDir(tmpEsm);\n ensureDir(tmpCjs);\n\n await Promise.all([\n build({\n ...sharedOptions,\n format: [\"esm\"],\n dts: pkg.dts !== false,\n outDir: tmpEsm,\n outputOptions: {\n preserveModules: true,\n preserveModulesRoot: srcDir,\n },\n }),\n build({\n ...sharedOptions,\n format: [\"cjs\"],\n // CJS skips DTS — types are served from ESM declarations (see package-json.ts).\n dts: false,\n outDir: tmpCjs,\n }),\n ]);\n\n reorganiseOutput(tmpEsm, buildPath, [\"esm\"], pkg, true);\n // keepNativeExtension=true: CJS files come out as .cjs from tsdown; we keep that\n // extension so the exports map (./cjs/index.cjs) resolves correctly.\n reorganiseOutput(tmpCjs, buildPath, [\"cjs\"], pkg, false, true);\n rmTmp(tmpEsm);\n rmTmp(tmpCjs);\n } else {\n // Single build: either one format only, or preserveModules disabled.\n const tmpDir = toForwardSlash(resolvePath(buildPath, \"_tmp\"));\n ensureDir(tmpDir);\n\n await build({\n ...sharedOptions,\n format: formats as (\"esm\" | \"cjs\")[],\n dts: pkg.dts !== false,\n outDir: tmpDir,\n ...(shouldPreserveModules && formats.includes(\"esm\")\n ? { outputOptions: { preserveModules: true, preserveModulesRoot: srcDir } }\n : {}),\n });\n\n reorganiseOutput(tmpDir, buildPath, formats as (\"esm\" | \"cjs\")[], pkg, shouldPreserveModules);\n rmTmp(tmpDir);\n }\n } catch (err) {\n throw wrapError(\"tsdown-build\", pkg.name, err);\n }\n\n logger.success(`Compiled ${pkg.name}`);\n}\n\nfunction rmTmp(dir: string): void {\n try {\n fs.rmSync(dir, { recursive: true, force: true });\n } catch {\n // non-fatal — stale tmp is harmless\n }\n}\n\n// ─── Output reorganisation ──────────────────────────────────────────────────\n\n/**\n * Move the flat tsdown output (in tmpDir) into `esm/` and `cjs/` subdirectories\n * under buildPath. Renames .mjs → .js and .cjs → .js so that relative imports\n * inside each format directory resolve correctly.\n */\nfunction reorganiseOutput(\n tmpDir: string,\n buildPath: string,\n formats: (\"esm\" | \"cjs\")[],\n pkg: PackageBase,\n preserveModules: boolean,\n keepNativeExtension = false,\n): void {\n const esmDir = joinPath(buildPath, \"esm\");\n const cjsDir = joinPath(buildPath, \"cjs\");\n\n if (formats.includes(\"esm\")) ensureDir(esmDir);\n if (formats.includes(\"cjs\")) ensureDir(cjsDir);\n\n const mainType = pkg.mainType ?? (formats.includes(\"cjs\") ? \"cjs\" : \"esm\");\n\n processDirectory(tmpDir, { esmDir, cjsDir, formats, mainType, pkg, tmpDir, preserveModules, keepNativeExtension });\n}\n\ninterface ReorgContext {\n esmDir: string;\n cjsDir: string;\n formats: (\"esm\" | \"cjs\")[];\n mainType: \"esm\" | \"cjs\";\n pkg: PackageBase;\n /** Absolute path to the flat _tmp/ directory — used to compute relative paths when preserveModules is on. */\n tmpDir: string;\n preserveModules: boolean;\n /**\n * When true, keep the native .mjs/.cjs extensions instead of normalising to .js.\n * Used in the CJS-only leg of the two-build path so the final file stays .cjs.\n */\n keepNativeExtension: boolean;\n}\n\nfunction processDirectory(dir: string, ctx: ReorgContext): void {\n if (!fs.existsSync(dir)) return;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = joinPath(dir, entry.name);\n if (entry.isDirectory()) {\n // Recursively handle subdirectories (chunk splits, etc.)\n processDirectory(fullPath, ctx);\n } else {\n processFile(fullPath, entry.name, ctx);\n }\n }\n}\n\nfunction processFile(filePath: string, name: string, ctx: ReorgContext): void {\n const { esmDir, cjsDir, formats, mainType, pkg, tmpDir, preserveModules } = ctx;\n\n // Relative subdirectory from the tmp root — preserves folder structure for both\n // preserveModules output and multi-entry single-bundle output (where each entry\n // lands in its own subdirectory, e.g. cli/index.cjs).\n // path.relative may return backslashes on Windows — normalise to forward slashes.\n const relDir = toForwardSlash(path.relative(tmpDir, path.dirname(filePath)));\n\n if (preserveModules) {\n if (isEsmFile(name)) {\n if (formats.includes(\"esm\")) {\n moveFile(filePath, joinPath(esmDir, relDir, name), pkg.name);\n }\n } else if (isCjsFile(name)) {\n if (formats.includes(\"cjs\")) {\n moveFile(filePath, joinPath(cjsDir, relDir, name), pkg.name);\n }\n } else if (isDtsFile(name)) {\n const targetDir = formats.includes(\"esm\") ? esmDir : cjsDir;\n moveFile(filePath, joinPath(targetDir, relDir, name), pkg.name);\n }\n // Unknown extensions silently ignored.\n return;\n }\n\n // ── Single-bundle mode ──────────────────────────────────────────────────────\n const { keepNativeExtension } = ctx;\n\n if (isEsmFile(name)) {\n if (formats.includes(\"esm\")) {\n const destName = keepNativeExtension ? name : normaliseEsmName(name);\n moveFile(filePath, joinPath(esmDir, relDir, destName), pkg.name);\n }\n } else if (isCjsFile(name)) {\n if (formats.includes(\"cjs\")) {\n const destName = keepNativeExtension ? name : normaliseCjsName(name);\n moveFile(filePath, joinPath(cjsDir, relDir, destName), pkg.name);\n }\n } else if (isDtsFile(name)) {\n const targetDir = formats.includes(\"esm\") ? esmDir : cjsDir;\n moveFile(filePath, joinPath(targetDir, relDir, name), pkg.name);\n } else if (isJsFile(name)) {\n // Plain .js / .js.map — emitted when the format array contains only one format\n // (tsdown uses .js instead of .mjs/.cjs when there's no other format to differentiate from).\n const targetDir = mainType === \"esm\" ? esmDir : cjsDir;\n if (formats.includes(mainType)) {\n // Files landing in cjsDir should use the .cjs extension for consistency.\n const destName =\n targetDir === cjsDir\n ? name.replace(/\\.js\\.map$/, \".cjs.map\").replace(/\\.js$/, \".cjs\")\n : name;\n moveFile(filePath, joinPath(targetDir, relDir, destName), pkg.name);\n }\n }\n // Unknown extensions are silently ignored.\n}\n\n// ─── Extension predicates ───────────────────────────────────────────────────\n\nfunction isEsmFile(name: string): boolean {\n return (\n name.endsWith(\".mjs\") ||\n name.endsWith(\".mjs.map\") ||\n name.endsWith(\".d.mts\") ||\n name.endsWith(\".d.mts.map\")\n );\n}\n\nfunction isCjsFile(name: string): boolean {\n return (\n name.endsWith(\".cjs\") ||\n name.endsWith(\".cjs.map\") ||\n name.endsWith(\".d.cts\") ||\n name.endsWith(\".d.cts.map\")\n );\n}\n\nfunction isDtsFile(name: string): boolean {\n return name.endsWith(\".d.ts\") || name.endsWith(\".d.ts.map\");\n}\n\nfunction isJsFile(name: string): boolean {\n return (\n (name.endsWith(\".js\") || name.endsWith(\".js.map\")) &&\n !name.endsWith(\".d.ts\") &&\n !name.endsWith(\".d.ts.map\")\n );\n}\n\n// ─── Name normalisation ─────────────────────────────────────────────────────\n\n/** Rename .mjs / .d.mts → .js / .d.ts for the esm/ directory. */\nfunction normaliseEsmName(name: string): string {\n return name\n .replace(/\\.mjs\\.map$/, \".js.map\")\n .replace(/\\.mjs$/, \".js\")\n .replace(/\\.d\\.mts\\.map$/, \".d.ts.map\")\n .replace(/\\.d\\.mts$/, \".d.ts\");\n}\n\n/** Rename .cjs / .d.cts → .js / .d.ts for the cjs/ directory. */\nfunction normaliseCjsName(name: string): string {\n return name\n .replace(/\\.cjs\\.map$/, \".js.map\")\n .replace(/\\.cjs$/, \".js\")\n .replace(/\\.d\\.cts\\.map$/, \".d.ts.map\")\n .replace(/\\.d\\.cts$/, \".d.ts\");\n}\n","import semver from \"semver\";\nimport { wrapError } from \"../utils/errors.js\";\n\n/**\n * Given the current version string and a version strategy, return the new version.\n *\n * @param currentVersion semver string from source package.json, e.g. \"1.2.3\"\n * @param strategy \"auto\" / \"patch\" → patch bump\n * \"minor\" → minor bump\n * \"major\" → major bump\n * any valid semver string → use as-is\n * @param packageName used in error messages only\n */\nexport function resolveVersion(\n currentVersion: string,\n strategy: \"auto\" | \"patch\" | \"minor\" | \"major\" | string = \"auto\",\n packageName: string,\n): string {\n const bumpType =\n strategy === \"auto\" || strategy === \"patch\" ? \"patch\"\n : strategy === \"minor\" ? \"minor\"\n : strategy === \"major\" ? \"major\"\n : null;\n\n if (bumpType) {\n const bumped = semver.inc(currentVersion, bumpType);\n if (!bumped) {\n throw wrapError(\n \"version-increment\",\n packageName,\n new Error(\n `Cannot ${bumpType}-bump invalid semver version \"${currentVersion}\" for package \"${packageName}\"`,\n ),\n );\n }\n return bumped;\n }\n\n // Explicit version string — validate it\n const cleaned = semver.valid(semver.coerce(strategy) ?? strategy);\n if (!cleaned) {\n throw wrapError(\n \"version-increment\",\n packageName,\n new Error(\n `Explicit version \"${strategy}\" is not a valid semver string for package \"${packageName}\"`,\n ),\n );\n }\n return cleaned;\n}\n","import simpleGit, { SimpleGit } from \"simple-git\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { joinPath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\n\n/**\n * Returns true if the given directory is inside a git repository.\n */\nexport async function isGitRepo(dir: string): Promise<boolean> {\n try {\n const git: SimpleGit = simpleGit(dir);\n const result = await git.checkIsRepo();\n return result;\n } catch {\n return false;\n }\n}\n\n/**\n * Perform git operations for a package after a successful build:\n * 1. git add -A (in the package root)\n * 2. git commit -m <message>\n * 3. git push origin <branch>\n * 4. git tag v<version>\n * 5. git push origin <tag>\n */\nexport async function gitCommitTagPush(\n packageRoot: string,\n packageName: string,\n version: string,\n commitMessage: string,\n branch: string,\n dryRun: boolean,\n): Promise<void> {\n const isRepo = await isGitRepo(packageRoot);\n if (!isRepo) {\n logger.warn(`[git] ${packageName}: directory is not a git repo — skipping git operations`);\n return;\n }\n\n const tag = `v${version}`;\n logger.step(`[git] ${packageName}: commit \"${commitMessage}\", tag ${tag}, push to ${branch}`);\n\n if (dryRun) {\n logger.info(`[dry-run] git add + commit \"${commitMessage}\" + tag ${tag} + push`);\n return;\n }\n\n const git: SimpleGit = simpleGit(packageRoot);\n\n try {\n // Stage all changes\n await git.add(\"-A\");\n\n // Commit\n await git.commit(commitMessage);\n\n // Push to remote\n await git.push(\"origin\", branch);\n\n // Tag\n await git.addTag(tag);\n\n // Push tags\n await git.pushTags(\"origin\");\n\n logger.success(`[git] ${packageName}: pushed ${branch}, tagged ${tag}`);\n } catch (err) {\n throw wrapError(\"git-operations\", packageName, err);\n }\n}\n\n/**\n * Resolve the current branch name in the given directory.\n * Falls back to \"main\" if the directory is not a git repo.\n */\nexport async function currentBranch(dir: string): Promise<string> {\n try {\n const git: SimpleGit = simpleGit(dir);\n const branch = await git.revparse([\"--abbrev-ref\", \"HEAD\"]);\n return branch.trim() || \"main\";\n } catch {\n return \"main\";\n }\n}\n","import { execa } from \"execa\";\nimport { wrapError } from \"./errors.js\";\n\nexport interface ExecResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\n/**\n * Run a shell command and return stdout/stderr.\n * Throws a BundlerError on non-zero exit.\n */\nexport async function exec(\n step: string,\n packageName: string,\n command: string,\n args: string[],\n cwd?: string,\n): Promise<ExecResult> {\n try {\n const result = await execa(command, args, {\n cwd,\n all: true,\n reject: false,\n });\n if (result.exitCode !== 0) {\n const combined = result.all ?? result.stderr ?? \"\";\n throw new Error(\n `Command \"${command} ${args.join(\" \")}\" exited with code ${result.exitCode}.\\n${combined}`,\n );\n }\n return {\n stdout: result.stdout ?? \"\",\n stderr: result.stderr ?? \"\",\n exitCode: result.exitCode,\n };\n } catch (err) {\n throw wrapError(step, packageName, err);\n }\n}\n\n/**\n * Run a command and ignore its output. Does NOT throw on non-zero exit.\n * Useful for optional operations (e.g. `git tag -d`).\n */\nexport async function execSilent(\n command: string,\n args: string[],\n cwd?: string,\n): Promise<number> {\n try {\n const result = await execa(command, args, { cwd, reject: false });\n return result.exitCode ?? 0;\n } catch {\n return 1;\n }\n}\n","import { exec } from \"../utils/exec.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { PackageBase } from \"../types/index.js\";\n\n/**\n * Run `npm publish` from the build output directory.\n */\nexport async function publishPackage(\n pkg: PackageBase,\n buildPath: string,\n dryRun: boolean,\n): Promise<void> {\n if (pkg.publish === false) {\n logger.info(`[publish] ${pkg.name}: publish=false, skipping`);\n return;\n }\n\n const access = pkg.access ?? \"public\";\n\n if (dryRun) {\n logger.info(`[dry-run] npm publish --access ${access} from ${buildPath}`);\n return;\n }\n\n logger.step(`Publishing ${pkg.name}@... to npm (access: ${access})`);\n\n await exec(\n \"npm-publish\",\n pkg.name,\n \"npm\",\n [\"publish\", \"--access\", access],\n buildPath,\n );\n\n logger.success(`Published ${pkg.name}`);\n}\n","import path from \"path\";\nimport { copyDir, ensureDir } from \"../files/file-manager.js\";\nimport {\n readSourcePackageJson,\n writeSourceVersion,\n writeBuildPackageJson,\n} from \"../files/package-json.js\";\nimport { cloneFiles } from \"../files/clone-files.js\";\nimport { compilePackage } from \"../compile/tsdown-compiler.js\";\nimport { resolveVersion } from \"../version/increment.js\";\nimport { gitCommitTagPush, currentBranch } from \"../git/operations.js\";\nimport { publishPackage } from \"../publish/npm-publisher.js\";\nimport { buildOutputPath, sourceSnapshotPath, resolvePath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { PackageBase, BuildOptions, BuilderSettings } from \"../types/index.js\";\n\nexport interface BuildResult {\n packageName: string;\n version: string;\n buildPath: string;\n success: boolean;\n error?: Error;\n}\n\n/**\n * Execute the full build pipeline for a single package.\n *\n * Steps:\n * 1. Resolve package root\n * 2. Read source package.json → current version\n * 3. Compute new version\n * 4. Create build output directory\n * 5. Source snapshot (optional)\n * 6. tsdown compile\n * 7. Clone extra files\n * 8. Write build package.json\n * 9. Update source package.json version\n * 10. Git: add, commit, push, tag\n * 11. npm publish\n */\nexport async function buildPackage(\n pkg: PackageBase,\n versionStrategy: \"auto\" | string = \"auto\",\n settings: BuilderSettings,\n options: BuildOptions,\n configDir: string,\n /**\n * Override commit message (used by family builder to apply a shared message).\n * If undefined, uses pkg.commit.\n */\n overrideCommit?: string,\n /**\n * Pre-resolved version — used when a family has already determined the version\n * and needs all member packages to use the same one.\n */\n forcedVersion?: string,\n): Promise<BuildResult> {\n const step = \"package-builder\";\n\n try {\n // 1. Resolve absolute package root\n const packageRoot = resolvePath(configDir, pkg.root);\n\n // 2. Read source package.json\n const sourceJson = readSourcePackageJson(packageRoot, pkg.name);\n const currentVersion = sourceJson.version;\n\n // 3. Determine new version\n const newVersion =\n forcedVersion ?? resolveVersion(currentVersion, versionStrategy, pkg.name);\n\n logger.info(`Building ${pkg.name}: ${currentVersion} → ${newVersion}`);\n\n // 4. Build output directory\n const absoluteBuildDir = resolvePath(configDir, settings.buildDir);\n const buildPath = buildOutputPath(absoluteBuildDir, pkg.name, newVersion);\n\n if (!options.dryRun) {\n ensureDir(buildPath);\n }\n\n // 5. Source snapshot\n if (settings.sourcesDir) {\n const absoluteSourcesDir = resolvePath(configDir, settings.sourcesDir);\n const snapshotPath = sourceSnapshotPath(absoluteSourcesDir, pkg.name);\n if (options.dryRun) {\n logger.info(`[dry-run] snapshot ${packageRoot} → ${snapshotPath}`);\n } else {\n ensureDir(snapshotPath);\n copyDir(packageRoot, snapshotPath);\n logger.debug(`Snapshot: ${packageRoot} → ${snapshotPath}`);\n }\n }\n\n // 6. Compile with tsdown\n await compilePackage(pkg, packageRoot, buildPath, sourceJson as Record<string, unknown>, options.dryRun);\n\n // 7. Clone extra files\n if (pkg.clone && pkg.clone.length > 0) {\n cloneFiles(packageRoot, buildPath, pkg.clone, pkg.name, options.dryRun);\n }\n\n // 8. Write build package.json\n if (!options.dryRun) {\n writeBuildPackageJson(pkg, sourceJson, buildPath, newVersion);\n logger.debug(`Wrote build package.json for ${pkg.name}@${newVersion}`);\n } else {\n logger.info(`[dry-run] write build package.json for ${pkg.name}@${newVersion}`);\n }\n\n // 9. Update source package.json version\n if (!options.dryRun) {\n writeSourceVersion(packageRoot, pkg.name, newVersion);\n logger.debug(`Updated source version ${pkg.name} → ${newVersion}`);\n } else {\n logger.info(`[dry-run] update source package.json version → ${newVersion}`);\n }\n\n // 10. Git operations (only if commit message is set and --no-git is not passed)\n const commitMessage = overrideCommit ?? pkg.commit;\n if (commitMessage && !options.noGit) {\n const branch = pkg.branch ?? (await currentBranch(packageRoot));\n await gitCommitTagPush(\n packageRoot,\n pkg.name,\n newVersion,\n commitMessage,\n branch,\n options.dryRun,\n );\n } else if (!commitMessage) {\n logger.debug(`[git] ${pkg.name}: no commit message set — skipping git`);\n }\n\n // 11. npm publish\n if (!options.noPublish) {\n await publishPackage(pkg, buildPath, options.dryRun);\n } else {\n logger.info(`[publish] ${pkg.name}: --no-publish, skipping`);\n }\n\n return { packageName: pkg.name, version: newVersion, buildPath, success: true };\n } catch (err) {\n const wrapped = wrapError(step, pkg.name, err);\n logger.error(`Failed to build ${pkg.name}: ${wrapped.message}`);\n return {\n packageName: pkg.name,\n version: \"\",\n buildPath: \"\",\n success: false,\n error: wrapped,\n };\n }\n}\n","import semver from \"semver\";\nimport { readSourcePackageJson } from \"../files/package-json.js\";\nimport { resolveVersion } from \"../version/increment.js\";\nimport { resolvePath } from \"../utils/paths.js\";\nimport { buildPackage } from \"./package-builder.js\";\nimport { runParallel } from \"./parallel-builder.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { Family, BuildOptions, BuilderSettings } from \"../types/index.js\";\nimport type { BuildResult } from \"./package-builder.js\";\n\n/**\n * Build all packages in a family using a single shared version.\n *\n * The shared version is determined by taking the HIGHEST current version\n * across all family members and bumping it. This prevents a lower-versioned\n * member (e.g. atomic-query@0.1.0) from pulling down a higher-versioned one\n * (e.g. react-atom@5.1.3) when they are first unified.\n */\nexport async function buildFamily(\n family: Family,\n settings: BuilderSettings,\n options: BuildOptions,\n configDir: string,\n): Promise<BuildResult[]> {\n if (family.packages.length === 0) {\n logger.warn(`Family \"${family.name}\" has no packages — nothing to build`);\n return [];\n }\n\n let newVersion: string;\n try {\n const strategy = family.version ?? \"auto\";\n const isBumpKeyword = strategy === \"auto\" || strategy === \"patch\" || strategy === \"minor\" || strategy === \"major\";\n\n if (!isBumpKeyword && semver.valid(semver.coerce(strategy) ?? strategy)) {\n // Explicit semver string — use as-is\n newVersion = strategy;\n } else {\n // Bump keyword — find the highest current version across all family members, then bump it\n let highestVersion = \"0.0.0\";\n for (const pkg of family.packages) {\n const root = resolvePath(configDir, pkg.root);\n const sourceJson = readSourcePackageJson(root, pkg.name);\n const v = sourceJson.version ?? \"0.0.0\";\n if (semver.gt(v, highestVersion)) {\n highestVersion = v;\n }\n }\n newVersion = resolveVersion(highestVersion, strategy, family.name);\n }\n } catch (err) {\n throw wrapError(\"family-version\", family.name, err);\n }\n\n logger.info(`Family \"${family.name}\": shared version → ${newVersion} (${family.packages.length} packages)`);\n\n const concurrency = options.concurrency ?? settings.concurrency ?? 4;\n\n // The family commit message overrides per-package commit messages\n const familyCommit = family.commit;\n\n const tasks = family.packages.map((pkg) => () =>\n buildPackage(\n pkg,\n \"auto\", // not used — forcedVersion overrides\n settings,\n options,\n configDir,\n familyCommit ?? pkg.commit,\n newVersion, // all packages use the same version\n ),\n );\n\n return runParallel(tasks, concurrency);\n}\n","import pLimit from \"p-limit\";\nimport type { BuildResult } from \"./package-builder.js\";\nimport { logger } from \"../utils/logger.js\";\n\n/**\n * Run an array of async build tasks with a concurrency cap.\n * Each task is a zero-argument function that returns a Promise<BuildResult>.\n */\nexport async function runParallel(\n tasks: (() => Promise<BuildResult>)[],\n concurrency: number,\n): Promise<BuildResult[]> {\n if (tasks.length === 0) return [];\n\n const limit = pLimit(Math.max(1, concurrency));\n\n logger.info(`Running ${tasks.length} task(s) with concurrency=${concurrency}`);\n\n const results = await Promise.all(\n tasks.map((task) => limit(task)),\n );\n\n const succeeded = results.filter((r) => r.success).length;\n const failed = results.filter((r) => !r.success).length;\n\n if (failed > 0) {\n logger.warn(`${succeeded} succeeded, ${failed} failed`);\n for (const r of results.filter((r) => !r.success)) {\n logger.error(` FAILED: ${r.packageName} — ${r.error?.message ?? \"unknown error\"}`);\n }\n } else {\n logger.success(`All ${succeeded} package(s) built successfully`);\n }\n\n return results;\n}\n"],"mappings":";AAMO,SAAS,aAAa,QAAsC;AACjE,SAAO;AACT;;;ACRA,OAAOA,WAAU;AACjB,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;;;ACFf,OAAO,UAAU;AAGV,SAAS,eAAe,GAAmB;AAChD,SAAO,EAAE,QAAQ,OAAO,GAAG;AAC7B;AAGO,SAAS,YAAY,UAA4B;AACtD,SAAO,eAAe,KAAK,KAAK,GAAG,QAAQ,CAAC;AAC9C;AAGO,SAAS,eAAe,UAA4B;AACzD,SAAO,eAAe,KAAK,QAAQ,GAAG,QAAQ,CAAC;AACjD;AAMO,SAAS,cAAc,aAA6B;AACzD,QAAM,QAAQ,YAAY,QAAQ,GAAG;AACrC,SAAO,UAAU,KAAK,cAAc,YAAY,MAAM,QAAQ,CAAC;AACjE;AAMO,SAAS,gBACd,UACA,aACA,SACQ;AACR,SAAO,SAAS,UAAU,cAAc,WAAW,GAAG,OAAO;AAC/D;AAMO,SAAS,mBACd,YACA,aACQ;AACR,SAAO,SAAS,YAAY,cAAc,WAAW,CAAC;AACxD;;;AC9CO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACkB,MACA,aAChB,SACgB,OAChB;AACA,UAAM,OAAO;A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O;AAE5B,QAAM,QAAQ,OAAO,SAAS;AAAA,IAAI,CAAC,QAAQ,MACzC;AAAA,MACE;AAAA,MACA;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB,IAAI;AAAA,MACpB;AAAA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,YAAY,OAAO,WAAW;AACvC;","names":["path","path","fs","path","fs","path","fs","fs","path","fs","fs","path","semver","r","semver"]}
|
|
1
|
+
{"version":3,"sources":["../src/config/define-config.ts","../src/config/load-config.ts","../src/utils/paths.ts","../src/utils/errors.ts","../src/files/file-manager.ts","../src/files/package-json.ts","../src/files/clone-files.ts","../src/utils/logger.ts","../src/compile/tsdown-compiler.ts","../src/version/increment.ts","../src/git/operations.ts","../src/utils/exec.ts","../src/publish/npm-publisher.ts","../src/build/package-builder.ts","../src/build/family-builder.ts","../src/build/parallel-builder.ts"],"sourcesContent":["import type { BundlerConfig } from \"../types/index.js\";\n\n/**\n * Type-safe config factory.\n * Simply returns the config object unchanged — used purely for IDE autocomplete and type checking.\n */\nexport function defineConfig(config: BundlerConfig): BundlerConfig {\n return config;\n}\n","import path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport fs from \"fs\";\nimport type { BundlerConfig } from \"../types/index.js\";\nimport { resolvePath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\n\nexport interface LoadedConfig {\n config: BundlerConfig;\n /** Absolute, forward-slash normalised path to the config file */\n configPath: string;\n /** Directory containing the config file — used to resolve relative roots */\n configDir: string;\n}\n\n/**\n * Register tsx as a Node loader so TypeScript config files can be imported\n * directly via dynamic import(). Safe to call multiple times — tsx is only\n * registered once. No-ops when tsx is not installed (JS-only config still works).\n */\nasync function ensureTsxRegistered(): Promise<void> {\n try {\n const { register } = await import(\"node:module\");\n let tsxUrl: string | null = null;\n try {\n tsxUrl = import.meta.resolve(\"tsx/esm\");\n } catch {\n // tsx not installed — JS-only configs still work fine\n }\n if (register && tsxUrl) {\n register(tsxUrl, import.meta.url);\n }\n } catch {\n // node:module unavailable (old Node) — fall through silently\n }\n}\n\n/** Load and validate a pkgist config file (TypeScript or JavaScript). */\nexport async function loadConfig(configFilePath: string): Promise<LoadedConfig> {\n const absolute = resolvePath(configFilePath);\n\n if (!fs.existsSync(absolute)) {\n throw new Error(`Config file not found: ${absolute}`);\n }\n\n let mod: { default?: BundlerConfig };\n\n try {\n // Register tsx so .ts config files import without the user needing\n // to prefix the command with `node --import tsx/esm`.\n if (absolute.endsWith(\".ts\")) {\n await ensureTsxRegistered();\n }\n\n // Convert to a file:// URL so dynamic import works correctly on Windows.\n const fileUrl = pathToFileURL(absolute).href;\n mod = await import(fileUrl);\n } catch (err) {\n throw wrapError(\"load-config\", absolute, err);\n }\n\n const config = mod.default;\n\n if (!config || typeof config !== \"object\") {\n throw new Error(\n `Config file ${absolute} must export a default object from defineConfig(). Got: ${typeof config}`,\n );\n }\n\n validateConfig(config, absolute);\n\n return {\n config,\n configPath: absolute,\n configDir: resolvePath(path.dirname(absolute)),\n };\n}\n\nfunction validateConfig(config: BundlerConfig, filePath: string): void {\n if (!config.settings) {\n throw new Error(`Config \"${filePath}\" must have a \"settings\" object.`);\n }\n if (!config.settings.buildDir) {\n throw new Error(`Config \"${filePath}\" settings.buildDir is required.`);\n }\n\n const names = new Set<string>();\n\n for (const pkg of config.standalone ?? []) {\n if (!pkg.name) throw new Error(`Standalone package is missing \"name\" in ${filePath}`);\n if (!pkg.root) throw new Error(`Standalone package \"${pkg.name}\" is missing \"root\"`);\n if (names.has(pkg.name)) throw new Error(`Duplicate package name: \"${pkg.name}\"`);\n names.add(pkg.name);\n }\n\n for (const family of config.families ?? []) {\n if (!family.name) throw new Error(`A family is missing \"name\" in ${filePath}`);\n for (const pkg of family.packages) {\n if (!pkg.name) throw new Error(`Package inside family \"${family.name}\" is missing \"name\"`);\n if (!pkg.root) throw new Error(`Package \"${pkg.name}\" in family \"${family.name}\" is missing \"root\"`);\n if (names.has(pkg.name)) throw new Error(`Duplicate package name: \"${pkg.name}\"`);\n names.add(pkg.name);\n }\n }\n}\n\n/**\n * Attempt to find the default config file in the working directory.\n * Tries: builder.ts, builder.js, mongez.ts, mongez.js\n */\nexport function findDefaultConfigPath(cwd: string): string {\n const candidates = [\"pkgist.config.ts\", \"pkgist.config.js\", \"builder.ts\", \"builder.js\", \"mongez.ts\", \"mongez.js\"];\n for (const candidate of candidates) {\n const full = path.join(cwd, candidate);\n if (fs.existsSync(full)) return full;\n }\n throw new Error(\n `No config file found in ${cwd}. Tried: ${candidates.join(\", \")}. ` +\n `Use --config <path> to specify a custom location.`,\n );\n}\n","import path from \"path\";\n\n/** Normalise any path to forward-slash form (Windows-safe). */\nexport function toForwardSlash(p: string): string {\n return p.replace(/\\\\/g, \"/\");\n}\n\n/** Join path segments and normalise the result to forward slashes. */\nexport function joinPath(...segments: string[]): string {\n return toForwardSlash(path.join(...segments));\n}\n\n/** Resolve an absolute path from segments and normalise to forward slashes. */\nexport function resolvePath(...segments: string[]): string {\n return toForwardSlash(path.resolve(...segments));\n}\n\n/**\n * Given a package name like \"@mongez/reinforcements\",\n * return just the scoped part without the scope prefix: \"reinforcements\".\n */\nexport function scopelessName(packageName: string): string {\n const slash = packageName.indexOf(\"/\");\n return slash === -1 ? packageName : packageName.slice(slash + 1);\n}\n\n/**\n * Build the versioned build output path:\n * <buildDir>/<scopeless-name>/<version>/\n */\nexport function buildOutputPath(\n buildDir: string,\n packageName: string,\n version: string,\n): string {\n return joinPath(buildDir, scopelessName(packageName), version);\n}\n\n/**\n * Build the sources snapshot path:\n * <sourcesDir>/<scopeless-name>/\n */\nexport function sourceSnapshotPath(\n sourcesDir: string,\n packageName: string,\n): string {\n return joinPath(sourcesDir, scopelessName(packageName));\n}\n","/** Base error class for all bundler errors. Carries a step name for structured logging. */\nexport class BundlerError extends Error {\n constructor(\n public readonly step: string,\n public readonly packageName: string,\n message: string,\n public readonly cause?: unknown,\n ) {\n super(message);\n this.name = \"BundlerError\";\n if (cause instanceof Error && cause.stack) {\n this.stack = `${this.stack}\\nCaused by: ${cause.stack}`;\n }\n }\n}\n\n/** Wrap any thrown value into a BundlerError with context. */\nexport function wrapError(\n step: string,\n packageName: string,\n error: unknown,\n): BundlerError {\n if (error instanceof BundlerError) return error;\n const msg =\n error instanceof Error\n ? error.message\n : typeof error === \"string\"\n ? error\n : JSON.stringify(error);\n return new BundlerError(step, packageName, `[${step}] ${packageName}: ${msg}`, error);\n}\n\n/** Throw a wrapped error immediately. */\nexport function failWith(\n step: string,\n packageName: string,\n error: unknown,\n): never {\n throw wrapError(step, packageName, error);\n}\n","import fs from \"fs\";\nimport path from \"path\";\nimport { resolvePath, joinPath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\n\n/**\n * Ensure a directory exists, creating all intermediate directories as needed.\n */\nexport function ensureDir(dir: string): void {\n try {\n fs.mkdirSync(dir, { recursive: true });\n } catch (err) {\n throw wrapError(\"ensure-dir\", dir, err);\n }\n}\n\n/**\n * Copy a single file from src to dest.\n * Creates the destination directory if it does not exist.\n */\nexport function copyFile(src: string, dest: string): void {\n ensureDir(path.dirname(dest));\n try {\n fs.copyFileSync(src, dest);\n } catch (err) {\n throw wrapError(\"copy-file\", src, err);\n }\n}\n\n/** Directories that are never copied in any directory tree operation. */\nconst COPY_EXCLUDES = new Set([\".git\", \"node_modules\", \"dist\", \".turbo\", \".cache\"]);\n\n/**\n * Copy an entire directory tree recursively, skipping .git and node_modules.\n */\nexport function copyDir(src: string, dest: string): void {\n ensureDir(dest);\n const entries = fs.readdirSync(src, { withFileTypes: true });\n for (const entry of entries) {\n if (COPY_EXCLUDES.has(entry.name)) continue;\n const srcPath = joinPath(src, entry.name);\n const destPath = joinPath(dest, entry.name);\n if (entry.isDirectory()) {\n copyDir(srcPath, destPath);\n } else {\n copyFile(srcPath, destPath);\n }\n }\n}\n\n/**\n * Read a file as a UTF-8 string, or throw a BundlerError with context.\n */\nexport function readFile(filePath: string, packageName = filePath): string {\n try {\n return fs.readFileSync(filePath, \"utf-8\");\n } catch (err) {\n throw wrapError(\"read-file\", packageName, err);\n }\n}\n\n/**\n * Write a UTF-8 string to a file, creating intermediate directories.\n */\nexport function writeFile(filePath: string, content: string, packageName = filePath): void {\n ensureDir(path.dirname(filePath));\n try {\n fs.writeFileSync(filePath, content, \"utf-8\");\n } catch (err) {\n throw wrapError(\"write-file\", packageName, err);\n }\n}\n\n/**\n * Move all files matching a glob-like condition.\n * Actually does a rename — works only within the same filesystem volume.\n */\nexport function moveFile(src: string, dest: string, packageName = src): void {\n ensureDir(path.dirname(dest));\n try {\n fs.renameSync(src, dest);\n } catch (err) {\n // rename across devices fails — fall back to copy+unlink\n try {\n fs.copyFileSync(src, dest);\n fs.unlinkSync(src);\n } catch (fallbackErr) {\n throw wrapError(\"move-file\", packageName, fallbackErr);\n }\n }\n}\n\n/**\n * Check whether a path exists on the filesystem.\n */\nexport function pathExists(p: string): boolean {\n return fs.existsSync(p);\n}\n\n/**\n * List all file paths inside a directory (non-recursive).\n */\nexport function listFiles(dir: string): string[] {\n if (!fs.existsSync(dir)) return [];\n return fs\n .readdirSync(dir, { withFileTypes: true })\n .filter((e) => e.isFile())\n .map((e) => joinPath(dir, e.name));\n}\n","import path from \"path\";\nimport { readFile, writeFile } from \"./file-manager.js\";\nimport { joinPath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport type { PackageBase } from \"../types/index.js\";\n\n// Fields kept verbatim from the source package.json into the build package.json.\nconst KEPT_FIELDS = [\n \"name\",\n \"description\",\n \"keywords\",\n \"author\",\n \"license\",\n \"repository\",\n \"homepage\",\n \"bugs\",\n \"dependencies\",\n \"peerDependencies\",\n \"sideEffects\",\n \"bin\",\n \"engines\",\n] as const;\n\nexport type SourcePackageJson = Record<string, unknown> & {\n version: string;\n dependencies?: Record<string, string>;\n peerDependencies?: Record<string, string>;\n};\n\n/**\n * Read and parse the package.json at <packageRoot>/package.json.\n * Throws a BundlerError if the file is missing or malformed.\n */\nexport function readSourcePackageJson(\n packageRoot: string,\n packageName: string,\n): SourcePackageJson {\n const pkgPath = joinPath(packageRoot, \"package.json\");\n let raw: string;\n try {\n raw = readFile(pkgPath, packageName);\n } catch {\n throw wrapError(\n \"read-package-json\",\n packageName,\n new Error(`package.json not found at ${pkgPath}`),\n );\n }\n\n try {\n const parsed = JSON.parse(raw) as SourcePackageJson;\n if (!parsed.version) {\n throw new Error(`package.json at ${pkgPath} is missing \"version\" field`);\n }\n return parsed;\n } catch (err) {\n throw wrapError(\"parse-package-json\", packageName, err);\n }\n}\n\n/**\n * Write the new version back into the source package.json.\n */\nexport function writeSourceVersion(\n packageRoot: string,\n packageName: string,\n newVersion: string,\n): void {\n const pkgPath = joinPath(packageRoot, \"package.json\");\n const raw = readFile(pkgPath, packageName);\n const parsed = JSON.parse(raw) as Record<string, unknown>;\n parsed.version = newVersion;\n writeFile(pkgPath, JSON.stringify(parsed, null, 2) + \"\\n\", packageName);\n}\n\n/**\n * Build and write the clean package.json for the build output directory.\n */\nexport function writeBuildPackageJson(\n pkg: PackageBase,\n sourceJson: SourcePackageJson,\n buildPath: string,\n newVersion: string,\n): void {\n const formats = pkg.formats ?? [\"esm\", \"cjs\"];\n const hasEsm = formats.includes(\"esm\");\n const hasCjs = formats.includes(\"cjs\");\n const esmOnly = hasEsm && !hasCjs;\n\n // When preserveModules is on (the default), tsdown keeps one file per source\n // module and uses native extensions (.mjs/.cjs) so internal cross-file imports\n // resolve correctly. When bundling, everything is renamed to .js for simplicity.\n const preserve = pkg.preserveModules !== false;\n const esmExt = preserve ? \".mjs\" : \".js\";\n const cjsExt = preserve ? \".cjs\" : \".js\";\n const esmDts = preserve ? \".d.mts\" : \".d.ts\";\n const cjsDts = preserve ? \".d.cts\" : \".d.ts\";\n\n // Determine entry base names from entries config\n const rawEntries = pkg.entries ?? [\"index.ts\"];\n const entryList = Array.isArray(rawEntries) ? rawEntries : [rawEntries];\n\n /**\n * Convert an entry path (relative to srcDir) into:\n * basePath — path without extension, used to build file paths (e.g. \"cli/index\")\n * exportPath — the key in the exports map (e.g. \"./cli\")\n *\n * When the basename is \"index\" the directory becomes the export path so that\n * `cli/index.ts` maps to `\"./cli\"` and `index.ts` maps to `\".\"`.\n */\n function entryPaths(entry: string): { basePath: string; exportPath: string } {\n const basePath = entry.replace(/\\.tsx?$/, \"\");\n const parts = basePath.split(\"/\");\n const last = parts[parts.length - 1];\n let exportPath: string;\n if (last === \"index\") {\n const dir = parts.slice(0, -1).join(\"/\");\n exportPath = dir ? `./${dir}` : \".\";\n } else {\n exportPath = `./${basePath}`;\n }\n return { basePath, exportPath };\n }\n\n // Primary entry drives `main` / `module` / `types` fields.\n const { basePath: primaryBase } = entryPaths(entryList[0]!);\n\n // Build the full exports map — one condition block per entry.\n const exportsMap: Record<string, unknown> = {};\n\n for (const entry of entryList) {\n const { basePath, exportPath } = entryPaths(entry);\n const conditions: Record<string, unknown> = {};\n\n if (hasEsm) {\n conditions[\"import\"] = {\n types: `./esm/${basePath}${esmDts}`,\n default: `./esm/${basePath}${esmExt}`,\n };\n }\n if (hasCjs) {\n // When preserveModules is on, CJS is built without DTS to avoid a rolldown bug.\n // TypeScript resolves types correctly from the ESM declarations via the exports map.\n const cjsTypes = preserve && hasEsm\n ? `./esm/${basePath}${esmDts}`\n : `./cjs/${basePath}${cjsDts}`;\n conditions[\"require\"] = {\n types: cjsTypes,\n default: `./cjs/${basePath}${cjsExt}`,\n };\n }\n\n exportsMap[exportPath] = conditions;\n }\n\n const output: Record<string, unknown> = {};\n\n // Copy allowed fields from source\n for (const field of KEPT_FIELDS) {\n if (field in sourceJson && sourceJson[field] !== undefined) {\n output[field] = sourceJson[field];\n }\n }\n\n // Override name / version\n output[\"name\"] = pkg.name;\n output[\"version\"] = newVersion;\n\n if (esmOnly) {\n output[\"type\"] = \"module\";\n }\n\n // Entry points\n const mainType = pkg.mainType ?? \"cjs\";\n if (mainType === \"esm\" || esmOnly) {\n output[\"main\"] = `./esm/${primaryBase}${esmExt}`;\n } else {\n output[\"main\"] = `./cjs/${primaryBase}${cjsExt}`;\n }\n\n if (hasEsm) {\n output[\"module\"] = `./esm/${primaryBase}${esmExt}`;\n }\n\n output[\"types\"] = `./esm/${primaryBase}${esmDts}`;\n\n output[\"exports\"] = exportsMap;\n\n const pkgPath = joinPath(buildPath, \"package.json\");\n writeFile(pkgPath, JSON.stringify(output, null, 2) + \"\\n\", pkg.name);\n}\n","import fs from \"fs\";\nimport { copyFile, copyDir, pathExists } from \"./file-manager.js\";\nimport { joinPath } from \"../utils/paths.js\";\nimport { logger } from \"../utils/logger.js\";\n\n/**\n * Clone extra files (README, license, etc.) from the package root into the build directory.\n *\n * Each entry in the `clone` array can be:\n * - a plain string: copied from `<packageRoot>/<str>` to `<buildDir>/<str>`\n * - a tuple [src, dest]: copied from `<packageRoot>/<src>` to `<buildDir>/<dest>`\n */\nexport function cloneFiles(\n packageRoot: string,\n buildDir: string,\n cloneList: (string | [string, string])[],\n packageName: string,\n dryRun: boolean,\n): void {\n for (const entry of cloneList) {\n const [srcRel, destRel] =\n typeof entry === \"string\" ? [entry, entry] : entry;\n\n const src = joinPath(packageRoot, srcRel);\n const dest = joinPath(buildDir, destRel);\n\n if (!pathExists(src)) {\n logger.warn(`[clone-files] ${packageName}: source file not found, skipping — ${src}`);\n continue;\n }\n\n if (dryRun) {\n logger.info(`[dry-run] clone ${src} → ${dest}`);\n continue;\n }\n\n const stat = fs.statSync(src);\n if (stat.isDirectory()) {\n copyDir(src, dest);\n } else {\n copyFile(src, dest);\n }\n logger.debug(`Cloned ${src} → ${dest}`);\n }\n}\n","import chalk from \"chalk\";\n\nexport type LogLevel = \"info\" | \"success\" | \"warn\" | \"error\" | \"debug\" | \"step\";\n\nlet _verbose = false;\n\nexport function setVerbose(v: boolean): void {\n _verbose = v;\n}\n\nexport function log(level: LogLevel, message: string): void {\n const ts = new Date().toISOString().replace(\"T\", \" \").replace(\"Z\", \"\");\n switch (level) {\n case \"info\":\n console.log(chalk.cyan(`[${ts}] INFO ${message}`));\n break;\n case \"success\":\n console.log(chalk.green(`[${ts}] OK ${message}`));\n break;\n case \"warn\":\n console.warn(chalk.yellow(`[${ts}] WARN ${message}`));\n break;\n case \"error\":\n console.error(chalk.red(`[${ts}] ERROR ${message}`));\n break;\n case \"step\":\n console.log(chalk.blueBright(`[${ts}] STEP ${message}`));\n break;\n case \"debug\":\n if (_verbose) {\n console.log(chalk.gray(`[${ts}] DEBUG ${message}`));\n }\n break;\n }\n}\n\nexport const logger = {\n info: (msg: string) => log(\"info\", msg),\n success: (msg: string) => log(\"success\", msg),\n warn: (msg: string) => log(\"warn\", msg),\n error: (msg: string) => log(\"error\", msg),\n step: (msg: string) => log(\"step\", msg),\n debug: (msg: string) => log(\"debug\", msg),\n};\n","import path from \"path\";\nimport fs from \"fs\";\nimport { build } from \"tsdown\";\nimport type { InputOptions } from \"rolldown\";\nimport type { PackageBase } from \"../types/index.js\";\nimport { joinPath, toForwardSlash, resolvePath } from \"../utils/paths.js\";\nimport { ensureDir, moveFile, listFiles, pathExists } from \"../files/file-manager.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\n\n// ─── Helpers ───────────────────────────────────────────────────────────────\n\n/**\n * Collect all dependency names that should be treated as external.\n * Both `dependencies` and `peerDependencies` must never be bundled.\n */\nfunction collectExternals(sourceJson: Record<string, unknown>): string[] {\n const deps = Object.keys((sourceJson[\"dependencies\"] as Record<string, string> | undefined) ?? {});\n const peers = Object.keys((sourceJson[\"peerDependencies\"] as Record<string, string> | undefined) ?? {});\n return [...new Set([...deps, ...peers])];\n}\n\n/**\n * Resolve entry file paths to absolute forward-slash paths.\n */\nfunction resolveEntries(pkg: PackageBase, packageRoot: string): string[] {\n const srcDir = pkg.srcDir ?? \"src\";\n const rawEntries = pkg.entries ?? [\"index.ts\"];\n const entryList = Array.isArray(rawEntries) ? rawEntries : [rawEntries];\n return entryList.map((e) => toForwardSlash(resolvePath(packageRoot, srcDir, e)));\n}\n\n/**\n * Return the path to the tsconfig.json inside the package root, if it exists.\n */\nfunction findTsconfig(packageRoot: string): string | undefined {\n const local = joinPath(packageRoot, \"tsconfig.json\");\n return pathExists(local) ? local : undefined;\n}\n\n// ─── Main compiler ──────────────────────────────────────────────────────────\n\n/**\n * Compile a single package using tsdown.\n *\n * When `preserveModules` is on (the default), we run two separate tsdown builds\n * in parallel so that each format's output options are fully independent:\n *\n * ESM build — preserveModules: true, dts: true → _tmp_esm/ → esm/*.mjs + *.d.mts\n * CJS build — preserveModules: false, dts: false → _tmp_cjs/ → cjs/*.cjs\n *\n * CJS skips DTS because rolldown has a bug in CJS preserveModules mode where\n * `export { default as X }` assigns the whole module object to exports.X instead\n * of unwrapping .default. Bundled CJS has no such issue. Types are shared from\n * the ESM declarations (TypeScript resolves them correctly via the exports map).\n *\n * When `preserveModules` is false, a single combined build is used.\n */\nexport async function compilePackage(\n pkg: PackageBase,\n packageRoot: string,\n buildPath: string,\n sourceJson: Record<string, unknown>,\n dryRun: boolean,\n): Promise<void> {\n if (dryRun) {\n logger.info(`[dry-run] compile ${pkg.name} → ${buildPath}`);\n return;\n }\n\n const entries = resolveEntries(pkg, packageRoot);\n const formats = pkg.formats ?? [\"esm\", \"cjs\"];\n const externals = collectExternals(sourceJson);\n const tsconfig = findTsconfig(packageRoot);\n const shouldPreserveModules = pkg.preserveModules !== false;\n const srcDir = toForwardSlash(resolvePath(packageRoot, pkg.srcDir ?? \"src\"));\n\n logger.step(`Compiling ${pkg.name} (${formats.join(\", \")}) → ${buildPath}`);\n logger.debug(` entries: ${entries.join(\", \")}`);\n logger.debug(` externals: ${externals.slice(0, 8).join(\", \")}${externals.length > 8 ? \"…\" : \"\"}`);\n\n // Wipe any previous esm/ and cjs/ output so re-runs of the same version don't\n // leave stale files from a different build mode.\n for (const subDir of [\"esm\", \"cjs\"]) {\n const dir = resolvePath(buildPath, subDir);\n if (fs.existsSync(dir)) {\n fs.rmSync(dir, { recursive: true, force: true });\n }\n }\n\n // Build inputOptions for rolldown — used to set the JSX transform for React packages.\n const rolldownInputOptions: InputOptions | undefined =\n pkg.type === \"react\"\n ? {\n transform: {\n jsx: \"react-jsx\", // automatic runtime — works with React 17+\n },\n }\n : undefined;\n\n // Common options shared across all tsdown invocations.\n const sharedOptions = {\n entry: entries,\n deps: { neverBundle: externals },\n sourcemap: pkg.sourcemap !== false,\n clean: true,\n minify: pkg.minify ?? false,\n tsconfig: tsconfig ?? true,\n ...(rolldownInputOptions ? { inputOptions: rolldownInputOptions } : {}),\n } as const;\n\n try {\n if (shouldPreserveModules && formats.includes(\"esm\") && formats.includes(\"cjs\")) {\n // Two parallel builds: ESM with preserveModules + DTS, CJS bundled without DTS.\n const tmpEsm = toForwardSlash(resolvePath(buildPath, \"_tmp_esm\"));\n const tmpCjs = toForwardSlash(resolvePath(buildPath, \"_tmp_cjs\"));\n ensureDir(tmpEsm);\n ensureDir(tmpCjs);\n\n await Promise.all([\n build({\n ...sharedOptions,\n format: [\"esm\"],\n dts: pkg.dts !== false,\n outDir: tmpEsm,\n outputOptions: {\n preserveModules: true,\n preserveModulesRoot: srcDir,\n },\n }),\n build({\n ...sharedOptions,\n format: [\"cjs\"],\n // CJS skips DTS — types are served from ESM declarations (see package-json.ts).\n dts: false,\n outDir: tmpCjs,\n }),\n ]);\n\n reorganiseOutput(tmpEsm, buildPath, [\"esm\"], pkg, true);\n // keepNativeExtension=true: CJS files come out as .cjs from tsdown; we keep that\n // extension so the exports map (./cjs/index.cjs) resolves correctly.\n reorganiseOutput(tmpCjs, buildPath, [\"cjs\"], pkg, false, true);\n rmTmp(tmpEsm);\n rmTmp(tmpCjs);\n } else {\n // Single build: either one format only, or preserveModules disabled.\n const tmpDir = toForwardSlash(resolvePath(buildPath, \"_tmp\"));\n ensureDir(tmpDir);\n\n await build({\n ...sharedOptions,\n format: formats as (\"esm\" | \"cjs\")[],\n dts: pkg.dts !== false,\n outDir: tmpDir,\n ...(shouldPreserveModules && formats.includes(\"esm\")\n ? { outputOptions: { preserveModules: true, preserveModulesRoot: srcDir } }\n : {}),\n });\n\n reorganiseOutput(tmpDir, buildPath, formats as (\"esm\" | \"cjs\")[], pkg, shouldPreserveModules);\n rmTmp(tmpDir);\n }\n } catch (err) {\n throw wrapError(\"tsdown-build\", pkg.name, err);\n }\n\n logger.success(`Compiled ${pkg.name}`);\n}\n\nfunction rmTmp(dir: string): void {\n try {\n fs.rmSync(dir, { recursive: true, force: true });\n } catch {\n // non-fatal — stale tmp is harmless\n }\n}\n\n// ─── Output reorganisation ──────────────────────────────────────────────────\n\n/**\n * Move the flat tsdown output (in tmpDir) into `esm/` and `cjs/` subdirectories\n * under buildPath. Renames .mjs → .js and .cjs → .js so that relative imports\n * inside each format directory resolve correctly.\n */\nfunction reorganiseOutput(\n tmpDir: string,\n buildPath: string,\n formats: (\"esm\" | \"cjs\")[],\n pkg: PackageBase,\n preserveModules: boolean,\n keepNativeExtension = false,\n): void {\n const esmDir = joinPath(buildPath, \"esm\");\n const cjsDir = joinPath(buildPath, \"cjs\");\n\n if (formats.includes(\"esm\")) ensureDir(esmDir);\n if (formats.includes(\"cjs\")) ensureDir(cjsDir);\n\n const mainType = pkg.mainType ?? (formats.includes(\"cjs\") ? \"cjs\" : \"esm\");\n\n processDirectory(tmpDir, { esmDir, cjsDir, formats, mainType, pkg, tmpDir, preserveModules, keepNativeExtension });\n}\n\ninterface ReorgContext {\n esmDir: string;\n cjsDir: string;\n formats: (\"esm\" | \"cjs\")[];\n mainType: \"esm\" | \"cjs\";\n pkg: PackageBase;\n /** Absolute path to the flat _tmp/ directory — used to compute relative paths when preserveModules is on. */\n tmpDir: string;\n preserveModules: boolean;\n /**\n * When true, keep the native .mjs/.cjs extensions instead of normalising to .js.\n * Used in the CJS-only leg of the two-build path so the final file stays .cjs.\n */\n keepNativeExtension: boolean;\n}\n\nfunction processDirectory(dir: string, ctx: ReorgContext): void {\n if (!fs.existsSync(dir)) return;\n\n const entries = fs.readdirSync(dir, { withFileTypes: true });\n for (const entry of entries) {\n const fullPath = joinPath(dir, entry.name);\n if (entry.isDirectory()) {\n // Recursively handle subdirectories (chunk splits, etc.)\n processDirectory(fullPath, ctx);\n } else {\n processFile(fullPath, entry.name, ctx);\n }\n }\n}\n\nfunction processFile(filePath: string, name: string, ctx: ReorgContext): void {\n const { esmDir, cjsDir, formats, mainType, pkg, tmpDir, preserveModules } = ctx;\n\n // Relative subdirectory from the tmp root — preserves folder structure for both\n // preserveModules output and multi-entry single-bundle output (where each entry\n // lands in its own subdirectory, e.g. cli/index.cjs).\n // path.relative may return backslashes on Windows — normalise to forward slashes.\n const relDir = toForwardSlash(path.relative(tmpDir, path.dirname(filePath)));\n\n if (preserveModules) {\n if (isEsmFile(name)) {\n if (formats.includes(\"esm\")) {\n moveFile(filePath, joinPath(esmDir, relDir, name), pkg.name);\n }\n } else if (isCjsFile(name)) {\n if (formats.includes(\"cjs\")) {\n moveFile(filePath, joinPath(cjsDir, relDir, name), pkg.name);\n }\n } else if (isDtsFile(name)) {\n const targetDir = formats.includes(\"esm\") ? esmDir : cjsDir;\n moveFile(filePath, joinPath(targetDir, relDir, name), pkg.name);\n }\n // Unknown extensions silently ignored.\n return;\n }\n\n // ── Single-bundle mode ──────────────────────────────────────────────────────\n const { keepNativeExtension } = ctx;\n\n if (isEsmFile(name)) {\n if (formats.includes(\"esm\")) {\n const destName = keepNativeExtension ? name : normaliseEsmName(name);\n moveFile(filePath, joinPath(esmDir, relDir, destName), pkg.name);\n }\n } else if (isCjsFile(name)) {\n if (formats.includes(\"cjs\")) {\n const destName = keepNativeExtension ? name : normaliseCjsName(name);\n moveFile(filePath, joinPath(cjsDir, relDir, destName), pkg.name);\n }\n } else if (isDtsFile(name)) {\n const targetDir = formats.includes(\"esm\") ? esmDir : cjsDir;\n moveFile(filePath, joinPath(targetDir, relDir, name), pkg.name);\n } else if (isJsFile(name)) {\n // Plain .js / .js.map — emitted when the format array contains only one format\n // (tsdown uses .js instead of .mjs/.cjs when there's no other format to differentiate from).\n const targetDir = mainType === \"esm\" ? esmDir : cjsDir;\n if (formats.includes(mainType)) {\n // Files landing in cjsDir should use the .cjs extension for consistency.\n const destName =\n targetDir === cjsDir\n ? name.replace(/\\.js\\.map$/, \".cjs.map\").replace(/\\.js$/, \".cjs\")\n : name;\n moveFile(filePath, joinPath(targetDir, relDir, destName), pkg.name);\n }\n }\n // Unknown extensions are silently ignored.\n}\n\n// ─── Extension predicates ───────────────────────────────────────────────────\n\nfunction isEsmFile(name: string): boolean {\n return (\n name.endsWith(\".mjs\") ||\n name.endsWith(\".mjs.map\") ||\n name.endsWith(\".d.mts\") ||\n name.endsWith(\".d.mts.map\")\n );\n}\n\nfunction isCjsFile(name: string): boolean {\n return (\n name.endsWith(\".cjs\") ||\n name.endsWith(\".cjs.map\") ||\n name.endsWith(\".d.cts\") ||\n name.endsWith(\".d.cts.map\")\n );\n}\n\nfunction isDtsFile(name: string): boolean {\n return name.endsWith(\".d.ts\") || name.endsWith(\".d.ts.map\");\n}\n\nfunction isJsFile(name: string): boolean {\n return (\n (name.endsWith(\".js\") || name.endsWith(\".js.map\")) &&\n !name.endsWith(\".d.ts\") &&\n !name.endsWith(\".d.ts.map\")\n );\n}\n\n// ─── Name normalisation ─────────────────────────────────────────────────────\n\n/** Rename .mjs / .d.mts → .js / .d.ts for the esm/ directory. */\nfunction normaliseEsmName(name: string): string {\n return name\n .replace(/\\.mjs\\.map$/, \".js.map\")\n .replace(/\\.mjs$/, \".js\")\n .replace(/\\.d\\.mts\\.map$/, \".d.ts.map\")\n .replace(/\\.d\\.mts$/, \".d.ts\");\n}\n\n/** Rename .cjs / .d.cts → .js / .d.ts for the cjs/ directory. */\nfunction normaliseCjsName(name: string): string {\n return name\n .replace(/\\.cjs\\.map$/, \".js.map\")\n .replace(/\\.cjs$/, \".js\")\n .replace(/\\.d\\.cts\\.map$/, \".d.ts.map\")\n .replace(/\\.d\\.cts$/, \".d.ts\");\n}\n","import semver from \"semver\";\nimport { wrapError } from \"../utils/errors.js\";\n\n/**\n * Given the current version string and a version strategy, return the new version.\n *\n * @param currentVersion semver string from source package.json, e.g. \"1.2.3\"\n * @param strategy \"auto\" / \"patch\" → patch bump\n * \"minor\" → minor bump\n * \"major\" → major bump\n * any valid semver string → use as-is\n * @param packageName used in error messages only\n */\nexport function resolveVersion(\n currentVersion: string,\n strategy: \"auto\" | \"patch\" | \"minor\" | \"major\" | string = \"auto\",\n packageName: string,\n): string {\n const bumpType =\n strategy === \"auto\" || strategy === \"patch\" ? \"patch\"\n : strategy === \"minor\" ? \"minor\"\n : strategy === \"major\" ? \"major\"\n : null;\n\n if (bumpType) {\n const bumped = semver.inc(currentVersion, bumpType);\n if (!bumped) {\n throw wrapError(\n \"version-increment\",\n packageName,\n new Error(\n `Cannot ${bumpType}-bump invalid semver version \"${currentVersion}\" for package \"${packageName}\"`,\n ),\n );\n }\n return bumped;\n }\n\n // Explicit version string — validate it\n const cleaned = semver.valid(semver.coerce(strategy) ?? strategy);\n if (!cleaned) {\n throw wrapError(\n \"version-increment\",\n packageName,\n new Error(\n `Explicit version \"${strategy}\" is not a valid semver string for package \"${packageName}\"`,\n ),\n );\n }\n return cleaned;\n}\n","import simpleGit, { SimpleGit } from \"simple-git\";\nimport fs from \"fs\";\nimport path from \"path\";\nimport { joinPath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\n\n/**\n * Returns true if the given directory is inside a git repository.\n */\nexport async function isGitRepo(dir: string): Promise<boolean> {\n try {\n const git: SimpleGit = simpleGit(dir);\n const result = await git.checkIsRepo();\n return result;\n } catch {\n return false;\n }\n}\n\n/**\n * Perform git operations for a package after a successful build:\n * 1. git add -A (in the package root)\n * 2. git commit -m <message>\n * 3. git push origin <branch>\n * 4. git tag v<version>\n * 5. git push origin <tag>\n */\nexport async function gitCommitTagPush(\n packageRoot: string,\n packageName: string,\n version: string,\n commitMessage: string,\n branch: string,\n dryRun: boolean,\n): Promise<void> {\n const isRepo = await isGitRepo(packageRoot);\n if (!isRepo) {\n logger.warn(`[git] ${packageName}: directory is not a git repo — skipping git operations`);\n return;\n }\n\n const tag = `v${version}`;\n logger.step(`[git] ${packageName}: commit \"${commitMessage}\", tag ${tag}, push to ${branch}`);\n\n if (dryRun) {\n logger.info(`[dry-run] git add + commit \"${commitMessage}\" + tag ${tag} + push`);\n return;\n }\n\n const git: SimpleGit = simpleGit(packageRoot);\n\n try {\n // Stage all changes\n await git.add(\"-A\");\n\n // Commit\n await git.commit(commitMessage);\n\n // Push to remote\n await git.push(\"origin\", branch);\n\n // Tag\n await git.addTag(tag);\n\n // Push tags\n await git.pushTags(\"origin\");\n\n logger.success(`[git] ${packageName}: pushed ${branch}, tagged ${tag}`);\n } catch (err) {\n throw wrapError(\"git-operations\", packageName, err);\n }\n}\n\n/**\n * Resolve the current branch name in the given directory.\n * Falls back to \"main\" if the directory is not a git repo.\n */\nexport async function currentBranch(dir: string): Promise<string> {\n try {\n const git: SimpleGit = simpleGit(dir);\n const branch = await git.revparse([\"--abbrev-ref\", \"HEAD\"]);\n return branch.trim() || \"main\";\n } catch {\n return \"main\";\n }\n}\n","import { execa } from \"execa\";\nimport { wrapError } from \"./errors.js\";\n\nexport interface ExecResult {\n stdout: string;\n stderr: string;\n exitCode: number;\n}\n\n/**\n * Run a shell command and return stdout/stderr.\n * Throws a BundlerError on non-zero exit.\n */\nexport async function exec(\n step: string,\n packageName: string,\n command: string,\n args: string[],\n cwd?: string,\n): Promise<ExecResult> {\n try {\n const result = await execa(command, args, {\n cwd,\n all: true,\n reject: false,\n });\n if (result.exitCode !== 0) {\n const combined = result.all ?? result.stderr ?? \"\";\n throw new Error(\n `Command \"${command} ${args.join(\" \")}\" exited with code ${result.exitCode}.\\n${combined}`,\n );\n }\n return {\n stdout: result.stdout ?? \"\",\n stderr: result.stderr ?? \"\",\n exitCode: result.exitCode,\n };\n } catch (err) {\n throw wrapError(step, packageName, err);\n }\n}\n\n/**\n * Run a command and ignore its output. Does NOT throw on non-zero exit.\n * Useful for optional operations (e.g. `git tag -d`).\n */\nexport async function execSilent(\n command: string,\n args: string[],\n cwd?: string,\n): Promise<number> {\n try {\n const result = await execa(command, args, { cwd, reject: false });\n return result.exitCode ?? 0;\n } catch {\n return 1;\n }\n}\n","import { exec } from \"../utils/exec.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { PackageBase } from \"../types/index.js\";\n\n/**\n * Run `npm publish` from the build output directory.\n */\nexport async function publishPackage(\n pkg: PackageBase,\n buildPath: string,\n dryRun: boolean,\n): Promise<void> {\n if (pkg.publish === false) {\n logger.info(`[publish] ${pkg.name}: publish=false, skipping`);\n return;\n }\n\n const access = pkg.access ?? \"public\";\n\n if (dryRun) {\n logger.info(`[dry-run] npm publish --access ${access} from ${buildPath}`);\n return;\n }\n\n logger.step(`Publishing ${pkg.name}@... to npm (access: ${access})`);\n\n await exec(\n \"npm-publish\",\n pkg.name,\n \"npm\",\n [\"publish\", \"--access\", access, \"--registry\", \"https://registry.npmjs.org\"],\n buildPath,\n );\n\n logger.success(`Published ${pkg.name}`);\n}\n","import path from \"path\";\nimport { copyDir, ensureDir } from \"../files/file-manager.js\";\nimport {\n readSourcePackageJson,\n writeSourceVersion,\n writeBuildPackageJson,\n} from \"../files/package-json.js\";\nimport { cloneFiles } from \"../files/clone-files.js\";\nimport { compilePackage } from \"../compile/tsdown-compiler.js\";\nimport { resolveVersion } from \"../version/increment.js\";\nimport { gitCommitTagPush, currentBranch } from \"../git/operations.js\";\nimport { publishPackage } from \"../publish/npm-publisher.js\";\nimport { buildOutputPath, sourceSnapshotPath, resolvePath } from \"../utils/paths.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { PackageBase, BuildOptions, BuilderSettings } from \"../types/index.js\";\n\nexport interface BuildResult {\n packageName: string;\n version: string;\n buildPath: string;\n success: boolean;\n error?: Error;\n}\n\n/**\n * Execute the full build pipeline for a single package.\n *\n * Steps:\n * 1. Resolve package root\n * 2. Read source package.json → current version\n * 3. Compute new version\n * 4. Create build output directory\n * 5. Source snapshot (optional)\n * 6. tsdown compile\n * 7. Clone extra files\n * 8. Write build package.json\n * 9. Update source package.json version\n * 10. Git: add, commit, push, tag\n * 11. npm publish\n */\nexport async function buildPackage(\n pkg: PackageBase,\n versionStrategy: \"auto\" | string = \"auto\",\n settings: BuilderSettings,\n options: BuildOptions,\n configDir: string,\n /**\n * Override commit message (used by family builder to apply a shared message).\n * If undefined, uses pkg.commit.\n */\n overrideCommit?: string,\n /**\n * Pre-resolved version — used when a family has already determined the version\n * and needs all member packages to use the same one.\n */\n forcedVersion?: string,\n): Promise<BuildResult> {\n const step = \"package-builder\";\n\n try {\n // 1. Resolve absolute package root\n const packageRoot = resolvePath(configDir, pkg.root);\n\n // 2. Read source package.json\n const sourceJson = readSourcePackageJson(packageRoot, pkg.name);\n const currentVersion = sourceJson.version;\n\n // 3. Determine new version\n const newVersion =\n forcedVersion ?? resolveVersion(currentVersion, versionStrategy, pkg.name);\n\n logger.info(`Building ${pkg.name}: ${currentVersion} → ${newVersion}`);\n\n // 4. Build output directory\n const absoluteBuildDir = resolvePath(configDir, settings.buildDir);\n const buildPath = buildOutputPath(absoluteBuildDir, pkg.name, newVersion);\n\n if (!options.dryRun) {\n ensureDir(buildPath);\n }\n\n // 5. Source snapshot\n if (settings.sourcesDir) {\n const absoluteSourcesDir = resolvePath(configDir, settings.sourcesDir);\n const snapshotPath = sourceSnapshotPath(absoluteSourcesDir, pkg.name);\n if (options.dryRun) {\n logger.info(`[dry-run] snapshot ${packageRoot} → ${snapshotPath}`);\n } else {\n ensureDir(snapshotPath);\n copyDir(packageRoot, snapshotPath);\n logger.debug(`Snapshot: ${packageRoot} → ${snapshotPath}`);\n }\n }\n\n // 6. Compile with tsdown\n await compilePackage(pkg, packageRoot, buildPath, sourceJson as Record<string, unknown>, options.dryRun);\n\n // 7. Clone extra files\n if (pkg.clone && pkg.clone.length > 0) {\n cloneFiles(packageRoot, buildPath, pkg.clone, pkg.name, options.dryRun);\n }\n\n // 8. Write build package.json\n if (!options.dryRun) {\n writeBuildPackageJson(pkg, sourceJson, buildPath, newVersion);\n logger.debug(`Wrote build package.json for ${pkg.name}@${newVersion}`);\n } else {\n logger.info(`[dry-run] write build package.json for ${pkg.name}@${newVersion}`);\n }\n\n // 9. Update source package.json version\n if (!options.dryRun) {\n writeSourceVersion(packageRoot, pkg.name, newVersion);\n logger.debug(`Updated source version ${pkg.name} → ${newVersion}`);\n } else {\n logger.info(`[dry-run] update source package.json version → ${newVersion}`);\n }\n\n // 10. Git operations (only if commit message is set and --no-git is not passed)\n const commitMessage = overrideCommit ?? pkg.commit;\n if (commitMessage && !options.noGit) {\n const branch = pkg.branch ?? (await currentBranch(packageRoot));\n await gitCommitTagPush(\n packageRoot,\n pkg.name,\n newVersion,\n commitMessage,\n branch,\n options.dryRun,\n );\n } else if (!commitMessage) {\n logger.debug(`[git] ${pkg.name}: no commit message set — skipping git`);\n }\n\n // 11. npm publish\n if (!options.noPublish) {\n await publishPackage(pkg, buildPath, options.dryRun);\n } else {\n logger.info(`[publish] ${pkg.name}: --no-publish, skipping`);\n }\n\n return { packageName: pkg.name, version: newVersion, buildPath, success: true };\n } catch (err) {\n const wrapped = wrapError(step, pkg.name, err);\n logger.error(`Failed to build ${pkg.name}: ${wrapped.message}`);\n return {\n packageName: pkg.name,\n version: \"\",\n buildPath: \"\",\n success: false,\n error: wrapped,\n };\n }\n}\n","import semver from \"semver\";\nimport { readSourcePackageJson } from \"../files/package-json.js\";\nimport { resolveVersion } from \"../version/increment.js\";\nimport { resolvePath } from \"../utils/paths.js\";\nimport { buildPackage } from \"./package-builder.js\";\nimport { runParallel } from \"./parallel-builder.js\";\nimport { wrapError } from \"../utils/errors.js\";\nimport { logger } from \"../utils/logger.js\";\nimport type { Family, BuildOptions, BuilderSettings } from \"../types/index.js\";\nimport type { BuildResult } from \"./package-builder.js\";\n\n/**\n * Build all packages in a family using a single shared version.\n *\n * The shared version is determined by taking the HIGHEST current version\n * across all family members and bumping it. This prevents a lower-versioned\n * member (e.g. atomic-query@0.1.0) from pulling down a higher-versioned one\n * (e.g. react-atom@5.1.3) when they are first unified.\n */\nexport async function buildFamily(\n family: Family,\n settings: BuilderSettings,\n options: BuildOptions,\n configDir: string,\n): Promise<BuildResult[]> {\n if (family.packages.length === 0) {\n logger.warn(`Family \"${family.name}\" has no packages — nothing to build`);\n return [];\n }\n\n let newVersion: string;\n try {\n const strategy = family.version ?? \"auto\";\n const isBumpKeyword = strategy === \"auto\" || strategy === \"patch\" || strategy === \"minor\" || strategy === \"major\";\n\n if (!isBumpKeyword && semver.valid(semver.coerce(strategy) ?? strategy)) {\n // Explicit semver string — use as-is\n newVersion = strategy;\n } else {\n // Bump keyword — find the highest current version across all family members, then bump it\n let highestVersion = \"0.0.0\";\n for (const pkg of family.packages) {\n const root = resolvePath(configDir, pkg.root);\n const sourceJson = readSourcePackageJson(root, pkg.name);\n const v = sourceJson.version ?? \"0.0.0\";\n if (semver.gt(v, highestVersion)) {\n highestVersion = v;\n }\n }\n newVersion = resolveVersion(highestVersion, strategy, family.name);\n }\n } catch (err) {\n throw wrapError(\"family-version\", family.name, err);\n }\n\n logger.info(`Family \"${family.name}\": shared version → ${newVersion} (${family.packages.length} packages)`);\n\n const concurrency = options.concurrency ?? settings.concurrency ?? 4;\n\n // The family commit message overrides per-package commit messages\n const familyCommit = family.commit;\n\n const tasks = family.packages.map((pkg) => () =>\n buildPackage(\n pkg,\n \"auto\", // not used — forcedVersion overrides\n settings,\n options,\n configDir,\n familyCommit ?? pkg.commit,\n newVersion, // all packages use the same version\n ),\n );\n\n return runParallel(tasks, concurrency);\n}\n","import pLimit from \"p-limit\";\nimport type { BuildResult } from \"./package-builder.js\";\nimport { logger } from \"../utils/logger.js\";\n\n/**\n * Run an array of async build tasks with a concurrency cap.\n * Each task is a zero-argument function that returns a Promise<BuildResult>.\n */\nexport async function runParallel(\n tasks: (() => Promise<BuildResult>)[],\n concurrency: number,\n): Promise<BuildResult[]> {\n if (tasks.length === 0) return [];\n\n const limit = pLimit(Math.max(1, concurrency));\n\n logger.info(`Running ${tasks.length} task(s) with concurrency=${concurrency}`);\n\n const results = await Promise.all(\n tasks.map((task) => limit(task)),\n );\n\n const succeeded = results.filter((r) => r.success).length;\n const failed = results.filter((r) => !r.success).length;\n\n if (failed > 0) {\n logger.warn(`${succeeded} succeeded, ${failed} failed`);\n for (const r of results.filter((r) => !r.success)) {\n logger.error(` FAILED: ${r.packageName} — ${r.error?.message ?? \"unknown error\"}`);\n }\n } else {\n logger.success(`All ${succeeded} package(s) built successfully`);\n }\n\n return results;\n}\n"],"mappings":";AAMO,SAAS,aAAa,QAAsC;AACjE,SAAO;AACT;;;ACRA,OAAOA,WAAU;AACjB,SAAS,qBAAqB;AAC9B,OAAO,QAAQ;;;ACFf,OAAO,UAAU;AAGV,SAAS,eAAe,GAAmB;AAChD,SAAO,EAAE,QAAQ,OAAO,GAAG;AAC7B;AAGO,SAAS,YAAY,UAA4B;AACtD,SAAO,eAAe,KAAK,KAAK,GAAG,QAAQ,CAAC;AAC9C;AAGO,SAAS,eAAe,UAA4B;AACzD,SAAO,eAAe,KAAK,QAAQ,GAAG,QAAQ,CAAC;AACjD;AAMO,SAAS,cAAc,aAA6B;AACzD,QAAM,QAAQ,YAAY,QAAQ,GAAG;AACrC,SAAO,UAAU,KAAK,cAAc,YAAY,MAAM,QAAQ,CAAC;AACjE;AAMO,SAAS,gBACd,UACA,aACA,SACQ;AACR,SAAO,SAAS,UAAU,cAAc,WAAW,GAAG,OAAO;AAC/D;AAMO,SAAS,mBACd,YACA,aACQ;AACR,SAAO,SAAS,YAAY,cAAc,WAAW,CAAC;AACxD;;;AC9CO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACkB,MACA,aAChB,SACgB,OAChB;AACA,UAAM,OAAO;AALG;AACA;AAEA;AAGhB,SAAK,OAAO;AACZ,QAAI,iBAAiB,SAAS,MAAM,OAAO;AACzC,WAAK,QAAQ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E;AAAA,MACA;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB,IAAI;AAAA,MACpB;AAAA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,YAAY,OAAO,WAAW;AACvC;","names":["path","path","fs","path","fs","path","fs","fs","path","fs","fs","path","semver","r","semver"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongez/pkgist",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Build, version, and publish tool for TypeScript npm packages. Powered by tsdown.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsup",
|
|
20
20
|
"dev": "tsup --watch",
|
|
21
|
-
"start": "node dist/cli.js"
|
|
21
|
+
"start": "node dist/cli.js",
|
|
22
|
+
"release": "pkgist build"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"chalk": "^5.3.0",
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import semver from "semver";
|
|
2
|
-
import { readSourcePackageJson } from "../files/package-json.js";
|
|
3
|
-
import { resolveVersion } from "../version/increment.js";
|
|
4
|
-
import { resolvePath } from "../utils/paths.js";
|
|
5
|
-
import { buildPackage } from "./package-builder.js";
|
|
6
|
-
import { runParallel } from "./parallel-builder.js";
|
|
7
|
-
import { wrapError } from "../utils/errors.js";
|
|
8
|
-
import { logger } from "../utils/logger.js";
|
|
9
|
-
import type { Family, BuildOptions, BuilderSettings } from "../types/index.js";
|
|
10
|
-
import type { BuildResult } from "./package-builder.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Build all packages in a family using a single shared version.
|
|
14
|
-
*
|
|
15
|
-
* The shared version is determined by taking the HIGHEST current version
|
|
16
|
-
* across all family members and bumping it. This prevents a lower-versioned
|
|
17
|
-
* member (e.g. atomic-query@0.1.0) from pulling down a higher-versioned one
|
|
18
|
-
* (e.g. react-atom@5.1.3) when they are first unified.
|
|
19
|
-
*/
|
|
20
|
-
export async function buildFamily(
|
|
21
|
-
family: Family,
|
|
22
|
-
settings: BuilderSettings,
|
|
23
|
-
options: BuildOptions,
|
|
24
|
-
configDir: string,
|
|
25
|
-
): Promise<BuildResult[]> {
|
|
26
|
-
if (family.packages.length === 0) {
|
|
27
|
-
logger.warn(`Family "${family.name}" has no packages — nothing to build`);
|
|
28
|
-
return [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let newVersion: string;
|
|
32
|
-
try {
|
|
33
|
-
const strategy = family.version ?? "auto";
|
|
34
|
-
const isBumpKeyword = strategy === "auto" || strategy === "patch" || strategy === "minor" || strategy === "major";
|
|
35
|
-
|
|
36
|
-
if (!isBumpKeyword && semver.valid(semver.coerce(strategy) ?? strategy)) {
|
|
37
|
-
// Explicit semver string — use as-is
|
|
38
|
-
newVersion = strategy;
|
|
39
|
-
} else {
|
|
40
|
-
// Bump keyword — find the highest current version across all family members, then bump it
|
|
41
|
-
let highestVersion = "0.0.0";
|
|
42
|
-
for (const pkg of family.packages) {
|
|
43
|
-
const root = resolvePath(configDir, pkg.root);
|
|
44
|
-
const sourceJson = readSourcePackageJson(root, pkg.name);
|
|
45
|
-
const v = sourceJson.version ?? "0.0.0";
|
|
46
|
-
if (semver.gt(v, highestVersion)) {
|
|
47
|
-
highestVersion = v;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
newVersion = resolveVersion(highestVersion, strategy, family.name);
|
|
51
|
-
}
|
|
52
|
-
} catch (err) {
|
|
53
|
-
throw wrapError("family-version", family.name, err);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
logger.info(`Family "${family.name}": shared version → ${newVersion} (${family.packages.length} packages)`);
|
|
57
|
-
|
|
58
|
-
const concurrency = options.concurrency ?? settings.concurrency ?? 4;
|
|
59
|
-
|
|
60
|
-
// The family commit message overrides per-package commit messages
|
|
61
|
-
const familyCommit = family.commit;
|
|
62
|
-
|
|
63
|
-
const tasks = family.packages.map((pkg) => () =>
|
|
64
|
-
buildPackage(
|
|
65
|
-
pkg,
|
|
66
|
-
"auto", // not used — forcedVersion overrides
|
|
67
|
-
settings,
|
|
68
|
-
options,
|
|
69
|
-
configDir,
|
|
70
|
-
familyCommit ?? pkg.commit,
|
|
71
|
-
newVersion, // all packages use the same version
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
return runParallel(tasks, concurrency);
|
|
76
|
-
}
|
package/src/build/index.ts
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { copyDir, ensureDir } from "../files/file-manager.js";
|
|
3
|
-
import {
|
|
4
|
-
readSourcePackageJson,
|
|
5
|
-
writeSourceVersion,
|
|
6
|
-
writeBuildPackageJson,
|
|
7
|
-
} from "../files/package-json.js";
|
|
8
|
-
import { cloneFiles } from "../files/clone-files.js";
|
|
9
|
-
import { compilePackage } from "../compile/tsdown-compiler.js";
|
|
10
|
-
import { resolveVersion } from "../version/increment.js";
|
|
11
|
-
import { gitCommitTagPush, currentBranch } from "../git/operations.js";
|
|
12
|
-
import { publishPackage } from "../publish/npm-publisher.js";
|
|
13
|
-
import { buildOutputPath, sourceSnapshotPath, resolvePath } from "../utils/paths.js";
|
|
14
|
-
import { wrapError } from "../utils/errors.js";
|
|
15
|
-
import { logger } from "../utils/logger.js";
|
|
16
|
-
import type { PackageBase, BuildOptions, BuilderSettings } from "../types/index.js";
|
|
17
|
-
|
|
18
|
-
export interface BuildResult {
|
|
19
|
-
packageName: string;
|
|
20
|
-
version: string;
|
|
21
|
-
buildPath: string;
|
|
22
|
-
success: boolean;
|
|
23
|
-
error?: Error;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Execute the full build pipeline for a single package.
|
|
28
|
-
*
|
|
29
|
-
* Steps:
|
|
30
|
-
* 1. Resolve package root
|
|
31
|
-
* 2. Read source package.json → current version
|
|
32
|
-
* 3. Compute new version
|
|
33
|
-
* 4. Create build output directory
|
|
34
|
-
* 5. Source snapshot (optional)
|
|
35
|
-
* 6. tsdown compile
|
|
36
|
-
* 7. Clone extra files
|
|
37
|
-
* 8. Write build package.json
|
|
38
|
-
* 9. Update source package.json version
|
|
39
|
-
* 10. Git: add, commit, push, tag
|
|
40
|
-
* 11. npm publish
|
|
41
|
-
*/
|
|
42
|
-
export async function buildPackage(
|
|
43
|
-
pkg: PackageBase,
|
|
44
|
-
versionStrategy: "auto" | string = "auto",
|
|
45
|
-
settings: BuilderSettings,
|
|
46
|
-
options: BuildOptions,
|
|
47
|
-
configDir: string,
|
|
48
|
-
/**
|
|
49
|
-
* Override commit message (used by family builder to apply a shared message).
|
|
50
|
-
* If undefined, uses pkg.commit.
|
|
51
|
-
*/
|
|
52
|
-
overrideCommit?: string,
|
|
53
|
-
/**
|
|
54
|
-
* Pre-resolved version — used when a family has already determined the version
|
|
55
|
-
* and needs all member packages to use the same one.
|
|
56
|
-
*/
|
|
57
|
-
forcedVersion?: string,
|
|
58
|
-
): Promise<BuildResult> {
|
|
59
|
-
const step = "package-builder";
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
// 1. Resolve absolute package root
|
|
63
|
-
const packageRoot = resolvePath(configDir, pkg.root);
|
|
64
|
-
|
|
65
|
-
// 2. Read source package.json
|
|
66
|
-
const sourceJson = readSourcePackageJson(packageRoot, pkg.name);
|
|
67
|
-
const currentVersion = sourceJson.version;
|
|
68
|
-
|
|
69
|
-
// 3. Determine new version
|
|
70
|
-
const newVersion =
|
|
71
|
-
forcedVersion ?? resolveVersion(currentVersion, versionStrategy, pkg.name);
|
|
72
|
-
|
|
73
|
-
logger.info(`Building ${pkg.name}: ${currentVersion} → ${newVersion}`);
|
|
74
|
-
|
|
75
|
-
// 4. Build output directory
|
|
76
|
-
const absoluteBuildDir = resolvePath(configDir, settings.buildDir);
|
|
77
|
-
const buildPath = buildOutputPath(absoluteBuildDir, pkg.name, newVersion);
|
|
78
|
-
|
|
79
|
-
if (!options.dryRun) {
|
|
80
|
-
ensureDir(buildPath);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 5. Source snapshot
|
|
84
|
-
if (settings.sourcesDir) {
|
|
85
|
-
const absoluteSourcesDir = resolvePath(configDir, settings.sourcesDir);
|
|
86
|
-
const snapshotPath = sourceSnapshotPath(absoluteSourcesDir, pkg.name);
|
|
87
|
-
if (options.dryRun) {
|
|
88
|
-
logger.info(`[dry-run] snapshot ${packageRoot} → ${snapshotPath}`);
|
|
89
|
-
} else {
|
|
90
|
-
ensureDir(snapshotPath);
|
|
91
|
-
copyDir(packageRoot, snapshotPath);
|
|
92
|
-
logger.debug(`Snapshot: ${packageRoot} → ${snapshotPath}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// 6. Compile with tsdown
|
|
97
|
-
await compilePackage(pkg, packageRoot, buildPath, sourceJson as Record<string, unknown>, options.dryRun);
|
|
98
|
-
|
|
99
|
-
// 7. Clone extra files
|
|
100
|
-
if (pkg.clone && pkg.clone.length > 0) {
|
|
101
|
-
cloneFiles(packageRoot, buildPath, pkg.clone, pkg.name, options.dryRun);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 8. Write build package.json
|
|
105
|
-
if (!options.dryRun) {
|
|
106
|
-
writeBuildPackageJson(pkg, sourceJson, buildPath, newVersion);
|
|
107
|
-
logger.debug(`Wrote build package.json for ${pkg.name}@${newVersion}`);
|
|
108
|
-
} else {
|
|
109
|
-
logger.info(`[dry-run] write build package.json for ${pkg.name}@${newVersion}`);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// 9. Update source package.json version
|
|
113
|
-
if (!options.dryRun) {
|
|
114
|
-
writeSourceVersion(packageRoot, pkg.name, newVersion);
|
|
115
|
-
logger.debug(`Updated source version ${pkg.name} → ${newVersion}`);
|
|
116
|
-
} else {
|
|
117
|
-
logger.info(`[dry-run] update source package.json version → ${newVersion}`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 10. Git operations (only if commit message is set and --no-git is not passed)
|
|
121
|
-
const commitMessage = overrideCommit ?? pkg.commit;
|
|
122
|
-
if (commitMessage && !options.noGit) {
|
|
123
|
-
const branch = pkg.branch ?? (await currentBranch(packageRoot));
|
|
124
|
-
await gitCommitTagPush(
|
|
125
|
-
packageRoot,
|
|
126
|
-
pkg.name,
|
|
127
|
-
newVersion,
|
|
128
|
-
commitMessage,
|
|
129
|
-
branch,
|
|
130
|
-
options.dryRun,
|
|
131
|
-
);
|
|
132
|
-
} else if (!commitMessage) {
|
|
133
|
-
logger.debug(`[git] ${pkg.name}: no commit message set — skipping git`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 11. npm publish
|
|
137
|
-
if (!options.noPublish) {
|
|
138
|
-
await publishPackage(pkg, buildPath, options.dryRun);
|
|
139
|
-
} else {
|
|
140
|
-
logger.info(`[publish] ${pkg.name}: --no-publish, skipping`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return { packageName: pkg.name, version: newVersion, buildPath, success: true };
|
|
144
|
-
} catch (err) {
|
|
145
|
-
const wrapped = wrapError(step, pkg.name, err);
|
|
146
|
-
logger.error(`Failed to build ${pkg.name}: ${wrapped.message}`);
|
|
147
|
-
return {
|
|
148
|
-
packageName: pkg.name,
|
|
149
|
-
version: "",
|
|
150
|
-
buildPath: "",
|
|
151
|
-
success: false,
|
|
152
|
-
error: wrapped,
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
}
|