Skip to content

Commit bbbda94

Browse files
authored
Merge pull request #12 from joshrlesch/FixYarnOptions
Correctly format options
2 parents 8e1c143 + 0adcb8c commit bbbda94

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

fastlane/Fastfile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1-
lane :test do
2-
yarn
1+
lane :install_packages do
2+
yarn(
3+
command: 'install'
4+
)
5+
end
6+
7+
lane :run_command_with_options do
8+
yarn(
9+
command: 'install',
10+
options: '--cache-folder ~/cache_folder' # Also accepts array of strings
11+
)
12+
end
13+
14+
lane :run_command_with_different_package_path do
15+
yarn(
16+
command: 'install',
17+
package_path: '../package.json'
18+
)
319
end

lib/fastlane/plugin/yarn/helper/yarn_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,21 @@ def initialize(package_path: nil, project_root: nil)
2727
# Run a certain action
2828
def trigger(command: nil, flags: nil, options: nil, print_command: true, print_command_output: true)
2929
unless options == "" || options == [] || options == nil then
30-
option_string = options.respond_to?(:join) ? "-- #{options.join(" ")}" : "-- #{options}"
30+
options = format_options(options)
31+
option_string = options.respond_to?(:join) ? options.join(" ") : options
3132
end
3233
command = [self.yarn, flags, command, option_string].compact.join(" ")
3334
Action.sh(command, print_command: print_command, print_command_output: print_command_output)
3435
end
3536

37+
def format_options(options)
38+
if options.kind_of?(Array)
39+
options.map! { |i| i.include?("--") ? i : "--#{i}" }
40+
else
41+
options.include?("--") ? options : "--#{options}"
42+
end
43+
end
44+
3645
def check_install
3746
check_package
3847
begin
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Fastlane
22
module Yarn
3-
VERSION = "1.1"
3+
VERSION = "1.2"
44
end
55
end

spec/yarn_action_spec.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@
2525
yarn(command: 'test', options: '--fail-fast', package_path: 'spec/fixtures/package.json')
2626
end").runner.execute(:test)
2727

28-
expect(result).to eq("cd spec/fixtures && yarn test -- --fail-fast")
28+
expect(result).to eq("cd spec/fixtures && yarn test --fail-fast")
29+
end
30+
it 'run some script with some option with missing --' do
31+
allow(FastlaneCore::FastlaneFolder).to receive(:path).and_return(nil)
32+
33+
result = Fastlane::FastFile.new.parse("lane :test do
34+
yarn(command: 'test', options: 'fail-fast', package_path: 'spec/fixtures/package.json')
35+
end").runner.execute(:test)
36+
37+
expect(result).to eq("cd spec/fixtures && yarn test --fail-fast")
2938
end
3039
it 'run some script with some option provided as list' do
3140
allow(FastlaneCore::FastlaneFolder).to receive(:path).and_return(nil)
@@ -34,10 +43,18 @@
3443
yarn(command: 'test', options: ['--fail-fast', 'please'], package_path: 'spec/fixtures/package.json')
3544
end").runner.execute(:test)
3645

37-
expect(result).to eq("cd spec/fixtures && yarn test -- --fail-fast please")
46+
expect(result).to eq("cd spec/fixtures && yarn test --fail-fast --please")
3847
end
39-
it 'fail if package_path and project root are both provided' do
48+
it 'run some script with some option provided as list, one with param value' do
49+
allow(FastlaneCore::FastlaneFolder).to receive(:path).and_return(nil)
50+
51+
result = Fastlane::FastFile.new.parse("lane :test do
52+
yarn(command: 'test', options: ['--fail-fast please', '--verbose'], package_path: 'spec/fixtures/package.json')
53+
end").runner.execute(:test)
4054

55+
expect(result).to eq("cd spec/fixtures && yarn test --fail-fast please --verbose")
56+
end
57+
it 'fail if package_path and project root are both provided' do
4158
expect {
4259
Fastlane::FastFile.new.parse("lane :boom do
4360
yarn(command: 'test', package_path: 'spec/fixtures/package.json', project_root:'racine')

0 commit comments

Comments
 (0)