You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
unsafe eval() and relationship to ncc instead of package.json bin field #945
I noticed some eval's in the code as I was looking at the download.js files to experiment with some of the environment options I proposed in #938 (and eliminate the need for --unsafe-perm or anything that would be disallowed in an enterprise environment (such as a code analysis tool catching eval in a module and failing a build as a result.
My question is why are we using ncc instead of just the bin field in package.json? I'm not arguing against it, just want to make sure I understand the reasons it is there so I can be confident in any PR contributions.
Also, instead of using eval, did you happen to try returning the value instead like so:
// probably better to move this up here anywaysconstpath=require('path)
constbinaryPath=function(){returnpath.join(__dirname,'../')}constversion=(pkg&&pkg.prisma&&pkg.prisma.version)||'latest'download({binaries: {'query-engine': binaryPath(),'migration-engine': binaryPath(),},showProgress: true,
version,})
One of the reasons I'm asking about ncc is so I can understand the usage of the compiled binary during development of the cli itself. (what test would I perform if I wanted to test out replacing eval with returns?
Edit: forgot to remove the require in the return statement. Fixed that.
and yes, I did the see the issue referenced in the original commit, which is why i was wondering if the return approach had been tried before using eval.
Thanks @LongLiveCHIEF for asking this, that's indeed a good question I'm happy to answer.
We use ncc in 3 places:
For the prisma2 cli - We rely on a significant amount of packages and want them to be safely packaged together and not rely on yarn/npm resolving the correct dependencies. In Prisma 1, we used to have normal npm dependencies in our CLI, te installation time was 60-120s. Here, with Prisma 2 the installation time is now cut down to a fraction of that.
The runtime for Photon is also ncc'ed. This comes from the decision, that Photon can be generated into any folder, e.g. ./my-photon. That folder should include all the dependencies needed, so that it can just be copied around in a CI system if needed.
In regards to binaries, ncc has nothing to do with how binaries are fetched or used. The same mechanism of binary fetching could be used without ncc.
In regards to eval statements: For the use cases 1) and 2), ncc is obviously an optimization. The main reason there is speed.
For 3) - we need some system to package things.
So what is now on the horizon?
We could work with the ncc team to have a proper solution not including the eval hacks.
Then you go into prisma2/cli/prisma2, do yarn build and yarn download to see if it works. The problem that eval solves, is that ncc tries to be smart, and everything that includes path.join(__dirname, ...) or path.resolve(__dirname, ...) will be rewritten by it.
This is the tracking issue regarding eval and ncc vercel/ncc#390
Thanks for the response, that helps a bunch. I'm hoping I can become a contributor to the prisma2 ecosystem, so this kind of background summary is much appreciated!
Activity
LongLiveCHIEF commentedon Nov 15, 2019
and yes, I did the see the issue referenced in the original commit, which is why i was wondering if the return approach had been tried before using eval.
timsuchanek commentedon Nov 16, 2019
Thanks @LongLiveCHIEF for asking this, that's indeed a good question I'm happy to answer.
We use ncc in 3 places:
Photon.js is one generator, but there could be many more. The idea is, that a generator is a standalone executable, which can be executed by the
prisma2cli.Again, in order to save pulling tons of dependencies in, we chose to have this as a ncc'ed build.
./my-photon. That folder should include all the dependencies needed, so that it can just be copied around in a CI system if needed.In regards to binaries, ncc has nothing to do with how binaries are fetched or used. The same mechanism of binary fetching could be used without ncc.
In regards to
evalstatements: For the use cases 1) and 2), ncc is obviously an optimization. The main reason there is speed.For 3) - we need some system to package things.
So what is now on the horizon?
We will look into both options and I 100% agree, that we need to get rid of the eval statements.
Now back to your question, if the
Would work with ncc, the answer is no. You can simply try it out by running ncc over a test file with
ncc build: https://github.com/zeit/nccOr to see the whole thing running, you can use https://github.com/prisma/prisma2-development-environment
Then you go into
prisma2/cli/prisma2, doyarn buildandyarn downloadto see if it works. The problem thatevalsolves, is that ncc tries to be smart, and everything that includespath.join(__dirname, ...)orpath.resolve(__dirname, ...)will be rewritten by it.This is the tracking issue regarding eval and ncc vercel/ncc#390
LongLiveCHIEF commentedon Nov 16, 2019
Thanks for the response, that helps a bunch. I'm hoping I can become a contributor to the prisma2 ecosystem, so this kind of background summary is much appreciated!
tml-2869: explicit RLS control — @@rls enablement, policy rename, per…
TML-2991: diff uniques and indexes structurally — delete the reconcil…
chore(postgres-rls): close out the project — promote ADRs, delete pro…