jekyll-esm 0.1.1 → 0.2.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: 874a4a2123da08d7db10936aa7c1ef9c0ad4bd4b40e1bbdba9c112c362834648
4
- data.tar.gz: 7eb4809d66b456733505bf68cbad740528c333a116bc8c15f05fe68884ed1b5f
3
+ metadata.gz: 22bef330cea6f3577397e75668c97c47c4e8ae2f1da943fea23043d7b2be4972
4
+ data.tar.gz: e0658de21883aaf0e8ea61b3f5c42c3643a83d83167144f3f8100ff7b8a19b4b
5
5
  SHA512:
6
- metadata.gz: e80869a7324675efcec4ee35c88dc8fba77f82f4068a30aee3aa896e512bc2db17eaa3bce7c736f6ad26ec44bc7ff1ceeae1c3c57a4e452c3352687e8298a676
7
- data.tar.gz: 3929653faeb53d75ea0754f48dbdacd39c8e2f59b2f0defbccdfdda323e4328b3021542af40055c4865fa5b0dbe7ea1a8e6759a7fa9b6c051825c60822ffa2c9
6
+ metadata.gz: d4f7cf93956ea11783b5aab896f188306e0687855f3e7e3bc136386f5870a2f0c16022a675dd6df07ffee0ef0def5de161e65e6650deb9f3e93dfc6a74b977b2
7
+ data.tar.gz: ec16d8d66a36e895b9d6e5ea1b5731000ab785dbd840297940ebac3f5536c4db0e8a7e5b041e37c22f144cd16e85bc4345bf3840d0a3cf98c537951ea98f24ad
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-esm (0.1.1)
4
+ jekyll-esm (0.2.3.1)
5
5
  jekyll
6
6
  listen
7
7
  nokogiri
data/README.md CHANGED
@@ -41,9 +41,42 @@ plugins:
41
41
  - jekyll/esm
42
42
  ```
43
43
 
44
+ # Ignore package.json!
45
+ 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
+
47
+ ```yml
48
+ exclude:
49
+ - package.json
50
+ ```
51
+
52
+ ## Optimizing
53
+ ### Strict mode
54
+ You can run in strict mode to increase logging verbosity from the js package manager.
55
+
56
+ ``` yml
57
+ # _config.yml
58
+
59
+ esm:
60
+ strict: true
61
+ ```
62
+
63
+ ### data-esm-id attribute
64
+ You can set this on a declaration to prevent Jekyll from processing it more than once (eg, if you have lots of compiled pages, with the same layout, you don't want to run it more than once per importmap declaration):-
65
+
66
+ ``` html
67
+ <script data-esm-id='1' type="importmap">
68
+ {
69
+ "imports": {
70
+ "/src/index.js": "/src/index.js"
71
+ }
72
+ }
73
+ </script>
74
+
75
+ If you have multiple importmap declarations with different values, set a different id for each one, or no id at all, but no id is less speed efficient, as jekyll will process them each time for every page.
76
+
44
77
  ### Example `_config.yml`
45
- You can have a look at the possible configuration options in the fixtures config file at `spec/fixtures/_config.yml` in this repo.
46
78
 
79
+ You can have a look at the possible configuration options in the fixtures config file at `spec/fixtures/_config.yml` in this repo.
47
80
 
48
81
  ## Development
49
82
 
data/lib/jekyll/esm.rb CHANGED
@@ -11,6 +11,7 @@ module Jekyll
11
11
  module Esm
12
12
  @@existing_esm_packages = []
13
13
  @@new_esm_packages = []
14
+ @@esm_ids = []
14
15
 
15
16
  class Error < StandardError; end
16
17
 
@@ -20,14 +21,27 @@ module Jekyll
20
21
  import_maps = doc.search('script[type=importmap]')
21
22
 
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
+
23
29
  importmap = JSON.parse(value.children[0].content)
24
30
  imports = importmap["imports"]
25
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
26
40
  import = import_key.split('/').first
27
41
  pkg_path = File.join(page.site.source, 'node_modules', import)
28
42
 
29
43
  # don't repeatedly attempt to install a package
30
- return if Dir.exists?(pkg_path) && @@new_esm_packages.include?(import)
44
+ next if Dir.exists?(pkg_path) && @@new_esm_packages.include?(import)
31
45
 
32
46
  @@new_esm_packages << import
33
47
 
@@ -47,26 +61,30 @@ module Jekyll
47
61
  end
48
62
 
49
63
  def self.apply(site)
50
- existing_packages = Dir.children(File.join(site.source, 'node_modules')).reject { |dir| dir =~ /^\..*$/ }
51
- for_removal = existing_packages - @@new_esm_packages.uniq
64
+ if @@existing_esm_packages.any?
65
+ for_removal = @@existing_esm_packages - @@new_esm_packages.uniq
52
66
 
53
- # Remove any packages that are no longer referenced in an esm declaration
54
- if for_removal.any?
55
- stdout, stderr, status = Open3.capture3(
56
- "yarn remove #{for_removal.join(' ')}",
57
- chdir: File.expand_path(site.source)
58
- )
67
+ # Remove any packages that are no longer referenced in an esm declaration
68
+ if for_removal.any?
69
+ stdout, stderr, status = Open3.capture3(
70
+ "yarn remove #{for_removal.join(' ')}",
71
+ chdir: File.expand_path(site.source)
72
+ )
59
73
 
60
- if site.config.dig('esm', 'strict')
61
- runtime_error = stdout =~ /ERROR in|SyntaxError/
74
+ if site.config.dig('esm', 'strict')
75
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
62
76
 
63
- raise Error, stderr if stderr.size > 0
64
- raise Error, stdout if !runtime_error.nil?
77
+ raise Error, stderr if stderr.size > 0
78
+ raise Error, stdout if !runtime_error.nil?
79
+ end
65
80
  end
66
81
  end
67
82
 
83
+ FileUtils.rm_rf(File.join(site.dest, 'node_modules'))
68
84
  FileUtils.cp_r(File.join(site.source, 'node_modules'), File.join(site.dest, 'node_modules'))
85
+ @@existing_esm_packages = @@new_esm_packages
69
86
  @@new_esm_packages = []
87
+ @@esm_ids = []
70
88
  end
71
89
  end
72
90
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Esm
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.3.1"
4
4
  end
5
5
  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.1.1
4
+ version: 0.2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Martin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-17 00:00:00.000000000 Z
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll