Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: path to cid-tool commands #1866

Merged
merged 1 commit into from
Feb 7, 2019
Merged

fix: path to cid-tool commands #1866

merged 1 commit into from
Feb 7, 2019

Conversation

alanshaw
Copy link
Member

@alanshaw alanshaw commented Feb 6, 2019

In the edge case where IPFS is a dependency of a project and the user attempts to use the IPFS CLI, the cid-tool will not be installed at proj/node_modules/ipfs/node_modules/cid-tool but will instead be flattened by npm and installed at proj/node_modules/cid-tool. i.e. next to ipfs in the dependency tree instead of a child of.

This PR fixes this situation by using require.resolve to get the path to the cid-tool instead of assuming where it is installed.

FYI I found this bug while using the ipfs cid base32 command with a JS IPFS installed with iim. I was getting the error:

$ ipfs cid base32 QmRgXEDv6DL8uchf7h9j8hAGG8Fq5r1UZ6Jy3TQAPxEb76
ENOENT: no such file or directory, scandir '/Users/alan/.iim/dists/[email protected]/node_modules/ipfs/node_modules/cid-tool/src/cli/commands'

Which is correct, the cid-tool was actually installed at /Users/alan/.iim/dists/[email protected]/node_modules/cid-tool.

In the edge case where IPFS is a dependency of a project and the user attempts to use the IPFS CLI, the cid-tool will not be installed at `proj/node_modules/ipfs/node_modules/cid-tool` but will instead be flattened by npm and installed at `proj/node_modules/cid-tool`. i.e. next to `ipfs` in the dependency tree instead of a child of.

This PR fixes this situation by using `require.resolve` to get the path to the `cid-tool` instead of assuming where it is installed.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@ghost ghost assigned alanshaw Feb 6, 2019
@ghost ghost added the status/in-progress In progress label Feb 6, 2019
Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

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

LGTM. Will help anyone using mono-repos too.

@alanshaw alanshaw merged commit 506f5be into master Feb 7, 2019
@ghost ghost removed the status/in-progress In progress label Feb 7, 2019
@alanshaw alanshaw deleted the fix/cid-tool-path branch February 7, 2019 14:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants