mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix(deploy): write node_modules/.modules.yaml to the deploy directory (#8465)
close #7731
This commit is contained in:
6
.changeset/pretty-yaks-remember.md
Normal file
6
.changeset/pretty-yaks-remember.md
Normal 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).
|
||||
6
.changeset/three-games-remember.md
Normal file
6
.changeset/three-games-remember.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/types": minor
|
||||
"@pnpm/plugin-commands-installation": minor
|
||||
---
|
||||
|
||||
Added optional modulesDir field to projects.
|
||||
@@ -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>
|
||||
}
|
||||
|
||||
@@ -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'> }
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user