nanoc-webpack.rb 0.8.1 → 0.9.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: 49f655a8bfc0aa523822ddc3b7ba6282e2cd76c93184a349fe1dbb08c24d41d3
4
+ data.tar.gz: 470d7218dc0946f4889a441a57ffccb1433a4ae253f92bf05eb5edfb99436ca1
5
5
  SHA512:
6
- metadata.gz: 7335426a9d835917faaf0217ba85f2e8525d02db9bb2c30f835d163eb3f24e1bd4371ccc648c7d478ed8fb78290fdbdf61b20a11d3db49b47d885d05aa6c51d0
7
- data.tar.gz: 940e00ae66c3b742efdf159987bc0e2b69ffc049ad447951d4c791d067bd80a141309e5a3dd24ca6ccc30d06ead28bc5ddd437a7d5caba4e55743623b267bc4c
6
+ metadata.gz: fc39909276721fbb75670fdb25f4ed15ac3707de64fc64ee95e377c86047c04d771627cf63b20b52194a1bfdb9c82971f9c6ecc838057037e166361077057256
7
+ data.tar.gz: 9c7153f00b889e798550ab037acbb2548f87d084e2ffd69ff132c48110e68a6fcc973fd1d4d21a5093a743fe959532a42fa6a4dfe6536c99f058648ed85bc85f
data/README.md CHANGED
@@ -67,7 +67,7 @@ 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
  ```
@@ -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(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
@@ -64,5 +66,23 @@ module Nanoc::Webpack
64
66
  def tmpdir
65
67
  File.join(Dir.getwd, "tmp", "webpack")
66
68
  end
69
+
70
+ def scan_argv(argv)
71
+ options = argv.filter_map { _1.start_with?("-") ? _1 : nil }
72
+ builtins = %w[--entry --output-path --output-filename]
73
+ options
74
+ .map { |option| [option, options.count { _1 == option }] }
75
+ .each do |option, count|
76
+ if builtins.include?(option)
77
+ abort log("[fatal] '#{option}' is a builtin option that can't be replaced")
78
+ elsif count > 1
79
+ warn log("[warn] '#{option}' appears in argv more than once")
80
+ end
81
+ end
82
+ end
83
+
84
+ def log(message)
85
+ "[nanoc-webpack.rb] #{message}"
86
+ end
67
87
  end
68
88
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Webpack
5
- VERSION = "0.8.1"
5
+ VERSION = "0.9.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.9.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.