fix: print a warning if a package.json uses workspaces field (#5547)

close #5363
close #5413
This commit is contained in:
Zoltan Kochan
2022-10-25 12:20:17 +03:00
committed by GitHub
parent f365491653
commit aacb83f734
7 changed files with 72 additions and 23 deletions

View 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).

View File

@@ -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",

View File

@@ -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

View File

@@ -0,0 +1,3 @@
{
"workspaces": ["packages/*"]
}

View File

@@ -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([])
})

View File

@@ -12,6 +12,9 @@
{
"path": "../../privatePackages/prepare"
},
{
"path": "../../privatePackages/test-fixtures"
},
{
"path": "../constants"
},

47
pnpm-lock.yaml generated
View File

@@ -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