squared 0.5.6 → 0.5.8

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.
@@ -5,15 +5,17 @@ module Squared
5
5
  module Project
6
6
  class Node < Git
7
7
  OPT_NPM = {
8
- common: %w[dry-run include-workspace-root workspaces=b? w|workspace=v].freeze,
9
- install: %w[prefer-dedupe package-lock-only cpu=b libc=b os=b].freeze,
10
- install_base: %w[ignore-scripts install-links strict-peer-deps include=b omit=b install-strategy=b].freeze,
8
+ common: %w[dry-run=!? include-workspace-root=!? loglevel=b workspaces=!? w|workspace=v].freeze,
9
+ install: %w[prefer-dedupe=!? package-lock-only=!? audit=! bin-links=! cpu=b fund=! libc=b os=b
10
+ package-lock=!].freeze,
11
+ install_base: %w[ignore-scripts=!? install-links=!? strict-peer-deps=!? include=b omit=b
12
+ install-strategy=b].freeze,
11
13
  install_no: %w[audit bin-links fund package-lock].freeze,
12
- install_as: %w[foreground-scripts g|global no-save save save-bundle save-dev E|save-exact save-optional
13
- save-peer S|save-prod].freeze,
14
- run: %w[foreground-scripts if-present ignore-scripts script-shell=p].freeze,
14
+ install_as: %w[no-save save-bundle save-dev save-optional save-peer save-prod foreground-scripts=!?
15
+ g|global=!? S|save=!? E|save-exact=!?].freeze,
16
+ run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].freeze,
15
17
  exec: %w[c|call=q package=b].freeze,
16
- pack: %w[json ignore-scripts pack-destination=p].freeze
18
+ pack: %w[json=!? pack-destination=p].freeze
17
19
  }.freeze
18
20
  OPT_PNPM = {
19
21
  common: %w[aggregate-output color no-color stream use-stderr C|dir=p loglevel=b w|workspace-root].freeze,
@@ -107,7 +109,7 @@ module Squared
107
109
  initialize_build(Node.ref, prod: prod?, **kwargs)
108
110
  initialize_env(**kwargs)
109
111
  end
110
- @dependfile = @path + 'package.json'
112
+ @dependfile = basepath 'package.json'
111
113
  @pm = { __: init }
112
114
  end
113
115
 
@@ -266,11 +268,6 @@ module Squared
266
268
  otp = args.first
267
269
  else
268
270
  tag, otp = param_guard(action, flag, args: args)
269
- unless SEM_VER.match?(tag)
270
- a = sub_style(project, styles: theme[:active])
271
- b = sub_style(tag, styles: theme[:inline])
272
- exit 1 unless confirm("Publish #{a}@#{b}?", 'N')
273
- end
274
271
  end
275
272
  publish(flag, otp: otp, tag: tag, dryrun: dryrun, access: access)
276
273
  end
@@ -377,12 +374,10 @@ module Squared
377
374
  target.mkpath
378
375
  subdir << target.to_s
379
376
  end
380
- begin
381
- FileUtils.cp(path + s, dest, verbose: verbose.is_a?(Numeric) && verbose > 0)
382
- rescue StandardError => e
383
- print_error e
384
- errors += 1
385
- end
377
+ FileUtils.cp(basepath(s), dest, verbose: verbose.is_a?(Numeric) && verbose > 0)
378
+ rescue StandardError => e
379
+ print_error e
380
+ errors += 1
386
381
  end
387
382
  rescue StandardError => e
388
383
  on_error e, :copy
@@ -393,7 +388,7 @@ module Squared
393
388
  end
394
389
  glob = Array(glob || '**/*')
395
390
  target = []
396
- from = path + from
391
+ from = basepath from
397
392
  if workspace
398
393
  from.glob('*').each do |entry|
399
394
  next unless entry.directory?
@@ -421,11 +416,9 @@ module Squared
421
416
  end
422
417
  target.each do |src, to|
423
418
  glob.each { |val| log.info "cp #{from + val} #{to}" }
424
- begin
425
- copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
426
- rescue StandardError => e
427
- on_error e, :copy
428
- end
419
+ copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
420
+ rescue StandardError => e
421
+ on_error e, :copy
429
422
  end
430
423
  end
431
424
  on :last, :copy
@@ -478,7 +471,7 @@ module Squared
478
471
  if flag == :add
479
472
  cmd << "--save-#{save}"
480
473
  cmd << '--save-exact' if exact
481
- cmd.merge(packages.map { |pkg| shell_escape(pkg) })
474
+ cmd.merge(packages.map { |pkg| shell_quote(pkg) })
482
475
  end
483
476
  cmd << '--workspaces=false' if env('NODE_WORKSPACES', equals: '0')
484
477
  cmd << '--package-lock=false' if option('package-lock', equals: '0')
@@ -661,14 +654,19 @@ module Squared
661
654
  end
662
655
 
663
656
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil)
664
- if !version || read_packagemanager(:private)
665
- warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: version ? 'private' : nil)
657
+ unless version && !read_packagemanager(:private)
658
+ print_error('invalid task "publish"', subject: name, hint: version ? 'private' : nil)
666
659
  return
