squared 0.7.3 → 0.7.5

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.
@@ -72,16 +72,14 @@ module Squared
72
72
  }.freeze
73
73
  OPT_TSC = {
74
74
  base: %w[all b|build init listFilesOnly locale=b p|project=p showConfig w|watch].freeze,
75
- compiler: %w[allowArbitraryExtensions=!? allowImportingTsExtensions=!? allowJs=!?
76
- allowSyntheticDefaultImports=!? allowUmdGlobalAccess=!? allowUnreachableCode=!?
77
- allowUnusedLabels=!? alwaysStrict=!? assumeChangesOnlyAffectDirectDependencies=!? baseUrl=p
75
+ compiler: %w[allowArbitraryExtensions=!? allowImportingTsExtensions=!? allowJs=!? allowUmdGlobalAccess=!?
76
+ allowUnreachableCode=!? allowUnusedLabels=!? assumeChangesOnlyAffectDirectDependencies=!?
78
77
  charset=b checkJs=!? composite=!? customConditions=q d|declaration=!? declarationDir=p
79
78
  declarationMap=!? diagnostics=!? disableReferencedProjectLoad=!? disableSizeLimit=!?
80
- disableSolutionSearching=!? downlevelIteration=!? emitBOM=!? emitDeclarationOnly=!?
81
- emitDecoratorMetadata=!? erasableSyntaxOnly=!? esModuleInterop=!? exactOptionalPropertyTypes=!?
82
- experimentalDecorators=!? explainFiles=!? extendedDiagnostics=!?
83
- forceConsistentCasingInFileNames=!? generateCpuProfile=b importHelpers=!?
84
- importsNotUsedAsValues=b incremental=!? inlineSourceMap=!? inlineSources=!?
79
+ disableSolutionSearching=!? emitBOM=!? emitDeclarationOnly=!? emitDecoratorMetadata=!?
80
+ erasableSyntaxOnly=!? exactOptionalPropertyTypes=!? experimentalDecorators=!? explainFiles=!?
81
+ extendedDiagnostics=!? forceConsistentCasingInFileNames=!? generateCpuProfile=b ignoreConfig=!?
82
+ importHelpers=!? importsNotUsedAsValues=b incremental=!? inlineSourceMap=!? inlineSources=!?
85
83
  isolatedDeclarations=!? isolatedModules=!? jsx=b jsxFactory=q jsxFragmentFactory=q
86
84
  jsxImportSource=q keyofStringsOnly=!? lib=q libReplacement=!? listEmittedFiles=!? listFiles=!?
87
85
  mapRoot=p maxNodeModuleJsDepth=i m|module=b moduleDetection=b moduleResolution=b moduleSuffixes=b
@@ -89,18 +87,22 @@ module Squared
89
87
  noFallthroughCasesInSwitch=!? noImplicitAny=!? noImplicitOverride=!? noImplicitReturns=!?
90
88
  noImplicitThis=!? noImplicitUseStrict=!? noLib=!? noPropertyAccessFromIndexSignature=!?
91
89
  noResolve=!? noStrictGenericChecks=!? noUncheckedIndexedAccess=!? noUncheckedSideEffectImports=!?
92
- noUnusedLocals=!? noUnusedParameters=!? outDir=p outFile=p paths=q plugins=b
93
- preserveConstEnums=!? preserveSymlinks=!? preserveValueImports=!? preserveWatchOutput=!?
94
- pretty=!? reactNamespace=b removeComments=!? resolveJsonModule=!? resolvePackageJsonExports=!?
95
- resolvePackageJsonImports=!? rewriteRelativeImportExtensions=!? rootDir=p rootDirs=p
96
- skipDefaultLibCheck=!? skipLibCheck=!? sourceMap=!? sourceRoot=p stopBuildOnErrors=!? strict=!?
90
+ noUnusedLocals=!? noUnusedParameters=!? outDir=p paths=q plugins=b preserveConstEnums=!?
91
+ preserveSymlinks=!? preserveValueImports=!? preserveWatchOutput=!? pretty=!? reactNamespace=b
92
+ removeComments=!? resolveJsonModule=!? resolvePackageJsonExports=!? resolvePackageJsonImports=!?
93
+ rewriteRelativeImportExtensions=!? rootDir=p rootDirs=p skipDefaultLibCheck=!? skipLibCheck=!?
94
+ sourceMap=!? sourceRoot=p stableTypeOrdering=!? stopBuildOnErrors=!? strict=!?
97
95
  strictBindCallApply=!? strictBuiltinIteratorReturn=!? strictFunctionTypes=!? strictNullChecks=!?
98
96
  strictPropertyInitialization=!? stripInternal=!? suppressExcessPropertyErrors=!?
99
97
  suppressImplicitAnyIndexErrors=!? t|target=b traceResolution=!? tsBuildInfoFile=p typeRoots=p
100
98
  types=b useDefineForClassFields=!? useUnknownInCatchVariables=!? verbatimModuleSyntax=!?].freeze,
101
99
  build: %w[clean=!? dry=!? force=!? v|verbose=!?].freeze,
102
100
  watch: %w[excludeDirectories=p excludeFiles=p fallbackPolling=b synchronousWatchDirectory=!? watchDirectory=b
103
- watchFile=b].freeze
101
+ watchFile=b].freeze,
102
+ v5: {
103
+ compiler: %w[allowSyntheticDefaultImports=!? alwaysStrict=!? baseUrl=p downlevelIteration=!?
104
+ esModuleInterop=!? outFile=p].freeze
105
+ }.freeze
104
106
  }.freeze
105
107
  PASS_NODE = {
106
108
  tsc: %w[excludeDirectories excludeFiles customConditions lib moduleSuffixes plugins rootDirs typeRoots
@@ -240,7 +242,7 @@ module Squared
240
242
  else
241
243
  npmopts :run
242
244
  end
243
- OptionPartition.new(opts, list, session(dependbin, 'run'), project: self)
245
+ OptionPartition.new(opts, list, session(dependbin, 'run'), project: self, strict: strict?)
244
246
  .add_first
245
247
  .append(delim: true, quote: false)
246
248
  run(from: :run)
@@ -259,7 +261,7 @@ module Squared
259
261
  list = npmopts :exec
260
262
  session 'npm', 'exec'
261
263
  end
262
- op = OptionPartition.new(args, list, cmd, project: self)
264
+ op = OptionPartition.new(args, list, cmd, project: self, strict: strict?)
263
265
  if op.empty?
264
266
  op << package
265
267
  if (args = readline('Enter arguments', force: false))
@@ -530,6 +532,7 @@ module Squared
530
532
  end
531
533
  save, exact, omit = save if save.is_a?(Array)
532
534
  ws = env('NODE_WORKSPACES', equals: '0')
535
+ ci = option('ci')
533
536
  om = lambda do |cmd|
534
537
  if omit
535
538
  save = case save
@@ -567,7 +570,7 @@ module Squared
567
570
  end
568
571
  if nolockfile?('yarn')
569
572
  cmd << '--no-lockfile'
570
- elsif option('ci')
573
+ elsif ci
571
574
  if yarn == 1
572
575
  cmd << '--frozen-lockfile'
573
576
  elsif !flag
@@ -603,15 +606,15 @@ module Squared
603
606
  '--force'
604
607
  elsif nolockfile?('pnpm')
605
608
  '--no-lockfile'
606
- elsif option('ci')
609
+ elsif ci
607
610
  '--frozen-lockfile'
608
611
  end
609
612
  cmd << '--ignore-scripts' if option('ignore-scripts')
610
613
  cmd << '--dangerously-allow-all-builds' if option('approve-builds')
611
614
  else
612
- cmd = session 'npm'
613
- cmd << (ci = option('ci') ? 'ci' : 'install')
615
+ cmd = session('npm', ci ? 'ci' : 'install')
614
616
  cmd << '--workspaces=false' if ws
617
+ cmd << '--force' if option('force')
615
618
  append_nocolor
616
619
  append_loglevel
617
620
  if omit
@@ -956,7 +959,7 @@ module Squared
956
959
  when :add, :update then OPT_BERRY[:add_a]
957
960
  else []
958
961
  end
959
- end, cmd, project: self)
962
+ end, cmd, project: self, strict: strict?)
960
963
  if yarn == 1 && flag != :reinstall
