jekyll-postcss 0.2.2 → 0.4.1

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: f1cfaea0a05a10e083038206f5834b33df1b64c845c444aba901a7966e3a505d
4
- data.tar.gz: 7a0a5f58661e27b29bf050056a186d599249e08e509c6610bbf441ab23454d68
3
+ metadata.gz: cba7273f4532e27ab92106857418dc0263b353e5bf82de0f6b01ab7a9f0672c3
4
+ data.tar.gz: d4f38cf3b58e9d5a5f84425b19795a99c586eb5a7a65e3f17c24edad9bda81af
5
5
  SHA512:
6
- metadata.gz: 5a589cb99ed995104b7b277e043ca0b98532790536585015f3910e69444e8d87bd3b2c4009c0187be1a03674ccffa65735c4b1977fdbc4b82088237839acae30
7
- data.tar.gz: 67f350a07a6aeb95f456e96ca738f2c19d777812ce6304d14fbc1b0943c398b41d980f41f5db02e0c78220a12088577cc73f734c114ab37e7dc330621a4bd87b
6
+ metadata.gz: 4c33fa3a5cbaa238644fe013dbe4f8c0dc7773c4c77993b193c08f130b00b2fd2917997ab83416e88eb169b9464a621ef1011567c60b7b33a8913f63723d20bc
7
+ data.tar.gz: 30238af1504ce3ec730a22bd9dd02a0e01ef2550467d4b4d78a21e10663b9b9f61cc1cc1f528819586cad62a11d999cbae244a08d71115aca1c70808584f50b6
@@ -0,0 +1 @@
1
+ github: mhanberg
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
 
13
13
  Gemfile.lock
