Skip to content

Commit

Permalink
Merge branch 'main' into process-jst-ejs-erb-files
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca authored Jun 23, 2022
2 parents f6bef3e + 881a819 commit 6ce1ae3
Show file tree
Hide file tree
Showing 54 changed files with 553 additions and 169 deletions.
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/ruby/.devcontainer/base.Dockerfile

# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.1, 3.0, 2, 2.7, 3-bullseye, 3.1-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 3-buster, 3.1-buster, 3.0-buster, 2-buster, 2.7-buster
ARG VARIANT="3.1-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install additional gems.
# RUN gem install <your-gem-names-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.0/containers/ruby
{
"name": "Ruby",
"build": {
"dockerfile": "Dockerfile",
"args": {
// Update 'VARIANT' to pick a Ruby version: 3, 3.1, 3.0, 2, 2.7
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3-bullseye",
// Options
"NODE_VERSION": "lts/*"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"rebornix.Ruby"
]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "ruby --version",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"github-cli": "latest"
}

}
32 changes: 32 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: CI
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
name: ${{ matrix.ruby }}
strategy:
matrix:
experimental: [false]
ruby:
- "2.5"
- "2.6"
- "2.7"
- "3.0"
- "3.1"
include:
- { ruby: jruby, experimental: true }
- { ruby: jruby-head, experimental: true }
- { ruby: head, experimental: true }

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run tests
timeout-minutes: 10
run: bundle exec rake
20 changes: 20 additions & 0 deletions .github/workflows/isolated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CI isolated tests
on: [push, pull_request]
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.7]

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Run tests
run: bundle exec rake test_isolated
28 changes: 28 additions & 0 deletions .github/workflows/rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: RuboCop

on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.7]

steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: /home/runner/bundle
key: bundle-use-ruby-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: bundle-use-ruby-gems-
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Bundle install
run: |
gem install bundler -v 2.1.4
bundle config path /home/runner/bundle
bundle install
- name: Run linter
run: bundle exec rubocop --parallel
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

16 changes: 14 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket

## Master

- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
- Fix `Sprockets::Server` to return lower-cased response headers to comply with Rack::Lint 3.0. [#744](https://github.com/rails/sprockets/pull/744)
- Adding new directive `depend_on_directory` [#668](https://github.com/rails/sprockets/pull/668)
- Fix `application/js-sourcemap+json` charset [#669](https://github.com/rails/sprockets/pull/669)
- Fix `CachedEnvironment` caching nil values [#723](https://github.com/rails/sprockets/pull/723)
- Process `*.jst.ejs.erb` files with ERBProcessor [#674](https://github.com/rails/sprockets/pull/674)

## 4.0.3

- Fix `Manifest#find` yielding from a Promise causing issue on Ruby 3.1.0-dev. [#720](https://github.com/rails/sprockets/pull/720)
- Better detect the ERB version to avoid deprecation warnings. [#719](https://github.com/rails/sprockets/pull/719)
- Allow assets already fingerprinted to be served through `Sprockets::Server`
- Do not fingerprint files that already contain a valid digest in their name
- Remove remaining support for Ruby < 2.4.[#672](https://github.com/rails/sprockets/pull/672)
- Fix cache key for coffee script processor to be dependent on the filename [#670](https://github.com/rails/sprockets/pull/670)

## 4.0.2

- Fix `etag` and digest path compilation that were generating string with invalid digest since 4.0.1.
Expand All @@ -28,7 +40,7 @@ Get upgrade notes from Sprockets 3.x to 4.x at https://github.com/rails/sprocket

## 4.0.0.beta9

- Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby verision of Rails [#604]
- Minimum Ruby version for Sprockets 4 is now 2.5+ which matches minimum ruby version of Rails [#604]
- Fix threading bug introduced in Sprockets 4 [#603]
- Warn when two potential manifest files exist. [#560]

Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
Contributing to Sprockets
=====================

[![Build Status](https://secure.travis-ci.org/rails/sprockets.svg?branch=master)](http://travis-ci.org/rails/sprockets)

Sprockets is work of [hundreds of contributors](https://github.com/rails/sprockets/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/rails/sprockets/pulls), [propose features and discuss issues](https://github.com/rails/sprockets/issues).

#### Fork the Project
Expand Down
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
source "https://rubygems.org"
gemspec

gem "rack", github: 'rack/rack'
67 changes: 59 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ Here is a list of the available directives:
- [`link_directory`](#link_directory) - Make target directory compile and be publicly available without adding contents to current
- [`link_tree`](#link_tree) - Make target tree compile and be publicly available without adding contents to current
- [`depend_on`](#depend_on) - Recompile current file if target has changed
- [`depend_on_directory`](#depend_on_directory) - Recompile current file if any files in target directory has changed
- [`stub`](#stub) - Ignore target file

You can see what each of these does below.
Expand Down Expand Up @@ -239,7 +240,7 @@ The first time this file is compiled the `application.js` output will be written

So, if `b.js` changes it will get recompiled. However instead of having to recompile the other files from `a.js` to `z.js` since they did not change, we can use the prior intermediary files stored in the cached values . If these files were expensive to generate, then this "partial" asset cache strategy can save a lot of time.

Directives such as `require`, `link`, and `depend_on` tell Sprockets what assets need to be re-compiled when a file changes. Files are considered "fresh" based on their mtime on disk and a combination of cache keys.
Directives such as `require`, `link`, `depend_on`, and `depend_on_directory` tell Sprockets what assets need to be re-compiled when a file changes. Files are considered "fresh" based on their mtime on disk and a combination of cache keys.

On Rails you can force a "clean" install by clearing the `public/assets` and `tmp/cache/assets` directories.

Expand Down Expand Up @@ -376,11 +377,19 @@ generated and made available to the public you can link it by including this in
```

The argument to `link` is a _logical path_, that is it will be resolved according to the
configured asset load paths. See [Accesing Assets](#accessing-assets) above. A path relative to
configured asset load paths. See [Accessing Assets](#accessing-assets) above. A path relative to
the current file won't work, it must be a logical path.

**Caution**: the "link" directive should always have an explicit extension on the end.

`link` can also be used to include manifest files from mounted Rails engines:

```
//= link my_engine
```

This would find a manifest file at `my_engine/app/assets/config/my_engine.js` and include its directives.

### link_directory

`link_directory` *path* links all the files inside the directory specified by the *path*. By "link", we mean they are specified as compilation targets to be written out to disk, and made available to be served to user-agents.
Expand Down Expand Up @@ -445,11 +454,53 @@ you need to tell sprockets that it needs to re-compile the file if `bar.data` ch
var bar = '<%= File.read("bar.data") %>'
```

To depend on an entire directory containing multiple files, use `depend_on_directory`

### depend_on_asset

`depend_on_asset` *path* works like `depend_on`, but operates
recursively reading the file and following the directives found. This is automatically implied if you use `link`, so consider if it just makes sense using `link` instead of `depend_on_asset`.

### depend_on_directory

`depend_on_directory` *path* declares all files in the given *path* without
including them in the bundle. This is useful when you need to expire an
asset's cache in response to a change in multiple files in a single directory.

All paths are relative to your declaration and must begin with `./`

Also, your must include these directories in your [load path](guides/building_an_asset_processing_framework.md#the-load-path).

**Example:**

If we've got a directory called `data` with files `a.data` and `b.data`

```
// ./data/a.data
A
```

```
// ./data/b.data
B
```

```
// ./file.js.erb
//= depend_on_directory ./data
var a = '<% File.read('data/a.data') %>'
var b = '<% File.read('data/b.data') %>'
```

Would produce:

```js
var a = "A";
var b = "B";
```

You can also see [Index files are proxies for folders](#index-files-are-proxies-for-folders) for another method of organizing folders that will give you more control.

### stub

`stub` *path* excludes that asset and its dependencies from the asset bundle.
Expand Down Expand Up @@ -491,9 +542,9 @@ When you modify the `logo.png` on disk, it will force `application.css` to be
recompiled so that the fingerprint will be correct in the generated asset.

You can manually make sprockets depend on any other file that is generated
by sprockets by using the `depend_on` directive. Rails implements the above
feature by auto calling `depend_on` on the original asset when the `asset_url`
is used inside of an asset.
by sprockets by using the `depend_on` or `depend_on_directory` directive. Rails
implements the above feature by auto calling `depend_on` on the original asset
when the `asset_url` is used inside of an asset.

### Styling with Sass and SCSS

Expand Down Expand Up @@ -606,19 +657,19 @@ Several JavaScript and CSS minifiers are available through shorthand.
In Rails you will specify them with:

```ruby
config.assets.js_compressor = :uglify
config.assets.js_compressor = :terser
config.assets.css_compressor = :scss
```

If you're not using Rails, configure this directly on the "environment".

``` ruby
environment.js_compressor = :uglify
environment.js_compressor = :terser
environment.css_compressor = :scss
```

If you are using Sprockets directly with a Rack app, don't forget to add
the `uglifier` and `sass` gems to your Gemfile when using above options.
the `terser` and `sass` gems to your Gemfile when using above options.

### Gzip

Expand Down
14 changes: 13 additions & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ How do you know if source maps are working correctly? Try adding a syntax error

When compiling assets with Sprockets, Sprockets needs to decide which top-level targets to compile, usually `application.css`, `application.js`, and images.

If you are using sprockets prior to 4.0, Rails will compile `application.css`, `application.js`; and *any* files found in your assets directory(ies) that are _not_ recognized as JS or CSS, but do have a filename extension. That latter was meant to apply to all your images usually in `./app/assets/images/`, but could have targetted other files as well.
If you are using sprockets prior to 4.0, Rails will compile `application.css`, `application.js`; and *any* files found in your assets directory(ies) that are _not_ recognized as JS or CSS, but do have a filename extension. That latter was meant to apply to all your images usually in `./app/assets/images/`, but could have targeted other files as well.

If you wanted to specify additional assets to deliver that were not included by this logic, for instance for a marketing page with its own CSS, you might add something like this:

Expand Down Expand Up @@ -88,6 +88,18 @@ Now you'll be able to use a `<%= stylesheet_link_tag "application" %>` or `<%= s

If you have additional non-standard files you need to be top-level targets, instead of using `config.assets.precompile`, you can use `link`, `link_directory`, and `link_tree` directives in the `manifest.js`.

If you are mounting Rails engines which provide their own assets, check to see if they define their own `manifest.js` file. That file can also be linked using the `link` directive:

```js
// app/assets/config/manifest.js
//= link my_engine

// my_engine/app/assets/config/my_engine.js
//= link_directory ../stylesheets/my_engine .css
```

This example will direct Sprockets to include the manifest file for the engine `my_engine`; since that manifest uses `link_directory`, the CSS file at `my_engine/app/assets/stylesheets/my_engine/overrides.css` will be made available to Rails (most importantly, to the engine's templates) at `my_engine/overrides`.

Existing `config.assets.precompile` settings will still work for string values (although it is discouraged), but if you were previously using regexp or proc values, they won't work at all with Sprockets 4, and if you try you'll get an exception raised that looks like `NoMethodError: undefined method 'start_with?'`

Some assets will be compiled as top-level assets when they are referenced from inside of another asset. For example, the `asset_url` erb helper will automatically link assets:
Expand Down
Loading

0 comments on commit 6ce1ae3

Please sign in to comment.