yarnpkg / berry

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

[Bug?]: Prepack script does not run on packages installed from git #6452

Open GNUGradyn opened 1 month ago

GNUGradyn commented 1 month ago

Self-service

Describe the bug

According to the lifecycle scripts section of the docs, the prepack script should be executed at the beginning of yarn pack, which should be executed when installing from git. I attempted to use this feature to generate the build output for a react native library in this repo, but no build output was produced and no errors were given

To reproduce

Here is an example repo, but this is pretty easy to repro without it as well as described below:

1: Create a new yarn package with yarn init 2: Create a prepack script that does something notable (in the example above I used mkdir itworked) and add it to the package.json 3: Test that this actually does what its supposed to with yarn prepack 4: Publish the package to GitHub (or another git provider) 5: Install the package to another yarn repo, e.g. yarn add yarn-mre@GNUGradyn/yarn-mre 6: Note that the result of prepack is not executed

Environment

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 AMD Ryzen 5 7600 6-Core Processor
  Binaries:
    Node: 20.13.1 - C:\Users\GRADYN~1\AppData\Local\Temp\xfs-d58cd52f\node.CMD
    Yarn: 4.1.1 - C:\Users\GRADYN~1\AppData\Local\Temp\xfs-d58cd52f\yarn.CMD
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD

Additional context

No response

clemyan commented 3 weeks ago

Create a prepack script that does something notable (in the example above I used mkdir itworked)

yarn pack does not pack empty directories into the .tgz; this is consistent with npm pack.

If you create a file in the prepack script, that will be packed

   "scripts": {
-    "prepack": "mkdir itworked"
+    "prepack": "mkdir itworked && echo 'it worked' > itworked/itworked.txt"
   }
> yarn pack --dry-run
➤ YN0036: Calling the "prepack" lifecycle script
➤ YN0000: README.md
➤ YN0000: itworked/itworked.txt
➤ YN0000: package.json
➤ YN0000: Done in 0s 59ms

I attempted to use this feature to generate the build output for a react native library in this repo, but no build output was produced and no errors were given

After installing that repo, I can see the lib directory in that package which seems like is generated by the prepack script?

> yarn init && yarn config set enableGlobalCache false
...
> yarn add react-native-google-auth@GNUGradyn/react-native-google-auth#commit=b001ca9adefb6e0d622dd2aaebb45f5fe1f85004
...
> unzip -l ./.yarn/cache/react-native-google-auth-https-bcf199d424-36239c4682.zip node_modules/react-native-google-auth/lib/**
Archive:  ./.yarn/cache/react-native-google-auth-https-bcf199d424-36239c4682.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/
       61  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/AuthorizationResult.js
      119  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/AuthorizationResult.js.map
       50  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/UserInfo.js
      108  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/UserInfo.js.map
     1354  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/index.js
     1412  06-22-1984 21:50   node_modules/react-native-google-auth/lib/commonjs/index.js.map
        0  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/
       48  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/AuthorizationResult.js
      119  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/AuthorizationResult.js.map
       37  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/UserInfo.js
      108  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/UserInfo.js.map
     1100  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/index.js
     1318  06-22-1984 21:50   node_modules/react-native-google-auth/lib/module/index.js.map
        0  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/
        0  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/
      183  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/AuthorizationResult.d.ts
      260  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/AuthorizationResult.d.ts.map
      152  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/UserInfo.d.ts
      244  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/UserInfo.d.ts.map
      358  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/index.d.ts
      354  06-22-1984 21:50   node_modules/react-native-google-auth/lib/typescript/src/index.d.ts.map
---------                     -------
     7385                     22 files