squared 0.4.29 → 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.
@@ -5,34 +5,32 @@ module Squared
5
5
  module Project
6
6
  class Node < Git
7
7
  OPT_NPM = {
8
- common: %w[dry-run=!? include-workspace-root=!? loglevel=b workspaces=!? w|workspace=v].freeze,
9
- install: %w[package-lock-only=!? prefer-dedupe=!? cpu=b libc=b os=b].freeze,
10
- install_base: %w[audit=! bin-links=! fund=! ignore-scripts=!? install-links=!? package-lock=!
11
- strict-peer-deps=!? include=b install-strategy=b omit=b].freeze,
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,
12
11
  install_no: %w[audit bin-links fund package-lock].freeze,
13
- install_as: %w[no-save save-bundle save-dev save-optional save-peer save-prod before=q foreground-scripts=!?
14
- g|global=!? S|save=!? E|save-exact=!?].freeze,
15
- run: %w[foreground-scripts=!? if-present=!? ignore-scripts=!? script-shell=p].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,
16
15
  exec: %w[c|call=q package=b].freeze,
17
- pack: %w[ignore-scripts=!? json=!? pack-destination=p].freeze
16
+ pack: %w[json ignore-scripts pack-destination=p].freeze
18
17
  }.freeze
19
18
  OPT_PNPM = {
20
19
  common: %w[aggregate-output color no-color stream use-stderr C|dir=p loglevel=b w|workspace-root].freeze,
21
- cpu: %w[cpu=b libc=b os=b].freeze,
22
20
  filter: %w[fail-if-no-match changed-files-ignore-pattern=q filter=q filter-prod=q test-pattern=q].freeze,
23
21
  install: %w[fix-lockfile force ignore-pnpmfile ignore-workspace lockfile-only merge-git-branch-lockfiles
24
- optimistic-repeat-install no-hoist no-lockfile no-optional prefer-frozen-lockfile resolution-only
25
- shamefully-hoist side-effects-cache side-effects-cache-readonly s|silent strict-peer-dependencies
22
+ no-hoist no-lockfile no-optional prefer-frozen-lockfile resolution-only shamefully-hoist
23
+ side-effects-cache side-effects-cache-readonly s|silent strict-peer-dependencies
26
24
  use-running-store-server use-store-server child-concurrency=i hoist-pattern=q lockfile-dir=p
27
25
  modules-dir=p network-concurrency=i package-import-method=b public-hoist-pattern=q
28
26
  reporter=b].freeze,
29
27
  install_base: %w[global-dir ignore-scripts offline prefer-offline store-dir=p virtual-store-dir=p].freeze,
30
28
  install_no: %w[frozen-lockfile verify-store-integrity].freeze,
31
29
  install_as: %w[D|dev global-dir no-optional P|prod r|recursive].freeze,
32
- update: %w[g|global i|interactive L|latest depth=i].freeze,
30
+ update: %w[global interactive latest depth=i].freeze,
33
31
  dedupe: %w[check].freeze,
34
- run: %w[if-present no-bail parallel r|recursive report-summary reporter-hide-prefix resume-from
35
- sequential].freeze,
32
+ run: %w[if-present no-bail parallel r|recursive report-summary reporter-hide-prefix resume-from sequential
33
+ stream use-stderr].freeze,
36
34
  exec: %w[no-reporter-hide-prefix parallel r|recursive report-summary resume-from c|shell-mode].freeze,
37
35
  pack: %w[json pack-destination=p pack-gzip-level=i].freeze
38
36
  }.freeze
@@ -96,10 +94,11 @@ module Squared
96
94
  'add' => nil,
97
95
  'run' => nil,
98
96
  'exec' => nil,
97
+ 'nvm' => nil,
99
98
  'pack' => nil
100
99
  })
101
100
 
102
- def initialize(*, init: nil, **kwargs)
101
+ def initialize(*, **kwargs)
103
102
  super
104
103
  if @pass.include?(Node.ref)
105
104
  initialize_ref Node.ref
@@ -108,8 +107,8 @@ module Squared
108
107
  initialize_build(Node.ref, prod: prod?, **kwargs)
109
108
  initialize_env(**kwargs)
110
109
  end
111
- @dependfile = basepath 'package.json'
112
- @pm = { __: init }
110
+ @dependfile = @path + 'package.json'
111
+ @pm = {}
113
112
  end
114
113
 
115
114
  def ref
@@ -118,35 +117,39 @@ module Squared
118
117
 
119
118
  def populate(*, **)
120
119
  super
121
- return unless (outdated? && ref?(Node.ref)) || @only
120
+ return unless outdated? && ref?(Node.ref)
122
121
 
123
122
  namespace name do
124
123
  Node.subtasks do |action, flags|
125
- next if task_pass?(action)
124
+ next if @pass.include?(action)
126
125
 
127
126
  if flags.nil?
128
127
  case action
129
128
  when 'add'
130
129
  format_desc action, nil, 'save?=prod|dev|optional|peer,name+'
131
130
  task action, [:save] do |_, args|
132
- packages = if args.save =~ /\A(=)?(prod|dev|optional|peer)\z/
133
- exact = !$1.nil?
134
- save = $2
135
- args.extras
136
- else
137
- save = 'prod'
138
- args.to_a
139
- end
131
+ save = param_guard(action, 'save', args: args, key: :save)
132
+ if save.start_with?('=')
133
+ exact = true
134
+ save = save[1..-1]
135
+ end
136
+ case save
137
+ when 'prod', 'dev', 'optional', 'peer'
138
+ packages = args.to_a.drop(1)
139
+ else
140
+ save = 'prod'
141
+ packages = args.to_a
142
+ end
140
143
  param_guard(action, 'name', args: packages)
141
144
  depend(:add, packages: packages, save: save, exact: exact)
142
145
  end
143
146
  when 'run'
144
147
  next if (list = read_scripts).empty?
145
148
 
146
- format_desc action, nil, "script,opts*|#{indexchar}index+|#,pattern*"
149
+ format_desc action, nil, 'script,opts*|^index+|#,pattern*'
147
150
  task action, [:script] do |_, args|
148
151
  if args.script == '#'
149
- 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)
150
153
  else
151
154
  args = param_guard(action, 'script', args: args.to_a)
152
155
  opts = []
@@ -183,7 +186,7 @@ module Squared
183
186
  format_desc action, nil, 'pkg/cmd,opts*,args*'
184
187
  task action, [:package] do |_, args|
185
188
  if (package = args.package)
186
- args = args.extras
189
+ args = args.to_a.drop(1)
187
190
  if pnpm?
188
191
  pre = ->(ch) { "-#{ch}" if (ch = args.delete(ch)) }
189
192
  cmd = session 'pnpm', pre.call('r'), pre.call('c'), 'exec'
@@ -208,6 +211,17 @@ module Squared
208
211
  end
209
212
  run(from: :exec)
210
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
211
225
  when 'pack'
212
226
  format_desc action, nil, 'opts*'
213
227
  task action do |_, args|
@@ -219,12 +233,12 @@ module Squared
219
233
  flags.each do |flag|
220
234
  case action
221
235
  when 'outdated'
222
- format_desc(action, flag, %w[update interactive dry-run], arg: 'opts?')
236
+ format_desc(action, flag, %w[prune interactive dry-run].freeze, arg: 'opts?')
223
237
  task flag do |_, args|
224
238
  outdated flag, args.to_a
225
239
  end
226
240
  when 'package'
227
- format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'name*')
241
+ format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'names*')
228
242
  task flag do |_, args|
229
243
  package flag, args.to_a
230
244
  end
@@ -245,7 +259,7 @@ module Squared
245
259
  format_desc(action, flag, 'otp?,dry-run?,public|restricted?', before: flag == :tag ? 'tag' : nil)
246
260
  task flag do |_, args|
247
261
  args = args.to_a
248
- dryrun = true if args.delete('dry-run') || args.delete('true') || args.delete('d')
262
+ dryrun = true if args.delete('dry-run') || args.delete('d')
249
263
  if args.delete('public') || args.delete('p')
250
264
  access = 'public'
251
265
  elsif args.delete('restricted') || args.delete('r')
@@ -266,7 +280,7 @@ module Squared
266
280
  end
267
281
  end
268
282
 
269
- def copy(from: 'build', into: 'node_modules', scope: nil, also: nil, create: nil, files: nil, workspace: false,
283
+ def copy(from: 'build', into: 'node_modules', scope: nil, also: nil, create: nil, workspace: false,
270
284
  link: false, force: false, override: false, sync: invoked_sync?('copy'), **kwargs)
271
285
  glob = kwargs[:include]
272
286
  pass = kwargs[:exclude]
@@ -275,7 +289,6 @@ module Squared
275
289
 
276
290
  from = @copy[:from] if @copy.key?(:from)
277
291
  into = @copy[:into] if @copy.key?(:into)
278
- files = @copy[:files] if @copy.key?(:files)
279
292
  workspace = @copy[:workspace] if @copy.key?(:workspace)
280
293
  link = @copy[:link] if @copy.key?(:link)
281
294
  force = @copy[:force] if @copy.key?(:force)
@@ -297,7 +310,6 @@ module Squared
297
310
 
298
311
  on :first, :copy
299
312
  print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/)
300
- packed = false
301
313
  items.each do |dir|
302
314
  case dir
303
315
  when Pathname
@@ -335,56 +347,16 @@ module Squared
335
347
  end
336
348
  next unless from && dest&.directory?
337
349
 
338
- if from == :npm
339
- begin
340
- unless packed
341
- require 'open3'
342
- files = pwd_set do
343
- Open3.capture2e(session_output('npm', 'pack --dry-run --no-color', npmname).to_s)
344
- .first
345
- .scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
346
- .map { |item| Pathname.new(item.first) }
347
- .select(&:exist?)
348
- end
349
- .concat(Array(files))
350
- packed = true
351
- end
352
- to = dest.join(into, npmname)
353
- to.mkpath
354
- log.info "cp npm:#{npmname} #{to}"
355
- subdir = []
356
- errors = 0
357
- files.each do |file|
358
- s, d = file.is_a?(Array) ? file : [file, file]
359
- dest = to + d
360
- unless subdir.include?((target = dest.dirname).to_s)
361
- target.mkpath
362
- subdir << target.to_s
363
- end
364
- begin
365
- FileUtils.cp(basepath(s), dest, verbose: verbosetype > 0)
366
- rescue StandardError => e
367
- print_error e
368
- errors += 1
369
- end
370
- end
371
- rescue StandardError => e
372
- on_error e, :copy
373
- else
374
- puts message(to, subdir.size, files.size - errors) if verbose
375
- end
376
- next
377
- end
378
- glob = Array(glob || '**/*')
350
+ from = path + from
351
+ glob = as_a(glob || '**/*')
379
352
  target = []
380
- from = basepath from
381
353
  if workspace
382
- Dir.glob(from + '*').each do |path|
383
- next unless (path = Pathname.new(path)).directory?
354
+ from.glob('*').each do |entry|
355
+ next unless entry.directory?
384
356
 
385
- sub = if (proj = @workspace.find(path))
357
+ sub = if (proj = @workspace.find(entry))
386
358
  proj.packagename
387
- elsif (file = path + 'package.json').exist?
359
+ elsif (file = entry + 'package.json').exist?
388
360
  begin
389
361
  doc = JSON.parse(file.read)
390
362
  rescue StandardError => e
@@ -395,20 +367,22 @@ module Squared
395
367
  end
396
368
  end
397
369
  if sub
398
- target << [path, dest.join(into, sub)]
370
+ target << [entry, dest.join(into, sub)]
399
371
  else
400
- log.debug message("package.json in \"#{path}\"", hint: 'not found')
372
+ log.debug message("package.json in \"#{entry}\"", hint: 'not found')
401
373
  end
402
374
  end
403
375
  else
404
- target << [from, dest.join(into, scope || npmname)]
376
+ target << [from, dest.join(into, scope || project)]
405
377
  end
406
378
  target.each do |src, to|
407
379
  glob.each { |val| log.info "cp #{from + val} #{to}" }
408
380
  begin
409
- copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbosetype > 0)
381
+ copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
410
382
  rescue StandardError => e
411
- on_error e, :copy
383
+ log.error e
384
+ ret = on(:error, :copy, e)
385
+ raise if exception && ret != true
412
386
  end
413
387
  end
414
388
  end
@@ -439,9 +413,8 @@ module Squared
439
413
  cmd << '--save-exact' if exact
440
414
  else
441
415
  cmd << 'install'
442
- append_platform
443
416
  end
444
- if (val = option('public-hoist-pattern', ignore: false))
417
+ option('public-hoist-pattern', ignore: false) do |val|
445
418
  split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt) }
446
419
  end
447
420
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
@@ -451,9 +424,7 @@ module Squared
451
424
  if flag == :add
452
425
  cmd << "--save-#{save}"
453
426
  cmd << '--save-exact' if exact
454
- cmd.merge(packages.map { |pkg| shell_quote(pkg) })
455
- else
456
- append_platform
427
+ cmd.merge(packages.map { |pkg| shell_escape(pkg) })
457
428
  end
458
429
  cmd << '--workspaces=false' if env('NODE_WORKSPACES', equals: '0')
459
430
  cmd << '--package-lock=false' if option('package-lock', equals: '0')
@@ -466,7 +437,7 @@ module Squared
466
437
 
467
438
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
468
439
  dryrun = opts.include?('dry-run') || opts.include?('d')
469
- if pnpm?
440
+ if pnpm? && read_packagemanager(version: '7.15', update: true)
470
441
  cmd = session 'pnpm', 'outdated'
471
442
  dryrun ||= dryrun?('pnpm')
472
443
  else
@@ -477,14 +448,19 @@ module Squared
477
448
  log.info cmd.to_s
478
449
  on :first, :outdated
479
450
  end
480
- banner = format_banner(cmd.temp(dryrun ? '--dry-run' : nil))
451
+ banner = format_banner(cmd.temp(dryrun ? ' --dry-run' : nil))
481
452
  print_item banner if sync
482
453
  begin
483
454
  data = pwd_set { `#{cmd.temp('--json', '--loglevel=error')}` }
484
455
  doc = dependfile.read
485
456
  json = JSON.parse(doc)
486
457
  rescue StandardError => e
487
- on_error(e, :outdated, dryrun: dryrun)
458
+ log.error e
459
+ unless dryrun
460
+ ret = on(:error, :outdated, e)
461
+ raise if exception && ret != true
462
+ end
463
+ warn log_message(Logger::WARN, e, pass: true) if warning?
488
464
  return
489
465
  else
490
466
  dep1 = json['dependencies'] || {}
@@ -511,19 +487,7 @@ module Squared
511
487
  next
512
488
  end
513
489
  current = val['current'] || file
514
- want = val['wanted']
515
- unless latest[SEM_VER, 6]
516
- case rev
517
- when :major
518
- want = latest
519
- when :minor
520
- want = latest if latest[SEM_VER, 1] == want[SEM_VER, 1]
521
- when :patch
522
- if (g = latest.match(SEM_VER)) && (h = want.match(SEM_VER)) && g[1] == h[1] && g[3] == h[3]
523
- want = latest
524
- end
525
- end
526
- end
490
+ want = rev == :major && !latest[SEM_VER, 6] ? latest : val['wanted']
527
491
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
528
492
 
529
493
  f = semscan file
@@ -580,7 +544,7 @@ module Squared
580
544
  found.each_with_index do |item, i|
581
545
  a, b, c, d, e = item
582
546
  f = inter && (rev != :major || e || semmajor?(item[5], item[6]))
583
- 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)
584
548
  cur = -1
585
549
  else
586
550
  cur = modified
@@ -615,13 +579,10 @@ module Squared
615
579
  footer.call(modified, found.size)
616
580
  elsif modified > 0
617
581
  modified = -1
582
+ footer.call(0, found.size)
618
583
  File.write(dependfile, doc)
619
- if opts.include?('update') || opts.include?('u') || option('update')
620
- update
621
- else
622
- footer.call(0, found.size)
623
- end
624
- commit(:add, ['package.json'], pass: true)
584
+ commit(:add, refs: ['package.json'], pass: true)
585
+ install if opts.include?('prune') || opts.include?('p')
625
586
  end
626
587
  elsif !avail.empty?
627
588
  col1 = size_col.call(avail, 0) + 4
@@ -647,60 +608,61 @@ module Squared
647
608
  end
648
609
 
649
610
  def update(*)
650
- package(:update, from: :update)
611
+ package 'update'
651
612
  end
652
613
 
653
- def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil)
654
- unless version && !read_packagemanager(:private)
655
- print_error('invalid task "publish"', subject: name, hint: version ? 'private' : nil)
614
+ def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil, access: 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
656
619
  return
657
620
  end
621
+ return unless version
622
+
658
623
  cmd = session 'npm', 'publish'
624
+ dryrun = dryrun?('npm') if dryrun.nil?
659
625
  cmd << basic_option('otp', otp) if otp ||= option('otp')
660
- cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
661
- case access || option('access')
662
- when 'p', 'public'
663
- cmd << '--access=public'
664
- when 'r', 'restricted'
665
- cmd << '--access=restricted'
666
- end
667
- dryrun ||= dryrun?('npm')
668
- if dryrun
669
- cmd << '--dry-run'
670
- else
671
- from = :publish
672
- log.info cmd.to_s
673
- end
674
- if sync
675
- run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(npmname, styles: theme[:active])}")
676
- else
677
- require 'open3'
678
- on :first, from
679
- pwd_set(from: from, dryrun: dryrun) do
680
- cmd = session_done cmd
681
- Open3.popen2e(cmd) do |_, out|
682
- write_lines(out, banner: format_banner(cmd),
683
- sub: npmnotice + [pat: /^(.+)(Tarball .+)$/, styles: color(:bright_blue), index: 2])
626
+ cmd << basic_option('tag', tag) if tag ||= option('tag')
627
+ cmd << basic_option('access', access) if access ||= option('access')
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
684
643
  end
644
+ on :last, :publish unless dryrun
645
+ return
685
646
  end
686
- on :last, from
647
+ elsif dryrun
648
+ return
687
649
  end
650
+ run(from: :publish, sync: sync)
688
651
  end
689
652
 
690
- def package(flag, opts = [], from: nil)
653
+ def package(flag, opts = [])
691
654
  workspace.rev_clear(name)
692
655
  if (yarn = dependtype(:yarn)) > 0
693
656
  cmd = session 'yarn', if flag == :update
694
- yarn == 1 ? 'upgrade' : 'up'
657
+ flag = yarn == 1 ? 'upgrade' : 'up'
695
658
  else
696
- yarn == 1 && flag == :dedupe ? 'install' : flag
659
+ flag
697
660
  end
698
661
  op = OptionPartition.new(opts, if yarn == 1
699
- OPT_YARN.fetch(flag == :dedupe ? :install : flag, []) + OPT_YARN[:common]
662
+ OPT_YARN.fetch(flag, []) + OPT_YARN[:common]
700
663
  else
701
664
  OPT_BERRY[flag]
702
665
  end, cmd, project: self)
703
- op << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0')
704
666
  op.clear
705
667
  append_loglevel
706
668
  else
@@ -708,7 +670,6 @@ module Squared
708
670
  cmd = session 'pnpm', flag
709
671
  list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common]
710
672
  list.concat(OPT_PNPM[:install_as] + OPT_PNPM[:filter]) unless flag == :dedupe
711
- list.concat(OPT_PNPM[:cpu]) unless flag == :update
712
673
  no = OPT_PNPM[:"#{flag}_no"]
713
674
  else
714
675
  cmd = session 'npm', flag
@@ -721,7 +682,7 @@ module Squared
721
682
  if opt =~ op.values
722
683
  case $1
723
684
  when 'w', 'workspace'
724
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
685
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
725
686
  end
726
687
  elsif opt.include?('=')
727
688
  op.errors << opt
@@ -730,17 +691,16 @@ module Squared
730
691
  end
731
692
  end
732
693
  op.swap
733
- append_platform if flag == :install
734
694
  append_nocolor
735
695
  append_loglevel
736
696
  if flag == :dedupe
737
697
  op.clear
738
698
  else
739
- op.append(quote: true)
699
+ op.append(escape: true)
740
700
  end
741
701
  op.clear(errors: true)
742
702
  end
743
- run(from: from || :"package:#{flag}")
703
+ run(from: :"package:#{flag}")
744
704
  end
745
705
 
746
706
  def bump(flag, val = nil)
@@ -754,17 +714,14 @@ module Squared
754
714
  when :major
755
715
  if seg[0] != '0' || seg[2].nil?
756
716
  seg[0] = seg[0].succ
757
- seg[2] = '0'
758
717
  else
759
718
  seg[2] = seg[2].succ
760
719
  end
761
- seg[4] = '0'
762
720
  when :minor
763
721
  if seg[0] == '0'
764
722
  seg[4] &&= seg[4].succ
765
723
  else
766
724
  seg[2] = seg[2].succ
767
- seg[4] &&= '0'
768
725
  end
769
726
  when :patch
770
727
  seg[4] &&= seg[4].succ
@@ -780,22 +737,24 @@ module Squared
780
737
  log.info "bump version #{cur} to #{val} (#{flag})"
781
738
  on :first, :bump
782
739
  end
783
- if stdin?
784
- puts val
785
- elsif verbose
740
+ if verbose
786
741
  major = flag == :major
787
742
  emphasize("version: #{val}", title: name, border: borderstyle, sub: [
788
743
  headerstyle,
789
744
  { pat: /\A(version:)( )(\S+)(.*)\z/, styles: color(major ? :green : :yellow), index: 3 },
790
745
  { pat: /\A(version:)(.*)\z/, styles: theme[major ? :major : :active] }
791
746
  ])
747
+ elsif stdin?
748
+ puts val
792
749
  end
793
750
  on :last, :bump unless dryrun?
794
751
  else
795
752
  raise_error('version not found', hint: dependfile)
796
753
  end
797
754
  rescue StandardError => e
798
- on_error e, :bump
755
+ log.debug e
756
+ ret = on(:error, :bump, e)
757
+ raise if exception && ret != true
799
758
  end
800
759
  end
801
760
 
@@ -805,7 +764,7 @@ module Squared
805
764
  cmd = session dependbin, 'pack'
806
765
  if dependtype(:yarn) > 1
807
766
  op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self)
808
- op.append?('out', Pathname.pwd + "#{project}-#{version}.tgz")
767
+ op << quote_option('out', Pathname.pwd + "#{project}-#{version}.tgz") unless op.arg?('out')
809
768
  else
810
769
  op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common], cmd,
811
770
  project: self)
@@ -815,12 +774,12 @@ module Squared
815
774
 
816
775
  case $1
817
776
  when 'w', 'workspace'
818
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
777
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
819
778
  op.found << opt
820
779
  end
821
780
  end
822
781
  end
823
- op.append?('pack-destination', Dir.pwd)
782
+ op << quote_option('pack-destination', Dir.pwd) unless op.arg?('pack-destination')
824
783
  end
825
784
  op.clear
826
785
  run(from: :pack)
@@ -832,16 +791,16 @@ module Squared
832
791
  if script
833
792
  ret = session dependbin, 'run'
834
793
  raise_error("#{dependbin} run: given #{target}", hint: from) unless append_any(target, build: true)
835
- append_any opts if opts
794
+ append_any opts
836
795
  append_loglevel
837
- append_any(args, delim: true) if args
796
+ append_any(args, delim: true)
838
797
  ret
839
798
  else
840
799
  case target
841
800
  when String
842
801
  target
843
802
  when Hash
844
- append_hash(target, target: []).join(' ')
803
+ append_hash(target).join(' ')
845
804
  when Enumerable
846
805
  target.to_a.join(' ')
847
806
  else
@@ -868,32 +827,45 @@ module Squared
868
827
 
869
828
  def yarn?
870
829
  (@pm[:yarn] ||= if rootpath('yarn.lock', ascend: dependext).exist?
871
- yarntype
872
- elsif (ver = read_packagemanager || read_install)
873
- if ver =~ /^yarn(?:@(\d)|$)/
874
- $1 && $1.to_i > 1 ? yarntype : 1
830
+ if (rc = rootpath('.yarnrc.yml', ascend: dependext)).exist?
831
+ begin
832
+ require 'yaml'
833
+ doc = YAML.load_file(rc)
834
+ doc.nodeLinker == 'node-modules' ? 2 : 3
835
+ rescue StandardError => e
836
+ log.debug e
837
+ 3
838
+ end
875
839
  else
876
- 0
877
- end
878
- else
879
- case @pm[:__]
880
- when 'yarn'
881
840
  1
882
- when 'berry'
883
- yarntype
884
- else
885
- 0
886
841
  end
842
+ elsif (ver = read_packagemanager || read_install)&.start_with?('yarn')
843
+ ver == 'yarn' || ver.include?('@1') ? 1 : 3
844
+ else
845
+ 0
887
846
  end) > 0
888
847
  end
889
848
 
890
849
  def pnpm?
891
850
  (@pm[:pnpm] ||= if rootpath('pnpm-lock.yaml', ascend: dependext).exist?
892
- pnpmtype
893
- elsif (ver = read_packagemanager || read_install)
894
- ver.start_with?('pnpm') ? pnpmtype : 0
851
+ begin
852
+ require 'yaml'
853
+ doc = YAML.load_file(basepath('node_modules/.modules.yaml', ascend: dependext))
854
+ @pm[:_] = doc['packageManager']
855
+ case doc['nodeLinker']
856
+ when 'hoisted'
857
+ 1
858
+ when 'pnp'
859
+ 3
860
+ else
861
+ 4
862
+ end
863
+ rescue StandardError => e
864
+ log.debug e
865
+ 4
866
+ end
895
867
  else
896
- @pm[:__] == 'pnpm' ? pnpmtype : 0
868
+ (read_packagemanager || read_install)&.start_with?('pnpm') ? 4 : 0
897
869
  end) > 0
898
870
  end
899
871
 
@@ -920,124 +892,50 @@ module Squared
920
892
  respond_to?(meth) && __send__(meth) ? @pm[prog] : 0
921
893
  end
922
894
 
923
- def dependbin
924
- if yarn?
925
- 'yarn'
926
- else
927
- pnpm? ? 'pnpm' : 'npm'
928
- end
929
- end
930
-
931
895
  def version
932
- @version ||= read_packagemanager(:version)
896
+ super || (@version = read_packagemanager(:version))
933
897
  end
934
898
 
935
899
  def packagename
936
900
  read_packagemanager :name
937
901
  end
938
902
 
939
- def scripts
940
- @scripts ||= read_scripts.to_h
941
- end
942
-
943
903
  private
944
904
 
945
905
  def read_packagemanager(key = nil, version: nil, update: false)
946
- if (key ? !@pm.key?(key) : @pm[:_].nil?) || update
906
+ if @pm[:_].nil? || update
947
907
  doc = JSON.parse(dependfile.read)
948
- if @pm[:_].nil?
949
- @pm[:_] = (val = doc['packageManager']) ? val[0, val.index('+') || val.size] : false
950
- @pm[:name] = doc['name']
951
- @pm[:scripts] = doc['scripts']
952
- @pm[:version] = doc['version']
953
- @pm[:private] = doc['private']
954
- @pm[:workspaces] = doc['workspaces']
955
- end
956
- @pm[key] = doc[key.to_s] if key
908
+ @pm[:_] = (val = doc['packageManager']) ? val[0, val.index('+') || val.size] : false
909
+ @pm[:name] = doc['name']
910
+ @pm[:scripts] = doc['scripts']
911
+ @pm[:version] = doc['version']
912
+ @pm[:private] = doc['private']
913
+ @pm[:workspaces] = doc['workspaces']
957
914
  end
958
915
  rescue StandardError => e
959
916
  log.debug e
960
917
  @pm[:_] = false
961
918
  nil
962
919
  else
963
- if key
964
- @pm[key]
965
- elsif (ret = @pm[:_]) && (!version || semgte?(ret[(ret.index('@') + 1)..-1], version))
966
- ret
967
- end
920
+ return @pm[key] if key
921
+
922
+ !(ret = @pm[:_]) || (version && ret[ret.index('@') + 1..-1] < version) ? nil : ret
968
923
  end
969
924
 
970
925
  def read_install
971
926
  return unless (ret = env('NODE_INSTALL'))
972
927
 
973
- if ret.include?(',')
974
- catch :found do
975
- split_escape(ret).each do |val|
976
- case val
977
- when /^yarn/
978
- next if yarntype(exist: true) == 0
979
- when /^pnpm/
980
- next if pnpmtype(exist: true) == 0
981
- when /^npm/
982
- nil
983
- else
984
- next
985
- end
986
- ret = val
987
- throw :found
988
- end
989
- return
990
- end
991
- end
992
- @pm[:_] ||= ret
928
+ @pm[:_] ||= ret if ret.include?('@')
993
929
  ret
994
930
  end
995
931
 
996
- def yarntype(exist: false)
997
- if (rc = rootpath('.yarnrc.yml', ascend: dependext)).exist?
998
- require 'yaml'
999
- doc = YAML.load_file(rc)
1000
- doc.nodeLinker == 'node-modules' ? 2 : 3
1001
- elsif exist && !basepath('yarn.lock').exist?
1002
- 0
1003
- else
1004
- 1
1005
- end
1006
- rescue StandardError => e
1007
- return 0 if exist
1008
-
1009
- log.debug e
1010
- 3
1011
- end
1012
-
1013
- def pnpmtype(exist: false)
1014
- require 'yaml'
1015
- doc = YAML.load_file(basepath('node_modules/.modules.yaml', ascend: dependext))
1016
- @pm['packageManager'] = doc['packageManager']
1017
- case doc['nodeLinker']
1018
- when 'hoisted'
1019
- 1
1020
- when 'pnp'
1021
- 3
1022
- else
1023
- 4
1024
- end
1025
- rescue StandardError => e
1026
- if exist
1027
- %w[pnpm-lock.yaml pnpm-workspace.yaml].any? { |val| basepath(val).exist? } ? 4 : 0
1028
- else
1029
- log.debug e
1030
- 4
1031
- end
1032
- end
1033
-
1034
932
  def read_scripts
1035
933
  ret = read_packagemanager(:scripts)
1036
934
  ret.is_a?(Hash) ? ret.to_a : []
1037
935
  end
1038
936
 
1039
937
  def append_loglevel(target: @session)
1040
- level = env('NODE_LOGLEVEL')
938
+ level = env 'NODE_LOGLEVEL'
1041
939
  silent = !verbose || level == 'silent'
1042
940
  return unless silent || level
1043
941
 
@@ -1068,11 +966,15 @@ module Squared
1068
966
  end
1069
967
  end
1070
968
 
1071
- def append_platform(target: @session)
1072
- %w[cpu os libc].each do |name|
1073
- next unless (val = option(name))
969
+ def dryrun?(prefix = dependbin, **)
970
+ super || !option('dry-run', prefix: prefix).nil?
971
+ end
1074
972
 
1075
- target << basic_option(name, val)
973
+ def dependbin
974
+ if yarn?
975
+ 'yarn'
976
+ else
977
+ pnpm? ? 'pnpm' : 'npm'
1076
978
  end
1077
979
  end
1078
980
 
@@ -1080,22 +982,14 @@ module Squared
1080
982
  'package.json' if parent&.has?('outdated', Node.ref)
1081
983
  end
1082
984
 
1083
- def npmname
1084
- packagename || project
1085
- end
1086
-
1087
985
  def npmnotice
1088
986
  [
1089
- { pat: /^(npm error )(code|\d+)(.+)$/, styles: color(:bright_cyan), index: 2 },
1090
- { pat: /^(npm )(error)(.*)$/, styles: color(:bright_red), index: 2 },
1091
- { pat: /^(npm )(notice)(.*)$/, styles: color(:bright_cyan), index: 2 },
987
+ { pat: /^(npm error )(code|\d+)(.+)$/, styles: color(:cyan), index: 2 },
988
+ { pat: /^(npm )(error)(.*)$/, styles: color(:red), index: 2 },
989
+ { pat: /^(npm )(notice)(.*)$/, styles: color(:cyan), index: 2 },
1092
990
  { pat: /^(npm )(.+)$/, styles: :bold }
1093
991
  ]
1094
992
  end
1095
-
1096
- def dryrun?(prefix = dependbin, **)
1097
- super || !option('dry-run', prefix: prefix).nil?
1098
- end
1099
993
  end
1100
994
 
1101
995
  Application.implement Node