nanoc-webpack.rb 0.8.1 → 0.10.0

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: c27b1415f331e970ecdd99955b365c8e543b8682d70b69a1aeac3f9951658146
4
- data.tar.gz: 2d5ef75a0ed5333fdc6e6bbef45120ac9812434e8dc433d9defc198d5861622a
3
+ metadata.gz: 55c01b8ff3d1ed45f8771cf2bb089bbda55fab111a4eb580c35a4f4af7abe8da
4
+ data.tar.gz: 0c771cccff972d2a773061a4f270f12288d82a5c0f8e656ff27e503f8ef1f4ca
5
5
  SHA512:
6
- metadata.gz: 7335426a9d835917faaf0217ba85f2e8525d02db9bb2c30f835d163eb3f24e1bd4371ccc648c7d478ed8fb78290fdbdf61b20a11d3db49b47d885d05aa6c51d0
7
- data.tar.gz: 940e00ae66c3b742efdf159987bc0e2b69ffc049ad447951d4c791d067bd80a141309e5a3dd24ca6ccc30d06ead28bc5ddd437a7d5caba4e55743623b267bc4c
6
+ metadata.gz: 8358191888f3b745a4a2a1ee674239930e20836a20e59cc1610ac6e1fcb794e57f5b326d75010c9ad7c145193bc22bc5d3a30e3b175547a7c356e412f6ae601d
7
+ data.tar.gz: 0dbf2d414ebfa34b5d8fef2dfe659d37b96a9d26539d532e636804823616bc127a1eefe93ef054a539e03df6ad892d7f37dfdb2697ac20a0c3eb868cec64b8f0
data/README.md CHANGED
@@ -67,12 +67,12 @@ returns the default command-line options forwarded to webpack:
67
67
  # Rules
68
68
  require "nanoc-webpack"
69
69
  compile "/js/main/App.tsx" do
70
- filter(:webpack, argv: ["--node-env", "production"])
70
+ filter(:webpack, argv: ["--config", "webpack.production.js"])
71
71
  write("/js/main/app.js")
72
72
  end
73
73
  ```
74
74
 
75
- ## <a id='install'>Install</a>
75
+ ## Install
76
76
 
77
77
  **Rubygems.org**
78
78
 
@@ -15,12 +15,12 @@ module Nanoc::Webpack
15
15
 
16
16
  ##
17
17
  # @example
18
- # Nanoc::Webpack.default_argv.replace ["--cache-type", "memory"]
18
+ # Nanoc::Webpack.default_argv.concat ["--cache-type", "filesystem"]
19
19
  #
20
20
  # @return [Array<String>]
21
21
  # The default command-line options forwarded to webpack.
22
22
  def self.default_argv
23
- @default_argv ||= ["--cache-type", "filesystem"]
23
+ @default_argv ||= []
24
24
  end
25
25
 
26
26
  ##
@@ -33,15 +33,17 @@ module Nanoc::Webpack
33
33
  # @return [void]
34
34
  def run(content, options = {})
35
35
  options = Ryo.from(options)
36
- path = temporary_file(content).path
36
+ path = temporary_file(content).path
37
37
  depend_on dependable(paths: options.depend_on, reject: options.reject)
38
38
  .map { items[_1] }
39
+ argv = [*(options.argv || []), *default_argv]
40
+ scan(argv)
39
41
  spawn "node",
40
42
  ["./node_modules/webpack/bin/webpack.js",
43
+ *argv,
41
44
  "--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
42
45
  "--output-path", File.dirname(path),
43
- "--output-filename", File.basename(path),
44
- *default_argv, *(options.argv || [])],
46
+ "--output-filename", File.basename(path)],
45
47
  log: File.join(tmpdir, "webpack.log")
46
48
  File.read(path)
47
49
  ensure
@@ -56,7 +58,11 @@ module Nanoc::Webpack
56
58
 
57
59
  def temporary_file(content)
58
60
  mkdir_p(tmpdir)
59
- file = Tempfile.new(File.basename(item.identifier.to_s), tmpdir)
61
+ name = item.identifier.to_s
62
+ file = Tempfile.new(
63
+ [ File.basename(name), File.extname(name).sub(/^\.(ts|tsx)$/, '.js') ],
64
+ tmpdir
65
+ )
60
66
  file.write(content)
61
67
  file.tap(&:flush)
62
68
  end
@@ -64,5 +70,23 @@ module Nanoc::Webpack
64
70
  def tmpdir
65
71
  File.join(Dir.getwd, "tmp", "webpack")
66
72
  end
73
+
74
+ def scan(argv)
75
+ options = argv.filter_map { _1.start_with?("-") ? _1 : nil }
76
+ builtins = %w[--entry --output-path --output-filename]
77
+ options
78
+ .map { |option| [option, options.count { _1 == option }] }
79
+ .each do |option, count|
80
+ if builtins.include?(option)
81
+ abort log("[fatal] '#{option}' is a builtin option that can't be replaced")
82
+ elsif count > 1
83
+ warn log("[warn] '#{option}' appears in argv more than once")
84
+ end
85
+ end
86
+ end
87
+
88
+ def log(message)
89
+ "[nanoc-webpack.rb] #{message}"
90
+ end
67
91
  end
68
92
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Webpack
5
- VERSION = "0.8.1"
5
+ VERSION = "0.10.0"
6
6
  end
7
7
  end
data/spec/filter_spec.rb CHANGED
@@ -125,28 +125,34 @@ RSpec.describe Nanoc::Webpack::Filter do
125
125
  context "when nodejs is executed" do
126
126
  let(:cmdline) do
127
127
  [
128
- "node",
129
- "./node_modules/webpack/bin/webpack.js",
130
128
  "--entry", File.join(Dir.getwd, "test.ts"),
131
129
  "--output-path", instance_of(String),
132
130
  "--output-filename", instance_of(String),
133
- "--cache-type", "filesystem"
134
131
  ]
135
132
  end
136
133
 
137
134
  context "with default arguments" do
138
135
  it "executes nodejs" do
139
- expect(Kernel).to receive(:spawn).with(*cmdline, instance_of(Hash))
136
+ expect(Kernel).to receive(:spawn).with(
137
+ "node",
138
+ "./node_modules/webpack/bin/webpack.js",
139
+ *cmdline,
140
+ instance_of(Hash)
141
+ )
140
142
  expect(Process).to receive(:wait)
141
143
  filter.run(item)
142
144
  end
143
145
  end
144
146
 
145
147
  context "with --no-cache" do
146
- let(:cmdline) { super().concat(["--no-cache"]) }
147
-
148
148
  it "executes nodejs with an argument" do
149
- expect(Kernel).to receive(:spawn).with(*cmdline, instance_of(Hash))
149
+ expect(Kernel).to receive(:spawn).with(
150
+ "node",
151
+ "./node_modules/webpack/bin/webpack.js",
152
+ "--no-cache",
153
+ *cmdline,
154
+ instance_of(Hash)
155
+ )
150
156
  expect(Process).to receive(:wait)
151
157
  filter.run(item, argv: ["--no-cache"])
152
158
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-webpack.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-30 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ryo.rb
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubygems_version: 3.5.3
141
+ rubygems_version: 3.5.9
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: nanoc-webpack.rb integrates webpack into nanoc.