nanoc-webpack.rb 0.10.1 → 0.10.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: 55ecfe50fc13e62efba068b1422e9d7887412d06b5dbf2e9fff646beeb426629
4
- data.tar.gz: 54382ce368c006c717c26b95e920e43fb7e348458eb8dc09593f001264e1cd22
3
+ metadata.gz: c939a1fe4e2fb2f767e80b0fdac38ff132c5beff92aeb46d3019d2b4e5ec12da
4
+ data.tar.gz: 20b1ef0e1a025de9088dd99bc8047346b51d2f4fcf09fa203b5379c858ca28d4
5
5
  SHA512:
6
- metadata.gz: 5e375aab35f0f9950729471a4558a228eeafda58866c1cc258e8a032d91b098e44261d2198b9b01464796697f0990d46b69caf59656601170e8285c357f4721a
7
- data.tar.gz: e5d4aaf5f4da55489c8d6e7ff4eaabe05c4b2be33037dc16958824decff84a19eb749e17878d186a0715ba6dd1ad26a20261fadb9fd781d2cbea97ff7c054837
6
+ metadata.gz: d3a31c40abbe1052cd4bdc36ecc11cbefc784b7f97c9733e959837dbe6f88d435b106efccd7337c31ebfa6db06c49e97e23ffc2b6129440081f1ae15f9e581bb
7
+ data.tar.gz: ce8807fca6f33918d61af7a5df0c1dc0065b51121bf1913d7b60a9be7811b46e4cbf4c6c8267be0ae1d638ec164340c906b22c8303d8d8ecfeaf3247e0ae7e86
data/README.md CHANGED
@@ -58,10 +58,10 @@ end
58
58
 
59
59
  **Option: argv**
60
60
 
61
- The `argv` option forwards command-line options directly
61
+ The `argv` option forwards command line arguments directly
62
62
  to the webpack executable. <br>
