squared 0.7.15 → 0.8.0

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.
@@ -8,17 +8,16 @@ module Squared
8
8
  common: %w[dry-run=!? force=!? loglevel=b include-workspace-root=!? workspaces=!? w|workspace=v].freeze,
9
9
  common_scripts: %w[dangerously-allow-all-scripts=!? strict-allow-scripts=!? allow-scripts=q].freeze,
10
10
  install: %w[package-lock-only=!? prefer-dedupe=!? E|save-exact=!? before=q cpu=b libc=b os=b].freeze,
11
- install_a: %w[audit=! bin-links=! engine-strict=!? foreground-scripts=!? fund=! ignore-scripts=!?
12
- install-links=!? package-lock=! strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
11
+ install_a: %w[audit=! bin-links=! foreground-scripts=!? fund=! ignore-scripts=!? install-links=!?
12
+ package-lock=! strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
13
13
  install_b: %w[no-save B|save-bundle D|save-dev O|save-optional save-peer P|save-prod g|global=!?
14
- min-release-age=i min-release-age-exclude=q S|save=!?].freeze,
14
+ S|save=!?].freeze,
15
15
  install_c: %w[allow-directory=b? allow-file=b? allow-git=b? allow-remote=b?].freeze,
16
16
  run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].freeze,
17
17
  exec: %w[c|call=q package=b].freeze,
18
18
  pack: %w[ignore-scripts=!? json=!? pack-destination=p].freeze,
19
19
  rebuild: %w[bin-links=! foreground-scripts=!? global=!? ignore-scripts=!? install-links=!?].freeze,
20
20
  'approve-scripts': %w[a|all allow-scripts-pending allow-scripts-pin=!? no-allow-scripts-pin json].freeze,
21
- 'deny-scripts': %w[a|all json].freeze,
22
21
  no: {
23
22
  install: %w[audit bin-links fund package-lock].freeze
24
23
  }.freeze
@@ -160,13 +159,13 @@ module Squared
160
159
  subtasks({
161
160
  'package' => %i[install add update dedupe approve deny rebuild reinstall].freeze,
162
161
  'outdated' => %i[major minor patch].freeze,
163
- 'bump' => %i[version major minor patch].freeze,
164
- 'publish' => %i[latest tag verify].freeze,
162
+ 'publish' => %i[latest tag stage verify].freeze,
165
163
  'tsc' => %i[project build].freeze,
166
164
  'add' => nil,
167
165
  'run' => nil,
168
166
  'exec' => nil,
169
167
  'nvm' => nil,
168
+ 'bump' => nil,
170
169
  'pack' => nil
171
170
  })
172
171
 
@@ -286,7 +285,7 @@ module Squared
286
285
 
287
286
  format_desc action, nil, 'version?,args*'
288
287
  task action, [:version] do |_, args|
289
- path = ->(s) { shell_quote(File.join(ENV['NVM_DIR'], s)) }
288
+ path = ->(s) { File.join(ENV['NVM_DIR'], s) }
290
289
  unless (version = args.version)
291
290
  cmd = ". #{path.call('nvm.sh')} && nvm list --no-colors --no-alias"
292
291
  version = pwd_set(from: :nvm) do
@@ -298,6 +297,18 @@ module Squared
298
297
  args.unshift(path.call('nvm-exec'))
299
298
  run(args.join(' '), { 'NODE_VERSION' => version }, banner: false, from: :nvm)
300
299
  end
300
+ when 'bump'
301
+ format_desc action, nil, 'version|pre?{major,minor,patch}|prerelease'
302
+ task action, [:version] do |_, args|
303
+ version = param_guard(action, 'to', args: args, key: :version)
304
+ if version.match?(/^((pre)?(major|minor|patch))|prerelease$/)
305
+ flag = version.to_sym
306
+ version = nil
307
+ else
308
+ flag = :version
309
+ end
310
+ bump flag, version
311
+ end
301
312
  when 'pack'
302
313
  format_desc action, nil, 'opts*'
303
314
  task action do |_, args|
@@ -314,69 +325,13 @@ module Squared
314
325
  outdated flag, args.to_a
315
326
  end
316
327
  when 'package'
317
- case flag
318
- when :approve, :deny
319
- format_desc(action, flag, 'opts*', before: flag == :approve ? 'name*|:' : 'name*|:|::')
320
- task flag do |_, args|
321
- args = args.to_a
322
- if args.first == ':' || (all = args.first == '::')
323
- args.shift
324
- list = []
325
- pad = 0
326
- size = ->(s) { pad = [pad, s.size].max }
327
- pwd_set do
328
- json = JSON.parse(`#{npm_output('install-scripts ls --json')}`)
329
- json&.fetch('allowScripts', [])&.each do |data|
330
- line = data['changes']&.find { |item| item['change'] == 'pending' }
331
- next unless line && line['key'] =~ /^(.+)@([^@]+)$/
332
-
333
- size.call($1)
334
- list << [$1, $2]
335
- end
336
- if all
337
- current = read_package 'allowScripts'
338
- current&.each_pair do |key, val|
339
- next unless val
340
-
341
- md = key.match(/^(.+?)(?:@([^@]+))?$/)
342
- size.call(md[1])
343
- list << [md[1], sub_style(md[2] || 'any', theme[:inline])]
344
- end
345
- end
346
- end
347
- if list.empty?
348
- puts log_message('no packages to review', subject: name, hint: "#{flag}-scripts")
349
- exit 0
350
- end
351
- list.map! { |name, ver| name.ljust(pad + ARG[:TAB]) + ver }
352
- args.concat(choice_index('Select packages', list, multiple: true, column: /^(\S+)/))
353
- end
354
- package flag, args
355
- end
356
- else
357
- format_desc(action, flag, 'opts*', before: case flag
358
- when :dedupe, :rebuild then nil
359
- when :reinstall then 'f/orce?'
360
- else 'name*'
361
- end)
362
- task flag do |_, args|
363
- package flag, args.to_a
364
- end
365
- end
366
- when 'bump'
367
- break unless version
368
-
369
- if flag == :version
370
- format_desc action, flag, 'version'
371
- task flag, [:version] do |_, args|
372
- version = param_guard(action, flag, args: args, key: :version)
373
- bump flag, version
374
- end
375
- else
376
- format_desc action, flag
377
- task flag do
378
- bump flag
379
- end
328
+ format_desc(action, flag, 'opts*', before: case flag
329
+ when :dedupe, :rebuild then nil
330
+ when :reinstall then 'force?'
331
+ else 'name*'
332
+ end)
333
+ task flag do |_, args|
334
+ package flag, args.to_a
380
335
  end
381
336
  when 'publish'
382
337
  if flag == :verify
@@ -390,22 +345,70 @@ module Squared
390
345
  publish(flag, version: version, ext: ext)
391
346
  end
392
347
  else
393
- format_desc(action, flag, 'otp?,p/ublic|r/estricted?,d/ry-run?',
394
- before: ('tag' if flag == :tag))
348
+ format_desc(action, flag,
349
+ "otp?,#{'registry?,' if flag == :stage}p/ublic|r/estricted?,d/ry-run?",
350
+ before: case flag
351
+ when :tag then 'tag'
352
+ when :stage then '{select=view,approve,reject,download}|publish=tag?'
353
+ end)
395
354
  task flag do |_, args|
396
355
  args = args.to_a
