sasso-rails 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 47fd62745a906cd33915884a073e5388d83256bea9532a27c21a03673834d7b3
4
- data.tar.gz: f605f87e6c421d01a67c4ee18a336a1b501be756cf74bdac88173e828fe982b5
3
+ metadata.gz: 182fa27772f53b3c1fbacd3befd6785adf4bac01018fb283e771e75cd4c1c53a
4
+ data.tar.gz: 3199c95dd402640b1408e998bf7879dd7aadcf352328e292a1e8700884be9df9
5
5
  SHA512:
6
- metadata.gz: 85f6248e5b1bec53c62170a86d94b9e7ebad12777447057b117d9410f63d5887918188f0d031e79a477aae9509d901cdeb54c9b1eac07a36531678744efb79d9
7
- data.tar.gz: 6a616ebbe2dbdda75c06f717d4fa7c71a0815aa2fcba243b6ea6ccf8db0cfb36696b1869fb346de3396709c6baa956dc172ce5deb7a8da616fbd3f5cf9129062
6
+ metadata.gz: 9b7fd563419f880c4540fa2da7a28dfcc33b06d7cc4e898ef8669794938614e0b903fcbc4e96cb365451a98890d3dcd907ca1100b7a5262f75d96a17ff767149
7
+ data.tar.gz: 2599b9c1c5f0e84d76b713eabbaf1bb6068863551f3d7ab38fc6b5d3ae6f1f0a6103cbc0089e00fb640a27cadd476831cfa89204ad4d5d3bf5cb169f15592130
data/CHANGELOG.md CHANGED
@@ -8,7 +8,33 @@ the engine-gem version range it requires.
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
- ## [0.1.1] - 2026-06-13
11
+ ## [0.1.3] - 2026-06-14
12
+
13
+ ### Fixed
14
+
15
+ - **Sprockets `assets:precompile` crash (`LoadError: cannot load such file --
16
+ sassc`).** On a Sprockets app (e.g. a default Rails 7.0 app), the install
17
+ generator left the manifest's default `//= link_directory ../stylesheets .css`
18
+ directive in place, so Sprockets 4 tried to COMPILE the `application.scss`
19
+ entrypoint with its built-in `SasscProcessor` (`require "sassc"`, not
20
+ installed) — harmless in dev but crashing `assets:precompile` on deploy. The
21
+ generator now neutralizes that directive (sasso owns the compiled output,
22
+ served from `../builds`, which is linked separately). Idempotent, and a no-op
23
+ on Propshaft (no manifest). Rails 7.0 + Sprockets now precompiles cleanly;
24
+ Propshaft (Rails 7.1 / 8.x) is unaffected. Verified end-to-end across both
25
+ pipelines, plus a generator unit test.
26
+
27
+ ## [0.1.2] - 2026-06-14
28
+
29
+ Requires the `sasso` gem **>= 0.2.0** (for its source-map API).
30
+
31
+ ### Added
32
+
33
+ - **Source maps.** `sasso:build` writes a `<output>.map` sidecar next to each
34
+ compiled CSS and appends the `sourceMappingURL` footer. Controlled by
35
+ `config.sasso.source_map` (default: on outside production, off in production);
36
+ the map's `sources` are rewritten relative to the builds directory and `file`
37
+ points at the built CSS.
12
38
 
13
39
  Makes `bin/rails generate sasso:install` drop-in on a fresh Rails 8 app.
14
40
 
data/README.md CHANGED
@@ -72,6 +72,10 @@ config.sasso.style = :compressed
72
72
  # searched first, so sibling partials need no configuration.
73
73
  config.sasso.load_paths = [Rails.root.join("vendor/styles").to_s]
74
74
 
75
+ # Source maps: write a <output>.map sidecar + sourceMappingURL footer.
76
+ # Default: on outside production, off in production. Set true/false to force.
77
+ config.sasso.source_map = nil
78
+
75
79
  # Defaults shown:
76
80
  config.sasso.source_dir = "app/assets/stylesheets"
77
81
  config.sasso.build_dir = "app/assets/builds"
@@ -90,8 +94,6 @@ that directory as a source of ready-to-serve assets:
90
94
 
91
95
  ## Notes & limitations
92
96
 
93
- - **Source maps are not supported yet.** The in-process compiler returns CSS
94
- only; there is no `.css.map` output in any environment.
95
97
  - **`builds` is file-to-file.** Each entry maps one input file to one output
96
98
  file. There is no directory-glob form (no `"." => "."`); list each entrypoint
97
99
  explicitly.
@@ -106,6 +108,29 @@ that directory as a source of ready-to-serve assets:
106
108
  - **Watch is a 1s mtime poll** (dependency-free, no native fs-events); it covers
107
109
  the source dir and `config.sasso.load_paths`.
108
110
 
111
+ ## Troubleshooting
112
+
113
+ **`Bundler::GemNotFound: Could not find sasso-<version>-<platform>`** on
114
+ `bin/rails sasso:build` (or any boot) right after `bundle install`. The `sasso`
115
+ compiler ships as a **precompiled native gem**, so the lockfile must list your
116
+ platform. If Bundler resolved the version but didn't materialize the native
117
+ build for your arch, add the platform and re-install:
118
+
119
+ ```console
120
+ $ bundle lock --add-platform arm64-darwin # or x86_64-linux, aarch64-linux, etc.
121
+ $ bundle install
122
+ ```
123
+
124
+ This is a generic Bundler behaviour for precompiled native gems (the same step
125
+ `nokogiri` etc. need on CI/Docker), not specific to sasso — but you may hit it
126
+ on a first local install. To bake every supported platform into the lockfile up
127
+ front:
128
+
129
+ ```console
130
+ $ bundle lock --add-platform x86_64-linux aarch64-linux \
131
+ x86_64-linux-musl aarch64-linux-musl arm64-darwin x86_64-darwin x64-mingw-ucrt
132
+ ```
133
+
109
134
  ## Versioning
110
135
 
111
136
  This gem versions independently of the `sasso` compiler gem and pins it with a
@@ -55,9 +55,24 @@ module Sasso
55
55
  manifest = "app/assets/config/manifest.js"
56
56
  full = File.join(destination_root, manifest)
57
57
  return unless File.exist?(full)
58
- return if File.read(full).include?("link_tree ../builds")
59
58
 
