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:
Yao DingandZoltan Kochan authored and GitHub committed 2020-03-10 18:46:22 +02:00
1 parent 028ebbd70b
commit 7ec32acce8
4 files changed
+43 -4

No files matched your search

+3 -1
View File
@@ -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> &
+11 -3
View File
@@ -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
+27
View File
@@ -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()
})