397
- access = if has_value!(args, 'r', 'restricted')
398
- 'restricted'
399
- elsif has_value!(args, 'p', 'public')
400
- 'public'
401
- end
402
- dryrun = has_value!(args, 'd', 'dry-run')
403
- if flag == :latest
356
+ access = nil
357
+ dryrun = nil
358
+ stage = []
359
+ parse = lambda do
360
+ access = if has_value!(args, 'r', 'restricted')
361
+ 'restricted'
362
+ elsif has_value!(args, 'p', 'public')
363
+ 'public'
364
+ end
365
+ dryrun = has_value!(args, 'd', 'dry-run')
366
+ end
367
+ case flag
368
+ when :stage
369
+ case args.first
370
+ when 'view', 'approve', 'reject', 'download'
371
+ out = pwd_set { `#{npm_output("stage list #{npmname} --json --loglevel=error")}` }
372
+ pad0 = 0
373
+ pad1 = 0
374
+ data = Array(parse_json(out, kind: Array)).map do |item|
375
+ ver = item['version']
376
+ tag = item['tag']
377
+ pad0 = [pad0, ver.size].max
378
+ pad1 = [pad1, tag.size].max
379
+ [ver, tag, item['id'], item['actor']]
380
+ end
381
+ if data.empty?
382
+ print_error('no staged releases', loglevel: Logger::INFO, subject: npmname)
383
+ exit 1
384
+ end
385
+ data.each do |item|
386
+ item[0] = item[0].rjust(pad0)
387
+ item[1] = item[1].rjust(pad1)
388
+ end
389
+ stage << args.shift
390
+ stage << choice_index('Select a release', data.map { |item| item.join(' ') },
391
+ column: /^(?:\S+\s+){2}(\S+)/)
392
+ if %w[approve reject].include?(stage.first)
393
+ otp = args.shift if args.first&.match?(/^\d+$/)
394
+ registry = args.first
395
+ option('otp', prefix: 'npm') { |val| otp = val }
396
+ option('registry', prefix: 'npm') { |val| registry = val }
397
+ end
398
+ else
399
+ stage << 'publish'
400
+ parse.call
401
+ tag, otp = args
402
+ end
403
+ when :latest
404
+ parse.call
404
405
  otp = args.first
405
406
  else
407
+ parse.call
406
408
  tag, otp = param_guard(action, flag, args: args)
407
409
  end
408
- publish(flag, otp: otp, tag: tag, access: access, dryrun: dryrun)
410
+ publish(flag, otp: otp, tag: tag, access: access, stage: stage, registry: registry,
411
+ dryrun: dryrun)
409
412
  end
410
413
  end
411
414
  when 'tsc'
@@ -462,7 +465,7 @@ module Squared
462
465
  return if items.empty?
463
466
 
464
467
  on :first, :copy
