squared 0.8.6 → 0.9.0.pre2

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,
@@ -483,8 +481,7 @@ module Squared
483
481
  when :url
484
482
  format_desc action, flag, 'path,url,opts*'
485
483
  task flag, [:path, :url] do |_, args|
486
- path = param_guard(action, flag, args: args, key: :path)
487
- url = param_guard(action, flag, args: args, key: :url)
484
+ path, url = param_guard(action, flag, args: args, key: %i[path url])
488
485
  submodule(flag, args.extras, path: path, url: url)
489
486
  end
490
487
  else
@@ -665,9 +662,9 @@ module Squared
665
662
  when :files
666
663
  format_desc action, flag, 'path1,path2,patch?'
667
664
  task flag, [:path1, :path2, :patch] do |_, args|
668
- path1 = param_guard(action, flag, args: args, key: :path1)
669
- path2 = param_guard(action, flag, args: args, key: :path2)
670
- diff(flag, refs: [path1, path2, args.patch])
665
+ refs = param_guard(action, flag, args: args, key: %i[path1 path2])
666
+ refs << args.patch if args.patch
667
+ diff(flag, refs: refs)
671
668
  end
672
669
  when :grep
673
670
  format_desc action, flag, 'pattern+,a/ll-match?,in/vert-grep?,i/E/F/P?,max-count?=i,f/ormat?=s'
@@ -814,11 +811,6 @@ module Squared
814
811
  end
815
812
  branch(flag, refs: refs, remote: remote)
816
813
  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
814
  when :move, :copy
823
815
  format_desc action, flag, 'branch,oldbranch?'
824
816
  task flag, [:branch, :oldbranch] do |_, args|
@@ -832,9 +824,9 @@ module Squared
832
824
  branch(flag, refs: [oldbranch, branch])
833
825
  end
834
826
  else
835
- format_desc action, flag
836
- task flag do
837
- branch flag
827
+ format_desc(action, flag, ('opts*,pattern*' if flag == :list))
828
+ task flag do |_, args|
829
+ branch flag, args.to_a
838
830
  end
839
831
  end
840
832
  when 'clone'
@@ -867,8 +859,7 @@ module Squared
867
859
  when :branch
868
860
  format_desc action, flag, 'branch/:,opts*'
869
861
  task flag, [:branch] do |_, args|
870
- branch = args.branch
871
- branch = nil if branch == ':'
862
+ branch = args.branch unless args.branch == ':'
872
863
  switch(flag, args.extras, branch: branch || choice_refs('Choose a branch'))
873
864
  end
874
865
  end
@@ -896,7 +887,7 @@ module Squared
896
887
  reset(flag, args.to_a, refs: [])
897
888
  end
898
889
  when :mode
899
- format_desc action, flag, 'mode,ref/:'
890
+ format_desc action, flag, 'mode,ref?|:'
900
891
  task flag, [:mode, :ref] do |_, args|
901
892
  mode = param_guard(action, flag, args: args, key: :mode)
902
893
  ref = commithead args.ref
@@ -914,25 +905,6 @@ module Squared
914
905
  reset flag
915
906
  end
916
907
  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
908
  when 'rebase', 'merge'
937
909
  case flag
938
910
  when :branch
@@ -1007,7 +979,7 @@ module Squared
1007
979
  task flag, [:ref, :size] do |_, args|
1008
980
  ref = commithead args.ref
1009
981
  size = args.size
1010
- if !size && ref.to_i.between?(4, 40)
982
+ if !size && ref.to_i.between?(4, 64)
1011
983
  size = ref
1012
984
  ref = nil
1013
985
  end
@@ -1099,8 +1071,7 @@ module Squared
1099
1071
  if flag == :add
1100
1072
  format_desc action, flag, 'name,url,opts*'
1101
1073
  task flag, [:name, :url] do |_, args|
1102
- name = param_guard(action, flag, args: args, key: :name)
1103
- url = param_guard(action, flag, args: args, key: :url)
1074
+ name, url = param_guard(action, flag, args: args, key: %i[name url])
1104
1075
  raise ArgumentError, message('invalid url', hint: url) unless url.match?(GIT_PROTO)
