Skip to content

Allow tilt/opal to use Opal::Builder with :build or :builder options#864

Merged
elia merged 5 commits intoopal:masterfrom
jeremyevans:tilt_build
May 17, 2015
Merged

Allow tilt/opal to use Opal::Builder with :build or :builder options#864
elia merged 5 commits intoopal:masterfrom
jeremyevans:tilt_build

Conversation

@jeremyevans
Copy link
Copy Markdown
Contributor

If :build option is used, the Opal::Builder defaults are used.
If :builder option is used, you can pass in your own custom
builder, which could have per-build stubs, append_paths, and
use_gems to change building without modifying global state.

Using this, it's possible to build arbitrary opal projects that
require other files using tilt without sprockets.

In order to get this to work, I had to make Opal.append_path
and Opal.use_gem available per builder instance, and fix
Opal::Builder#dup to work correctly, which is what the earlier
commits are for.

The Opal::CLI commit is not necessary, but I think it's a good
idea in general to avoid mutating global state unless it is
necessary.

This allows you to use gems for specific builders instead of
modifying global state. In order to do so, it moves use_gem
from being a singleton method on Opal to being a module that
extends Opal, and including that module in Opal::Builder.

To unify the Opal singleton API and Opal::Builder instance
API, add append_paths methods to both, with Opal just using
appending to the global paths, and Opal::Builder appending
the paths to the underlying file_finder inside the path_reader.
Instead, only modify the state of the generated builder. In order
to test this, add a CLI#build method that returns the builder
object.
Previously this did not duplicate internal structures, causing the
objects to not be independent.
If :build option is used, the Opal::Builder defaults are used.
If :builder option is used, you can pass in your own custom
builder, which could have per-build stubs, append_paths, and
use_gems to change building without modifying global state.

Using this, it's possible to build arbitrary opal projects that
require other files using tilt without sprockets.
@elia
Copy link
Copy Markdown
Member

elia commented May 15, 2015

Great stuff!

The failing spec is the one that uses a sprockets server, at a first look seems it's missing a load path, could be related to Opal.paths changes, but not sure yet.

Alas I won't have time to debug until tomorrow

@jeremyevans
Copy link
Copy Markdown
Contributor Author

OK. I'm having some trouble setting up the infrastructure needed to run mspec_phantom locally, if you can take a look tomorrow, that will be great, otherwise I'll give it a shot on Monday.

@elia
Copy link
Copy Markdown
Member

elia commented May 15, 2015

just for ref

➋➁ opal:tilt_build> rake mspec_phantom:build
[filters] Adding 40 spec files...
[shared] Adding 161 spec files...
[lexer] Adding 1 spec files...
[parser] Adding 30 spec files...
[rubyspecs] Adding 204 spec files...
rake aborted!
Sprockets::FileNotFound: couldn't find file 'spec_helper' with type 'application/javascript'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/resolve.rb:64:in `resolve!'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/context.rb:88:in `resolve'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/legacy.rb:259:in `resolve_with_compat'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/context.rb:142:in `require_asset'
/Users/elia/Code/opal/lib/opal/sprockets/processor.rb:68:in `block in process_requires'
/Users/elia/Code/opal/lib/opal/sprockets/processor.rb:66:in `each'
/Users/elia/Code/opal/lib/opal/sprockets/processor.rb:66:in `process_requires'
/Users/elia/Code/opal/lib/opal/sprockets/processor.rb:45:in `evaluate'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/legacy_tilt_processor.rb:25:in `call'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:86:in `load_asset_by_uri'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:45:in `block in load'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:156:in `fetch_asset_from_dependency_cache'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:38:in `load'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/cached_environment.rb:47:in `yield'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/cached_environment.rb:47:in `load'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/bundle.rb:23:in `block in call'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/utils.rb:183:in `dfs'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/bundle.rb:24:in `call'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:86:in `load_asset_by_uri'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:45:in `block in load'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:156:in `fetch_asset_from_dependency_cache'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/loader.rb:38:in `load'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/cached_environment.rb:47:in `yield'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/cached_environment.rb:47:in `load'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/base.rb:63:in `find_asset'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/environment.rb:30:in `find_asset'
/Users/elia/.rvm/gems/ruby-2.2.0/gems/sprockets-3.1.0/lib/sprockets/base.rb:89:in `[]'
/Users/elia/Code/opal/lib/mspec/opal/rake_task.rb:138:in `specs'
/Users/elia/Code/opal/lib/mspec/opal/rake_task.rb:212:in `build_specs'
/Users/elia/Code/opal/lib/mspec/opal/rake_task.rb:29:in `block (2 levels) in initialize'
/Users/elia/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
/Users/elia/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => mspec_phantom:build
(See full trace by running task with --trace)

elia added a commit that referenced this pull request May 17, 2015
Allow tilt/opal to use Opal::Builder with :build or :builder options
@elia elia merged commit d88ebcf into opal:master May 17, 2015
hmdne pushed a commit to hmdne/opal that referenced this pull request Jan 27, 2024
Bumps [mocha](https://github.com/mochajs/mocha) from 6.1.4 to 7.1.1.
- [Release notes](https://github.com/mochajs/mocha/releases)
- [Changelog](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md)
- [Commits](mochajs/mocha@v6.1.4...v7.1.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
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