465
- print_item unless @output[0] || silent? || task_invoked?(/^copy(?::#{Node.ref}|$)/)
468
+ print_item unless @output[0] || silent? || task_invoked?(/^copy(:#{Node.ref}|$)/)
466
469
  packed = false
467
470
  items.each do |dir|
468
471
  case dir
@@ -477,7 +480,7 @@ module Squared
477
480
  @workspace.rev_clear(proj.name, sync: sync)
478
481
  proj.path
479
482
  else
480
- log.warn message("copy project :#{dir}", hint: 'missing')
483
+ log.warn message('target not found', dir, hint: 'copy')
481
484
  nil
482
485
  end
483
486
  when Hash
@@ -497,7 +500,7 @@ module Squared
497
500
  dest = dir.path
498
501
  @workspace.rev_clear(dir.name, sync: sync)
499
502
  else
500
- raise_error TypeError, "unknown: #{dir}", hint: 'copy'
503
+ raise TypeError, message('unknown', dir, hint: 'copy')
501
504
  end
502
505
  next unless from && dest&.directory?
503
506
 
@@ -559,7 +562,7 @@ module Squared
559
562
  if sub
560
563
  target << [entry, dest.join(into, sub)]
561
564
  else
562
- log.debug message("#{dependname} in \"#{entry}\"", hint: 'missing')
565
+ log.debug message("missing #{dependname} in \"#{entry}\"", hint: 'copy')
563
566
  end
564
567
  end
565
568
  else
@@ -608,7 +611,7 @@ module Squared
608
611
  rm = lambda do |target|
609
612
  return if remove.empty?
610
613
 
611
- run(target.temp(*remove).sub!(/ (?:add|install) /, ' remove '), sync: sync, from: :remove)
614
+ run(target.temp(*remove).sub!(/ (add|install) /, ' remove '), sync: sync, from: :remove)
612
615
  end
613
616
  yarn = dependtype(:yarn)
614
617
  if yarn > 0
@@ -625,7 +628,7 @@ module Squared
625
628
  cmd << '--mode=skip-build' if option('ignore-scripts')
626
629
  cmd << '--check-cache' if !flag && option('force')
627
630
  end
628
- if nolockfile?('yarn')
631
+ if nolockfile?(prefix: 'yarn')
629
632
  cmd << '--no-lockfile'
630
633
  elsif option('ci')
631
634
  if yarn == 1
@@ -661,7 +664,7 @@ module Squared
661
664
  cmd << '--ignore-workspace' if ws
662
665
  cmd << if option('force')
663
666
  '--force'
664
- elsif nolockfile?('pnpm')
667
+ elsif nolockfile?(prefix: 'pnpm')
665
668
  '--no-lockfile'
666
669
  elsif option('ci')
667
670
  '--frozen-lockfile'
@@ -669,7 +672,8 @@ module Squared
669
672
  cmd << '--ignore-scripts' if option('ignore-scripts')
670
673
  cmd << '--dangerously-allow-all-builds' if option('approve-builds')
671
674
  else
672
- cmd = session('npm', (ci = option('ci', prefix: 'npm')) ? 'ci' : 'install')
675
+ cmd = session 'npm'
676
+ cmd << (ci = option('ci') ? 'ci' : 'install')
673
677
  option('approve-scripts') do |val|
674
678
  cmd = npm_output 'approve-scripts'
675
679
  cmd << case val
@@ -683,26 +687,6 @@ module Squared
683
687
  print_run cmd, silent?
684
688
  run(cmd, banner: false)
685
689
  end
686
- option('allow-scripts', ignore: false) do |val|
687
- cmd << case val
688
- when '0'
689
- '--ignore-scripts'
690
- when 'false'
691
- '--strict-allow-scripts'
692
- when '1', 'true'
693
- '--dangerously-allow-all-scripts'
694
- else
695
- quote_option 'allow-scripts', val
696
- end
697
- end
698
- option('engine-strict', ignore: false) do |val|
699
- cmd << case val
700
- when '0', 'false'
701
- '--engine-strict=false'
702
- else
703
- '--engine-strict'
704
- end
705
- end
706
690
  cmd << '--workspaces=false' if ws
707
691
  cmd << '--force' if option('force')
708
692
  append_nocolor
@@ -722,7 +706,7 @@ module Squared
722
706
  append_platform
723
707
  end
724
708
  end
725
- cmd << '--package-lock=false' << '--save=false' if nolockfile?('npm')
709
+ cmd << '--package-lock=false' << 'save=false' if nolockfile?(prefix: 'npm')
726
710
  cmd << '--ignore-scripts' if option('ignore-scripts')
727
711
  end
728
712
  if add
@@ -802,7 +786,7 @@ module Squared
802
786
  end
803
787
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
804
788
 
805
- f = semscan file
789
+ f = semscan(file, fill: !option('save-exact').nil?)
806
790
  w = semscan want
807
791
  a = f[0]
808
792
  b = f[2]
@@ -812,8 +796,12 @@ module Squared
812
796
  when :major
813
797
  a == '0' ? c == '0' || c == '1' : true
814
798
  when :minor
799
+ next unless f[4]
800
+
815
801
  ch == '^' && (a == '0' ? c == '0' && b == d : a == c)
816
802
  when :patch
803
+ next unless b && f[4]
804
+
817
805
  a == c && b == d && f[4] != w[4]
818
806
  end
819
807
  if upgrade && !w[6]
@@ -825,7 +813,7 @@ module Squared
825
813
  a == '0' ? 1 : 3
826
814
  else
827
815
  5
828
- end, major, f, w]
816
+ end, major, semscan(file), w]
829
817
  elsif !major
830
818
  avail << [key, file, latest, latest != current]
831
819
  end
@@ -848,9 +836,9 @@ module Squared
848
836
  end
849
837
  print_item banner unless sync
850
838
  if !found.empty?
851
- col1 = width.call(found, 0) + ARG[:TAB]
852
- col2 = width.call(found, 1) + ARG[:TAB]
853
- col3 = pad.call(found.size, found).size + (ARG[:TAB] / 2) + col1 + col2 + width.call(found, 2)
839
+ col1 = width.call(found, 0) + 4
840
+ col2 = width.call(found, 1) + 4
841
+ col3 = pad.call(found.size, found).size + 2 + col1 + col2 + width.call(found, 2)
854
842
  packages = []
855
843
  pat = ->(a) { /("#{Regexp.escape(a[0])}"\s*:\s*)"([~^])#{'?' if a[4]}#{Regexp.escape(a[1])}"/ }
856
844
  edit = lambda do |a, pkg, mod|
@@ -872,17 +860,17 @@ module Squared
872
860
  end
873
861
  a = a.ljust(col1)
874
862
  b = b.ljust(col2)
875
- b = sub_style b, theme[:current] if theme[:current] && !stdin?
863
+ sub_style! b, theme[:current] if theme[:current] && !stdin?
876
864
  if cur == -1
877
865
  c = 'SKIP'
878
866
  elsif modified == cur
879
867
  c = 'FAIL'
880
868
  elsif !stdin?
881
869
  if d == 1
882
- a = sub_style a, theme[:major]
883
- c = sub_style c, :bold, color(:green)
870
+ sub_style! a, theme[:major]
871
+ sub_style! c, :bold, color(:green)
884
872
  else
885
- c = sub_style(c, **opt_style(color(d == 3 ? :green : :yellow), SEM_VER, d))
873
+ sub_style!(c, **opt_style(color(d == 3 ? :green : :yellow), SEM_VER, d))
886
874
  end
887
875
  g = item
888
876
  end
@@ -946,17 +934,17 @@ module Squared
946
934
  end
947
935
  end
948
936
  elsif !avail.empty?
949
- col1 = width.call(avail, 0) + ARG[:TAB]
937
+ col1 = width.call(avail, 0) + 4
950
938
  col2 = width.call(avail, 1)
951
- col3 = width.call(avail, 2) + ARG[:TAB]
939
+ col3 = width.call(avail, 2) + 4
952
940
  avail.each_with_index do |item, i|
953
941
  a, b, c, d = item
954
942
  a = a.ljust(col1)
955
943
  b = sub_style b.ljust(col2), color(d ? :red : :yellow)
956
944
  c = c.ljust(col3)
957
945
  unless d
958
- a = sub_style a, theme[:active]
959
- c = sub_style c, color(:green)
946
+ sub_style! a, theme[:active]
947
+ sub_style! c, color(:green)
960
948
  pending += 1
961
949
  end
962
950
  puts "#{pad.call(i, avail)}. #{(a + c + b).subhint(d ? 'locked' : 'latest')}"
@@ -973,18 +961,14 @@ module Squared
973
961
  end
974
962
 
975
963
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil,
976
- version: nil, ext: [], workspace: false)
964
+ version: nil, stage: [], registry: nil, ext: [], workspace: false)
977
965
  if read_package('private')
