MCPcopy
hub / github.com/prisma/prisma / getPackedPackage

Function getPackedPackage

packages/internals/src/getPackedPackage.ts:9–47  ·  view source on GitHub ↗
(name: string, target?: string, packageDir?: string)

Source from the content-addressed store, hash-verified

7import { resolvePkg } from './resolvePkg'
8
9export async function getPackedPackage(name: string, target?: string, packageDir?: string): Promise<string | void> {
10 packageDir =
11 packageDir || (await resolvePkg(name, { basedir: process.cwd() })) || (await resolvePkg(name, { basedir: target }))
12
13 if (!packageDir) {
14 const pkgPath = up({ cwd: target })
15 if (pkgPath) {
16 const pkgJson = JSON.parse(readFileSync(pkgPath, { encoding: 'utf-8' }))
17 if (pkgJson.name === name) {
18 packageDir = path.dirname(pkgPath)
19 }
20 }
21 }
22
23 if (!packageDir && fs.existsSync(path.join(process.cwd(), 'package.json'))) {
24 packageDir = process.cwd()
25 }
26
27 if (!packageDir) {
28 throw new Error(`Error in getPackage: Could not resolve package ${name} from ${process.cwd()} target ${target}`)
29 }
30
31 const tmpDir = target ?? tempy.directory() // thanks Sindre
32
33 const pkgFiles = await packlist({ path: packageDir })
34
35 // we compute the paths of the files that would get npm published
36
37 // we copy each file that we found in pkg to a new destination
38 for (const file of pkgFiles) {
39 const src = path.join(packageDir, file)
40 const dest = path.join(tmpDir, file)
41
42 await fs.promises.mkdir(path.dirname(dest), { recursive: true })
43 await fs.promises.copyFile(src, dest)
44 }
45
46 return path.join(tmpDir)
47}

Callers 4

generateInFolderFunction · 0.90
types.test.tsFile · 0.90
generator.test.tsFile · 0.90

Calls 3

resolvePkgFunction · 0.90
readFileSyncFunction · 0.90
parseMethod · 0.65

Tested by

no test coverage detected