squared 0.7.6 → 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.
@@ -6,15 +6,18 @@ module Squared
6
6
  class Node < Git
7
7
  OPT_NPM = {
8
8
  common: %w[dry-run=!? force=!? loglevel=b include-workspace-root=!? workspaces=!? w|workspace=v].freeze,
9
+ common_scripts: %w[dangerously-allow-all-scripts=!? strict-allow-scripts=!? allow-scripts=q].freeze,
9
10
  install: %w[package-lock-only=!? prefer-dedupe=!? E|save-exact=!? before=q cpu=b libc=b os=b].freeze,
10
11
  install_a: %w[audit=! bin-links=! foreground-scripts=!? fund=! ignore-scripts=!? install-links=!?
11
12
  package-lock=! strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
12
13
  install_b: %w[no-save B|save-bundle D|save-dev O|save-optional save-peer P|save-prod g|global=!?
13
14
  S|save=!?].freeze,
15
+ install_c: %w[allow-directory=b? allow-file=b? allow-git=b? allow-remote=b?].freeze,
14
16
  run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].freeze,
15
17
  exec: %w[c|call=q package=b].freeze,
16
18
  pack: %w[ignore-scripts=!? json=!? pack-destination=p].freeze,
17
19
  rebuild: %w[bin-links=! foreground-scripts=!? global=!? ignore-scripts=!? install-links=!?].freeze,
20
+ 'approve-scripts': %w[a|all allow-scripts-pending allow-scripts-pin=!? no-allow-scripts-pin json].freeze,
18
21
  no: {
19
22
  install: %w[audit bin-links fund package-lock].freeze
20
23
  }.freeze
@@ -26,15 +29,16 @@ module Squared
26
29
  common_filter: %w[fail-if-no-match changed-files-ignore-pattern=q filter=q filter-prod=q
27
30
  test-pattern=q].freeze,
28
31
  install: %w[fix-lockfile force ignore-pnpmfile ignore-workspace lockfile-only merge-git-branch-lockfiles
29
- optimistic-repeat-install no-hoist no-lockfile no-optional prefer-frozen-lockfile resolution-only
30
- shamefully-hoist side-effects-cache side-effects-cache-readonly s|silent strict-peer-dependencies
31
- use-running-store-server use-store-server child-concurrency=i hoist-pattern=q lockfile-dir=p
32
- modules-dir=p network-concurrency=i package-import-method=b public-hoist-pattern=q
33
- reporter=b].freeze,
32
+ optimistic-repeat-install no-hoist no-lockfile no-optional no-runtime prefer-frozen-lockfile
33
+ resolution-only shamefully-hoist side-effects-cache side-effects-cache-readonly s|silent
34
+ strict-peer-dependencies trust-lockfile use-running-store-server use-store-server
35
+ child-concurrency=i hoist-pattern=q lockfile-dir=p modules-dir=p network-concurrency=i
36
+ package-import-method=b public-hoist-pattern=q reporter=b trust-policy=b trust-policy-exclude=q
37
+ trust-policy-ignore-after=i].freeze,
34
38
  install_a: %w[dangerously-allow-all-builds global-dir ignore-scripts offline prefer-offline store-dir=p
35
39
  virtual-store-dir=p].freeze,
36
40
  install_b: %w[D|dev no-optional P|prod].freeze,