961
964
  op << '--no-lockfile' if nolockfile?('yarn')
962
965
  op << '--ignore-engines' if option('ignore-engines')
@@ -1025,7 +1028,7 @@ module Squared
1025
1028
  session('npm', flag)
1026
1029
  ]
1027
1030
  end
1028
- op = OptionPartition.new(*args, no: no, project: self)
1031
+ op = OptionPartition.new(*args, no: no, project: self, strict: strict?)
1029
1032
  append_platform if flag == :install
1030
1033
  append_nocolor
1031
1034
  end
@@ -1045,7 +1048,8 @@ module Squared
1045
1048
  end
1046
1049
  end
1047
1050
  op.swap.concat(packages)
1048
- raise_error ArgumentError, 'no packages to add' if op.empty? && spec == 1
1051
+ raise ArgumentError, 'no packages to add' if op.empty? && spec == 1
1052
+
1049
1053
  op.append(quote: true)
1050
1054
  .clear(errors: true)
1051
1055
  else
@@ -1090,10 +1094,11 @@ module Squared
1090
1094
 
1091
1095
  cmd = session dependbin, 'pack'
1092
1096
  if dependtype(:yarn) > 1
1093
- op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self)
1097
+ op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self, strict: strict?)
1094
1098
  op.append?('out', Pathname.pwd + "#{project}-#{version}.tgz")
1095
1099
  else
1096
- op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : npmopts(:pack), cmd, project: self)
1100
+ op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : npmopts(:pack), cmd, project: self,
1101
+ strict: strict?)
1097
1102
  unless pnpm?
1098
1103
  op.each do |opt|
1099
1104
  next unless opt =~ op.values
@@ -1117,6 +1122,7 @@ module Squared
1117
1122
  b = kwargs[:build]
1118
1123
  w = kwargs[:watch]
1119
1124
  list = OPT_TSC[:base] + OPT_TSC[:compiler]
1125
+ list.concat(Array(kwargs.fetch(:legacy, 5)).flat_map { |n| OPT_TSC.fetch(:"v#{n}", {}).fetch(:compiler, []) })
1120
1126
  cmd = session 'tsc', if p
1121
1127
  quote_option 'p', basepath(p)
1122
1128
  elsif b
@@ -1127,7 +1133,7 @@ module Squared
1127
1133
  list.concat(OPT_TSC[:watch])
1128
1134
  cmd << '-w'
1129
1135
  end
1130
- op = OptionPartition.new(args, list, cmd, project: self, sep: ' ')
1136
+ op = OptionPartition.new(args, list, cmd, project: self, strict: strict?, sep: ' ')
1131
1137
  unless p
1132
1138
  if b.is_a?(String)
1133
1139
  op.add_path(b)
@@ -131,7 +131,7 @@ module Squared
131
131
  initialize_build(Python.ref, **kwargs)
132
132
  initialize_env(**kwargs)
133
133
  end
134
- dependfile_set DEP_PYTHON
134
+ dependfile_set(DEP_PYTHON, default: 2)
135
135
  serve_set kwargs[:serve]
136
136
  editable_set editable
137
137
  venv_set kwargs[:venv]
@@ -216,7 +216,8 @@ module Squared
216
216
  found |= 1
217
217
  run(pdm_session('run', val), from: :run)
218
218
  else
219
- raise_error "script: #{val}" if exception
219
+ raise "script: #{val}" if exception
220
+
220
221
  found |= 2
221
222
  log.warn "run script \"#{val}\"".subhint('not indexed')
222
223
  end
@@ -232,7 +233,7 @@ module Squared
232
233
  subject: name, hint: pyprojectfile)
233
234
  end
234
235
  when 'exec'
235
- format_desc action, nil, ':|command,args*'
236
+ format_desc action, nil, 'command|:,args*'
236
237
  task action do |_, args|
237
238
  args = args.to_a
238
239
  cmd = if (i = args.delete(':')) && !workspace.windows?
@@ -243,7 +244,7 @@ module Squared
243
244
  command_args(args, min: 1, prefix: 'python')
244
245
  args.join(' ')
245
246
  end
246
- shell(cmd, name: :exec, chdir: path)
247
+ run(cmd, send: :exec, banner: false)
247
248
  end
248
249
  end
249
250
  else
@@ -296,11 +297,24 @@ module Squared
296
297
  install flag, ['upgrade', *args.to_a, 'pip']
297
298
  end
298
299
  when :freeze
299
- format_desc action, flag, "file?=#{DEP_PYTHON[4]},opts*"
300
+ format_desc action, flag, "file?=#{DEP_PYTHON[4]},u/uninstall,opts*"
300
301
  task flag do |_, args|
301
- next unless (file = pip(flag, opts: args.to_a, banner: true)) && !silent?
302
-
303
- puts File.read(file)
302
+ opts = args.to_a
303
+ if has_value!(opts, 'u', 'uninstall')
304
+ unless venv
305
+ print_error('no venv detected', subject: name)
306
+ exit 1
307
+ end
308
+ require 'tempfile'
309
+ temp = Tempfile.new("#{name}-")
310
+ temp.close
311
+ requirement = Pathname.new(temp)
312
+ end
313
+ file = pip(flag, opts: opts, banner: requirement.nil?, requirement: requirement)
314
+ puts File.read(file) unless silent?
315
+ if requirement && confirm_basic('Uninstall?', file)
316
+ pip(:uninstall, opts: ['y', "r=#{shell_quote(file)}"])
317
+ end
304
318
  end
305
319
  when :uninstall
306
320
  format_desc action, flag, 'package+,opts*'
@@ -590,7 +604,7 @@ module Squared
590
604
  def install(flag, opts = [], packages: [], banner: !silent?)
591
605
  if flag == :poetry
592
606
  OptionPartition.new(opts, OPT_POETRY[:install] + OPT_POETRY[:common], poetry_session('install'),
593
- project: self, single: singleopt(flag))
607
+ project: self, strict: strict?, single: singleopt(flag))
594
608
  else
595
609
  op = append_pip(flag, opts, pipopts(:install), target: pip_session('install'))
596
610
  end
@@ -626,7 +640,7 @@ module Squared
626
640
  cmd, opts = python_session('-m build', opts: opts)
627
641
  OPT_PYTHON[:build]
628
642
  end
629
- op = OptionPartition.new(opts, list, cmd, project: self, single: singleopt(flag))
643
+ op = OptionPartition.new(opts, list, cmd, project: self, strict: strict?, single: singleopt(flag))
630
644
  case flag
631
645
  when :hatch
632
646
  op.add_path(outdir) if !ENV['HATCH_BUILD_LOCATION'] && (outdir ||= op.shift)
@@ -662,7 +676,9 @@ module Squared
662
676
  from = symjoin flag, 'build'
663
677
  if flag == :meson
664
678
  cmd = session_output 'meson', 'compile', quote_option('C', basepath(outdir))
665
- OptionPartition.new(op.extras, OPT_MESON[:compile], cmd, project: self).append unless op.empty?
679
+ unless op.empty?
680
+ OptionPartition.new(op.extras, OPT_MESON[:compile], cmd, project: self, strict: strict?).append
681
+ end
666
682
  run_s(op, cmd.done, from: from)
667
683
  else
668
684
  op.clear
@@ -685,7 +701,7 @@ module Squared
685
701
  session 'twine', 'upload'
686
702
  OPT_TWINE[:publish]
687
703
  end
688
- op = OptionPartition.new(opts, list, @session, project: self, single: singleopt(flag))
704
+ op = OptionPartition.new(opts, list, @session, project: self, strict: strict?, single: singleopt(flag))
689
705
  dist = lambda do
690
706
  dir = basepath 'dist'
691
707
  return dir if dir.directory? && !dir.empty?
@@ -720,8 +736,8 @@ module Squared
720
736
  def python(*args, sync: true, banner: verbose?, with: nil, pass: PASS_PYTHON[:python], **kwargs)
