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 +4 -4
- data/README.md +1 -1
- data/lib/nanoc/webpack/filter.rb +25 -5
- data/lib/nanoc/webpack/version.rb +1 -1
- data/spec/filter_spec.rb +13 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f655a8bfc0aa523822ddc3b7ba6282e2cd76c93184a349fe1dbb08c24d41d3
|
4
|
+
data.tar.gz: 470d7218dc0946f4889a441a57ffccb1433a4ae253f92bf05eb5edfb99436ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: ["--
|
70
|
+
filter(:webpack, argv: ["--config", "webpack.production.js"])
|
71
71
|
write("/js/main/app.js")
|
72
72
|
end
|
73
73
|
```
|
data/lib/nanoc/webpack/filter.rb
CHANGED
@@ -15,12 +15,12 @@ module Nanoc::Webpack
|
|
15
15
|
|
16
16
|
##
|
17
17
|
# @example
|
18
|
-
# Nanoc::Webpack.default_argv.
|
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 ||= [
|
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
|
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
|
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(
|
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(
|
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.
|
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-
|
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.
|
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.
|