fix: better error message on store mismatch

close #847
This commit is contained in:
Zoltan Kochan
2019-07-15 02:55:10 +03:00
parent 34a51b8939
commit 0fc38ec372
4 changed files with 16 additions and 8 deletions

View File

@@ -79,11 +79,15 @@ function reportUnexpectedStore (err: Error, msg: object) {
return stripIndent`
${formatErrorSummary(err.message)}
expected: ${highlight(msg['expectedStorePath'])}
actual: ${highlight(msg['actualStorePath'])}
The dependencies at "${msg['modulesDir']}" are currently linked from the store at "${msg['expectedStorePath']}".
If you want to use the new store, run the same command with the ${highlight('--force')} parameter.
`
pnpm now wants to use the store at "${msg['actualStorePath']}" to link dependencies.
If you want to use the new store location, reinstall your dependencies with "pnpm install --force".
You may change the global store location by running "pnpm config set store <location>".
(This error may happen if the node_modules was installed with a different major version of pnpm)
`
}
function reportStoreBreakingChange (msg: object) {

View File

@@ -3,14 +3,17 @@ import { PnpmError } from '../../errorTypes'
export default class UnexpectedStoreError extends PnpmError {
public expectedStorePath: string
public actualStorePath: string
public modulesDir: string
constructor (
opts: {
expectedStorePath: string,
actualStorePath: string,
modulesDir: string,
},
) {
super('ERR_PNPM_UNEXPECTED_STORE', 'Unexpected store used for installation')
super('ERR_PNPM_UNEXPECTED_STORE', 'Unexpected store location')
this.expectedStorePath = opts.expectedStorePath
this.actualStorePath = opts.actualStorePath
this.modulesDir = opts.modulesDir
}
}

View File

@@ -8,7 +8,7 @@ export default function checkCompatibility (
modules: Modules,
opts: {
storePath: string,
modulesPath: string,
modulesDir: string,
},
) {
// Important: comparing paths with path.relative()
@@ -19,11 +19,12 @@ export default function checkCompatibility (
throw new UnexpectedStoreError({
actualStorePath: opts.storePath,
expectedStorePath: modules.store,
modulesDir: opts.modulesDir,
})
}
if (!modules.layoutVersion || modules.layoutVersion !== LAYOUT_VERSION) {
throw new ModulesBreakingChangeError({
modulesPath: opts.modulesPath,
modulesPath: opts.modulesDir,
})
}
}

View File

@@ -183,7 +183,7 @@ async function validateNodeModules (
+ ' You must remove that option, or else add the --force option to recreate the "node_modules" folder.',
)
}
checkCompatibility(modules, { storePath: opts.store, modulesPath: importer.modulesDir })
checkCompatibility(modules, { storePath: opts.store, modulesDir: importer.modulesDir })
if (opts.lockfileDirectory !== importer.prefix && opts.include && modules.included) {
for (const depsField of DEPENDENCIES_FIELDS) {
if (opts.include[depsField] !== modules.included[depsField]) {