667
660
  end
668
661
  cmd = session 'npm', 'publish'
669
662
  cmd << basic_option('otp', otp) if otp ||= option('otp')
670
- cmd << basic_option('tag', tag) if tag ||= option('tag')
671
- cmd << basic_option('access', access) if access ||= option('access')
663
+ cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
664
+ case access || option('access')
665
+ when 'p', 'public'
666
+ cmd << '--access=public'
667
+ when 'r', 'restricted'
668
+ cmd << '--access=restricted'
669
+ end
672
670
  dryrun ||= dryrun?('npm')
673
671
  if dryrun
674
672
  cmd << '--dry-run'
@@ -679,13 +677,13 @@ module Squared
679
677
  if sync
680
678
  run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(npmname, styles: theme[:active])}")
681
679
  else
680
+ require 'open3'
682
681
  on :first, from
683
682
  pwd_set(from: from, dryrun: dryrun) do
684
- require 'open3'
685
- banner = format_banner cmd.to_s
686
- Open3.popen2e(cmd.done) do |_, out|
687
- write_lines(out, sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2],
688
- banner: banner)
683
+ cmd = session_done cmd
684
+ Open3.popen2e(cmd) do |_, out|
685
+ write_lines(out, banner: format_banner(cmd),
686
+ sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:bright_blue), index: 2])
689
687
  end
690
688
  end
691
689
  on :last, from
@@ -725,7 +723,7 @@ module Squared
725
723
  if opt =~ op.values
726
724
  case $1
727
725
  when 'w', 'workspace'
728
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
726
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
729
727
  end
730
728
  elsif opt.include?('=')
731
729
  op.errors << opt
@@ -817,7 +815,7 @@ module Squared
817
815
 
818
816
  case $1
819
817
  when 'w', 'workspace'
820
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
818
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
821
819
  op.found << opt
822
820
  end
823
821
  end
@@ -1028,9 +1026,9 @@ module Squared
1028
1026
 
1029
1027
  def npmnotice
1030
1028
  [
1031
- { pat: /^(npm error )(code|\d+)(.+)$/, styles: color(:cyan), index: 2 },
1032
- { pat: /^(npm )(error)(.*)$/, styles: color(:red), index: 2 },
1033
- { pat: /^(npm )(notice)(.*)$/, styles: color(:cyan), index: 2 },
1029
+ { pat: /^(npm error )(code|\d+)(.+)$/, styles: color(:bright_cyan), index: 2 },
1030
+ { pat: /^(npm )(error)(.*)$/, styles: color(:bright_red), index: 2 },
1031
+ { pat: /^(npm )(notice)(.*)$/, styles: color(:bright_cyan), index: 2 },
1034
1032
  { pat: /^(npm )(.+)$/, styles: :bold }
1035
1033
  ]
1036
1034
  end
@@ -37,8 +37,8 @@ module Squared
37
37
  common: %w[I|ignore-python no-cache n|non-interactive].freeze,
38
38
  build: %w[C=bm no-clean no-isolation no-sdist no-wheel quiet verbose config-setting=q d|dest=p p|project=p
39
39
  k|skip=b].freeze,
40
- publish: %w[no-build no-very-ssl quiet S|sign skip-existing verbose ca-certs=p c|comment=q d|dest=p identity=b
41
- p|password=q p|project=p r|repository=q k|skip=b u|username=b].freeze
40
+ publish: %w[no-build no-very-ssl quiet S|sign skip-existing verbose ca-certs=p c|comment=q d|dest=p
41
+ i|identity=b P|password=q p|project=p r|repository=q k|skip=b u|username=b].freeze
42
42
  }.freeze
43
43
  OPT_HATCH = {
44
44
  common: %w[color interactive no-color no-interactive cache-dir=p config=p data-dir=p e|env=b p|project=b
@@ -207,7 +207,7 @@ module Squared
207
207
  if flag == :create
208
208
  format_desc action, flag, 'dir,opts*'
209
209
  task flag, [:dir] do |_, args|
210
- dir = path + param_guard(action, flag, args: args, key: :dir)
210
+ dir = basepath param_guard(action, flag, args: args, key: :dir)
211
211
  venv_create dir, args.extras
212
212
  end
213
213
  elsif venv
@@ -245,10 +245,7 @@ module Squared
245
245
  when :upgrade
246
246
  format_desc action, flag, 'opts*'
247
247
  task flag do |_, args|
248
- args = args.to_a
249
- args.prepend('upgrade')
250
- args.append('pip')
251
- install flag, args
248
+ install flag, ['upgrade', *args.to_a, 'pip']
252
249
  end
253
250
  when :freeze
254
251
  format_desc action, flag, "file?=#{DEP_PYTHON[4]},opts*"
@@ -306,7 +303,7 @@ module Squared
306
303
  when 'build'
307
304
  case flag
308
305
  when :poetry
309
- next unless poetry?
306
+ next unless build_backend == 'poetry.core.masonry.api'
310
307
  when :pdm
311
308
  next unless build_backend == 'pdm.backend'
312
309
  when :hatch
@@ -360,7 +357,7 @@ module Squared
360
357
  when :user
361
358
  cmd << '--user'
362
359
  when :target
363
- cmd << quote_option('target', path + target)
360
+ cmd << quote_option('target', basepath(target))
364
361
  when :force
365
362
  cmd << '--force-reinstall'
366
363
  end
@@ -483,11 +480,7 @@ module Squared
483
480
  cmd << '--user' if user
484
481
  cmd << basic_option('upgrade-strategy', strategy) if strategy
485
482
  append_value out
486
- if workspace.windows?
487
- pip = cmd.to_a.drop(1)
488
- cmd = python_session '-m pip'
489
- cmd.merge(pip)
490
- end
483
+ python_session('-m pip', *cmd.to_a.drop(1)) if workspace.windows?
491
484
  end
492
485
  run(from: :install)
493
486
  end
@@ -524,7 +517,7 @@ module Squared
524
517
  if op.arg?(*args)
525
518
  op.push(srcdir)
526
519
  else
527
- op << quote_option(args.last, path + srcdir)
520
+ op << quote_option(args.last, basepath(srcdir))
528
521
  end
529
522
  srcdir = nil
530
523
  end
@@ -558,7 +551,7 @@ module Squared
558
551
  end
559
552
  op = OptionPartition.new(opts, list, @session, project: self, single: singleopt(flag))
560
553
  dist = lambda do
561
- path.join('dist').tap do |dir|
554
+ basepath('dist').tap do |dir|
562
555
  raise_error('no source files found', hint: dir) unless dir.directory? && !dir.empty?
563
556
  end
564
557
  end
@@ -574,7 +567,7 @@ module Squared
574
567
  if op.empty?
575
568
  op.push("#{dist.call}/*")
576
569
  else
577
- op.map! { |val| path + val }
570
+ op.map! { |val| basepath(val) }
578
571
  end
579
572
  op.append
580
573
  else
@@ -650,7 +643,7 @@ module Squared
650
643
 
651
644
  def poetry_session(*cmd)
652
645
  ret = session('poetry', *cmd, *preopts)
653
- option('project', ignore: false) { |val| ret << quote_option('project', path + val) }
646
+ option('project', ignore: false) { |val| ret << quote_option('project', basepath(val)) }
654
647
  ret
655
648
  end
656
649
 
@@ -671,7 +664,7 @@ module Squared
671
664
  end
672
665
 
673
666
  def append_pip(flag, opts, target: @session, from: nil)
674
- if !from || opts.empty?
667
+ unless from && !opts.empty?
675
668
  append_global(target: target)
676
669
  return []
677
670
  end
@@ -695,11 +688,11 @@ module Squared
695
688
  op << '--no-build-isolation' if option('build-isolation', equals: '0')
696
689
  op.swap
697
690
  if edit
698
- edit = path + edit unless %r{\A[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
691
+ edit = basepath(edit) unless %r{\A[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
699
692
  if flag == :editable
700
693
  op.push(edit)
701
694
  else
702
- target << quote_option('e', edit)
695
+ op << quote_option('e', edit)
703
696
  end
704
697
  end
705
698
  case flag
@@ -710,25 +703,25 @@ module Squared
710
703
  []
711
704
  end
712
705
  else
713
- opts
706
+ op.extras
714
707
  end
715
708
  end
716
709
 
717
710
  def append_editable(target: @session)
718
- return if requirements?
711
+ return if requirements? && editable == '.'
719
712
 
720
713
  if (val = option('editable', 'e', target: target, ignore: false))
721
- session_delete('e', 'editable', target: target)
714
+ OptionPartition.delete_key(target, 'e', 'editable')
722
715
  case val
723
716
  when '0', 'false'
724
717
  return
725
718
  else
726
- val = path + val
719
+ val = basepath val
727
720
  end
728
721
  elsif session_arg?('e', 'editable', target: target) || !(val = editable)
729
722
  return
730
723
  end
731
- target << quote_option('e', val)
724
+ target << quote_option('e', basepath(val))
732
725
  end
733
726
 
734
727
  def append_global(target: @session)
@@ -737,11 +730,11 @@ module Squared
737
730
  when '0', 'false'
738
731
  '--no-cache-dir'
739
732
  else
740
- quote_option('cache-dir', path + val)
733
+ quote_option('cache-dir', basepath(val))
741
734
  end
742
735
  end
743
736
  option('proxy', target: target) { |val| target << shell_option('proxy', val) }
744
- option('python', target: target) { |val| target << quote_option('python', path + val) }
737
+ option('python', target: target) { |val| target << quote_option('python', basepath(val)) }
745
738
  append_nocolor(target: target)
746
739
  end
747
740
 
@@ -863,7 +856,7 @@ module Squared
863
856
  when '.', Pathname
864
857
  val
865
858
  when String
866
- Pathname.new(editable)
859
+ Pathname.new(val) unless val.empty?
867
860
  end
868
861
  end
869
862
 
@@ -874,8 +867,7 @@ module Squared
874
867
  val, *opts = val
875
868
  @venvopts = opts
876
869
  end
877
- @venv = Pathname.new(val)
878
- @venv = @path + @venv unless @venv.absolute?
870
+ @venv = basepath(val)
879
871
  if projectpath?(@venv)
880
872
  if @venv.exist?
881
873
  log.debug "venv found: #{@venv}"
@@ -909,11 +901,11 @@ module Squared
909
901
  end
910
902
 
911
903
  def setuptools?
912
- build_backend ? build_backend == 'setuptools.build_meta' : dependtype == 2 || dependtype == 4
904
+ dependtype == 2 || dependtype == 4
913
905
  end
914
906
 
915
907
  def poetry?
916
- build_backend ? build_backend == 'poetry.core.masonry.api' : dependtype == 1
908
+ dependtype == 1
917
909
  end
918
910
 
919
911
  def requirements?