(config: ArkSchemaConfig)
| 240 | } |
| 241 | |
| 242 | export const configureSchema = (config: ArkSchemaConfig): ArkSchemaConfig => { |
| 243 | assertNoProblemConfig(config) |
| 244 | if ("clone" in config) throwParseError(removedCloneMessage) |
| 245 | // a misspelled option would otherwise be kept and never read |
| 246 | for (const k in config) { |
| 247 | if (isNodeKind(k) || hasOwn(optionNames, k)) continue |
| 248 | const nearest = nearestOptionTo(k) |
| 249 | throwParseError( |
| 250 | writeUnknownConfigOptionMessage(k) + |
| 251 | (nearest ? `. Did you mean '${nearest}'?` : "") |
| 252 | ) |
| 253 | } |
| 254 | // as is another library's word for one, like "strip" |
| 255 | if ( |
| 256 | config.onUndeclaredKey !== undefined && |
| 257 | !hasOwn(undeclaredKeyBehaviors, config.onUndeclaredKey) |
| 258 | ) { |
| 259 | throwParseError( |
| 260 | writeInvalidUndeclaredKeyBehaviorMessage(config.onUndeclaredKey) |
| 261 | ) |
| 262 | } |
| 263 | if (config.locale !== undefined && !hasDomain(config.locale, "object")) |
| 264 | throwParseError(writeInvalidLocaleMessage(config.locale)) |
| 265 | const merged = mergeConfigs($ark.config, copyConfig(config)) |
| 266 | if ($ark.cfg) { |
| 267 | // a config file evaluated again, as after a test runner resets modules, |
| 268 | // can reapply what's set, which changes nothing |
| 269 | if (!isSameConfig(merged, $ark.config)) { |
| 270 | const frozenBy = $ark.cfgFrozenBy |
| 271 | let firstType: string | undefined |
| 272 | if (typeof frozenBy === "function") { |
| 273 | try { |
| 274 | firstType = frozenBy() |
| 275 | } catch { |
| 276 | firstType = undefined |
| 277 | } |
| 278 | } else firstType = frozenBy |
| 279 | return throwParseError(writeConfigureAfterTypeMessage(firstType)) |
| 280 | } |
| 281 | } else Object.assign($ark.config, merged) |
| 282 | // what was passed, as a precompiled program's configure() returns, rather |
| 283 | // than $ark.config, whose writes would skip this validation |
| 284 | return config |
| 285 | } |
| 286 | |
| 287 | /** $ark.config merged over base, with its static locale */ |
| 288 | export const resolveGlobalConfig = (base: ResolvedConfig): ResolvedConfig => { |
no test coverage detected