The Wayback Machine - https://web.archive.org/web/20201123153102/https://github.com/shelljs/shelljs/pull/484
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

refactor: expose plugin utils & add initial tests #484

Merged
merged 2 commits into from Jul 27, 2016
Merged

Conversation

@nfischer
Copy link
Member

@nfischer nfischer commented Jul 26, 2016

After more experimentation, I realized that #482 wasn't a perfect approach, but that this would be a better one. Even after #482, shell.error() was actually broken. This fixes that issue.

This also starts differentiating internal implementations (src/common.js) from exposed parts of the plugin API (plugin.js). This is of course still far from a complete plugin API, but this should be enough to make simple plugins (and still get benefits like globbing, shelljs-style error signaling, etc.).

All implementations are still within src/common.js, and internal commands still rely on that directly, but external plugins are intended to use var plugin = require('shelljs/plugin') to get functions like plugin.register(). This also makes it easy to modify the plugin API without breaking ShellJS commands.

I also started unit tests for the plugin API. This creates one sample plugin (with all the bells and whistles like automatic option parsing) and then makes sure it works properly. We may also want to create a simpler plugin (i.e. no automatic option-parsing, no wrapping the return value, etc.) and test that.

If you have any suggestions on naming conventions, or think there's a better approach to this issue, let me know. Like I said, this is still far from complete, but suggestions are welcome.

@@ -6,13 +6,7 @@
// http://github.com/arturadib/shelljs
//

var commonPath = './src/common';

This comment has been minimized.

@ariporad

ariporad Jul 27, 2016
Contributor

Why are we deleting this?

This comment has been minimized.

@nfischer

nfischer Jul 27, 2016
Author Member

This reverts #482, which I realized was not the best approach. We could leave #482 in, but it's just extra-complicated code once this gets merged, so I think it's best to revert.

@nfischer
Copy link
Member Author

@nfischer nfischer commented Jul 27, 2016

@ariporad I just fixed the issue with node v0.10-12. This should be good now.

@nfischer
Copy link
Member Author

@nfischer nfischer commented Jul 27, 2016

For reference, the bug I found with the approach in #482 is that there are two different instances of common.state: one that the plugin has access to and modifies, and one that the ShellJS instance has access to.

A plugin might signal an error using plugin.error('some message'), however any calls to shell.error() after that would not see that error message, since shell.error() accesses one common.state and plugin.error() modified a different one.

@ariporad
Copy link
Contributor

@ariporad ariporad commented Jul 27, 2016

LGTM!

@ariporad ariporad merged commit 8f7a7d8 into master Jul 27, 2016
5 checks passed
5 checks passed
approvals/lgtm this commit looks good
continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@ariporad ariporad deleted the refactor-plugin-utils branch Jul 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.