squared 0.4.14 → 0.5.0

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.
@@ -94,6 +94,7 @@ module Squared
94
94
  'add' => nil,
95
95
  'run' => nil,
96
96
  'exec' => nil,
97
+ 'nvm' => nil,
97
98
  'pack' => nil
98
99
  })
99
100
 
@@ -134,7 +135,7 @@ module Squared
134
135
  end
135
136
  case save
136
137
  when 'prod', 'dev', 'optional', 'peer'
137
- packages = args.extras
138
+ packages = args.to_a.drop(1)
138
139
  else
139
140
  save = 'prod'
140
141
  packages = args.to_a
@@ -145,10 +146,10 @@ module Squared
145
146
  when 'run'
146
147
  next if (list = read_scripts).empty?
147
148
 
148
- format_desc action, nil, "script,opts*|#{indexchar}index+|#,pattern*"
149
+ format_desc action, nil, 'script,opts*|^index+|#,pattern*'
149
150
  task action, [:script] do |_, args|
150
151
  if args.script == '#'
151
- format_list(list, "run[#{indexchar}N]", 'scripts', grep: args.extras, from: dependfile)
152
+ format_list(list, 'run[^N]', 'scripts', grep: args.extras, from: dependfile.to_s)
152
153
  else
153
154
  args = param_guard(action, 'script', args: args.to_a)
154
155
  opts = []
@@ -185,7 +186,7 @@ module Squared
185
186
  format_desc action, nil, 'pkg/cmd,opts*,args*'
186
187
  task action, [:package] do |_, args|
187
188
  if (package = args.package)
188
- args = args.extras
189
+ args = args.to_a.drop(1)
189
190
  if pnpm?
190
191
  pre = ->(ch) { "-#{ch}" if (ch = args.delete(ch)) }
191
192
  cmd = session 'pnpm', pre.call('r'), pre.call('c'), 'exec'
@@ -210,6 +211,17 @@ module Squared
210
211
  end
211
212
  run(from: :exec)
212
213
  end
214
+ when 'nvm'
215
+ next unless ENV['NVM_DIR']
216
+
217
+ format_desc action, nil, 'version,args*'
218
+ task action, [:version] do |_, args|
219
+ version = param_guard(action, 'version', args: args, key: :version)
220
+ args = args.to_a.drop(1)
221
+ args << readline('Enter command', force: true) if args.empty?
222
+ args.prepend(File.join(ENV['NVM_DIR'], 'nvm-exec'))
223
+ run(args.join(' '), { 'NODE_VERSION' => version }, banner: false, from: :nvm)
224
+ end
213
225
  when 'pack'
214
226
  format_desc action, nil, 'opts*'
215
227
  task action do |_, args|
@@ -226,7 +238,7 @@ module Squared
226
238
  outdated flag, args.to_a
227
239
  end
228
240
  when 'package'
229
- format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'name*')
241
+ format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'names*')
230
242
  task flag do |_, args|
231
243
  package flag, args.to_a
232
244
  end
@@ -247,7 +259,7 @@ module Squared
247
259
  format_desc(action, flag, 'otp?,dry-run?,public|restricted?', before: flag == :tag ? 'tag' : nil)
248
260
  task flag do |_, args|
249
261
  args = args.to_a
250
- dryrun = true if args.delete('dry-run') || args.delete('true') || args.delete('d')
262
+ dryrun = true if args.delete('dry-run') || args.delete('d')
251
263
  if args.delete('public') || args.delete('p')
252
264
  access = 'public'
253
265
  elsif args.delete('restricted') || args.delete('r')
@@ -336,15 +348,15 @@ module Squared
336
348
  next unless from && dest&.directory?
337
349
 
338
350
  from = path + from
339
- glob = Array(glob || '**/*')
351
+ glob = as_a(glob || '**/*')
340
352
  target = []
341
353
  if workspace
342
- Dir.glob(from + '*').each do |path|
343
- next unless (path = Pathname.new(path)).directory?
354
+ from.glob('*').each do |entry|
355
+ next unless entry.directory?
344
356
 
345
- sub = if (proj = @workspace.find(path))
357
+ sub = if (proj = @workspace.find(entry))
346
358
  proj.packagename
347
- elsif (file = path + 'package.json').exist?
359
+ elsif (file = entry + 'package.json').exist?
348
360
  begin
349
361
  doc = JSON.parse(file.read)
350
362
  rescue StandardError => e
@@ -355,9 +367,9 @@ module Squared
355
367
  end
356
368
  end
357
369
  if sub
358
- target << [path, dest.join(into, sub)]
370
+ target << [entry, dest.join(into, sub)]
359
371
  else
360
- log.debug message("package.json in \"#{path}\"", hint: 'not found')
372
+ log.debug message("package.json in \"#{entry}\"", hint: 'not found')
361
373
  end
362
374
  end
363
375
  else
@@ -402,7 +414,7 @@ module Squared
402
414
  else
403
415
  cmd << 'install'
404
416
  end
405
- if (val = option('public-hoist-pattern', ignore: false))
417
+ option('public-hoist-pattern', ignore: false) do |val|
406
418
  split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt) }
407
419
  end
408
420
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
@@ -448,7 +460,7 @@ module Squared
448
460
  ret = on(:error, :outdated, e)
449
461
  raise if exception && ret != true
450
462
  end
451
- warn log_message(Logger::WARN, e) if warning?
463
+ warn log_message(Logger::WARN, e, pass: true) if warning?
452
464
  return
453
465
  else
454
466
  dep1 = json['dependencies'] || {}
@@ -532,7 +544,7 @@ module Squared
532
544
  found.each_with_index do |item, i|
533
545
  a, b, c, d, e = item
534
546
  f = inter && (rev != :major || e || semmajor?(item[5], item[6]))
535
- if f && !confirm_outdated(a, c, (d / 2.0).ceil, lock: e)
547
+ if f && !confirm_outdated(a, c, (d / 2.0).ceil, b, lock: e, col1: col1)
536
548
  cur = -1
537
549
  else
538
550
  cur = modified
@@ -596,43 +608,49 @@ module Squared
596
608
  end
597
609
 
598
610
  def update(*)
599
- package('update', from: :update)
611
+ package 'update'
600
612
  end
601
613
 
602
614
  def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil, access: nil)
603
- if !version || read_packagemanager(:private)
604
- warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: version ? 'private' : nil)
615
+ if read_packagemanager(:private)
616
+ if warning?
617
+ warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: 'private', pass: true)
618
+ end
605
619
  return
606
620
  end
621
+ return unless version
622
+
607
623
  cmd = session 'npm', 'publish'
624
+ dryrun = dryrun?('npm') if dryrun.nil?
608
625
  cmd << basic_option('otp', otp) if otp ||= option('otp')
609
626
  cmd << basic_option('tag', tag) if tag ||= option('tag')
610
627
  cmd << basic_option('access', access) if access ||= option('access')
611
- dryrun = dryrun?('npm') if dryrun.nil?
612
- if dryrun
613
- cmd << '--dry-run'
614
- else
615
- from = :publish
616
- log.info cmd.to_s
617
- end
618
- if sync
619
- run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(project, styles: theme[:active])}")
620
- else
621
- on :first, from
622
- pwd_set(from: :publish, dryrun: dryrun) do
623
- require 'open3'
624
- banner = format_banner(cmd.to_s)
625
- Open3.popen2e(cmd.done) do |_, out|
626
- write_lines(out, banner: banner, sub: npmnotice + [
627
- { pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2 }
628
- ])
628
+ if verbose
629
+ if dryrun
630
+ cmd << '--dry-run'
631
+ else
632
+ log.info cmd.to_s
633
+ end
634
+ unless sync
635
+ on :first, :publish unless dryrun
636
+ pwd_set(from: :publish) do
637
+ require 'open3'
638
+ banner = format_banner cmd.to_s
639
+ Open3.popen2e(cmd.done) do |_, out|
640
+ write_lines(out, sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:blue), index: 2],
641
+ banner: banner)
642
+ end
629
643
  end
644
+ on :last, :publish unless dryrun
645
+ return
630
646
  end
631
- on :last, from
647
+ elsif dryrun
648
+ return
632
649
  end
650
+ run(from: :publish, sync: sync)
633
651
  end
634
652
 
635
- def package(flag, opts = [], from: nil)
653
+ def package(flag, opts = [])
636
654
  workspace.rev_clear(name)
637
655
  if (yarn = dependtype(:yarn)) > 0
638
656
  cmd = session 'yarn', if flag == :update
@@ -658,7 +676,6 @@ module Squared
658
676
  list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
659
677
  list.concat(OPT_NPM[:install_as]) unless flag == :dedupe
660
678
  no = OPT_NPM[:install_no]
661
- cmd << '--save=true' if option('save')
662
679
  end
663
680
  op = OptionPartition.new(opts, list, cmd, no: no, project: self)
664
681
  op.each do |opt|
@@ -683,7 +700,7 @@ module Squared
683
700
  end
684
701
  op.clear(errors: true)
685
702
  end
686
- run(from: from || :"package:#{flag}")
703
+ run(from: :"package:#{flag}")
687
704
  end
688
705
 
689
706
  def bump(flag, val = nil)
@@ -774,9 +791,9 @@ module Squared
774
791
  if script
775
792
  ret = session dependbin, 'run'
776
793
  raise_error("#{dependbin} run: given #{target}", hint: from) unless append_any(target, build: true)
777
- append_any opts if opts
794
+ append_any opts
778
795
  append_loglevel
779
- append_any(args, delim: true) if args
796
+ append_any(args, delim: true)
780
797
  ret
781
798
  else
782
799
  case target
@@ -900,11 +917,9 @@ module Squared
900
917
  @pm[:_] = false
901
918
  nil
902
919
  else
903
- if key
904
- @pm[key]
905
- elsif (ret = @pm[:_]) && !(version && ret[(ret.index('@') + 1)..-1] < version)
906
- ret
907
- end
920
+ return @pm[key] if key
921
+
922
+ !(ret = @pm[:_]) || (version && ret[ret.index('@') + 1..-1] < version) ? nil : ret
908
923
  end
909
924
 
910
925
  def read_install
@@ -920,7 +935,7 @@ module Squared
920
935
  end
921
936
 
922
937
  def append_loglevel(target: @session)
923
- level = env('NODE_LOGLEVEL')
938
+ level = env 'NODE_LOGLEVEL'
924
939
  silent = !verbose || level == 'silent'
925
940
  return unless silent || level
926
941