squared 0.7.9 → 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.
@@ -159,13 +159,13 @@ module Squared
159
159
  subtasks({
160
160
  'package' => %i[install add update dedupe approve deny rebuild reinstall].freeze,
161
161
  'outdated' => %i[major minor patch].freeze,
162
- 'bump' => %i[version major minor patch].freeze,
163
- 'publish' => %i[latest tag verify].freeze,
162
+ 'publish' => %i[latest tag stage verify].freeze,
164
163
  'tsc' => %i[project build].freeze,
165
164
  'add' => nil,
166
165
  'run' => nil,
167
166
  'exec' => nil,
168
167
  'nvm' => nil,
168
+ 'bump' => nil,
169
169
  'pack' => nil
170
170
  })
171
171
 
@@ -297,6 +297,18 @@ module Squared
297
297
  args.unshift(path.call('nvm-exec'))
298
298
  run(args.join(' '), { 'NODE_VERSION' => version }, banner: false, from: :nvm)
299
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
300
312
  when 'pack'
301
313
  format_desc action, nil, 'opts*'
302
314
  task action do |_, args|
@@ -315,27 +327,12 @@ module Squared
315
327
  when 'package'
316
328
  format_desc(action, flag, 'opts*', before: case flag
317
329
  when :dedupe, :rebuild then nil
318
- when :reinstall then 'f/orce?'
330
+ when :reinstall then 'force?'
319
331
  else 'name*'
320
332
  end)
321
333
  task flag do |_, args|
322
334
  package flag, args.to_a
323
335
  end
324
- when 'bump'
325
- break unless version
326
-
327
- if flag == :version
328
- format_desc action, flag, 'version'
329
- task flag, [:version] do |_, args|
330
- version = param_guard(action, flag, args: args, key: :version)
331
- bump flag, version
332
- end
333
- else
334
- format_desc action, flag
335
- task flag do
336
- bump flag
337
- end
338
- end
339
336
  when 'publish'
340
337
  if flag == :verify
341
338
  format_desc action, flag, 'version?,ext*'
@@ -348,22 +345,70 @@ module Squared
348
345
  publish(flag, version: version, ext: ext)
349
346
  end
350
347
  else
351
- format_desc(action, flag, 'otp?,p/ublic|r/estricted?,d/ry-run?',
352
- 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)
353
354
  task flag do |_, args|
354
355
  args = args.to_a
355
- access = if has_value!(args, 'r', 'restricted')
356
- 'restricted'
357
- elsif has_value!(args, 'p', 'public')
358
- 'public'
359
- end
360
- dryrun = has_value!(args, 'd', 'dry-run')
361
- 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
362
405
  otp = args.first
363
406
  else
407
+ parse.call
364
408
  tag, otp = param_guard(action, flag, args: args)
365
409
  end
366
- 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)
367
412
  end
368
413
  end
369
414
  when 'tsc'
@@ -420,7 +465,7 @@ module Squared
420
465
  return if items.empty?
421
466
 
422
467
  on :first, :copy
423
- print_item unless @output[0] || silent? || task_invoked?(/^copy(?::#{Node.ref}|$)/)
468
+ print_item unless @output[0] || silent? || task_invoked?(/^copy(:#{Node.ref}|$)/)
424
469
  packed = false
425
470
  items.each do |dir|
426
471
  case dir
@@ -435,7 +480,7 @@ module Squared
435
480
  @workspace.rev_clear(proj.name, sync: sync)
436
481
  proj.path
437
482
  else
438
- log.warn message("copy project :#{dir}", hint: 'missing')
483
+ log.warn message('target not found', dir, hint: 'copy')
439
484
  nil
440
485
  end
441
486
  when Hash
@@ -455,7 +500,7 @@ module Squared
455
500
  dest = dir.path
456
501
  @workspace.rev_clear(dir.name, sync: sync)
457
502
  else
458
- raise_error TypeError, "unknown: #{dir}", hint: 'copy'
503
+ raise TypeError, message('unknown', dir, hint: 'copy')
459
504
  end
460
505
  next unless from && dest&.directory?
461
506
 
@@ -517,7 +562,7 @@ module Squared
517
562
  if sub
518
563
  target << [entry, dest.join(into, sub)]
519
564
  else
520
- log.debug message("#{dependname} in \"#{entry}\"", hint: 'missing')
565
+ log.debug message("missing #{dependname} in \"#{entry}\"", hint: 'copy')
521
566
  end
522
567
  end
523
568
  else
@@ -566,7 +611,7 @@ module Squared
566
611
  rm = lambda do |target|
567
612
  return if remove.empty?
568
613
 
569
- 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)
570
615
  end
571
616
  yarn = dependtype(:yarn)
572
617
  if yarn > 0
@@ -583,7 +628,7 @@ module Squared
583
628
  cmd << '--mode=skip-build' if option('ignore-scripts')
584
629
  cmd << '--check-cache' if !flag && option('force')
585
630
  end
586
- if nolockfile?('yarn')
631
+ if nolockfile?(prefix: 'yarn')
587
632
  cmd << '--no-lockfile'
588
633
  elsif option('ci')
589
634
  if yarn == 1
@@ -619,7 +664,7 @@ module Squared
619
664
  cmd << '--ignore-workspace' if ws
620
665
  cmd << if option('force')
621
666
  '--force'
622
- elsif nolockfile?('pnpm')
667
+ elsif nolockfile?(prefix: 'pnpm')
623
668
  '--no-lockfile'
624
669
  elsif option('ci')
625
670
  '--frozen-lockfile'
@@ -642,18 +687,6 @@ module Squared
642
687
  print_run cmd, silent?
643
688
  run(cmd, banner: false)
644
689
  end
645
- option('allow-scripts', ignore: false) do |val|
646
- cmd << case val
647
- when '0'
648
- '--ignore-scripts'
649
- when 'false'
650
- '--strict-allow-scripts'
651
- when '1', 'true'
652
- '--dangerously-allow-all-scripts'
653
- else
654
- quote_option 'allow-scripts', val
655
- end
656
- end
657
690
  cmd << '--workspaces=false' if ws
658
691
  cmd << '--force' if option('force')
659
692
  append_nocolor
@@ -673,7 +706,7 @@ module Squared
673
706
  append_platform
674
707
  end
675
708
  end
676
- cmd << '--package-lock=false' << 'save=false' if nolockfile?('npm')
709
+ cmd << '--package-lock=false' << 'save=false' if nolockfile?(prefix: 'npm')
677
710
  cmd << '--ignore-scripts' if option('ignore-scripts')
678
711
  end
679
712
  if add
@@ -753,7 +786,7 @@ module Squared
753
786
  end
754
787
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
755
788
 
756
- f = semscan file
789
+ f = semscan(file, fill: !option('save-exact').nil?)
757
790
  w = semscan want
758
791
  a = f[0]
759
792
  b = f[2]
@@ -763,8 +796,12 @@ module Squared
763
796
  when :major
764
797
  a == '0' ? c == '0' || c == '1' : true
765
798
  when :minor
799
+ next unless f[4]
800
+
766
801
  ch == '^' && (a == '0' ? c == '0' && b == d : a == c)
767
802
  when :patch
803
+ next unless b && f[4]
804
+
768
805
  a == c && b == d && f[4] != w[4]
769
806
  end
770
807
  if upgrade && !w[6]
@@ -776,7 +813,7 @@ module Squared
776
813
  a == '0' ? 1 : 3
777
814
  else
778
815
  5
779
- end, major, f, w]
816
+ end, major, semscan(file), w]
780
817
  elsif !major
781
818
  avail << [key, file, latest, latest != current]
782
819
  end
@@ -924,18 +961,14 @@ module Squared
924
961
  end
925
962
 
926
963
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil,
927
- version: nil, ext: [], workspace: false)
964
+ version: nil, stage: [], registry: nil, ext: [], workspace: false)
928
965
  if read_package('private')
929
- return if workspace
966
+ return if workspace || !stage.empty?
930
967
 
931
- ws = children.select { |proj| proj.ref?(Node.ref) }
932
- if ws.empty?
933
- print_error('nothing to publish', subject: name, hint: 'private')
934
- elsif confirm_basic("#{flag == :verify ? 'Verify' : 'Publish'} workspace?", ws.map(&:name).join(', '), 'N')
935
- ws.each do |proj|
936
- proj.publish(flag, sync: sync, otp: otp, tag: tag, access: access, dryrun: dryrun, version: version,
937
- ext: ext, workspace: true)
938
- 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)
939
972
  end
940
973
  elsif version ||= self.version
941
974
  if flag == :verify
@@ -1006,24 +1039,35 @@ module Squared
1006
1039
  end
1007
1040
  end
1008
1041
  else
1009
- cmd = session 'npm', 'publish'
1010
- cmd << basic_option('otp', otp) if otp ||= option('otp')
1011
- cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
1012
- case access || option('access')
1013
- when 'p', 'public'
1014
- cmd << '--access=public'
1015
- when 'r', 'restricted'
1016
- cmd << '--access=restricted'
1042
+ args = ['npm']
1043
+ if stage.empty?
1044
+ args << 'publish'
1045
+ else
1046
+ args << 'stage' << stage.shift
1047
+ args.concat(stage)
1048
+ end
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')
1017
1060
  end
1018
- dryrun ||= dryrun?('npm')
1061
+ cmd << basic_option('otp', otp) if otp
1062
+ cmd << quote_option('registry', registry) if registry
1019
1063
  if dryrun
1020
1064
  cmd << '--dry-run'
1021
1065
  else
1022
- from = :'npm:publish'
1023
1066
  log.info cmd.to_s
1067
+ from = symjoin args.take(3)
1024
1068
  end
1025
1069
  if sync
1026
- run(sync: sync, from: from, interactive: !dryrun && ['Publish', 'N', npmname])
1070
+ run(sync: sync, from: from, interactive: !dryrun && stage.empty? && ['Publish', 'N', npmname])
1027
1071
  else
1028
1072
  require 'open3'
1029
1073
  on :first, from
@@ -1038,13 +1082,12 @@ module Squared
1038
1082
  end
1039
1083
  end
1040
1084
  elsif !workspace
1041
- print_error("version: #{dependname}", subject: name, hint: 'not found')
1085
+ print_error('version not found', subject: name, hint: dependname)
1042
1086
  end
1043
1087
  end
1044
1088
 
1045
1089
  def package(flag, opts = [], packages: [], from: nil)
1046
1090
  workspace.rev_clear(name)
1047
- force = true if flag == :reinstall && has_value!(opts, 'f')
1048
1091
  yarn = dependtype(:yarn)
1049
1092
  if yarn > 0 && !(yarn == 1 && ((flag == :update && !packages.empty?) || %i[approve deny
1050
1093
  rebuild].include?(flag)))
@@ -1058,8 +1101,8 @@ module Squared
1058
1101
  end
1059
1102
  when :reinstall
1060
1103
  if yarn == 1
1061
- remove_modules 'yarn' if opts.include?('force') || force
1062
- elsif opts.delete('force') || force
1104
+ remove_modules(prefix: 'yarn') if opts.include?('force')
1105
+ elsif opts.delete('force')
1063
1106
  opts << 'check-cache'
1064
1107
  end
1065
1108
  opts << 'no-lockfile' if lockfile(true)
@@ -1079,7 +1122,7 @@ module Squared
1079
1122
  end
1080
1123
  end, cmd, project: self, strict: strict?)
1081
1124
  if yarn == 1 && flag != :reinstall
1082
- op << '--no-lockfile' if nolockfile?('yarn')
1125
+ op << '--no-lockfile' if nolockfile?(prefix: 'yarn')
1083
1126
  op << '--ignore-engines' if option('ignore-engines')
1084
1127
  end
1085
1128
  else
@@ -1092,7 +1135,7 @@ module Squared
1092
1135
  else
1093
1136
  case flag
1094
1137
  when :install, :update
1095
- opts << 'no-lockfile' if nolockfile?('pnpm')
1138
+ opts << 'no-lockfile' if nolockfile?(prefix: 'pnpm')
1096
1139
  spec = 0 if flag == :update
1097
1140
  when :add
1098
1141
  spec = 1
@@ -1122,13 +1165,13 @@ module Squared
1122
1165
  else
1123
1166
  case flag
1124
1167
  when :install, :update
1125
- opts.unshift('package-lock=false', 'save=false') if nolockfile?('npm')
1168
+ opts.unshift('package-lock=false', 'save=false') if nolockfile?(prefix: 'npm')
1126
1169
  spec = flag == :install ? 0 : 2
1127
1170
  when :add
1128
1171
  spec = 1
1129
1172
  flag = :install
1130
1173
  when :reinstall
1131
- remove_modules 'npm' if opts.delete('force') || force
1174
+ remove_modules(prefix: 'npm') if opts.delete('force')
1132
1175
  opts.unshift('package-lock=false') if lockfile(true)
1133
1176
  flag = :install
1134
1177
  end
@@ -1189,35 +1232,41 @@ module Squared
1189
1232
  run(from: from || symjoin('package', flag))
1190
1233
  end
1191
1234
 
1192
- def bump(flag, val = nil)
1193
- 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
1194
1246
 
1195
- doc = dependfile.read
1196
- if doc.sub!(/"version"\s*:\s*"#{version}"/, "\"version\": \"#{val}\"")
1197
- unless dryrun?
1198
- log.info "bump version #{version} to #{val.subhint(flag)}"
1199
- on :first, :bump
1200
- dependfile.write(doc)
1201
- end
1202
- if stdin?
1203
- puts val
1204
- elsif !silent?
1205
- major = flag == :major
1206
- emphasize("version: #{val}", title: name, border: borderstyle, sub: [
1207
- headerstyle,
1208
- opt_style(color(major ? :green : :yellow), /\A(version:)( )(\S+)(.*)\z/, 3),
1209
- opt_style(theme[major ? :major : :active], /\A(version:)(.*)\z/)
1210
- ])
1211
- end
1212
- unless dryrun?
1213
- commit(:add, [dependname], pass: true)
1214
- 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?)
1215
1268
  end
1216
- else
1217
- raise_error 'version not found', hint: dependfile
1218
1269
  end
1219
- rescue => e
1220
- on_error(e, dryrun: dryrun?)
1221
1270
  end
1222
1271
 
1223
1272
  def pack(opts = [])
@@ -1289,7 +1338,8 @@ module Squared
1289
1338
 
1290
1339
  if script
1291
1340
  ret = session dependbin, 'run'
1292
- 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
+
1293
1343
  append_any opts if opts
1294
1344
  append_loglevel
1295
1345
  append_any(args, delim: true) if args
@@ -1303,7 +1353,7 @@ module Squared
1303
1353
  when Enumerable
1304
1354
  target.to_a.join(' ')
1305
1355
  else
1306
- raise_error TypeError, "unknown: #{target}", hint: 'compose'
1356
+ raise TypeError, message('unknown', target, hint: 'compose')
1307
1357
  end
1308
1358
  end
1309
1359
  end
@@ -1403,11 +1453,7 @@ module Squared
1403
1453
  end
1404
1454
 
1405
1455
  def dependbin
1406
- if yarn?
1407
- 'yarn'
1408
- else
1409
- pnpm? ? 'pnpm' : 'npm'
1410
- end
1456
+ yarn? ? 'yarn' : pnpm? ? 'pnpm' : 'npm'
1411
1457
  end
1412
1458
 
1413
1459
  def version
@@ -1517,7 +1563,7 @@ module Squared
1517
1563
  end
1518
1564
  end
1519
1565
 
1520
- def remove_modules(prefix = dependbin)
1566
+ def remove_modules(prefix: dependbin)
1521
1567
  modules = basepath 'node_modules'
1522
1568
  return false unless modules.directory? && confirm_basic('Remove?', modules, prefix: prefix)
1523
1569
 
@@ -1582,7 +1628,7 @@ module Squared
1582
1628
  end
1583
1629
 
1584
1630
  def dependroot
1585
- dependname if parent&.has?('outdated', Node.ref)
1631
+ dependname if parent&.has?('outdated', ref: Node.ref)
1586
1632
  end
1587
1633
 
1588
1634
  def npmname
@@ -1607,11 +1653,7 @@ module Squared
1607
1653
  end
1608
1654
 
1609
1655
  def lockfile(delete = false)
1610
- ret = basepath(if yarn?
1611
- 'yarn.lock'
1612
- else
1613
- pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json'
1614
- end)
1656
+ ret = basepath(yarn? ? 'yarn.lock' : pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json')
1615
1657
  if ret.exist?
1616
1658
  if delete
1617
1659
  ret.delete
@@ -1630,11 +1672,11 @@ module Squared
1630
1672
  @serve != false
1631
1673
  end
1632
1674
 
1633
- def nolockfile?(prefix = dependbin)
1675
+ def nolockfile?(prefix: dependbin)
1634
1676
  option('package-lock', 'lockfile', prefix: prefix, equals: '0') || !option('no-lockfile', prefix: prefix).nil?
1635
1677
  end
1636
1678
 
1637
- def dryrun?(prefix = dependbin)
1679
+ def dryrun?(prefix: dependbin)
1638
1680
  super(target: @session, prefix: prefix)
1639
1681
  end
1640
1682
  end