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 parent-recursive plugin module search #136

Merged
merged 4 commits into from
Jan 27, 2017
Merged

Conversation

mbland
Copy link
Owner

@mbland mbland commented Jan 26, 2017

Part of #120, built upon @go.search_plugins. This implements semantics similar to npm's node_modules for library modules.

Since Bash's flat namespace creates the potential for function redefinitions, a warning is emitted when a module collision occurs. The hope is that this will encourage good compatibility practices via semantic versioning, ultimately reducing the need for nested plugin module checkouts due to version incompatibilities.

Since command scripts should define their own functions using a project-specific namespace that prevents them from being treated as exported units when sourced by a parent script (especially those exported as plugins), command script namespace collisions should be less of a concern.

Also includes some touch-ups to other test files along the way.

Done during the course of adding new test cases in later commits.
Part of #120, built upon `@go.search_plugins`. This implements semantics
similar to npm's `node_modules` for library modules.

Since Bash's flat namespace creates the potential for function
redefinitions, a warning is emitted when a module collision occurs. The
hope is that this will encourage good compatibility practices via
semantic versioning, ultimately reducing the need for nested plugin
module checkouts due to version incompatibilities.

Since command scripts should define their own functions using a
project-specific namespace that prevents them from being treated as
exported units when sourced by a parent script (especially those
exported as plugins), command script namespace collisions should be less
of a concern.

Also, the `_@go.set_use_caller` wrapper function is necessary due to the
same Bash <4.3 bug from commit 2b8f09f.

Accessing `BASH_SOURCE` and `FUNCNAME` through at least two levels of
indirection apparently resolves the issue; this is why
`@go.print_stack_trace` always worked. Confirmed the breakage from the
previous commit under Bash 3.2.57 and 4.2.25 is resolved by the
`_@go.set_use_caller` wrapper.
The test that first caught this was `modules/main: --imported`. Added
the new `modules/use: import builtin module` test case to cover any
regression in a more obvious way.
@mbland mbland added this to the v1.4.0 milestone Jan 26, 2017
@mbland mbland self-assigned this Jan 26, 2017
Realized that if a plugin contains an internal or exported module that
matches the same filename as an internal or exported module in the
parent, that the code as it was would find the parent module first. The
fix was straightforward: extract most operations into
`_@go.find_module`.

Touching up the "modules/use: prevent self, circular, and multiple
importing" test case required a bit more care to touch-up, since the
plugin module in the test could no longer access its parent's modules
any longer.
@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 95.133% when pulling 2068c96 on plugin-module-search into b0d3f17 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.02%) to 95.087% when pulling 524682b on plugin-module-search into b0d3f17 on master.

@mbland mbland merged commit 4de3d6a into master Jan 27, 2017
@mbland mbland deleted the plugin-module-search branch January 27, 2017 02:17
mbland added a commit that referenced this pull request Jan 31, 2017
This concludes the refactoring of `_GO_USE_MODULES` to provide correct
`@go` command script scope for plugin modules. It is germane to #120.

Whereas #136 implemented correctly-scoped lookup of other plugin
modules, this allows any module, plugin or otherwise, to invoke its own
command scripts or plugin command scripts via `@go`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants