squared 0.4.13 → 0.4.15

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.
@@ -3,7 +3,7 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Git
6
- GIT_REPO = {}
6
+ GIT_REPO = Workspace.hashobj
7
7
  GIT_PROTO = %r{^(?:https?|ssh|git|file)://}i.freeze
8
8
  private_constant :GIT_REPO, :GIT_PROTO
9
9
 
@@ -27,7 +27,7 @@ module Squared
27
27
  base = name
28
28
  @project.each_value { |proj| repo << proj if !proj.parent && check.call(proj) }
29
29
  else
30
- warn log_message(Logger::WARN, name, subject: 'git', hint: 'invalid', pass: true) if warning
30
+ warn log_message(Logger::WARN, name, subject: 'git', hint: 'invalid') if warning
31
31
  return self
32
32
  end
33
33
  if base
@@ -58,8 +58,8 @@ module Squared
58
58
  end
59
59
  end
60
60
  key = task_name key
61
- (GIT_REPO[main] ||= {})[key] = [uri.to_s, opts]
62
- (@kind[key] ||= []) << Project::Git
61
+ GIT_REPO[main][key] = [uri.to_s, opts]
62
+ @kind[key] << Project::Git
63
63
  end
64
64
  if cache == true
65
65
  revbuild
@@ -340,7 +340,7 @@ module Squared
340
340
  'restore' => %i[source staged worktree].freeze,
341
341
  'rev' => %i[commit build output].freeze,
342
342
  'show' => %i[format oneline textconv].freeze,
343
- 'stash' => %i[push pop apply drop clear list].freeze,
343
+ 'stash' => %i[push pop apply branch drop clear list].freeze,
344
344
  'switch' => %i[create detach merge].freeze,
345
345
  'tag' => %i[add sign delete list].freeze
346
346
  })
@@ -367,13 +367,13 @@ module Squared
367
367
  case action
368
368
  when 'pull', 'fetch'
369
369
  if flag == :remote
370
- format_desc action, flag, 'remote,opts*'
370
+ format_desc action, flag, 'remote?,opts*'
371
371
  task flag, [:remote] do |_, args|
372
372
  if (remote = args.remote)
373
373
  args = args.extras
374
374
  else
375
375
  remote = choice_remote
376
- args = args.to_a.drop(1)
376
+ args = args.to_a
377
377
  end
378
378
  __send__(action, flag, args, remote: remote)
379
379
  end
@@ -396,12 +396,12 @@ module Squared
396
396
  if flag == :fixup
397
397
  ref, squash, pick = choice_commit(accept: [['Auto squash?', true]], reflog: false,
398
398
  values: ['Pick [amend|reword]'])
399
- pick = case pick&.downcase
400
- when 'a', 'amend'
401
- 'amend'
402
- when 'r', 'reword'
403
- 'reword'
404
- end
399
+ pick &&= case pick.downcase
400
+ when 'a', 'amend'
401
+ 'amend'
402
+ when 'r', 'reword'
403
+ 'reword'
404
+ end
405
405
  if squash
406
406
  found = false
407
407
  git_spawn(git_output('log --format=%h'), stdout: false).each do |val|
@@ -413,12 +413,14 @@ module Squared
413
413
  end
414
414
  end
415
415
  end
416
- refs = pick == 'reword' ? [] : param_guard(action, flag, args: args.to_a)
417
- if flag == :add
418
- opts = refs
419
- refs = []
420
- else
421
- opts = []
416
+ opts = []
417
+ refs = []
418
+ unless pick == 'reword'
419
+ if flag == :add
420
+ opts = param_guard(action, flag, args: args.to_a)
421
+ elsif (refs = args.to_a).empty?
422
+ refs = readline('Enter file patterns', force: true).shellsplit
423
+ end
422
424
  end
423
425
  commit(flag, opts, refs: refs, ref: ref, squash: squash, pick: pick)
424
426
  end
@@ -459,6 +461,7 @@ module Squared
459
461
  when 'stash'
460
462
  format_desc(action, flag, 'opts*', after: case flag
461
463
  when :push then 'pathspec*'
464
+ when :branch then 'name,stash?|:'
462
465
  when :clear, :list then nil
463
466
  else 'stash?|:' end)
464
467
  task flag do |_, args|
@@ -927,7 +930,7 @@ module Squared
927
930
  source(sync: sync, sub: if verbose
928
931
  [
929
932
  { pat: /^(.+)(\|\s+\d+\s+)([^-]*)(-+)(.*)$/, styles: color(:red), index: 4 },
930
- { pat: /^(.+)(\|\s+\d+\s+)(\++)(-*)(.*)$/, styles: color(:green), index: 3 }
933
+ { pat: /^(.+)(\|\s+\d+\s+)(\++)(.*)$/, styles: color(:green), index: 3 }
931
934
  ]
932
935
  end, **threadargs)
933
936
  end
@@ -942,7 +945,7 @@ module Squared
942
945
  return unless upstream
943
946
 
944
947
  op = OptionPartition.new(opts, OPT_GIT[:rebase], cmd, project: self, no: OPT_GIT[:no][:rebase])
945
- cmd << shell_escape(upstream)
948
+ cmd << upstream
946
949
  append_head op.shift
947
950
  op.clear(pass: false)
948
951
  when :onto
@@ -950,7 +953,7 @@ module Squared
950
953
 
951
954
  cmd << '--interactive' if option('interactive', 'i')
952
955
  cmd << shell_option('onto', commit) if commit
953
- cmd << shell_escape(upstream)
956
+ cmd << upstream
954
957
  append_head branch
955
958
  else
956
959
  return unless VAL_GIT[:rebase][:send].include?(command)
@@ -1012,12 +1015,26 @@ module Squared
1012
1015
  case flag
1013
1016
  when :push
1014
1017
  append_pathspec op.extras
1015
- when :pop, :apply, :drop
1018
+ when :pop, :apply, :drop, :branch
1016
1019
  if op.extras.delete(':')
1017
- op << choice_index('Choose a stash', git_spawn('stash list', stdout: false),
1018
- column: /^[^@]+@\{(\d+)\}/, force: true)
1020
+ if flag == :branch
1021
+ if op.empty?
1022
+ values = [['Branch name', true]]
1023
+ else
1024
+ op << op.pop
1025
+ end
1026
+ end
1027
+ out = choice_index('Choose a stash', git_spawn('stash list', stdout: false),
1028
+ values: values, column: /^[^@]+@\{(\d+)\}/, force: true)
1029
+ if values
1030
+ op.merge(out.reverse)
1031
+ else
1032
+ op << out
1033
+ end
1019
1034
  elsif !op.empty?
1020
- op << shell_escape(op.pop)
1035
+ op << op.pop
1036
+ elsif flag == :branch
1037
+ raise_error 'no branch name'
1021
1038
  end
1022
1039
  op.clear
1023
1040
  when :clear
@@ -1079,8 +1096,8 @@ module Squared
1079
1096
  def revbuild(flag = nil, opts = [], sync: nil, **kwargs)
1080
1097
  statusargs = lambda do
1081
1098
  {
1082
- include: relativepath(as_a(kwargs[:include]), all: true),
1083
- exclude: relativepath(as_a(kwargs[:exclude]), all: true)
1099
+ include: relativepath(Array(kwargs[:include]), all: true),
1100
+ exclude: relativepath(Array(kwargs[:exclude]), all: true)
1084
1101
  }
1085
1102
  end
1086
1103
  unless workspace.closed
@@ -1189,13 +1206,14 @@ module Squared
1189
1206
  else
1190
1207
  op = OptionPartition.new(opts, OPT_GIT[:checkout], cmd, project: self, no: OPT_GIT[:no][:checkout],
1191
1208
  first: flag == :path ? matchpathspec : nil)
1192
- if flag == :commit
1193
- op.append(commit)
1194
- .clear(pass: false)
1195
- else
1209
+ if flag == :path
1196
1210
  append_head
1197
1211
  append_pathspec(op.extras, pass: false)
1212
+ print_success if success?(source)
1213
+ return
1198
1214
  end
1215
+ op.append(commit)
1216
+ .clear(pass: false)
1199
1217
  end
1200
1218
  source
1201
1219
  end
@@ -1235,9 +1253,9 @@ module Squared
1235
1253
 
1236
1254
  def log!(flag, opts = [], range: [], index: [])
1237
1255
  cmd, opts = git_session('log', opts: opts)
1238
- op = OptionPartition.new(opts, collect_hash(OPT_GIT[:log]), cmd,
1239
- project: self, no: collect_hash(OPT_GIT[:no][:log]),
1240
- first: matchpathspec)
1256
+ op = OptionPartition.new(opts, collect_hash(OPT_GIT[:log]), cmd, project: self,
1257
+ no: collect_hash(OPT_GIT[:no][:log]),
1258
+ first: matchpathspec)
1241
1259
  case flag
1242
1260
  when :between, :contain
1243
1261
  op << shell_quote(range.join(flag == :between ? '..' : '...'))
@@ -1624,19 +1642,20 @@ module Squared
1624
1642
  red = color(:red)
1625
1643
  grep.map! { |val| Regexp.new(val[1..-2]) }
1626
1644
  files = status_data.map! do |a, b|
1627
- next unless grep.empty? || grep.any? { |pat| pat.match?(a) }
1645
+ next if b.strip.empty? || (!grep.empty? && grep.none? { |pat| pat.match?(a) })
1628
1646
 
1629
1647
  "#{sub_style(b, styles: red)} #{a}"
1630
1648
  end
1631
1649
  .compact
1632
1650
  unless files.empty?
1633
1651
  files = choice_index('Select files', files, multiple: true, force: true, trim: /^\S+\s/,
1634
- accept: 'Add?')
1652
+ accept: [['Add?', false, true]])
1635
1653
  end
1636
1654
  op.swap(list + files)
1637
1655
  end
1638
1656
  end
1639
- append_pathspec(op.extras)
1657
+ return source(git_session('status', '-s'), banner: false) unless append_pathspec(op.extras)
1658
+
1640
1659
  verbose = flag == :add && !op.arg?('verbose')
1641
1660
  print_success if success?(source) && verbose
1642
1661
  return
@@ -1665,30 +1684,36 @@ module Squared
1665
1684
  private
1666
1685
 
1667
1686
  def source(cmd = @session, exception: true, io: false, sync: true, stdout: false, stderr: false, banner: true,
1668
- multiple: false, **kwargs)
1687
+ multiple: false, from: nil, **kwargs)
1669
1688
  cmd = cmd.target if cmd.is_a?(OptionPartition)
1670
- banner = nil if banner && (multiple || !banner?)
1671
- if cmd.respond_to?(:done)
1672
- if io && banner == false
1673
- from = nil
1674
- elsif !from && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z\-]*\z/) })
1675
- from = :"git:#{from}"
1689
+ if io && banner == false
1690
+ from = nil
1691
+ banner = nil
1692
+ else
1693
+ banner = nil if banner && (multiple || !banner?)
1694
+ if cmd.respond_to?(:done)
1695
+ if from.nil? && (from = cmd.drop(1).find { |val| val.match?(/\A[a-z]{1,2}[a-z\-]*\z/) })
1696
+ from = :"git:#{from}"
1697
+ end
1698
+ banner &&= cmd.temp { |val| val.start_with?('--work-tree') || val.start_with?('--git-dir') }
1676
1699
  end
1677
- banner &&= cmd.temp { |val| val.start_with?('--work-tree') || val.start_with?('--git-dir') }
1700
+ from = nil if from == false
1678
1701
  end
1679
1702
  cmd = session_done cmd
1680
1703
  log&.info cmd
1681
- on :first, from
1682
1704
  banner = if banner
1683
1705
  format_banner((banner.is_a?(String) ? banner : cmd).gsub(File.join(path, ''), ''), banner: true)
1684
1706
  end
1707
+ on :first, from
1685
1708
  begin
1686
1709
  if io
1687
- return `#{cmd}` if stdout
1688
-
1689
- return banner ? [IO.popen(cmd), banner, from] : IO.popen(cmd)
1690
- end
1691
- if stdin? ? sync : stdout
1710
+ ret = if stdout
1711
+ `#{cmd}`
1712
+ else
1713
+ banner ? [IO.popen(cmd), banner, from] : IO.popen(cmd)
1714
+ end
1715
+ return ret
1716
+ elsif stdin? ? sync : stdout
1692
1717
  print_item banner unless multiple
1693
1718
  ret = `#{cmd}`
1694
1719
  if !ret.empty?
@@ -1696,7 +1721,7 @@ module Squared
1696
1721
  elsif success?(!banner.nil?)
1697
1722
  print_success
1698
1723
  end
1699
- elsif sync || (!exception && !stderr)
1724
+ elsif !kwargs[:sub] && (sync || (!exception && !stderr))
1700
1725
  print_item banner unless multiple
1701
1726
  ret = shell(cmd, exception: exception)
1702
1727
  else
@@ -1889,6 +1914,7 @@ module Squared
1889
1914
  def append_pathspec(files = [], target: @session, expect: false, parent: false, pass: true)
1890
1915
  if session_arg?('pathspec-from-file', target: target)
1891
1916
  option_clear files
1917
+ true
1892
1918
  else
1893
1919
  if files.empty? && (val = option('pathspec', target: target))
1894
1920
  files = split_escape val
@@ -1896,8 +1922,11 @@ module Squared
1896
1922
  files = projectmap(files, parent: parent, pass: pass)
1897
1923
  if !files.empty?
1898
1924
  target << '--' << files.join(' ')
1925
+ true
1899
1926
  elsif expect
1900
1927
  raise_error(parent ? 'pathspec not present' : 'pathspec not within worktree')
1928
+ else
1929
+ false
1901
1930
  end
1902
1931
  end
1903
1932
  end
@@ -1940,8 +1969,10 @@ module Squared
1940
1969
  end
1941
1970
 
1942
1971
  def foreachref(path, *args, format: nil)
1943
- path = as_a(path).map! { |val| "refs/#{val}" }
1944
- git_spawn('for-each-ref', format && quote_option('format', format), *args, *path, stdout: false)
1972
+ path = Array(path).map! { |val| "refs/#{val}" }
1973
+ format &&= quote_option('format', format)
1974
+ ret = git_spawn('for-each-ref', format, *args, *path, stdout: workspace.windows?)
1975
+ ret.is_a?(String) ? ret.lines : ret
1945
1976
  end
1946
1977
 
1947
1978
  def git_session(*cmd, opts: nil, worktree: true, **kwargs)
@@ -1979,8 +2010,8 @@ module Squared
1979
2010
 
1980
2011
  def repotrack(origin, branch, quote: true)
1981
2012
  i = origin.index('/')
1982
- branch = "#{branch}:#{origin[i + 1..-1]}" unless origin.end_with?("/#{branch}")
1983
- ret = [origin[0..i - 1], branch]
2013
+ branch = "#{branch}:#{origin[(i + 1)..-1]}" unless origin.end_with?("/#{branch}")
2014
+ ret = [origin[0..(i - 1)], branch]
1984
2015
  quote ? ret.map! { |val| shell_quote(val) } : ret
1985
2016
  end
1986
2017
 
@@ -134,7 +134,7 @@ module Squared
134
134
  end
135
135
  case save
136
136
  when 'prod', 'dev', 'optional', 'peer'
137
- packages = args.to_a.drop(1)
137
+ packages = args.extras
138
138
  else
139
139
  save = 'prod'
140
140
  packages = args.to_a
@@ -145,10 +145,10 @@ module Squared
145
145
  when 'run'
146
146
  next if (list = read_scripts).empty?
147
147
 
148
- format_desc action, nil, 'script,opts*|^index+|#,pattern*'
148
+ format_desc action, nil, "script,opts*|#{indexchar}index+|#,pattern*"
149
149
  task action, [:script] do |_, args|
150
150
  if args.script == '#'
151
- format_list(list, 'run[^N]', 'scripts', grep: args.extras, from: dependfile.to_s)
151
+ format_list(list, "run[#{indexchar}N]", 'scripts', grep: args.extras, from: dependfile)
152
152
  else
153
153
  args = param_guard(action, 'script', args: args.to_a)
154
154
  opts = []
@@ -185,7 +185,7 @@ module Squared
185
185
  format_desc action, nil, 'pkg/cmd,opts*,args*'
186
186
  task action, [:package] do |_, args|
187
187
  if (package = args.package)
188
- args = args.to_a.drop(1)
188
+ args = args.extras
189
189
  if pnpm?
190
190
  pre = ->(ch) { "-#{ch}" if (ch = args.delete(ch)) }
191
191
  cmd = session 'pnpm', pre.call('r'), pre.call('c'), 'exec'
@@ -226,7 +226,7 @@ module Squared
226
226
  outdated flag, args.to_a
227
227
  end
228
228
  when 'package'
229
- format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'names*')
229
+ format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'name*')
230
230
  task flag do |_, args|
231
231
  package flag, args.to_a
232
232
  end
@@ -336,7 +336,7 @@ module Squared
336
336
  next unless from && dest&.directory?
337
337
 
338
338
  from = path + from
339
- glob = as_a(glob || '**/*')
339
+ glob = Array(glob || '**/*')
340
340
  target = []
341
341
  if workspace
342
342
  Dir.glob(from + '*').each do |path|
@@ -448,7 +448,7 @@ module Squared
448
448
  ret = on(:error, :outdated, e)
449
449
  raise if exception && ret != true
450
450
  end
451
- warn log_message(Logger::WARN, e, pass: true) if warning?
451
+ warn log_message(Logger::WARN, e) if warning?
452
452
  return
453
453
  else
454
454
  dep1 = json['dependencies'] || {}
@@ -596,50 +596,43 @@ module Squared
596
596
  end
597
597
 
598
598
  def update(*)
599
- package 'update'
599
+ package('update', from: :update)
600
600
  end
601
601
 
602
602
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil, access: nil)
603
- if read_packagemanager(:private)
604
- if warning?
605
- warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: 'private', pass: true)
606
- end
603
+ if !version || read_packagemanager(:private)
604
+ warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: version ? 'private' : nil)
607
605
  return
608
606
  end
609
- return unless version
610
-
611
607
  cmd = session 'npm', 'publish'
612
- dryrun = dryrun?('npm') if dryrun.nil?
613
608
  cmd << basic_option('otp', otp) if otp ||= option('otp')
614
609
  cmd << basic_option('tag', tag) if tag ||= option('tag')
615
610
  cmd << basic_option('access', access) if access ||= option('access')
616
- if verbose
617
- if dryrun
618
- cmd << '--dry-run'
619
- else
620
- log.info cmd.to_s
621
- end
622
- unless sync
623
- on :first, :publish unless dryrun
624
- pwd_set(from: :publish, dryrun: dryrun) do
625
- require 'open3'
626
- banner = format_banner(cmd.to_s)
627
- Open3.popen2e(cmd.done) do |_, out|
628
- write_lines(out, banner: banner, sub: npmnotice + [
629
- { pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2 }
630
- ])
631
- end
611
+ dryrun = dryrun?('npm') if dryrun.nil?
612
+ if dryrun
613
+ cmd << '--dry-run'
614
+ else
615
+ from = :publish
616
+ log.info cmd.to_s
617
+ end
618
+ if sync
619
+ run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(project, styles: theme[:active])}")
620
+ else
621
+ on :first, from
622
+ pwd_set(from: :publish, dryrun: dryrun) do
623
+ require 'open3'
624
+ banner = format_banner(cmd.to_s)
625
+ Open3.popen2e(cmd.done) do |_, out|
626
+ write_lines(out, banner: banner, sub: npmnotice + [
627
+ { pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2 }
628
+ ])
632
629
  end
633
- on :last, :publish unless dryrun
634
- return
635
630
  end
636
- elsif dryrun
637
- return
631
+ on :last, from
638
632
  end
639
- run(from: :publish, sync: sync)
640
633
  end
641
634
 
642
- def package(flag, opts = [])
635
+ def package(flag, opts = [], from: nil)
643
636
  workspace.rev_clear(name)
644
637
  if (yarn = dependtype(:yarn)) > 0
645
638
  cmd = session 'yarn', if flag == :update
@@ -665,6 +658,7 @@ module Squared
665
658
  list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
666
659
  list.concat(OPT_NPM[:install_as]) unless flag == :dedupe
667
660
  no = OPT_NPM[:install_no]
661
+ cmd << '--save=true' if option('save')
668
662
  end
669
663
  op = OptionPartition.new(opts, list, cmd, no: no, project: self)
670
664
  op.each do |opt|
@@ -689,7 +683,7 @@ module Squared
689
683
  end
690
684
  op.clear(errors: true)
691
685
  end
692
- run(from: :"package:#{flag}")
686
+ run(from: from || :"package:#{flag}")
693
687
  end
694
688
 
695
689
  def bump(flag, val = nil)
@@ -906,9 +900,11 @@ module Squared
906
900
  @pm[:_] = false
907
901
  nil
908
902
  else
909
- return @pm[key] if key
910
-
911
- !(ret = @pm[:_]) || (version && ret[ret.index('@') + 1..-1] < version) ? nil : ret
903
+ if key
904
+ @pm[key]
905
+ elsif (ret = @pm[:_]) && !(version && ret[(ret.index('@') + 1)..-1] < version)
906
+ ret
907
+ end
912
908
  end
913
909
 
914
910
  def read_install