squared 0.8.8 → 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.
@@ -11,7 +11,7 @@ module Squared
11
11
  install_a: %w[audit=! bin-links=! engine-strict=!? foreground-scripts=!? fund=! ignore-scripts=!?
12
12
  install-links=!? package-lock=! strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
13
13
  install_b: %w[no-save B|save-bundle D|save-dev O|save-optional save-peer P|save-prod g|global=!?
14
- min-release-age=i min-release-age-exclude=q S|save=!?].freeze,
14
+ S|save=!?].freeze,
15
15
  install_c: %w[allow-directory=b? allow-file=b? allow-git=b? allow-remote=b?].freeze,
16
16
  run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].freeze,
17
17
  exec: %w[c|call=q package=b].freeze,
@@ -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*'
@@ -329,39 +334,26 @@ module Squared
329
334
  when 'package'
330
335
  case flag
331
336
  when :approve, :deny
332
- format_desc(action, flag, 'opts*', before: flag == :approve ? 'name*|:' : 'name*|:|::')
337
+ format_desc action, flag, 'name*|:,opts*'
333
338
  task flag do |_, args|
334
339
  args = args.to_a
335
- if choice!(args) || (flag == :deny && (all = choice!(args, char: '::')))
336
- list = []
337
- pad = 0
338
- size = ->(s) { pad = [pad, s.size].max }
340
+ if choice!(args)
339
341
  pwd_set do
340
- json = JSON.parse(`#{npm_output('install-scripts ls --json')}`)
341
- json&.fetch('allowScripts', [])&.each do |data|
342
- line = data['changes']&.find { |item| item['change'] == 'pending' }
343
- next unless line && line['key'] =~ /^(.+)@([^@]+)$/
344
-
345
- size.call($1)
346
- list << [$1, $2]
347
- end
348
- if all
349
- current = read_package 'allowScripts'
350
- current&.each_pair do |key, val|
351
- next unless val
352
-
353
- md = key.match(/^(.+?)(?:@([^@]+))?$/)
354
- size.call(md[1])
355
- list << [md[1], sub_style(md[2] || 'any', theme[:inline])]
356
- end
342
+ pad = 0
343
+ list = IO.popen(npm_output('approve-scripts --allow-scripts-pending').to_s)
344
+ .each_with_object([]) do |line, out|
345
+ next unless line =~ /^\s+([a-z\d@][^@]*)@(\S+)/
346
+
347
+ pad = [pad, $1.size].max
348
+ out << [$1, $2]
349
+ end
350
+ .map { |name, ver| name.ljust(pad + 4) + ver }
351
+ if list.empty?
352
+ puts log_message('no packages to review', subject: name, hint: "#{flag}-scripts")
353
+ exit 0
357
354
  end
355
+ args.concat(choice_index('Select packages', list, multiple: true, column: /^(\S+)/))
358
356
  end
359
- if list.empty?
360
- puts log_message('no packages to review', subject: name, hint: "#{flag}-scripts")
361
- exit 0
362
- end
363
- list.map! { |name, ver| name.ljust(pad + ARG[:TAB]) + ver }
364
- args.concat(choice_index('Select packages', list, multiple: true, column: /^(\S+)/))
365
357
  end
366
358
  package flag, args
367
359
  end
@@ -556,8 +548,7 @@ module Squared
556
548
  Open3.capture2e(cmd.to_s)
557
549
  .first
558
550
  .scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
559
- .map { |item| Pathname.new(item.first) }
560
- .select(&:exist?)
551
+ .filter_map { |item| item.first if File.exist?(item.first) }
561
552
  end.concat(Array(files))
562
553
  packed = true
563
554
  end
@@ -673,7 +664,7 @@ module Squared
673
664
  end
674
665
  if nolockfile?(prefix: 'yarn')
675
666
  cmd << '--no-lockfile'
676
- elsif option('ci') || (ci? && exist?(yarnlock))
667
+ elsif ci? && exist?('yarn.lock')
677
668
  if yarn == 1
678
669
  cmd << '--frozen-lockfile'
679
670
  elsif !flag
@@ -709,14 +700,13 @@ module Squared
709
700
  '--force'
710
701
  elsif nolockfile?(prefix: 'pnpm')
711
702
  '--no-lockfile'
712
- elsif option('ci') || (ci? && exist?(pnpmlock))
703
+ elsif ci? && exist?('pnpm-lock.yaml')
713
704
  '--frozen-lockfile'
714
705
  end
715
706
  cmd << '--ignore-scripts' if option('ignore-scripts')
716
707
  cmd << '--dangerously-allow-all-builds' if option('approve-builds')
717
708
  else
718
- ci = option('ci', prefix: 'npm') || (ci? && exist?(npmlock))
719
- cmd = session('npm', ci ? 'ci' : 'install')
709
+ cmd = session('npm', ci = ci? && exist?('package-lock.json') ? 'ci' : 'install')
720
710
  option('approve-scripts') do |val|
721
711
  cmd = npm_output 'approve-scripts'
722
712
  cmd << case val
@@ -769,7 +759,7 @@ module Squared
769
759
  append_platform
770
760
  end
771
761
  end
772
- cmd << '--package-lock=false' << '--save=false' if nolockfile?(prefix: 'npm')
762
+ cmd << '--package-lock=false' << 'save=false' if nolockfile?(prefix: 'npm')
773
763
  cmd << '--ignore-scripts' if option('ignore-scripts')
774
764
  end
775
765
  if add
@@ -782,7 +772,7 @@ module Squared
782
772
  end
783
773
 
784
774
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
785
- cmd = session(pnpm? && exist?(pnpmlock) ? 'pnpm' : 'npm', 'outdated')
775
+ cmd = session(pnpm? && exist?('pnpm-lock.yaml') ? 'pnpm' : 'npm', 'outdated')
786
776
  dryrun = has_value?(opts, 'd', 'dry-run') || dryrun?
787
777
  unless dryrun
788
778
  log.info cmd.to_s
@@ -826,7 +816,7 @@ module Squared
826
816
  latest = val['latest']
827
817
  ch = file[0]
828
818
  if ch.match?(/[~^]/)
829
- file = file[1..-1]
819
+ file = file[1..]
830
820
  elsif ia && flag == :major
831
821
  major = true
832
822
  else
@@ -899,9 +889,9 @@ module Squared
899
889
  end
900
890
  print_item banner unless sync
901
891
  if !found.empty?
902
- col1 = width.call(found, 0) + ARG[:TAB]
903
- col2 = width.call(found, 1) + ARG[:TAB]
904
- col3 = pad.call(found, found.size).size + (ARG[:TAB] / 2) + col1 + col2 + width.call(found, 2)
892
+ col1 = width.call(found, 0) + 4
893
+ col2 = width.call(found, 1) + 4
894
+ col3 = pad.call(found, found.size).size + 2 + col1 + col2 + width.call(found, 2)
905
895
  packages = []
906
896
  pat = ->(a) { /("#{Regexp.escape(a[0])}"\s*:\s*)"([~^])#{'?' if a[4]}#{Regexp.escape(a[1])}"/ }
907
897
  edit = lambda do |a, pkg, mod|
@@ -971,7 +961,7 @@ module Squared
971
961
  (1..items.size)
972
962
  else
973
963
  choice('Select a package', items.map(&:first), multiple: true, force: false, index: true,
974
- border: true)
964
+ border: true, **parse_select)
975
965
  end.each do |n|
976
966
  item = items[n.pred].last
977
967
  doc.sub!(pat.call(item)) { edit.call(item, $1, $2) }
@@ -997,9 +987,9 @@ module Squared
997
987
  end
998
988
  end
999
989
  elsif !avail.empty?
1000
- col1 = width.call(avail, 0) + ARG[:TAB]
990
+ col1 = width.call(avail, 0) + 4
1001
991
  col2 = width.call(avail, 1)
1002
- col3 = width.call(avail, 2) + ARG[:TAB]
992
+ col3 = width.call(avail, 2) + 4
1003
993
  avail.each_with_index do |item, i|
1004
994
  a, b, c, d = item
1005
995
  a = a.ljust(col1)
@@ -1050,7 +1040,7 @@ module Squared
1050
1040
  c = 0
1051
1041
  e = 0
1052
1042
  doc['files'].each do |item|
1053
- path = item['path'][n..-1]
1043
+ path = item['path'][n..]
1054
1044
  js = File.extname(path)
1055
1045
  next unless ext.empty? || ext.any? { |val| val == js }
1056
1046
 
@@ -1366,7 +1356,8 @@ module Squared
1366
1356
  b = kwargs[:build]
1367
1357
  w = kwargs[:watch]
1368
1358
  list = OPT_TSC[:base] + OPT_TSC[:compiler]
1369
- 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, []) })
1370
1361
  cmd = session 'tsc', if p
1371
1362
  quote_option 'p', basepath(p)
1372
1363
  elsif b
