Unverified Commit ecc601b4 authored by Alexey Orlenko's avatar Alexey Orlenko
Browse files

prisma: fix dangling symlinks

Make sure we don't leave dangling symlinks in `$out` when building
`prisma`.

1. We remove the original `node_modules` after buliding the packages to
   re-install the runtime dependencies without the dev dependencies. The
   way it was done was incorrect: only the root `node_modules` directory
   was removed but not the nested ones inside the packages. The
   follow-up `pnpm install` command didn't re-create or empty them and
   only created new files within, so we were left with tons of dangling
   symlinks from the first, full, `pnpm install` invocation.

2. `.pnpm/node_modules` inside the root `node_modules` contains symlinks
   to each workspace member package. However, we don't copy every
   package to `$out`, so we need to clean up this directory to remove
   the references to the missing packages.

Fixes: https://github.com/NixOS/nixpkgs/issues/380427
parent 922ee4f3
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ stdenv.mkDerivation (finalAttrs: {
    deps=$(jq -r '[.. | strings | select(startswith("link:../")) | sub("^link:../"; "")] | unique[]' <<< "$deps_json")

    # Remove unnecessary external dependencies
    rm -rf node_modules
    find . -name node_modules -type d -prune -exec rm -rf {} +
    pnpm install --offline --ignore-scripts --frozen-lockfile --prod
    cp -r node_modules $out/lib/prisma

@@ -72,10 +72,14 @@ stdenv.mkDerivation (finalAttrs: {
    for package in cli $deps; do
      filename=$(npm pack --json ./packages/$package | jq -r '.[].filename')
      mkdir -p $out/lib/prisma/packages/$package
      [ -d "packages/$package/node_modules" ] && \
        cp -r packages/$package/node_modules $out/lib/prisma/packages/$package
      tar xf $filename --strip-components=1 -C $out/lib/prisma/packages/$package
    done

    # Remove dangling symlinks to packages we didn't copy to $out
    find $out/lib/prisma/node_modules/.pnpm/node_modules -type l -exec test ! -e {} \; -delete

    makeWrapper "${lib.getExe nodejs}" "$out/bin/prisma" \
      --add-flags "$out/lib/prisma/packages/cli/build/index.js" \
      --set PRISMA_SCHEMA_ENGINE_BINARY ${prisma-engines}/bin/schema-engine \