squared 0.8.7 → 0.9.0.pre1

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.
@@ -53,7 +53,7 @@ module Squared
53
53
  opts = options
54
54
  val.is_a?(String) ? val : key.to_s
55
55
  end
56
- unless uri.match?(GIT_PROTO) || Pathname.new(uri).absolute?
56
+ unless uri.match?(GIT_PROTO) || File.absolute_path?(uri)
57
57
  if uri.start_with?('.')
58
58
  uri = rootpath uri
59
59
  elsif base
@@ -135,8 +135,7 @@ module Squared
135
135
  def rev_write(name = nil, data = nil, sync: true, utc: nil)
136
136
  return unless @revfile
137
137
 
138
- sleep 0 while !sync && @revlock
139
- @revlock = true
138
+ (@revlock ||= Monitor.new).enter unless sync
140
139
  if name
141
140
  data&.each { |key, val| rev_entry(name, key, val: val) }
142
141
  rev_timeutc(name, utc) if utc
@@ -145,7 +144,7 @@ module Squared
145
144
  rescue => e
146
145
  warn log_warn(e, pass: true) if warning
147
146
  ensure
148
- @revlock = false
147
+ @revlock.exit unless sync
149
148
  end
150
149
  end
151
150
 
@@ -204,6 +203,8 @@ module Squared
204
203
  X|strategy-option=b].freeze,
205
204
  rm: %w[r cached f|force n|dry-run ignore-unmatch pathspec-file-nul q|quiet sparse
206
205
  pathspec-from-file=p].freeze,
206
+ show: %w[t combined-all-paths no-diff-merges remerge-diff show-notes-by-default show-signature diff-merges=b
207
+ encoding=b expand-tabs=i notes=q show-notes=q?].freeze,
207
208
  'sparse-checkout': %w[cone sparse-index no-cone no-sparse-index skip-checks].freeze
208
209
  }.freeze,
209
210
  log: {
@@ -270,8 +271,6 @@ module Squared
270
271
  branches=q? default=q disambiguate=b exclude=q exclude-hidden=b git-path=p glob=q
271
272
  output-object-format=b path-format=b? prefix=q remotes=q? resolve-git-dir=p short=i?
272
273
  show-object-format=b? since=q tags=q? until=q].freeze,
273
- show: %w[t combined-all-paths no-diff-merges remerge-diff show-notes-by-default show-signature diff-merges=b
274
- encoding=b expand-tabs=i notes=q show-notes=q?].freeze,
275
274
  sparse_checkout: {
276
275
  add: %w[skip-checks].freeze,
277
276
  clean: %w[n f v].freeze
@@ -370,7 +369,7 @@ module Squared
370
369
  'range-diff' => %i[view between contain].freeze,
371
370
  'fetch' => %i[origin remote all].freeze,
372
371
  'files' => %i[cached modified deleted others].freeze,
373
- 'git' => %i[add blame clean grep mv revert rm sparse-checkout status].freeze,
372
+ 'git' => %i[add blame clean grep mv revert rm show sparse-checkout status].freeze,
374
373
  'log' => %i[grep view between contain].freeze,
375
374
  'merge' => %i[commit no-commit send].freeze,
376
375
  'pull' => %i[origin remote all].freeze,
@@ -381,7 +380,6 @@ module Squared
381
380
  'reset' => %i[commit index patch mode undo].freeze,
382
381
  'restore' => %i[source staged worktree].freeze,
383
382
  'rev' => %i[commit branch build output].freeze,
384
- 'show' => %i[format oneline textconv].freeze,
385
383
  'sparse-checkout' => %i[add reapply list clean disable].freeze,
386
384
  'stash' => %i[push pop apply drop command].freeze,
387
385
  'submodule' => %i[status update branch url sync].freeze,
@@ -814,11 +812,6 @@ module Squared
814
812
  end
815
813
  branch(flag, refs: refs, remote: remote)
816
814
  end
817
- when :list
818
- format_desc action, flag, 'opts*,pattern*'
819
- task flag do |_, args|
820
- branch flag, args.to_a
821
- end
822
815
  when :move, :copy
823
816
  format_desc action, flag, 'branch,oldbranch?'
824
817
  task flag, [:branch, :oldbranch] do |_, args|
@@ -832,9 +825,9 @@ module Squared
832
825
  branch(flag, refs: [oldbranch, branch])
833
826
  end
834
827
  else
835
- format_desc action, flag
836
- task flag do
837
- branch flag
828
+ format_desc(action, flag, ('opts*,pattern*' if flag == :list))
829
+ task flag do |_, args|
830
+ branch flag, args.to_a
838
831
  end
839
832
  end
840
833
  when 'clone'
@@ -914,25 +907,6 @@ module Squared
914
907
  reset flag
915
908
  end
916
909
  end
917
- when 'show'
918
- case flag
919
- when :oneline
920
- format_desc action, flag, 'opts*,object*'
921
- task flag do |_, args|
922
- show flag, args.to_a
923
- end
924
- when :format
925
- format_desc action, flag, 'format?,opts*,object*'
926
- task flag, [:format] do |_, args|
927
- show(flag, args.extras, format: args.format)
928
- end
929
- when :textconv
930
- format_desc action, flag, 'files+'
931
- task flag do |_, args|
932
- files = param_guard(action, flag, args: args.to_a)
933
- show(flag, files: files)
934
- end
935
- end
936
910
  when 'rebase', 'merge'
937
911
  case flag
938
912
  when :branch
@@ -968,13 +942,10 @@ module Squared
968
942
  when :commit, :'no-commit'
969
943
  format_desc action, flag, 'branch|:,ours|theirs?,opts*'
970
944
  task flag, [:branch] do |_, args|
971
- branch = if args.branch == ':'
972
- choice_refs('Choose a branch', accept: "#{action.capitalize}?")
973
- else
974
- args.branch
975
- end
976
- current = git_value 'branch --show-current'
945
+ branch = args.branch
946
+ current = git_spawn('branch --show-current').chomp
977
947
  if branch
948
+ branch = choice_refs('Choose a branch', accept: "#{action.capitalize}?") if branch == ':'
978
949
  opts = args.extras
979
950
  if has_value!(opts, 'ours')
980
951
  opts << 's=ort' << 'X=ours'
@@ -1007,7 +978,7 @@ module Squared
1007
978
  task flag, [:ref, :size] do |_, args|
1008
979
  ref = commithead args.ref
1009
980
  size = args.size
1010
- if !size && ref.to_i.between?(4, 40)
981
+ if !size && ref.to_i.between?(4, 64)
1011
982
  size = ref
1012
983
  ref = nil
1013
984
  end
@@ -1106,7 +1077,7 @@ module Squared
1106
1077
  git(:remote, args.extras, extras: [name, url])
1107
1078
  end
1108
1079
  else
1109
- format_desc(action, flag, 'opts*', before: OPT_GIT[:remote])
1080
+ format_desc action, flag, "#{OPT_GIT[:remote].keys.join('|')},opts*" if TASK_METADATA
1110
1081
  task flag, [:command] do |_, args|
1111
1082
  command = param_guard(action, flag, args: args, key: :command)
1112
1083
  cmd, opts = git_session('remote', opts: args.extras)
@@ -1148,6 +1119,8 @@ module Squared
1148
1119
  'source+,destination'
1149
1120
  when :revert
1150
1121
  'commit+'
1122
+ when :show
1123
+ 'format?'
1151
1124
  end
1152
1125
  after = case flag
1153
1126
  when :add
@@ -1158,6 +1131,8 @@ module Squared
1158
1131
  'dir+'
1159
1132
  when :clean, :rm, :status
1160
1133
  'pathspec*'
1134
+ when :show
1135
+ 'object*'
1161
1136
  end
1162
1137
  format_desc(action, flag, 'opts*', before: before, after: after)
1163
1138
  task flag do |_, args|
@@ -1226,7 +1201,7 @@ module Squared
1226
1201
  (heads.dup << cur).each_with_index do |branch, i|
1227
1202
  next unless (i < heads.size && cur != branch) || i == heads.size
1228
1203
 
1229
- git_spawn('switch --quiet', force && '--force', shell_quote(branch))
1204
+ git_spawn 'switch --quiet', force && '--force', shell_quote(branch)
1230
1205
  pull(nil, opts, sync: false, hint: branch) if heads.include?(branch)
1231
1206
  end
1232
1207
  return
@@ -1302,13 +1277,13 @@ module Squared
1302
1277
  if flag
1303
1278
  return unless dir && ref
1304
1279
 
1305
- url = git_value "config --get remote.#{remotetrack}.url"
1280
+ url = git_spawn("config --get remote.#{remotetrack}.url")
1306
1281
  cmd, opts = git_session('clone', worktree: false, opts: opts)
1307
1282
  op = OptionPartition.new(opts, OPT_GIT[:clone], cmd, project: self, strict: strict?,
1308
1283
  no: OPT_GIT[:no][:clone])
1309
1284
  op.add_option('b', ref)
1310
1285
  .delim
1311
- .add_quote(url)
1286
+ .add_quote(url.chomp)
1312
1287
  .add_path(dir)
1313
1288
  .clear
1314
1289
  source
@@ -1501,7 +1476,7 @@ module Squared
1501
1476
  end
1502
1477
  return
1503
1478
  end
1504
- sha = git_value 'rev-parse --verify HEAD'
1479
+ sha = git_spawn('rev-parse --verify HEAD').chomp
1505
1480
  return if sha.empty?
1506
1481
 
1507
1482
  sync = kwargs.fetch(:sync) { invoked_sync?('revbuild', flag) }
@@ -1522,7 +1497,7 @@ module Squared
1522
1497
  run_p(*Array(kwargs[:before]), sync: sync, from: symjoin(from, 'before')) if kwargs[:before]
1523
1498
  force = if (force = env('REVBUILD_FORCE', strict: true))
1524
1499
  force != '0' && force != 'false'
1525
- elsif (force = ENV['GIT_FORCE'] || ENV['REVBUILD_FORCE'])
1500
+ elsif (force = env('GIT_FORCE', suffix: false) || env('REVBUILD_FORCE', suffix: false))
1526
1501
  split_escape(force).any? { |val| val == '1' || val == 'true' || val == name }
1527
1502
  end
1528
1503
  if !force && (cur = workspace.rev_entry(name)) && cur['revision'] == sha
@@ -1564,7 +1539,7 @@ module Squared
1564
1539
  .clear(pass: false)
1565
1540
  when :commit
1566
1541
  exit 1 unless ref
1567
- branch ||= git_value('name-rev --name-only', ref)
1542
+ branch ||= git_spawn('name-rev --name-only', ref).chomp
1568
1543
  raise ArgumentError, message('could not resolve upstream branch', hint: ref) if branch.empty?
1569
1544
 
1570
1545
  op.append(remotetrack, "#{ref}:#{branch}")
@@ -1759,7 +1734,7 @@ module Squared
1759
1734
  end
1760
1735
  if (n = op.index('>'))
1761
1736
  patch = op.slice!(n, 2)[1]
1762
- elsif !op.last.include?('*') && !op.exist?(op.last)
1737
+ elsif !op.exist?(op.last)
1763
1738
  patch ||= op.pop
1764
1739
  end
1765
1740
  append_pathspec op.extras
@@ -1865,8 +1840,7 @@ module Squared
1865
1840
  if adding.empty? && !cached.empty? && banner?
1866
1841
  puts(cached.lines(chomp: true).map { |val| "cached #{shell_quote(val)}" })
1867
1842
  end
1868
- source co
1869
- source pu
1843
+ ENV['COMMIT_PUSH'] = git_spawn 'rev-parse --verify HEAD' if source(co) && source(pu) && !dryrun?
1870
1844
  else
1871
1845
  if banner?
1872
1846
  puts 'Nothing to commit'
@@ -1966,13 +1940,13 @@ module Squared
1966
1940
  print_item banner
1967
1941
  ret = write_lines(out, sub: [
1968
1942
  opt_style(color(:green), /^(\*\s+)(\S+)(.*)$/, 2),
1943
+ opt_style(color(:blue), /^(.+)((?<=\[)[^\]]+(?=\]))(.*)$/, 2),
1969
1944
  opt_style(color(:red), %r{^(\s*)(remotes/\S+)(.*)$}, 2)
1970
1945
  ])
1971
1946
  list_result(ret, 'branches', banner: banner, from: from)
1972
1947
  return
1973
1948
  else
1974
- head = git_value 'rev-parse --abbrev-ref HEAD'
1975
- if head.empty?
1949
+ if (head = git_spawn('rev-parse --abbrev-ref HEAD').chomp).empty?
1976
1950
  ret = 0
1977
1951
  else
1978
1952
  git_spawn 'fetch --all --prune --quiet' if option('sync')
@@ -2057,35 +2031,6 @@ module Squared
2057
2031
  source(sync: false, stderr: true)
2058
2032
  end
2059
2033
 
2060
- def show(flag, opts = [], format: nil, files: [])
2061
- cmd, opts = git_session('show', opts: opts)
2062
- case flag
2063
- when :textconv
2064
- cmd << '--textconv'
2065
- append_value(files.flat_map { |val| Dir[val] }
2066
- .select { |val| projectpath?(val) }
2067
- .map { |val| "HEAD:#{val}" })
2068
- source(banner: false)
2069
- return
2070
- when :oneline
2071
- format = flag.to_s
2072
- end
2073
- case format
2074
- when 'oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
2075
- cmd << basic_option('format', format)
2076
- when /^t?format:|%/
2077
- cmd << quote_option('pretty', format)
2078
- else
2079
- opts << format if format
2080
- end
2081
- list = OPT_GIT[:show] + OPT_GIT[:diff][:show] + collect_hash(OPT_GIT[:log], pass: [:base])
2082
- op = OptionPartition.new(opts, list, cmd,
2083
- project: self, strict: strict?,
2084
- no: OPT_GIT[:no][:show] + collect_hash(OPT_GIT[:no][:log], pass: [:base]))
2085
- op.append
2086
- source(exception: false, banner: flag != :oneline)
2087
- end
2088
-
2089
2034
  def rev_parse(flag, opts = [], ref: nil, size: nil)
