squared 0.0.9 → 0.0.11

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.
@@ -1,61 +1,57 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'json'
4
-
5
3
  module Squared
6
4
  module Workspace
7
5
  module Project
8
6
  class Node < Git
7
+ include Common::Prompt
8
+
9
9
  class << self
10
10
  def populate(*); end
11
11
 
12
12
  def tasks
13
- nil
13
+ %i[outdated].freeze
14
+ end
15
+
16
+ def batchargs
17
+ [ref, { refresh: %i[build copy] }]
18
+ end
19
+
20
+ def aliasargs
21
+ [ref, { refresh: :build }]
14
22
  end
15
23
 
16
24
  def prod?
17
25
  ENV['NODE_ENV'] == 'production'
18
26
  end
19
27
 
20
- def is_a?(val)
21
- if (val = as_path(val))
22
- val.join('package.json').exist?
23
- else
24
- super
25
- end
28
+ def config?(val)
29
+ return false unless (val = as_path(val))
30
+
31
+ val.join('package.json').exist?
26
32
  end
27
33
  end
28
34
 
29
35
  @@tasks[ref] = {
30
- install: %i[force frozen dedupe],
31
- outdated: %i[major minor patch],
36
+ install: %i[force frozen dedupe].freeze,
37
+ outdated: %i[major minor patch].freeze,
38
+ bump: %i[major minor patch].freeze,
32
39
  run: nil
33
40
  }.freeze
34
41
 
35
42
  attr_reader :package
36
43
 
37
- def initialize(*, script: nil, **kwargs)
44
+ def initialize(*, **kwargs)
38
45
  super
39
- initialize_script(Node.ref, **kwargs)
40
- @dev = kwargs[:dev]
41
- @prod = kwargs[:prod]
46
+ if @pass.include?(Node.ref)
47
+ initialize_ref(Node.ref)
48
+ initialize_logger(**kwargs)
49
+ else
50
+ initialize_build(Node.ref, prod: prod?, **kwargs)
51
+ initialize_env(**kwargs)
52
+ end
42
53
  @pm = {}
43
54
  @package = base_path('package.json')
44
- return if @output[0] == false
45
-
46
- if @output[0].nil?
47
- val, ext = @workspace.script(Node.ref, @group)
48
- script_set val
49
- unless ext
50
- if script
51
- script_set script
52
- elsif (val = @script && @script[:run])
53
- @output[0] = val
54
- @output[1] = nil
55
- end
56
- end
57
- end
58
- @output[@output[0] || val.include?(' ') ? 0 : 1] = val if (val = env('BUILD', strict: true))
59
55
  end
60
56
 
61
57
  def ref
@@ -71,11 +67,55 @@ module Squared
71
67
  if flags.nil?
72
68
  case action
73
69
  when :run
74
- desc format_desc(action, nil, 'command+')
70
+ desc format_desc(action, nil, 'command+|^index|#,pattern*')
75
71
  task action, [:command] do |_, args|
76
- cmd = args.to_a
77
- guard_params(action, 'command', args: cmd)
78
- run_script cmd
72
+ if args.command == '#'
73
+ list = read_scripts
74
+ grep = args.extras.map { |val| Regexp.new(val) }
75
+ lines = []
76
+ if (pad = list.size) > 0
77
+ pad = pad.to_s.size
78
+ list.each_with_index do |val, i|
79
+ next unless grep.empty? || grep.any? { |pat| pat.match?(val[0]) }
80
+
81
+ lines << "#{(i + 1).to_s.rjust(pad)}. #{val[0]}"
82
+ end
83
+ end
84
+ if lines.empty?
85
+ lines = ['No scripts were found:', '']
86
+ unless args.extras.empty?
87
+ i = 0
88
+ lines += args.extras.to_a.map { |s| "#{i += 1}. #{s}" }
89
+ lines << ''
90
+ end
91
+ lines << package.to_s
92
+ pat = /^(#{Regexp.escape(lines.last)})(.*)$/
93
+ else
94
+ pat = /^(\s*\d+\.)(.+)$/
95
+ end
96
+ emphasize(lines, title: task_join(name, 'run[^N]'), border: borderstyle, sub: [
97
+ headerstyle,
98
+ { pat: pat, styles: theme[:active] }
99
+ ])
100
+ else
101
+ cmd = args.to_a
102
+ guard_params(action, 'command', args: cmd)
103
+ list = nil
104
+ cmd.each do |val|
105
+ if (data = /\A\^(\d+)\z/.match(val))
106
+ list ||= read_scripts
107
+ n = data[1].to_i
108
+ if (item = list[n - 1])
109
+ val = item.first
110
+ elsif exception
111
+ raise_error("requested index #{n}", hint: "total #{list.size}")
112
+ else
113
+ next log.warn "run script #{n} of #{list.size} (out of range)"
114
+ end
115
+ end
116
+ run compose(val, script: true)
117
+ end
118
+ end
79
119
  end
80
120
  end
81
121
  else
@@ -88,10 +128,15 @@ module Squared
88
128
  depend(flag)
89
129
  end
90
130
  when :outdated
91
- desc format_desc(action, flag, %w[prune interactive dry-run], arg: 'opts?')
131
+ desc format_desc(action, flag, %w[prune interactive dry-run].freeze, arg: 'opts?')
92
132
  task flag, [:opts] do |_, args|
93
133
  outdated(flag, opts: args.to_a)
94
134
  end
135
+ else
136
+ desc format_desc(action, flag)
137
+ task flag do
138
+ __send__(action, flag)
139
+ end
95
140
  end
96
141
  end
97
142
  end
@@ -100,20 +145,21 @@ module Squared
100
145
  end
101
146
  end
102
147
 
103
- def copy(from: 'build', glob: '**/*', subdir: 'node_modules', into: nil, also: [], override: false)
148
+ def copy(from: 'build', glob: '**/*', into: 'node_modules', scope: nil, also: nil, override: false)
104
149
  if @copy && !override
105
- return super if @copy.is_a?(::String)
150
+ return super if runnable?(@copy)
106
151
 
107
152
  from = @copy[:from] if @copy.key?(:from)
108
153
  glob = @copy[:glob] if @copy.key?(:glob)
109
- subdir = @copy[:subdir] if @copy.key?(:subdir)
110
154
  into = @copy[:into] if @copy.key?(:into)
155
+ scope = @copy[:scope] if @copy.key?(:scope)
111
156
  also = @copy[:also] if @copy.key?(:also)
112
157
  end
113
- items = [name == workspace.main ? nil : workspace.home].concat(as_a(also))
158
+ items = [path != workspace.home && workspace.home? ? workspace.home : nil]
159
+ items += as_a(also) if also
114
160
  items.each_with_index do |dir, i|
115
161
  if i == 0
116
- next unless dev? & !doc?
162
+ next unless dev? && build?
117
163
 
118
164
  dest = dir
119
165
  else
@@ -123,16 +169,19 @@ module Squared
123
169
  when ::Symbol
124
170
  dest = Workspace.resolve(dir)&.path
125
171
  when ::Hash
126
- into = nil
127
- glob = nil
172
+ glob = '**/*'
173
+ dest = nil
174
+ scope = nil
128
175
  dir.each do |key, val|
129
176
  case key.to_sym
177
+ when :target
178
+ dest = val
130
179
  when :from
131
180
  from = val
132
181
  when :glob
133
182
  glob = val
134
- when :subdir
135
- subdir = val
183
+ when :scope
184
+ scope = val
136
185
  when :into
137
186
  into = val
138
187
  end
@@ -140,18 +189,17 @@ module Squared
140
189
  when Project::Base
141
190
  dest = dir.path
142
191
  end
143
- next unless into
144
192
  end
145
193
  next unless dest&.directory?
146
194
 
147
195
  from = base_path(from)
148
- dest = dest.join(subdir, into || project)
149
- log.warn "cp #{from.join(glob)} #{dest}"
150
- copy_d(from, dest, glob: glob, verbose: verbose?)
196
+ dest = dest.join(into, scope || project)
197
+ (glob = as_a(glob)).each { |val| log.info "cp #{from.join(val)} #{dest}" }
198
+ copy_d(from, dest, glob: glob, verbose: verbose)
151
199
  end
152
200
  end
153
201
 
154
- def depend(flag = nil)
202
+ def depend(flag = nil, sync: invoked_sync?('depend', flag))
155
203
  if @depend && !flag
156
204
  super
157
205
  elsif outdated?
@@ -173,8 +221,8 @@ module Squared
173
221
  elsif flag == :frozen
174
222
  '--frozen-lockfile'
175
223
  end
176
- cmd << '--production' if prod?
177
- cmd << '--ignore-engines' unless env('YARN_IGNORE_ENGINES', equals: '0')
224
+ cmd << '--production' if flag && prod?
225
+ cmd << '--ignore-engines' unless option('ignore-engines', equals: '0')
178
226
  end
179
227
  elsif pnpm?
180
228
  cmd = session 'pnpm'
@@ -187,9 +235,12 @@ module Squared
187
235
  '--frozen-lockfile'
188
236
  end
189
237
  end
190
- cmd << '--prod' if prod?
238
+ cmd << '--prod' if flag && prod?
239
+ if (val = option('public-hoist-pattern', ignore: false))
240
+ split_escape(val).each { |opt| cmd << "--public-hoist-pattern=#{shell_escape(opt, quote: true)}" }
241
+ end
191
242
  cmd << '--ignore-workspace' if env('NODE_WORKSPACES', equals: '0')
192
- append_nocolor
243
+ append_nocolor option('no-color')
193
244
  else
194
245
  cmd = session 'npm'
195
246
  if flag == :dedupe
@@ -201,60 +252,73 @@ module Squared
201
252
  '--package-lock-only'
202
253
  end
203
254
  end
204
- cmd << '--omit=dev' if prod?
255
+ cmd << '--omit=dev' if flag && prod?
205
256
  cmd << '--workspaces=false' if env('NODE_WORKSPACES', equals: '0')
206
- cmd << '--package-lock=false' if env('NPM_PACKAGE_LOCK', equals: '0')
207
- append_nocolor
257
+ cmd << '--package-lock=false' if option('package-lock', equals: '0')
258
+ append_nocolor option('no-color')
208
259
  end
209
260
  append_loglevel
210
- run(sync: invoked_sync?('depend', flag))
261
+ run(sync: sync)
211
262
  end
212
263
  end
213
264
 
214
265
  def outdated(rev = nil, opts: [])
215
- equ = rev || (prod? ? :patch : :minor)
216
- cmd = pnpm? ? 'pnpm outdated' : 'npm outdated'
266
+ dryrun = opts.include?('dry-run')
267
+ if pnpm? && read_packagemanager(version: '7.15')
268
+ cmd = 'pnpm outdated'
269
+ dryrun ||= !option('dry-run', prefix: 'pnpm').nil?
270
+ else
271
+ cmd = 'npm outdated'
272
+ dryrun ||= !option('dry-run', prefix: 'npm').nil?
273
+ end
217
274
  log.info cmd
218
- if store_pwd || invoked_sync?("outdated#{rev && ":#{rev}"}")
219
- print_item format_banner("#{cmd}#{opts.include?('dry-run') ? ' --dry-run' : ''}", multiple: true)
275
+ banner = format_banner("#{cmd}#{dryrun ? ' --dry-run' : ''}", multiple: true)
276
+ if invoked_sync?('outdated', rev)
277
+ print_item banner
278
+ banner = nil
220
279
  end
221
- data = `#{cmd} --json --loglevel=error`
222
- store_pwd true
280
+ data = nil
281
+ pwd_set { data = `#{cmd} --json --loglevel=error` }
223
282
  json = JSON.parse(doc = package.read)
224
283
  dep1 = json['dependencies'] || {}
225
284
  dep2 = json['devDependencies'] || {}
226
285
  found = []
227
286
  avail = []
228
- if !data.empty?
287
+ rev ||= (prod? ? :patch : :minor)
288
+ inter = opts.include?('interactive')
289
+ unless data.empty?
229
290
  JSON.parse(data).each_pair do |key, val|
230
- val = val.find { |item| item['dependent'] == json['name'] } if val.is_a?(Array)
231
- next unless val && (file = dep1[key] || dep2[key])
291
+ val = val.find { |obj| obj['dependent'] == json['name'] } if val.is_a?(::Array)
292
+ next unless val && (file = dep1[key] || dep2[key]) && file != '*'
232
293
 
294
+ latest = val['latest']
233
295
  ch = file[0]
234
- unless ch =~ /[~^]/
235
- avail << [key, file, val['latest'], true]
296
+ if ch =~ /[~^]/
297
+ file = file[1..-1]
298
+ elsif inter && rev == :major
299
+ major = true
300
+ else
301
+ avail << [key, file, latest, true]
236
302
  next
237
303
  end
238
- file = file[1..-1]
239
- cur = val['current']
240
- want = if equ == :major && val['latest'] =~ SEM_VER
241
- [val['latest'], val['wanted']].max { |a, b| a <=> b }
242
- else
243
- val['wanted']
244
- end
245
- next unless (cur != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
246
-
247
- a, b = file.split('.')
248
- c, d, e = want.split('.')
249
- case equ
304
+ want = rev == :major && (ver = latest.match(SEM_VER)) && !ver[6] ? latest : val['wanted']
305
+ next unless (val['current'] != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
306
+
307
+ f = semver(semscan(file))
308
+ w = semver(semscan(want))
309
+ a = f[0]
310
+ b = f[2]
311
+ c = w[0]
312
+ d = w[2]
313
+ case rev
250
314
  when :major
251
315
  upgrade = a == '0' ? c == '0' : true
252
316
  when :minor
253
317
  upgrade = ch == '^' && (a == '0' ? c == '0' && b == d : a == c)
254
318
  when :patch
255
- upgrade = a == c && b == d && !e.nil?
319
+ upgrade = a == c && b == d && f[4] != w[4]
256
320
  end
257
- if upgrade
321
+ if upgrade && !w[5]
258
322
  next if file == want
259
323
 
260
324
  index = if a != c
@@ -264,9 +328,9 @@ module Squared
264
328
  else
265
329
  5
266
330
  end
267
- found << [key, file, want, index]
268
- else
269
- avail << [key, file, val['latest'], false]
331
+ found << [key, file, want, index, major, f, w]
332
+ elsif !major
333
+ avail << [key, file, latest, false]
270
334
  end
271
335
  end
272
336
  end
@@ -278,7 +342,7 @@ module Squared
278
342
  ord.size > 9 ? ret.rjust(ord.size.to_s.size) : ret
279
343
  end
280
344
  footer = lambda do |val = 0|
281
- next unless verbose?
345
+ next unless verbose
282
346
 
283
347
  msg, hint = if modified == -1
284
348
  ['Packages were updated', 'more possible']
@@ -287,25 +351,24 @@ module Squared
287
351
  end
288
352
  puts print_footer(empty_status(msg, hint, pending + val))
289
353
  end
354
+ print_item banner if banner
290
355
  if !found.empty?
291
356
  col1 = size_col.(found, 0) + 4
292
357
  col2 = size_col.(found, 1) + 4
293
- inter = opts.include?('interactive')
294
358
  found.each_with_index do |item, i|
295
- a, b, c, d = item
296
- prompt = inter && (equ != :major || semmajor(semver(b.scan(SEM_VER)[0]), semver(c.scan(SEM_VER)[0])))
297
- if prompt && !confirm_outdated(equ.upcase, a, c)
359
+ a, b, c, d, e = item
360
+ if inter && (rev != :major || e || semmajor(item[5], item[6])) && !confirm_outdated(a, c, d, e)
298
361
  cur = -1
299
362
  else
300
363
  cur = modified
301
- doc.sub!(/("#{Regexp.escape(a)}"\s*:\s*)"([~^])#{Regexp.escape(b)}"/) do |capture|
302
- if $2 == '~' && equ != :patch
364
+ doc.sub!(/("#{Regexp.escape(a)}"\s*:\s*)"([~^])#{e ? '?' : ''}#{Regexp.escape(b)}"/) do |capture|
365
+ if $2 == '~' && rev != :patch
303
366
  cur = -1
304
367
  pending += 1
305
368
  capture
306
369
  else
307
370
  modified += 1
308
- "#{$1}\"#{$2 || ''}#{c}\""
371
+ "#{$1}\"#{$2 || (d == 1 && e ? '^' : '')}#{c}\""
309
372
  end
310
373
  end
311
374
  end
@@ -316,14 +379,14 @@ module Squared
316
379
  'FAIL'
317
380
  elsif d == 1
318
381
  a = sub_style(a, styles: theme[:major])
319
- sub_style(c, :green, :bold)
382
+ sub_style(c, :bold, styles: color(:green))
320
383
  else
321
- sub_style(c, :green, pat: SEM_VER, index: d)
384
+ sub_style(c, pat: SEM_VER, styles: color(:green), index: d)
322
385
  end
323
386
  puts "#{pad_ord.(i, found)}. #{a}#{b.ljust(col2)}#{c}"
324
387
  end
325
388
  pending = avail.reduce(pending) { |a, b| a + (b[3] ? 0 : 1) }
326
- if opts.include?('dry-run') || (modified == 0 && pending > 0)
389
+ if dryrun || (modified == 0 && pending > 0)
327
390
  footer.(modified)
328
391
  elsif modified > 0
329
392
  File.write(package, doc)
@@ -339,11 +402,11 @@ module Squared
339
402
  avail.each_with_index do |item, i|
340
403
  a, b, c, d = item
341
404
  a = a.ljust(col1)
342
- b = sub_style(b.ljust(col2), d ? :red : :yellow)
405
+ b = sub_style(b.ljust(col2), styles: color(d ? :red : :yellow))
343
406
  c = c.ljust(col3)
344
407
  unless d
345
408
  a = sub_style(a, styles: theme[:active])
346
- c = sub_style(c, :green)
409
+ c = sub_style(c, styles: color(:green))
347
410
  pending += 1
348
411
  end
349
412
  puts "#{pad_ord.(i, avail)}. #{a + c + b} (#{d ? 'locked' : 'latest'})"
@@ -354,23 +417,75 @@ module Squared
354
417
  end
355
418
  end
356
419
 
357
- def compose(args)
358
- args ||= @output[1]
359
- cmd = [if yarn?
360
- 'yarn'
361
- else
362
- pnpm? ? 'pnpm' : 'npm'
363
- end]
364
- cmd << 'run'
365
- append_loglevel cmd
366
- if args.is_a?(::Array)
367
- cmd += args
368
- elsif args.is_a?(::String)
369
- cmd << args
420
+ def compose(opts, flags = nil, script: false)
421
+ return unless opts && script
422
+
423
+ ret = session (if yarn?
424
+ 'yarn'
425
+ else
426
+ pnpm? ? 'pnpm' : 'npm'
427
+ end), 'run', flags
428
+ append_loglevel
429
+ case opts
430
+ when ::Enumerable
431
+ ret += opts.to_a
432
+ when ::String
433
+ ret << opts
370
434
  else
371
- raise_error("#{cmd.first} script name", hint: args.nil? ? 'missing' : 'invalid')
435
+ raise_error("#{ret.first} script name", hint: opts.nil? ? 'missing' : 'invalid')
436
+ end
437
+ ret
438
+ end
439
+
440
+ def bump(flag)
441
+ return unless (ver = version)
442
+
443
+ seg = semscan(ver)
444
+ case flag
445
+ when :major
446
+ if seg[0] != '0' || seg[2].nil?
447
+ seg[0] = seg[0].succ
448
+ else
449
+ seg[2] = seg[2].succ
450
+ end
451
+ when :minor
452
+ if seg[0] == '0'
453
+ seg[4] &&= seg[4].succ
454
+ else
455
+ seg[2] = seg[2].succ
456
+ end
457
+ when :patch
458
+ seg[4] &&= seg[4].succ
459
+ end
460
+ unless (out = seg.join) == ver
461
+ begin
462
+ doc = package.read
463
+ if doc.sub!(/"version"\s*:\s*"#{ver}"/, "\"version\": \"#{out}\"")
464
+ package.write(doc)
465
+ log.info "bump version #{ver} to #{out} (#{flag})"
466
+ if verbose
467
+ major = flag == :major
468
+ emphasize("version: #{out}", title: name, border: borderstyle, sub: [
469
+ headerstyle,
470
+ { pat: /^(version:)( )(\S+)(.*)$/, styles: color(major ? :green : :yellow), index: 3 },
471
+ { pat: /^(version:)(.*)$/, styles: theme[major ? :major : :active] }
472
+ ])
473
+ elsif stdin?
474
+ puts out
475
+ end
476
+ else
477
+ raise_error('not found', hint: 'version')
478
+ end
479
+ rescue StandardError => e
480
+ log.debug e
481
+ raise
482
+ end
372
483
  end
373
- cmd.join(' ')
484
+ end
485
+
486
+ def version
487
+ read_packagemanager
488
+ @pm[:version]
374
489
  end
375
490
 
376
491
  def install_type(prog = nil)
@@ -380,12 +495,12 @@ module Squared
380
495
  @pm[prog] || 0
381
496
  end
382
497
 
383
- def build?
384
- @output[0] != false && (!@output[0].nil? || !@output[1].nil?)
498
+ def depend?
499
+ @depend != false && (!@depend.nil? || outdated?)
385
500
  end
386
501
 
387
502
  def copy?
388
- !!@copy
503
+ super || @copy.is_a?(::Hash)
389
504
  end
390
505
 
391
506
  def outdated?
@@ -393,8 +508,8 @@ module Squared
393
508
  end
394
509
 
395
510
  def yarn?
396
- (@pm[:yarn] ||= if File.exist?(base_path('yarn.lock'))
397
- if File.exist?(rc = base_path('.yarnrc.yml'))
511
+ (@pm[:yarn] ||= if base_path('yarn.lock', ascend: find_package).exist?
512
+ if (rc = base_path('.yarnrc.yml', ascend: find_package)).exist?
398
513
  begin
399
514
  require 'yaml'
400
515
  doc = YAML.load_file(rc)
@@ -405,7 +520,7 @@ module Squared
405
520
  else
406
521
  1
407
522
  end
408
- elsif (ver = read_packagemanager || env('NODE_INSTALL')) && ver.start_with?('yarn')
523
+ elsif (ver = read_packagemanager || read_install) && ver.start_with?('yarn')
409
524
  ver == 'yarn' || ver.include?('@1') ? 1 : 3
410
525
  else
411
526
  0
@@ -413,10 +528,11 @@ module Squared
413
528
  end
414
529
 
415
530
  def pnpm?
416
- (@pm[:pnpm] ||= if File.exist?(base_path('pnpm-lock.yaml'))
531
+ (@pm[:pnpm] ||= if base_path('pnpm-lock.yaml', ascend: find_package).exist?
417
532
  begin
418
533
  require 'yaml'
419
- doc = YAML.load_file(base_path('node_modules/.modules.yaml'))
534
+ doc = YAML.load_file(base_path('node_modules/.modules.yaml', ascend: find_package))
535
+ @pm[:_] = doc['packageManager']
420
536
  case doc['nodeLinker']
421
537
  when 'hoisted'
422
538
  1
@@ -429,86 +545,116 @@ module Squared
429
545
  4
430
546
  end
431
547
  else
432
- (read_packagemanager || env('NODE_INSTALL'))&.start_with?('pnpm') ? 4 : 0
548
+ (read_packagemanager || read_install)&.start_with?('pnpm') ? 4 : 0
433
549
  end) > 0
434
550
  end
435
551
 
552
+ def workspaces?
553
+ if pnpm?
554
+ base_path('pnpm-workspace.yaml').exist?
555
+ else
556
+ read_packagemanager
557
+ @pm[:workspaces].is_a?(::Array)
558
+ end
559
+ end
560
+
436
561
  def dev?
437
- !Node.prod? && workspace.dev?(pat: @dev, **runargs)
562
+ !Node.prod? && super
438
563
  end
439
564
 
440
565
  def prod?
441
- Node.prod? || workspace.prod?(pat: @prod, **runargs)
566
+ @prod != false && (Node.prod? || super)
442
567
  end
443
568
 
444
569
  private
445
570
 
446
- def run_script(cmd)
447
- cmd.each { |val| run_s compose(val) }
571
+ def read_packagemanager(version: nil)
572
+ if @pm[:_].nil?
573
+ doc = JSON.parse(package.read)
574
+ @pm[:_] = (val = doc['packageManager']) ? val[0..(val.index('+') || 0) - 1] : false
575
+ @pm[:scripts] = doc['scripts']
576
+ @pm[:version] = doc['version']
577
+ @pm[:workspaces] = doc['workspaces']
578
+ end
579
+ rescue StandardError => e
580
+ log.debug e if package.exist?
581
+ @pm[:_] = false
582
+ nil
583
+ else
584
+ return if !@pm[:_] || (version && @pm[:_][@pm[:_].index('@') + 1..-1] < version)
585
+
586
+ @pm[:_]
587
+ end
588
+
589
+ def read_install
590
+ return unless (ret = env('NODE_INSTALL'))
591
+
592
+ @pm[:_] ||= ret if ret.include?('@')
593
+ ret
448
594
  end
449
595
 
450
- def append_loglevel(cmd = @session)
451
- return unless (level = env('NODE_LOGLEVEL'))
596
+ def read_scripts
597
+ read_packagemanager
598
+ @pm[:scripts].is_a?(Hash) ? @pm[:scripts].to_a : []
599
+ end
600
+
601
+ def append_loglevel
602
+ level = env('NODE_LOGLEVEL')
603
+ silent = !verbose || level == 'silent'
604
+ return unless silent || level
452
605
 
453
- silent = !workspace.verbose || level == 'silent'
454
606
  if yarn?
455
607
  if install_type(:yarn) == 1
456
608
  if silent
457
- cmd << '--silent'
609
+ @session << '--silent'
458
610
  elsif level == 'verbose'
459
- cmd << '--verbose'
611
+ @session << '--verbose'
460
612
  end
461
613
  end
462
614
  elsif pnpm?
463
615
  if silent
464
- cmd << '--reporter=silent'
616
+ @session << '--reporter=silent'
465
617
  level ||= 'error'
466
618
  end
467
619
  case level
468
620
  when 'debug', 'info', 'warn', 'error'
469
- cmd << "--loglevel=#{level}"
621
+ @session << "--loglevel=#{level}"
470
622
  end
471
623
  elsif silent
472
- cmd << '--loglevel=silent'
624
+ @session << '--loglevel=silent'
473
625
  else
474
626
  case level
475
627
  when 'error', 'warn', 'notice', 'http', 'info', 'verbose', 'silly'
476
- cmd << "--loglevel=#{level}"
628
+ @session << "--loglevel=#{level}"
477
629
  end
478
630
  end
479
631
  end
480
632
 
481
- def confirm_outdated(rev, pkg, ver)
482
- m = ver == :major
483
- confirm("Upgrade to #{rev}? #{sub_style("#{pkg} #{ver}", styles: theme[:inline])} [#{m ? 'y/N' : 'Y/n'}] ",
484
- default: m ? 'N' : 'Y', timeout: 60)
485
- end
486
-
487
- def read_packagemanager
488
- if @pm[:_].nil?
489
- doc = JSON.parse(package.read)
490
- @pm[:_] = (val = doc['packageManager']) ? val[0..(val.index('+') || 0) - 1] : false
491
- end
492
- rescue StandardError => e
493
- log.warn e if package.exist?
494
- @pm[:_] = false
495
- nil
496
- else
497
- @pm[:_] || nil
633
+ def confirm_outdated(pkg, ver, rev, lock)
634
+ a = sub_style(case rev
635
+ when 1
636
+ 'MAJOR'
637
+ when 3
638
+ 'MINOR'
639
+ else
640
+ 'PATCH'
641
+ end, styles: theme[:header])
642
+ b = sub_style("#{pkg} #{ver}", styles: theme[:inline])
643
+ c, d = rev == 1 || lock ? ['y/N', 'N'] : ['Y/n', 'Y']
644
+ e = lock ? " #{sub_style('(locked)', styles: color(:red))}" : ''
645
+ confirm("Upgrade to #{a}? #{b}#{e} [#{c}] ", d, timeout: 60)
498
646
  end
499
647
 
500
- def script_set(val)
501
- @output[1] = if val.is_a?(::Array)
502
- val[Node.prod? ? 1 : 0]
503
- else
504
- val
505
- end
648
+ def find_package
649
+ 'package.json' if parent&.has?('outdated', Node.ref)
506
650
  end
507
651
 
508
- def runargs
509
- { script: @output[1], ref: Node.ref, group: group, global: @output[0].nil? && !(@script && @script[:run]) }
652
+ def headerstyle
653
+ { pat: /^(\S+)(\s+)$/, styles: theme[:header] }
510
654
  end
511
655
  end
656
+
657
+ Application.implement Node
512
658
  end
513
659
  end
514
660
  end