-
Notifications
You must be signed in to change notification settings - Fork 67
Facade package @prisma/photon
#261
Comments
Awesome, I think this would feel very idiomatic. |
With https://github.com/prisma-labs/nexus-prisma/blob/master/package.json#L23 "dependencies": {
"@prisma/photon": "^0.2.94", for e.g. types: import * as Photon from '@prisma/photon'
import { transform } from './transformer'
import { DMMFClass } from './DMMFClass'
export function fromPhotonDMMF(photonDMMF: Photon.DMMF.Document): DMMFClass {
return new DMMFClass(transform(photonDMMF))
} We're pinning against the generator but what we're actually interested in is the runtime. Ideally libs should be able to depend on a pinned version of My conclusion from the above requirement is that Maybe I'm missing something, but this seems to be more than just about DX then, but reliability. |
@jasonkuhrt My understanding is that the runtime is downloaded during the generation step, and what is generated/ downloaded is determined by the version of prisma2. Of course that may be false, but that's the mental model that I'm currently working with. |
@jasonkuhrt Apologies. I didn't grasp the full context of what you're suggesting during my first read. I now understand that you want to pin against a specifically generated version of the runtime and the client in a 3rd party lib as a peer dependency. |
Related prisma/specs#152 |
The first hiccup I ran into when trying this out. I made an empty package that runs Figuring out a way to override this. Update: Take 1 at fixing this - prisma/prisma#789 |
When prisma2 generate is run from within node_modules, npm scripts provide that path as the process.cwd() path However, it also provides the init cwd in this environment variable: https://docs.npmjs.com/cli/run-script Related issue: prisma/prisma-client-js#261
Notes from further exploration on Heroku.
With this setup, Heroku has a race condition between running the As a temporary workaround, I am using Also to note that Heroku has defaults for stripping Sample Photon placeholder: https://github.com/divyendu-test/photon-placeholder |
But first Heroku installs everything, runs |
@jasonkuhrt Great catch, just ran into this: https://help.heroku.com/P5IMU3MP/heroku-node-js-build-script-change-faq This means using "build" in place of "postinstall" might work for Heroku (still not a generic solution) 👍 Update: This only works for app level "build", doesn't change much for a sub-package ( |
This looks like an interesting direction, all I would as is that you check that it works with yarn workspaces, where packages might be hoisted to the root. Theoretically you could have 2 divergent |
Update: The docs update is in progress and will be finished by tomorrow. Breaking change will be prominently highlighted in release notes. |
@nikolasburk Sounds great! It turns out that the release notes can be found under the prisma2 repo. |
Implemented in preview release 17. |
Naive question: what is the reason for generating the photon library in Is that to ensure it's not committed into SCM given that it's normally generated from the Prisma file (which is generally managed from within the SCM)? |
@2color the generation result is based on the contents of the users' |
@2color we also have a short section about this in the docs: https://github.com/prisma/prisma2/blob/master/docs/photon/codegen-and-node-setup.md#why-is-photonjs-generated-into-node_modulesprismaphoton-by-default TLDR:
|
@2color i think I misunderstood your question. You were talking about user’s project scm, I missed that. Anyways @nikolasburk gave a great answer! |
I'm having an issue with deploying a prisma client to heroku. The client is generated in postinstall (default to node_modules) but after herokus pruning and starting the app I get following error: "Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again." |
@Johannes-B-stock you can modify the location of the generated client: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/generators Maybe that'll work, and then you can be sure that it's the pruning step. |
@Johannes-B-stock We also have this example on Heroku from our E2E tests https://github.com/prisma/prisma2-e2e-tests/tree/master/platforms/heroku |
This issue describes the idea to introduce a new NPM package published on
@prisma/photon
to solve current usability problems and make Photon.js more resilient in regards to build and deployment workflows. (Note: This issue also assumes the path of the generated Photon.js library is changed from@generated/photon
to@prisma/photon
as described in #88. The mentioned@prisma/photon
package below has nothing to do with the currently existing NPM package which is an implementation detail.)1. Current problems
There are currently a few friction points in regards to the "generated
node_modules
package nature" of Photon.js as follows:1.1. Users are currently required to add
"postinstall": 'prisma2 generate'"
to theirscripts
in theirpackage.json
file to make sure Photon.js is re-generated after e.g.npm install
has been running. This is an additional friction point that we should remove as it clutters a userspackage.json
file and in the case of a user forgetting to add it will lead to breaking a users app.1.2. Even with a
postinstall
in place there still seems to be an issue with packages being pruned (see #88 (comment)).2. Solution
The solution for the problems above could be to introduce a "facade package" published on NPM as
@prisma/photon
which the user adds to theirpackage.json
as any other regular package. This "facade package" doesn't come with the actual Photon.js library (i.e. no runtime/types) but is basically just a "smart placeholder" to solve the problems above and provide a better user experience. The user would still need to runprisma2 generate
(initially and whenever their Prisma schema changes) however Photon.js wouldn't be deleted anymore when the user runs e.g.npm install
and "survives pruning".Running
prisma2 generate
will overwrite the facade package and basically replace it with a functional version of Photon.js. (The specifics of this are TBD. It could also simply add e.g. agenerated
folder in the facade package which makes it functional. Engineering will have to figure out the details here.)To make things even smoother the
@prisma/photon
package can provide its ownpostinstall
hook (i.e. not required in the user'spackage.json
) which could do the following when a user runsnpm install
:prisma2
is available in the$PATH
(either globally or via NPM) and callprisma2 generate
. Otherwise print a helpful message in the terminal that the user still needs to runprisma2 generate
prisma2 generate
yet.3. Considerations
postinstall
step.npm install @prisma/photon
the primary getting started experience. However, the user would still need theprisma
Framework CLI as a dev dependency.output
config option for thephotonjs
generator.4. Related issues
package.json
alongside Photon prisma#6645. Further notes
In order to make the generation step optional, I also considered to split up Photon.js into an optional generated
@types/@prisma/photon
types component (same asnexus-prisma
does) and a separate runtime library component published on NPM. However this doesn't work as you still need a generation step to generate the "DMMF" part of Photon.js which isn't really an improvement. I still wanted to document these thoughts here regardless. 🤷♂The text was updated successfully, but these errors were encountered: