Zero Installs "plug-n-play"

In an effort to increase Docker build time, and improve general developer experience, I am interested in getting yarn Zero-Installs “plug-n-play” working. I hit two blockers:

1. Prisma client generation

  • The generated client needs to be placed somewhere else, eg /api/src/generated, since we no longer use node_modules. This is easy to update in the schema file output
generator client {
  provider      = "prisma-client-js"
  output        = "../src/generated"
}
  • The Redwood CLI and runtime tries to find the client in node_modules/.prisma/client, but is unsuccessful. The tooling must be updated to check in the new client location.
  • Generating the client is now different. pnpify is needed to prevent prisma from triggering npm install. See related issue for more explanation.
# in /api
yarn add -D @yarnpkg/pnpify
yarn unplug prisma @prisma/client
yarn pnpify prisma generate --schema db/schema.prisma

2. Web side missing deps

I did not explore this side much.

Module not found: Error: Can't resolve 'react' in '/home/dev/repos/oauth2-server-redwood/.yarn/__virtual__/react-dom-virtual-424690f422/0/cache/react-dom-npm-17.0.2-f551215af1-1c1eaa3bca.zip/node_modules/react-dom/cjs'
...
Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@babel/plugin-proposal-class-properties' imported from /home/dev/repos/oauth2-server-redwood/babel-virtual-resolve-base.js

Final setup

Test repo link when installation worked (but not rw dev) GitHub - UseKeyp/oauth2-server-redwood at 886d8cc6e15c41c62c5ef67c766cdb55babdf669

.yarnrc.yml

cacheFolder: "./.yarn/cache"

nodeLinker: pnp

pnpMode: "loose"

yarnPath: .yarn/releases/yarn-3.2.3.cjs

packageExtensions:
  "@prisma/client@*":
    dependencies:
      ".prisma": 'link:See "resolution" field of package.json'

package.json root

  "resolutions": {
    "@prisma/client/.prisma": "link:node_modules/.prisma"
  },
  "packageManager": "yarn@3.2.3",
  "dependenciesMeta": {
    "@prisma/client@4.9.0": {
      "unplugged": true
    },
    "prisma@4.9.0": {
      "unplugged": true
    }
  }
2 Likes

@pi0neerpat based on a quick read of your post, I believe that you dived a lot deeper into pnp world. My experience was driven by my desire to get rid of node_modules giant folder - and at that time I was successful. Since then (a year ago) both pnp and rw changed and I will start by repeating my experiments first and continue with your post above.

After a few days of mucking around, I established that even repeating my experiments isn’t that simple, mostly due to the changes that took place in my development context. So, do not hold your breath waiting for my next post :grinning: