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