Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor library to use smaller modules #91

Merged
merged 7 commits into from
May 14, 2019

Conversation

demurgos
Copy link
Contributor

The index.js file got pretty big over time. This commit splits it into smaller modules:

  • The core logic remains in index.js
  • The munge functions are moved to the lib/munge directory. Each module detects and wraps one kind of target.
  • Helper functions are moved out of index.js to the lib directory

Using multiple modules instead of a single index.js enables easier future extensions.

The `index.js` file got pretty big over time. This commit splits it into smaller modules:
- The core logic remains in `index.js`
- The `munge` functions are moved to the `lib/munge` directory. Each module detects and wraps one kind of target.
- Helper functions are moved out of `index.js` to the `lib` directory

Using multiple modules instead of a single `index.js` enables easier future extensions.
lib/homedir.js Outdated Show resolved Hide resolved
const osHomedir = require('os-homedir')

const home = process.env.SPAWN_WRAP_SHIM_ROOT || osHomedir()
const homedir = home + '/.node-spawn-wrap-'
Copy link
Member

Choose a reason for hiding this comment

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

path.resolve?

index.js Show resolved Hide resolved
lib/debug.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
lib/mungers/cmd.js Show resolved Hide resolved
}

let npmPath = whichOrUndefined('npm') || 'npm'
npmPath = path.dirname(npmPath) + '\\node_modules\\npm\\bin\\npm-cli.js'
Copy link
Member

Choose a reason for hiding this comment

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

Would love to eliminate path concatenation, use path.join instead. Again this can be a follow-up, I know what's here is just a straight move from index.js.

}

if (hasMain) {
const replace = workingDir + '/' + command
Copy link
Member

Choose a reason for hiding this comment

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

follow-up: path.join

options.originalNode = shebangbin
options.basename = maybeNode
options.file = shebangbin
options.args = [shebangbin, workingDir + '/' + maybeNode]
Copy link
Member

Choose a reason for hiding this comment

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

follow-up: path.join

@coreyfarrell
Copy link
Member

Oh @demurgos if you make these changes please just add a commit, I will squash when I do the merge. This will make it easier for me to re-review.

@demurgos
Copy link
Contributor Author

demurgos commented May 10, 2019

Thanks for the reviews.
I'll avoid force-pushing in the future when there are reviews.

I'll address the comments tomorrow (moving let, fixing homedir). I'll keep the updates to the path operations as a follow-up PR: this one is intended to simply move code around without extra changes.

Edit: I'm not sure if I'll have time this week-end, but I'll try to address your comments.

@coreyfarrell
Copy link
Member

force-pushing is fine for the smaller PR's.

Copy link
Member

@JaKXz JaKXz left a comment

Choose a reason for hiding this comment

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

Adding some notes on top of Corey's review. Thanks for this!

index.js Outdated Show resolved Hide resolved
if (!IS_DEBUG) {
return;
}
const prefix = 'SW ' + process.pid + ': '
Copy link
Member

Choose a reason for hiding this comment

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

We should use template strings

lib/debug.js Outdated Show resolved Hide resolved
lib/exe-type.js Outdated Show resolved Hide resolved
lib/mungers/cmd.js Show resolved Hide resolved
This commit inlines the `KNOWN_SHELLS` constant inside `isSh` and uses a simple array instead of a set.
In debug mode, the shim directory is not cleaned-up but the `signalExit` handler is still passed. This commit simplifies the code by avoiding to attach the handler altogether when it has no effect.
@demurgos
Copy link
Contributor Author

demurgos commented May 13, 2019

I fixed most of the comments relative to minor issues. I'll leave replacing string concatenation with dedicated functions to a follow-up PR because it is an important topic.

I think that this PR can be merged as-is. You can squash the commits or simply rebase (each one is a self-contained minor fix)

@JaKXz
Copy link
Member

JaKXz commented May 14, 2019

For semantic versioning I think this will need to be squashed into the chore commit. But thanks @demurgos! I'll take a closer look soon!

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

👍 nice cleanup;

Be very cautious when rolling this out, just because of how finicky the module is; probably we should go to a next branch, and test on a wider variety of libraries than we usually do before a release.

Copy link
Member

@JaKXz JaKXz left a comment

Choose a reason for hiding this comment

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

👍

I'll leave the merge and release to @bcoe or @coreyfarrell

@demurgos demurgos mentioned this pull request May 14, 2019
@coreyfarrell coreyfarrell merged commit d58a3ed into istanbuljs:master May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants