From c1aeab91d85e9feb0086c101089f2b5977602404 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Thu, 23 Jul 2026 06:56:14 +0200 Subject: [PATCH] chore: update `@rnx-kit/yarn-plugin-dynamic-overrides` --- .../yarn-plugin-dynamic-overrides.cjs | 83 +++++++++++++------ .yarnrc.yml | 31 +++---- 2 files changed, 72 insertions(+), 42 deletions(-) diff --git a/.yarn/plugins/@rnx-kit/yarn-plugin-dynamic-overrides.cjs b/.yarn/plugins/@rnx-kit/yarn-plugin-dynamic-overrides.cjs index 410cdad45..2e7932b2b 100644 --- a/.yarn/plugins/@rnx-kit/yarn-plugin-dynamic-overrides.cjs +++ b/.yarn/plugins/@rnx-kit/yarn-plugin-dynamic-overrides.cjs @@ -1,13 +1,15 @@ // @ts-check /** - * @import { Descriptor, Hooks, Ident, Plugin } from "@yarnpkg/core"; + * @import { Descriptor, Hooks, Ident, Plugin, Project } from "@yarnpkg/core"; * * @typedef {Ident & { specifier: string; }} ExtendedIdent */ const DEFAULT_SPECIFIER = "^"; const DYNAMIC_OVERRIDES_KEY = "dynamicPackageOverrides"; +const DEFAULT_SPECIFIER_KEY = "defaultSpecifier"; +const OVERRIDES_KEY = "overrides"; /** * @param {Descriptor} dependency @@ -41,22 +43,47 @@ exports.factory = (require) => { const { SettingsType, structUtils } = require("@yarnpkg/core"); /** - * @param {Map} entry - * @returns {[string, ExtendedIdent]} + * @param {Project} project + * @returns {Map} */ - function toKeyValuePair(entry) { - const id = entry.get("id"); - if (!id) { - throw new Error(`"${DYNAMIC_OVERRIDES_KEY}" expects an id`); + function parseConfig(project) { + const config = project.configuration.get(DYNAMIC_OVERRIDES_KEY); + if (!(config instanceof Map)) { + throw new Error(`Expected "${DYNAMIC_OVERRIDES_KEY}" to be a map`); } - const ident = structUtils.parseIdent(id); - return [ - ident.identHash, - { - ...ident, - specifier: entry.get("specifier") ?? DEFAULT_SPECIFIER, - }, - ]; + + const defaultSpecifier = config.get(DEFAULT_SPECIFIER_KEY); + if (typeof defaultSpecifier !== "string") { + throw new Error( + `Expected "${DYNAMIC_OVERRIDES_KEY}.${DEFAULT_SPECIFIER_KEY}" to be a string` + ); + } + + const overrides = config.get(OVERRIDES_KEY); + if (!Array.isArray(overrides)) { + throw new Error( + `Expected "${DYNAMIC_OVERRIDES_KEY}.${OVERRIDES_KEY}" to be an array` + ); + } + + return new Map( + overrides.map((entry) => { + const id = entry.get("id"); + if (!id) { + throw new Error( + `"${DYNAMIC_OVERRIDES_KEY}.${OVERRIDES_KEY}" expects an id` + ); + } + const ident = structUtils.parseIdent(id); + return [ + ident.identHash, + { + ...ident, + specifier: entry.get("specifier") ?? defaultSpecifier, + }, + ]; + }) + ); } /** @type {Plugin["configuration"] & Record} */ @@ -64,15 +91,23 @@ exports.factory = (require) => { configuration[DYNAMIC_OVERRIDES_KEY] = { description: "Packages whose dependencies are overridden", type: SettingsType.SHAPE, - isArray: true, properties: { - id: { - type: SettingsType.STRING, - }, - specifier: { + defaultSpecifier: { type: SettingsType.STRING, default: DEFAULT_SPECIFIER, }, + overrides: { + type: SettingsType.SHAPE, + isArray: true, + properties: { + id: { + type: SettingsType.STRING, + }, + specifier: { + type: SettingsType.STRING, + }, + }, + }, }, }; @@ -90,13 +125,7 @@ exports.factory = (require) => { _extra ) => { if (!overrides) { - const config = project.configuration.get(DYNAMIC_OVERRIDES_KEY); - if (!Array.isArray(config)) { - throw new Error( - `Expected "${DYNAMIC_OVERRIDES_KEY}" to be an array` - ); - } - overrides = new Map(config.map(toKeyValuePair)); + overrides = parseConfig(project); } const ident = overrides.get(locator.identHash); diff --git a/.yarnrc.yml b/.yarnrc.yml index 01bf0c5f6..11eaffa39 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -9,20 +9,21 @@ catalog: "@types/node": ^24.0.0 compressionLevel: 0 dynamicPackageOverrides: - - id: "@appium/base-driver" - - id: "@appium/logger" - - id: "@appium/support" - - id: "@microsoft/eslint-plugin-sdl" - - id: "@nx/devkit" - - id: "@nx/js" - - id: "@nx/workspace" - - id: appium - - id: argparse - - id: compression - - id: nx - - id: react-native-windows - - id: simple-plist - specifier: ~ + overrides: + - id: "@appium/base-driver" + - id: "@appium/logger" + - id: "@appium/support" + - id: "@microsoft/eslint-plugin-sdl" + - id: "@nx/devkit" + - id: "@nx/js" + - id: "@nx/workspace" + - id: appium + - id: argparse + - id: compression + - id: nx + - id: react-native-windows + - id: simple-plist + specifier: ~ enableGlobalCache: false enableScripts: false enableTelemetry: false @@ -51,7 +52,7 @@ plugins: - checksum: 8d8252c376e41a67ca509b2778f3fb92164aa91828459ae8a6aa0e13f1b6f9843586d0983ba9a200f6d813d37efc171474c8dbc85b0dff01df56c0d476c238ce path: .yarn/plugins/@rnx-kit/yarn-plugin-ignore.cjs spec: "https://raw.githubusercontent.com/microsoft/rnx-kit/main/incubator/yarn-plugin-ignore/dist/yarn-plugin-ignore.cjs" - - checksum: 3b1a87005ab0306362d5ef0813715cf981544b8cc916079259b71b27bb8ad6bb36b53568e0e474ec1809a7632235597a591d0a3a389e0d3aa41f1d661969c379 + - checksum: 95b353b32020b8cbee886499a1bf8c7b0dffd3026ce5605af29693bbbd6f906341461458efe9603270d495a0fcb25adeeb3550f477e195f1f852813cdaf6348e path: .yarn/plugins/@rnx-kit/yarn-plugin-dynamic-overrides.cjs spec: "https://raw.githubusercontent.com/microsoft/rnx-kit/refs/heads/main/incubator/yarn-plugin-dynamic-overrides/index.js" tsEnableAutoTypes: false