fix(deploy): write node_modules/.modules.yaml to the deploy directory (#8465)

close #7731
This commit is contained in:
Zoltan Kochan
2024-08-26 17:07:16 +02:00
committed by GitHub
parent 9c56ca0be9
commit 7ee59a166a
6 changed files with 29 additions and 7 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-deploy": patch
"pnpm": patch
---
`pnpm deploy` should write the `node_modules/.modules.yaml` to the `node_modules` directory within the deploy directory [#7731](https://github.com/pnpm/pnpm/issues/7731).

View File

@@ -0,0 +1,6 @@
---
"@pnpm/types": minor
"@pnpm/plugin-commands-installation": minor
---
Added optional modulesDir field to projects.

View File

@@ -3,6 +3,7 @@ import { type ProjectManifest } from './package'
export interface Project {
rootDir: ProjectRootDir
rootDirRealPath: ProjectRootDirRealPath
modulesDir?: string
manifest: ProjectManifest
writeProjectManifest: (manifest: ProjectManifest, force?: boolean | undefined) => Promise<void>
}

View File

@@ -504,12 +504,16 @@ function getAllProjects (manifestsByPath: ManifestsByPath, allProjectsGraph: Pro
const chunks = sort !== false
? sortPackages(allProjectsGraph)
: [(Object.keys(allProjectsGraph) as ProjectRootDir[]).sort()]
return chunks.map((prefixes, buildIndex) => prefixes.map((rootDir) => ({
buildIndex,
manifest: manifestsByPath[rootDir].manifest,
rootDir,
rootDirRealPath: allProjectsGraph[rootDir].package.rootDirRealPath,
}))).flat()
return chunks.map((prefixes, buildIndex) => prefixes.map((rootDir) => {
const { rootDirRealPath, modulesDir } = allProjectsGraph[rootDir].package
return {
buildIndex,
manifest: manifestsByPath[rootDir].manifest,
rootDir,
rootDirRealPath,
modulesDir,
}
})).flat()
}
interface ManifestsByPath { [dir: string]: Omit<Project, 'rootDir' | 'rootDirRealPath'> }

View File

@@ -88,6 +88,10 @@ export async function handler (
await fs.promises.mkdir(deployDir, { recursive: true })
const includeOnlyPackageFiles = !opts.deployAllFiles
await copyProject(deployedDir, deployDir, { includeOnlyPackageFiles })
const deployedProject = opts.allProjects?.find(({ rootDir }) => rootDir === deployedDir)
if (deployedProject) {
deployedProject.modulesDir = path.relative(deployedDir, path.join(deployDir, 'node_modules'))
}
await install.handler({
...opts,
confirmModulesPurge: false,
@@ -109,7 +113,7 @@ export async function handler (
preferFrozenLockfile: false,
saveLockfile: false,
virtualStoreDir: path.join(deployDir, 'node_modules/.pnpm'),
modulesDir: path.relative(deployedDir, path.join(deployDir, 'node_modules')),
modulesDir: path.relative(opts.workspaceDir, path.join(deployDir, 'node_modules')),
rawLocalConfig: {
...opts.rawLocalConfig,
// This is a workaround to prevent frozen install in CI envs.

View File

@@ -69,6 +69,7 @@ test('deploy', async () => {
project.hasNot('is-negative')
expect(fs.existsSync('deploy/index.js')).toBeTruthy()
expect(fs.existsSync('deploy/test.js')).toBeFalsy()
expect(fs.existsSync('deploy/node_modules/.modules.yaml')).toBeTruthy()
expect(fs.existsSync('deploy/node_modules/.pnpm/project-2@file+project-2/node_modules/project-2/index.js')).toBeTruthy()
expect(fs.existsSync('deploy/node_modules/.pnpm/project-2@file+project-2/node_modules/project-2/test.js')).toBeFalsy()
expect(fs.existsSync('deploy/node_modules/.pnpm/project-3@file+project-3/node_modules/project-3/index.js')).toBeTruthy()