Skip to content

Commit

Permalink
fix(deploy): inject all types of deps (#5084)
Browse files Browse the repository at this point in the history
close #5078
  • Loading branch information
zkochan committed Jul 23, 2022
1 parent dcab314 commit 107d011
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/loud-weeks-move.md
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-deploy": patch
"pnpm": patch
---

`pnpm deploy` should inject local dependencies of all types (dependencies, optionalDependencies, devDependencies) [#5078](https://github.com/pnpm/pnpm/issues/5078).
1 change: 1 addition & 0 deletions packages/plugin-commands-deploy/package.json
Expand Up @@ -51,6 +51,7 @@
"@pnpm/error": "workspace:*",
"@pnpm/fs.indexed-pkg-importer": "workspace:*",
"@pnpm/plugin-commands-installation": "workspace:*",
"@pnpm/types": "workspace:*",
"@zkochan/rimraf": "^2.1.2",
"render-help": "^1.0.2"
},
Expand Down
13 changes: 1 addition & 12 deletions packages/plugin-commands-deploy/src/deploy.ts
Expand Up @@ -7,6 +7,7 @@ import { install } from '@pnpm/plugin-commands-installation'
import PnpmError from '@pnpm/error'
import rimraf from '@zkochan/rimraf'
import renderHelp from 'render-help'
import { deployHook } from './deployHook'

export const shorthands = install.shorthands

Expand Down Expand Up @@ -99,15 +100,3 @@ async function copyProject (src: string, dest: string) {
const importPkg = createIndexedPkgImporter('clone-or-copy')
await importPkg(dest, { filesMap: filesIndex, force: true, fromStore: true })
}

function deployHook (pkg: any) { // eslint-disable-line
pkg.dependenciesMeta = pkg.dependenciesMeta || {}
for (const [depName, depVersion] of Object.entries(pkg.dependencies ?? {})) {
if ((depVersion as string).startsWith('workspace:')) {
pkg.dependenciesMeta[depName] = {
injected: true,
}
}
}
return pkg
}
15 changes: 15 additions & 0 deletions packages/plugin-commands-deploy/src/deployHook.ts
@@ -0,0 +1,15 @@
import { DEPENDENCIES_FIELDS } from '@pnpm/types'

export function deployHook (pkg: any) { // eslint-disable-line
pkg.dependenciesMeta = pkg.dependenciesMeta || {}
for (const depField of DEPENDENCIES_FIELDS) {
for (const [depName, depVersion] of Object.entries(pkg[depField] ?? {})) {
if ((depVersion as string).startsWith('workspace:')) {
pkg.dependenciesMeta[depName] = {
injected: true,
}
}
}
}
return pkg
}
36 changes: 36 additions & 0 deletions packages/plugin-commands-deploy/test/deployHook.test.ts
@@ -0,0 +1,36 @@
import { deployHook } from '../src/deployHook'

test('deployHook()', () => {
expect(deployHook({
dependencies: {
a: 'workspace:1',
},
devDependencies: {
b: 'workspace:2',
},
optionalDependencies: {
c: 'workspace:3',
},
})).toStrictEqual({
dependencies: {
a: 'workspace:1',
},
devDependencies: {
b: 'workspace:2',
},
optionalDependencies: {
c: 'workspace:3',
},
dependenciesMeta: {
a: {
injected: true,
},
b: {
injected: true,
},
c: {
injected: true,
},
},
})
})
3 changes: 3 additions & 0 deletions packages/plugin-commands-deploy/tsconfig.json
Expand Up @@ -35,6 +35,9 @@
},
{
"path": "../plugin-commands-installation"
},
{
"path": "../types"
}
]
}
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 107d011

Please sign in to comment.