37
- add: %w[allow-build config g|global save-catalog D|save-dev O|save-optional save-peer P|save-prod
41
+ add: %w[allow-build config g|global registry=q save-catalog D|save-dev O|save-optional save-peer P|save-prod
38
42
  save-catalog-name=b].freeze,
39
43
  update: %w[g|global i|interactive L|latest depth=i].freeze,
40
44
  dedupe: %w[check].freeze,
@@ -153,15 +157,15 @@ module Squared
153
157
  end
154
158
 
155
159
  subtasks({
156
- 'package' => %i[install add update dedupe rebuild reinstall].freeze,
160
+ 'package' => %i[install add update dedupe approve deny rebuild reinstall].freeze,
157
161
  'outdated' => %i[major minor patch].freeze,
158
- 'bump' => %i[version major minor patch].freeze,
159
- 'publish' => %i[latest tag verify].freeze,
162
+ 'publish' => %i[latest tag stage verify].freeze,
160
163
  'tsc' => %i[project build].freeze,
161
164
  'add' => nil,
162
165
  'run' => nil,
163
166
  'exec' => nil,
164
167
  'nvm' => nil,
168
+ 'bump' => nil,
165
169
  'pack' => nil
166
170
  })
167
171
 
@@ -198,7 +202,7 @@ module Squared
198
202
  when 'add'
199
203
  format_desc action, nil, 'save?=[=-]prod|dev|optional|peer|bundle,(-)name+'
200
204
  task action, [:save] do |_, args|
201
- packages = if args.save =~ /\A([=-]*)?(prod|dev|optional|peer|bundle)\z/
205
+ packages = if args.save =~ /^([=-]*)(prod|dev|optional|peer|bundle)$/
202
206
  save = [$2, $1.include?('='), $1.include?('-')]
203
207
  args.extras
204
208
  else
@@ -221,7 +225,7 @@ module Squared
221
225
  if (n, extra = indexitem(val))
222
226
  if (item = list[n.pred])
223
227
  run compose([item.first, extra].compact.join(' '), script: true)
224
- elsif exception
228
+ elsif exception?
225
229
  indexerror n, list
226
230
  else
227
231
  log.warn "run script #{n} of #{list.size}".subhint('out of range')
@@ -257,7 +261,7 @@ module Squared
257
261
  list = pnpmopts :exec, :common_filter
258
262
  session 'pnpm', pre.call('r'), pre.call('c'), 'exec'
259
263
  else
260
- list = npmopts :exec
264
+ list = npmopts :exec, :common_scripts
261
265
  session 'npm', 'exec'
262
266
  end
263
267
  op = OptionPartition.new(args, list, cmd, project: self, strict: strict?)
@@ -293,6 +297,18 @@ module Squared
293
297
  args.unshift(path.call('nvm-exec'))
294
298
  run(args.join(' '), { 'NODE_VERSION' => version }, banner: false, from: :nvm)
295
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
296
312
  when 'pack'
297
313
  format_desc action, nil, 'opts*'
298
314
  task action do |_, args|
@@ -317,21 +333,6 @@ module Squared
317
333
  task flag do |_, args|
318
334
  package flag, args.to_a
319
335
  end
320
- when 'bump'
321
- break unless version
322
-
323
- if flag == :version
324
- format_desc action, flag, 'version'
325
- task flag, [:version] do |_, args|
326
- version = param_guard(action, flag, args: args, key: :version)
327
- bump flag, version
328
- end
329
- else
330
- format_desc action, flag
331
- task flag do
332
- bump flag
333
- end
334
- end
335
336
  when 'publish'
336
337
  if flag == :verify
337
338
  format_desc action, flag, 'version?,ext*'
@@ -344,22 +345,70 @@ module Squared
344
345
  publish(flag, version: version, ext: ext)
345
346
  end
346
347
  else
347
- format_desc(action, flag, 'otp?,p/ublic|r/estricted?,d/ry-run?',
348
- 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)
349
354
  task flag do |_, args|
350
355
  args = args.to_a
351
- access = if has_value!(args, 'r', 'restricted')
352
- 'restricted'
353
- elsif has_value!(args, 'p', 'public')
354
- 'public'
355
- end
356
- dryrun = has_value!(args, 'd', 'dry-run')
357
- 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
358
405
  otp = args.first
359
406
  else
407
+ parse.call
360
408
  tag, otp = param_guard(action, flag, args: args)
361
409
  end
362
- 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)
363
412
  end
364
413
  end
365
414
  when 'tsc'
