fix: rename .pnp.js to .pnp.cjs (#3148)

ref #2902
This commit is contained in:
Zoltan Kochan
2021-02-17 00:37:17 +02:00
committed by GitHub
parent 46e71ea4a6
commit 048c948719
11 changed files with 23 additions and 14 deletions

View File

@@ -0,0 +1,9 @@
---
"@pnpm/headless": major
"@pnpm/plugin-commands-script-runners": major
"@pnpm/lockfile-to-pnp": minor
"supi": minor
"@pnpm/mount-modules": patch
---
`.pnp.js` renamed to `.pnp.cjs` in order to force CommonJS.

2
.gitignore vendored
View File

@@ -6,7 +6,7 @@ npm-debug.log*
# Dependency directory
**/node_modules/**
_node_modules
.pnp.js
.pnp.cjs
# Coverage directory used by tools like istanbul
coverage

View File

@@ -351,7 +351,7 @@ export default async (opts: HeadlessOptions) => {
}
let extraEnv: Record<string, string> | undefined
if (opts.enablePnp) {
extraEnv = makeNodeRequireOption(path.join(opts.lockfileDir, '.pnp.js'))
extraEnv = makeNodeRequireOption(path.join(opts.lockfileDir, '.pnp.cjs'))
}
await buildModules(graph, Array.from(directNodes), {
childConcurrency: opts.childConcurrency,

View File

@@ -727,7 +727,7 @@ test('installing in a workspace', async () => {
test('installing with no symlinks but with PnP', async () => {
const prefix = path.join(fixtures, 'simple')
await rimraf(path.join(prefix, 'node_modules'))
await rimraf(path.join(prefix, '.pnp.js'))
await rimraf(path.join(prefix, '.pnp.cjs'))
await headless(await testDefaults({
enablePnp: true,
@@ -741,13 +741,13 @@ test('installing with no symlinks but with PnP', async () => {
const project = assertProject(prefix)
expect(await project.readCurrentLockfile()).toBeTruthy()
expect(await project.readModulesManifest()).toBeTruthy()
expect(await exists(path.join(prefix, '.pnp.js'))).toBeTruthy()
expect(await exists(path.join(prefix, '.pnp.cjs'))).toBeTruthy()
})
test('installing with no modules directory', async () => {
const prefix = path.join(fixtures, 'simple')
await rimraf(path.join(prefix, 'node_modules'))
await rimraf(path.join(prefix, '.pnp.js'))
await rimraf(path.join(prefix, '.pnp.cjs'))
await headless(await testDefaults({
enableModulesDir: false,

View File

@@ -14,7 +14,7 @@ import * as R from 'ramda'
export async function lockfileToPnp (lockfileDir: string) {
const lockfile = await readWantedLockfile(lockfileDir, { ignoreIncompatible: true })
if (!lockfile) throw new Error('Cannot generate a .pnp.js without a lockfile')
if (!lockfile) throw new Error('Cannot generate a .pnp.cjs without a lockfile')
const importerNames: { [importerId: string]: string } = {}
await Promise.all(
Object.keys(lockfile.importers)
@@ -54,7 +54,7 @@ export async function writePnpFile (
packageRegistry,
shebang: undefined,
})
await fs.writeFile(path.join(opts.lockfileDir, '.pnp.js'), loaderFile, 'utf8')
await fs.writeFile(path.join(opts.lockfileDir, '.pnp.cjs'), loaderFile, 'utf8')
}
export function lockfileToPackageRegistry (

View File

@@ -22,7 +22,7 @@ const STAT_DEFAULT = {
export default async function createFuseHandlers (lockfileDir: string, cafsDir: string) {
const lockfile = await readWantedLockfile(lockfileDir, { ignoreIncompatible: true })
if (!lockfile) throw new Error('Cannot generate a .pnp.js without a lockfile')
if (!lockfile) throw new Error('Cannot generate a .pnp.cjs without a lockfile')
return createFuseHandlersFromLockfile(lockfile, lockfileDir, cafsDir)
}

View File

@@ -73,7 +73,7 @@ export async function handler (
const chunks = opts.sort
? sortPackages(opts.selectedProjectsGraph)
: [Object.keys(opts.selectedProjectsGraph).sort()]
const existsPnp = existsInDir.bind(null, '.pnp.js')
const existsPnp = existsInDir.bind(null, '.pnp.cjs')
const workspacePnpPath = opts.workspaceDir && await existsPnp(opts.workspaceDir)
for (const chunk of chunks) {

View File

@@ -164,7 +164,7 @@ so you may run "pnpm -w ${scriptName}"`,
stdio: 'inherit',
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
}
const existsPnp = existsInDir.bind(null, '.pnp.js')
const existsPnp = existsInDir.bind(null, '.pnp.cjs')
const pnpPath = (opts.workspaceDir && await existsPnp(opts.workspaceDir)) ??
await existsPnp(dir)
if (pnpPath) {

View File

@@ -48,7 +48,7 @@ export default async (
opts.workspaceConcurrency === 1 ||
packageChunks.length === 1 && packageChunks[0].length === 1
) ? 'inherit' : 'pipe'
const existsPnp = existsInDir.bind(null, '.pnp.js')
const existsPnp = existsInDir.bind(null, '.pnp.cjs')
const workspacePnpPath = opts.workspaceDir && await existsPnp(opts.workspaceDir)
for (const chunk of packageChunks) {

View File

@@ -451,7 +451,7 @@ export async function mutateModules (
if (!opts.ignoreScripts) {
if (opts.enablePnp) {
scriptsOpts.extraEnv = makeNodeRequireOption(path.join(opts.lockfileDir, '.pnp.js'))
scriptsOpts.extraEnv = makeNodeRequireOption(path.join(opts.lockfileDir, '.pnp.cjs'))
}
await runLifecycleHooksConcurrently(['install', 'postinstall', 'prepublish', 'prepare'],
projectsToBeInstalled,
@@ -775,7 +775,7 @@ async function installInContext (
let extraEnv: Record<string, string> | undefined
if (opts.enablePnp) {
extraEnv = makeNodeRequireOption(path.join(opts.lockfileDir, '.pnp.js'))
extraEnv = makeNodeRequireOption(path.join(opts.lockfileDir, '.pnp.cjs'))
}
await buildModules(dependenciesGraph, rootNodes, {
childConcurrency: opts.childConcurrency,

View File

@@ -1217,7 +1217,7 @@ test('installing with no symlinks with PnP', async () => {
expect(await project.readCurrentLockfile()).toBeTruthy()
expect(await project.readModulesManifest()).toBeTruthy()
expect(await exists(path.resolve('.pnp.js'))).toBeTruthy()
expect(await exists(path.resolve('.pnp.cjs'))).toBeTruthy()
})
test('installing with no modules directory', async () => {