978
- return if workspace
966
+ return if workspace || !stage.empty?
979
967
 
980
- ws = children.select { |proj| proj.ref?(Node.ref) }
981
- if ws.empty?
982
- print_error('nothing to publish', subject: name, hint: 'private')
983
- elsif confirm_basic("#{flag == :verify ? 'Verify' : 'Publish'} workspace?", ws.map(&:name).join(', '), 'N')
984
- ws.each do |proj|
985
- proj.publish(flag, sync: sync, otp: otp, tag: tag, access: access, dryrun: dryrun, version: version,
986
- ext: ext, workspace: true)
987
- end
968
+ from, accept = flag == :verify ? %w[verify Y] : %w[publish N]
969
+ each(accept: accept, ref: Node.ref, from: from) do |proj|
970
+ proj.publish(flag, sync: sync, otp: otp, tag: tag, access: access, dryrun: dryrun, version: version,
971
+ ext: ext, workspace: true)
988
972
  end
989
973
  elsif version ||= self.version
990
974
  if flag == :verify
@@ -1055,24 +1039,35 @@ module Squared
1055
1039
  end
1056
1040
  end
1057
1041
  else
1058
- cmd = session 'npm', 'publish'
1059
- cmd << basic_option('otp', otp) if otp ||= option('otp')
1060
- cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
1061
- case access || option('access')
1062
- when 'p', 'public'
1063
- cmd << '--access=public'
1064
- when 'r', 'restricted'
1065
- cmd << '--access=restricted'
1042
+ args = ['npm']
1043
+ if stage.empty?
1044
+ args << 'publish'
1045
+ else
1046
+ args << 'stage' << stage.shift
1047
+ args.concat(stage)
1066
1048
  end
