jekyll-esm 0.1.0 → 0.2.3

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: 7a0c78f818f77fd849f9607aaafb450596ecf19cfc734a1e6c94a261ced383d3
4
- data.tar.gz: 0312d0bc24f988fe6aca12f7a06f46cb66fb8b42e8a19d4e1b964a0b0749f8e3
3
+ metadata.gz: a2fc1ecabf3be2949cece5c1bb60e7285fd273da8b8bbce30f2bf2f28d2117ed
4
+ data.tar.gz: 03021cb0dcfe320ff0861f1d2ffdf44cc2f839827d1c9b7812fce47511f6f737
5
5
  SHA512:
6
- metadata.gz: de5aa84406b28865a4187efdbe990a5064a435980fd28480048d0adda66e5ecad7c0d4d7fb94b4c585b81ad37379ee8357a10e20d785f1b3fd6dc67b1a7367e5
7
- data.tar.gz: 9960ff7fb28d4af09c00bdacdb515002362beeec21c9c8381ceab90df4f69c786363b2afa464f0cab82e2c79a2d09aa7ed9abf5794bbb47f7087c02289932e30
6
+ metadata.gz: 91ea6cf5552e9d4e888229cd5b47c53e1317985f99fcfa4b14893eb2a08d3eeedff0665e35ff2cb0ad10e6479e4109183f17bce81bdc0de4640fd66e3d58de78
7
+ data.tar.gz: a755d7b58b87571896041a2f095014bb360077663c68c4f70038dbf76a54ed67858ebeac2214f54b48722a19a16560ffce7c45d5441e77f68fd8dade5a4e8768
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jekyll-esm (0.0.3)
4
+ jekyll-esm (0.2.2)
5
5
  jekyll
6
6
  listen
7
7
  nokogiri
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Steve Martin
3
+ Copyright (c) 2021 Steve Martin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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,13 +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
- imports.keys.each do |import|
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
40
+ import = import_key.split('/').first
26
41
  pkg_path = File.join(page.site.source, 'node_modules', import)
27
42
 
28
43
  # don't repeatedly attempt to install a package
29
- return if Dir.exists?(pkg_path) && @@new_esm_packages.include?(import)
44
+ next if Dir.exists?(pkg_path) && @@new_esm_packages.include?(import)
30
45
 
31
46
  @@new_esm_packages << import
32
47
 
@@ -46,25 +61,28 @@ module Jekyll
46
61
  end
47
62
 
48
63
  def self.apply(site)
49
- existing_packages = Dir.children(File.join(site.source, 'node_modules')).reject { |dir| dir =~ /^\..*$/ }
50
- for_removal = existing_packages - @@new_esm_packages.uniq
64
+ if @@existing_esm_packages.any?
65
+ for_removal = @@existing_esm_packages - @@new_esm_packages.uniq
51
66
 
52
- # Remove any packages that are no longer referenced in an esm declaration
53
- if for_removal.any?
54
- stdout, stderr, status = Open3.capture3(
55
- "yarn remove #{for_removal.join(' ')}",
56
- chdir: File.expand_path(site.source)
57
- )
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
+ )
58
73
 
59
- if site.config.dig('esm', 'strict')
60
- runtime_error = stdout =~ /ERROR in|SyntaxError/
74
+ if site.config.dig('esm', 'strict')
75
+ runtime_error = stdout =~ /ERROR in|SyntaxError/
61
76
 
62
- raise Error, stderr if stderr.size > 0
63
- 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
64
80
  end
65
81
  end
66
82
 
83
+ FileUtils.rm_rf(File.join(site.dest, 'node_modules'))
67
84
  FileUtils.cp_r(File.join(site.source, 'node_modules'), File.join(site.dest, 'node_modules'))
85
+ @@existing_esm_packages = @@new_esm_packages
68
86
  @@new_esm_packages = []
69
87
  end
70
88
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Esm
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.3"
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.0
4
+ version: 0.2.3
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