jekyll-esm 0.2.4 → 0.3.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: 6749b3df8551bf909787abb952ae08972414b0bbdf5f7e7f23f4bff6d4ef8ab2
4
- data.tar.gz: 29ea4044988a289d95a1997a5b51f00c2845f4b12e32ad495335f8522879efb2
3
+ metadata.gz: d212ba159da0ce94de768f433163e5ae82b6925bc98ff6f6e97954dee8333df7
4
+ data.tar.gz: ec795062ad244777de16db061fc3130063ec98ecbaa7babe94956ea7067c8cce
5
5
  SHA512:
6
- metadata.gz: a3d16da0b768b51ff364380ea717561dd08a7615ef3e703575174323bc357b4ef5cc38502862fb1ad3a9349801481d3211b425da41bd25064b5599dd7f59c7e6
7
- data.tar.gz: 3aecd4960c952a1f931ce244889ace705a4b86f185d7b40348c06835073f143f5f2509d7453efaf55e272bca08994e69231c260ca649bbe5fe6d08e4aa8da1be
6
+ metadata.gz: 8a1e14be4494ef6b61288bda264b05368ea425af7e765b86066b65f57c5c3a1a44adc7b89708324d1e36f619a02e216a8caedd5f9047b032db56915004a4b244
7
+ data.tar.gz: 05ea6d9f22f296afcea11239f6d4190bbb96fccc4b82676bb7c0c3a5e8e100ed1cd6b339c3c6841442e518b64571ce3da023a91d7dd4c3fc0374bac3d1eaa608
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-esm (0.2.3.1)
4
+ jekyll-esm (0.3.1)
5
5
  jekyll
6
6
  listen
7
7
  nokogiri
@@ -19,7 +19,7 @@ GEM
19
19
  eventmachine (>= 0.12.9)
20
20
  http_parser.rb (~> 0.6.0)
21
21
  eventmachine (1.2.7)
22
- ffi (1.15.3)
22
+ ffi (1.15.4)
23
23
  formatador (0.3.0)
24
24
  forwardable-extended (2.6.0)
25
25
  guard (2.18.0)
@@ -37,9 +37,9 @@ GEM
37
37
  guard-compat (~> 1.1)
38
38
  rspec (>= 2.99.0, < 4.0)
39
39
  http_parser.rb (0.6.0)
40
- i18n (1.8.10)
40
+ i18n (1.8.11)
41
41
  concurrent-ruby (~> 1.0)
42
- jekyll (4.2.0)
42
+ jekyll (4.2.1)
43
43
  addressable (~> 2.4)
44
44
  colorator (~> 1.0)
45
45
  em-websocket (~> 0.5)
@@ -63,14 +63,18 @@ GEM
63
63
  kramdown-parser-gfm (1.1.0)
64
64
  kramdown (~> 2.0)
65
65
  liquid (4.0.3)
66
- listen (3.6.0)
66
+ listen (3.7.0)
67
67
  rb-fsevent (~> 0.10, >= 0.10.3)
68
68
  rb-inotify (~> 0.9, >= 0.9.10)
69
69
  lumberjack (1.2.8)
70
70
  mercenary (0.4.0)
71
71
  method_source (1.0.0)
72
+ mini_portile2 (2.6.1)
72
73
  nenv (0.3.0)
73
- nokogiri (1.12.3-x86_64-darwin)
74
+ nokogiri (1.12.5)
75
+ mini_portile2 (~> 2.6.1)
76
+ racc (~> 1.4)
77
+ nokogiri (1.12.5-x86_64-darwin)
74
78
  racc (~> 1.4)
75
79
  notiffany (0.1.3)
76
80
  nenv (~> 0.1)
@@ -81,13 +85,13 @@ GEM
81
85
  coderay (~> 1.1)
82
86
  method_source (~> 1.0)
83
87
  public_suffix (4.0.6)
84
- racc (1.5.2)
88
+ racc (1.6.0)
85
89
  rake (12.3.3)
86
90
  rb-fsevent (0.11.0)
87
91
  rb-inotify (0.10.1)
88
92
  ffi (~> 1.0)
89
93
  rexml (3.2.5)
90
- rouge (3.26.0)
94
+ rouge (3.26.1)
91
95
  rspec (3.10.0)
92
96
  rspec-core (~> 3.10.0)
