squared 0.4.11 → 0.4.12

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.
@@ -11,10 +11,12 @@ module Squared
11
11
  install_no: %w[audit bin-links fund package-lock].freeze,
12
12
  install_as: %w[foreground-scripts g|global no-save save save-bundle save-dev E|save-exact save-optional
13
13
  save-peer S|save-prod].freeze,
14
+ run: %w[foreground-scripts if-present ignore-scripts script-shell=p].freeze,
14
15
  pack: %w[json ignore-scripts pack-destination=p].freeze
15
16
  }.freeze
16
17
  OPT_PNPM = {
17
18
  common: %w[aggregate-output color no-color stream use-stderr C|dir=p loglevel=b w|workspace-root].freeze,
19
+ filter: %w[fail-if-no-match changed-files-ignore-pattern=q filter=q filter-prod=q test-pattern=q].freeze,
18
20
  install: %w[fix-lockfile force ignore-pnpmfile ignore-workspace lockfile-only merge-git-branch-lockfiles
19
21
  no-hoist no-lockfile no-optional prefer-frozen-lockfile resolution-only shamefully-hoist
20
22
  side-effects-cache side-effects-cache-readonly s|silent strict-peer-dependencies
@@ -23,28 +25,31 @@ module Squared
23
25
  reporter=b].freeze,
24
26
  install_base: %w[global-dir ignore-scripts offline prefer-offline store-dir=p virtual-store-dir=p].freeze,
25
27
  install_no: %w[frozen-lockfile verify-store-integrity].freeze,
26
- install_as: %w[D|dev fail-if-no-match global-dir no-optional P|prod r|recursive
27
- changed-files-ignore-pattern=q filter=q filter-prod=q test-pattern=q].freeze,
28
+ install_as: %w[D|dev global-dir no-optional P|prod r|recursive].freeze,
28
29
  update: %w[global interactive latest depth=i].freeze,
29
30
  dedupe: %w[check].freeze,
31
+ run: %w[if-present no-bail parallel r|recursive report-summary reporter-hide-prefix resume-from sequential
32
+ stream use-stderr].freeze,
30
33
  pack: %w[json pack-destination=p pack-gzip-level=i].freeze
31
34
  }.freeze
32
35
  OPT_YARN = {
33
- common: %w[no-default-rc s|silent verbose cwd=p use-yarnrc=p].freeze,
36
+ common: %w[check-files disable-pnp enable-pnp flat focus force frozen-lockfile json har ignore-engines
37
+ ignore-optional ignore-platform ignore-scripts link-duplicates no-bin-links no-default-rc
38
+ no-lockfile no-node-version-check no-progress non-interactive offline pnp prefer-offline prod
39
+ pure-lockfile s|silent skip-integrity-check strict-semver verbose cache-folder=p cwd=p emoji=b?
40
+ global-folder=p https-proxy=q link-folder=p modules-folder=p mutex=q network-concurrency=i
41
+ network-timeout=i preferred-cache-folder=p production=b? proxy=q otp=b registry=q update-checksums
42
+ use-yarnrc=p].freeze,
34
43
  install: %w[A|audit g|global S|save D|save-dev E|save-exact P|save-peer O|save-optional T|save-tilde].freeze,
35
- install_base: %w[check-files disable-pnp enable-pnp flat focus force frozen-lockfile har ignore-platform
36
- ignore-engines ignore-optional ignore-scripts json link-duplicates no-bin-links no-lockfile
37
- no-node-version-check no-progress non-interactive offline pnp prefer-offline prod
38
- pure-lockfile skip-integrity-check strict-semver update-checksums cache-folder=p emoji=b?
39
- global-folder=p https-proxy=q link-folder=p modules-folder=p mutex=q network-concurrency=i
40
- network-timeout=i preferred-cache-folder=p production=b? proxy=q otp=b registry=q].freeze,
41
- update: %w[A|audit C|caret E|exact L|latest T|tilde P|pattern=q S|scope=b].freeze
44
+ update: %w[A|audit C|caret E|exact L|latest T|tilde P|pattern=q S|scope=b].freeze,
45
+ run: %w[scripts-prepend-node-path=b?].freeze
42
46
  }.freeze