60
- append_to_file manifest, %(//= link_tree ../builds\n)
59
+ unless File.read(full).include?("link_tree ../builds")
60
+ append_to_file manifest, %(//= link_tree ../builds\n)
61
+ end
62
+
63
+ # The default Sprockets manifest links the stylesheets SOURCE directory
64
+ # (`//= link_directory ../stylesheets .css`). Sprockets 4 then tries to
65
+ # COMPILE our `application.scss` entrypoint with its built-in
66
+ # SasscProcessor, which `require "sassc"` — not installed on a default
67
+ # app — so `assets:precompile` crashes with
68
+ # `LoadError: cannot load such file -- sassc`. sasso owns the compiled
69
+ # output (served from ../builds, linked above), so the raw source dir
70
+ # must NOT be linked. Neutralize the directive — idempotent, since the
71
+ # regex only matches the live `//=` form (a re-run is a no-op).
72
+ gsub_file manifest,
73
+ %r{^([ \t]*)//=([ \t]*link_directory[ \t]+\.\./stylesheets\b.*)$},
74
+ "\\1//\\2 -- disabled by sasso-rails (sasso compiles ../stylesheets to ../builds; " \
75
+ "linking the source dir makes Sprockets compile .scss via sassc)"
61
76
  end
62
77
 
63
78
  def add_watch_to_procfile
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "fileutils"
4
+ require "json"
5
+ require "pathname"
4
6
 
5
7
  module Sasso
6
8
  module Rails
@@ -21,17 +23,18 @@ module Sasso
21
23
 
22
24
  ALLOWED_STYLES = %i[expanded compressed].freeze
23
25
 
24
- attr_reader :root, :builds, :style, :load_paths, :source_dir, :build_dir
26
+ attr_reader :root, :builds, :style, :load_paths, :source_dir, :build_dir, :source_map
25
27
 
26
28
  def initialize(root:, builds:, style: :expanded, load_paths: [],
27
29
  source_dir: "app/assets/stylesheets",
28
- build_dir: "app/assets/builds")
30
+ build_dir: "app/assets/builds", source_map: false)
29
31
  @root = File.expand_path(root.to_s)
30
32
  @builds = normalize_builds(builds)
31
33
  @style = normalize_style(style)
32
34
  @load_paths = Array(load_paths).map(&:to_s)
33
35
  @source_dir = source_dir.to_s
34
36
  @build_dir = build_dir.to_s
37
+ @source_map = source_map ? true : false
35
38
  end
36
39
 
37
40
  # Compile every entrypoint; returns the list of written output paths.
@@ -47,13 +50,18 @@ module Sasso
47
50
  raise Error, "sasso-rails: input stylesheet not found: #{src}"
48
51
  end
49
52
 
50
- # `Sasso.compile` already searches the entry file's own directory first
51
- # (for sibling @use/@import); pass any extra include dirs after it.
52
- css = ::Sasso.compile(src, style: @style, load_paths: @load_paths)
53
-
54
53
  dest = File.join(@root, @build_dir, output)
55
54
  FileUtils.mkdir_p(File.dirname(dest))
56
- File.write(dest, css)
55
+
56
+ # `Sasso.compile` already searches the entry file's own directory first
57
+ # (for sibling @use/@import); pass any extra include dirs after it.
58
+ if @source_map
59
+ result = ::Sasso.compile(src, style: @style, load_paths: @load_paths, source_map: true)
60
+ write_source_map(dest, result.source_map)
61
+ File.write(dest, result.css + source_map_footer(File.basename(dest)))
62
+ else
63
+ File.write(dest, ::Sasso.compile(src, style: @style, load_paths: @load_paths))
64
+ end
57
65
  dest
58
66
  end
59
67
 
@@ -76,6 +84,33 @@ module Sasso
76
84
 
77
85
  private
78
86
 
87
+ # Write the sidecar `<dest>.map`, pointing `file` at the built CSS and
88
+ # rewriting each source URL to a path relative to the builds directory
89
+ # (the .map lives next to the CSS). `source_map` is the parsed v3 Hash.
90
+ def write_source_map(dest, source_map)
91
+ from_dir = File.dirname(dest)
92
+ source_map["file"] = File.basename(dest)
93
+ source_map["sources"] = Array(source_map["sources"]).map { |s| relative_source(s, from_dir) }
94
+ File.write("#{dest}.map", JSON.generate(source_map))
95
+ end
96
+
97
+ # The `sourceMappingURL` footer for the built CSS. Matches dart-sass: the
98
+ # expanded footer sits on its own line after the trailing newline; the
99
+ # compressed footer is appended directly (no leading newline).
100
+ def source_map_footer(css_basename)
101
+ comment = "/*# sourceMappingURL=#{css_basename}.map */"
102
+ @style == :compressed ? "#{comment}\n" : "\n#{comment}\n"
103
+ end
104
+
105
+ # A source URL made relative to the .map's directory (so a DevTools that
106
+ # loads the .map resolves the original next to it). Falls back to the URL
107
+ # unchanged if it is not a relativizable path.
108
+ def relative_source(url, from_dir)
109
+ Pathname.new(url).relative_path_from(Pathname.new(from_dir)).to_s
110
+ rescue ArgumentError
111
+ url
112
+ end
113
+
79
114
  # Compile, downgrading a Sass/config error to a warning so a watcher does
80
115
  # not die on it (used at startup and on every recompile).
81
116
  def safe_build
@@ -12,6 +12,7 @@ module Sasso
12
12
  # config.sasso.load_paths # extra @use/@import include dirs (Array)
13
13
  # config.sasso.source_dir # default "app/assets/stylesheets"
14
14
  # config.sasso.build_dir # default "app/assets/builds"
15
+ # config.sasso.source_map # true | false (default: on outside production)
15
16
  #
16
17
  # The `sasso:build` rake task is enhanced onto `assets:precompile`, so the
17
18
  # CSS is generated before Propshaft/Sprockets fingerprints it on deploy.
@@ -22,6 +23,7 @@ module Sasso
22
23
  config.sasso.load_paths = []
23
24
  config.sasso.source_dir = "app/assets/stylesheets"
24
25
  config.sasso.build_dir = "app/assets/builds"
26
+ config.sasso.source_map = nil # resolved in `Sasso::Rails.source_map_for`
25
27
 
26
28
  # NOTE: no `rake_tasks do load ... end` — Rails::Engine already auto-loads
27
29
  # lib/tasks/**/*.rake into the host app. Loading it again here would define
@@ -40,9 +42,20 @@ module Sasso
40
42
  load_paths: cfg.load_paths,
41
43
  source_dir: cfg.source_dir,
42
44
  build_dir: cfg.build_dir,
45
+ source_map: source_map_for(cfg.source_map),
43
46
  )
44
47
  end
45
48
 
49
+ # Generate source maps outside production by default (debugging aid); an
50
+ # explicit `config.sasso.source_map` (true/false) always wins. Off in
51
+ # production by default to avoid shipping `.map` sidecars + the asset-digest
52
+ # interaction unless opted in.
53
+ def source_map_for(configured)
54
+ return configured ? true : false unless configured.nil?
55
+
56
+ !::Rails.env.production?
57
+ end
58
+
46
59
  # Default to compressed CSS in production (smaller payload), expanded
47
60
  # elsewhere (readable). An explicit `config.sasso.style` always wins.
48
61
  #
@@ -5,6 +5,6 @@ module Sasso
5
5
  # Versioned INDEPENDENTLY of both the `sasso` gem and the `sasso` crate.
6
6
  # The gemspec pins the engine gem with a range (sasso >= 0.1.1, < 1), so a
7
7
  # compiler bump does not force a lockstep release of this integration gem.
8
- VERSION = "0.1.1"
8
+ VERSION = "0.1.3"
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sasso-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - momiji-rs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-13 00:00:00.000000000 Z
11
+ date: 2026-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -30,7 +30,7 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.1
33
+ version: 0.2.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '1'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.1.1
43
+ version: 0.2.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1'