squared 0.4.25 → 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,11 +117,11 @@ 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
@@ -134,23 +133,23 @@ module Squared
134
133
  exact = true
135
134
  save = save[1..-1]
136
135
  end
137
- packages = case save
138
- when 'prod', 'dev', 'optional', 'peer'
139
- args.extras
140
- else
141
- save = 'prod'
142
- args.to_a
143
- 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
144
143
  param_guard(action, 'name', args: packages)
145
144
  depend(:add, packages: packages, save: save, exact: exact)
146
145
  end
147
146
  when 'run'
148
147
  next if (list = read_scripts).empty?
149
148
 
150
- format_desc action, nil, "script,opts*|#{indexchar}index+|#,pattern*"
149
+ format_desc action, nil, 'script,opts*|^index+|#,pattern*'
151
150
  task action, [:script] do |_, args|
152
151
  if args.script == '#'
153
- 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)
154
153
  else
155
154
  args = param_guard(action, 'script', args: args.to_a)
156
155
  opts = []
@@ -187,7 +186,7 @@ module Squared
187
186
  format_desc action, nil, 'pkg/cmd,opts*,args*'
188
187
  task action, [:package] do |_, args|
189
188
  if (package = args.package)
190
- args = args.extras
189
+ args = args.to_a.drop(1)
191
190
  if pnpm?
192
191
  pre = ->(ch) { "-#{ch}" if (ch = args.delete(ch)) }
193
192
  cmd = session 'pnpm', pre.call('r'), pre.call('c'), 'exec'
@@ -212,6 +211,17 @@ module Squared
212
211
  end
213
212
  run(from: :exec)
214
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
215
225
  when 'pack'
216
226
  format_desc action, nil, 'opts*'
217
227
  task action do |_, args|
@@ -223,12 +233,12 @@ module Squared
223
233
  flags.each do |flag|
224
234
  case action
225
235
  when 'outdated'
226
- format_desc(action, flag, %w[update interactive dry-run], arg: 'opts?')
236
+ format_desc(action, flag, %w[prune interactive dry-run].freeze, arg: 'opts?')
227
237
  task flag do |_, args|
228
238
  outdated flag, args.to_a
229
239
  end
230
240
  when 'package'
231
- format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'name*')
241
+ format_desc(action, flag, 'opts*', after: flag == :dedupe ? nil : 'names*')
232
242
  task flag do |_, args|
233
243
  package flag, args.to_a
234
244
  end
@@ -249,7 +259,7 @@ module Squared
249
259
  format_desc(action, flag, 'otp?,dry-run?,public|restricted?', before: flag == :tag ? 'tag' : nil)
250
260
  task flag do |_, args|
251
261
  args = args.to_a
252
- dryrun = true if args.delete('dry-run') || args.delete('true') || args.delete('d')
262
+ dryrun = true if args.delete('dry-run') || args.delete('d')
253
263
  if args.delete('public') || args.delete('p')
254
264
  access = 'public'
255
265
  elsif args.delete('restricted') || args.delete('r')
@@ -270,7 +280,7 @@ module Squared
270
280
  end
271
281
  end
272
282
 
273
- 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,
274
284
  link: false, force: false, override: false, sync: invoked_sync?('copy'), **kwargs)
275
285
  glob = kwargs[:include]
276
286
  pass = kwargs[:exclude]
@@ -279,7 +289,6 @@ module Squared
279
289
 
280
290
  from = @copy[:from] if @copy.key?(:from)
281
291
  into = @copy[:into] if @copy.key?(:into)
282
- files = @copy[:files] if @copy.key?(:files)
283
292
  workspace = @copy[:workspace] if @copy.key?(:workspace)
284
293
  link = @copy[:link] if @copy.key?(:link)
285
294
  force = @copy[:force] if @copy.key?(:force)
@@ -301,7 +310,6 @@ module Squared
301
310
 
302
311
  on :first, :copy
303
312
  print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/)
304
- packed = false
305
313
  items.each do |dir|
306
314
  case dir
307
315
  when Pathname
@@ -339,56 +347,16 @@ module Squared
339
347
  end
340
348
  next unless from && dest&.directory?
341
349
 