43
47
  OPT_BERRY = {
44
48
  install: %w[check-cache check-resolutions immutable immutable-cache inline-builds json refresh-lockfile
45
49
  mode=b].freeze,
46
50
  update: %w[C|caret E|exact F|fixed interactive T|tilde R|recursive mode=b].freeze,
47
51
  dedupe: %w[check json mode=b strategy=b].freeze,
52
+ run: %w[B|binaries-only inspect inspect-brk T|top-level require=q].freeze,
48
53
  pack: %w[n|dry-run install-if-needed json o|out=p].freeze
49
54
  }.freeze
50
55
  private_constant :OPT_NPM, :OPT_PNPM, :OPT_YARN, :OPT_BERRY
@@ -137,24 +142,40 @@ module Squared
137
142
  when 'run'
138
143
  next if (list = read_scripts).empty?
139
144
 
140
- format_desc action, nil, 'command+|^index|#,pattern*'
141
- task action, [:command] do |_, args|
142
- if args.command == '#'
145
+ format_desc action, nil, 'script,opts*|^index+|#,pattern*'
146
+ task action, [:script] do |_, args|
147
+ if args.script == '#'
143
148
  format_list(list, 'run[^N]', 'scripts', grep: args.extras, from: dependfile.to_s)
144
149
  else
145
- cmd = param_guard(action, 'command', args: args.to_a)
146
- cmd.each do |val|
147
- if (n, opts = indexitem(val))
150
+ args = param_guard(action, 'script', args: args.to_a)
151
+ opts = []
152
+ args.each do |val|
153
+ if (n, extra = indexitem(val))
148
154
  if (item = list[n - 1])
149
- val = opts ? "#{item.first} #{opts}" : item.first
155
+ val = extra ? "#{item.first} #{extra}" : item.first
150
156
  elsif exception
151
157
  indexerror n, list
152
158
  else
153
159
  next log.warn "run script #{n} of #{list.size} (out of range)"
154
160
  end
161
+ run compose(val, script: true)
162
+ else
163
+ opts << val
155
164
  end
156
- run compose(val, script: true)
157
165
  end
166
+ next if opts.empty?
167
+
168
+ list = if (yarn = dependtype(:yarn)) > 0
169
+ yarn == 1 ? OPT_YARN[:run] + OPT_YARN[:common] : OPT_BERRY[:run]
170
+ elsif pnpm?
171
+ OPT_PNPM[:run] + OPT_PNPM[:filter] + OPT_PNPM[:common]
172
+ else
173
+ OPT_NPM[:run] + OPT_NPM[:common]
174
+ end
175
+ op = OptionPartition.new(opts, list, session(dependbin, 'run'), project: self)
176
+ op << op.extras.shift
177
+ op.append(delim: true, quote: false)
178
+ run(from: :run)
158
179
  end
159
180
  end
160
181
  when 'pack'
@@ -372,7 +393,7 @@ module Squared
372
393
  end
373
394
 
374
395
  def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated', flag))
375
- dryrun = opts.include?('dry-run')
396
+ dryrun = opts.include?('dry-run') || opts.include?('d')
376
397
  if pnpm? && read_packagemanager(version: '7.15', update: true)
377
398
  cmd = session 'pnpm', 'outdated'
378
399
  dryrun ||= dryrun?('pnpm')
@@ -406,7 +427,7 @@ module Squared
406
427
  found = []
407
428
  avail = []
408
429
  rev = flag || (prod? ? :patch : :minor)
409
- inter = opts.include?('interactive')
430
+ inter = opts.include?('interactive') || opts.include?('i')
410
431
  unless data.empty?
411
432
  JSON.parse(data).each_pair do |key, val|
412
433
  val = val.find { |obj| obj['dependent'] == target } if val.is_a?(Array)
@@ -446,7 +467,7 @@ module Squared
446
467
  found << [key, file, want, if a != c
447
468
  1
448
469
  elsif b != d
449
- 3
470
+ a == '0' ? 1 : 3
450
471
  else
451
472
  5
452
473
  end, major, f, w]
@@ -479,8 +500,8 @@ module Squared
479
500
  col2 = size_col.call(found, 1) + 4
480
501
  found.each_with_index do |item, i|
481
502
  a, b, c, d, e = item
