[Bug] It's unclear when postinstall script runs
See original GitHub issueWe have this root package.json
:
{
"name": "@company/our-packages",
"private": true,
"workspaces": [
"*"
],
"scripts": {
"postinstall": "bash postinstall-script.sh"
}
}
The postinstall
script used to run in Yarn 2.2 but after upgrading to v2.4, it doesn’t and we’re getting this warning instead:
➤ YN0006: │ @company/our-packages@workspace:. lists build scripts, but is referenced through a soft link. Soft links don’t support build scripts, so they’ll be ignored.
I came to ask on Discord but still quite don’t know what the expected behavior is – for example, @larixer suggested that the first install should invoke the postinstall
but subsequent ones should trigger the warning.
So I tried building a Sherlock repro which expects the YN0006 error produced but the “bug” is that it doesn’t:
UPDATE: better repro posted in https://github.com/yarnpkg/berry/issues/2209#issuecomment-738335690.
Reproduction
const installPromise = packageJsonAndInstall({
"name": "@company/our-packages",
"private": true,
"workspaces": [
"*"
],
"scripts": {
"postinstall": "echo running postinstall..."
}
});
const output = await installPromise;
// it was suggested by @larixer that the first run shouldn't produce YN0006:
expect(output).not.toContain('YN0006');
expect(output).toContain('workspace:. must be built because it never did before or the last one failed');
const output2 = await yarn('install');
expect(output2).toContain('YN0006');
expect(output2).not.toContain('workspace:. must be built because it never did before or the last one failed');
Output:
Error: [2mexpect([22m[31mreceived[39m[2m).[22mtoContain[2m([22m[32mexpected[39m[2m) // indexOf[22m
Expected substring: [32m"YN0006"[39m
Received string: [31m"➤ YN0000: ┌ Resolution step[39m
[31m➤ YN0000: └ Completed[39m
[31m➤ YN0000: ┌ Fetch step[39m
[31m➤ YN0000: └ Completed[39m
[31m➤ YN0000: ┌ Link step[39m
[31m➤ YN0000: └ Completed[39m
[31m➤ YN0000: Done in 0s 76ms[39m
[31m"[39m
at module.exports (evalmachine.<anonymous>:19:17)
at process._tickCallback (internal/process/next_tick.js:68:7)
Why I believe YN0006 should be produced:
- Workspace root is a “soft link” package (
linkType: soft
inyarn.lock
) - The warning says “Soft links don’t support build scripts, so they’ll be ignored.”
- The docs of YN0006 also confirm that: “Since Yarn avoids doing anything unsafe, it cannot run build scripts on soft links.”
It is a bit strange that I see YN0006 in my real project but not in the Sherlock repro – it might be a mistake of that setup but I can’t spot it yet. In any case, I’d like to understand when postinstall script runs (or doesn’t) as it’s pretty important for our project.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (9 by maintainers)
“Workspaces are special” - does this mean that there is a bug in yarn reporting this as an error in a workspaced environment? Would we envision in the future that postinstall scripts are fine for workspaced projects using
nodeLinker: node-modules
?@arcanis per what you wrote:
a soft linked workspace should run postinstall scripts but the behaviour I am seeing with
2.4
is contradictory.The script is ignored with the above message