63
63
  [Nanoc::Webpack.default_argv](https://0x1eef.github.io/x/nanoc-webpack.rb/Nanoc/Webpack.html#default_argv-class_method)
64
- returns the default command-line options forwarded to webpack:
64
+ returns the default command line arguments forwarded to webpack:
65
65
 
66
66
  ```ruby
67
67
  # Rules
@@ -76,10 +76,15 @@ end
76
76
 
77
77
  **Rubygems.org**
78
78
 
79
- nanoc-webpack.rb can be installed via rubygems.org.
79
+ nanoc-webpack.rb can be installed via rubygems.org
80
80
 
81
81
  gem install nanoc-webpack.rb
82
82
 
83
+ ## See also
84
+
85
+ * [0x1eef/terry.reflectslight.io](https://github.com/0x1eef/terry.reflectslight.io) <br>
86
+ A simple nanoc application that uses nanoc-webpack.rb
87
+
83
88
  ## Sources
84
89
 
85
90
  * [GitHub](https://github.com/0x1eef/nanoc-webpack.rb#readme)
@@ -14,26 +14,28 @@ module Nanoc::Webpack
14
14
  type :text
15
15
 
16
16
  ##
17
+ # The default argv for webpack
18
+ #
17
19
  # @example
18
20
  # Nanoc::Webpack.default_argv.concat ["--cache-type", "filesystem"]
19
21
  #
20
22
  # @return [Array<String>]
21
- # The default command-line options forwarded to webpack.
23
+ # Default argv for webpack
22
24
  def self.default_argv
23
25
  @default_argv ||= []
24
26
  end
25
27
 
26
28
  ##
27
29
  # @param [String] content
28
- # The contents of a file.
30
+ # The contents of a file
29
31
  #
30
32
  # @param [Hash] options
31
- # A hash of options.
33
+ # A hash of options
32
34
  #
33
35
  # @return [void]
34
36
  def run(content, options = {})
35
37
  options = Ryo.from(options)
36
- path = temporary_file(content).path
38
+ file = temporary_file(content)
37
39
  depend_on dependable(paths: options.depend_on, reject: options.reject)
38
40
  .map { items[_1] }
39
41
  argv = [*(options.argv || []), *default_argv]
@@ -42,12 +44,11 @@ module Nanoc::Webpack
42
44
  ["./node_modules/webpack/bin/webpack.js",
43
45
  *argv,
44
46
  "--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
45
- "--output-path", File.dirname(path),
46
- "--output-filename", File.basename(path)],
47
- log: File.join(tmpdir, "webpack.log")
48
- File.read(path)
47
+ "--output-path", File.dirname(file.path),
48
+ "--output-filename", File.basename(file.path)]
49
+ File.read(file.path)
49
50
  ensure
50
- rm(path)
51
+ file ? file.tap(&:unlink).close : nil
51
52
  end
52
53
 
53
54
  private
@@ -57,20 +58,16 @@ module Nanoc::Webpack
57
58
  end
58
59
 
59
60
  def temporary_file(content)
60
- mkdir_p(tmpdir)
61
+ tmpdir = File.join(Dir.getwd, "tmp", "webpack")
61
62
  name = item.identifier.to_s
62
63
  file = Tempfile.new(
63
64
  [ File.basename(name), File.extname(name).sub(/\A\.(ts|tsx|jsx)\z/, '.js') ],
64
- tmpdir
65
+ mkdir_p(tmpdir).last
65
66
  )
66
67
  file.write(content)
67
68
  file.tap(&:flush)
68
69
  end
69
70
 
70
- def tmpdir
71
- File.join(Dir.getwd, "tmp", "webpack")
72
- end
73
-
74
71
  def scan(argv)
75
72
  options = argv.filter_map { _1.start_with?("-") ? _1 : nil }
76
73
  builtins = %w[--entry --output-path --output-filename]
@@ -1,17 +1,30 @@
1
1
  module Nanoc::Webpack
2
2
  module Spawn
3
+ require "test-cmd"
3
4
  Error = Class.new(RuntimeError)
4
- def spawn(exe, argv, log:)
5
- Kernel.spawn(
6
- exe, *argv, { STDOUT => log, STDERR => log }
7
- )
8
- Process.wait
9
- unless $?.success?
5
+
6
+ ##
7
+ # Spawns a process
8
+ #
9
+ # @param [String] exe
10
+ # The path to an executable
11
+ #
12
+ # @param [Array<String>] argv
13
+ # An array of command line arguments
14
+ #
15
+ # @return [Integer]
16
+ # Returns the exit code of the spawned process
17
+ def spawn(exe, argv)
18
+ r = cmd(exe, *argv)
19
+ if r.success?
20
+ r.exit_status
21
+ else
10
22
  raise Error,
11
- "#{File.basename(exe)} exited unsuccessfully " \
12
- "(exit code: #{$?.exitstatus}, " \
13
- "item: #{item.identifier}, " \
14
- "log: #{log.gsub(Dir.getwd, '')[1..]})",
23
+ "#{File.basename(exe)} exited unsuccessfully\n" \
24
+ "(item: #{item.identifier})\n" \
25
+ "(exit code: #{r.exit_status})\n" \
26
+ "(stdout: #{r.stdout.gsub(Dir.getwd, '')[1..]&.chomp})\n" \
27
+ "(stderr: #{r.stderr.gsub(Dir.getwd, '')[1..]&.chomp})\n",
15
28
  []
16
29
  end
17
30
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Webpack
5
- VERSION = "0.10.1"
5
+ VERSION = "0.10.3"
6
6
  end
7
7
  end
@@ -10,9 +10,10 @@ Gem::Specification.new do |gem|
10
10
  gem.licenses = ["0BSD"]
11
11
  gem.files = `git ls-files`.split($/)
12
12
  gem.require_paths = ["lib"]
13
- gem.summary = "nanoc-webpack.rb integrates webpack into nanoc."
13
+ gem.summary = "nanoc-webpack.rb = nanoc + webpack"
14
14
  gem.description = gem.summary
15
15
  gem.add_runtime_dependency "ryo.rb", "~> 0.5"
16
+ gem.add_runtime_dependency "test-cmd.rb", "~> 0.12.2"
16
17
  gem.add_development_dependency "yard", "~> 0.9"
17
18
  gem.add_development_dependency "redcarpet", "~> 3.5"
18
19
  gem.add_development_dependency "rspec", "~> 3.10"
data/spec/filter_spec.rb CHANGED
@@ -127,33 +127,29 @@ RSpec.describe Nanoc::Webpack::Filter do
127
127
  [
128
128
  "--entry", File.join(Dir.getwd, "test.ts"),
129
129
  "--output-path", instance_of(String),
130
- "--output-filename", instance_of(String),
130
+ "--output-filename", instance_of(String)
131
131
  ]
132
132
  end
133
133
 
134
134
  context "with default arguments" do
135
135
  it "executes nodejs" do
136
- expect(Kernel).to receive(:spawn).with(
136
+ expect(filter).to receive(:cmd).with(
137
137
  "node",
138
138
  "./node_modules/webpack/bin/webpack.js",
139
139
  *cmdline,
140
- instance_of(Hash)
141
- )
142
- expect(Process).to receive(:wait)
140
+ ).and_return(Ryo('success?' => true))
143
141
  filter.run(item)
144
142
  end
145
143
  end
146
144
 
147
145
  context "with --no-cache" do
148
146
  it "executes nodejs with an argument" do
149
- expect(Kernel).to receive(:spawn).with(
147
+ expect(filter).to receive(:cmd).with(
150
148
  "node",
151
149
  "./node_modules/webpack/bin/webpack.js",
152
150
  "--no-cache",
153
151
  *cmdline,
154
- instance_of(Hash)
155
- )
156
- expect(Process).to receive(:wait)
152
+ ).and_return(Ryo('success?' => true))
157
153
  filter.run(item, argv: ["--no-cache"])
158
154
  end
159
155
  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.10.1
4
+ version: 0.10.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-25 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ryo.rb
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: test-cmd.rb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.12.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.12.2
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: yard
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +108,7 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '2.11'
97
- description: nanoc-webpack.rb integrates webpack into nanoc.
111
+ description: nanoc-webpack.rb = nanoc + webpack
98
112
  email:
99
113
  - 0x1eef@protonmail.com
100
114
  executables: []
@@ -141,5 +155,5 @@ requirements: []
141
155
  rubygems_version: 3.5.9
142
156
  signing_key:
143
157
  specification_version: 4
144
- summary: nanoc-webpack.rb integrates webpack into nanoc.
158
+ summary: nanoc-webpack.rb = nanoc + webpack
145
159
  test_files: []