2090
2035
  cmd, opts = git_session('rev-parse', opts: opts)
2091
2036
  case flag
@@ -2099,7 +2044,7 @@ module Squared
2099
2044
  else
2100
2045
  ref
2101
2046
  end)
2102
- return git_value(cmd, exception: false)
2047
+ return git_spawn(cmd, exception: false).chomp
2103
2048
  when :output
2104
2049
  if opts.delete('sq-quote')
2105
2050
  cmd << '--sq-quote'
@@ -2149,18 +2094,28 @@ module Squared
2149
2094
 
2150
2095
  def git(flag, opts = [], extras: [])
2151
2096
  cmd, opts = git_session(flag, opts: opts)
2152
- list = OPT_GIT[:git].fetch(flag, []) + OPT_GIT.fetch(flag, []).yield_self { |a| a.is_a?(Array) ? a : [] }
2097
+ list = OPT_GIT[:git].fetch(flag, []) + OPT_GIT.fetch(flag, []).then { |a| a.is_a?(Array) ? a : [] }
2098
+ no = OPT_GIT[:no].fetch(flag, [])
2153
2099
  case flag
2154
2100
  when :add
2155
2101
  list.concat(OPT_GIT[:log][:diff_context])
2156
2102
  when :revert
2157
2103
  list.concat(VAL_GIT[:rebase][:send])
2104
+ when :show
2105
+ list.concat(OPT_GIT[:diff][:show], collect_hash(OPT_GIT[:log], pass: [:base]))
2106
+ no += collect_hash(OPT_GIT[:no][:log], pass: [:base])
2107
+ case opts.first
2108
+ when 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
2109
+ cmd << basic_option('format', opts.shift)
2110
+ when /^t?format:|%/
2111
+ cmd << quote_option('pretty', opts.shift)
2112
+ end
2158
2113
  when :'sparse-checkout'
2159
2114
  cmd << 'set'
2160
2115
  end
2161
- op = OptionPartition.new(opts, list, cmd, project: self, strict: strict?, no: OPT_GIT[:no][flag],
2116
+ op = OptionPartition.new(opts, list, cmd, project: self, strict: strict?, no: no,
2162
2117
  first: case flag
2163
- when :blame, :revert, :'sparse-checkout' then nil
2118
+ when :blame, :revert, :show, :'sparse-checkout' then nil
2164
2119
  else matchpathspec
2165
2120
  end)
2166
2121
  case flag
@@ -2226,6 +2181,20 @@ module Squared
2226
2181
  op.add_quote(val)
2227
2182
  end
2228
2183
  end
2184
+ when :show
2185
+ if op.arg?('textconv')
2186
+ op.each do |val|
2187
+ files = Dir[val]
2188
+ if files.empty? || !files.all? { |path| projectpath?(path) }
2189
+ op.add_quote(val)
2190
+ else
2191
+ op.append(files.map { |path| "HEAD:#{path}" })
2192
+ end
2193
+ end
2194
+ else
2195
+ op.append
2196
+ end
2197
+ return source(exception: false, banner: !op.arg?('oneline', 'textconv'))
2229
2198
  end
2230
2199
  case flag
2231
2200
  when :revert, :mv, :rm
@@ -2341,7 +2310,9 @@ module Squared
2341
2310
  end
2342
2311
  args = []
2343
2312
  args << quote_option('sort', sort) if sort
2344
- args << basic_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
2313
+ if count && (count = env('GIT_COUNT') || ARG[:CHOICE]) && count != Float::INFINITY
2314
+ args << basic_option('count', count)
2315
+ end
2345
2316
  choice_index(msg, foreachref(type, *args, format: format), trim: trim, **kwargs)
2346
2317
  end
2347
2318
 
@@ -2349,11 +2320,13 @@ module Squared
2349
2320
  kwargs[:attempts] ||= 1 unless force
2350
2321
  cmd = git_output(reflog && env('GIT_REFLOG') ? 'reflog' : 'log', range)
2351
2322
  cmd << quote_option('format', "#{commitstyle('%h')} %s")
2352
- cmd << basic_option('max-count', env('GIT_COUNT', ARG[:CHOICE])) if count
2323
+ if count && (count = env('GIT_COUNT') || ARG[:CHOICE]) && count != Float::INFINITY
2324
+ cmd << basic_option('max-count', count)
2325
+ end
2353
2326
  ret = choice_index(msg, git_spawn(cmd, stdout: false), column: /^(\S+)/, force: force, **kwargs)
2354
2327
  case ret
2355
2328
  when Array
2356
- ret.map { |val| val.is_a?(Array) ? val.map { |s| s&.stripstyle } : val&.stripstyle }
2329
+ ret.map { |val| val&.stripstyle }
2357
2330
  when String
2358
2331
  ret.stripstyle
2359
2332
  else
@@ -2531,10 +2504,6 @@ module Squared
2531
2504
  stdout: stdout, banner: banner, **kwargs)
2532
2505
  end
2533
2506
 
2534
- def git_value(*cmd, exception: true)
2535
- git_spawn(*cmd, exception: exception).chomp
2536
- end
2537
-
2538
2507
  def git_grep(cmd, *grep, equals: true, **kwargs)
2539
2508
  ret = []
2540
2509
  git_spawn(cmd, **kwargs).lines(chomp: true).each do |line|
@@ -2578,8 +2547,8 @@ module Squared
2578
2547
  n = origin&.index('/')
2579
2548
  raise message("missing #{origin ? 'branch' : 'remote'} name", hint: origin) unless n && branch
2580
2549
 
2581
- branch = "#{branch}:#{origin[n.succ..-1]}" unless origin.end_with?("/#{branch}")
2582
- ret = [origin[0..n.pred], branch]
2550
+ branch = task_join branch, origin[n.succ..] unless origin.end_with?("/#{branch}")
2551
+ ret = [origin[...n], branch]
2583
2552
  ret.quote! if quote
2584
2553
  ret
2585
2554
  end
@@ -2589,7 +2558,7 @@ module Squared
2589
2558
  end
2590
2559
 
2591
2560
  def commithash(val)
2592
- val[/\A:(\h{5,40})\z/, 1]
2561
+ val[/\A:(\h{5,64})\z/, 1]
2593
2562
  end
2594
2563
 
2595
2564
  def commithead(val)
@@ -69,7 +69,7 @@ module Squared
69
69
  install: %w[check-cache check-resolutions immutable immutable-cache inline-builds json refresh-lockfile
70
70
  mode=b].freeze,
71
71
  add: %w[cached D|dev json O|optional P|peer prefer-dev].freeze,
72
- add_a: %w[C|caret E|exact F|fixed i|interactive no-time-gate T|tilde mode=b].freeze,
72
+ add_a: %w[C|caret E|exact F|fixed interactive T|tilde mode=b].freeze,
73
73
  update: %w[R|recursive].freeze,
74
74
  dedupe: %w[check json mode=b strategy=b].freeze,
75
75
  run: %w[B|binaries-only inspect inspect-brk T|top-level require=q].freeze,
@@ -104,6 +104,9 @@ module Squared
104
104
  build: %w[clean=!? dry=!? force=!? v|verbose=!?].freeze,
105
105
  watch: %w[excludeDirectories=p excludeFiles=p fallbackPolling=b synchronousWatchDirectory=!? watchDirectory=b
106
106
  watchFile=b].freeze,
107
+ v7: {
108
+ compiler: %w[builders=i checkers=i singleThreaded=!?]
109
+ },
107
110
  v5: {
108
111
  compiler: %w[allowSyntheticDefaultImports=!? alwaysStrict=!? baseUrl=p downlevelIteration=!?
109
112
  esModuleInterop=!? outFile=p].freeze
@@ -305,11 +308,13 @@ module Squared
305
308
  format_desc action, nil, 'version|pre?{major,minor,patch}|prerelease'
306
309
  task action, [:version] do |_, args|
307
310
  version = param_guard(action, 'to', args: args, key: :version)
308
- if version.match?(/^(pre)?(major|minor|patch)|prerelease$/)
309
- bump version.to_sym
311
+ if version.match?(/^((pre)?(major|minor|patch))|prerelease$/)
312
+ flag = version.to_sym
313
+ version = nil
310
314
  else
311
- bump :version, version
315
+ flag = :version
312
316
  end
317
+ bump flag, version
313
318
  end
314
319
  when 'pack'
315
320
  format_desc action, nil, 'opts*'
@@ -543,8 +548,7 @@ module Squared
543
548
  Open3.capture2e(cmd.to_s)
544
549
  .first
545
550
  .scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
546
- .map { |item| Pathname.new(item.first) }
547
- .select(&:exist?)
551
+ .filter_map { |item| item.first if File.exist?(item.first) }
548
552
  end.concat(Array(files))
549
553
  packed = true
550
554
  end
@@ -660,7 +664,7 @@ module Squared
660
664
  end
661
665
  if nolockfile?(prefix: 'yarn')
662
666
  cmd << '--no-lockfile'
663
- elsif option('ci') || (ci? && exist?(yarnlock))
667
+ elsif ci? && exist?('yarn.lock')
664
668
  if yarn == 1
665
669
  cmd << '--frozen-lockfile'
666
670
  elsif !flag
@@ -696,14 +700,13 @@ module Squared
696
700
  '--force'
697
701
  elsif nolockfile?(prefix: 'pnpm')
698
702
  '--no-lockfile'
699
- elsif option('ci') || (ci? && exist?(pnpmlock))
703
+ elsif ci? && exist?('pnpm-lock.yaml')
700
704
  '--frozen-lockfile'
701
705
  end
702
706
  cmd << '--ignore-scripts' if option('ignore-scripts')
703
707
  cmd << '--dangerously-allow-all-builds' if option('approve-builds')
704
708
  else
705
- ci = option('ci', prefix: 'npm') || (ci? && exist?(npmlock))
706
- cmd = session('npm', ci ? 'ci' : 'install')
709
+ cmd = session('npm', ci = ci? && exist?('package-lock.json') ? 'ci' : 'install')
707
710
  option('approve-scripts') do |val|
708
711
  cmd = npm_output 'approve-scripts'
709
712
  cmd << case val
@@ -756,7 +759,7 @@ module Squared
756
759
  append_platform
757
760
  end
758
761
  end
759
- cmd << '--package-lock=false' << '--save=false' if nolockfile?(prefix: 'npm')
762
+ cmd << '--package-lock=false' << 'save=false' if nolockfile?(prefix: 'npm')
760
763
  cmd << '--ignore-scripts' if option('ignore-scripts')
761
764
  end
762
765
  if add
@@ -769,7 +772,7 @@ module Squared
769
772
  end
770
773
 
771
774
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
772
- cmd = session(pnpm? && exist?(pnpmlock) ? 'pnpm' : 'npm', 'outdated')
775
+ cmd = session(pnpm? && exist?('pnpm-lock.yaml') ? 'pnpm' : 'npm', 'outdated')
773
776
  dryrun = has_value?(opts, 'd', 'dry-run') || dryrun?
774
777
  unless dryrun
775
778
  log.info cmd.to_s
@@ -813,7 +816,7 @@ module Squared
813
816
  latest = val['latest']
814
817
  ch = file[0]
815
818
  if ch.match?(/[~^]/)
816
- file = file[1..-1]
819
+ file = file[1..]
817
820
  elsif ia && flag == :major
818
821
  major = true
819
822
  else
@@ -958,7 +961,7 @@ module Squared
958
961
  (1..items.size)
959
962
  else
960
963
  choice('Select a package', items.map(&:first), multiple: true, force: false, index: true,
961
- border: true)
964
+ border: true, **parse_select)
962
965
  end.each do |n|
