mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-31 19:18:19 -05:00
fix: throw an exception if the workspace manifest is named incorrectly
PR #3039
This commit is contained in:
5
.changeset/hot-apples-bow.md
Normal file
5
.changeset/hot-apples-bow.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/find-workspace-dir": major
|
||||
---
|
||||
|
||||
Throw an exception if the workspace manifest is created with the wrong extension.
|
||||
@@ -28,6 +28,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/pnpm/pnpm/blob/master/packages/find-workspace-dir#readme",
|
||||
"dependencies": {
|
||||
"@pnpm/error": "workspace:^1.4.0",
|
||||
"find-up": "^5.0.0"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm"
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import PnpmError from '@pnpm/error'
|
||||
import path = require('path')
|
||||
import findUp = require('find-up')
|
||||
|
||||
const WORKSPACE_MANIFEST_FILENAME = 'pnpm-workspace.yaml'
|
||||
|
||||
export default async function findWorkspaceDir (cwd: string) {
|
||||
const workspaceManifestLocation = await findUp(WORKSPACE_MANIFEST_FILENAME, { cwd })
|
||||
const workspaceManifestLocation = await findUp([WORKSPACE_MANIFEST_FILENAME, 'pnpm-workspace.yml'], { cwd })
|
||||
if (workspaceManifestLocation?.endsWith('.yml')) {
|
||||
throw new PnpmError('BAD_WORKSPACE_MANIFEST_NAME', `The workspace manifest file should be named "pnpm-workspace.yaml". File found: ${workspaceManifestLocation}`)
|
||||
}
|
||||
return workspaceManifestLocation && path.dirname(workspaceManifestLocation)
|
||||
}
|
||||
|
||||
@@ -8,5 +8,9 @@
|
||||
"src/**/*.ts",
|
||||
"../../typings/**/*.d.ts"
|
||||
],
|
||||
"references": []
|
||||
"references": [
|
||||
{
|
||||
"path": "../error"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { scopeLogger } from '@pnpm/core-loggers'
|
||||
import { filterPackages } from '@pnpm/filter-workspace-packages'
|
||||
import findWorkspacePackages from '@pnpm/find-workspace-packages'
|
||||
import logger from '@pnpm/logger'
|
||||
import { ParsedCliArgs } from '@pnpm/parse-cli-args'
|
||||
import checkForUpdates from './checkForUpdates'
|
||||
import pnpmCmds, { getRCOptionsTypes } from './cmd'
|
||||
import { formatUnknownOptionsError } from './formatError'
|
||||
@@ -41,6 +42,14 @@ const DEPRECATED_OPTIONS = new Set([
|
||||
])
|
||||
|
||||
export default async function run (inputArgv: string[]) {
|
||||
let parsedCliArgs!: ParsedCliArgs
|
||||
try {
|
||||
parsedCliArgs = await parseCliArgs(inputArgv)
|
||||
} catch (err) {
|
||||
// Reporting is not initialized at this point, so just printing the error
|
||||
printError(err.message, err['hint'])
|
||||
process.exit(1)
|
||||
}
|
||||
const {
|
||||
argv,
|
||||
params: cliParams,
|
||||
@@ -48,10 +57,9 @@ export default async function run (inputArgv: string[]) {
|
||||
cmd,
|
||||
unknownOptions,
|
||||
workspaceDir,
|
||||
} = await parseCliArgs(inputArgv)
|
||||
} = parsedCliArgs
|
||||
if (cmd !== null && !pnpmCmds[cmd]) {
|
||||
console.error(`${chalk.bgRed.black('\u2009ERROR\u2009')} ${chalk.red(`Unknown command '${cmd}'`)}`)
|
||||
console.log('For help, run: pnpm help')
|
||||
printError(`Unknown command '${cmd}'`, 'For help, run: pnpm help')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -66,8 +74,7 @@ export default async function run (inputArgv: string[]) {
|
||||
}
|
||||
console.log(deprecationMsg)
|
||||
} else {
|
||||
console.error(formatUnknownOptionsError(unknownOptions))
|
||||
console.log(`For help, run: pnpm help${cmd ? ` ${cmd}` : ''}`)
|
||||
printError(formatUnknownOptionsError(unknownOptions), `For help, run: pnpm help${cmd ? ` ${cmd}` : ''}`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
@@ -91,12 +98,8 @@ export default async function run (inputArgv: string[]) {
|
||||
config.argv = argv
|
||||
} catch (err) {
|
||||
// Reporting is not initialized at this point, so just printing the error
|
||||
console.error(`${chalk.bgRed.black('\u2009ERROR\u2009')} ${chalk.red(err.message)}`)
|
||||
if (err['hint']) {
|
||||
console.log(err['hint'])
|
||||
} else {
|
||||
console.log(`For help, run: pnpm help${cmd ? ` ${cmd}` : ''}`)
|
||||
}
|
||||
const hint = err['hint'] ? err['hint'] : `For help, run: pnpm help${cmd ? ` ${cmd}` : ''}`
|
||||
printError(err.message, hint)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -247,3 +250,10 @@ export default async function run (inputArgv: string[]) {
|
||||
process.exit(exitCode)
|
||||
}
|
||||
}
|
||||
|
||||
function printError (message: string, hint?: string) {
|
||||
console.error(`${chalk.bgRed.black('\u2009ERROR\u2009')} ${chalk.red(message)}`)
|
||||
if (hint) {
|
||||
console.log(hint)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,21 @@ test('no projects found', async () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('incorrect workspace manifest', async () => {
|
||||
preparePackages([
|
||||
{
|
||||
name: 'project',
|
||||
version: '1.0.0',
|
||||
},
|
||||
])
|
||||
|
||||
await writeYamlFile('pnpm-workspace.yml', { packages: ['**', '!store/**'] })
|
||||
|
||||
const { status, stderr } = execPnpmSync(['install'])
|
||||
expect(stderr.toString()).toMatch(/The workspace manifest file should be named "pnpm-workspace.yaml"/)
|
||||
expect(status).toBe(1)
|
||||
})
|
||||
|
||||
test('linking a package inside a monorepo', async () => {
|
||||
const projects = preparePackages([
|
||||
{
|
||||
|
||||
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
@@ -544,8 +544,10 @@ importers:
|
||||
p-filter: ^2.1.0
|
||||
packages/find-workspace-dir:
|
||||
dependencies:
|
||||
'@pnpm/error': 'link:../error'
|
||||
find-up: 5.0.0
|
||||
specifiers:
|
||||
'@pnpm/error': 'workspace:^1.4.0'
|
||||
find-up: ^5.0.0
|
||||
packages/find-workspace-packages:
|
||||
dependencies:
|
||||
|
||||
Reference in New Issue
Block a user