@@ -416,7 +465,7 @@ module Squared
416
465
  return if items.empty?
417
466
 
418
467
  on :first, :copy
419
- print_item unless @output[0] || silent? || task_invoked?(/^copy(?::#{Node.ref}|$)/)
468
+ print_item unless @output[0] || silent? || task_invoked?(/^copy(:#{Node.ref}|$)/)
420
469
  packed = false
421
470
  items.each do |dir|
422
471
  case dir
@@ -431,7 +480,7 @@ module Squared
431
480
  @workspace.rev_clear(proj.name, sync: sync)
432
481
  proj.path
433
482
  else
434
- log.warn message("copy project :#{dir}", hint: 'missing')
483
+ log.warn message('target not found', dir, hint: 'copy')
435
484
  nil
436
485
  end
437
486
  when Hash
@@ -451,7 +500,7 @@ module Squared
451
500
  dest = dir.path
452
501
  @workspace.rev_clear(dir.name, sync: sync)
453
502
  else
454
- raise_error TypeError, "unknown: #{dir}", hint: 'copy'
503
+ raise TypeError, message('unknown', dir, hint: 'copy')
455
504
  end
456
505
  next unless from && dest&.directory?
457
506
 
@@ -513,7 +562,7 @@ module Squared
513
562
  if sub
514
563
  target << [entry, dest.join(into, sub)]
515
564
  else
516
- log.debug message("#{dependname} in \"#{entry}\"", hint: 'missing')
565
+ log.debug message("missing #{dependname} in \"#{entry}\"", hint: 'copy')
517
566
  end
518
567
  end
519
568
  else
@@ -544,7 +593,6 @@ module Squared
544
593
  end
545
594
  save, exact, omit = save if save.is_a?(Array)
546
595
  ws = env('NODE_WORKSPACES', equals: '0')
547
- ci = option('ci')
548
596
  om = lambda do |cmd|
549
597
  if omit
550
598
  save = case save
@@ -563,7 +611,7 @@ module Squared
563
611
  rm = lambda do |target|
564
612
  return if remove.empty?
565
613
 
566
- 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)
567
615
  end
568
616
  yarn = dependtype(:yarn)
569
617
  if yarn > 0
@@ -580,9 +628,9 @@ module Squared
580
628
  cmd << '--mode=skip-build' if option('ignore-scripts')
581
629
  cmd << '--check-cache' if !flag && option('force')
582
630
  end
583
- if nolockfile?('yarn')
631
+ if nolockfile?(prefix: 'yarn')
584
632
  cmd << '--no-lockfile'
585
- elsif ci
633
+ elsif option('ci')
586
634
  if yarn == 1
587
635
  cmd << '--frozen-lockfile'
588
636
  elsif !flag
@@ -616,15 +664,29 @@ module Squared
616
664
  cmd << '--ignore-workspace' if ws
617
665
  cmd << if option('force')
618
666
  '--force'
619
- elsif nolockfile?('pnpm')
667
+ elsif nolockfile?(prefix: 'pnpm')
620
668
  '--no-lockfile'
621
- elsif ci
669
+ elsif option('ci')
622
670
  '--frozen-lockfile'
623
671
  end
624
672
  cmd << '--ignore-scripts' if option('ignore-scripts')
625
673
  cmd << '--dangerously-allow-all-builds' if option('approve-builds')
626
674
  else
627
- cmd = session('npm', ci ? 'ci' : 'install')
675
+ cmd = session 'npm'
676
+ cmd << (ci = option('ci') ? 'ci' : 'install')
677
+ option('approve-scripts') do |val|
678
+ cmd = npm_output 'approve-scripts'
679
+ cmd << case val
680
+ when '1'
681
+ '--all --no-allow-scripts-pin'
682
+ when 'true', 'all'
683
+ '--all'
684
+ else
685
+ val.split(/\s+/).quote!.join(' ')
686
+ end
687
+ print_run cmd, silent?
688
+ run(cmd, banner: false)
689
+ end
628
690
  cmd << '--workspaces=false' if ws
629
691
  cmd << '--force' if option('force')
630
692
  append_nocolor
@@ -644,7 +706,7 @@ module Squared
644
706
  append_platform
645
707
  end
646
708
  end
647
- cmd << '--package-lock=false' << 'save=false' if nolockfile?('npm')
709
+ cmd << '--package-lock=false' << 'save=false' if nolockfile?(prefix: 'npm')
648
710
  cmd << '--ignore-scripts' if option('ignore-scripts')
649
711
  end
650
712
  if add
@@ -724,7 +786,7 @@ module Squared
724
786
  end
725
787
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
726
788
 
727
- f = semscan file
789
+ f = semscan(file, fill: !option('save-exact').nil?)
728
790
  w = semscan want
729
791
  a = f[0]
730
792
  b = f[2]
@@ -734,11 +796,15 @@ module Squared
734
796
  when :major
735
797
  a == '0' ? c == '0' || c == '1' : true
736
798
  when :minor
799
+ next unless f[4]
800
+
737
801
  ch == '^' && (a == '0' ? c == '0' && b == d : a == c)
738
802
  when :patch
803
+ next unless b && f[4]
804
+
739
805
  a == c && b == d && f[4] != w[4]
740
806
  end
741
- if upgrade && !w[5]
807
+ if upgrade && !w[6]
742
808
  next if file == want
743
809
 
744
810
  found << [key, file, want, if a != c
@@ -747,7 +813,7 @@ module Squared
747
813
  a == '0' ? 1 : 3
748
814
  else
749
815
  5
750
- end, major, f, w]
816
+ end, major, semscan(file), w]
751
817
  elsif !major
752
818
  avail << [key, file, latest, latest != current]
753
819
  end
@@ -895,18 +961,14 @@ module Squared
895
961
  end
896
962
 
897
963
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil,
898
- version: nil, ext: [], workspace: false)
964
+ version: nil, stage: [], registry: nil, ext: [], workspace: false)
899
965
  if read_package('private')
