squared 0.6.2 → 0.6.3

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.
@@ -6,20 +6,22 @@ module Squared
6
6
  class Node < Git
7
7
  OPT_NPM = {
8
8
  common: %w[dry-run=!? loglevel=b include-workspace-root=!? workspaces=!? w|workspace=v].freeze,
9
- install: %w[package-lock-only=!? prefer-dedupe=!? cpu=b libc=b os=b].freeze,
10
- install_a: %w[audit=! bin-links=! fund=! ignore-scripts=!? install-links=!? package-lock=! strict-peer-deps=!?
11
- include=b install-strategy=b omit=b].freeze,
12
- install_b: %w[no-save save-bundle save-dev save-optional save-peer save-prod before=q foreground-scripts=!?
13
- g|global=!? S|save=!? E|save-exact=!?].freeze,
9
+ install: %w[package-lock-only=!? prefer-dedupe=!? E|save-exact=!? before=q cpu=b libc=b os=b].freeze,
10
+ install_a: %w[audit=! bin-links=! foreground-scripts=!? fund=! ignore-scripts=!? install-links=!?
11
+ package-lock=! strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
12
+ install_b: %w[no-save B|save-bundle D|save-dev O|save-optional save-peer P|save-prod g|global=!?
13
+ S|save=!?].freeze,
14
14
  run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].freeze,
15
15
  exec: %w[c|call=q package=b].freeze,
16
16
  pack: %w[ignore-scripts=!? json=!? pack-destination=p].freeze,
17
+ rebuild: %w[bin-links=! foreground-scripts=!? global=!? ignore-scripts=!? install-links=!?].freeze,
17
18
  no: {
18
19
  install: %w[audit bin-links fund package-lock].freeze
19
20
  }.freeze
20
21
  }.freeze
21
22
  OPT_PNPM = {
22
- common: %w[aggregate-output color no-color stream use-stderr C|dir=p loglevel=b w|workspace-root].freeze,
23
+ common: %w[aggregate-output color ignore-workspace-root-check no-color stream use-stderr C|dir=p loglevel=b
24
+ r|recursive w|workspace-root].freeze,
23
25
  common_cpu: %w[cpu=b libc=b os=b].freeze,
24
26
  common_filter: %w[fail-if-no-match changed-files-ignore-pattern=q filter=q filter-prod=q
25
27
  test-pattern=q].freeze,
@@ -30,15 +32,18 @@ module Squared
30
32
  modules-dir=p network-concurrency=i package-import-method=b public-hoist-pattern=q
31
33
  reporter=b].freeze,
32
34
  install_a: %w[global-dir ignore-scripts offline prefer-offline store-dir=p virtual-store-dir=p].freeze,
33
- install_b: %w[D|dev global-dir no-optional P|prod r|recursive].freeze,
35
+ install_b: %w[D|dev no-optional P|prod].freeze,
36
+ add: %w[allow-build config g|global save-catalog D|save-dev O|save-optional save-peer P|save-prod
37
+ save-catalog-name=b].freeze,
34
38
  update: %w[g|global i|interactive L|latest depth=i].freeze,
35
39
  dedupe: %w[check].freeze,
36
- run: %w[if-present no-bail parallel r|recursive report-summary reporter-hide-prefix resume-from
37
- sequential].freeze,
38
- exec: %w[no-reporter-hide-prefix parallel r|recursive report-summary resume-from c|shell-mode].freeze,
39
- pack: %w[json r|recursive pack-destination=p pack-gzip-level=i out=p workspace-concurrency=i].freeze,
40
+ run: %w[if-present no-bail parallel report-summary reporter-hide-prefix resume-from sequential].freeze,
41
+ exec: %w[no-reporter-hide-prefix parallel report-summary resume-from c|shell-mode].freeze,
42
+ pack: %w[json pack-destination=p pack-gzip-level=i out=p workspace-concurrency=i].freeze,
43
+ rebuild: %w[filter=q].freeze,
40
44
  no: {
41
- install: %w[frozen-lockfile verify-store-integrity].freeze
45
+ install: %w[frozen-lockfile verify-store-integrity].freeze,
46
+ add: %w[save-exact save-workspace-protocol].freeze
42
47
  }.freeze
43
48
  }.freeze
