Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function lockfileToPnp (lockfileDirectory: string) {
const lockfile = await readWantedLockfile(lockfileDirectory, { ignoreIncompatible: true })
if (!lockfile) throw new Error('Cannot generate a .pnp.js without a lockfile')
const importerNames = {} as { [importerId: string]: string }
await Promise.all(
Object.keys(lockfile.importers)
.map(async (importerId) => {
const importerDirectory = path.join(lockfileDirectory, importerId)
const { manifest } = await readImporterManifest(importerDirectory)
importerNames[importerId] = manifest.name as string
}),
)
const { registries, store } = await getConfigs({ cliArgs: {}, packageManager: { name: 'pnpm', version: '*' } })
const storeDirectory = await resolveStoreDir(lockfileDirectory, store)
const packageRegistry = lockfileToPackageRegistry(lockfile, {
importerNames,
lockfileDirectory,
registries,
storeDirectory,
})
const loaderFile = pnp.generateInlinedScript({
blacklistedLocations: undefined,
ignorePattern: undefined,
packageRegistry,
shebang: undefined,
})
await fs.writeFile(path.join(lockfileDirectory, '.pnp.js'), loaderFile, 'utf8')
}