jekyll-esm 0.2.0 → 0.2.4

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: 1afb8eff9885f0d3929ec26e1e8453171c9e3ce80cbc324636aaa4e0560fd5a3
4
- data.tar.gz: d3839dd0821dfc36e51f5e67e4b3560a1b3e50c2d73bb8385a08c371bfe21d79
3
+ metadata.gz: 6749b3df8551bf909787abb952ae08972414b0bbdf5f7e7f23f4bff6d4ef8ab2
4
+ data.tar.gz: 29ea4044988a289d95a1997a5b51f00c2845f4b12e32ad495335f8522879efb2
5
5
  SHA512:
6
- metadata.gz: 044f9722e1c7f6a4a8e56e0cbf451ac2648ecc8fd27c342e3862b24641c9f6a8a86a74c8c8e8b62d18e9289ed527b5b36f44fa039e70686e24fdc8c175b27ccb
7
- data.tar.gz: 4fbe841607df6d91039683482ffd7a06eb01153a51cead4e5ec826970438919afcd7b4565d59bbf749ef0b88588d7ddbe9630d85ed7ceee358426726c5433dc1
6
+ metadata.gz: a3d16da0b768b51ff364380ea717561dd08a7615ef3e703575174323bc357b4ef5cc38502862fb1ad3a9349801481d3211b425da41bd25064b5599dd7f59c7e6
7
+ data.tar.gz: 3aecd4960c952a1f931ce244889ace705a4b86f185d7b40348c06835073f143f5f2509d7453efaf55e272bca08994e69231c260ca649bbe5fe6d08e4aa8da1be
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /spec/fixtures/package.json
10
+ /spec/fixtures/yarn*
9
11
  /spec/fixtures/.jekyll-cache/
10
12
  /spec/fixtures/_site/
11
13
  /spec/fixtures/dist/
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-esm (0.2.0)
4
+ jekyll-esm (0.2.3.1)
5
5
  jekyll
6
6
  listen
7
7
  nokogiri
data/README.md CHANGED
@@ -41,7 +41,7 @@ plugins:
41
41
  - jekyll/esm
42
42
  ```
43
43
 
44
- # Ingore package.json!
44
+ # Ignore package.json!
45
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
46
 
47
47
  ```yml
@@ -49,6 +49,31 @@ exclude:
49
49
  - package.json
50
50
  ```
51
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
+
52
77
  ### Example `_config.yml`
53
78
 
54
79
  You can have a look at the possible configuration options in the fixtures config file at `spec/fixtures/_config.yml` in this repo.
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,13 +21,28 @@ 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
26
33
  next if import_key =~ /https?:\/\/[\S]+/
34
+ # ignore relative paths
27
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
28
45
 
29
- import = import_key.split('/').first
30
46
  pkg_path = File.join(page.site.source, 'node_modules', import)
31
47
 
32
48
  # don't repeatedly attempt to install a package
@@ -73,6 +89,7 @@ module Jekyll
73
89
  FileUtils.cp_r(File.join(site.source, 'node_modules'), File.join(site.dest, 'node_modules'))
74
90
  @@existing_esm_packages = @@new_esm_packages
75
91
  @@new_esm_packages = []
92
+ @@esm_ids = []
76
93
  end
77
94
  end
78
95
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Esm
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.4"
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.2.0
4
+ version: 0.2.4
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