482
- inter &&= rev != :major || e || semmajor?(item[5], item[6])
483
- if inter && !confirm_outdated(a, c, (d / 2.0).ceil, lock: e)
503
+ f = inter && (rev != :major || e || semmajor?(item[5], item[6]))
504
+ if f && !confirm_outdated(a, c, (d / 2.0).ceil, lock: e)
484
505
  cur = -1
485
506
  else
486
507
  cur = modified
@@ -518,7 +539,7 @@ module Squared
518
539
  footer.call(0, found.size)
519
540
  File.write(dependfile, doc)
520
541
  commit(:add, refs: ['package.json'], pass: true)
521
- install if opts.include?('prune')
542
+ install if opts.include?('prune') || opts.include?('p')
522
543
  end
523
544
  elsif !avail.empty?
524
545
  col1 = size_col.call(avail, 0) + 4
@@ -596,47 +617,47 @@ module Squared
596
617
  flag
597
618
  end
598
619
  op = OptionPartition.new(opts, if yarn == 1
599
- OPT_PNPM[:install_base] + OPT_YARN.fetch(flag, []) + OPT_YARN[:common]
620
+ OPT_YARN.fetch(flag, []) + OPT_YARN[:common]
600
621
  else
601
622
  OPT_BERRY[flag]
602
623
  end, cmd, project: self)
603
624
  op.clear
604
625
  append_loglevel
605
- run(from: :"package:#{flag}")
606
- return
607
- elsif pnpm?
608
- cmd = session 'pnpm', flag
609
- list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common]
610
- list.concat(OPT_PNPM[:install_as]) unless flag == :dedupe
611
- no = OPT_PNPM[:"#{flag}_no"]
612
626
  else
613
- cmd = session 'npm', flag
614
- list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
615
- list.concat(OPT_NPM[:install_as]) unless flag == :dedupe
616
- no = OPT_NPM[:install_no]
617
- end
618
- op = OptionPartition.new(opts, list, cmd, no: no, project: self)
619
- op.each do |opt|
620
- if opt =~ op.values
621
- case $1
622
- when 'w', 'workspace'
623
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
627
+ if pnpm?
628
+ cmd = session 'pnpm', flag
629
+ list = OPT_PNPM[:install_base] + OPT_PNPM.fetch(flag, []) + OPT_PNPM[:common]
630
+ list.concat(OPT_PNPM[:install_as] + OPT_PNPM[:filter]) unless flag == :dedupe
631
+ no = OPT_PNPM[:"#{flag}_no"]
632
+ else
633
+ cmd = session 'npm', flag
634
+ list = OPT_NPM[:install_base] + OPT_NPM.fetch(flag, []) + OPT_NPM[:common]
635
+ list.concat(OPT_NPM[:install_as]) unless flag == :dedupe
636
+ no = OPT_NPM[:install_no]
637
+ end
638
+ op = OptionPartition.new(opts, list, cmd, no: no, project: self)
639
+ op.each do |opt|
640
+ if opt =~ op.values
641
+ case $1
642
+ when 'w', 'workspace'
643
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
644
+ end
645
+ elsif opt.include?('=')
646
+ op.errors << opt
647
+ else
648
+ op.found << opt
624
649
  end
625
- elsif opt.include?('=')
626
- op.errors << opt
650
+ end
651
+ op.swap
652
+ append_nocolor
653
+ append_loglevel
654
+ if flag == :dedupe
655
+ op.clear
627
656
  else
628
- op.found << opt
657
+ op.append(escape: true)
629
658
  end
659
+ op.clear(errors: true)
630
660
  end
631
- op.swap
632
- append_nocolor
633
- append_loglevel
634
- if flag == :dedupe
635
- op.clear
636
- else
637
- op.append(escape: true)
638
- end
639
- op.clear(errors: true)
640
661
  run(from: :"package:#{flag}")
641
662
  end
642
663
 
@@ -120,20 +120,14 @@ module Squared
120
120
  format_desc action, flag, 'dir,opts*'
121
121
  task flag, [:dir] do |_, args|
122
122
  dir = path + param_guard(action, flag, args: args, key: :dir)
123
- cmd, opts = python_session('-m venv', opts: args.extras)
124
- op = OptionPartition.new(opts, OPT_PYTHON[:venv], cmd, project: self)
125
- op.append(dir, delim: true)
126
- .clear(pass: false)
127
- v = op.arg?(/\A-v+\z/, 'verbose')
128
- run(exception: true)
129
- puts(dir.directory? ? "Success: #{dir}" : 'Failed') unless v
123
+ venv_create dir, args.extras
130
124
  end