900
- return if workspace
966
+ return if workspace || !stage.empty?
901
967
 
902
- ws = children.select { |proj| proj.ref?(Node.ref) }
903
- if ws.empty?
904
- print_error('nothing to publish', subject: name, hint: 'private')
905
- elsif confirm_basic("#{flag == :verify ? 'Verify' : 'Publish'} workspace?", ws.map(&:name).join(', '), 'N')
906
- ws.each do |proj|
907
- proj.publish(flag, sync: sync, otp: otp, tag: tag, access: access, dryrun: dryrun, version: version,
908
- ext: ext, workspace: true)
909
- 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)
910
972
  end
911
973
  elsif version ||= self.version
912
974
  if flag == :verify
@@ -977,24 +1039,35 @@ module Squared
977
1039
  end
978
1040
  end
979
1041
  else
980
- cmd = session 'npm', 'publish'
981
- cmd << basic_option('otp', otp) if otp ||= option('otp')
982
- cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
983
- case access || option('access')
984
- when 'p', 'public'
985
- cmd << '--access=public'
986
- when 'r', 'restricted'
987
- cmd << '--access=restricted'
1042
+ args = ['npm']
1043
+ if stage.empty?
1044
+ args << 'publish'
1045
+ else
1046
+ args << 'stage' << stage.shift
1047
+ args.concat(stage)
988
1048
  end
989
- 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
990
1063
  if dryrun
991
1064
  cmd << '--dry-run'
992
1065
  else
993
- from = :'npm:publish'
994
1066
  log.info cmd.to_s
1067
+ from = symjoin args.take(3)
995
1068
  end
996
1069
  if sync
997
- run(sync: sync, from: from, interactive: !dryrun && ['Publish', 'N', npmname])
1070
+ run(sync: sync, from: from, interactive: !dryrun && stage.empty? && ['Publish', 'N', npmname])
998
1071
  else
999
1072
  require 'open3'
1000
1073
  on :first, from
@@ -1009,14 +1082,15 @@ module Squared
1009
1082
  end
1010
1083
  end
1011
1084
  elsif !workspace
1012
- print_error("version: #{dependname}", subject: name, hint: 'not found')
1085
+ print_error('version not found', subject: name, hint: dependname)
1013
1086
  end
1014
1087
  end
1015
1088
 
1016
1089
  def package(flag, opts = [], packages: [], from: nil)
1017
1090
  workspace.rev_clear(name)
1018
1091
  yarn = dependtype(:yarn)
1019
- if yarn > 0 && !(yarn == 1 && ((flag == :update && !packages.empty?) || flag == :rebuild))
1092
+ if yarn > 0 && !(yarn == 1 && ((flag == :update && !packages.empty?) || %i[approve deny
1093
+ rebuild].include?(flag)))
1020
1094
  cmd = session 'yarn', case flag
1021
1095
  when :update
1022
1096
  if yarn == 1
@@ -1027,7 +1101,7 @@ module Squared
1027
1101
  end
1028
1102
  when :reinstall
1029
1103
  if yarn == 1
1030
- remove_modules 'yarn' if opts.include?('force')
1104
+ remove_modules(prefix: 'yarn') if opts.include?('force')
1031
1105
  elsif opts.delete('force')
1032
1106
  opts << 'check-cache'
1033
1107
  end
@@ -1048,70 +1122,81 @@ module Squared
1048
1122
  end
1049
1123
  end, cmd, project: self, strict: strict?)
1050
1124
  if yarn == 1 && flag != :reinstall
1051
- op << '--no-lockfile' if nolockfile?('yarn')
1125
+ op << '--no-lockfile' if nolockfile?(prefix: 'yarn')
1052
1126
  op << '--ignore-engines' if option('ignore-engines')
1053
1127
  end
1054
1128
  else
1129
+ flags = []
1055
1130
  args = if pnpm?
1056
- case flag
1057
- when :install, :update
1058
- opts << 'no-lockfile' if nolockfile?('pnpm')
1059
- spec = 0 if flag == :update
1060
- when :add
1061
- spec = 1
1062
- when :reinstall
1063
- opts << 'force'
1064
- flag = :install
1065
- end
1066
- flags = [flag]
1067
- flags << :install_a unless flag == :rebuild
1068
- unless flag == :dedupe
1069
- flags << :common_filter
1070
- unless flag == :add
1071
- flags << :install_b
1072
- flags << :common_cpu unless flag == :update
1131
+ if flag == :approve || flag == :deny
1132
+ opts.map! { |val| val.start_with?('!') ? val : "!#{val}" } if flag == :deny
1133
+ flag = :'approve-builds'
1134
+ spec = true
1135
+ else
1136
+ case flag
1137
+ when :install, :update
1138
+ opts << 'no-lockfile' if nolockfile?(prefix: 'pnpm')
1139
+ spec = 0 if flag == :update
1140
+ when :add
1141
+ spec = 1
1142
+ when :reinstall
1143
+ opts << 'force'
1144
+ flag = :install
1073
1145
  end
1146
+ flags << :install_a unless flag == :rebuild
1147
+ unless flag == :dedupe
1148
+ flags << :common_filter
1149
+ unless flag == :add
1150
+ flags << :install_b
1151
+ flags << :common_cpu unless flag == :update
1152
+ end
1153
+ end
1154
+ no = OPT_PNPM[:no][flag]
1074
1155
  end
1075
- no = OPT_PNPM[:no][flag]
1076
1156
  [
1077
1157
  opts,
1078
- pnpmopts(*flags),
1158
+ pnpmopts(flag, *flags),
1079
1159
  session('pnpm', flag)
1080
1160
  ]
1081
1161
  else
1082
- case flag
1083
- when :install, :update
1084
- opts.unshift('package-lock=false', 'save=false') if nolockfile?('npm')
1085
- spec = flag == :install ? 0 : 2
1086
- when :add
1087
- spec = 1
1088
- flag = :install
1089
- when :reinstall
1090
- remove_modules 'npm' if opts.delete('force')
1091
- opts.unshift('package-lock=false') if lockfile(true)
1092
- flag = :install
1093
- end
1094
- flags = [flag]
1095
- unless flag == :rebuild
1096
- flags << :install_a
1097
- unless flag == :dedupe
1098
- %w[save ignore-scripts strict-peer-deps].each do |key|
1099
- option(key, prefix: 'npm', ignore: false) do |val|
1100
- opts << basic_option(key, case val
1101
- when '0', 'false'
1102
- false
1103
- else
1104
- true
1105
- end)
1162
+ if flag == :approve || flag == :deny
1163
+ flag = :"#{flag}-scripts"
1164
+ spec = true
1165
+ else
1166
+ case flag
1167
+ when :install, :update
1168
+ opts.unshift('package-lock=false', 'save=false') if nolockfile?(prefix: 'npm')
1169
+ spec = flag == :install ? 0 : 2
1170
+ when :add
1171
+ spec = 1
1172
+ flag = :install
1173
+ when :reinstall
1174
+ remove_modules(prefix: 'npm') if opts.delete('force')
1175
+ opts.unshift('package-lock=false') if lockfile(true)
1176
+ flag = :install
1177
+ end
1178
+ unless flag == :rebuild
1179
+ flags << :install_a
1180
+ unless flag == :dedupe
1181
+ %w[save ignore-scripts strict-peer-deps].each do |key|
1182
+ option(key, prefix: 'npm', ignore: false) do |val|
1183
+ opts << basic_option(key, case val
1184
+ when '0', 'false'
1185
+ false
1186
+ else
1187
+ true
1188
+ end)
1189
+ end
1106
1190
  end
1191
+ flags << :install_b << :common_scripts
1107
1192
  end
1108
- flags << :install_b
1193
+ flags << :install_c unless flag == :update
1194
+ no = OPT_NPM[:no][:install]
1109
1195
  end
1110
- no = OPT_NPM[:no][:install]
1111
1196
  end
1112
1197
  [
1113
1198
  opts,
1114
- npmopts(*flags),
1199
+ npmopts(flag, *flags),
1115
1200
  session('npm', flag)
1116
1201
  ]
1117
1202
  end
@@ -1139,41 +1224,49 @@ module Squared
1139
1224
 
1140
1225
  op.append(quote: true)
1141
1226
  .clear(errors: true)
1227
+ when true
1228
+ op.append(quote: true)
1142
1229
  else
1143
1230
  op.clear
1144
1231
  end
1145
1232
  run(from: from || symjoin('package', flag))
1146
1233
  end
1147
1234
 
1148
- def bump(flag, val = nil)
1149
- return unless val ||= sembump(version, flag)
1235
+ def bump(flag = :patch, val = nil, workspace: false)
1236
+ if read_package('private')
1237
+ return if workspace
1150
1238
 
1151
- doc = dependfile.read
1152
- if doc.sub!(/"version"\s*:\s*"#{version}"/, "\"version\": \"#{val}\"")
1153
- unless dryrun?
1154
- log.info "bump version #{version} to #{val.subhint(flag)}"
1155
- on :first, :bump
1156
- dependfile.write(doc)
1157
- end
1158
- if stdin?
1159
- puts val
1160
- elsif !silent?
1161
- major = flag == :major
1162
- emphasize("version: #{val}", title: name, border: borderstyle, sub: [
1163
- headerstyle,
1164
- opt_style(color(major ? :green : :yellow), /\A(version:)( )(\S+)(.*)\z/, 3),
1165
- opt_style(theme[major ? :major : :active], /\A(version:)(.*)\z/)
1166
- ])
1167
- end
1168
- unless dryrun?
1169
- commit(:add, [dependname], pass: true)
1170
- on :last, :bump
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
1246
+
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?)
1171
1268
  end
