yarnpkg / berry

📦🐈 Active development trunk for Yarn ⚒
https://yarnpkg.com
BSD 2-Clause "Simplified" License
7.37k stars 1.1k forks source link

fix: yarn install failed when dependency package using yarn in postin… #6350

Open benny1213 opened 3 months ago

benny1213 commented 3 months ago

What's the problem this PR addresses?

when running yarn install script, there is an error occur: "xx must be built because it never has been before or the last one failed" and the postinstall script of the error package did not run correctly.

Preconditions:

  1. using yarnPath with a pre-built yarn.js
  2. some of our npm package include yarn command in the postinstall script.

you can find more detail from minimal reproducible repo

How did you fix it?

after debug, i found the linkersCustomData did not restore correctly when running the yarn in the postinstall script, which causing yarn command in postinstall script refused to run.

image

so i tried calling project.restoreInstallState() when customData is missing to try restore the customData.

after i fixed this issue, i found two little issue still showing:

  1. when calling project.findLocatorForLocation yarn alway pass a path with a / ending, but the locatorByPath map only contains key without / ending.
  2. the locator should be a Locator struct instead of a string image

i also fixed these two problem as the file changes show.

Checklist

arcanis commented 3 months ago

Can you add a comprehensive description of what this change is supposed to do/fix?

benny1213 commented 3 months ago

Can you add a comprehensive description of what this change is supposed to do/fix?

sure, i will create a minimal Minimal reproducible repository for better describe this PR later, please wait a moment thanks.

benny1213 commented 3 months ago

hi @arcanis it's my first time raising a PR to public repo, If there is anything wrong, I am willing to modify it.

i think there is two work still need to do:

  1. should write a test for this case, but i don't know how for this error case, can anyone help advice?
  2. i can't pass all the test pipeline, it showing certification issue in windows node pipeline, i think it's not relevant to my change.