Skip to content

Commit

Permalink
fix(cli): Exclude source maps from bundled client (#18571)
Browse files Browse the repository at this point in the history
Client, bundled in cli still shipped with source maps. Fixed by using
`npm-packlist`, so that contents of bundled client will always be
identical to `@prisma/client` pacakge.
  • Loading branch information
SevInf committed Apr 3, 2023
1 parent 7c1879c commit efab78e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
34 changes: 18 additions & 16 deletions packages/cli/helpers/copy-prisma-client.ts
@@ -1,23 +1,25 @@
import fg from 'fast-glob'
import { copySync } from 'fs-extra'
import packlist from 'npm-packlist'
import path from 'path'

// that's where we want to copy the local client for @prisma/studio
const clientCopyPath = path.join(__dirname, '..', 'prisma-client')
async function main() {
// that's where we want to copy the local client for @prisma/studio
const clientCopyPath = path.join(__dirname, '..', 'prisma-client')

// we resolve where the client is located via our own dependencies
const clientPath = path.dirname(require.resolve('@prisma/client'))
const clientPkg = require('@prisma/client/package.json')
// we resolve where the client is located via our own dependencies
const clientPath = path.dirname(require.resolve('@prisma/client'))

// we compute the paths of the files that would get npm published
// this uses a glob library to understand patterns in files.
// Using tooling from npm would be even better, but it is in magnitudes slower compared to this approach.
// Ideally, it would be great if we could remove this somehow.
const clientFiles = fg.sync(clientPkg.files, { cwd: clientPath, dot: true, onlyFiles: false })
const clientFiles = await packlist({ path: clientPath })

// we copy each file that we found in pkg to a new destination
for (const file of clientFiles) {
const from = path.join(clientPath, file)
const to = path.join(clientCopyPath, file)
copySync(from, to, { overwrite: true, recursive: true })
// we copy each file that we found in pkg to a new destination
for (const file of clientFiles) {
const from = path.join(clientPath, file)
const to = path.join(clientCopyPath, file)
copySync(from, to, { overwrite: true, recursive: true })
}
}

main().catch((error) => {
console.error(error)
process.exitCode = 1
})
1 change: 1 addition & 0 deletions packages/cli/package.json
Expand Up @@ -94,6 +94,7 @@
"line-replace": "2.0.1",
"log-update": "4.0.0",
"node-fetch": "2.6.9",
"npm-packlist": "5.1.3",
"open": "7.4.2",
"pkg-up": "3.1.0",
"resolve-pkg": "2.0.0",
Expand Down
5 changes: 2 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efab78e

Please sign in to comment.