721
737
  op = OptionPartition.new(session_opts(with, args: args, kwargs: kwargs, pass: pass), OPT_PYTHON[:common],
722
738
  session('python', path: !venv?),
723
- project: self, multiple: [/^-c/], single: singleopt(:python), args: true,
724
- stdin: true)
739
+ project: self, strict: strict?, multiple: [/^-c/], single: singleopt(:python),
740
+ args: true, stdin: true)
725
741
  op.concat(args)
726
742
  if op.include?('-')
727
743
  op.exist?(add: true)
@@ -769,7 +785,12 @@ module Squared
769
785
  when :freeze
770
786
  venv_init
771
787
  op << '>'
772
- op.add_quote(ret = basepath(op.detect { |val| op.exist?(val) } || DEP_PYTHON[4]))
788
+ ret = kwargs[:requirement] || begin
789
+ file = op.detect { |val| op.exist?(val) }
790
+ op.remove(file) if file
791
+ basepath(file || DEP_PYTHON[4])
792
+ end
793
+ op.add_quote(ret)
773
794
  .clear
774
795
  when :cache
775
796
  op.concat(args)
@@ -852,7 +873,7 @@ module Squared
852
873
  when :editable
853
874
  editable_set args.first
854
875
  when :venv
855
- @venv = args.empty? || args.first.nil? ? nil : basepath(*args)
876
+ @venv = (basepath(*args) unless args.empty? || args.first.nil?)
856
877
  else
857
878
  super
858
879
  end
@@ -867,7 +888,7 @@ module Squared
867
888
  end
868
889
 
869
890
  def venv?
870
- !venv.nil?
891
+ !venv.nil? && venv.directory? && !venv.empty?
871
892
  end
872
893
 
873
894
  def serve?
@@ -877,11 +898,18 @@ module Squared
877
898
  private
878
899
 
879
900
  def pip_session(*cmd)
880
- session('pip', *cmd, *preopts, path: !venv?)
901
+ main = venv?
902
+ ret = session('pip', *cmd, *preopts, main: main, path: false)
903
+ return ret if main
904
+
905
+ python_session '-m', ret.to_s
881
906
  end
882
907
 
883
908
  def pip_output(*cmd)
884
- session_output('pip', *cmd, *preopts, path: !venv?)
909
+ ret = session_output('pip', *cmd, path: false)
910
+ return ret if venv?
911
+
912
+ session_output 'python', '-m', ret.to_s
885
913
  end
886
914
 
887
915
  def python_session(*cmd, opts: nil)
@@ -910,12 +938,12 @@ module Squared
910
938
  pre = preopts(quiet: quiet)
911
939
  return session(name, *pre, *cmd, path: !venv?) unless opts
912
940
 
913
- op = OptionPartition.new(opts, common, project: self, single: singleopt(name.to_sym))
941
+ op = OptionPartition.new(opts, common, project: self, strict: strict?, single: singleopt(name.to_sym))
914
942
  [session(name, *pre, *op.to_a, *cmd, path: !venv?), op.extras]
915
943
  end
916
944
 
917
945
  def append_pip(flag, opts, list, target: @session)
918
- op = OptionPartition.new(opts, list, target, project: self, single: singleopt)
946
+ op = OptionPartition.new(opts, list, target, project: self, strict: strict?, single: singleopt)
919
947
  append_global(target: target)
920
948
  case flag
921
949
  when :install, :lock, :wheel, :editable, :upgrade
@@ -1172,7 +1200,7 @@ module Squared
1172
1200
  :venv
1173
1201
  end
1174
1202
  cmd, opts = python_session('-m', flag, opts: opts)
1175
- op = OptionPartition.new(opts, OPT_PYTHON[flag], cmd, project: self)
1203
+ op = OptionPartition.new(opts, OPT_PYTHON[flag], cmd, project: self, strict: strict?)
1176
1204
  op.append(dir, delim: true)
1177
1205
  .clear(pass: false)
1178
1206
  status ||= op.arg?(/\A-v+\z/)