14
+ node_modules
15
+ yarn-error.log
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.5.3
1
+ ruby 2.7.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.1
4
+
5
+ - Fix a weird issue where the jekyll server never booted up because the converter class got in an infinite loop trying to make a socket connection to the postcss server.
6
+
7
+ ## 0.4.0
8
+
9
+ ### Process SCSS/Sass files
10
+
11
+ The plugin now processes scss and sass files in addition to css files. This requires using the [postcss-scss](https://github.com/postcss/postcss-scss) syntax parser in your postcss.config.js
12
+
13
+ ```javascript
14
+ module.exports = {
15
+ parser: 'postcss-scss',
16
+ plugins: [
17
+ // ...
18
+ ]
19
+ };
20
+
21
+ jekyll-postcss has a higher priority, so it will hand off the the postcss output to jekyll-sass-converter to finish off compiling.
22
+
23
+ ```
24
+
25
+ ## 0.3.2
26
+
27
+ - Output valid CSS when running outside the development environment
28
+
29
+ ## 0.3.1
30
+
31
+ - Only run development server in development.
32
+ - This was discovered when attempting to deploy to Netlify. You can read more about it here [#8](https://github.com/mhanberg/jekyll-postcss/issues/8), [#15](https://github.com/mhanberg/jekyll-postcss/issues/15), and [here](https://community.netlify.com/t/deploy-is-hanging-postcss-problem/14822).
33
+
34
+ ## 0.3.0
35
+
36
+ - Update rake
37
+ - Performance improvement
38
+ - [Breaking?]: Uses `postcss` instead of `postcss-cli`. I think that it will continue to work without changing your dependencies since `postcss-cli` uses `postcss` as a dependency.
39
+
3
40
  ## 0.2.2
4
41
 
5
42
  - Use `Array.unshift` instead of `Array.prepend` to support older Ruby versions
data/README.md CHANGED
@@ -13,6 +13,7 @@ Add this line to your application's Gemfile:
13
13
  ```ruby
14
14
  gem 'jekyll-postcss'
15
15
  ```
16
+
16
17
  And then add this line to your application's `_config.yml`:
17
18
 
18
19
  ```yml
@@ -24,26 +25,76 @@ plugins:
24
25
 
25
26
  ## Usage
26
27
 
27
- Make sure you have [postcss-cli](https://github.com/postcss/postcss-cli) installed and has its binary located at `./node_modules/.bin/postcss`.
28
+ Make sure you have [postcss](https://github.com/postcss/postcss) installed.
28
29
 
29
30
  Add your PostCSS plugins to a `postcss.config.js` file in the root of your repository.
30
31
 
31
32
  ```javascript
32
33
  // postcss.config.js
33
34
 
34
- module.exports {
35
+ module.exports = {
36
+ plugins: [
37
+ require("autoprefixer"), // example of plugin you might use
38
+ ...(process.env.JEKYLL_ENV == "production" // example of only using a plugin in production
39
+ ? [require("cssnano")({ preset: "default" })]
40
+ : [])
41
+ ]
42
+ };
43
+ ```
44
+
45
+ All CSS and SCSS/Sass files will now be processed by PostCSS.
46
+
47
+ ### SCSS/Sass
48
+
49
+ If using SCSS/Sass, you must have [postcss-scss](https://github.com/postcss/postcss-scss) installed and configured in your `postcss.config.js`
50
+
51
+ ```javascript
52
+ module.exports = {
53
+ parser: 'postcss-scss',
35
54
  plugins: [
36
- require("autoprefixer") // example of plugin you might use
55
+ // ...
37
56
  ]
38
57
  };
39
58
  ```
40
59
 
41
- All files with the `.css` extension will now be processed by PostCSS.
60
+ ### Deployment
61
+
62
+ When deploying, make sure to set your `JEKYLL_ENV` to something like `production` or `staging`. This is necessary to make sure that jekyll-postcss will not use internal development conveniences when building on your host's servers.
42
63
 
64
+ This can be done so by setting your build command like so
43
65
 
44
- ### Note
66
+ ```shell
67
+ JEKYLL_ENV=production bundle exec jekyll build
68
+ ```
45
69
 
46
- `jekyll-postcss` will cache your styles to avoid rebuilding when nothing has changed.
70
+ or using your hosts proprietary configuration. Here is an example using Netlify.
71
+
72
+ ```toml
73
+ # netlify.toml
74
+
75
+ [context.production.environment]
76
+ JEKYLL_ENV = "production"
77
+
78
+ [context.branch-deploy.environment]
79
+ JEKYLL_ENV = "staging"
80
+
81
+ [context.deploy-preview.environment]
82
+ JEKYLL_ENV = "staging"
83
+ ```
84
+
85
+ ### Front Matter Reminder
86
+
87
+ Your stylesheets still need to have [front matter](https://jekyllrb.com/docs/step-by-step/03-front-matter/) for them to be processed by Jekyll.
88
+
89
+ ```
90
+ ---
91
+ ---
92
+
93
+ /* Example using Tailwind */
94
+ @tailwind base;
95
+ @tailwind components;
96
+ @tailwind utilities;
97
+ ```
47
98
 
48
99
  ## Development
49
100
 
data/bin/command ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env bash
2
+
3
+ script_status="running"
4
+
5
+ # Start the program in the background
6
+ exec "$@" &
7
+ pid1=$!
8
+
9
+ shutdown(){
10
+ local pid1=$1
11
+ local pid2=$2
12
+
13
+ if [ $script_status = "running" ]; then
14
+ script_status="shutting down"
15
+ wait "$pid1"
16
+ ret=$?
17
+ kill -KILL "$pid2"
18
+ exit $ret
19
+ fi
20
+ }
21
+
22
+ # Silence warnings from here on
23
+ exec >/dev/null 2>&1
24
+
25
+ # Read from stdin in the background and
26
+ # kill running program when stdin closes
27
+ exec 0<&0 "$(
28
+ while read -r; do :; done
29
+ kill -KILL "$pid1"
30
+ )" &
31
+ pid2=$!
32
+
33
+ # Clean up
34
+ trap 'shutdown $pid1 $pid2' INT HUP TERM
35
+ shutdown "$pid1" "$pid2"
36
+
data/bin/postcss ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+
3
+ const postcss = require(require.resolve("postcss", { paths: [process.cwd()] }));
4
+ const config = require(`${process.cwd()}/postcss.config.js`);
5
+ const net = require("net");
6
+
7
+ class PostCSS {
8
+ static process(data, write) {
9
+ postcss(config.plugins)
10
+ .process(JSON.parse(data).raw_content, { from: "stdin" })
11
+ .then((result) => write(result))
12
+ .catch((error) => {
13
+ console.error("PostCSS Error!\n");
14
+ console.error(error.toString());
15
+ });
16
+ }
17
+
18
+ static startServer() {
19
+ const server = net.createServer((c) => {
20
+ c.on("data", (data) => {
21
+ this.process(data, function (result) {
22
+ const packet = { compiled_css: result.toString() };
23
+
24
+ c.write(`${JSON.stringify(packet)}\n`);
25
+ });
26
+ });
27
+ });
28
+
29
+ server.on("error", (err) => {
30
+ console.error("PostCSS Server Error!\n");
31
+ throw err;
32
+ });
33
+
34
+ server.listen(8124, () => {
35
+ console.log("PostCSS Server listening on port 8124...");
36
+ });
37
+ }
38
+ }
39
+
40
+ switch (process.argv[2]) {
41
+ case "--development":
42
+ PostCSS.startServer();
43
+ break;
44
+ default:
45
+ PostCSS.process(process.argv[2], function (result) {
46
+ const packet = { compiled_css: result.toString() };
47
+
48
+ process.stdout.write(`${JSON.stringify(packet)}`);
49
+ });
50
+ }
data/bin/release ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec rake release
data/bin/spec ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec rspec "$@"
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
32
32
  spec.add_development_dependency "bundler", "~> 1.17"
33
33
  spec.add_development_dependency "jekyll",
34
34
  ENV["JEKYLL_VERSION"] ? "~> #{ENV["JEKYLL_VERSION"]}" : ">= 2.0"
35
- spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rake", ">= 12.3.3"
36
36
  spec.add_development_dependency "rspec", "~> 3.0"
37
37
  spec.add_development_dependency "rubocop-jekyll", "~> 0.5.1"
38
38
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "socket"
4
+ require "json"
5
+
6
+ module PostCss
7
+ class Socket
8
+ class PostCssRuntimeError; end
9
+ START_SCRIPT = File.expand_path("../../bin/command", __dir__)
10
+ POSTCSS_SCRIPT = File.expand_path("../../bin/postcss", __dir__)
11
+
12
+ def initialize
13
+ start_dev_server if development?
14
+ end
15
+
16
+ def write(data)
17
+ if development?
18
+ @postcss.puts encode(data)
19
+ else
20
+ @compiled_css = `#{POSTCSS_SCRIPT} '#{encode(data)}'`
21
+ end
22
+
23
+ nil
24
+ end
25
+
26
+ def read
27
+ if development?
28
+ decode(@postcss.gets.chomp)
29
+ else
30
+ raise "You must call PostCss#write before calling PostCss#read" if @compiled_css.nil?
31
+
32
+ decode(@compiled_css)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def encode(data)
39
+ JSON.dump(:raw_content => data)
40
+ end
41
+
42
+ def decode(data)
43
+ JSON.parse(data)["compiled_css"]
44
+ end
45
+
46
+ def development?
47
+ @env ||= Jekyll.env
48
+
49
+ @env == "development"
50
+ end
51
+
52
+ MAX_ATTEMPTS = 100
53
+
54
+ def start_dev_server
55
+ Thread.new do
56
+ system "#{START_SCRIPT} #{POSTCSS_SCRIPT} --development"
57
+ end
58
+
59
+ attempts = 0
60
+ @postcss =
61
+ begin
62
+ TCPSocket.open("localhost", 8124)
63
+ rescue StandardError => e
64
+ attempts = attempts + 1
65
+
66
+ if attempts < MAX_ATTEMPTS
67
+ sleep 0.1
68
+ retry
69
+ else
70
+ raise "Could not connect to the PostCSS server"
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module PostCss
5
- VERSION = "0.2.2"
5
+ VERSION = "0.4.1"
6
6
  end
7
7
  end
@@ -1,32 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "open3"
4
3
  require "digest"
4
+ require_relative "../../jekyll-postcss/socket"
5
5
 
6
6
  module Jekyll
7
7
  module Converters
8
8
  class PostCss < Converter
9
9
  safe true
10
- priority :low
10
+ priority :normal
11
11
 
12
12
  def initialize(config = {})
13
13
  super
14
14
 
15
+ @socket = config.fetch("socket") { ::PostCss::Socket.new }
15
16
  @raw_cache = nil
16
17
  @import_raw_cache = {}
17
18
  @converted_cache = nil
18
19
  end
19
20
 
20
21
  def matches(ext)
21
- ext.casecmp(".css").zero?
22
+ [".css", ".scss", ".sass"].include?(ext.downcase)
22
23
  end
23
24
 
24
- def output_ext(_ext)
25
- ".css"
25
+ def output_ext(ext)
26
+ ext
26
27
  end
27
28
 
28
29
  def convert(content)
29
- raise PostCssNotFoundError unless File.file?("./node_modules/.bin/postcss")
30
+ raise PostCssNotFoundError unless Dir.exist?("./node_modules/postcss")
30
31
 
31
32
  @raw_digest = Digest::MD5.hexdigest content
32
33
  @raw_import_digests = import_digests(content)
@@ -35,12 +36,9 @@ module Jekyll
35
36
  @raw_cache = @raw_digest.dup
36
37
  @import_raw_cache = @raw_import_digests.dup
37
38
 
38
- compiled_css, status =
39
- Open3.capture2("./node_modules/.bin/postcss", :stdin_data => content)
39
+ @socket.write content
40
40
 
41
- raise PostCssRuntimeError unless status.success?
42
-
43
- @converted_cache = compiled_css
41
+ @converted_cache = @socket.read
44
42
  end
45
43
 
46
44
  reset
@@ -75,4 +73,3 @@ module Jekyll
75
73
  end
76
74
 
77
75
  class PostCssNotFoundError < RuntimeError; end
78
- class PostCssRuntimeError < RuntimeError; end
data/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "jekyll-postcss",
3
+ "version": "0.3.0",
4
+ "repository": "git@github.com:mhanberg/jekyll-postcss.git",
5
+ "author": "Mitchell Hanberg <mitch@mitchellhanberg.com>",
6
+ "license": "MIT",
7
+ "devDependencies": {
8
+ "prettier": "^2.0.5"
9
+ }
10
+ }
data/yarn.lock ADDED
@@ -0,0 +1,8 @@
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ prettier@^2.0.5:
6
+ version "2.0.5"
7
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
8
+ integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-postcss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mitchell Hanberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-06 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -87,6 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/FUNDING.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
93
  - ".rubocop.yml"
@@ -98,12 +99,19 @@ files:
98
99
  - LICENSE.txt
99
100
  - README.md
100
101
  - Rakefile
102
+ - bin/command
101
103
  - bin/console
104
+ - bin/postcss
105
+ - bin/release
102
106
  - bin/setup
107
+ - bin/spec
103
108
  - jekyll-postcss.gemspec
104
109
  - lib/jekyll-postcss.rb
110
+ - lib/jekyll-postcss/socket.rb
105
111
  - lib/jekyll-postcss/version.rb
106
112
  - lib/jekyll/converters/postcss.rb
113
+ - package.json
114
+ - yarn.lock
107
115
  homepage: https://github.com/mhanberg/jekyll-postcss
108
116
  licenses:
109
117
  - MIT
@@ -125,8 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
133
  - !ruby/object:Gem::Version
126
134
  version: '0'
127
135
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.7.6
136
+ rubygems_version: 3.1.4
130
137
  signing_key:
131
138
  specification_version: 4
132
139
  summary: A PostCSS plugin for Jekyll.