nanoc-webpack.rb 0.5.5 → 0.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +23 -15
- data/lib/nanoc/webpack/filter.rb +10 -5
- data/lib/nanoc/webpack/version.rb +1 -1
- data/lib/nanoc/webpack.rb +7 -1
- data/spec/filter_spec.rb +153 -0
- metadata +3 -3
- data/spec/dependable_spec.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22ee6ae13d75181d02e95948c6f00446a7f92effe96fcc87c8e017f95c707a3e
|
4
|
+
data.tar.gz: bccc782d822fe1b6f843204a45b6eff75f677979bc7f4c68c853a71351f649ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dc66a6c40e1cadcdd50de9acd480ec69d80364bcd1b61e31345fdf4ab817fa7bb51c31fdd0790971b6915cbcce80c372b600b932cb450fac4caf947aa113579
|
7
|
+
data.tar.gz: 6509714bfa75b8d55b7030736a94f8ea66226bd7a86ceecc958c1749d08abc58618940a4cb1c009924bc76a172dedab0ccb6956facfb9e77145c222c6de73211
|
data/.rubocop.yml
CHANGED
@@ -45,6 +45,10 @@ RSpec/DescribeClass:
|
|
45
45
|
Enabled: false
|
46
46
|
RSpec/ImplicitSubject:
|
47
47
|
Enabled: false
|
48
|
+
RSpec/MessageSpies:
|
49
|
+
Enabled: false
|
50
|
+
RSpec/MultipleMemoizedHelpers:
|
51
|
+
Enabled: false
|
48
52
|
Style/LambdaCall:
|
49
53
|
Enabled: false
|
50
54
|
Layout/MultilineMethodCallIndentation:
|
data/README.md
CHANGED
@@ -10,21 +10,27 @@ connects nanoc, and the JavaScript, TypeScript, and nodejs ecosystems.
|
|
10
10
|
|
11
11
|
## Examples
|
12
12
|
|
13
|
-
|
13
|
+
### Defaults
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
#### /js/main/App.tsx
|
16
|
+
|
17
|
+
The following example forwards the entry point `/js/main/App.tsx` to webpack,
|
18
|
+
and then writes the result to `/js/app.js`. This example and all the other
|
19
|
+
examples assume that the files `webpack.config.js`, `tsconfig.json`, and
|
20
|
+
`package.json` already exist at the root of the project:
|
17
21
|
|
18
22
|
``` ruby
|
19
23
|
# Rules
|
20
24
|
require "nanoc-webpack"
|
21
|
-
compile "/js/
|
25
|
+
compile "/js/main/App.tsx" do
|
22
26
|
filter(:webpack)
|
23
27
|
write("/js/app.js")
|
24
28
|
end
|
25
29
|
```
|
26
30
|
|
27
|
-
|
31
|
+
### Options
|
32
|
+
|
33
|
+
#### Option: "depend_on"
|
28
34
|
|
29
35
|
The `depend_on` option tells nanoc what files an entry point imports or requires.
|
30
36
|
When a file being tracked by the `depend_on` option undergoes a change, nanoc
|
@@ -33,13 +39,13 @@ will initiate a recompilation of the entry point:
|
|
33
39
|
```ruby
|
34
40
|
# Rules
|
35
41
|
require "nanoc-webpack"
|
36
|
-
compile "/js/
|
42
|
+
compile "/js/main/App.tsx" do
|
37
43
|
filter(:webpack, depend_on: ["/js/lib", "/js/components", "/js/hooks"])
|
38
44
|
write("/js/app.js")
|
39
45
|
end
|
40
46
|
```
|
41
47
|
|
42
|
-
|
48
|
+
#### Option: "reject"
|
43
49
|
|
44
50
|
The `depend_on` option can be combined with the `reject` option to exclude
|
45
51
|
certain files or directories from being tracked. For example, maybe you want
|
@@ -48,7 +54,7 @@ to track `/js/lib/` but not `/js/lib/foo/`:
|
|
48
54
|
```ruby
|
49
55
|
# Rules
|
50
56
|
require "nanoc-webpack"
|
51
|
-
compile "/js/
|
57
|
+
compile "/js/main/App.tsx" do
|
52
58
|
filter :webpack,
|
53
59
|
depend_on: ["/js/lib", "/js/components", "/js/hooks"],
|
54
60
|
reject: proc { |path| path.start_with?("/js/lib/foo/") }
|
@@ -56,16 +62,20 @@ compile "/js/ReactApp.jsx" do
|
|
56
62
|
end
|
57
63
|
```
|
58
64
|
|
59
|
-
|
65
|
+
#### Option: "args"
|
60
66
|
|
61
67
|
The `args` option can be used to forward command-line options directly
|
62
|
-
to the webpack executable.
|
63
|
-
|
68
|
+
to the webpack executable.
|
69
|
+
<br>
|
70
|
+
`$ webpack build --help verbose` provides a list of all available options,
|
71
|
+
and
|
72
|
+
[Nanoc::Webpack.default_options](https://0x1eef.github.io/x/nanoc-webpack.rb/Nanoc/Webpack.html#default_options-class_method)
|
73
|
+
returns the default options nanoc-webpack.rb will forward to webpack:
|
64
74
|
|
65
75
|
```ruby
|
66
76
|
# Rules
|
67
77
|
require "nanoc-webpack"
|
68
|
-
compile "/js/
|
78
|
+
compile "/js/main/App.tsx" do
|
69
79
|
filter :webpack, args: {"--no-stats" => true}
|
70
80
|
write("/js/app.js")
|
71
81
|
end
|
@@ -77,8 +87,6 @@ end
|
|
77
87
|
nanoc-webpack.rb assumes that:
|
78
88
|
|
79
89
|
* A "node" executable is available in $PATH.
|
80
|
-
* [npm](https://www.npmjs.com) or [yarn](https://yarnpkg.com/) are used for
|
81
|
-
package management.
|
82
90
|
* "webpack" / "webpack-cli" exist as dependencies in package.json.
|
83
91
|
|
84
92
|
## Sources
|
@@ -98,7 +106,7 @@ are available as sources.
|
|
98
106
|
|
99
107
|
```ruby
|
100
108
|
# Gemfile
|
101
|
-
gem "nanoc-webpack.rb", github: "0x1eef/nanoc-webpack.rb", tag: "v0.5.
|
109
|
+
gem "nanoc-webpack.rb", github: "0x1eef/nanoc-webpack.rb", tag: "v0.5.6"
|
102
110
|
```
|
103
111
|
|
104
112
|
**Rubygems.org**
|
data/lib/nanoc/webpack/filter.rb
CHANGED
@@ -12,18 +12,23 @@ class Nanoc::Webpack::Filter < Nanoc::Filter
|
|
12
12
|
type :text
|
13
13
|
|
14
14
|
##
|
15
|
+
# @example
|
16
|
+
# Nanoc::Webpack.default_options.merge!(
|
17
|
+
# "--cache-type" => "memory"
|
18
|
+
# )
|
19
|
+
#
|
15
20
|
# @return [Hash]
|
16
|
-
# Returns the default command-line options given
|
17
|
-
# to the webpack executable.
|
21
|
+
# Returns the default command-line options given to webpack.
|
18
22
|
def self.default_options
|
19
|
-
@default_options ||= {}
|
23
|
+
@default_options ||= {"--cache-type" => "filesystem"}
|
20
24
|
end
|
21
25
|
|
22
26
|
def run(content, options = {})
|
27
|
+
args = options[:args] || options["args"] || {}
|
23
28
|
depend_on dependable(paths: options[:depend_on], reject: options[:reject])
|
24
29
|
.map { items[_1] }
|
25
30
|
webpack temporary_file_for(content),
|
26
|
-
args: self.class.default_options.merge(
|
31
|
+
args: self.class.default_options.merge(args)
|
27
32
|
end
|
28
33
|
|
29
34
|
private
|
@@ -57,7 +62,7 @@ class Nanoc::Webpack::Filter < Nanoc::Filter
|
|
57
62
|
def temporary_file_for(content)
|
58
63
|
dir = File.join(Dir.getwd, "tmp", "nanoc-webpack.rb")
|
59
64
|
mkdir_p(dir) unless Dir.exist?(dir)
|
60
|
-
file = Tempfile.new(File.basename(item.identifier.to_s), dir)
|
65
|
+
file = Tempfile.new(File.basename(@item.identifier.to_s), dir)
|
61
66
|
file.write(content)
|
62
67
|
file.tap(&:flush)
|
63
68
|
end
|
data/lib/nanoc/webpack.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "nanoc"
|
4
|
-
require "ryo"
|
5
4
|
module Nanoc::Webpack
|
5
|
+
require "ryo"
|
6
6
|
require_relative "webpack/filter"
|
7
|
+
##
|
8
|
+
# @example (see Nanoc::Webpack::Filter.default_options)
|
9
|
+
# @return (see Nanoc::Webpack::Filter.default_options)
|
10
|
+
def self.default_options
|
11
|
+
Nanoc::Webpack::Filter.default_options
|
12
|
+
end
|
7
13
|
end
|
data/spec/filter_spec.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "setup"
|
4
|
+
RSpec.describe Nanoc::Webpack::Filter do
|
5
|
+
let(:paths) { ["/1", "/1/1.txt", "/1/2", "/1/2/1.txt"] }
|
6
|
+
let(:root) { File.join("spec", "fakefs", "content") }
|
7
|
+
let(:reject) { nil }
|
8
|
+
let(:item) do
|
9
|
+
Ryo.from(
|
10
|
+
identifier: {to_s: "test.ts"},
|
11
|
+
attributes: {content_filename: "test.ts"}
|
12
|
+
)
|
13
|
+
end
|
14
|
+
let(:items) do
|
15
|
+
paths.each_with_object({}) { _2[_1] = _1 }
|
16
|
+
end
|
17
|
+
let(:config) do
|
18
|
+
Ryo.from(
|
19
|
+
each: {to_h: {data_sources: [{content_dir: root}]}},
|
20
|
+
data_sources: [{content_dir: root}]
|
21
|
+
)
|
22
|
+
end
|
23
|
+
let(:filter) do
|
24
|
+
Nanoc::Filter
|
25
|
+
.named!(:webpack)
|
26
|
+
.new(item:, items:, config:)
|
27
|
+
end
|
28
|
+
include FileUtils
|
29
|
+
|
30
|
+
context "when given dependables" do
|
31
|
+
subject { filter.dependable(paths: target, reject:) }
|
32
|
+
|
33
|
+
before do
|
34
|
+
mkdir_p(root)
|
35
|
+
paths.each do
|
36
|
+
path = File.join(root, _1)
|
37
|
+
File.extname(path).empty? ? mkdir_p(path) : touch(path)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
after { rm_rf(root) }
|
42
|
+
|
43
|
+
context "when the directory depth is 2" do
|
44
|
+
context "when given /1 as a path" do
|
45
|
+
let(:target) { "/1" }
|
46
|
+
it { is_expected.to contain_exactly("/1/1.txt", "/1/2/1.txt") }
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when given /1/2 as a path" do
|
50
|
+
let(:target) { "/1/2" }
|
51
|
+
it { is_expected.to contain_exactly("/1/2/1.txt") }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "when the directory depth is 5" do
|
56
|
+
let(:paths) { super().concat(["/1/2/3/4/5", "/1/2/3/4/5/1.txt"]) }
|
57
|
+
|
58
|
+
context "when given /1 as a path" do
|
59
|
+
let(:target) { "/1" }
|
60
|
+
it do
|
61
|
+
is_expected.to contain_exactly(
|
62
|
+
"/1/1.txt",
|
63
|
+
"/1/2/1.txt",
|
64
|
+
"/1/2/3/4/5/1.txt"
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "when given /1/2 as a path" do
|
70
|
+
let(:target) { "/1/2" }
|
71
|
+
it { is_expected.to contain_exactly("/1/2/1.txt", "/1/2/3/4/5/1.txt") }
|
72
|
+
end
|
73
|
+
|
74
|
+
context "when given /1/2/3 as a path" do
|
75
|
+
let(:target) { "/1/2/3" }
|
76
|
+
it { is_expected.to contain_exactly("/1/2/3/4/5/1.txt") }
|
77
|
+
end
|
78
|
+
|
79
|
+
context "when depth 5 has descendant directories" do
|
80
|
+
let(:paths) do
|
81
|
+
super().concat([
|
82
|
+
"/1/2/3/4/5/a", "/1/2/3/4/5/a/a.txt",
|
83
|
+
"/1/2/3/4/5/b", "/1/2/3/4/5/b/b.txt",
|
84
|
+
"/1/2/3/4/5/c", "/1/2/3/4/5/c/c.txt"
|
85
|
+
])
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when given /1 as a path" do
|
89
|
+
let(:target) { "/1" }
|
90
|
+
it do
|
91
|
+
is_expected.to contain_exactly(
|
92
|
+
"/1/1.txt", "/1/2/1.txt", "/1/2/3/4/5/1.txt",
|
93
|
+
"/1/2/3/4/5/a/a.txt", "/1/2/3/4/5/b/b.txt",
|
94
|
+
"/1/2/3/4/5/c/c.txt"
|
95
|
+
)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "when one or more directories are excluded" do
|
102
|
+
let(:paths) { super().concat(["/2/3", "/2/3/1.txt", "/3/4", "/3/4/1.txt"]) }
|
103
|
+
|
104
|
+
context "when the target is [!12]" do
|
105
|
+
let(:target) { "/[!12]/" }
|
106
|
+
it { is_expected.to contain_exactly("/3/4/1.txt") }
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when the reject filter is used" do
|
110
|
+
let(:paths) do
|
111
|
+
["/lib/WebPackage/", "/lib/WebPackage/foo.ts",
|
112
|
+
"/lib/Web/", "/lib/Web/foo.ts",
|
113
|
+
"/lib/foo/", "/lib/foo/foo.ts"]
|
114
|
+
end
|
115
|
+
let(:target) { "/lib/" }
|
116
|
+
let(:reject) { proc { |path| path.include?("WebPackage") } }
|
117
|
+
|
118
|
+
it do
|
119
|
+
is_expected.to contain_exactly("/lib/Web/foo.ts", "/lib/foo/foo.ts")
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when nodejs is executed" do
|
126
|
+
let(:cmdline) do
|
127
|
+
[
|
128
|
+
"node",
|
129
|
+
"./node_modules/webpack/bin/webpack.js",
|
130
|
+
"--entry", File.join(Dir.getwd, "test.ts"),
|
131
|
+
"--output-path", instance_of(String),
|
132
|
+
"--output-filename", instance_of(String),
|
133
|
+
"--cache-type", "filesystem"
|
134
|
+
]
|
135
|
+
end
|
136
|
+
|
137
|
+
context "with default arguments" do
|
138
|
+
it "executes nodejs" do
|
139
|
+
expect(filter).to receive(:system).with(*cmdline)
|
140
|
+
filter.run(item)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "with --no-cache" do
|
145
|
+
let(:cmdline) { super().concat(["--no-cache"]) }
|
146
|
+
|
147
|
+
it "executes nodejs with an argument" do
|
148
|
+
expect(filter).to receive(:system).with(*cmdline)
|
149
|
+
filter.run(item, args: {"--no-cache" => true})
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
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.5.
|
4
|
+
version: 0.5.6
|
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-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ryo.rb
|
@@ -116,7 +116,7 @@ files:
|
|
116
116
|
- lib/nanoc/webpack/filter/dependable.rb
|
117
117
|
- lib/nanoc/webpack/version.rb
|
118
118
|
- nanoc-webpack.rb.gemspec
|
119
|
-
- spec/
|
119
|
+
- spec/filter_spec.rb
|
120
120
|
- spec/setup.rb
|
121
121
|
homepage: https://github.com/0x1eef/nanoc-webpack.rb#readme
|
122
122
|
licenses:
|
data/spec/dependable_spec.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "setup"
|
4
|
-
|
5
|
-
RSpec.describe Nanoc::Webpack::Filter::Dependable do
|
6
|
-
subject { filter.dependable(paths: target, reject:) }
|
7
|
-
let(:paths) { ["/1", "/1/1.txt", "/1/2", "/1/2/1.txt"] }
|
8
|
-
let(:root) { File.join("spec", "fakefs", "content") }
|
9
|
-
let(:reject) { nil }
|
10
|
-
let(:filter) do
|
11
|
-
Object.new.instance_exec(root, paths) do |root, paths|
|
12
|
-
extend Nanoc::Webpack::Filter::Dependable
|
13
|
-
define_singleton_method(:items) { paths.each_with_object({}) { _2[_1] = _1 } }
|
14
|
-
define_singleton_method(:root) { root }
|
15
|
-
self
|
16
|
-
end
|
17
|
-
end
|
18
|
-
include FileUtils
|
19
|
-
|
20
|
-
before do
|
21
|
-
mkdir_p(root)
|
22
|
-
paths.each do
|
23
|
-
path = File.join(root, _1)
|
24
|
-
File.extname(path).empty? ? mkdir_p(path) : touch(path)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
after { rm_rf(root) }
|
29
|
-
|
30
|
-
context "when the directory depth is 2" do
|
31
|
-
context "when given /1 as a path" do
|
32
|
-
let(:target) { "/1" }
|
33
|
-
it { is_expected.to contain_exactly("/1/1.txt", "/1/2/1.txt") }
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when given /1/2 as a path" do
|
37
|
-
let(:target) { "/1/2" }
|
38
|
-
it { is_expected.to contain_exactly("/1/2/1.txt") }
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when the directory depth is 5" do
|
43
|
-
let(:paths) { super().concat(["/1/2/3/4/5", "/1/2/3/4/5/1.txt"]) }
|
44
|
-
|
45
|
-
context "when given /1 as a path" do
|
46
|
-
let(:target) { "/1" }
|
47
|
-
it do
|
48
|
-
is_expected.to contain_exactly(
|
49
|
-
"/1/1.txt",
|
50
|
-
"/1/2/1.txt",
|
51
|
-
"/1/2/3/4/5/1.txt"
|
52
|
-
)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when given /1/2 as a path" do
|
57
|
-
let(:target) { "/1/2" }
|
58
|
-
it { is_expected.to contain_exactly("/1/2/1.txt", "/1/2/3/4/5/1.txt") }
|
59
|
-
end
|
60
|
-
|
61
|
-
context "when given /1/2/3 as a path" do
|
62
|
-
let(:target) { "/1/2/3" }
|
63
|
-
it { is_expected.to contain_exactly("/1/2/3/4/5/1.txt") }
|
64
|
-
end
|
65
|
-
|
66
|
-
context "when depth 5 has descendant directories" do
|
67
|
-
let(:paths) do
|
68
|
-
super().concat([
|
69
|
-
"/1/2/3/4/5/a", "/1/2/3/4/5/a/a.txt",
|
70
|
-
"/1/2/3/4/5/b", "/1/2/3/4/5/b/b.txt",
|
71
|
-
"/1/2/3/4/5/c", "/1/2/3/4/5/c/c.txt"
|
72
|
-
])
|
73
|
-
end
|
74
|
-
|
75
|
-
context "when given /1 as a path" do
|
76
|
-
let(:target) { "/1" }
|
77
|
-
it do
|
78
|
-
is_expected.to contain_exactly(
|
79
|
-
"/1/1.txt", "/1/2/1.txt", "/1/2/3/4/5/1.txt",
|
80
|
-
"/1/2/3/4/5/a/a.txt", "/1/2/3/4/5/b/b.txt",
|
81
|
-
"/1/2/3/4/5/c/c.txt"
|
82
|
-
)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "when one or more directories are excluded" do
|
89
|
-
let(:paths) { super().concat(["/2/3", "/2/3/1.txt", "/3/4", "/3/4/1.txt"]) }
|
90
|
-
|
91
|
-
context "when the target is [!12]" do
|
92
|
-
let(:target) { "/[!12]/" }
|
93
|
-
it { is_expected.to contain_exactly("/3/4/1.txt") }
|
94
|
-
end
|
95
|
-
|
96
|
-
context "when the reject filter is used" do
|
97
|
-
let(:paths) do
|
98
|
-
["/lib/WebPackage/", "/lib/WebPackage/foo.ts",
|
99
|
-
"/lib/Web/", "/lib/Web/foo.ts",
|
100
|
-
"/lib/foo/", "/lib/foo/foo.ts"]
|
101
|
-
end
|
102
|
-
let(:target) { "/lib/" }
|
103
|
-
let(:reject) { proc { |path| path.include?("WebPackage") } }
|
104
|
-
|
105
|
-
it do
|
106
|
-
is_expected.to contain_exactly("/lib/Web/foo.ts", "/lib/foo/foo.ts")
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|