@@ -1392,7 +1383,7 @@ module Squared
1392
1383
  print_run(cmd, banner, **kwargs)
1393
1384
  session 'npx', cmd
1394
1385
  start = time_epoch if kwargs.fetch(:verbose, verbose? && !stdin?)
1395
- 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)
1396
1387
  print_status(name, subject: 'tsc', start: start) if success?(ret, banner, start.nil?) && start
1397
1388
  ret
1398
1389
  end
@@ -1463,7 +1454,7 @@ module Squared
1463
1454
  end
1464
1455
 
1465
1456
  def yarn?
1466
- (@pm[:yarn] ||= if rootpath(yarnlock, ascend: dependroot).exist?
1457
+ (@pm[:yarn] ||= if rootpath('yarn.lock', ascend: dependroot).exist?
1467
1458
  yarntype
1468
1459
  elsif (ver = read_package || read_install)
1469
1460
  if ver =~ /^yarn(?:@(\d)|$)/
@@ -1484,7 +1475,7 @@ module Squared
1484
1475
  end
1485
1476
 
1486
1477
  def pnpm?
1487
- (@pm[:pnpm] ||= if rootpath(pnpmlock, ascend: dependroot).exist?
1478
+ (@pm[:pnpm] ||= if rootpath('pnpm-lock.yaml', ascend: dependroot).exist?
1488
1479
  pnpmtype
1489
1480
  elsif (ver = read_package || read_install)
1490
1481
  ver.start_with?('pnpm') ? pnpmtype : 0
@@ -1529,7 +1520,7 @@ module Squared
1529
1520
  end
1530
1521
 
1531
1522
  def scripts
1532
- @scripts ||= read_package('scripts').yield_self { |ret| ret.is_a?(Hash) ? ret : {} }
1523
+ @scripts ||= read_package('scripts').then { |ret| ret.is_a?(Hash) ? ret : {} }
1533
1524
  end
1534
1525
 
1535
1526
  private
@@ -1593,7 +1584,7 @@ module Squared
1593
1584
  require 'yaml'
1594
1585
  doc = YAML.load_file(rc)
1595
1586
  doc.nodeLinker == 'node-modules' ? 2 : 3
1596
- elsif exist && !exist?(yarnlock)
1587
+ elsif exist && !exist?('yarn.lock')
1597
1588
  0
1598
1589
  else
1599
1590
  1
@@ -1605,10 +1596,6 @@ module Squared
1605
1596
  3
1606
1597
  end
1607
1598
 
1608
- def yarnlock
1609
- 'yarn.lock'
1610
- end
1611
-
1612
1599
  def pnpmtype(exist: false)
1613
1600
  require 'yaml'
1614
1601
  doc = YAML.load_file(basepath('node_modules/.modules.yaml', ascend: dependroot))
@@ -1623,21 +1610,13 @@ module Squared
1623
1610
  end
1624
1611
  rescue => e
1625
1612
  if exist
1626
- %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
1627
1614
  else
1628
1615
  log.debug e
1629
1616
  4
1630
1617
  end
1631
1618
  end
1632
1619
 
1633
- def pnpmlock
1634
- 'pnpm-lock.yaml'
1635
- end
1636
-
1637
- def pnpmopts(*args)
1638
- OPT_PNPM[:common] + args.flat_map { |name| OPT_PNPM.fetch(name, []) }
1639
- end
1640
-
1641
1620
  def remove_modules(prefix: dependbin)
1642
1621
  modules = basepath!('node_modules', type: 'd')
1643
1622
  return false unless modules && confirm_basic('Remove?', modules, prefix: prefix)
@@ -1719,16 +1698,16 @@ module Squared
1719
1698
  ].concat(args)
1720
1699
  end
1721
1700
 
1722
- def npmlock
1723
- 'package-lock.json'
1724
- end
1725
-
1726
1701
  def npmopts(*args)
1727
1702
  OPT_NPM[:common] + args.flat_map { |name| OPT_NPM.fetch(name, []) }
1728
1703
  end
1729
1704
 
1705
+ def pnpmopts(*args)
1706
+ OPT_PNPM[:common] + args.flat_map { |name| OPT_PNPM.fetch(name, []) }
1707
+ end
1708
+
1730
1709
  def lockfile(delete = false)
1731
- ret = basepath(yarn? ? yarnlock : pnpm? ? pnpmlock : npmlock)
1710
+ ret = basepath(yarn? ? 'yarn.lock' : pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json')
1732
1711
  if ret.exist?
1733
1712
  if delete
1734
1713
  ret.delete