963
966
  item = items[n.pred].last
964
967
  doc.sub!(pat.call(item)) { edit.call(item, $1, $2) }
@@ -1037,7 +1040,7 @@ module Squared
1037
1040
  c = 0
1038
1041
  e = 0
1039
1042
  doc['files'].each do |item|
1040
- path = item['path'][n..-1]
1043
+ path = item['path'][n..]
1041
1044
  js = File.extname(path)
1042
1045
  next unless ext.empty? || ext.any? { |val| val == js }
1043
1046
 
@@ -1353,7 +1356,8 @@ module Squared
1353
1356
  b = kwargs[:build]
1354
1357
  w = kwargs[:watch]
1355
1358
  list = OPT_TSC[:base] + OPT_TSC[:compiler]
1356
- list.concat(Array(kwargs.fetch(:legacy, 5)).flat_map { |n| OPT_TSC.fetch(:"v#{n}", {}).fetch(:compiler, []) })
1359
+ kwargs[:legacy] = semapp('npx', 'tsc', '--version', minor: false) if kwargs[:detect]
1360
+ list.concat(Array(kwargs[:legacy]).flat_map { |n| OPT_TSC.fetch(:"v#{n}", {}).fetch(:compiler, []) })
1357
1361
  cmd = session 'tsc', if p
1358
1362
  quote_option 'p', basepath(p)
1359
1363
  elsif b
@@ -1379,7 +1383,7 @@ module Squared
1379
1383
  print_run(cmd, banner, **kwargs)
1380
1384
  session 'npx', cmd
1381
1385
  start = time_epoch if kwargs.fetch(:verbose, verbose? && !stdin?)
1382
- ret = run(sync: sync, banner: banner, exception: exception?(**kwargs), from: from)
1386
+ ret = run(sync: sync, banner: banner, exception: kwargs.fetch(:exception, exception?), from: from)
1383
1387
  print_status(name, subject: 'tsc', start: start) if success?(ret, banner, start.nil?) && start
1384
1388
  ret
1385
1389
  end
@@ -1450,7 +1454,7 @@ module Squared
1450
1454
  end
1451
1455
 
1452
1456
  def yarn?
1453
- (@pm[:yarn] ||= if rootpath(yarnlock, ascend: dependroot).exist?
1457
+ (@pm[:yarn] ||= if rootpath('yarn.lock', ascend: dependroot).exist?
1454
1458
  yarntype
1455
1459
  elsif (ver = read_package || read_install)
1456
1460
  if ver =~ /^yarn(?:@(\d)|$)/
@@ -1471,7 +1475,7 @@ module Squared
1471
1475
  end
1472
1476
 
1473
1477
  def pnpm?
1474
- (@pm[:pnpm] ||= if rootpath(pnpmlock, ascend: dependroot).exist?
1478
+ (@pm[:pnpm] ||= if rootpath('pnpm-lock.yaml', ascend: dependroot).exist?
1475
1479
  pnpmtype
1476
1480
  elsif (ver = read_package || read_install)
1477
1481
  ver.start_with?('pnpm') ? pnpmtype : 0
@@ -1516,7 +1520,7 @@ module Squared
1516
1520
  end
1517
1521
 
1518
1522
  def scripts
1519
- @scripts ||= read_package('scripts').yield_self { |ret| ret.is_a?(Hash) ? ret : {} }
1523
+ @scripts ||= read_package('scripts').then { |ret| ret.is_a?(Hash) ? ret : {} }
1520
1524
  end
1521
1525
 
1522
1526
  private
@@ -1580,7 +1584,7 @@ module Squared
1580
1584
  require 'yaml'
1581
1585
  doc = YAML.load_file(rc)
1582
1586
  doc.nodeLinker == 'node-modules' ? 2 : 3
1583
- elsif exist && !exist?(yarnlock)
1587
+ elsif exist && !exist?('yarn.lock')
1584
1588
  0
1585
1589
  else
1586
1590
  1
@@ -1592,10 +1596,6 @@ module Squared
1592
1596
  3
1593
1597
  end
1594
1598
 
1595
- def yarnlock
1596
- 'yarn.lock'
1597
- end
1598
-
1599
1599
  def pnpmtype(exist: false)
1600
1600
  require 'yaml'
1601
1601
  doc = YAML.load_file(basepath('node_modules/.modules.yaml', ascend: dependroot))
@@ -1610,21 +1610,13 @@ module Squared
1610
1610
  end
1611
1611
  rescue => e
1612
1612
  if exist
1613
- %W[#{pnpmlock} pnpm-workspace.yaml].any? { |val| exist?(val) } ? 4 : 0
1613
+ %w[pnpm-lock.yaml pnpm-workspace.yaml].any? { |val| exist?(val) } ? 4 : 0
1614
1614
  else
1615
1615
  log.debug e
1616
1616
  4
1617
1617
  end
1618
1618
  end
1619
1619
 
1620
- def pnpmlock
1621
- 'pnpm-lock.yaml'
1622
- end
1623
-
1624
- def pnpmopts(*args)
1625
- OPT_PNPM[:common] + args.flat_map { |name| OPT_PNPM.fetch(name, []) }
1626
- end
1627
-
1628
1620
  def remove_modules(prefix: dependbin)
1629
1621
  modules = basepath!('node_modules', type: 'd')
1630
1622
  return false unless modules && confirm_basic('Remove?', modules, prefix: prefix)
@@ -1706,16 +1698,16 @@ module Squared
1706
1698
  ].concat(args)
1707
1699
  end
1708
1700
 
1709
- def npmlock
1710
- 'package-lock.json'
1711
- end
1712
-
1713
1701
  def npmopts(*args)
1714
1702
  OPT_NPM[:common] + args.flat_map { |name| OPT_NPM.fetch(name, []) }
1715
1703
  end
1716
1704
 
1705
+ def pnpmopts(*args)
1706
+ OPT_PNPM[:common] + args.flat_map { |name| OPT_PNPM.fetch(name, []) }
1707
+ end
1708
+
1717
1709
  def lockfile(delete = false)
1718
- ret = basepath(yarn? ? yarnlock : pnpm? ? pnpmlock : npmlock)
1710
+ ret = basepath(yarn? ? 'yarn.lock' : pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json')
1719
1711
  if ret.exist?
1720
1712
  if delete
1721
1713
  ret.delete