131
125
  elsif venv
132
126
  case flag
133
127
  when :remove
134
128
  next unless projectpath?(venv)
135
129
 
136
- format_desc action, flag, 'c|reate?,d|epend?'
130
+ format_desc action, flag, 'c|create?,d|depend?'
137
131
  task flag do |_, args|
138
132
  rm_rf(venv, verbose: true)
139
133
  venv_init if has_value?(%w[c create], args.to_a)
@@ -598,6 +592,10 @@ module Squared
598
592
  end
599
593
 
600
594
  def venv_set(val)
595
+ if val.is_a?(Array)
596
+ val, *opts = val
597
+ @venvopts = opts
598
+ end
601
599
  @venv = Pathname.new(val)
602
600
  @venv = @path + @venv unless @venv.absolute?
603
601
  if projectpath?(@venv)
@@ -617,11 +615,21 @@ module Squared
617
615
  return if !venv || (venvbin.directory? && !venvbin.empty?)
618
616
 
619
617
  puts log_message(Logger::INFO, venv, subject: 'venv', hint: 'init')
620
- cmd = session 'python', '-m venv', shell_option('prompt', name), '--upgrade-deps', shell_quote(venv)
621
- run(cmd, false, exception: true, banner: false)
618
+ @venvopts &&= @venvopts.map { |val| OptionPartition.strip(val) }.flatten
619
+ venv_create(venv, @venvopts || ["prompt=#{name}", 'upgrade-deps'], env: false, banner: false)
622
620
  puts log_message(Logger::INFO, venv, subject: 'venv', hint: 'created')
623
621
  end
624
622
 
623
+ def venv_create(dir, opts = [], env: nil, banner: true)
624
+ cmd, opts = python_session('-m venv', opts: opts)
625
+ op = OptionPartition.new(opts, OPT_PYTHON[:venv], cmd, project: self)
626
+ op.append(dir, delim: true)
627
+ .clear(pass: false)
628
+ status = op.arg?(/\A-v+\z/, 'verbose')
629
+ run(op, env, exception: true, banner: banner)
630
+ puts(dir.directory? ? "Success: #{dir}" : 'Failed') if banner && !status
631
+ end
632
+
625
633
  def requirements?
626
634
  dependtype == 5
627
635
  end
@@ -374,8 +374,7 @@ module Squared
374
374
  found += 1
375
375
  end
376
376
  if theme[:current]