1172
- else
1173
- raise_error 'version not found', hint: dependfile
1174
1269
  end
1175
- rescue => e
1176
- on_error(e, dryrun: dryrun?)
1177
1270
  end
1178
1271
 
1179
1272
  def pack(opts = [])
@@ -1245,7 +1338,8 @@ module Squared
1245
1338
 
1246
1339
  if script
1247
1340
  ret = session dependbin, 'run'
1248
- 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
+
1249
1343
  append_any opts if opts
1250
1344
  append_loglevel
1251
1345
  append_any(args, delim: true) if args
@@ -1259,7 +1353,7 @@ module Squared
1259
1353
  when Enumerable
1260
1354
  target.to_a.join(' ')
1261
1355
  else
1262
- raise_error TypeError, "unknown: #{target}", hint: 'compose'
1356
+ raise TypeError, message('unknown', target, hint: 'compose')
1263
1357
  end
1264
1358
  end
1265
1359
  end
@@ -1359,11 +1453,7 @@ module Squared
1359
1453
  end
1360
1454
 
1361
1455
  def dependbin
1362
- if yarn?
1363
- 'yarn'
1364
- else
1365
- pnpm? ? 'pnpm' : 'npm'
1366
- end
1456
+ yarn? ? 'yarn' : pnpm? ? 'pnpm' : 'npm'
1367
1457
  end
1368
1458
 
1369
1459
  def version
@@ -1380,6 +1470,10 @@ module Squared
1380
1470
 
1381
1471
  private
1382
1472
 
1473
+ def npm_output(*cmd, **kwargs)
1474
+ session_output('npm', *cmd, **kwargs)
1475
+ end
1476
+
1383
1477
  def read_package(key = 'packageManager', update: false)
1384
1478
  unless !update && @pm.key?(key)
1385
1479
  doc = JSON.parse(dependfile.read)
@@ -1469,7 +1563,7 @@ module Squared
1469
1563
  end
1470
1564
  end
1471
1565
 
1472
- def remove_modules(prefix = dependbin)
1566
+ def remove_modules(prefix: dependbin)
1473
1567
  modules = basepath 'node_modules'
1474
1568
  return false unless modules.directory? && confirm_basic('Remove?', modules, prefix: prefix)
1475
1569
 
@@ -1534,7 +1628,7 @@ module Squared
1534
1628
  end
1535
1629
 
1536
1630
  def dependroot
1537
- dependname if parent&.has?('outdated', Node.ref)
1631
+ dependname if parent&.has?('outdated', ref: Node.ref)
1538
1632
  end
1539
1633
 
1540
1634
  def npmname
@@ -1559,11 +1653,7 @@ module Squared
1559
1653
  end
1560
1654
 
1561
1655
  def lockfile(delete = false)
1562
- ret = basepath(if yarn?
1563
- 'yarn.lock'
1564
- else
1565
- pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json'
1566
- end)
1656
+ ret = basepath(yarn? ? 'yarn.lock' : pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json')
1567
1657
  if ret.exist?
1568
1658
  if delete
1569
1659
  ret.delete
@@ -1582,11 +1672,11 @@ module Squared
1582
1672
  @serve != false
1583
1673
  end
1584
1674
 
1585
- def nolockfile?(prefix = dependbin)
1675
+ def nolockfile?(prefix: dependbin)
1586
1676
  option('package-lock', 'lockfile', prefix: prefix, equals: '0') || !option('no-lockfile', prefix: prefix).nil?
1587
1677
  end
1588
1678
 
1589
- def dryrun?(prefix = dependbin)
1679
+ def dryrun?(prefix: dependbin)
1590
1680
  super(target: @session, prefix: prefix)
1591
1681
  end
1592
1682
  end