Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion __tests__/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ test.concurrent('--integrity should not die on missing fields in integrity file'
try {
await runCheck([], {integrity: true}, 'missing-fields');
} catch (err) {
console.log(err);
integrityError = true;
}
expect(integrityError).toEqual(false);
Expand Down
9 changes: 9 additions & 0 deletions __tests__/commands/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ if (isCI) {
});
}

test.concurrent("shouldn't expose unwanted binaries", async (): Promise<void> => {
const tmpGlobalFolder = await createTempGlobalFolder();
const tmpPrefixFolder = await createTempPrefixFolder();
const flags = {globalFolder: tmpGlobalFolder, prefix: tmpPrefixFolder};
return runGlobal(['add', 'fs-kit'], flags, 'add-with-prefix-flag', async config => {
expect(await fs.exists(path.join(tmpPrefixFolder, 'bin', 'touch'))).toEqual(false);
});
});

test.concurrent('bin', (): Promise<void> => {
const tmpGlobalFolder = getTempGlobalFolder();
return runGlobal(
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions src/cli/commands/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import * as fs from '../../util/fs.js';
const nativeFs = require('fs');

class GlobalAdd extends Add {
constructor(args: Array<string>, flags: Object, config: Config, reporter: Reporter, lockfile: Lockfile) {
super(args, flags, config, reporter, lockfile);

this.linker.setTopLevelBinLinking(false);
}

maybeOutputSaveTree(): Promise<void> {
for (const pattern of this.addedPatterns) {
const manifest = this.resolver.getStrictResolvedPattern(pattern);
Expand Down
8 changes: 7 additions & 1 deletion src/package-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,23 @@ export default class PackageLinker {
this.reporter = config.reporter;
this.config = config;
this.artifacts = {};
this.topLevelBinLinking = true;
}

artifacts: InstallArtifacts;
reporter: Reporter;
resolver: PackageResolver;
config: Config;
topLevelBinLinking: boolean;

setArtifacts(artifacts: InstallArtifacts) {
this.artifacts = artifacts;
}

setTopLevelBinLinking(topLevelBinLinking: boolean) {
this.topLevelBinLinking = topLevelBinLinking;
}

async linkSelfDependencies(pkg: Manifest, pkgLoc: string, targetBinLoc: string): Promise<void> {
targetBinLoc = path.join(targetBinLoc, '.bin');
await fs.mkdirp(targetBinLoc);
Expand Down Expand Up @@ -400,7 +406,7 @@ export default class PackageLinker {
for (const [dest, {pkg, isDirectRequire}] of flatTree) {
const {name} = pkg;

if (!linksToCreate.has(name) || isDirectRequire) {
if (isDirectRequire || (this.topLevelBinLinking && !linksToCreate.has(name))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may wanna go one step back and prevent these from getting added to linksToCreate at all may be?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, NVM. I'm just being stupid lol

linksToCreate.set(name, [dest, pkg]);
}
}
Expand Down