377
- line = sub_style(line, styles: theme[:current], pat: /^(.+)(#{Regexp.escape(c)})(.+)$/,
378
- index: 2)
377
+ line = sub_style(line, styles: theme[:current], pat: /^(.+)(#{Regexp.escape(c)})(.+)$/, index: 2)
379
378
  end
380
379
  line = sub_style(line, *colormap(styles), pat: /^((?:\S+\s+){2})(#{Regexp.escape(l)})(.*)$/,
381
380
  index: 2)
@@ -757,7 +756,9 @@ module Squared
757
756
 
758
757
  def irb(name, opts = [], path: @path + 'lib', load: nil)
759
758
  op = OptionPartition.new(opts, OPT_RUBY[:irb], session('irb'), project: self, first: [/\.rb$/])
760
- as_a(name).each { |val| op << shell_option('r', val, merge: true) }
759
+ r = as_a name
760
+ r.unshift('bundler/setup') unless load
761
+ r.each { |val| op << shell_option('r', val, merge: true) }
761
762
  as_a(path).each { |val| op << quote_option('I', val, merge: true) }
762
763
  if load
763
764
  op << '--' << load
@@ -44,7 +44,7 @@ module Squared
44
44
  return [] unless val
45
45
 
46
46
  val = shell_split(val) if val.is_a?(String)
47
- val.map { |s| s.sub(/\A-([a-z\d])(.+)\z/mi, '\1=\2').sub(/\A--?/, '') }.reject(&:empty?)
47
+ val.map { |s| s.sub(/\A-([a-z\d])(.+)\z/i, '\1=\2').sub(/\A--?/, '') }.reject(&:empty?)
48
48
  end
49
49
 
50
50
  def arg?(target, *args, value: false)
@@ -60,9 +60,9 @@ module Squared
60
60
  attr_reader :target, :extras, :found, :errors, :values, :project, :path
61
61
 
62
62
  def_delegators :@target, :+, :-, :<<, :any?, :none?, :include?, :add, :add?, :find, :find_all, :find_index,
63
- :merge, :delete, :delete?, :grep, :inspect, :to_a, :to_s
64
- def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :first, :last, :shift, :pop, :push,
65
- :join, :map, :map!, :dup, :size
63
+ :merge, :delete, :delete?, :delete_if, :grep, :inspect, :to_a, :to_s
64
+ def_delegators :@extras, :empty?, :each, :each_with_index, :partition, :dup, :first, :last, :shift, :unshift,
65
+ :pop, :push, :join, :map, :map!, :select, :reject, :size
66
66
 
67
67
  def initialize(opts, list, target = Set.new, project: nil, path: nil, **kwargs, &blk)
68
68
  @target = target.is_a?(Set) ? target : Set.new(target)
@@ -7,13 +7,8 @@ module Squared
7
7
  attr_accessor :line_width
8
8
 
9
9
  def max_width(lines)
10
- win = 0
11
- if $stdout.tty?
12
- require 'io/console'
13
- win = $stdout.winsize[1] rescue nil
14
- end
15
- n = [lines.max_by(&:size).size, line_width].max
16
- [n, win > 0 ? win : ::Float::INFINITY].min
10
+ n = [lines.max_by(&:size).size, 80].max
11
+ [n, Rake.application.terminal_width].min
17
12
  end
18
13
  end
19
14
 
@@ -76,6 +76,7 @@ module Squared
76
76
  @sync = []
77
77
  @multiple = []
78
78
  @parallel = []
79
+ @chain = {}
79
80
  @exclude = exclude.freeze
80
81
  @session = {
81
82
  group: {},
@@ -139,6 +140,26 @@ module Squared
139
140
  @multiple.concat(sync)
140
141
  end
141
142
 
143
+ def chain(key, level, sync: [])
144
+ return if level.empty?
145
+
146
+ index = 0
147
+ prereqs = level.map do |tasks|
148
+ task_join(key, index += 1).tap do |subkey|
149
+ if sync.include?(tasks) || (tasks.size == 1 && (sync << tasks))
150
+ task subkey => tasks
151
+ else
152
+ multitask subkey => tasks
153
+ end
154
+ end
155
+ end
156
+ @chain[key] = level.freeze
157
+ parallel << key
158
+
159
+ format_desc key, level.map(&:size).join('-')
160
+ task key => prereqs
161
+ end
162
+
142
163
  def name_get(key)
143
164
  (TASK_NAME[key] || key).to_s
144
165
  end
@@ -187,6 +208,19 @@ module Squared
187
208
  data.keys.any? { |ref| obj.ref?(ref) }
188
209
  end
189
210
 
211
+ def chain?(val)
212
+ @chain.each_value do |tasks|
213
+ tasks.flatten(1).each do |task|
214
+ next unless Rake::Task[task].already_invoked
215
+
216
+ if val == task || Rake::Task[task].prerequisites.any? { |pr| pr == val && Rake::Task[val].already_invoked }
217
+ return true
218
+ end
219
+ end
220
+ end
221
+ false
222
+ end
223
+
190
224
  def multiple?(val = nil)
191
225
  already_invoked?(multiple, val)
192
226
  end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Squared
4
+ module Workspace
5
+ module Support
6
+ RunData = Struct.new(:run, :block)
7
+ ChainData = Struct.new(:action, :step, :with, :before, :after, :sync)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'support/data'
@@ -36,6 +36,7 @@ module Squared
36
36
  end
37
37
  end
38
38
 
39
+ require_relative 'workspace/support'
39
40
  require_relative 'workspace/application'
40
41
  require_relative 'workspace/series'
41
42
  require_relative 'workspace/project'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.11
4
+ version: 0.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -101,6 +101,8 @@ files:
101
101
  - lib/squared/workspace/project/support/class.rb
102
102
  - lib/squared/workspace/repo.rb
103
103
  - lib/squared/workspace/series.rb
104
+ - lib/squared/workspace/support.rb
105
+ - lib/squared/workspace/support/data.rb
104
106
  - squared.gemspec
105
107
  homepage: https://github.com/anpham6/squared
106
108
  licenses: