Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167import { nodeConfig, type NodeFlavorConfig,} from '@monochromatic-dev/config-rolldown/.node.ts';
import packageMetadata from './package.json' with { type: 'json', };
/** Separator between independently supported Node runtime lines. */const NODE_ENGINE_RANGE_SEPARATOR = ' || ';/** Prefix for each exact minimum in the Node engine range. */const NODE_ENGINE_RANGE_PREFIX = '^';/** Number of components required by an exact Node runtime version. */const SEMANTIC_VERSION_COMPONENT_COUNT = 3;/** Canonical package runtime contract. */const { node: nodeEngineRange, } = packageMetadata.engines;/** Supported Node runtime ranges from the package manifest. */const nodeEngineRanges = nodeEngineRange.split(NODE_ENGINE_RANGE_SEPARATOR,);
/** Checks whether one version component is an unsigned canonical integer.
@param component - Version component from package engine floor.
@returns Whether component has canonical integer spelling.
@example ```ts isCanonicalVersionComponent('11'); ``` */function isCanonicalVersionComponent(component: string,): boolean { if (component === '') return false; /** Numeric value used to reject unsafe and noncanonical components. */ const numericComponent = Number(component,); return Number.isSafeInteger(numericComponent,) && (numericComponent >= 0) && (String(numericComponent,) === component);}
/** Extracts and validates one exact minimum from a caret runtime range.
@param runtimeRange - One package engine range.
@returns Exact minimum runtime version.
@example ```ts extractNodeVersion('^24.11.0'); ``` */function extractNodeVersion(runtimeRange: string,): string { if (!runtimeRange.startsWith(NODE_ENGINE_RANGE_PREFIX,)) throw new Error(`cli-git Node engine must contain caret ranges, received ${nodeEngineRange}`,); /** Exact version text after the caret range prefix. */ const version = runtimeRange.slice(NODE_ENGINE_RANGE_PREFIX.length,); /** Components used to validate exact version spelling. */ const components = version.split('.',); if ((components.length !== SEMANTIC_VERSION_COMPONENT_COUNT) || (!components.every(isCanonicalVersionComponent,))) { throw new Error(`cli-git Node engine must contain canonical versions, received ${nodeEngineRange}`,); } return version;}
/** Compares two exact Node runtime versions.
@param leftVersion - First exact runtime version.
@param rightVersion - Second exact runtime version.
@returns Numeric ordering of runtime versions.
@example ```ts compareNodeVersions({ leftVersion: '24.11.0', rightVersion: '26.0.0', }); ``` */function compareNodeVersions({ leftVersion, rightVersion,}: { readonly leftVersion: string; readonly rightVersion: string;},): number { /** Numeric components from first runtime version. */ const [leftMajor = 0, leftMinor = 0, leftPatch = 0,] = leftVersion .split('.',) .map(Number,); /** Numeric components from second runtime version. */ const [rightMajor = 0, rightMinor = 0, rightPatch = 0,] = rightVersion .split('.',) .map(Number,); return (leftMajor - rightMajor) || (leftMinor - rightMinor) || (leftPatch - rightPatch);}
/** Exact runtime versions supported by the package. */const supportedNodeVersions = nodeEngineRanges.map(extractNodeVersion,);/** Exact minimum runtime used as the build transform target. */const minimumNodeVersion = supportedNodeVersions.reduce( function selectMinimum( currentMinimum: string, candidate: string, ): string { return compareNodeVersions({ leftVersion: candidate, rightVersion: currentMinimum, }) < 0 ? candidate : currentMinimum; },);
/** Shared Node flavor before cli-git's package-specific runtime target. */const baseConfig: NodeFlavorConfig = nodeConfig({ outputOverrides: { minify: false, codeSplitting: false, },},);
/** Node build configuration for shadow bin and authoring API.
Transform target comes from same manifest range used by package managers and supported-runtime CI. Unminified single-chunk output keeps trust diagnostics, stack traces, and dynamic imports in one auditable file. */const config: NodeFlavorConfig = { ...baseConfig, transform: { ...baseConfig.transform, target: `node${minimumNodeVersion}`, },};
export default config;