Skip to content

Commit

Permalink
fix: print a warning if a package.json uses workspaces field (#5547)
Browse files Browse the repository at this point in the history
close #5363
close #5413
  • Loading branch information
zkochan committed Oct 25, 2022
1 parent f365491 commit aacb83f
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .changeset/twelve-bikes-serve.md
@@ -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).
1 change: 1 addition & 0 deletions packages/config/package.json
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion packages/config/src/index.ts
Expand Up @@ -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

Expand Down
@@ -0,0 +1,3 @@
{
"workspaces": ["packages/*"]
}
30 changes: 30 additions & 0 deletions packages/config/test/index.ts
Expand Up @@ -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'

Expand All @@ -26,6 +27,7 @@ const env = {
PNPM_HOME: __dirname,
[PATH]: __dirname,
}
const f = fixtures(__dirname)

test('getConfig()', async () => {
const { config } = await getConfig({
Expand Down Expand Up @@ -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([])
})
3 changes: 3 additions & 0 deletions packages/config/tsconfig.json
Expand Up @@ -12,6 +12,9 @@
{
"path": "../../privatePackages/prepare"
},
{
"path": "../../privatePackages/test-fixtures"
},
{
"path": "../constants"
},
Expand Down
47 changes: 25 additions & 22 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 aacb83f

Please sign in to comment.