Open MicahZoltu opened 5 years ago
I'd happy to replace fs-extra, but yargs would be hard.
the fact that almost all of the work with this library occurs at compile time
I'm not sure what you mean by that. The only piece which could be considered compile time is downloadCurrentVersion.js
.
Hmm, I'm not sure what I was thinking with that particular comment. 🤪
Perhaps a solution to the yargs problem would be to have a separate package for the CLI from the library? All of my projects compile programmatically (not using the CLI), and I don't think I'm alone in following this pattern. Since yargs
presumably is only used by the CLI portion, that would all go away if this project was split.
Just checked and it appears yargs is actually gone already. 🎉 There is still fs-extra
which brings in 16 out of the 25 dependencies. I feel like if we can drop fs-extra
this could probably be closed (though it would be cool to get rid of any of the remaining 9 dependencies if possible).
Do you want to submit a PR for replacing fs-extra? I assume we only use one or two helpers, and having it inline defined would not result in more than 20 extra lines of code?
I'm considering it. If someone beats me to it though that would make me happy. 😉
If fs-extra
was replaced by fs
(built-in) then the only function missing would be ensureDirSync
. Looking at fs-extra
it is just an alias of makeDirSync
internally. The following code I think is what would be required to remove the dependency on fs-extra
entirely:
function checkPath (pth) {
if (process.platform === 'win32') {
const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ''))
if (pathHasInvalidWinCharacters) {
const error = new Error(`Path contains invalid characters: ${pth}`)
error.code = 'EINVAL'
throw error
}
}
}
export function ensureDirSync(dir) {
checkPath(dir)
return fs.mkdirSync(dir, { mode: 0o777, recursive: true })
}
I don't have a dev environment setup at the moment so I can't do this myself, but it should be a really easy change:
fs-extra
dependency from package.json
solcjs
.require('fs-extra');
to `require('fs');DO we really need to check if the path is valid?
For context, the above code was a direct copy (with a couple simplifications) of the dependency I'm proposing to remove. It is certainly possible that in the place it is being used, the check is unnecessary.
This is a minor quality of life thing, but at the moment the NPM
solc
package brings with it 77 dependencies. Given the simplicity of this project (just a wrapper around solc binaries) and the fact that almost all of the work with this library occurs at compile time, it feels like there is an opportunity to reduce the dependencies thatsolc
brings into a project using it.Can any of the dependencies be moved over to
devDependencies
? Can any of the dependencies be replaced with just some inline code?Looking at solc in http://npm.anvaka.com/#/view/2d/solc, it appears that the number one offender is
yargs
followed byfs-extra
andkeccak
. I already have a PR out for removingkeccak
(in favor ofjs-sha3
), and it appears thatfs-extra
is used in one place and could easily be replaced with node's built-infs
package.yargs
I suspect will be harder to get rid of, though perhaps there is a similar library that doesn't bring in 58 transitive dependencies?