93
97
  rspec-expectations (~> 3.10.0)
@@ -100,7 +104,7 @@ GEM
100
104
  rspec-mocks (3.10.2)
101
105
  diff-lcs (>= 1.2.0, < 2.0)
102
106
  rspec-support (~> 3.10.0)
103
- rspec-support (3.10.2)
107
+ rspec-support (3.10.3)
104
108
  safe_yaml (1.0.5)
105
109
  sassc (2.4.0)
106
110
  ffi (~> 1.9)
@@ -108,9 +112,10 @@ GEM
108
112
  terminal-table (2.0.0)
109
113
  unicode-display_width (~> 1.1, >= 1.1.1)
110
114
  thor (1.1.0)
111
- unicode-display_width (1.7.0)
115
+ unicode-display_width (1.8.0)
112
116
 
113
117
  PLATFORMS
118
+ aarch64-linux
114
119
  x86_64-darwin-19
115
120
 
116
121
  DEPENDENCIES
data/README.md CHANGED
@@ -4,7 +4,7 @@ This plugin will allow you to define esm module definitions directly in your mar
4
4
 
5
5
  ## Why?
6
6
 
7
- Looks like some of the major frameworks are moving away from asset bundlers as es6 is now able to do most of it internally, which is great. Now you can simply declare your esm definitions in the markup of your templates and with this plugin Jekyll will manage the installation behind the scenes with yarn (will make the package manager configurable in a later version).
7
+ Looks like some of the major frameworks are moving away from asset bundlers as es6 is now able to do most of it internally, which is great. Now you can simply declare your esm definitions in the markup of your templates and with this plugin Jekyll will manage the installation behind the scenes with yarn by default, but you can additionally specify npm or bower as the package manager.
8
8
 
9
9
 
10
10
  ## Installation
@@ -27,20 +27,34 @@ And add the following to your site's `_config.yml`
27
27
 
28
28
  ```yml
29
29
  plugins:
30
- - jekyll/esm
30
+ - jekyll-esm
31
31
  ```
32
32
 
33
- NOTE the `/` - the `-` variant is not available yet.
33
+ ## Select a package manager
34
+ jekyll-esm uses yarn by default but if you prefer npm or bower, its:
34
35
 