1067
- dryrun ||= dryrun?('npm')
1049
+ cmd = session(*args)
1050
+ if stage.empty?
1051
+ otp ||= option('otp')
1052
+ cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
1053
+ case access || option('access')
1054
+ when 'p', 'public'
1055
+ cmd << '--access=public'
1056
+ when 'r', 'restricted'
1057
+ cmd << '--access=restricted'
1058
+ end
1059
+ dryrun ||= dryrun?(prefix: 'npm')
1060
+ end
1061
+ cmd << basic_option('otp', otp) if otp
1062
+ cmd << quote_option('registry', registry) if registry
1068
1063
  if dryrun
1069
1064
  cmd << '--dry-run'
1070
1065
  else
1071
- from = :'npm:publish'
1072
1066
  log.info cmd.to_s
1067
+ from = symjoin args.take(3)
1073
1068
  end
1074
1069
  if sync
1075
- run(sync: sync, from: from, interactive: !dryrun && ['Publish', 'N', npmname])
1070
+ run(sync: sync, from: from, interactive: !dryrun && stage.empty? && ['Publish', 'N', npmname])
1076
1071
  else
1077
1072
  require 'open3'
1078
1073
  on :first, from
@@ -1087,13 +1082,12 @@ module Squared
1087
1082
  end
1088
1083
  end
1089
1084
  elsif !workspace
1090
- print_error("version: #{dependname}", subject: name, hint: 'not found')
1085
+ print_error('version not found', subject: name, hint: dependname)
1091
1086
  end
1092
1087
  end
1093
1088
 
1094
1089
  def package(flag, opts = [], packages: [], from: nil)
1095
1090
  workspace.rev_clear(name)
1096
- force = true if flag == :reinstall && has_value!(opts, 'f')
1097
1091
  yarn = dependtype(:yarn)
1098
1092
  if yarn > 0 && !(yarn == 1 && ((flag == :update && !packages.empty?) || %i[approve deny
1099
1093
  rebuild].include?(flag)))
@@ -1107,8 +1101,8 @@ module Squared
1107
1101
  end
1108
1102
  when :reinstall
1109
1103
  if yarn == 1
1110
- remove_modules 'yarn' if opts.include?('force') || force
1111
- elsif opts.delete('force') || force
1104
+ remove_modules(prefix: 'yarn') if opts.include?('force')
1105
+ elsif opts.delete('force')
1112
1106
  opts << 'check-cache'
1113
1107
  end
1114
1108
  opts << 'no-lockfile' if lockfile(true)
@@ -1128,7 +1122,7 @@ module Squared
1128
1122
  end
1129
1123
  end, cmd, project: self, strict: strict?)
1130
1124
  if yarn == 1 && flag != :reinstall
1131
- op << '--no-lockfile' if nolockfile?('yarn')
1125
+ op << '--no-lockfile' if nolockfile?(prefix: 'yarn')
1132
1126
  op << '--ignore-engines' if option('ignore-engines')
1133
1127
  end
1134
1128
  else