342
- if from == :npm
343
- begin
344
- unless packed
345
- require 'open3'
346
- files = pwd_set do
347
- Open3.capture2e(session_output('npm', 'pack --dry-run --no-color', npmname).to_s)
348
- .first
349
- .scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
350
- .map { |item| Pathname.new(item.first) }
351
- .select(&:exist?)
352
- end
353
- .concat(Array(files))
354
- packed = true
355
- end
356
- to = dest.join(into, npmname)
357
- to.mkpath
358
- log.info "cp npm:#{npmname} #{to}"
359
- subdir = []
360
- errors = 0
361
- files.each do |file|
362
- s, d = file.is_a?(Array) ? file : [file, file]
363
- dest = to + d
364
- unless subdir.include?((target = dest.dirname).to_s)
365
- target.mkpath
366
- subdir << target.to_s
367
- end
368
- begin
369
- FileUtils.cp(basepath(s), dest, verbose: verbosetype > 0)
370
- rescue StandardError => e
371
- print_error e
372
- errors += 1
373
- end
374
- end
375
- rescue StandardError => e
376
- on_error e, :copy
377
- else
378
- puts message(to, subdir.size, files.size - errors) if verbose
379
- end
380
- next
381
- end
382
- glob = Array(glob || '**/*')
350
+ from = path + from
351
+ glob = as_a(glob || '**/*')
383
352
  target = []
384
- from = basepath from
385
353
  if workspace
386
- Dir.glob(from + '*').each do |path|
387
- next unless (path = Pathname.new(path)).directory?
354
+ from.glob('*').each do |entry|
355
+ next unless entry.directory?
388
356
 
389
- sub = if (proj = @workspace.find(path))
357
+ sub = if (proj = @workspace.find(entry))
390
358
  proj.packagename
391
- elsif (file = path + 'package.json').exist?
359
+ elsif (file = entry + 'package.json').exist?
392
360
  begin
393
361
  doc = JSON.parse(file.read)
394
362
  rescue StandardError => e
@@ -399,20 +367,22 @@ module Squared
399
367
  end
400
368
  end
401
369
  if sub
402
- target << [path, dest.join(into, sub)]
370
+ target << [entry, dest.join(into, sub)]
403
371
  else
404
- log.debug message("package.json in \"#{path}\"", hint: 'not found')
372
+ log.debug message("package.json in \"#{entry}\"", hint: 'not found')
405
373
  end
406
374
  end
407
375
  else
408
- target << [from, dest.join(into, scope || npmname)]
376
+ target << [from, dest.join(into, scope || project)]
409
377
  end
410
378
  target.each do |src, to|
411
379
  glob.each { |val| log.info "cp #{from + val} #{to}" }
412
380
  begin
413
- 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)
414
382
  rescue StandardError => e
415
- on_error e, :copy
383
+ log.error e
384
+ ret = on(:error, :copy, e)
385
+ raise if exception && ret != true
416
386
  end
417
387
  end
418
388
  end
@@ -426,19 +396,7 @@ module Squared
426
396
  workspace.rev_clear(name, sync: sync)
427
397
  return update if !flag && env('NODE_UPDATE')
428
398
 
429
- pnpm = pnpm?
430
- yarn = pnpm ? 0 : dependtype(:yarn)
431
- if @pm[:__] && !pnpm && yarn == 0
432
- case @pm[:__]
433
- when 'pnpm'
434
- pnpm = true
435
- when 'yarn'
436
- yarn = 1
437
- when 'berry'
438
- yarn = 2
439
- end
440
- end
441
- if yarn > 0
399
+ if (yarn = dependtype(:yarn)) > 0
442
400
  cmd = session 'yarn'
443
401
  if flag == :add
444
402
  cmd << 'add'
@@ -448,16 +406,15 @@ module Squared
448
406
  cmd << 'install'
449
407
  cmd << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0')
450
408
  end
451
- elsif pnpm
409
+ elsif pnpm?
452
410
  cmd = session 'pnpm'
453
411
  if flag == :add
454
412
  cmd << 'add' << "--save-#{save}"
455
413
  cmd << '--save-exact' if exact
456
414
  else
457
415
  cmd << 'install'
458
- append_platform
459
416
  end
460
- if (val = option('public-hoist-pattern', ignore: false))
417
+ option('public-hoist-pattern', ignore: false) do |val|
461
418
  split_escape(val).each { |opt| cmd << shell_option('public-hoist-pattern', opt) }
462
419
  end
463
420
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
@@ -467,9 +424,7 @@ module Squared
467
424
  if flag == :add
468
425
  cmd << "--save-#{save}"
469
426
  cmd << '--save-exact' if exact
470
- cmd.merge(packages.map { |pkg| shell_quote(pkg) })
471
- else
472
- append_platform
427
+ cmd.merge(packages.map { |pkg| shell_escape(pkg) })
473
428
  end
474
429
  cmd << '--workspaces=false' if env('NODE_WORKSPACES', equals: '0')
475
430
  cmd << '--package-lock=false' if option('package-lock', equals: '0')
@@ -482,7 +437,7 @@ module Squared
482
437
 
483
438
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
484
439
  dryrun = opts.include?('dry-run') || opts.include?('d')
485
- if pnpm?
440
+ if pnpm? && read_packagemanager(version: '7.15', update: true)
486
441
  cmd = session 'pnpm', 'outdated'
487
442
  dryrun ||= dryrun?('pnpm')
488
443
  else
@@ -493,14 +448,19 @@ module Squared
493
448
  log.info cmd.to_s
494
449
  on :first, :outdated
495
450
  end
496
- banner = format_banner(cmd.temp(dryrun ? '--dry-run' : nil))
451
+ banner = format_banner(cmd.temp(dryrun ? ' --dry-run' : nil))
497
452
  print_item banner if sync
498
453
  begin
499
454
  data = pwd_set { `#{cmd.temp('--json', '--loglevel=error')}` }
500
455
  doc = dependfile.read
501
456
  json = JSON.parse(doc)
502
457
  rescue StandardError => e
503
- 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?
504
464
  return
505
465
  else
506
466
  dep1 = json['dependencies'] || {}
@@ -527,19 +487,7 @@ module Squared
527
487
  next
528
488
  end
529
489
  current = val['current'] || file
530
- want = val['wanted']
531
- unless latest[SEM_VER, 6]
532
- case rev
533
- when :major
534
- want = latest
535
- when :minor
536
- want = latest if latest[SEM_VER, 1] == want[SEM_VER, 1]
537
- when :patch
538
- if (g = latest.match(SEM_VER)) && (h = want.match(SEM_VER)) && g[1] == h[1] && g[3] == h[3]
539
- want = latest
540
- end
541
- end
542
- end
490
+ want = rev == :major && !latest[SEM_VER, 6] ? latest : val['wanted']
543
491
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
544
492
 
545
493
  f = semscan file
@@ -596,7 +544,7 @@ module Squared
596
544
  found.each_with_index do |item, i|
597
545
  a, b, c, d, e = item
598
546
  f = inter && (rev != :major || e || semmajor?(item[5], item[6]))
599
- 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)
600
548
  cur = -1
601
549
  else
602
550
  cur = modified
@@ -631,13 +579,10 @@ module Squared
631
579
  footer.call(modified, found.size)
632
580
  elsif modified > 0
633
581
  modified = -1
582
+ footer.call(0, found.size)
634
583
  File.write(dependfile, doc)
635
- if opts.include?('update') || opts.include?('u') || option('update')
636
- update
637
- else
638
- footer.call(0, found.size)
639
- end
640
584
  commit(:add, refs: ['package.json'], pass: true)
585
+ install if opts.include?('prune') || opts.include?('p')
641
586
  end
642
587
  elsif !avail.empty?
643
588
  col1 = size_col.call(avail, 0) + 4
@@ -663,60 +608,61 @@ module Squared
663
608
  end
664
609
 
665
610
  def update(*)
666
- package(:update, from: :update)
611
+ package 'update'
667
612
  end
668
613
 
669
- def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil)
670
- unless version && !read_packagemanager(:private)
671
- 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
672
619
  return
673
620
  end
621
+ return unless version
622
+
674
623
  cmd = session 'npm', 'publish'
624
+ dryrun = dryrun?('npm') if dryrun.nil?
675
625
  cmd << basic_option('otp', otp) if otp ||= option('otp')
676
- cmd << basic_option('tag', tag.tr(' ', '-')) if tag ||= option('tag')
677
- case access || option('access')
678
- when 'p', 'public'
679
- cmd << '--access=public'
680
- when 'r', 'restricted'
681
- cmd << '--access=restricted'
682
- end
683
- dryrun ||= dryrun?('npm')
684
- if dryrun
685
- cmd << '--dry-run'
686
- else
687
- from = :publish
688
- log.info cmd.to_s
689
- end
690
- if sync
691
- run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(npmname, styles: theme[:active])}")
692
- else
693
- require 'open3'
694
- on :first, from
695
- pwd_set(from: from, dryrun: dryrun) do
696
- cmd = session_done cmd
697
- Open3.popen2e(cmd) do |_, out|
698
- write_lines(out, banner: format_banner(cmd),
699
- 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
700
643
  end
644
+ on :last, :publish unless dryrun
645
+ return
701
646
  end
702
- on :last, from
647
+ elsif dryrun
648
+ return
703
649
  end
650
+ run(from: :publish, sync: sync)
704
651
  end
705
652
 
706
- def package(flag, opts = [], from: nil)
653
+ def package(flag, opts = [])
707
654
  workspace.rev_clear(name)
708
655
  if (yarn = dependtype(:yarn)) > 0
709
656
  cmd = session 'yarn', if flag == :update
710
- yarn == 1 ? 'upgrade' : 'up'
657
+ flag = yarn == 1 ? 'upgrade' : 'up'
711
658
  else
712
- yarn == 1 && flag == :dedupe ? 'install' : flag
659
+ flag
713
660
  end
714
661
  op = OptionPartition.new(opts, if yarn == 1
715
- OPT_YARN.fetch(flag == :dedupe ? :install : flag, []) + OPT_YARN[:common]
662
+ OPT_YARN.fetch(flag, []) + OPT_YARN[:common]
716
663
  else
717
664
  OPT_BERRY[flag]
718
665
  end, cmd, project: self)
719
- op << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0')
720
666
  op.clear
721
667
  append_loglevel
722
668
  else
@@ -724,7 +670,6 @@ module Squared
724
670
  cmd = session 'pnpm', flag
725
671
  list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common]
726
672
  list.concat(OPT_PNPM[:install_as] + OPT_PNPM[:filter]) unless flag == :dedupe
727
- list.concat(OPT_PNPM[:cpu]) unless flag == :update
728
673
  no = OPT_PNPM[:"#{flag}_no"]
729
674
  else
730
675
  cmd = session 'npm', flag
@@ -737,7 +682,7 @@ module Squared
737
682
  if opt =~ op.values
738
683
  case $1
739
684
  when 'w', 'workspace'
740
- 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))
741
686
  end
742
687
  elsif opt.include?('=')
743
688
  op.errors << opt
@@ -746,17 +691,16 @@ module Squared
746
691
  end
747
692
  end
748
693
  op.swap
749
- append_platform if flag == :install
750
694
  append_nocolor
751
695
  append_loglevel
752
696
  if flag == :dedupe
753
697
  op.clear
754
698
  else
755
- op.append(quote: true)
699
+ op.append(escape: true)
756
700
  end
757
701
  op.clear(errors: true)
758
702
  end
759
- run(from: from || :"package:#{flag}")
703
+ run(from: :"package:#{flag}")
760
704
  end
761
705
 
762
706
  def bump(flag, val = nil)
@@ -770,17 +714,14 @@ module Squared
770
714
  when :major
771
715
  if seg[0] != '0' || seg[2].nil?
772
716
  seg[0] = seg[0].succ
773
- seg[2] = '0'
774
717
  else
775
718
  seg[2] = seg[2].succ
776
719
  end
777
- seg[4] = '0'
778
720
  when :minor
779
721
  if seg[0] == '0'
780
722
  seg[4] &&= seg[4].succ
781
723
  else
782
724
  seg[2] = seg[2].succ
783
- seg[4] &&= '0'
784
725
  end
785
726
  when :patch
786
727
  seg[4] &&= seg[4].succ
@@ -796,22 +737,24 @@ module Squared
796
737
  log.info "bump version #{cur} to #{val} (#{flag})"
797
738
  on :first, :bump
798
739
  end
799
- if stdin?
800
- puts val
801
- elsif verbose
740
+ if verbose
802
741
  major = flag == :major
803
742
  emphasize("version: #{val}", title: name, border: borderstyle, sub: [
804
743
  headerstyle,
805
744
  { pat: /\A(version:)( )(\S+)(.*)\z/, styles: color(major ? :green : :yellow), index: 3 },
806
745
  { pat: /\A(version:)(.*)\z/, styles: theme[major ? :major : :active] }
807
746
  ])
747
+ elsif stdin?
748
+ puts val
808
749
  end
809
750
  on :last, :bump unless dryrun?
810
751
  else
811
752
  raise_error('version not found', hint: dependfile)
812
753
  end
813
754
  rescue StandardError => e
814
- on_error e, :bump
755
+ log.debug e
756
+ ret = on(:error, :bump, e)
757
+ raise if exception && ret != true
815
758
  end
816
759
  end
817
760
 
@@ -821,7 +764,7 @@ module Squared
821
764
  cmd = session dependbin, 'pack'
822
765
  if dependtype(:yarn) > 1
823
766
  op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self)
824
- op.append?('out', Pathname.pwd + "#{project}-#{version}.tgz")
767
+ op << quote_option('out', Pathname.pwd + "#{project}-#{version}.tgz") unless op.arg?('out')
825
768
  else
826
769
  op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common], cmd,
827
770
  project: self)
@@ -831,12 +774,12 @@ module Squared
831
774
 
832
775
  case $1
833
776
  when 'w', 'workspace'
834
- 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))
835
778
  op.found << opt
836
779
  end
837
780
  end
838
781
  end
839
- op.append?('pack-destination', Dir.pwd)
782
+ op << quote_option('pack-destination', Dir.pwd) unless op.arg?('pack-destination')
840
783
  end
841
784
  op.clear
842
785
  run(from: :pack)
@@ -848,16 +791,16 @@ module Squared
848
791
  if script
849
792
  ret = session dependbin, 'run'
850
793
  raise_error("#{dependbin} run: given #{target}", hint: from) unless append_any(target, build: true)
851
- append_any opts if opts
794
+ append_any opts
852
795
  append_loglevel
853
- append_any(args, delim: true) if args
796
+ append_any(args, delim: true)
854
797
  ret
855
798
  else
856
799
  case target
857
800
  when String
858
801
  target
859
802
  when Hash
860
- append_hash(target, target: []).join(' ')
803
+ append_hash(target).join(' ')
861
804
  when Enumerable
862
805
  target.to_a.join(' ')
863
806
  else
@@ -949,26 +892,14 @@ module Squared
949
892
  respond_to?(meth) && __send__(meth) ? @pm[prog] : 0
950
893
  end
951
894
 
952
- def dependbin
953
- if yarn?
954
- 'yarn'
955
- else
956
- pnpm? ? 'pnpm' : 'npm'
957
- end
958
- end
959
-
960
895
  def version
961
- @version ||= read_packagemanager(:version)
896
+ super || (@version = read_packagemanager(:version))
962
897
  end
963
898
 
964
899
  def packagename
965
900
  read_packagemanager :name
966
901
  end
967
902
 
968
- def scripts
969
- @scripts ||= read_scripts.to_h
970
- end
971
-
972
903
  private
973
904
 
974
905
  def read_packagemanager(key = nil, version: nil, update: false)
@@ -986,11 +917,9 @@ module Squared
986
917
  @pm[:_] = false
987
918
  nil
988
919
  else
989
- if key
990
- @pm[key]
991
- elsif (ret = @pm[:_]) && (!version || semgte?(ret[(ret.index('@') + 1)..-1], version))
992
- ret
993
- end
920
+ return @pm[key] if key
921
+
922
+ !(ret = @pm[:_]) || (version && ret[ret.index('@') + 1..-1] < version) ? nil : ret
994
923
  end
995
924
 
996
925
  def read_install
@@ -1006,7 +935,7 @@ module Squared
1006
935
  end
1007
936
 
1008
937
  def append_loglevel(target: @session)
1009
- level = env('NODE_LOGLEVEL')
938
+ level = env 'NODE_LOGLEVEL'
1010
939
  silent = !verbose || level == 'silent'
1011
940
  return unless silent || level
1012
941
 
@@ -1037,11 +966,15 @@ module Squared
1037
966
  end
1038
967
  end
1039
968
 
1040
- def append_platform(target: @session)
1041
- %w[cpu os libc].each do |name|
1042
- next unless (val = option(name))
969
+ def dryrun?(prefix = dependbin, **)
970
+ super || !option('dry-run', prefix: prefix).nil?
971
+ end
1043
972
 
1044
- target << basic_option(name, val)
973
+ def dependbin
974
+ if yarn?
975
+ 'yarn'
976
+ else
977
+ pnpm? ? 'pnpm' : 'npm'
1045
978
  end
1046
979
  end
1047
980
 
@@ -1049,22 +982,14 @@ module Squared
1049
982
  'package.json' if parent&.has?('outdated', Node.ref)
1050
983
  end
1051
984
 
1052
- def npmname
1053
- packagename || project
1054
- end
1055
-
1056
985
  def npmnotice
1057
986
  [
1058
- { pat: /^(npm error )(code|\d+)(.+)$/, styles: color(:bright_cyan), index: 2 },
1059
- { pat: /^(npm )(error)(.*)$/, styles: color(:bright_red), index: 2 },
1060
- { 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 },
1061
990
  { pat: /^(npm )(.+)$/, styles: :bold }
1062
991
  ]
1063
992
  end
1064
-
1065
- def dryrun?(prefix = dependbin, **)
1066
- super || !option('dry-run', prefix: prefix).nil?
1067
- end
1068
993
  end
1069
994
 
1070
995
  Application.implement Node