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

Require theme dependencies #19

Merged
merged 14 commits into from
May 7, 2018
Merged

Require theme dependencies #19

merged 14 commits into from
May 7, 2018

Conversation

benbalter
Copy link
Owner

@benbalter benbalter commented Dec 27, 2017

This PR builds on @ashmaroli's work over in #15 by folding the PluginManager logic into MockGemspec so that we can use Jekyll's native PluginManager functionality to safely require theme dependencies.

Specifically:

  • MockGemspec#runtime_dependencies now returns an array of Gem::Dependency objects, which it builds from a regex match against the theme's Gemspec
  • We then call site.plugin_manager.require_theme_deps in Munger#configure_theme, which calls theme.gemspec.runtime_dependencies and uses Jekyll's native theme dependency logic to require only whitelisted plugins, provides error output, etc.
  • To test this, I created Jekyll Test Theme Malicious which attemps to require the existing Jekyll Test Plugin Malicious for an integration test.

Since this is potentially requiring arbitrary ruby, @parkr, I'd ❤️ your 👀 as well, when you can.

@@ -9,16 +9,43 @@ class MockGemspec
extend Forwardable
def_delegator :theme, :root, :full_gem_path

DEPENDENCY_PREFIX = %r!^\s*[a-z]+\.add_(?:runtime_)?dependency!
Copy link

Choose a reason for hiding this comment

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

Hm. I wish we could just use _config.yml, since we can load that safely. What is the advantage of using the gemspec? What if a remote theme doesn't specify a gemspec but does specify a _config.yml? Could we try both?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I could see it either way. If you're a theme, you'd then have to list dependencies twice. That said, if you're using e.g., the page gem, you'd have to list it twice in your gemspec.

Do you think it's more intuitive to look to the plugins key of the theme? Will that cause confusion when other values aren't carried over? FWIW, the example theme doesn't have a config file.

Copy link

Choose a reason for hiding this comment

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

If they build an example site, they’ll specify a _config.yml because Pages doesn’t parse the gemspec. While developing, they may want to use a config file instead of a gemspec for simplicity. So I’d say doing both—and this mimicking the normal jekyll experience—would be best. Reading in the theme config would be interesting in general!

Copy link
Contributor

Choose a reason for hiding this comment

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

The jekyll-data plugin reads and loads a config file within a theme-gem when available.. and merges that data into the original site.config hash.. perhaps have something like that here too?

output, status = Open3.capture2e(*args)
output = output.encode("UTF-8",
@output, @status = Open3.capture2e(*args(config_path))
@output = @output.encode("UTF-8",
Copy link

Choose a reason for hiding this comment

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

Can we do output in a let(:output) block instead of this? let is generall preferred over instance variables in RSpec that I've seen.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Let isn't intended for values that persist between examples. This allows us to build the site once, rather than per test.


# Hash in the form of gemspec fixture => expected dependencies
{
"alldeps" => %w(jekyll jekyll-feed jekyll-sitemap bundler rake),
Copy link

Choose a reason for hiding this comment

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

bundler and rake are usually development dependencies. We don't want to require those, right?

Copy link
Owner Author

Choose a reason for hiding this comment

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

In the fixture, they're listed as runtime.

@stale
Copy link

stale bot commented Mar 6, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 6, 2018
@parkr
Copy link

parkr commented Mar 6, 2018

@benbalter Hello! Want us to pick this back up? I love the idea...

@stale stale bot removed the wontfix label Mar 6, 2018
@stale
Copy link

stale bot commented May 5, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 5, 2018
@benbalter
Copy link
Owner Author

I'd like to move forward with merging this. I'm going to stick with the Gemspec-based approach, since that's what themes do today, but see value in a config-based approach (either in addition or instead) down the line.

@stale stale bot removed the wontfix label May 7, 2018
@benbalter benbalter merged commit 6a54322 into master May 7, 2018
@benbalter benbalter deleted the require-theme-dependencies branch May 7, 2018 14:21
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.

3 participants