From e0f4bc11ef6dee622f30f0b989156ea426a25274 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Fri, 11 Sep 2026 14:09:07 -0600 Subject: [PATCH] Fix publish-preview to target only workspaces when adding resolutions When the `publish-preview` action runs for a monorepo, before it renames all packages to use the preview NPM scope, it adds resolutions for each package to ensure that imports and references to internal dependencies still work. For example, if `@metamask/accounts-controller` is present in the monorepo, before it is renamed to `@metamask-previews/accounts-controller`, a resolution `"@metamask/accounts-controller": "portal:./path/to/accounts-controller"` will be added. However, this resolution is too broad. If an external dependency relies on a different version of a package that exists in the monorepo, then it will be force-resolved to the version of that package in the monorepo instead of the old version. This can cause type errors in the later step of the `publish-preview` workflow that builds the monorepo, because it subverts an assumption that the code is making. To fix this problem, this commit narrows each added resolution to the version of the corresponding monorepo package it is attempting to target. --- .github/workflows/publish-preview.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-preview.yml b/.github/workflows/publish-preview.yml index de9e7717..debb9f6b 100644 --- a/.github/workflows/publish-preview.yml +++ b/.github/workflows/publish-preview.yml @@ -151,10 +151,21 @@ jobs: } if [[ "$IS_MONOREPO" == "true" ]]; then + workspace_list="$(yarn workspaces list --no-private --json \ + | jq --slurp --raw-output 'map([.location, .name]) | map(@tsv) | .[]')" + # Add resolutions so renamed packages still resolve from local workspace echo "Adding workspace resolutions to root manifest..." - resolutions="$(yarn workspaces list --no-private --json \ - | jq --slurp 'reduce .[] as $pkg ({}; .[$pkg.name] = "portal:./" + $pkg.location)')" + resolutions='{}' + while IFS=$'\t' read -r location name; do + version="$(jq --raw-output '.version' "$location/package.json")" + resolutions="$(jq \ + --arg name "$name" \ + --arg version "$version" \ + --arg location "$location" \ + '.[$name + "@^" + $version] = "portal:./" + $location' \ + <<< "$resolutions")" + done <<< "$workspace_list" jq --argjson resolutions "$resolutions" '.resolutions = ((.resolutions // {}) + $resolutions)' package.json > temp.json mv temp.json package.json @@ -162,7 +173,7 @@ jobs: while IFS=$'\t' read -r location name; do echo "- $name" prepare_manifest "$location/package.json" - done < <(yarn workspaces list --no-private --json | jq --slurp --raw-output 'map([.location, .name]) | map(@tsv) | .[]') + done <<< "$workspace_list" else echo "Preparing manifest..." prepare_manifest package.json