@@ -1141,7 +1135,7 @@ module Squared
1141
1135
  else
1142
1136
  case flag
1143
1137
  when :install, :update
1144
- opts << 'no-lockfile' if nolockfile?('pnpm')
1138
+ opts << 'no-lockfile' if nolockfile?(prefix: 'pnpm')
1145
1139
  spec = 0 if flag == :update
1146
1140
  when :add
1147
1141
  spec = 1
@@ -1171,13 +1165,13 @@ module Squared
1171
1165
  else
1172
1166
  case flag
1173
1167
  when :install, :update
1174
- opts.unshift('package-lock=false', 'save=false') if nolockfile?('npm')
1168
+ opts.unshift('package-lock=false', 'save=false') if nolockfile?(prefix: 'npm')
1175
1169
  spec = flag == :install ? 0 : 2
1176
1170
  when :add
1177
1171
  spec = 1
1178
1172
  flag = :install
1179
1173
  when :reinstall
1180
- remove_modules 'npm' if opts.delete('force') || force
1174
+ remove_modules(prefix: 'npm') if opts.delete('force')
1181
1175
  opts.unshift('package-lock=false') if lockfile(true)
1182
1176
  flag = :install
1183
1177
  end
@@ -1238,35 +1232,41 @@ module Squared
1238
1232
  run(from: from || symjoin('package', flag))
1239
1233
  end
1240
1234
 
1241
- def bump(flag, val = nil)
1242
- return unless val ||= sembump(version, flag)
1235
+ def bump(flag = :patch, val = nil, workspace: false)
1236
+ if read_package('private')
1237
+ return if workspace
1238
+
1239
+ each(accept: 'N', ref: Node.ref, from: 'bump') { |proj| proj.bump(flag, val, workspace: true) }
1240
+ elsif val ||= version && sembump(version, flag)
1241
+ begin
1242
+ doc = dependfile.read
1243
+ unless doc.sub!(/"version"\s*:\s*"#{version}"/, "\"version\": \"#{val}\"")
1244
+ raise message('version not found', hint: dependfile)
1245
+ end
1243
1246
 
1244
- doc = dependfile.read
1245
- if doc.sub!(/"version"\s*:\s*"#{version}"/, "\"version\": \"#{val}\"")
1246
- unless dryrun?
1247
- log.info "bump version #{version} to #{val.subhint(flag)}"
1248
- on :first, :bump
1249
- dependfile.write(doc)
1250
- end
1251
- if stdin?
1252
- puts val
1253
- elsif !silent?
1254
- major = flag == :major
1255
- emphasize("version: #{val}", title: name, border: borderstyle, sub: [
1256
- headerstyle,
1257
- opt_style(color(major ? :green : :yellow), /\A(version:)( )(\S+)(.*)\z/, 3),
1258
- opt_style(theme[major ? :major : :active], /\A(version:)(.*)\z/)
1259
- ])
1260
- end
1261
- unless dryrun?
1262
- commit(:add, [dependname], pass: true)
1263
- on :last, :bump
1247
+ unless dryrun?
1248
+ log.info "bump version #{version} to #{val.subhint(flag)}"
1249
+ on :first, :bump
1250
+ dependfile.write(doc)
1251
+ end
1252
+ if stdin?
1253
+ puts val
1254
+ elsif !silent?
1255
+ major = flag == :major
1256
+ emphasize("version: #{val}", title: name, border: borderstyle, sub: [
1257
+ headerstyle,
1258
+ opt_style(color(major ? :green : :yellow), /\A(version:)( )(\S+)(.*)\z/, 3),
1259
+ opt_style(theme[major ? :major : :active], /\A(version:)(.*)\z/)
1260
+ ])
1261
+ end
1262
+ unless dryrun?
1263
+ commit(:add, [dependname], pass: true)
1264
+ on :last, :bump
1265
+ end
1266
+ rescue => e
1267
+ on_error(e, dryrun: dryrun?)
1264
1268
  end
1265
- else
1266
- raise_error 'version not found', hint: dependfile
1267
1269
  end