1105
1076
 
1106
1077
  git(:remote, args.extras, extras: [name, url])
@@ -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|
@@ -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
@@ -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,6 +1940,7 @@ 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)
@@ -2057,35 +2032,6 @@ module Squared
2057
2032
  source(sync: false, stderr: true)
2058
2033
  end
2059
2034
 
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
2035
  def rev_parse(flag, opts = [], ref: nil, size: nil)
2090
2036
  cmd, opts = git_session('rev-parse', opts: opts)
2091
2037
  case flag
@@ -2149,18 +2095,28 @@ module Squared
2149
2095
 
2150
2096
  def git(flag, opts = [], extras: [])
2151
2097
  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 : [] }
2098
+ list = OPT_GIT[:git].fetch(flag, []) + OPT_GIT.fetch(flag, []).then { |a| a.is_a?(Array) ? a : [] }
2099
+ no = OPT_GIT[:no].fetch(flag, [])
2153
2100
  case flag
2154
2101
  when :add
2155
2102
  list.concat(OPT_GIT[:log][:diff_context])
2156
2103
  when :revert
2157
2104
  list.concat(VAL_GIT[:rebase][:send])
2105
+ when :show
2106
+ list.concat(OPT_GIT[:diff][:show], collect_hash(OPT_GIT[:log], pass: [:base]))
2107
+ no += collect_hash(OPT_GIT[:no][:log], pass: [:base])
2108
+ case opts.first
2109
+ when 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'raw'
2110
+ cmd << basic_option('format', opts.shift)
2111
+ when /^t?format:|%/
2112
+ cmd << quote_option('pretty', opts.shift)
2113
+ end
2158
2114
  when :'sparse-checkout'
2159
2115
  cmd << 'set'
2160
2116
  end
2161
- op = OptionPartition.new(opts, list, cmd, project: self, strict: strict?, no: OPT_GIT[:no][flag],
2117
+ op = OptionPartition.new(opts, list, cmd, project: self, strict: strict?, no: no,
2162
2118
  first: case flag
2163
- when :blame, :revert, :'sparse-checkout' then nil
2119
+ when :blame, :revert, :show, :'sparse-checkout' then nil
2164
2120
  else matchpathspec
2165
2121
  end)
2166
2122
  case flag
@@ -2226,6 +2182,20 @@ module Squared
2226
2182
  op.add_quote(val)
2227
2183
  end
2228
2184
  end
2185
+ when :show
2186
+ if op.arg?('textconv')
2187
+ op.each do |val|
2188
+ files = Dir[val]
2189
+ if files.empty? || !files.all? { |path| projectpath?(path) }
2190
+ op.add_quote(val)
2191
+ else
2192
+ op.append(files.map { |path| "HEAD:#{path}" })
2193
+ end
2194
+ end
2195
+ else
2196
+ op.append
2197
+ end
2198
+ return source(exception: false, banner: !op.arg?('oneline', 'textconv'))
2229
2199
  end
2230
2200
  case flag
2231
2201
  when :revert, :mv, :rm
@@ -2341,7 +2311,9 @@ module Squared
2341
2311
  end
2342
2312
  args = []
2343
2313
  args << quote_option('sort', sort) if sort
2344
- args << basic_option('count', env('GIT_COUNT', ARG[:CHOICE])) if count
2314
+ if count && (count = env('GIT_COUNT') || ARG[:CHOICE]) && count != Float::INFINITY
2315
+ args << basic_option('count', count)
2316
+ end
2345
2317
  choice_index(msg, foreachref(type, *args, format: format), trim: trim, **kwargs)
2346
2318
  end
2347
2319
 
@@ -2349,7 +2321,9 @@ module Squared
2349
2321
  kwargs[:attempts] ||= 1 unless force
2350
2322
  cmd = git_output(reflog && env('GIT_REFLOG') ? 'reflog' : 'log', range)
2351
2323
  cmd << quote_option('format', "#{commitstyle('%h')} %s")
2352
- cmd << basic_option('max-count', env('GIT_COUNT', ARG[:CHOICE])) if count
2324
+ if count && (count = env('GIT_COUNT') || ARG[:CHOICE]) && count != Float::INFINITY
2325
+ cmd << basic_option('max-count', count)
2326
+ end
2353
2327
  ret = choice_index(msg, git_spawn(cmd, stdout: false), column: /^(\S+)/, force: force, **kwargs)
2354
2328
  case ret
2355
2329
  when Array
@@ -2578,8 +2552,8 @@ module Squared
2578
2552
  n = origin&.index('/')
2579
2553
  raise message("missing #{origin ? 'branch' : 'remote'} name", hint: origin) unless n && branch
2580
2554
 
2581
- branch = "#{branch}:#{origin[n.succ..-1]}" unless origin.end_with?("/#{branch}")
2582
- ret = [origin[0..n.pred], branch]
2555
+ branch = task_join branch, origin[n.succ..] unless origin.end_with?("/#{branch}")
2556
+ ret = [origin[...n], branch]
2583
2557
  ret.quote! if quote
2584
2558
  ret
2585
2559
  end
@@ -2589,7 +2563,7 @@ module Squared
2589
2563
  end
2590
2564
 
2591
2565
  def commithash(val)
2592
- val[/\A:(\h{5,40})\z/, 1]
2566
+ val[/\A:(\h{5,64})\z/, 1]
2593
2567
  end
2594
2568
 
2595
2569
  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 interactive T|tilde mode=b].freeze,
72
+ add_a: %w[C|caret E|exact F|fixed i|interactive no-time-gate 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,
@@ -77,36 +77,37 @@ module Squared
77
77
  }.freeze
78
78
  OPT_TSC = {
79
79
  base: %w[all b|build init listFilesOnly locale=b p|project=p showConfig w|watch].freeze,
80
- compiler: %w[allowArbitraryExtensions=!? allowImportingTsExtensions=!? allowJs=!? allowUmdGlobalAccess=!?
81
- allowUnreachableCode=!? allowUnusedLabels=!? assumeChangesOnlyAffectDirectDependencies=!?
82
- charset=b checkJs=!? composite=!? customConditions=q d|declaration=!? declarationDir=p
83
- declarationMap=!? diagnostics=!? disableReferencedProjectLoad=!? disableSizeLimit=!?
84
- disableSolutionSearching=!? emitBOM=!? emitDeclarationOnly=!? emitDecoratorMetadata=!?
85
- erasableSyntaxOnly=!? exactOptionalPropertyTypes=!? experimentalDecorators=!? explainFiles=!?
86
- extendedDiagnostics=!? forceConsistentCasingInFileNames=!? generateCpuProfile=b ignoreConfig=!?
87
- importHelpers=!? importsNotUsedAsValues=b incremental=!? inlineSourceMap=!? inlineSources=!?
88
- isolatedDeclarations=!? isolatedModules=!? jsx=b jsxFactory=q jsxFragmentFactory=q
89
- jsxImportSource=q keyofStringsOnly=!? lib=q libReplacement=!? listEmittedFiles=!? listFiles=!?
90
- mapRoot=p maxNodeModuleJsDepth=i m|module=b moduleDetection=b moduleResolution=b moduleSuffixes=b
91
- newLine=b noCheck=!? noEmit=!? noEmitHelpers=!? noEmitOnError=!? noErrorTruncation=!?
92
- noFallthroughCasesInSwitch=!? noImplicitAny=!? noImplicitOverride=!? noImplicitReturns=!?
93
- noImplicitThis=!? noImplicitUseStrict=!? noLib=!? noPropertyAccessFromIndexSignature=!?
94
- noResolve=!? noStrictGenericChecks=!? noUncheckedIndexedAccess=!? noUncheckedSideEffectImports=!?
95
- noUnusedLocals=!? noUnusedParameters=!? outDir=p paths=q plugins=b preserveConstEnums=!?
96
- preserveSymlinks=!? preserveValueImports=!? preserveWatchOutput=!? pretty=!? reactNamespace=b
97
- removeComments=!? resolveJsonModule=!? resolvePackageJsonExports=!? resolvePackageJsonImports=!?
98
- rewriteRelativeImportExtensions=!? rootDir=p rootDirs=p skipDefaultLibCheck=!? skipLibCheck=!?
99
- sourceMap=!? sourceRoot=p stableTypeOrdering=!? stopBuildOnErrors=!? strict=!?
100
- strictBindCallApply=!? strictBuiltinIteratorReturn=!? strictFunctionTypes=!? strictNullChecks=!?
101
- strictPropertyInitialization=!? stripInternal=!? suppressExcessPropertyErrors=!?
102
- suppressImplicitAnyIndexErrors=!? t|target=b traceResolution=!? tsBuildInfoFile=p typeRoots=p
103
- types=b useDefineForClassFields=!? useUnknownInCatchVariables=!? verbatimModuleSyntax=!?].freeze,
104
- build: %w[clean=!? dry=!? force=!? v|verbose=!?].freeze,
105
- watch: %w[excludeDirectories=p excludeFiles=p fallbackPolling=b synchronousWatchDirectory=!? watchDirectory=b
80
+ compiler: %w[allowArbitraryExtensions allowImportingTsExtensions allowJs allowUmdGlobalAccess
81
+ allowUnreachableCode allowUnusedLabels assumeChangesOnlyAffectDirectDependencies charset=b
82
+ checkJs composite customConditions=q d|declaration declarationDir=p declarationMap diagnostics
83
+ disableReferencedProjectLoad disableSizeLimit disableSolutionSearching emitBOM
84
+ emitDeclarationOnly emitDecoratorMetadata erasableSyntaxOnly exactOptionalPropertyTypes
85
+ experimentalDecorators explainFiles extendedDiagnostics forceConsistentCasingInFileNames
86
+ generateCpuProfile=b ignoreConfig importHelpers importsNotUsedAsValues=b incremental
87
+ inlineSourceMap inlineSources isolatedDeclarations isolatedModules jsx=b jsxFactory=q
88
+ jsxFragmentFactory=q jsxImportSource=q keyofStringsOnly lib=q libReplacement listEmittedFiles
89
+ listFiles mapRoot=p maxNodeModuleJsDepth=i m|module=b moduleDetection=b moduleResolution=b
90
+ moduleSuffixes=b newLine=b noCheck noEmit noEmitHelpers noEmitOnError noErrorTruncation
91
+ noFallthroughCasesInSwitch noImplicitAny noImplicitOverride noImplicitReturns noImplicitThis
92
+ noImplicitUseStrict noLib noPropertyAccessFromIndexSignature noResolve noStrictGenericChecks
93
+ noUncheckedIndexedAccess noUncheckedSideEffectImports noUnusedLocals noUnusedParameters outDir=p
94
+ paths=q plugins=b preserveConstEnums preserveSymlinks preserveValueImports preserveWatchOutput
95
+ pretty reactNamespace=b removeComments resolveJsonModule resolvePackageJsonExports
96
+ resolvePackageJsonImports rewriteRelativeImportExtensions rootDir=p rootDirs=p
97
+ skipDefaultLibCheck skipLibCheck sourceMap sourceRoot=p stableTypeOrdering stopBuildOnErrors
98
+ strict strictBindCallApply strictBuiltinIteratorReturn strictFunctionTypes strictNullChecks
99
+ strictPropertyInitialization stripInternal suppressExcessPropertyErrors
100
+ suppressImplicitAnyIndexErrors t|target=b traceResolution tsBuildInfoFile=p typeRoots=p types=b
101
+ useDefineForClassFields useUnknownInCatchVariables verbatimModuleSyntax].freeze,
102
+ build: %w[clean dry force v|verbose].freeze,
103
+ watch: %w[excludeDirectories=p excludeFiles=p fallbackPolling=b synchronousWatchDirectory watchDirectory=b
106
104
  watchFile=b].freeze,
105
+ v7: {
106
+ compiler: %w[builders=i checkers=i singleThreaded=!?]
107
+ },
107
108
  v5: {
108
- compiler: %w[allowSyntheticDefaultImports=!? alwaysStrict=!? baseUrl=p downlevelIteration=!?
109
- esModuleInterop=!? outFile=p].freeze
109
+ compiler: %w[allowSyntheticDefaultImports alwaysStrict baseUrl=p downlevelIteration esModuleInterop
110
+ outFile=p].freeze
110
111
  }.freeze
111
112
  }.freeze
112
113
  PASS_NODE = {
@@ -347,7 +348,7 @@ module Squared
347
348
  .map { |name, ver| name.ljust(pad + 4) + ver }
348
349
  if list.empty?
349
350
  puts log_message('no packages to review', subject: name, hint: "#{flag}-scripts")
350
- exit 0
351
+ exit
351
352
  end
352
353
  args.concat(choice_index('Select packages', list, multiple: true, column: /^(\S+)/))
353
354
  end
@@ -545,8 +546,7 @@ module Squared
545
546
  Open3.capture2e(cmd.to_s)
546
547
  .first
547
548
  .scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
548
- .map { |item| Pathname.new(item.first) }
549
- .select(&:exist?)
549
+ .filter_map { |item| item.first if File.exist?(item.first) }
550
550
  end.concat(Array(files))
551
551
  packed = true
552
552
  end
@@ -662,7 +662,7 @@ module Squared
662
662
  end
663
663
  if nolockfile?(prefix: 'yarn')
664
664
  cmd << '--no-lockfile'
665
- elsif option('ci') || (ci? && exist?('yarn.lock'))
665
+ elsif ci? && exist?(yarnlock)
666
666
  if yarn == 1
667
667
  cmd << '--frozen-lockfile'
668
668
  elsif !flag
@@ -698,14 +698,13 @@ module Squared
698
698
  '--force'
699
699
  elsif nolockfile?(prefix: 'pnpm')
700
700
  '--no-lockfile'
701
- elsif option('ci') || (ci? && exist?('pnpm-lock.yaml'))
701
+ elsif ci? && exist?(pnpmlock)
702
702
  '--frozen-lockfile'
703
703
  end
704
704
  cmd << '--ignore-scripts' if option('ignore-scripts')
705
705
  cmd << '--dangerously-allow-all-builds' if option('approve-builds')
706
706
  else
707
- ci = option('ci', prefix: 'npm') || (ci? && exist?('package-lock.json'))
708
- cmd = session('npm', ci ? 'ci' : 'install')
707
+ cmd = session('npm', ci = ci? && exist?(npmlock) ? 'ci' : 'install')
709
708
  option('approve-scripts') do |val|
710
709
  cmd = npm_output 'approve-scripts'
711
710
  cmd << case val
@@ -758,7 +757,7 @@ module Squared
758
757
  append_platform
759
758
  end
760
759
  end
761
- cmd << '--package-lock=false' << 'save=false' if nolockfile?(prefix: 'npm')
760
+ cmd << '--package-lock=false' << '--save=false' if nolockfile?(prefix: 'npm')
762
761
  cmd << '--ignore-scripts' if option('ignore-scripts')
763
762
  end
764
763
  if add
@@ -771,7 +770,7 @@ module Squared
771
770
  end
772
771
 
773
772
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
774
- cmd = session(pnpm? && exist?('pnpm-lock.yaml') ? 'pnpm' : 'npm', 'outdated')
773
+ cmd = session(pnpm? && exist?(pnpmlock) ? 'pnpm' : 'npm', 'outdated')
775
774
  dryrun = has_value?(opts, 'd', 'dry-run') || dryrun?
776
775
  unless dryrun
777
776
  log.info cmd.to_s
@@ -815,7 +814,7 @@ module Squared
815
814
  latest = val['latest']
816
815
  ch = file[0]
817
816
  if ch.match?(/[~^]/)
818
- file = file[1..-1]
817
+ file = file[1..]
819
818
  elsif ia && flag == :major
820
819
  major = true
821
820
  else
@@ -960,7 +959,7 @@ module Squared
960
959
  (1..items.size)
961
960
  else
962
961
  choice('Select a package', items.map(&:first), multiple: true, force: false, index: true,
963
- border: true)
962
+ border: true, **parse_select)
964
963
  end.each do |n|
965
964
  item = items[n.pred].last
966
965
  doc.sub!(pat.call(item)) { edit.call(item, $1, $2) }
@@ -1039,7 +1038,7 @@ module Squared
1039
1038
  c = 0
1040
1039
  e = 0
1041
1040
  doc['files'].each do |item|
1042
- path = item['path'][n..-1]
1041
+ path = item['path'][n..]
1043
1042
  js = File.extname(path)
1044
1043
  next unless ext.empty? || ext.any? { |val| val == js }
1045
1044
 
@@ -1350,37 +1349,46 @@ module Squared
1350
1349
  end
1351
1350
 
1352
1351
  def tsc(*args, with: nil, pass: PASS_NODE[:tsc], sync: true, banner: verbose?, from: :tsc, **kwargs)
1353
- session_apply(with, args: args, kwargs: kwargs, pass: pass) if with
1352
+ opts = session_opts(with, args: args, kwargs: kwargs, pass: pass)
1354
1353
  p = kwargs[:project]
1355
1354
  b = kwargs[:build]
1356
1355
  w = kwargs[:watch]
1357
1356
  list = OPT_TSC[:base] + OPT_TSC[:compiler]
1358
- list.concat(Array(kwargs.fetch(:legacy, 5)).flat_map { |n| OPT_TSC.fetch(:"v#{n}", {}).fetch(:compiler, []) })
1357
+ kwargs[:legacy] = semapp('npx', 'tsc', '--version', minor: false) if kwargs[:detect]
1358
+ list.concat(Array(kwargs[:legacy]).flat_map { |n| OPT_TSC.fetch(:"v#{n}", {}).fetch(:compiler, []) })
1359
+ auto = %w[h|help v|version]
1359
1360
  cmd = session 'tsc', if p
1360
1361
  quote_option 'p', basepath(p)
1361
1362
  elsif b
1362
1363
  list.concat(OPT_TSC[:build])
1364
+ auto[1] = 'version'
1363
1365
  '-b'
1364
1366
  end
1365
1367
  if w
1366
1368
  list.concat(OPT_TSC[:watch])
1367
1369
  cmd << '-w'
1368
1370
  end
1369
- op = OptionPartition.new(args, list, cmd, project: self, strict: strict?, sep: ' ')
1370
- unless p
1371
- if b.is_a?(String)
1372
- op.add_path(b)
1373
- elsif w.is_a?(String)
1374
- op.add_path(w)
1375
- else
1376
- op.exist?(add: true)
1371
+ flags, args = args.partition { |val| val.start_with?('-') }
1372
+ op = OptionPartition.new(opts + args, list, cmd, project: self, strict: strict?, auto: auto, explicit: true,
1373
+ sep: ' ')
1374
+ if op.stdout
1375
+ banner = false
1376
+ else
1377
+ unless p
1378
+ if b.is_a?(String)
1379
+ op.add_path(b)
1380
+ elsif w.is_a?(String)
1381
+ op.add_path(w)
1382
+ else
1383
+ op.exist?(add: true)
1384
+ end
1377
1385
  end
1386
+ op.append(flags, escape: kwargs.fetch(:escape, false), quote: kwargs.fetch(:quote, false))
1387
+ .clear
1388
+ print_run(op, banner, **kwargs)
1389
+ start = time_epoch if kwargs.fetch(:verbose, verbose? && !stdin?)
1378
1390
  end
1379
- op.clear
1380
- cmd = session_done(op.target)
1381
- print_run(cmd, banner, **kwargs)
1382
- session 'npx', cmd
1383
- start = time_epoch if kwargs.fetch(:verbose, verbose? && !stdin?)
1391
+ session 'npx', session_done(op.target)
1384
1392
  ret = run(sync: sync, banner: banner, exception: exception?(**kwargs), from: from)
1385
1393
  print_status(name, subject: 'tsc', start: start) if success?(ret, banner, start.nil?) && start
1386
1394
  ret
@@ -1452,7 +1460,7 @@ module Squared
1452
1460
  end
1453
1461
 
1454
1462
  def yarn?
1455
- (@pm[:yarn] ||= if rootpath('yarn.lock', ascend: dependroot).exist?
1463
+ (@pm[:yarn] ||= if rootpath(yarnlock, ascend: dependroot).exist?
1456
1464
  yarntype
1457
1465
  elsif (ver = read_package || read_install)
1458
1466
  if ver =~ /^yarn(?:@(\d)|$)/
@@ -1473,7 +1481,7 @@ module Squared
1473
1481
  end
1474
1482
 
1475
1483
  def pnpm?
1476
- (@pm[:pnpm] ||= if rootpath('pnpm-lock.yaml', ascend: dependroot).exist?
1484
+ (@pm[:pnpm] ||= if rootpath(pnpmlock, ascend: dependroot).exist?
1477
1485
  pnpmtype
1478
1486
  elsif (ver = read_package || read_install)
1479
1487
  ver.start_with?('pnpm') ? pnpmtype : 0
@@ -1518,7 +1526,7 @@ module Squared
1518
1526
  end
1519
1527
 
1520
1528
  def scripts
1521
- @scripts ||= read_package('scripts').yield_self { |ret| ret.is_a?(Hash) ? ret : {} }
1529
+ @scripts ||= read_package('scripts').then { |ret| ret.is_a?(Hash) ? ret : {} }
1522
1530
  end
1523
1531
 
1524
1532
  private
@@ -1582,7 +1590,7 @@ module Squared
1582
1590
  require 'yaml'
1583
1591
  doc = YAML.load_file(rc)
1584
1592
  doc.nodeLinker == 'node-modules' ? 2 : 3
1585
- elsif exist && !exist?('yarn.lock')
1593
+ elsif exist && !exist?(yarnlock)
1586
1594
  0
1587
1595
  else
1588
1596
  1
@@ -1594,6 +1602,10 @@ module Squared
1594
1602
  3
1595
1603
  end
1596
1604
 
1605
+ def yarnlock
1606
+ 'yarn.lock'
1607
+ end
1608
+
1597
1609
  def pnpmtype(exist: false)
1598
1610
  require 'yaml'
1599
1611
  doc = YAML.load_file(basepath('node_modules/.modules.yaml', ascend: dependroot))
@@ -1608,13 +1620,21 @@ module Squared
1608
1620
  end
1609
1621
  rescue => e
1610
1622
  if exist
1611
- %w[pnpm-lock.yaml pnpm-workspace.yaml].any? { |val| exist?(val) } ? 4 : 0
1623
+ %W[#{pnpmlock} pnpm-workspace.yaml].any? { |val| exist?(val) } ? 4 : 0
1612
1624
  else
1613
1625
  log.debug e
1614
1626
  4
1615
1627
  end
1616
1628
  end
1617
1629
 
1630
+ def pnpmlock
1631
+ 'pnpm-lock.yaml'
1632
+ end
1633
+
1634
+ def pnpmopts(*args)
1635
+ OPT_PNPM[:common] + args.flat_map { |name| OPT_PNPM.fetch(name, []) }
1636
+ end
1637
+
1618
1638
  def remove_modules(prefix: dependbin)
1619
1639
  modules = basepath!('node_modules', type: 'd')
1620
1640
  return false unless modules && confirm_basic('Remove?', modules, prefix: prefix)
@@ -1696,16 +1716,16 @@ module Squared
1696
1716
  ].concat(args)
1697
1717
  end
1698
1718
 
1699
- def npmopts(*args)
1700
- OPT_NPM[:common] + args.flat_map { |name| OPT_NPM.fetch(name, []) }
1719
+ def npmlock
1720
+ 'package-lock.json'
1701
1721
  end
1702
1722
 
1703
- def pnpmopts(*args)
1704
- OPT_PNPM[:common] + args.flat_map { |name| OPT_PNPM.fetch(name, []) }
1723
+ def npmopts(*args)
1724
+ OPT_NPM[:common] + args.flat_map { |name| OPT_NPM.fetch(name, []) }
1705
1725
  end
1706
1726
 
1707
1727
  def lockfile(delete = false)
1708
- ret = basepath(yarn? ? 'yarn.lock' : pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json')
1728
+ ret = basepath(yarn? ? yarnlock : pnpm? ? pnpmlock : npmlock)
1709
1729
  if ret.exist?
1710
1730
  if delete
1711
1731
  ret.delete