Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add warning if package.json specifies workspaces #5413

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/find-workspace-dir/package.json
Expand Up @@ -30,6 +30,7 @@
"homepage": "https://github.com/pnpm/pnpm/blob/main/packages/find-workspace-dir#readme",
"dependencies": {
"@pnpm/error": "workspace:*",
"@pnpm/graceful-fs": "workspace:*",
"find-up": "^5.0.0"
},
"funding": "https://opencollective.com/pnpm",
Expand Down
10 changes: 10 additions & 0 deletions packages/find-workspace-dir/src/index.ts
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import path from 'path'
import PnpmError from '@pnpm/error'
import findUp from 'find-up'
import gfs from '@pnpm/graceful-fs'

const WORKSPACE_DIR_ENV_VAR = 'NPM_CONFIG_WORKSPACE_DIR'
const WORKSPACE_MANIFEST_FILENAME = 'pnpm-workspace.yaml'
Expand All @@ -14,6 +15,15 @@ export default async function findWorkspaceDir (cwd: string) {
if (workspaceManifestLocation?.endsWith('.yml')) {
throw new PnpmError('BAD_WORKSPACE_MANIFEST_NAME', `The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${workspaceManifestLocation}`)
}
const packageManifestFile = workspaceManifestDirEnvVar
? path.join(workspaceManifestDirEnvVar, 'package.json')
: await findUp([WORKSPACE_MANIFEST_FILENAME, 'package.json'], { cwd: await getRealPath(cwd) })
const packageManifest = JSON.parse(await gfs.readFile(packageManifestFile!, 'utf-8'))

if (packageManifest?.workspaces?.length) {
throw new PnpmError('BAD_PACKAGE_JSON_WORKSPACES', 'The root package.json file should not have workspaces defined with pnpm. Remove and use "pnpm-workspace.yaml" instead!')
}

return workspaceManifestLocation && path.dirname(workspaceManifestLocation)
}

Expand Down
3 changes: 3 additions & 0 deletions packages/find-workspace-dir/tsconfig.json
Expand Up @@ -11,6 +11,9 @@
"references": [
{
"path": "../error"
},
{
"path": "../graceful-fs"
}
]
}
2 changes: 1 addition & 1 deletion packages/plugin-commands-publishing/package.json
Expand Up @@ -17,7 +17,7 @@
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7778 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7779 pnpm run test:e2e",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-commands-rebuild/package.json
Expand Up @@ -16,7 +16,7 @@
"registry-mock": "registry-mock",
"test:jest": "jest",
"test:e2e": "registry-mock prepare && run-p -r registry-mock test:jest",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7779 pnpm run test:e2e",
"_test": "cross-env PNPM_REGISTRY_MOCK_PORT=7778 pnpm run test:e2e",
"test": "pnpm run compile && pnpm run _test",
"prepublishOnly": "pnpm run compile",
"compile": "tsc --build && pnpm run lint --fix"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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