44
49
  OPT_YARN = {
@@ -50,13 +55,16 @@ module Squared
50
55
  network-timeout=i preferred-cache-folder=p production=b? proxy=q otp=b registry=q update-checksums
51
56
  use-yarnrc=p].freeze,
52
57
  install: %w[A|audit g|global S|save D|save-dev E|save-exact P|save-peer O|save-optional T|save-tilde].freeze,
58
+ add: %w[A|audit D|dev E|exact O|optional P|peer T|tilde ignore-workspace-root-check].freeze,
53
59
  update: %w[A|audit C|caret E|exact L|latest T|tilde P|pattern=q S|scope=b].freeze,
54
60
  run: %w[scripts-prepend-node-path=b?].freeze
55
61
  }.freeze
56
62
  OPT_BERRY = {
57
63
  install: %w[check-cache check-resolutions immutable immutable-cache inline-builds json refresh-lockfile
58
64
  mode=b].freeze,
59
- update: %w[C|caret E|exact F|fixed interactive T|tilde R|recursive mode=b].freeze,
65
+ add: %w[cached D|dev json O|optional P|peer prefer-dev].freeze,
66
+ add_a: %w[C|caret E|exact F|fixed interactive T|tilde mode=b].freeze,
67
+ update: %w[R|recursive].freeze,
60
68
  dedupe: %w[check json mode=b strategy=b].freeze,
61
69
  run: %w[B|binaries-only inspect inspect-brk T|top-level require=q].freeze,
62
70
  pack: %w[n|dry-run install-if-needed json o|out=p].freeze
@@ -128,7 +136,7 @@ module Squared
128
136
  end
129
137
 
130
138
  subtasks({
131
- 'package' => %i[install reinstall dedupe update].freeze,
139
+ 'package' => %i[install add update dedupe rebuild reinstall].freeze,
132
140
  'outdated' => %i[major minor patch].freeze,
133
141
  'bump' => %i[version major minor patch].freeze,
134
142
  'publish' => %i[latest tag].freeze,
@@ -170,18 +178,17 @@ module Squared
170
178
  if flags.nil?
171
179
  case action
172
180
  when 'add'
173
- format_desc action, nil, 'save?=prod|dev|optional|peer,name+'
181
+ format_desc action, nil, 'save?=[=-]prod|dev|optional|peer|bundle,(-)name+'
174
182
  task action, [:save] do |_, args|
175
- packages = if args.save =~ /\A(=)?(prod|dev|optional|peer)\z/
176
- exact = !$1.nil?
177
- save = $2
183
+ packages = if args.save =~ /\A([=-]*)?(prod|dev|optional|peer|bundle)\z/
184
+ save = [$2, $1.include?('='), $1.include?('-')]
178
185
  args.extras
179
186
  else
180
187
  save = 'prod'
181
188
  args.to_a
182
189
  end
183
190
  param_guard(action, 'name', args: packages)
184
- depend(:add, packages: packages, save: save, exact: exact)
191
+ depend(:add, packages: packages, save: save)
185
192
  end
186
193
  when 'run'
187
194
  next if scripts.empty?
@@ -279,7 +286,7 @@ module Squared
279
286
  end
280
287
  when 'package'
281
288
  format_desc(action, flag, 'opts*', before: case flag
282
- when :dedupe then nil
289
+ when :dedupe, :rebuild then nil
283
290
  when :reinstall then 'force?'
284
291
  else 'name*'
285
292
  end)
@@ -368,7 +375,7 @@ module Squared
368
375
  return if items.empty?
369
376
 
370
377
  on :first, :copy
371
- print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/)
378
+ print_item unless @output[0] || silent? || task_invoked?(/^copy(?::#{Node.ref}|$)/)
372
379
  packed = false
373
380
  items.each do |dir|
374
381
  case dir
@@ -417,8 +424,7 @@ module Squared
417
424
  .scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
418
425
  .map { |item| Pathname.new(item.first) }
419
426
  .select(&:exist?)
420
- end
421
- .concat(Array(files))
427
+ end.concat(Array(files))
422
428
  packed = true
423
429
  end
424
430
  base = dest.join(into, npmname)
@@ -433,7 +439,7 @@ module Squared
433
439
  target.mkpath
434
440
  subdir << target.to_s
435
441
  end
436
- FileUtils.cp(basepath(s), dest, verbose: verbosetype > 0)
442
+ FileUtils.cp(basepath(s), dest, verbose: !silent?)
437
443
  rescue StandardError => e
438
444
  print_error e
439
445
  errors += 1
@@ -441,7 +447,7 @@ module Squared
441
447
  rescue StandardError => e
442
448
  on_error e, :copy
443
449
  else
444
- puts message(base, subdir.size, files.size - errors) if verbose
450
+ puts message(base, subdir.size, files.size - errors) unless silent?
445
451
  end
446
452
  next
447
453
  end
@@ -474,7 +480,7 @@ module Squared
474
480
  end
475
481
  target.each do |src, to|
476
482
  glob.each { |val| log.info "cp #{from + val} #{to}" }
477
- copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbosetype > 0)
483
+ copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: !silent?)
478
484
  rescue StandardError => e
479
485
  on_error e, :copy
480
486
  end
@@ -482,45 +488,81 @@ module Squared
482
488
  on :last, :copy
483
489
  end
484
490
 
485
- def depend(flag = nil, *, sync: invoked_sync?('depend', flag), packages: [], save: nil, exact: nil, **)
491
+ def depend(flag = nil, *, sync: invoked_sync?('depend', flag), packages: [], save: nil, exact: nil,
492
+ omit: env('NPM_OMIT'), **)
486
493
  if @depend && !flag
487
494
  super
488
495
  elsif outdated?
489
496
  workspace.rev_clear(name, sync: sync)
490
497
  return update if !flag && env('NODE_UPDATE')
491
498
 
499
+ add = flag == :add
500
+ if add
501
+ remove, packages = packages.partition { |val| val.delete_prefix!('-') }
502
+ remove.map! { |pkg| shell_quote(pkg) }
503
+ end
504
+ save, exact, omit = save if save.is_a?(Array)
492
505
  ws = env('NODE_WORKSPACES', equals: '0')
493
- ci = option('ci')
506
+ ci = -> { option('ci') }
507
+ is = -> { option('ignore-scripts') }
508
+ om = lambda do
509
+ next unless omit
510
+
511
+ save = case save
512
+ when 'peer'
513
+ 'optional'
514
+ when 'optional'
515
+ 'dev'
516
+ when 'dev'
517
+ 'prod'
518
+ end
519
+ end
520
+ rm = lambda do |target|
521
+ next if remove.empty?
522
+
523
+ run(target.temp(*remove).sub!(/ (?:add|install) /, ' remove '), from: :remove, sync: sync)
524
+ end
494
525
  if (yarn = dependtype(:yarn)) > 0
495
- cmd = session 'yarn'
496
- if flag == :add
497
- cmd << 'add'
498
- cmd << "--#{save}" unless save == 'prod'
499
- cmd << '--exact' if exact
526
+ cmd = session('yarn', flag || 'install')
527
+ append_loglevel
528
+ if yarn == 1
529
+ cmd << '--ignore-engines' unless option('ignore-engines', equals: '0')
530
+ cmd << '--ignore-scripts' if is.call
531
+ cmd << '--force' if option('force')
500
532
  else
501
- cmd << 'install'
502
- cmd << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0')
503
- cmd << (yarn == 1 ? '--force' : '--check-cache') if option('force')
533
+ cmd << '--mode=skip-build' if is.call
534
+ cmd << '--check-cache' if !flag && option('force')
504
535
  end
505
536
  if nolockfile?('yarn')
506
537
  cmd << '--no-lockfile'
507
- elsif ci
538
+ elsif ci.call
508
539
  if yarn == 1
509
540
  cmd << '--frozen-lockfile'
510
- else
541
+ elsif !flag
511
542
  cmd << '--immutable' << '--refresh-lockfile'
512
543
  end
513
544
  end
545
+ if add
546
+ cmd << '-W' if yarn == 1 && !option('w', 'ignore-workspace-root-check', equals: '0')
547
+ rm.call(cmd)
548
+ om.call
549
+ cmd << "--#{save}" if save && save != 'bundle'
550
+ cmd << '--exact' if exact
551
+ end
514
552
  elsif pnpm?
515
- cmd = session 'pnpm'
516
- if flag == :add
517
- cmd << 'add' << "--save-#{save}"
553
+ cmd = session('pnpm', flag || 'install')
554
+ append_nocolor
555
+ append_loglevel
556
+ if add
557
+ om.call
558
+ cmd << "--save-#{save}" if save && save != 'bundle'
559
+ rm.call(cmd)
518
560
  cmd << '--save-exact' if exact
561
+ option('allow-build') { |val| cmd << quote_option('allow-build', val) }
519
562
  else
520
- cmd << 'install'
521
563
  append_platform
522
564
  end
523
- option('public-hoist-pattern', ignore: false) do |val|
565
+ option('public-hoist-pattern') do |val|
524
566
  split_escape(val) { |opt| cmd << shell_option('public-hoist-pattern', opt) }
525
567
  end
526
568
  cmd << '--ignore-workspace' if ws
@@ -528,30 +570,37 @@ module Squared
528
570
  '--force'
529
571
  elsif nolockfile?('pnpm')
530
572
  '--no-lockfile'
531
- elsif ci
573
+ elsif ci.call
532
574
  '--frozen-lockfile'
533
575
  end
534
- append_nocolor
576
+ cmd << '--ignore-scripts' if is.call
535
577
  else
536
- cmd = session 'npm'
537
- if ci
538
- cmd << 'ci'
539
- else
540
- cmd << 'install'
541
- if flag == :add
542
- cmd << "--save-#{save}"
578
+ cmd = session('npm', (ci = ci.call) ? 'ci' : 'install')
579
+ cmd << '--workspaces=false' if ws
580
+ append_nocolor
581
+ append_loglevel
582
+ if omit
583
+ cmd << "--omit=#{save}"
584
+ save = nil
585
+ end
586
+ unless ci
587
+ if add
588
+ cmd << "--save-#{save}" if save
589
+ rm.call(cmd)
543
590
  cmd << '--save-exact' if exact
544
- cmd.merge(packages.map { |pkg| shell_quote(pkg) })
545
591
  else
546
592
  append_platform
547
593
  end
548
594
  end
549
- cmd << '--workspaces=false' if ws
550
595
  cmd << '--package-lock=false' << 'save=false' if nolockfile?('npm')
551
- append_nocolor
596
+ cmd << '--ignore-scripts' if is.call
552
597
  end
553
- append_loglevel
554
- run(from: :depend, sync: sync)
598
+ if add
599
+ return if packages.empty?
600
+
601
+ cmd.merge(packages.map { |pkg| shell_quote(pkg) })
602
+ end
603
+ run(from: flag || :depend, sync: sync)
555
604
  end
556
605
  end
557
606
 
@@ -647,11 +696,8 @@ module Squared
647
696
  end
648
697
  pending = 0
649
698
  modified = 0
650
- size_col = ->(a, i) { a.map { |aa| aa[i] }.max_by(&:size).size }
651
- pad_ord = lambda do |val, ord|
652
- ret = val.succ.to_s
653
- ord.size > 9 ? ret.rjust(ord.size.to_s.size) : ret
654
- end
699
+ width = ->(a, i) { a.map { |aa| aa[i] }.max_by(&:size).size }
700
+ pad = ->(val, ord) { val.succ.to_s.rjust([ord.size.to_s.size, 2].max) }
655
701
  footer = lambda do |val, size|
656
702
  next unless verbose
657
703
 
@@ -665,19 +711,21 @@ module Squared
665
711
  end
666
712
  print_item banner unless sync
667
713
  if !found.empty?
668
- col1 = size_col.call(found, 0) + 4
669
- col2 = size_col.call(found, 1) + 4
714
+ col1 = width.call(found, 0) + 4
715
+ col2 = width.call(found, 1) + 4
670
716
  packages = []
671
- pat = ->(a) { /("#{Regexp.escape(a[0])}"\s*:\s*)"([~^])#{a[4] ? '?' : ''}#{Regexp.escape(a[1])}"/ }
717
+ pat = ->(a) { /("#{Regexp.escape(a[0])}"\s*:\s*)"([~^])#{'?' if a[4]}#{Regexp.escape(a[1])}"/ }
672
718
  edit = lambda do |a, pkg, mod|
673
719
  packages << a[0]
674
720
  modified += 1
675
721
  "#{pkg}\"#{mod || (a[3] == 1 && a[4] ? '^' : '')}#{a[2]}\""
676
722
  end
723
+ kwargs = { col1: col1, col2: col2, col3: width.call(found, 2), timeout: 0 }
677
724
  found.each_with_index do |item, i|
678
725
  a, b, c, d, e = item
679
726
  f = ia && (rev != :major || e || semmajor?(item[5], item[6]))
680
- if f && !confirm_outdated(a, c, (d / 2.0).ceil, b, lock: e, col1: col1, timeout: 0)
727
+ col0 = "#{pad.call(i, found)}. "
728
+ if f && !confirm_outdated(a, c, (d / 2.0).ceil, b, lock: e, col0: col0, **kwargs)
681
729
  cur = -1
682
730
  else
683
731
  cur = modified
@@ -691,9 +739,14 @@ module Squared
691
739
  end
692
740
  end
693
741
  end
694
- a = a.ljust(col1)
695
- b = b.ljust(col2)
696
- b = sub_style(b, styles: theme[:current]) if theme[:current] && !stdin?
742
+ if f
743
+ a = ' ' * col1
744
+ b = ' ' * col2
745
+ else
746
+ a = a.ljust(col1)
747
+ b = b.ljust(col2)
748
+ sub_style! b, theme[:current] if theme[:current] && !stdin?
749
+ end
697
750
  c = if cur == -1
698
751
  'SKIP'
699
752
  elsif modified == cur
@@ -703,15 +756,15 @@ module Squared
703
756
  else
704
757
  g = item
705
758
  if d == 1
706
- a = sub_style(a, styles: theme[:major])
707
- sub_style(c, :bold, styles: color(:green))
759
+ sub_style! a, theme[:major]
760
+ sub_style c, :bold, color(:green)
708
761
  else
709
762
  sub_style(c, **opt_style(color(d == 3 ? :green : :yellow), SEM_VER, d))
710
763
  end
711
764
  end
712
765
  s = a + b + c
713
766
  if !items
714
- puts "#{pad_ord.call(i, found)}. #{s}"
767
+ puts "#{f ? ' ' * col0.size : col0}#{s}"
715
768
  elsif g
716
769
  items << [s, g]
717
770
  end
@@ -749,20 +802,20 @@ module Squared
749
802
  end
750
803
  end
751
804
  elsif !avail.empty?
752
- col1 = size_col.call(avail, 0) + 4
753
- col2 = size_col.call(avail, 1)
754
- col3 = size_col.call(avail, 2) + 4
805
+ col1 = width.call(avail, 0) + 4
806
+ col2 = width.call(avail, 1)
807
+ col3 = width.call(avail, 2) + 4
755
808
  avail.each_with_index do |item, i|
756
809
  a, b, c, d = item
757
810
  a = a.ljust(col1)
758
- b = sub_style(b.ljust(col2), styles: color(d ? :red : :yellow))
811
+ b = sub_style b.ljust(col2), color(d ? :red : :yellow)
759
812
  c = c.ljust(col3)
760
813
  unless d
761
- a = sub_style(a, styles: theme[:active])
762
- c = sub_style(c, styles: color(:green))
814
+ sub_style! a, theme[:active]
815
+ sub_style! c, color(:green)
763
816
  pending += 1
764
817
  end
765
- puts "#{pad_ord.call(i, avail)}. #{(a + c + b).subhint(d ? 'locked' : 'latest')}"
818
+ puts "#{pad.call(i, avail)}. #{(a + c + b).subhint(d ? 'locked' : 'latest')}"
766
819
  end
767
820
  footer.call(0, avail.size)
768
821
  else
@@ -777,7 +830,7 @@ module Squared
777
830
 
778
831
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil)
779
832
  if read_package('private')
780
- ws = @children.select { |proj| proj.ref?(Node.ref) }
833
+ ws = children.select { |proj| proj.ref?(Node.ref) }
781
834
  if ws.empty?
782
835
  print_error('nothing to publish', subject: name, hint: 'private')
783
836
  elsif confirm_basic('Publish workspace?', ws.map(&:name).join(', '), 'N')
@@ -820,10 +873,16 @@ module Squared
820
873
 
821
874
  def package(flag, opts = [], packages: [], from: nil)
822
875
  workspace.rev_clear(name)
823
- if (yarn = dependtype(:yarn)) > 0
876
+ yarn = dependtype(:yarn)
877
+ if yarn > 0 && !(yarn == 1 && ((flag == :update && !packages.empty?) || flag == :rebuild))
824
878
  cmd = session 'yarn', case flag
825
879
  when :update
826
- yarn == 1 ? 'upgrade' : 'up'
880
+ if yarn == 1
881
+ 'upgrade'
882
+ else
883
+ spec = 0
884
+ 'up'
885
+ end
827
886
  when :reinstall
828
887
  if yarn == 1
829
888
  remove_modules 'yarn' if opts.include?('force')
@@ -832,35 +891,51 @@ module Squared
832
891
  end
833
892
  opts << 'no-lockfile' if lockfile(true)
834
893
  'install'
894
+ when :add
895
+ spec = 1
896
+ 'add'
835
897
  else
836
898
  yarn == 1 && flag == :dedupe ? 'install' : flag
837
899
  end
838
900
  op = OptionPartition.new(opts, if yarn == 1
839
901
  OPT_YARN.fetch(flag == :dedupe ? :install : flag, []) + OPT_YARN[:common]
840
902
  else
841
- OPT_BERRY.fetch(flag, [])
903
+ OPT_BERRY.fetch(flag, []) + case flag
904
+ when :add, :update then OPT_BERRY[:add_a]
905
+ else []
906
+ end
842
907
  end, cmd, project: self)
843
908
  if yarn == 1 && flag != :reinstall
844
909
  op << '--no-lockfile' if nolockfile?('yarn')
845
910
  op << '--ignore-engines' unless option('ignore-engines', equals: '0')
846
911
  end
847
- op.clear
848
- append_loglevel
849
912
  else
850
913
  args = if pnpm?
851
914
  case flag
852
915
  when :install, :update
853
916
  opts << 'no-lockfile' if nolockfile?('pnpm')
917
+ spec = 0 if flag == :update
918
+ when :add
919
+ spec = 1
854
920
  when :reinstall
855
921
  opts << 'force'
856
922
  flag = :install
857
923
  end
858
- no = OPT_PNPM[:no][flag]
924
+ flags = [flag]
925
+ unless flag == :rebuild
926
+ flags << :install_a
927
+ no = OPT_PNPM[:no][flag]
928
+ end
859
929
  [
860
930
  opts,
861
- [flag, :install_a].yield_self do |out|
862
- out.push(:install_b, :common_filter) unless flag == :dedupe
863
- out << :common_cpu unless flag == :update
931
+ flags.yield_self do |out|
932
+ unless flag == :dedupe
933
+ out << :common_filter
934
+ unless flag == :add
935
+ out << :install_b
936
+ out << :common_cpu unless flag == :update
937
+ end
938
+ end
864
939
  pnpmopts(*out)
865
940
  end,
866
941
  session('pnpm', flag)
@@ -869,27 +944,51 @@ module Squared
869
944
  case flag
870
945
  when :install, :update
871
946
  opts.unshift('package-lock=false', 'save=false') if nolockfile?('npm')
947
+ spec = 0
948
+ when :add
949
+ spec = 1
950
+ flag = :install
872
951
  when :reinstall
873
952
  remove_modules 'npm' if opts.delete('force')
874
953
  opts.unshift('package-lock=false') if lockfile(true)
875
954
  flag = :install
876
955
  end
877
- no = OPT_NPM[:no][:install]
956
+ flags = [flag]
957
+ unless flag == :rebuild
958
+ flags << :install_a
959
+ unless flag == :dedupe
960
+ %w[save ignore-scripts strict-peer-deps].each do |key|
961
+ option(key, prefix: 'npm', ignore: false) do |val|
962
+ opts << case val
963
+ when '0', 'false'
964
+ "#{key}=false"
965
+ else
966
+ "#{key}=true"
967
+ end
968
+ end
969
+ end
970
+ flags << :install_b
971
+ end
972
+ no = OPT_NPM[:no][:install]
973
+ end
878
974
  [
879
975
  opts,
880
- [flag, :install_a].yield_self do |out|
881
- out << :install_b unless flag == :dedupe
882
- npmopts(*out)
883
- end,
976
+ npmopts(*flags),
884
977
  session('npm', flag)
885
978
  ]
886
979
  end
887
980
  op = OptionPartition.new(*args, no: no, project: self)
981
+ append_platform if flag == :install
982
+ append_nocolor
983
+ end
984
+ append_loglevel
985
+ case spec
986
+ when 0, 1
888
987
  op.each do |opt|
889
988
  if opt =~ op.values
890
989
  case $1
891
990
  when 'w', 'workspace'
892
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
991
+ op << quotepath($1, $2)
893
992
  end
894
993
  elsif opt.include?('=') || opt.start_with?('-')
895
994
  op.errors << opt
@@ -899,22 +998,17 @@ module Squared
899
998
  end
900
999
  op.swap
901
1000
  .concat(packages)
902
- append_platform if flag == :install
903
- append_nocolor
904
- append_loglevel
905
- if flag == :dedupe
906
- op.clear
907
- else
908
- op.append(quote: true)
909
- end
910
- op.clear(errors: true)
1001
+ raise_error ArgumentError, 'no packages to add' if op.empty? && spec == 1
1002
+ op.append(quote: true)
1003
+ .clear(errors: true)
1004
+ else
1005
+ op.clear
911
1006
  end
912
1007
  run(from: from || :"package:#{flag}")
913
1008
  end
914
1009
 
915
1010
  def bump(flag, val = nil)
916
- val = sembump version, flag unless flag == :version
917
- return unless val
1011
+ return unless val ||= sembump(version, flag)
918
1012
 
919
1013
  doc = dependfile.read
920
1014
  if doc.sub!(/"version"\s*:\s*"#{version}"/, "\"version\": \"#{val}\"")
@@ -925,7 +1019,7 @@ module Squared
925
1019
  end
926
1020
  if stdin?
927
1021
  puts val
928
- elsif verbose
1022
+ elsif !silent?
929
1023
  major = flag == :major
930
1024
  emphasize("version: #{val}", title: name, border: borderstyle, sub: [
931
1025
  headerstyle,
@@ -959,7 +1053,7 @@ module Squared
959
1053
 
960
1054
  case $1
961
1055
  when 'w', 'workspace'
962
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
1056
+ op << quotepath($1, $2)
963
1057
  op.found << opt
964
1058
  end
965
1059
  end
@@ -1231,7 +1325,7 @@ module Squared
1231
1325
 
1232
1326
  def append_loglevel(target: @session)
1233
1327
  level = env('NODE_LOGLEVEL')
1234
- silent = !verbose || level == 'silent'
1328
+ silent = silent? || level == 'silent'
1235
1329
  return unless silent || level
1236
1330
 
1237
1331
  if yarn?
@@ -1265,6 +1359,14 @@ module Squared
1265
1359
  %w[cpu os libc].each { |name| option(name) { |val| target << basic_option(name, val) } }
1266
1360
  end
1267
1361
 
1362
+ def quotepath(name, val)
1363
+ if $2.include?(File::SEPARATOR) || (workspace.windows? && val.match?(%r{[\\/]}))
1364
+ quote_option name, basepath(val)
1365
+ else
1366
+ shell_option name, val
1367
+ end
1368
+ end
1369
+
1268
1370
  def dependroot
1269
1371
  dependname if parent&.has?('outdated', Node.ref)
1270
1372
  end
@@ -269,7 +269,7 @@ module Squared
269
269
  when :freeze
270
270
  format_desc action, flag, "file?=#{DEP_PYTHON[4]},opts*"
271
271
  task flag do |_, args|
272
- if (file = pip(flag, opts: args.to_a, banner: true)) && verbose
272
+ if (file = pip(flag, opts: args.to_a, banner: true)) && !silent?
273
273
  puts File.read(file)
274
274
  end
275
275
  end
@@ -457,15 +457,15 @@ module Squared
457
457
  styles = color(:yellow)
458
458
  else
459
459
  styles = color(:green)
460
- line = sub_style(line, styles: if type == 2
461
- styles += [:bold]
462
- theme[:major]
463
- else
464
- theme[:active]
465
- end, pat: /^(\S+)(.+)$/)
460
+ sub_style!(line, if type == 2
461
+ styles += [:bold]
462
+ theme[:major]
463
+ else
464
+ theme[:active]
465
+ end, pat: /^(\S+)(.+)$/)
466
466
  end
467
- line = sub_style(line, **opt_style(tc, /^(.+)(#{Regexp.escape(current)})(.+)$/, 2)) if tc
468
- line = sub_style(line, **opt_style(styles, /^(.+)(#{Regexp.escape(latest)})(.+)$/, 2))
467
+ sub_style!(line, **opt_style(tc, /^(.+)(#{Regexp.escape(current)})(.+)$/, 2)) if tc
468
+ sub_style!(line, **opt_style(styles, /^(.+)(#{Regexp.escape(latest)})(.+)$/, 2))
469
469
  found += 1
470
470
  end
471
471
  if items