mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix: print a warning if a package.json uses workspaces field (#5547)
close #5363 close #5413
This commit is contained in:
6
.changeset/twelve-bikes-serve.md
Normal file
6
.changeset/twelve-bikes-serve.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/config": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Print a warning if a package.json has a workspaces field but there is no pnpm-workspace.yaml file [#5363](https://github.com/pnpm/pnpm/issues/5363).
|
||||
@@ -54,6 +54,7 @@
|
||||
"devDependencies": {
|
||||
"@pnpm/config": "workspace:*",
|
||||
"@pnpm/prepare": "workspace:*",
|
||||
"@pnpm/test-fixtures": "workspace:*",
|
||||
"@types/is-windows": "^1.0.0",
|
||||
"@types/ramda": "0.28.15",
|
||||
"@types/which": "^2.0.1",
|
||||
|
||||
@@ -524,7 +524,10 @@ export async function getConfig (
|
||||
if (!pnpmConfig.ignorePnpmfile) {
|
||||
pnpmConfig.hooks = requireHooks(pnpmConfig.lockfileDir ?? pnpmConfig.dir, pnpmConfig)
|
||||
}
|
||||
pnpmConfig.rootProjectManifest = await safeReadProjectManifestOnly(pnpmConfig.lockfileDir ?? pnpmConfig.dir) ?? undefined
|
||||
pnpmConfig.rootProjectManifest = await safeReadProjectManifestOnly(pnpmConfig.lockfileDir ?? pnpmConfig.workspaceDir ?? pnpmConfig.dir) ?? undefined
|
||||
if (pnpmConfig.rootProjectManifest?.['workspaces']?.length && !pnpmConfig.workspaceDir) {
|
||||
warnings.push('The "workspaces" field in package.json is not supported by pnpm. Create a "pnpm-workspace.yaml" file instead.')
|
||||
}
|
||||
|
||||
pnpmConfig.failedToLoadBuiltInConfig = failedToLoadBuiltInConfig
|
||||
|
||||
|
||||
3
packages/config/test/fixtures/pkg-using-workspaces/package.json
vendored
Normal file
3
packages/config/test/fixtures/pkg-using-workspaces/package.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"workspaces": ["packages/*"]
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { getConfig } from '@pnpm/config'
|
||||
import { PnpmError } from '@pnpm/error'
|
||||
import loadNpmConf from '@pnpm/npm-conf'
|
||||
import { prepare, prepareEmpty } from '@pnpm/prepare'
|
||||
import { fixtures } from '@pnpm/test-fixtures'
|
||||
|
||||
import symlinkDir from 'symlink-dir'
|
||||
|
||||
@@ -26,6 +27,7 @@ const env = {
|
||||
PNPM_HOME: __dirname,
|
||||
[PATH]: __dirname,
|
||||
}
|
||||
const f = fixtures(__dirname)
|
||||
|
||||
test('getConfig()', async () => {
|
||||
const { config } = await getConfig({
|
||||
@@ -941,3 +943,31 @@ test('getConfig() returns failedToLoadBuiltInConfig', async () => {
|
||||
|
||||
expect(config.failedToLoadBuiltInConfig).toBeDefined()
|
||||
})
|
||||
|
||||
test('return a warning if a package.json has workspaces field but there is no pnpm-workspaces.yaml file', async () => {
|
||||
const prefix = f.find('pkg-using-workspaces')
|
||||
const { warnings } = await getConfig({
|
||||
cliOptions: { dir: prefix },
|
||||
packageManager: {
|
||||
name: 'pnpm',
|
||||
version: '1.0.0',
|
||||
},
|
||||
})
|
||||
|
||||
expect(warnings).toStrictEqual([
|
||||
'The "workspaces" field in package.json is not supported by pnpm. Create a "pnpm-workspace.yaml" file instead.',
|
||||
])
|
||||
})
|
||||
|
||||
test('do not return a warning if a package.json has workspaces field and there is a pnpm-workspace.yaml file', async () => {
|
||||
const prefix = f.find('pkg-using-workspaces')
|
||||
const { warnings } = await getConfig({
|
||||
cliOptions: { dir: prefix },
|
||||
workspaceDir: prefix,
|
||||
packageManager: {
|
||||
name: 'pnpm',
|
||||
version: '1.0.0',
|
||||
},
|
||||
})
|
||||
expect(warnings).toStrictEqual([])
|
||||
})
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
{
|
||||
"path": "../../privatePackages/prepare"
|
||||
},
|
||||
{
|
||||
"path": "../../privatePackages/test-fixtures"
|
||||
},
|
||||
{
|
||||
"path": "../constants"
|
||||
},
|
||||
|
||||
47
pnpm-lock.yaml
generated
47
pnpm-lock.yaml
generated
@@ -214,22 +214,6 @@ importers:
|
||||
specifier: 13.2.9
|
||||
version: 13.2.9
|
||||
|
||||
packages/network.auth-header:
|
||||
dependencies:
|
||||
'@pnpm/error':
|
||||
specifier: workspace:*
|
||||
version: link:../error
|
||||
nerf-dart:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0
|
||||
devDependencies:
|
||||
'@pnpm/network.auth-header':
|
||||
specifier: workspace:*
|
||||
version: 'link:'
|
||||
safe-buffer:
|
||||
specifier: 5.2.1
|
||||
version: 5.2.1
|
||||
|
||||
packages/build-modules:
|
||||
dependencies:
|
||||
'@pnpm/calc-dep-state':
|
||||
@@ -432,9 +416,6 @@ importers:
|
||||
|
||||
packages/client:
|
||||
dependencies:
|
||||
'@pnpm/network.auth-header':
|
||||
specifier: workspace:*
|
||||
version: link:../network.auth-header
|
||||
'@pnpm/default-resolver':
|
||||
specifier: workspace:*
|
||||
version: link:../default-resolver
|
||||
@@ -450,6 +431,9 @@ importers:
|
||||
'@pnpm/git-fetcher':
|
||||
specifier: workspace:*
|
||||
version: link:../git-fetcher
|
||||
'@pnpm/network.auth-header':
|
||||
specifier: workspace:*
|
||||
version: link:../network.auth-header
|
||||
'@pnpm/resolver-base':
|
||||
specifier: workspace:*
|
||||
version: link:../resolver-base
|
||||
@@ -539,6 +523,9 @@ importers:
|
||||
'@pnpm/prepare':
|
||||
specifier: workspace:*
|
||||
version: link:../../privatePackages/prepare
|
||||
'@pnpm/test-fixtures':
|
||||
specifier: workspace:*
|
||||
version: link:../../privatePackages/test-fixtures
|
||||
'@types/is-windows':
|
||||
specifier: ^1.0.0
|
||||
version: 1.0.0
|
||||
@@ -2422,6 +2409,22 @@ importers:
|
||||
specifier: ^3.0.2
|
||||
version: 3.0.2
|
||||
|
||||
packages/network.auth-header:
|
||||
dependencies:
|
||||
'@pnpm/error':
|
||||
specifier: workspace:*
|
||||
version: link:../error
|
||||
nerf-dart:
|
||||
specifier: 1.0.0
|
||||
version: 1.0.0
|
||||
devDependencies:
|
||||
'@pnpm/network.auth-header':
|
||||
specifier: workspace:*
|
||||
version: 'link:'
|
||||
safe-buffer:
|
||||
specifier: 5.2.1
|
||||
version: 5.2.1
|
||||
|
||||
packages/node.fetcher:
|
||||
dependencies:
|
||||
'@pnpm/create-cafs-store':
|
||||
@@ -2999,9 +3002,6 @@ importers:
|
||||
'@pnpm/audit':
|
||||
specifier: workspace:*
|
||||
version: link:../audit
|
||||
'@pnpm/network.auth-header':
|
||||
specifier: workspace:*
|
||||
version: link:../network.auth-header
|
||||
'@pnpm/cli-utils':
|
||||
specifier: workspace:*
|
||||
version: link:../cli-utils
|
||||
@@ -3017,6 +3017,9 @@ importers:
|
||||
'@pnpm/lockfile-file':
|
||||
specifier: workspace:*
|
||||
version: link:../lockfile-file
|
||||
'@pnpm/network.auth-header':
|
||||
specifier: workspace:*
|
||||
version: link:../network.auth-header
|
||||
'@pnpm/read-project-manifest':
|
||||
specifier: workspace:*
|
||||
version: link:../read-project-manifest
|
||||
|
||||
Reference in New Issue
Block a user