opal-sprockets 0.4.9.1.0.3.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4219e230743e17009790fafebb6ab1ff5dc149bb1c1ef84c92818d455bd8d25f
4
- data.tar.gz: a864f139a015e995b14013252a95734f6fb87358ce9bbf9822e53c15aa350ed9
3
+ metadata.gz: 3b7553caf49b2308f3315be681e7b7ab68d57eaf46b391927e6b1b5942aa8b4e
4
+ data.tar.gz: 846dd949a0c534c4053b0a298c927bbb101aa5788a7480ba7a855c902a1f599f
5
5
  SHA512:
6
- metadata.gz: 7a9bfe6e8905b81daca542ce0013e3ba00337846fd34cf9bda3e6efd31b819bf4ee70320d66e9c55518ae5c581a54a4ad8f11e6fa2c49ed93ed3124a7d201ccc
7
- data.tar.gz: 3b16bfcda0c2742af3f9e7155be2d07084e13af2e7045477a7f0616e25987c9e7198eb15332dea624841b539411b2aa013da713ea94d523dafca4752cb2dfc1f
6
+ metadata.gz: b0ed4adf7cab6d38ad475a2393a66ab65fefd0d9522a1aff5acd25fb107f6d56794508dc4fb774da2871fd6d52bb1e8e5823a53fa28dee973239d7585f1c84a5
7
+ data.tar.gz: 6e96b8ea2acdbd21f38ab91670d8f4c0cd2ed4b4ad3fb0d1c49f78eb45469241efb221bb5a72c0181654012796be7f9673789889c61391f19cfe3d6f688a71e6
@@ -0,0 +1,26 @@
1
+ on:
2
+ - push
3
+ - pull_request
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ matrix:
9
+ os: [ 'ubuntu-latest' ]
10
+ ruby: [ "3.0", "2.7", "2.6", "2.5" ]
11
+ opal: [ "1.0.3", "1.1.0" ]
12
+
13
+ runs-on: ${{ matrix.os }}
14
+
15
+ env:
16
+ OPAL_VERSION: ${{ matrix.opal }}
17
+
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - name: Setup project
24
+ run: bin/setup
25
+ - name: Run test
26
+ run: bin/rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.0](https://github.com/opal/opal-sprockets/compare/v0.4.9.1.0.3.7...v1.0.0)
4
+
5
+ *19 February 2021*
6
+
7
+ - Bump the supported sprockets version to v4
8
+ - Add support for Opal v1.1
9
+ - Only support Ruby comments in directive preprocessor (no one should have ever used "//", ["/*", or "*/")
10
+ - Fix the namespaces and move everything under Opal::Sprockets (the legacy namespaces will be dropped in version 1.1)
11
+ - The version schema has been simplified, not expecting sprockets to have major earthquakes like it was for v4
12
+
13
+
3
14
  ## [v0.4.9](https://github.com/opal/opal-sprockets/compare/v0.4.8.1.0.3.7...v0.4.9.1.0.3.7)
4
15
 
5
16
  *11 September 2020*
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "opal"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+
6
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ gem install bundler --conservative
7
+
8
+ bundle update
@@ -0,0 +1,4 @@
1
+ warn "Opal::Environment is deprecated, please switch to Opal::Sprockets::Environment.", uplevel: 1
2
+
3
+ require 'opal/sprockets/environment'
4
+ Opal::Environment = Opal::Sprockets::Environment
@@ -0,0 +1,4 @@
1
+ warn "Opal::Processor is deprecated, please switch to Opal::Sprockets::Processor.", uplevel: 1
2
+
3
+ require 'opal/sprockets/processor'
4
+ Opal::Processor = Opal::Sprockets::Processor
@@ -1,87 +1,19 @@
1
1
  require 'opal'
2
- require 'opal/sprockets/processor'
3
- require 'opal/sprockets/erb'
4
- require 'opal/sprockets/server'
2
+ require 'opal/sprockets/version'
5
3
 
6
4
  module Opal
7
5
  module Sprockets
8
- # Bootstraps modules loaded by sprockets on `Opal.modules` marking any
9
- # non-Opal asset as already loaded.
10
- #
11
- # @example
12
- #
13
- # Opal::Sprockets.load_asset('application')
14
- #
15
- # @example Will output the following JavaScript:
16
- #
17
- # Opal.loaded("jquery.self", "yet_another_carousel.self");
18
- # Opal.require("opal", "application");
19
- #
20
- # @param name [String] The logical name of the main asset to be loaded (without extension)
21
- #
22
- # @return [String] JavaScript code
23
- def self.load_asset(*names)
24
- if names.last.is_a?(::Sprockets::Environment)
25
- unless @load_asset_warning_displayed
26
- @load_asset_warning_displayed = true
27
- warn "Passing a sprockets environment to Opal::Sprockets.load_asset no more needed.\n #{caller(1, 3).join("\n ")}"
28
- end
29
- names.pop
30
- end
31
-
32
- names = names.map { |name| name.sub(/(\.(js|rb|opal))*\z/, '') }
33
- stubbed = ::Opal::Config.stubbed_files.to_a
34
-
35
- loaded = 'typeof(OpalLoaded) === "undefined" ? [] : OpalLoaded'
36
- loaded = "#{stubbed.to_json}.concat(#{loaded})" if stubbed.any?
37
-
38
- [
39
- "Opal.loaded(#{loaded});",
40
- *names.map { |name| "Opal.require(#{name.to_json});" }
41
- ].join("\n")
42
- end
43
-
44
- # Mark an asset as already loaded.
45
- # This is useful for requiring JavaScript files which are not managed by Opal's laoding system.
46
- #
47
- # @param [String] name The "logical name" of the asset
48
- # @return [String] JavaScript code
49
- def self.loaded_asset(name)
50
- %{if (typeof(OpalLoaded) === 'undefined') OpalLoaded = []; OpalLoaded.push(#{name.to_json});}
51
- end
52
-
53
- # Generate a `<script>` tag for Opal assets.
54
- #
55
- # @param [String] name The logical name of the asset to be loaded (without extension)
56
- # @param [Hash] options The options about sprockets
57
- # @option options [Sprockets::Environment] :sprockets The sprockets instance
58
- # @option options [String] :prefix The prefix String at which is mounted Sprockets, e.g. '/assets'
59
- # @option options [Boolean] :debug Wether to enable debug mode along with sourcemaps support
60
- #
61
- # @return a string of HTML code containing `<script>` tags.
62
- def self.javascript_include_tag(name, options = {})
63
- sprockets = options.fetch(:sprockets)
64
- prefix = options.fetch(:prefix)
65
- debug = options.fetch(:debug)
66
-
67
- # Avoid double slashes
68
- prefix = prefix.chop if prefix.end_with? '/'
69
-
70
- asset = sprockets[name]
71
- raise "Cannot find asset: #{name}" if asset.nil?
72
- scripts = []
73
-
74
- if debug
75
- asset.to_a.map do |dependency|
76
- scripts << %{<script src="#{prefix}/#{dependency.digest_path}?body=1"></script>}
77
- end
78
- else
79
- scripts << %{<script src="#{prefix}/#{name}.js"></script>}
80
- end
81
-
82
- scripts << %{<script>#{load_asset('opal', name)}</script>}
83
-
84
- scripts.join "\n"
85
- end
6
+ require 'opal/sprockets/assets_helper'
7
+ require 'opal/sprockets/mime_types'
8
+ extend AssetsHelper
9
+ extend MimeTypes
10
+
11
+ require 'opal/sprockets/environment'
12
+ require 'opal/sprockets/erb'
13
+ require 'opal/sprockets/processor'
14
+ require 'opal/sprockets/server'
86
15
  end
16
+
17
+ autoload :Processor, 'opal/processor'
18
+ autoload :Environment, 'opal/environment'
87
19
  end
@@ -0,0 +1,78 @@
1
+ module Opal::Sprockets::AssetsHelper
2
+ # Bootstraps modules loaded by sprockets on `Opal.modules` marking any
3
+ # non-Opal asset as already loaded.
4
+ #
5
+ # @example
6
+ #
7
+ # Opal::Sprockets.load_asset('application')
8
+ #
9
+ # @example Will output the following JavaScript:
10
+ #
11
+ # Opal.loaded("jquery.self", "yet_another_carousel.self");
12
+ # Opal.require("opal", "application");
13
+ #
14
+ # @param name [String] The logical name of the main asset to be loaded (without extension)
15
+ #
16
+ # @return [String] JavaScript code
17
+ def load_asset(*names)
18
+ if names.last.is_a?(::Sprockets::Environment)
19
+ unless @load_asset_warning_displayed
20
+ @load_asset_warning_displayed = true
21
+ warn "Passing a sprockets environment to Opal::Sprockets.load_asset no more needed.\n #{caller(1, 3).join("\n ")}"
22
+ end
23
+ names.pop
24
+ end
25
+
26
+ names = names.map { |name| name.sub(/(\.(js|rb|opal))*\z/, '') }
27
+ stubbed = ::Opal::Config.stubbed_files.to_a
28
+
29
+ loaded = 'typeof(OpalLoaded) === "undefined" ? [] : OpalLoaded'
30
+ loaded = "#{stubbed.to_json}.concat(#{loaded})" if stubbed.any?
31
+
32
+ [
33
+ "Opal.loaded(#{loaded});",
34
+ *names.map { |name| "Opal.require(#{name.to_json});" }
35
+ ].join("\n")
36
+ end
37
+
38
+ # Mark an asset as already loaded.
39
+ # This is useful for requiring JavaScript files which are not managed by Opal's laoding system.
40
+ #
41
+ # @param [String] name The "logical name" of the asset
42
+ # @return [String] JavaScript code
43
+ def loaded_asset(name)
44
+ %{if (typeof(OpalLoaded) === 'undefined') OpalLoaded = []; OpalLoaded.push(#{name.to_json});}
45
+ end
46
+
47
+ # Generate a `<script>` tag for Opal assets.
48
+ #
49
+ # @param [String] name The logical name of the asset to be loaded (without extension)
50
+ # @param [Hash] options The options about sprockets
51
+ # @option options [Sprockets::Environment] :sprockets The sprockets instance
52
+ # @option options [String] :prefix The prefix String at which is mounted Sprockets, e.g. '/assets'
53
+ # @option options [Boolean] :debug Wether to enable debug mode along with sourcemaps support
54
+ #
55
+ # @return a string of HTML code containing `<script>` tags.
56
+ def javascript_include_tag(name, options = {})
57
+ sprockets = options.fetch(:sprockets)
58
+ prefix = options.fetch(:prefix)
59
+ debug = options.fetch(:debug)
60
+
61
+ # Avoid double slashes
62
+ prefix = prefix.chop if prefix.end_with? '/'
63
+
64
+ asset = sprockets[name, accept: "application/javascript", pipeline: debug ? :debug : nil]
65
+ raise "Cannot find asset: #{name}" if asset.nil?
66
+ scripts = []
67
+
68
+ if debug
69
+ scripts << %{<script src="#{prefix}/#{asset.digest_path}"></script>}
70
+ else
71
+ scripts << %{<script src="#{prefix}/#{name}.js"></script>}
72
+ end
73
+
74
+ scripts << %{<script>#{load_asset('opal', name)}</script>}
75
+
76
+ scripts.join "\n"
77
+ end
78
+ end
@@ -2,22 +2,20 @@ require 'sprockets'
2
2
  require 'opal/sprockets/processor'
3
3
  require 'opal/sprockets/erb'
4
4
 
5
- module Opal
6
- class Environment < ::Sprockets::Environment
7
- def initialize *args
8
- super
9
- append_opal_paths
10
- end
5
+ class Opal::Sprockets::Environment < ::Sprockets::Environment
6
+ def initialize *args
7
+ super
8
+ append_opal_paths
9
+ end
11
10
 
12
- def use_gem gem_name
13
- Opal.use_gem gem_name
14
- append_opal_paths
15
- end
11
+ def use_gem gem_name
12
+ Opal.use_gem gem_name
13
+ append_opal_paths
14
+ end
16
15
 
17
- private
16
+ private
18
17
 
19
- def append_opal_paths
20
- Opal.paths.each { |p| append_path p }
21
- end
18
+ def append_opal_paths
19
+ Opal.paths.each { |p| append_path p }
22
20
  end
23
21
  end
@@ -1,23 +1,19 @@
1
1
  require 'tilt'
2
2
  require 'sprockets'
3
3
  require 'opal/sprockets/processor'
4
+ require 'opal/erb'
4
5
 
5
- module Opal
6
- module ERB
7
- class Processor < ::Opal::Processor
8
- def initialize_engine
9
- super
10
- require_template_library 'opal/erb'
11
- end
12
-
13
- def evaluate(context, locals, &block)
14
- compiler = Opal::ERB::Compiler.new(@data, context.logical_path.sub(/#{REGEXP_START}templates\//, ''))
15
- @data = compiler.prepared_source
16
- super
17
- end
18
- end
6
+ class Opal::Sprockets::ERB < ::Opal::Sprockets::Processor
7
+ def call
8
+ compiler = Opal::ERB::Compiler.new(@data, logical_path.sub(/#{Opal::REGEXP_START}templates\//, ''))
9
+ @data = compiler.prepared_source
10
+ super
19
11
  end
12
+
13
+ # @deprecated
14
+ ::Opal::ERB::Processor = self
20
15
  end
21
16
 
22
- Tilt.register 'opalerb', Opal::ERB::Processor
23
- Sprockets.register_engine '.opalerb', Opal::ERB::Processor, mime_type: 'application/javascript', silence_deprecation: true
17
+ Sprockets.register_mime_type 'application/html+javascript+ruby', extensions: ['.opalerb', '.opal.erb', '.html.opal.erb']
18
+ Sprockets.register_transformer 'application/html+javascript+ruby', 'application/javascript', Opal::ERB::Processor
19
+ Opal::Sprockets.register_mime_type 'application/html+javascript+ruby'
@@ -0,0 +1,19 @@
1
+ module Opal::Sprockets::MimeTypes
2
+ def register_mime_type(mime_type)
3
+ mime_types << mime_type
4
+ end
5
+
6
+ def mime_types
7
+ @mime_types ||= []
8
+ end
9
+
10
+ def sprockets_extnames_regexp(sprockets, opal_only: false)
11
+ opal_extnames = sprockets.mime_types.map do |type, hash|
12
+ hash[:extensions] if !opal_only || Opal::Sprockets.mime_types.include?(type)
13
+ end.compact.flatten
14
+
15
+ opal_extnames << ".js" unless opal_only
16
+
17
+ Regexp.union(opal_extnames.map { |i| /#{Regexp.escape(i)}\z/ })
18
+ end
19
+ end
@@ -3,158 +3,147 @@ require 'base64'
3
3
  require 'tilt/opal'
4
4
  require 'sprockets'
5
5
  require 'opal/builder'
6
- require 'opal/sprockets/path_reader'
6
+ require 'opal/sprockets'
7
+
8
+ # Internal: The Processor class is used to make ruby files (with .rb or .opal
9
+ # extensions) available to any sprockets based server. Processor will then
10
+ # get passed any ruby source file to build.
11
+ class Opal::Sprockets::Processor
12
+ @@cache_key = nil
13
+ def self.cache_key
14
+ @@cache_key ||= ['Opal', Opal::VERSION, Opal::Config.config].to_json.freeze
15
+ end
7
16
 
8
- module Opal
9
- # Internal: The Processor class is used to make ruby files (with .rb or .opal
10
- # extensions) available to any sprockets based server. Processor will then
11
- # get passed any ruby source file to build.
12
- class Processor < TiltTemplate
17
+ def self.reset_cache_key!
13
18
  @@cache_key = nil
14
- def self.cache_key
15
- @@cache_key ||= ['Opal', Opal::VERSION, Opal::Config.config].to_json.freeze
19
+ end
20
+
21
+ def self.call(input)
22
+ data, map, dependencies, required = input[:cache].fetch([self.cache_key, input[:filename], input[:data]]) do
23
+ new(input).call
16
24
  end
17
25
 
18
- def self.reset_cache_key!
19
- @@cache_key = nil
26
+ if map
27
+ map = ::Sprockets::SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
20
28
  end
21
29
 
22
- def evaluate(context, locals, &block)
23
- return super unless context.is_a? ::Sprockets::Context
30
+ {
31
+ data: data,
32
+ map: map,
33
+ dependencies: input[:metadata][:dependencies].to_a + dependencies.to_a,
34
+ required: input[:metadata][:required].to_a + required.to_a,
35
+ }
36
+ end
24
37
 
25
- @sprockets = sprockets = context.environment
38
+ def initialize(input)
39
+ @input = input
40
+ @sprockets = input[:environment]
41
+ @context = sprockets.context_class.new(input)
42
+ @data = input[:data]
43
+ end
26
44
 
27
- # In Sprockets 3 logical_path has an odd behavior when the filename is "index"
28
- # thus we need to bake our own logical_path
29
- filename = context.respond_to?(:filename) ? context.filename : context.pathname.to_s
30
- root_path_regexp = Regexp.escape(context.root_path)
31
- logical_path = filename.gsub(%r{^#{root_path_regexp}/?(.*?)#{sprockets_extnames_regexp}}, '\1')
45
+ attr_reader :input, :sprockets, :context, :data
32
46
 
33
- compiler_options = self.compiler_options.merge(file: logical_path)
47
+ # In Sprockets 3 logical_path has an odd behavior when the filename is "index"
48
+ # thus we need to bake our own logical_path
49
+ def logical_path
50
+ @logical_path ||= context.filename.gsub(%r{^#{Regexp.escape(context.root_path)}/?(.*?)}, '\1')
51
+ end
34
52
 
35
- compiler = Compiler.new(data, compiler_options)
36
- result = compiler.compile
53
+ def call
54
+ compiler_options = Opal::Config.compiler_options.merge(requirable: true, file: logical_path)
37
55
 
38
- process_requires(compiler.requires, context)
39
- process_required_trees(compiler.required_trees, context)
56
+ compiler = Opal::Compiler.new(data, compiler_options)
57
+ result = compiler.compile
40
58
 
41
- if Opal::Config.source_map_enabled
42
- map_data = compiler.source_map.as_json
43
- # Opal 0.11 doesn't fill sourcesContent
44
- add_sources_content_if_missing(map_data, data)
45
- "#{result}\n#{to_data_uri_comment(map_data.to_json)}"
46
- else
47
- result.to_s
48
- end
49
- end
59
+ process_requires(compiler.requires, context)
60
+ process_required_trees(compiler.required_trees, context)
50
61
 
51
- def self.sprockets_extnames_regexp(sprockets)
52
- joined_extnames = (['.js']+sprockets.engines.keys).map { |ext| Regexp.escape(ext) }.join('|')
53
- Regexp.new("(#{joined_extnames})*$")
62
+ if Opal::Config.source_map_enabled
63
+ map = compiler.source_map.as_json.transform_keys!(&:to_s)
64
+ map["sources"][0] = input[:filename]
65
+ map = ::Sprockets::SourceMapUtils.format_source_map(map, input)
54
66
  end
55
67
 
56
- def sprockets_extnames_regexp
57
- @sprockets_extnames_regexp ||= self.class.sprockets_extnames_regexp(@sprockets)
58
- end
68
+ [result.to_s, map , context.metadata[:dependencies], context.metadata[:required]]
69
+ end
59
70
 
60
- def process_requires(requires, context)
61
- requires.each do |required|
62
- required = required.to_s.sub(sprockets_extnames_regexp, '')
63
- context.require_asset required unless ::Opal::Config.stubbed_files.include? required
64
- end
71
+ def sprockets_extnames_regexp
72
+ @sprockets_extnames_regexp ||= Opal::Sprockets.sprockets_extnames_regexp(@sprockets)
73
+ end
74
+
75
+ def process_requires(requires, context)
76
+ requires.each do |required|
77
+ required = required.to_s.sub(sprockets_extnames_regexp, '')
78
+ context.require_asset required unless ::Opal::Config.stubbed_files.include? required
65
79
  end
80
+ end
66
81
 
67
- # Internal: Add files required with `require_tree` as asset dependencies.
68
- #
69
- # Mimics (v2) Sprockets::DirectiveProcessor#process_require_tree_directive
70
- def process_required_trees(required_trees, context)
71
- return if required_trees.empty?
82
+ # Internal: Add files required with `require_tree` as asset dependencies.
83
+ #
84
+ # Mimics (v2) Sprockets::DirectiveProcessor#process_require_tree_directive
85
+ def process_required_trees(required_trees, context)
86
+ return if required_trees.empty?
72
87
 
73
- # This is the root dir of the logical path, we need this because
74
- # the compiler gives us the path relative to the file's logical path.
75
- dirname = File.dirname(file).gsub(/#{Regexp.escape File.dirname(context.logical_path)}#{REGEXP_END}/, '')
76
- dirname = Pathname(dirname)
88
+ # This is the root dir of the logical path, we need this because
89
+ # the compiler gives us the path relative to the file's logical path.
90
+ dirname = File.dirname(input[:filename]).gsub(/#{Regexp.escape File.dirname(context.logical_path)}#{Opal::REGEXP_END}/, '')
91
+ dirname = Pathname(dirname)
77
92
 
78
- required_trees.each do |original_required_tree|
79
- required_tree = Pathname(original_required_tree)
93
+ required_trees.each do |original_required_tree|
94
+ required_tree = Pathname(original_required_tree)
80
95
 
81
- unless required_tree.relative?
82
- raise ArgumentError, "require_tree argument must be a relative path: #{required_tree.inspect}"
83
- end
96
+ unless required_tree.relative?
97
+ raise ArgumentError, "require_tree argument must be a relative path: #{required_tree.inspect}"
98
+ end
84
99
 
85
- required_tree = dirname.join(file, '..', required_tree)
100
+ required_tree = dirname.join(input[:filename], '..', required_tree)
86
101
 
87
- unless required_tree.directory?
88
- raise ArgumentError, "require_tree argument must be a directory: #{{source: original_required_tree, pathname: required_tree}.inspect}"
89
- end
102
+ unless required_tree.directory?
103
+ raise ArgumentError, "require_tree argument must be a directory: #{{source: original_required_tree, pathname: required_tree}.inspect}"
104
+ end
90
105
 
91
- context.depend_on required_tree.to_s
106
+ context.depend_on required_tree.to_s
92
107
 
93
- environment = context.environment
108
+ environment = context.environment
94
109
 
95
- processor = ::Sprockets::DirectiveProcessor.new
96
- processor.instance_variable_set('@dirname', File.dirname(file))
97
- processor.instance_variable_set('@environment', environment)
98
- path = processor.__send__(:expand_relative_dirname, :require_tree, original_required_tree)
99
- absolute_paths = environment.__send__(:stat_sorted_tree_with_dependencies, path).first.map(&:first)
110
+ processor = ::Sprockets::DirectiveProcessor.new
111
+ processor.instance_variable_set('@dirname', File.dirname(input[:filename]))
112
+ processor.instance_variable_set('@environment', environment)
113
+ path = processor.__send__(:expand_relative_dirname, :require_tree, original_required_tree)
114
+ absolute_paths = environment.__send__(:stat_sorted_tree_with_dependencies, path).first.map(&:first)
100
115
 
101
- absolute_paths.each do |path|
102
- path = Pathname(path)
103
- pathname = path.relative_path_from(dirname).to_s
116
+ absolute_paths.each do |path|
117
+ path = Pathname(path)
118
+ pathname = path.relative_path_from(dirname).to_s
119
+ pathname_noext = pathname.sub(sprockets_extnames_regexp, '')
104
120
 
105
- if name.to_s == file then next
106
- elsif path.directory? then context.depend_on(path.to_s)
107
- else context.require_asset(pathname)
108
- end
121
+ if path.to_s == logical_path then next
122
+ elsif ::Opal::Config.stubbed_files.include?(pathname_noext) then next
123
+ elsif path.directory? then context.depend_on(path.to_s)
124
+ else context.require_asset(pathname_noext)
109
125
  end
110
126
  end
111
127
  end
128
+ end
112
129
 
113
- # @deprecated
114
- def self.stubbed_files
115
- warn "Deprecated: `::Opal::Processor.stubbed_files' is deprecated, use `::Opal::Config.stubbed_files' instead"
116
- puts caller(5)
117
- ::Opal::Config.stubbed_files
118
- end
119
-
120
- # @deprecated
121
- def self.stub_file(name)
122
- warn "Deprecated: `::Opal::Processor.stub_file' is deprecated, use `::Opal::Config.stubbed_files << #{name.inspect}.to_s' instead"
123
- puts caller(5)
124
- ::Opal::Config.stubbed_files << name.to_s
125
- end
126
-
127
-
128
- private
129
-
130
- def add_sources_content_if_missing(data, content)
131
- data[:sourcesContent] = data.delete(:sourcesContent) || data.delete('sourcesContent') || [content]
132
- end
130
+ private
133
131
 
134
- def to_data_uri_comment(map_to_json)
135
- "//# sourceMappingURL=data:application/json;base64,#{Base64.encode64(map_to_json).delete("\n")}"
136
- end
132
+ def to_data_uri_comment(map_to_json)
133
+ "//# sourceMappingURL=data:application/json;base64,#{Base64.encode64(map_to_json).delete("\n")}"
134
+ end
137
135
 
138
- def stubbed_files
139
- ::Opal::Config.stubbed_files
140
- end
136
+ def stubbed_files
137
+ ::Opal::Config.stubbed_files
141
138
  end
142
- end
143
139
 
144
- module Opal::Sprockets::Processor
145
140
  module PlainJavaScriptLoader
146
141
  def self.call(input)
147
142
  sprockets = input[:environment]
148
- asset = OpenStruct.new(input)
149
-
150
- opal_extnames = sprockets.engines.map do |ext, engine|
151
- ext if engine <= ::Opal::Processor
152
- end.compact
153
143
 
154
- path_extnames = -> path { File.basename(path).scan(/\.[^.]+/) }
155
- processed_by_opal = -> asset { (path_extnames[asset.filename] & opal_extnames).any? }
144
+ opal_extnames_regexp = Opal::Sprockets.sprockets_extnames_regexp(sprockets, opal_only: true)
156
145
 
157
- if processed_by_opal[asset]
146
+ if input[:filename] =~ opal_extnames_regexp
158
147
  input[:data]
159
148
  else
160
149
  "#{input[:data]}\n#{Opal::Sprockets.loaded_asset(input[:name])}"
@@ -163,7 +152,15 @@ module Opal::Sprockets::Processor
163
152
  end
164
153
  end
165
154
 
166
- Sprockets.register_engine '.rb', Opal::Processor, mime_type: 'application/javascript', silence_deprecation: true
167
- Sprockets.register_engine '.opal', Opal::Processor, mime_type: 'application/javascript', silence_deprecation: true
168
- Sprockets.register_postprocessor 'application/javascript', Opal::Sprockets::Processor::PlainJavaScriptLoader
155
+ Sprockets.register_mime_type 'application/ruby', extensions: ['.rb', '.opal', '.js.rb', '.js.opal']
156
+ Sprockets.register_transformer 'application/ruby', 'application/javascript', Opal::Sprockets::Processor
157
+ Opal::Sprockets.register_mime_type 'application/ruby'
158
+
159
+ Sprockets.register_mime_type 'application/ruby+ruby', extensions: ['.rb.erb', '.opal.erb', '.js.rb.erb', '.js.opal.erb']
160
+ Sprockets.register_transformer 'application/ruby+ruby', 'application/ruby', Sprockets::ERBProcessor
161
+ Opal::Sprockets.register_mime_type 'application/ruby+ruby'
169
162
 
163
+ Sprockets.register_preprocessor 'application/ruby', Sprockets::DirectiveProcessor.new(comments: ["#"])
164
+ Sprockets.register_preprocessor 'application/ruby+ruby', Sprockets::DirectiveProcessor.new(comments: ["#"])
165
+
166
+ Sprockets.register_postprocessor 'application/javascript', Opal::Sprockets::Processor::PlainJavaScriptLoader