mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-31 13:32:18 -04:00
fix: print warning when installing dependency from a non-existent directory (#7222)
* chore: print warning when installing dependency from a non-existent directory * chore: remove console.log * refactor: message * docs: add changesets --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
6
.changeset/fast-ants-tie.md
Normal file
6
.changeset/fast-ants-tie.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@pnpm/local-resolver": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Print a warning when installing a dependency from a non-existent directory [#7159](https://github.com/pnpm/pnpm/issues/7159)
|
||||
5
.changeset/heavy-candles-retire.md
Normal file
5
.changeset/heavy-candles-retire.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/local-resolver": major
|
||||
---
|
||||
|
||||
`@pnpm/logger` added as a peer dependency.
|
||||
3
pnpm-lock.yaml
generated
3
pnpm-lock.yaml
generated
@@ -4917,6 +4917,9 @@ importers:
|
||||
'@pnpm/graceful-fs':
|
||||
specifier: workspace:*
|
||||
version: link:../../fs/graceful-fs
|
||||
'@pnpm/logger':
|
||||
specifier: ^5.0.0
|
||||
version: 5.0.0
|
||||
'@pnpm/read-project-manifest':
|
||||
specifier: workspace:*
|
||||
version: link:../../pkg-manifest/read-project-manifest
|
||||
|
||||
@@ -45,6 +45,9 @@
|
||||
"@types/normalize-path": "^3.0.0",
|
||||
"@types/ssri": "^7.1.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@pnpm/logger": "^5.0.0"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm",
|
||||
"exports": {
|
||||
".": "./lib/index.js"
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
} from '@pnpm/resolver-base'
|
||||
import { type DependencyManifest } from '@pnpm/types'
|
||||
import ssri from 'ssri'
|
||||
import { logger } from '@pnpm/logger'
|
||||
import { parsePref, type WantedLocalDependency } from './parsePref'
|
||||
|
||||
export type { WantedLocalDependency }
|
||||
@@ -59,6 +60,10 @@ export async function resolveFromLocal (
|
||||
throw new PnpmError('LINKED_PKG_DIR_NOT_FOUND',
|
||||
`Could not install from "${spec.fetchSpec}" as it does not exist.`)
|
||||
}
|
||||
logger.warn({
|
||||
message: `Installing a dependency from a non-existent directory: ${spec.fetchSpec}`,
|
||||
prefix: opts.projectDir,
|
||||
})
|
||||
localDependencyManifest = {
|
||||
name: path.basename(spec.fetchSpec),
|
||||
version: '0.0.0',
|
||||
|
||||
@@ -3,6 +3,7 @@ import path from 'path'
|
||||
import { resolveFromLocal } from '@pnpm/local-resolver'
|
||||
import { type DirectoryResolution } from '@pnpm/resolver-base'
|
||||
import normalize from 'normalize-path'
|
||||
import { logger } from '@pnpm/logger'
|
||||
|
||||
test('resolve directory', async () => {
|
||||
const resolveResult = await resolveFromLocal({ pref: '..' }, { projectDir: __dirname })
|
||||
@@ -128,12 +129,18 @@ test('fail when resolving from not existing directory an injected dependency', a
|
||||
})
|
||||
|
||||
test('do not fail when resolving from not existing directory', async () => {
|
||||
jest.spyOn(logger, 'warn')
|
||||
const wantedDependency = { pref: 'link:./dir-does-not-exist' }
|
||||
const resolveResult = await resolveFromLocal(wantedDependency, { projectDir: __dirname })
|
||||
expect(resolveResult?.manifest).toStrictEqual({
|
||||
name: 'dir-does-not-exist',
|
||||
version: '0.0.0',
|
||||
})
|
||||
expect(logger.warn).toHaveBeenCalledWith({
|
||||
message: `Installing a dependency from a non-existent directory: ${path.join(__dirname, './dir-does-not-exist')}`,
|
||||
prefix: __dirname,
|
||||
})
|
||||
;(logger.warn as jest.Mock).mockRestore()
|
||||
})
|
||||
|
||||
test('throw error when the path: protocol is used', async () => {
|
||||
|
||||
Reference in New Issue
Block a user