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

Add support for shareable modules #69

Merged
merged 4 commits into from
Oct 10, 2018
Merged

Conversation

thoov
Copy link
Contributor

@thoov thoov commented Oct 3, 2018

Enables the config of scripty.modules which specifies an array of modules to include in the search space of script executables.

Implements #68

Enables the config of `scripts.modules` which specifies an
array of modules to include in the search space of script
executables.

Implements testdouble#68
@thoov
Copy link
Contributor Author

thoov commented Oct 3, 2018

cc: @stefanpenner

@thoov
Copy link
Contributor Author

thoov commented Oct 3, 2018

@searls Could you review this? I am open to any feedback / changes you come up with.

Copy link
Member

@searls searls left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! See my feedback and let me know what you think!


if (options && Array.isArray(options.modules)) {
options.modules.forEach(function (moduleName) {
const modulePath = resolvePkg(moduleName + '/scripts')
Copy link
Member

Choose a reason for hiding this comment

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

I'll be the first to admit scripty has pretty piss-poor Windows support, but seeing a '/' reminds me I need to ask whether this new feature works under Windows, given it'll be looking for a scripts-win directory?

See our appveyor build and if there's some way to make sure this is tested to behave as predicted under windows (literally just resolving scripts-win when on win platform?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have access to the appveyor build. I get "Project not found or access denied."

For the "/" I can use https://nodejs.org/api/path.html#path_path_sep if that is what you are referring to. I don't have a dev windows setup for testing so do you have any suggestions on what you use?

Copy link
Member

Choose a reason for hiding this comment

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

I should be more clear:

  1. Windows command support is implemented in a custom way in Scripty. If you're on Windows, it will first look in a mirrored directory hierarchy under scripts-win/, not scripts/. That means for you to keep Windows support working consistently, this feature would need to resolve windows paths in the same way other scripts are loaded (via this bit of code here).

  2. Whoops, fixed the Appveyor permission error. You can see a build log here. What I think this PR really needs to be sure it works is a "safe" (i.e. integration) test that uses a new set of minimal nested module fixtures to verify that script-module loading works as you expect it to, and that also exercises scripts-win. I think if you look under the safe/ path you should find readily imitatible tests to start from

globArray.push(path.join(moduleLocation, '*'))
}
})
}
Copy link
Member

Choose a reason for hiding this comment

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

This method was pretty tidy previously and now has a 2-nested branch condition shoehorned into it. Could we extract this to a well named private function? Maybe:

return [
  stuff,
  that, 
  was, 
  here
].concat(arrayOfNewNestedStuff(options.modules))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep will do

yarn.lock Outdated
@@ -0,0 +1,1906 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link
Member

Choose a reason for hiding this comment

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

scripty uses npm and an npm package-lock.json. Could you please use npm & update its package-lock? I'm uncomfortable with the idea of having two (potentially divergent) sources of truth as to the library's nested dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops 😄 (total just assumed yarn... I wonder if there is a wrapper that would just delegate to either yarn or npm based on the presence of a yarn.lock or package-lock 🤔). I will get rid of this and use package-lock.json.

- Restructuring load-option.js
- Cleaning up glob-patterns.js
- Remove yarn.lock and use package-lock.json
@thoov
Copy link
Contributor Author

thoov commented Oct 8, 2018

@searls Thanks for the review! I believe I have addressed all of your comments (expect the windows one which I left a clarifying comment). Let me know if my response / changes make sense or if you have any other comments / suggestions.

Copy link
Member

@searls searls left a comment

Choose a reason for hiding this comment

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

Ok, everything looks good. I think the last step is adding an integration test for this that also exercises the Windows code paths (see comment)


if (options && Array.isArray(options.modules)) {
options.modules.forEach(function (moduleName) {
const modulePath = resolvePkg(moduleName + '/scripts')
Copy link
Member

Choose a reason for hiding this comment

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

I should be more clear:

  1. Windows command support is implemented in a custom way in Scripty. If you're on Windows, it will first look in a mirrored directory hierarchy under scripts-win/, not scripts/. That means for you to keep Windows support working consistently, this feature would need to resolve windows paths in the same way other scripts are loaded (via this bit of code here).

  2. Whoops, fixed the Appveyor permission error. You can see a build log here. What I think this PR really needs to be sure it works is a "safe" (i.e. integration) test that uses a new set of minimal nested module fixtures to verify that script-module loading works as you expect it to, and that also exercises scripts-win. I think if you look under the safe/ path you should find readily imitatible tests to start from

@thoov thoov force-pushed the shareable-scripts branch from e95dd7b to b01719f Compare October 10, 2018 00:39
@thoov
Copy link
Contributor Author

thoov commented Oct 10, 2018

@searls I added a "safe" test that exercises the win32 flow (thanks for the clarification and pointing me to those examples). I believe this to be in a good spot now. Could you review (glob-patterns.js and script-dirs.js) as those were the places that I changed the most between your last review and now.

@searls searls merged commit 9db01a0 into testdouble:master Oct 10, 2018
@searls
Copy link
Member

searls commented Oct 10, 2018

Landed in v.1.8.0! 🎊

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.

2 participants