Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 56 additions & 27 deletions .yarn/plugins/@rnx-kit/yarn-plugin-dynamic-overrides.cjs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,38 +43,71 @@ exports.factory = (require) => {
const { SettingsType, structUtils } = require("@yarnpkg/core");

/**
* @param {Map<string, string>} entry
* @returns {[string, ExtendedIdent]}
* @param {Project} project
* @returns {Map<string, ExtendedIdent>}
*/
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<Hooks>["configuration"] & Record<string, unknown>} */
const configuration = {};
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,
},
},
},
},
};

Expand All @@ -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);
Expand Down
31 changes: 16 additions & 15 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading