feat: print a warning if a globally installed package has no bins
PR #2402 close #2309 Co-Authored-By: Zoltan Kochan <zkochan@users.noreply.github.com>
This commit is contained in:
1 parent
028ebbd70b
commit
7ec32acce8
4 files changed
+43
-4
No files matched your search
@@ -81,7 +81,7 @@ async function linkBins (
|
||||
warn: (msg: string) => void,
|
||||
},
|
||||
) {
|
||||
if (!allCmds.length) return
|
||||
if (!allCmds.length) return [] as string[]
|
||||
|
||||
await makeDir(binPath)
|
||||
|
||||
@@ -105,6 +105,8 @@ async function linkBins (
|
||||
throw result.reason
|
||||
}
|
||||
}
|
||||
|
||||
return allCmds.map(cmd => cmd.pkgName)
|
||||
}
|
||||
|
||||
async function isFromModules (filename: string) {
|
||||
|
||||
@@ -74,6 +74,8 @@ export interface StrictInstallOptions {
|
||||
|
||||
independentLeaves: boolean,
|
||||
forceIndependentLeaves: boolean,
|
||||
|
||||
global: boolean,
|
||||
}
|
||||
|
||||
export type InstallOptions = Partial<StrictInstallOptions> &
|
||||
|
||||
@@ -837,9 +837,17 @@ async function installInContext (
|
||||
})
|
||||
}
|
||||
|
||||
if (!opts.lockfileOnly) {
|
||||
await Promise.all(projectsToLink.map(linkBinsOfImporter))
|
||||
}
|
||||
await Promise.all(projectsToLink.map(async (project, index) => {
|
||||
const linkedPackages = await linkBinsOfImporter(project)
|
||||
const projectToInstall = projects[index]
|
||||
if (opts.global && projectToInstall.mutation.includes('install')) {
|
||||
projectToInstall.wantedDependencies.forEach(pkg => {
|
||||
if (!linkedPackages?.includes(pkg.alias)) {
|
||||
logger.warn({ message: `${pkg.alias} has no binaries`, prefix: opts.lockfileDir })
|
||||
}
|
||||
})
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
// waiting till the skipped packages are downloaded to the store
|
||||
|
||||
@@ -1162,3 +1162,30 @@ test('fail if none of the available resolvers support a version spec', async (t:
|
||||
],
|
||||
)
|
||||
})
|
||||
|
||||
test('globally installed package which don\'t have bins should log warning message', async (t: tape.Test) => {
|
||||
const project = prepareEmpty(t)
|
||||
const reporter = sinon.spy()
|
||||
|
||||
const opts = await testDefaults({ global: true, reporter })
|
||||
|
||||
await mutateModules([
|
||||
{
|
||||
buildIndex: 0,
|
||||
manifest: {
|
||||
dependencies: {
|
||||
'is-positive': '1.0.0',
|
||||
},
|
||||
},
|
||||
mutation: 'install',
|
||||
rootDir: process.cwd(),
|
||||
},
|
||||
], opts)
|
||||
|
||||
t.ok(reporter.calledWithMatch({
|
||||
message: 'is-positive has no binaries',
|
||||
prefix: process.cwd(),
|
||||
}))
|
||||
|
||||
t.end()
|
||||
})
|
||||
Reference in new issue
Block a user