35
- ALSO NOTE - it's probably advisable to place this plugin as the very last one in the build pipe. EG:-
36
+ ``` yml
37
+ # _config.yml
36
38
 
37
- ```yml
38
- plugins:
39
- - jekyll-otherplug
40
- ...
41
- - jekyll/esm
39
+ esm:
40
+ manager: npm|bower
42
41
  ```
43
42
 
43
+ # Destination folder
44
+ Additionally you can rename the destination folder for production, so where by default it would output to _\_site/node_packages_ or _\_site/bower_components_, if you set the `dist`:
45
+
46
+ _A NOTE ON NPM_ if you don't have a _package.json_ file in your root, npm will actually search in the parent folder for a _package.json_.
47
+
48
+
49
+ ``` yml
50
+ # _config.yml
51
+
52
+ esm:
53
+ dist: dist
54
+ ```
55
+
56
+ Then all your managed packages will be available at `_site/dist`.
57
+
44
58
  # Ignore package.json!
45
59
  Currently You *MUST* exclude package.json in the `_config.yml` otherwise jekyll will go into a loop. Sucks a bit but will try and improve that.
46
60
 
data/jekyll-esm.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- require_relative 'lib/jekyll/esm/version'
1
+ require_relative 'lib/jekyll-esm/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "jekyll-esm"
data/lib/jekyll/esm.rb CHANGED
@@ -1,112 +1,2 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll/esm/version"
4
- require "jekyll"
5
- require "open3"
6
- require 'tmpdir'
7
- require 'nokogiri'
8
- require 'json'
9
-
10
- module Jekyll
11
- module Esm
12
- @@existing_esm_packages = []
13
- @@new_esm_packages = []
14
- @@esm_ids = []
15
-
16
- class Error < StandardError; end
17
-
18
- def self.process(page)
19
- doc = Nokogiri::HTML(page.output)
20
-
21
- import_maps = doc.search('script[type=importmap]')
22
-
23
- import_maps.each do |value|
24
- esm_id = value.attributes["data-esm-id"]&.value
25
- # declare a data-esm-id so that jekyll will only process an esm declaration once
26
- next if @@esm_ids.include?(esm_id)
27
- @@esm_ids << esm_id if esm_id
28
-
29
- importmap = JSON.parse(value.children[0].content)
30
- imports = importmap["imports"]
31
- imports.keys.each do |import_key|
32
- # ignore urls
33
- next if import_key =~ /https?:\/\/[\S]+/
34
- # ignore relative paths
35
- next if import_key =~ /(^\.+\/)+/
36
- # ignore absolute paths
37
- next if import_key =~ /^\/[\S]+/
38
-
39
- # ignore namespaces but only if it is not scoped
40
- if import_key =~ /^@[\S]+/
41
- import = import_key.split('/')[0..2].join('/')
42
- else
43
- import = import_key.split('/').first
44
- end
45
-
46
- pkg_path = File.join(page.site.source, 'node_modules', import)
47
-
48
- # don't repeatedly attempt to install a package
49
- next if Dir.exists?(pkg_path) && @@new_esm_packages.include?(import)
50
-
51
- @@new_esm_packages << import
52
-
53
- stdout, stderr, status = Open3.capture3(
54
- "yarn add #{import}",
55
- chdir: File.expand_path(page.site.source)
56
- )
57
-
58
- if page.site.config.dig('esm', 'strict')
59
- runtime_error = stdout =~ /ERROR in|SyntaxError/
60
-
61
- raise Error, stderr if stderr.size > 0
62
- raise Error, stdout if !runtime_error.nil?
63
- end
64
- end
65
- end
66
- end
67
-
68
- def self.apply(site)
69
- if @@existing_esm_packages.any?
70
- for_removal = @@existing_esm_packages - @@new_esm_packages.uniq
71
-
72
- # Remove any packages that are no longer referenced in an esm declaration
73
- if for_removal.any?
74
- stdout, stderr, status = Open3.capture3(
75
- "yarn remove #{for_removal.join(' ')}",
76
- chdir: File.expand_path(site.source)
77
- )
78
-
79
- if site.config.dig('esm', 'strict')
80
- runtime_error = stdout =~ /ERROR in|SyntaxError/
81
-
82
- raise Error, stderr if stderr.size > 0
83
- raise Error, stdout if !runtime_error.nil?
84
- end
85
- end
86
- end
87
-
88
- FileUtils.rm_rf(File.join(site.dest, 'node_modules'))
89
- FileUtils.cp_r(File.join(site.source, 'node_modules'), File.join(site.dest, 'node_modules'))
90
- @@existing_esm_packages = @@new_esm_packages
91
- @@new_esm_packages = []
92
- @@esm_ids = []
93
- end
94
- end
95
- end
96
-
97
-
98
- Jekyll::Hooks.register :pages, :post_render do |page|
99
- Jekyll::Esm.process(page)
100
- end
101
-
102
- Jekyll::Hooks.register :documents, :post_render do |page|
103
- Jekyll::Esm.process(page)
104
- end
105
-
106
- Jekyll::Hooks.register :posts, :post_render do |page|
107
- Jekyll::Esm.process(page)
108
- end
109
-
110
- Jekyll::Hooks.register :site, :post_write do |site|
111
- Jekyll::Esm.apply(site)
112
- end
1
+ # keep support for _config plugin syntax '- jekyll/esm'
2
+ require_relative '../jekyll-esm.rb'
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module Jekyll
5
+ module Esm
6
+ module Managers
7
+ module Bower
8
+ class Error < StandardError; end
9
+
10
+ def self.location(config)
11
+ config.dig('esm', 'bower', 'dir') || 'bower_components'
12
+ end
13
+
14
+ def self.dist(config)
15
+ config.dig('esm', 'dist') || location(config) || 'bower_components'
16
+ end
17
+
18
+ def self.add(package:, site:)
19
+ stdout, stderr, status = Open3.capture3(
20
+ "bower install #{package}",
21
+ chdir: File.expand_path(site.source)
22
+ )
23
+
24
+ if site.config.dig('esm', 'strict')
25
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
26
+
27
+ raise Error, stderr if stderr.size > 0
28
+ raise Error, stdout if !runtime_error.nil?
29
+ end
30
+ end
31
+
32
+ def self.remove(packages:, site:)
33
+ stdout, stderr, status = Open3.capture3(
34
+ "bower uninstall #{packages}",
35
+ chdir: File.expand_path(site.source)
36
+ )
37
+
38
+ if site.config.dig('esm', 'strict')
39
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
40
+
41
+ raise Error, stderr if stderr.size > 0
42
+ raise Error, stdout if !runtime_error.nil?
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module Jekyll
5
+ module Esm
6
+ module Managers
7
+ module Npm
8
+ class Error < StandardError; end
9
+
10
+ def self.location(config)
11
+ config.dig('esm', 'npm', 'dir') || 'node_modules'
12
+ end
13
+
14
+ def self.dist(config)
15
+ config.dig('esm', 'dist') || location(config) || 'node_modules'
16
+ end
17
+
18
+ def self.add(package:, site:)
19
+ stdout, stderr, status = Open3.capture3(
20
+ "npm install #{package}",
21
+ chdir: File.expand_path(File.join(site.source, '/'))
22
+ )
23
+
24
+ if site.config.dig('esm', 'strict')
25
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
26
+
27
+ raise Error, stderr if stderr.size > 0
28
+ raise Error, stdout if !runtime_error.nil?
29
+ end
30
+ end
31
+
32
+ def self.remove(packages:, site:)
33
+ stdout, stderr, status = Open3.capture3(
34
+ "npm uninstall #{packages}",
35
+ chdir: File.expand_path(File.join(site.source, '/'))
36
+ )
37
+
38
+ if site.config.dig('esm', 'strict')
39
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
40
+
41
+ raise Error, stderr if stderr.size > 0
42
+ raise Error, stdout if !runtime_error.nil?
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module Jekyll
5
+ module Esm
6
+ module Managers
7
+ module Yarn
8
+
9
+ def self.location(config)
10
+ config.dig('esm', 'yarn', 'dir') || 'node_modules'
11
+ end
12
+
13
+ def self.dist(config)
14
+ config.dig('esm', 'dist') || location(config) || 'node_modules'
15
+ end
16
+
17
+ def self.add(package:, site:)
18
+ stdout, stderr, status = Open3.capture3(
19
+ "yarn add #{package}",
20
+ chdir: File.expand_path(site.source)
21
+ )
22
+
23
+ if site.config.dig('esm', 'strict')
24
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
25
+
26
+ raise Error, stderr if stderr.size > 0
27
+ raise Error, stdout if !runtime_error.nil?
28
+ end
29
+ end
30
+
31
+ def self.remove(packages:, site:)
32
+ stdout, stderr, status = Open3.capture3(
33
+ "yarn remove #{packages}",
34
+ chdir: File.expand_path(site.source)
35
+ )
36
+
37
+ if site.config.dig('esm', 'strict')
38
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
39
+
40
+ raise Error, stderr if stderr.size > 0
41
+ raise Error, stdout if !runtime_error.nil?
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Esm
3
- VERSION = "0.2.4"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
data/lib/jekyll-esm.rb ADDED
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll-esm/version"
4
+ require "jekyll-esm/managers/yarn"
5
+ require "jekyll-esm/managers/npm"
6
+ require "jekyll-esm/managers/bower"
7
+ require "jekyll"
8
+ require "open3"
9
+ require 'tmpdir'
10
+ require 'nokogiri'
11
+ require 'json'
12
+
13
+ module Jekyll
14
+ module Esm
15
+ @@existing_esm_packages = []
16
+ @@new_esm_packages = []
17
+ @@esm_ids = []
18
+
19
+ class Error < StandardError; end
20
+
21
+ def self.process(page)
22
+ site = page.site
23
+ manager = select_manager(site.config.dig('esm', 'manager'))
24
+ location = manager.location(site.config)
25
+
26
+ doc = Nokogiri::HTML(page.output)
27
+
28
+ import_maps = doc.search('script[type=importmap]')
29
+
30
+ import_maps.each do |value|
31
+ esm_id = value.attributes["data-esm-id"]&.value
32
+ # declare a data-esm-id so that jekyll will only process an esm declaration once
33
+ next if @@esm_ids.include?(esm_id)
34
+ @@esm_ids << esm_id if esm_id
35
+
36
+ importmap = JSON.parse(value.children[0].content)
37
+ imports = importmap["imports"]
38
+ imports.keys.each do |import_key|
39
+ # ignore urls
40
+ next if import_key =~ /https?:\/\/[\S]+/
41
+ next if imports[import_key] =~ /https?:\/\/[\S]+/
42
+ # ignore relative paths
43
+ next if import_key =~ /(^\.+\/)+/
44
+ # ignore absolute paths
45
+ next if import_key =~ /^\/[\S]+/
46
+
47
+ # ignore namespaces but only if it is not scoped
48
+ if import_key =~ /^@[\S]+/
49
+ import = import_key.split('/')[0..1].join('/')
50
+ else
51
+ import = import_key.split('/').first
52
+ end
53
+
54
+ pkg_path = File.join(site.source, location, import)
55
+
56
+ # don't repeatedly attempt to install a package
57
+ next if Dir.exists?(pkg_path) && @@new_esm_packages.include?(import)
58
+
59
+ @@new_esm_packages << import
60
+
61
+ manager.add(package: import, site: site)
62
+
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.select_manager(name)
68
+ return Managers::Npm if name == 'npm'
69
+ return Managers::Bower if name == 'bower'
70
+ return Managers::Yarn
71
+ end
72
+
73
+ def self.apply(site)
74
+ manager = select_manager(site.config.dig('esm', 'manager'))
75
+ location = manager.location(site.config)
76
+ dist = manager.dist(site.config)
77
+
78
+ if @@existing_esm_packages.any?
79
+ for_removal = @@existing_esm_packages - @@new_esm_packages.uniq
80
+
81
+ # Remove any packages that are no longer referenced in an esm declaration
82
+ if for_removal.any?
83
+ packages = for_removal.join(' ')
84
+ manager.remove(packages: packages, site: site)
85
+ end
86
+ end
87
+
88
+ return unless Dir.exists?(File.join(site.source, location))
89
+
90
+ FileUtils.rm_rf(File.join(site.dest, dist))
91
+ FileUtils.cp_r(File.join(site.source, location), File.join(site.dest, dist))
92
+ @@existing_esm_packages = @@new_esm_packages
93
+ @@new_esm_packages = []
94
+ @@esm_ids = []
95
+ end
96
+ end
97
+ end
98
+
99
+
100
+ Jekyll::Hooks.register :pages, :post_render do |page|
101
+ Jekyll::Esm.process(page)
102
+ end
103
+
104
+ Jekyll::Hooks.register :documents, :post_render do |page|
105
+ Jekyll::Esm.process(page)
106
+ end
107
+
108
+ Jekyll::Hooks.register :posts, :post_render do |page|
109
+ Jekyll::Esm.process(page)
110
+ end
111
+
112
+ Jekyll::Hooks.register :site, :post_write do |site|
113
+ Jekyll::Esm.apply(site)
114
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-esm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Martin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-18 00:00:00.000000000 Z
11
+ date: 2021-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -157,8 +157,12 @@ files:
157
157
  - bin/console
158
158
  - bin/setup
159
159
  - jekyll-esm.gemspec
160
+ - lib/jekyll-esm.rb
161
+ - lib/jekyll-esm/managers/bower.rb
162
+ - lib/jekyll-esm/managers/npm.rb
163
+ - lib/jekyll-esm/managers/yarn.rb
164
+ - lib/jekyll-esm/version.rb
160
165
  - lib/jekyll/esm.rb
161
- - lib/jekyll/esm/version.rb
162
166
  - package.json
163
167
  - yarn.lock
164
168
  homepage: https://github.com/tevio/jekyll-esm
@@ -167,7 +171,7 @@ licenses:
167
171
  metadata:
168
172
  homepage_uri: https://github.com/tevio/jekyll-esm
169
173
  source_code_uri: https://github.com/mml/jekyll-esm
170
- post_install_message:
174
+ post_install_message:
171
175
  rdoc_options: []
172
176
  require_paths:
173
177
  - lib
@@ -182,8 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
186
  - !ruby/object:Gem::Version
183
187
  version: '0'
184
188
  requirements: []
185
- rubygems_version: 3.2.3
186
- signing_key:
189
+ rubygems_version: 3.1.6
190
+ signing_key:
187
191
  specification_version: 4
188
192
  summary: Compile assets with esm module definitions in your markup
189
193
  test_files: []