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 +4 -4
- data/.github/workflows/build.yml +26 -0
- data/CHANGELOG.md +11 -0
- data/bin/console +14 -0
- data/bin/rake +6 -0
- data/bin/rspec +29 -0
- data/bin/setup +8 -0
- data/lib/opal/environment.rb +4 -0
- data/lib/opal/processor.rb +4 -0
- data/lib/opal/sprockets.rb +13 -81
- data/lib/opal/sprockets/assets_helper.rb +78 -0
- data/lib/opal/sprockets/environment.rb +12 -14
- data/lib/opal/sprockets/erb.rb +12 -16
- data/lib/opal/sprockets/mime_types.rb +19 -0
- data/lib/opal/sprockets/processor.rb +111 -114
- data/lib/opal/sprockets/server.rb +94 -98
- data/lib/opal/sprockets/version.rb +1 -8
- data/opal-sprockets.gemspec +38 -24
- data/spec/fixtures/complex_sprockets.js.rb.erb +1 -1
- data/spec/fixtures/{jst_file.js.jst → jst_file.jst.ejs} +0 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/sprockets/erb_spec.rb +15 -25
- data/spec/sprockets/processor_spec.rb +53 -57
- data/spec/sprockets/server_spec.rb +95 -25
- data/spec/tilt/opal_spec.rb +1 -1
- metadata +66 -24
- data/.travis.yml +0 -21
- data/lib/opal/sprockets/path_reader.rb +0 -36
- data/spec/shared/path_finder_shared.rb +0 -19
- data/spec/shared/path_reader_shared.rb +0 -31
- data/spec/sprockets/path_reader_spec.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b7553caf49b2308f3315be681e7b7ab68d57eaf46b391927e6b1b5942aa8b4e
|
4
|
+
data.tar.gz: 846dd949a0c534c4053b0a298c927bbb101aa5788a7480ba7a855c902a1f599f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
data/lib/opal/sprockets.rb
CHANGED
@@ -1,87 +1,19 @@
|
|
1
1
|
require 'opal'
|
2
|
-
require 'opal/sprockets/
|
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
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
5
|
+
class Opal::Sprockets::Environment < ::Sprockets::Environment
|
6
|
+
def initialize *args
|
7
|
+
super
|
8
|
+
append_opal_paths
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def use_gem gem_name
|
12
|
+
Opal.use_gem gem_name
|
13
|
+
append_opal_paths
|
14
|
+
end
|
16
15
|
|
17
|
-
|
16
|
+
private
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
18
|
+
def append_opal_paths
|
19
|
+
Opal.paths.each { |p| append_path p }
|
22
20
|
end
|
23
21
|
end
|
data/lib/opal/sprockets/erb.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
23
|
-
Sprockets.
|
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
|
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
|
-
|
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
|
-
|
15
|
-
|
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
|
-
|
19
|
-
|
26
|
+
if map
|
27
|
+
map = ::Sprockets::SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
|
20
28
|
end
|
21
29
|
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
36
|
-
|
53
|
+
def call
|
54
|
+
compiler_options = Opal::Config.compiler_options.merge(requirable: true, file: logical_path)
|
37
55
|
|
38
|
-
|
39
|
-
|
56
|
+
compiler = Opal::Compiler.new(data, compiler_options)
|
57
|
+
result = compiler.compile
|
40
58
|
|
41
|
-
|
42
|
-
|
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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
57
|
-
|
58
|
-
end
|
68
|
+
[result.to_s, map , context.metadata[:dependencies], context.metadata[:required]]
|
69
|
+
end
|
59
70
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
79
|
-
|
93
|
+
required_trees.each do |original_required_tree|
|
94
|
+
required_tree = Pathname(original_required_tree)
|
80
95
|
|
81
|
-
|
82
|
-
|
83
|
-
|
96
|
+
unless required_tree.relative?
|
97
|
+
raise ArgumentError, "require_tree argument must be a relative path: #{required_tree.inspect}"
|
98
|
+
end
|
84
99
|
|
85
|
-
|
100
|
+
required_tree = dirname.join(input[:filename], '..', required_tree)
|
86
101
|
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
106
|
+
context.depend_on required_tree.to_s
|
92
107
|
|
93
|
-
|
108
|
+
environment = context.environment
|
94
109
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
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
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
139
|
-
|
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
|
-
|
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
|
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.
|
167
|
-
Sprockets.
|
168
|
-
Sprockets.
|
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
|