1268
- rescue => e
1269
- on_error(e, dryrun: dryrun?)
1270
1270
  end
1271
1271
 
1272
1272
  def pack(opts = [])
@@ -1338,7 +1338,8 @@ module Squared
1338
1338
 
1339
1339
  if script
1340
1340
  ret = session dependbin, 'run'
1341
- raise_error "#{dependbin} run: #{target}", hint: from unless append_any(target, build: true)
1341
+ raise message(dependbin, 'run', target, hint: from) unless append_any(target, build: true)
1342
+
1342
1343
  append_any opts if opts
1343
1344
  append_loglevel
1344
1345
  append_any(args, delim: true) if args
@@ -1352,7 +1353,7 @@ module Squared
1352
1353
  when Enumerable
1353
1354
  target.to_a.join(' ')
1354
1355
  else
1355
- raise_error TypeError, "unknown: #{target}", hint: 'compose'
1356
+ raise TypeError, message('unknown', target, hint: 'compose')
1356
1357
  end
1357
1358
  end
1358
1359
  end
@@ -1452,11 +1453,7 @@ module Squared
1452
1453
  end
1453
1454
 
1454
1455
  def dependbin
1455
- if yarn?
1456
- 'yarn'
1457
- else
1458
- pnpm? ? 'pnpm' : 'npm'
1459
- end
1456
+ yarn? ? 'yarn' : pnpm? ? 'pnpm' : 'npm'
1460
1457
  end
1461
1458
 
1462
1459
  def version
@@ -1512,7 +1509,8 @@ module Squared
1512
1509
  next if yarntype(exist: true) == 0
1513
1510
  when /^pnpm/
1514
1511
  next if pnpmtype(exist: true) == 0
1515
- when /^npm/ then nil
1512
+ when /^npm/
1513
+ nil
1516
1514
  else
1517
1515
  next
1518
1516
  end
@@ -1565,9 +1563,9 @@ module Squared
1565
1563
  end
1566
1564
  end
1567
1565
 
1568
- def remove_modules(prefix = dependbin)
1569
- modules = basepath!('node_modules', type: 'd')
1570
- return false unless modules && confirm_basic('Remove?', modules, prefix: prefix)
1566
+ def remove_modules(prefix: dependbin)
1567
+ modules = basepath 'node_modules'
1568
+ return false unless modules.directory? && confirm_basic('Remove?', modules, prefix: prefix)
1571
1569
 
1572
1570
  modules.rmtree
1573
1571
  rescue Timeout::Error => e
@@ -1630,7 +1628,7 @@ module Squared
1630
1628
  end
1631
1629
 
1632
1630
  def dependroot
1633
- dependname if parent&.has?('outdated', Node.ref)
1631
+ dependname if parent&.has?('outdated', ref: Node.ref)
1634
1632
  end
1635
1633
 
1636
1634
  def npmname
@@ -1655,11 +1653,7 @@ module Squared
1655
1653
  end
1656
1654
 
1657
1655
  def lockfile(delete = false)
1658
- ret = basepath(if yarn?
1659
- 'yarn.lock'
1660
- else
1661
- pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json'
1662
- end)
1656
+ ret = basepath(yarn? ? 'yarn.lock' : pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json')
1663
1657
  if ret.exist?
1664
1658
  if delete
1665
1659
  ret.delete
@@ -1678,11 +1672,11 @@ module Squared
1678
1672
  @serve != false
1679
1673
  end
1680
1674
 
1681
- def nolockfile?(prefix = dependbin)
1675
+ def nolockfile?(prefix: dependbin)
1682
1676
  option('package-lock', 'lockfile', prefix: prefix, equals: '0') || !option('no-lockfile', prefix: prefix).nil?
1683
1677
  end
1684
1678
 
1685
- def dryrun?(prefix = dependbin)
1679
+ def dryrun?(prefix: dependbin)
1686
1680
  super(target: @session, prefix: prefix)
1687
1681
  end
1688
1682
  end