sprockets 4.0.0.beta2 → 4.0.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +25 -13
- data/lib/rake/sprocketstask.rb +1 -0
- data/lib/sprockets.rb +4 -2
- data/lib/sprockets/asset.rb +1 -0
- data/lib/sprockets/autoload.rb +1 -0
- data/lib/sprockets/autoload/babel.rb +1 -0
- data/lib/sprockets/autoload/closure.rb +1 -0
- data/lib/sprockets/autoload/coffee_script.rb +1 -0
- data/lib/sprockets/autoload/eco.rb +1 -0
- data/lib/sprockets/autoload/ejs.rb +1 -0
- data/lib/sprockets/autoload/jsminc.rb +1 -0
- data/lib/sprockets/autoload/sass.rb +1 -0
- data/lib/sprockets/autoload/sassc.rb +1 -0
- data/lib/sprockets/autoload/uglifier.rb +1 -0
- data/lib/sprockets/autoload/yui.rb +1 -0
- data/lib/sprockets/babel_processor.rb +3 -1
- data/lib/sprockets/base.rb +3 -2
- data/lib/sprockets/bower.rb +1 -0
- data/lib/sprockets/bundle.rb +1 -0
- data/lib/sprockets/cache.rb +4 -1
- data/lib/sprockets/cache/file_store.rb +1 -0
- data/lib/sprockets/cache/memory_store.rb +1 -0
- data/lib/sprockets/cache/null_store.rb +1 -0
- data/lib/sprockets/cached_environment.rb +4 -3
- data/lib/sprockets/closure_compressor.rb +3 -1
- data/lib/sprockets/coffee_script_processor.rb +2 -1
- data/lib/sprockets/compressing.rb +19 -0
- data/lib/sprockets/configuration.rb +1 -0
- data/lib/sprockets/context.rb +3 -2
- data/lib/sprockets/dependencies.rb +1 -0
- data/lib/sprockets/digest_utils.rb +64 -41
- data/lib/sprockets/directive_processor.rb +15 -10
- data/lib/sprockets/eco_processor.rb +1 -0
- data/lib/sprockets/ejs_processor.rb +1 -0
- data/lib/sprockets/encoding_utils.rb +1 -0
- data/lib/sprockets/environment.rb +3 -2
- data/lib/sprockets/erb_processor.rb +1 -0
- data/lib/sprockets/errors.rb +1 -0
- data/lib/sprockets/file_reader.rb +1 -0
- data/lib/sprockets/http_utils.rb +1 -0
- data/lib/sprockets/jsminc_compressor.rb +1 -0
- data/lib/sprockets/jst_processor.rb +1 -0
- data/lib/sprockets/loader.rb +2 -1
- data/lib/sprockets/manifest.rb +1 -0
- data/lib/sprockets/manifest_utils.rb +1 -0
- data/lib/sprockets/mime.rb +1 -0
- data/lib/sprockets/path_dependency_utils.rb +1 -0
- data/lib/sprockets/path_digest_utils.rb +1 -0
- data/lib/sprockets/path_utils.rb +18 -13
- data/lib/sprockets/paths.rb +1 -0
- data/lib/sprockets/preprocessors/default_source_map.rb +1 -0
- data/lib/sprockets/processing.rb +1 -0
- data/lib/sprockets/processor_utils.rb +15 -3
- data/lib/sprockets/resolve.rb +2 -1
- data/lib/sprockets/sass_cache_store.rb +1 -0
- data/lib/sprockets/sass_compressor.rb +1 -0
- data/lib/sprockets/sass_functions.rb +1 -0
- data/lib/sprockets/sass_importer.rb +1 -0
- data/lib/sprockets/sass_processor.rb +15 -3
- data/lib/sprockets/sassc_compressor.rb +4 -1
- data/lib/sprockets/sassc_processor.rb +5 -0
- data/lib/sprockets/server.rb +2 -1
- data/lib/sprockets/source_map_comment_processor.rb +1 -0
- data/lib/sprockets/source_map_processor.rb +9 -2
- data/lib/sprockets/source_map_utils.rb +1 -0
- data/lib/sprockets/transformers.rb +1 -0
- data/lib/sprockets/uglifier_compressor.rb +9 -12
- data/lib/sprockets/unloaded_asset.rb +1 -0
- data/lib/sprockets/uri_tar.rb +3 -4
- data/lib/sprockets/uri_utils.rb +2 -1
- data/lib/sprockets/utils.rb +25 -11
- data/lib/sprockets/utils/gzip.rb +1 -0
- data/lib/sprockets/version.rb +2 -1
- data/lib/sprockets/yui_compressor.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 190eb10207d44db44036ce106c1dcc7947ffc52e
|
4
|
+
data.tar.gz: 49cc56e570a817c030e35b7be44d4adee429285b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20c3b7704e5aa45a458001cfa1213aa04226f5616bb339a818b1333abfe33b0d3f58305165d5170888f8d947f936372f83e39639c40afdb68fc61a3cf6f98348
|
7
|
+
data.tar.gz: 127f4dd25e9d3129b0a65859fc65e31442ca22021debee813d15abf48473a8bd606d862d985156358df406803135f5a2cf5ed363c6ce59010f21f5a8ef60cbdd
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprockets/blob/master/UPGRADING.md
|
4
4
|
|
5
|
+
## 4.0.0.beta3
|
6
|
+
|
7
|
+
- Source Map fixes [#255] [#367]
|
8
|
+
- Performance improvements
|
9
|
+
|
5
10
|
## 4.0.0.beta2
|
6
11
|
|
7
12
|
- Fix load_paths on Sass processors [#223]
|
data/README.md
CHANGED
@@ -22,19 +22,19 @@ gem 'sprockets', '~> 3.0'
|
|
22
22
|
|
23
23
|
## Using Sprockets
|
24
24
|
|
25
|
-
For most people interested in using Sprockets you will want to see [End User Asset Generation](guides/end_user_asset_generation.md) guide. This contains information about
|
25
|
+
For most people interested in using Sprockets, you will want to see [End User Asset Generation](guides/end_user_asset_generation.md) guide. This contains information about Sprockets' directive syntax and default processing behavior.
|
26
26
|
|
27
27
|
If you are a framework developer that is using Sprockets, see [Building an Asset Processing Framework](guides/building_an_asset_processing_framework.md).
|
28
28
|
|
29
29
|
If you are a library developer who is extending the functionality of Sprockets, see [Extending Sprockets](guides/extending_sprockets.md).
|
30
30
|
|
31
|
-
Below is a disjointed mix of documentation for all three of these roles. Eventually they will be moved to an appropriate guide, for now the recommended way to consume this documentation is to view the appropriate guide first and then supplement with docs from the README.
|
31
|
+
Below is a disjointed mix of documentation for all three of these roles. Eventually they will be moved to an appropriate guide, but for now, the recommended way to consume this documentation is to view the appropriate guide first and then supplement with docs from the README.
|
32
32
|
|
33
33
|
## Behavior
|
34
34
|
|
35
35
|
### Index files are proxies for folders
|
36
36
|
|
37
|
-
In Sprockets index files such as `index.js` or `index.css`
|
37
|
+
In Sprockets, index files such as `index.js` or `index.css` inside of a folder will generate a file with the folder's name. So if you have a file named `foo/index.js`, it will compile down to `foo.js`. This is similar to Node.js's behavior of using [folders as modules](https://nodejs.org/api/modules.html#modules_folders_as_modules). It is also somewhat similar to the way that a file in `public/my_folder/index.html` can be reached by a request to `/my_folder`. This means that you cannot directly use an index file. For example this would not work:
|
38
38
|
|
39
39
|
```
|
40
40
|
<%= asset_path("foo/index.js") %>
|
@@ -52,7 +52,7 @@ Why would you want to use this behavior? It is common behavior where you might
|
|
52
52
|
//= require_tree .
|
53
53
|
```
|
54
54
|
|
55
|
-
This has the problem that files are required alphabetically. If your directory has `jquery-ui.js` and `jquery.min.js
|
55
|
+
This has the problem that files are required alphabetically. If your directory has `jquery-ui.js` and `jquery.min.js`, then Sprockets will require `jquery-ui.js` before `jquery` is required, which won't work (because jquery-ui depends on jquery). Previously the only way to get the correct ordering would be to rename your files, something like `0-jquery-ui.js`. Instead of doing that you can use an index file.
|
56
56
|
|
57
57
|
For example, if you have an `application.js` and want all the files in the `foo/` folder you could do this:
|
58
58
|
|
@@ -67,7 +67,7 @@ Then create a file `foo/index.js` that requires all the files in that folder in
|
|
67
67
|
//= require foo-ui.js
|
68
68
|
```
|
69
69
|
|
70
|
-
Now
|
70
|
+
Now, your `application.js` will correctly load the `foo.min.js` before `foo-ui.js`. If you used `require_tree` it would not work correctly.
|
71
71
|
|
72
72
|
## Understanding the Sprockets Environment
|
73
73
|
|
@@ -204,8 +204,8 @@ environment.js_compressor = :uglify
|
|
204
204
|
environment.css_compressor = :scss
|
205
205
|
```
|
206
206
|
|
207
|
-
If you are using Sprockets directly with Rack app, don't forget to add
|
208
|
-
`uglifier` and `sass` gems to your Gemfile when using above options.
|
207
|
+
If you are using Sprockets directly with a Rack app, don't forget to add
|
208
|
+
the `uglifier` and `sass` gems to your Gemfile when using above options.
|
209
209
|
|
210
210
|
### Styling with Sass and SCSS
|
211
211
|
|
@@ -362,7 +362,7 @@ reference files relative to the location of the current file.
|
|
362
362
|
specified by *path*. If the file is required multiple times, it will
|
363
363
|
appear in the bundle only once.
|
364
364
|
|
365
|
-
|
365
|
+
#### The `require_directory` Directive
|
366
366
|
|
367
367
|
`require_directory` *path* requires all source files of the same
|
368
368
|
format in the directory specified by *path*. Files are required in
|
@@ -404,6 +404,16 @@ automatically be defined for you.
|
|
404
404
|
}
|
405
405
|
```
|
406
406
|
|
407
|
+
#### The `link_directory` Directive
|
408
|
+
|
409
|
+
`link_directory` *path* links all the files inside the directory specified by the *path*
|
410
|
+
|
411
|
+
#### The `link_tree` Directive
|
412
|
+
|
413
|
+
`link_tree` *path* works like `link_directory`, but operates
|
414
|
+
recursively to link all files in all subdirectories of the
|
415
|
+
directory specified by *path*.
|
416
|
+
|
407
417
|
#### The `depend_on` Directive
|
408
418
|
|
409
419
|
`depend_on` *path* declares a dependency on the given *path* without
|
@@ -424,9 +434,9 @@ within any subdependencies.
|
|
424
434
|
|
425
435
|
## Processor Interface
|
426
436
|
|
427
|
-
Sprockets 2.x was originally
|
437
|
+
Sprockets 2.x was originally designed around [Tilt](https://github.com/rtomayko/tilt)'s engine interface. However, starting with 3.x, a new interface has been introduced deprecating Tilt.
|
428
438
|
|
429
|
-
Similar to Rack, a processor is
|
439
|
+
Similar to Rack, a processor is any "callable" (an object that responds to `call`). This may be a simple Proc or a full class that defines a `def self.call(input)` method. The `call` method accepts an `input` Hash and returns a Hash of metadata.
|
430
440
|
|
431
441
|
Also see [`Sprockets::ProcessorUtils`](https://github.com/rails/sprockets/blob/master/lib/sprockets/processor_utils.rb) for public helper methods.
|
432
442
|
|
@@ -434,11 +444,11 @@ Also see [`Sprockets::ProcessorUtils`](https://github.com/rails/sprockets/blob/m
|
|
434
444
|
|
435
445
|
The `input` Hash defines the following public fields.
|
436
446
|
|
437
|
-
* `:data` - String asset contents
|
447
|
+
* `:data` - String asset contents.
|
438
448
|
* `:environment` - Current `Sprockets::Environment` instance.
|
439
449
|
* `:cache` - A `Sprockets::Cache` instance. See [`Sprockets::Cache#fetch`](https://github.com/rails/sprockets/blob/master/lib/sprockets/cache.rb).
|
440
450
|
* `:uri` - String Asset URI.
|
441
|
-
* `:
|
451
|
+
* `:source_path` - String full path to original file.
|
442
452
|
* `:load_path` - String current load path for filename.
|
443
453
|
* `:name` - String logical path for filename.
|
444
454
|
* `:content_type` - String content type of the output asset.
|
@@ -455,7 +465,7 @@ end
|
|
455
465
|
|
456
466
|
### return Hash
|
457
467
|
|
458
|
-
The processor should return metadata `Hash`. With the exception of the `:data` key, the processor can store arbitrary JSON
|
468
|
+
The processor should return metadata `Hash`. With the exception of the `:data` key, the processor can store arbitrary valid JSON values in this Hash. The data will be stored and exposed on `Asset#metadata`.
|
459
469
|
|
460
470
|
The returned `:data` replaces the assets `input[:data]` to the next processor in the chain. Returning a `String` is shorthand for returning `{ data: str }`. And returning `nil` is shorthand for a no-op where the input data is not transformed, `{ data: input[:data] }`.
|
461
471
|
|
@@ -467,6 +477,8 @@ The metadata Hash provides an open format for processors to extend the pipeline
|
|
467
477
|
* `:stubbed` - A `Set` of String Asset URIs that will be omitted from the `:required` set.
|
468
478
|
* `:links` - A `Set` of String Asset URIs that should be compiled along with this asset.
|
469
479
|
* `:dependencies` - A `Set` of String Cache URIs that should be monitored for caching.
|
480
|
+
* `:map` - An `Array` of source maps for the asset.
|
481
|
+
* `:charset` - The mime charset for an asset.
|
470
482
|
|
471
483
|
``` ruby
|
472
484
|
def self.call(input)
|
data/lib/rake/sprocketstask.rb
CHANGED
data/lib/sprockets.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
2
4
|
require 'sprockets/version'
|
3
5
|
require 'sprockets/cache'
|
4
6
|
require 'sprockets/environment'
|
@@ -121,8 +123,8 @@ module Sprockets
|
|
121
123
|
register_bundle_processor 'application/javascript', Bundle
|
122
124
|
register_bundle_processor 'text/css', Bundle
|
123
125
|
|
124
|
-
register_bundle_metadata_reducer '*/*', :data, proc { "" }, :concat
|
125
|
-
register_bundle_metadata_reducer 'application/javascript', :data, proc { "" }, Utils.method(:concat_javascript_sources)
|
126
|
+
register_bundle_metadata_reducer '*/*', :data, proc { String.new("") }, :concat
|
127
|
+
register_bundle_metadata_reducer 'application/javascript', :data, proc { String.new("") }, Utils.method(:concat_javascript_sources)
|
126
128
|
register_bundle_metadata_reducer '*/*', :links, :+
|
127
129
|
register_bundle_metadata_reducer '*/*', :map, SourceMapUtils.method(:concat_source_maps)
|
128
130
|
|
data/lib/sprockets/asset.rb
CHANGED
data/lib/sprockets/autoload.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/autoload'
|
2
3
|
require 'sprockets/path_utils'
|
3
4
|
require 'sprockets/source_map_utils'
|
@@ -38,7 +39,8 @@ module Sprockets
|
|
38
39
|
'sourceRoot' => input[:load_path],
|
39
40
|
'moduleRoot' => nil,
|
40
41
|
'filename' => input[:filename],
|
41
|
-
'filenameRelative' => PathUtils.split_subpath(input[:load_path], input[:filename])
|
42
|
+
'filenameRelative' => PathUtils.split_subpath(input[:load_path], input[:filename]),
|
43
|
+
'sourceFileName' => input[:source_path]
|
42
44
|
}.merge(@options)
|
43
45
|
|
44
46
|
if opts['moduleIds'] && opts['moduleRoot']
|
data/lib/sprockets/base.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/asset'
|
2
3
|
require 'sprockets/bower'
|
3
4
|
require 'sprockets/cache'
|
@@ -14,7 +15,7 @@ require 'sprockets/source_map_utils'
|
|
14
15
|
require 'sprockets/uri_tar'
|
15
16
|
|
16
17
|
module Sprockets
|
17
|
-
# `Base` class for `Environment` and `
|
18
|
+
# `Base` class for `Environment` and `CachedEnvironment`.
|
18
19
|
class Base
|
19
20
|
include PathUtils, PathDependencyUtils, PathDigestUtils, DigestUtils, SourceMapUtils
|
20
21
|
include Configuration
|
@@ -34,7 +35,7 @@ module Sprockets
|
|
34
35
|
@cache = Cache.new(cache, logger)
|
35
36
|
end
|
36
37
|
|
37
|
-
# Return an `
|
38
|
+
# Return an `CachedEnvironment`. Must be implemented by the subclass.
|
38
39
|
def cached
|
39
40
|
raise NotImplementedError
|
40
41
|
end
|
data/lib/sprockets/bower.rb
CHANGED
data/lib/sprockets/bundle.rb
CHANGED
data/lib/sprockets/cache.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'logger'
|
2
3
|
require 'sprockets/digest_utils'
|
3
4
|
|
@@ -153,7 +154,9 @@ module Sprockets
|
|
153
154
|
#
|
154
155
|
# Returns a String with a length less than 250 characters.
|
155
156
|
def expand_key(key)
|
156
|
-
|
157
|
+
digest_key = DigestUtils.pack_urlsafe_base64digest(DigestUtils.digest(key))
|
158
|
+
namespace = digest_key[0, 2]
|
159
|
+
"sprockets/v#{VERSION}/#{namespace}/#{digest_key}"
|
157
160
|
end
|
158
161
|
|
159
162
|
PEEK_SIZE = 100
|
@@ -1,14 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/base'
|
2
3
|
|
3
4
|
module Sprockets
|
4
|
-
# `
|
5
|
+
# `CachedEnvironment` is a special cached version of `Environment`.
|
5
6
|
#
|
6
7
|
# The expection is that all of its file system methods are cached
|
7
|
-
# for the instances lifetime. This makes `
|
8
|
+
# for the instances lifetime. This makes `CachedEnvironment` much faster. This
|
8
9
|
# behavior is ideal in production environments where the file system
|
9
10
|
# is immutable.
|
10
11
|
#
|
11
|
-
# `
|
12
|
+
# `CachedEnvironment` should not be initialized directly. Instead use
|
12
13
|
# `Environment#cached`.
|
13
14
|
class CachedEnvironment < Base
|
14
15
|
def initialize(environment)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/autoload'
|
2
3
|
require 'sprockets/digest_utils'
|
3
4
|
|
@@ -35,11 +36,12 @@ module Sprockets
|
|
35
36
|
attr_reader :cache_key
|
36
37
|
|
37
38
|
def initialize(options = {})
|
38
|
-
@
|
39
|
+
@options = options
|
39
40
|
@cache_key = "#{self.class.name}:#{Autoload::Closure::VERSION}:#{Autoload::Closure::COMPILER_VERSION}:#{VERSION}:#{DigestUtils.digest(options)}".freeze
|
40
41
|
end
|
41
42
|
|
42
43
|
def call(input)
|
44
|
+
@compiler ||= Autoload::Closure::Compiler.new(@options)
|
43
45
|
@compiler.compile(input[:data])
|
44
46
|
end
|
45
47
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/autoload'
|
2
3
|
require 'sprockets/source_map_utils'
|
3
4
|
|
@@ -7,7 +8,7 @@ module Sprockets
|
|
7
8
|
#
|
8
9
|
# For more infomation see:
|
9
10
|
#
|
10
|
-
# https://github.com/
|
11
|
+
# https://github.com/rails/ruby-coffee-script
|
11
12
|
#
|
12
13
|
module CoffeeScriptProcessor
|
13
14
|
VERSION = '2'
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'sprockets/utils'
|
2
3
|
|
3
4
|
module Sprockets
|
@@ -10,6 +11,24 @@ module Sprockets
|
|
10
11
|
config[:compressors]
|
11
12
|
end
|
12
13
|
|
14
|
+
# Public: Register a new compressor `klass` at `sym` for `mime_type`.
|
15
|
+
#
|
16
|
+
# Registering a processor allows it to be looked up by `sym` later when
|
17
|
+
# assigning a JavaScript or CSS compressor.
|
18
|
+
#
|
19
|
+
# Compressors only operate on JavaScript and CSS. If you want to compress a
|
20
|
+
# different type of asset, use a processor instead.
|
21
|
+
#
|
22
|
+
# Examples
|
23
|
+
#
|
24
|
+
# register_compressor 'text/css', :my_sass, MySassCompressor
|
25
|
+
# css_compressor = :my_sass
|
26
|
+
#
|
27
|
+
# mime_type - String MIME Type (one of: 'test/css' or 'application/javascript').
|
28
|
+
# sym - Symbol registration address.
|
29
|
+
# klass - The compressor class.
|
30
|
+
#
|
31
|
+
# Returns nothing.
|
13
32
|
def register_compressor(mime_type, sym, klass)
|
14
33
|
self.config = hash_reassoc(config, :compressors, mime_type) do |compressors|
|
15
34
|
compressors[sym] = klass
|
data/lib/sprockets/context.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'rack/utils'
|
2
3
|
require 'set'
|
3
4
|
require 'sprockets/errors'
|
@@ -99,7 +100,7 @@ module Sprockets
|
|
99
100
|
# including it.
|
100
101
|
#
|
101
102
|
# This is used for caching purposes. Any changes made to
|
102
|
-
# the dependency file
|
103
|
+
# the dependency file will invalidate the cache of the
|
103
104
|
# source file.
|
104
105
|
def depend_on(path)
|
105
106
|
if environment.absolute_path?(path) && environment.stat(path)
|
@@ -115,7 +116,7 @@ module Sprockets
|
|
115
116
|
#
|
116
117
|
# This is used for caching purposes. Any changes that would
|
117
118
|
# invalidate the dependency asset will invalidate the source
|
118
|
-
# file. Unlike `depend_on`, this will
|
119
|
+
# file. Unlike `depend_on`, this will recursively include
|
119
120
|
# the target asset's dependencies.
|
120
121
|
def depend_on_asset(path)
|
121
122
|
load(resolve(path))
|