squared 0.4.15 → 0.4.17
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -0
- data/README.md +10 -5
- data/README.ruby.md +21 -15
- data/lib/squared/common/prompt.rb +3 -3
- data/lib/squared/common/shell.rb +1 -2
- data/lib/squared/common/system.rb +17 -16
- data/lib/squared/common/utils.rb +9 -0
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +24 -15
- data/lib/squared/workspace/project/base.rb +193 -130
- data/lib/squared/workspace/project/docker.rb +84 -70
- data/lib/squared/workspace/project/git.rb +233 -138
- data/lib/squared/workspace/project/node.rb +87 -30
- data/lib/squared/workspace/project/python.rb +48 -19
- data/lib/squared/workspace/project/ruby.rb +98 -57
- data/lib/squared/workspace/project/support/class.rb +66 -17
- data/lib/squared/workspace/repo.rb +46 -42
- data/lib/squared/workspace/series.rb +4 -4
- data/lib/squared/workspace/support/base.rb +17 -0
- data/lib/squared/workspace/support.rb +1 -0
- data/lib/squared/workspace.rb +0 -8
- data/squared.gemspec +2 -2
- metadata +3 -2
@@ -97,7 +97,7 @@ module Squared
|
|
97
97
|
'pack' => nil
|
98
98
|
})
|
99
99
|
|
100
|
-
def initialize(*, **kwargs)
|
100
|
+
def initialize(*, init: nil, **kwargs)
|
101
101
|
super
|
102
102
|
if @pass.include?(Node.ref)
|
103
103
|
initialize_ref Node.ref
|
@@ -107,7 +107,7 @@ module Squared
|
|
107
107
|
initialize_env(**kwargs)
|
108
108
|
end
|
109
109
|
@dependfile = @path + 'package.json'
|
110
|
-
@pm = {}
|
110
|
+
@pm = { __: init }
|
111
111
|
end
|
112
112
|
|
113
113
|
def ref
|
@@ -116,11 +116,11 @@ module Squared
|
|
116
116
|
|
117
117
|
def populate(*, **)
|
118
118
|
super
|
119
|
-
return unless outdated? && ref?(Node.ref)
|
119
|
+
return unless (outdated? && ref?(Node.ref)) || @only
|
120
120
|
|
121
121
|
namespace name do
|
122
122
|
Node.subtasks do |action, flags|
|
123
|
-
next if
|
123
|
+
next if task_pass?(action)
|
124
124
|
|
125
125
|
if flags.nil?
|
126
126
|
case action
|
@@ -257,6 +257,11 @@ module Squared
|
|
257
257
|
otp = args.first
|
258
258
|
else
|
259
259
|
tag, otp = param_guard(action, flag, args: args)
|
260
|
+
unless SEM_VER.match?(tag)
|
261
|
+
a = sub_style(project, styles: theme[:active])
|
262
|
+
b = sub_style(tag, styles: theme[:inline])
|
263
|
+
exit 1 unless confirm("Publish #{a}@#{b}? [y/N] ", 'N')
|
264
|
+
end
|
260
265
|
end
|
261
266
|
publish(flag, otp: otp, tag: tag, dryrun: dryrun, access: access)
|
262
267
|
end
|
@@ -268,7 +273,7 @@ module Squared
|
|
268
273
|
end
|
269
274
|
end
|
270
275
|
|
271
|
-
def copy(from: 'build', into: 'node_modules', scope: nil, also: nil, create: nil, workspace: false,
|
276
|
+
def copy(from: 'build', into: 'node_modules', scope: nil, also: nil, create: nil, files: nil, workspace: false,
|
272
277
|
link: false, force: false, override: false, sync: invoked_sync?('copy'), **kwargs)
|
273
278
|
glob = kwargs[:include]
|
274
279
|
pass = kwargs[:exclude]
|
@@ -277,6 +282,7 @@ module Squared
|
|
277
282
|
|
278
283
|
from = @copy[:from] if @copy.key?(:from)
|
279
284
|
into = @copy[:into] if @copy.key?(:into)
|
285
|
+
files = @copy[:files] if @copy.key?(:files)
|
280
286
|
workspace = @copy[:workspace] if @copy.key?(:workspace)
|
281
287
|
link = @copy[:link] if @copy.key?(:link)
|
282
288
|
force = @copy[:force] if @copy.key?(:force)
|
@@ -298,6 +304,7 @@ module Squared
|
|
298
304
|
|
299
305
|
on :first, :copy
|
300
306
|
print_item unless @output[0] || !verbose || task_invoked?(/^copy(?::#{Node.ref}|$)/)
|
307
|
+
packed = false
|
301
308
|
items.each do |dir|
|
302
309
|
case dir
|
303
310
|
when Pathname
|
@@ -335,9 +342,49 @@ module Squared
|
|
335
342
|
end
|
336
343
|
next unless from && dest&.directory?
|
337
344
|
|
338
|
-
from
|
345
|
+
if from == :npm
|
346
|
+
begin
|
347
|
+
unless packed
|
348
|
+
require 'open3'
|
349
|
+
files = pwd_set do
|
350
|
+
Open3.capture2e(session_output('npm', 'pack --dry-run --no-color', npmname).to_s)
|
351
|
+
.first
|
352
|
+
.scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
|
353
|
+
.map { |item| Pathname.new(item.first) }
|
354
|
+
.select(&:exist?)
|
355
|
+
end
|
356
|
+
.concat(Array(files))
|
357
|
+
packed = true
|
358
|
+
end
|
359
|
+
to = dest.join(into, npmname)
|
360
|
+
to.mkpath
|
361
|
+
log.info "cp npm:#{npmname} #{to}"
|
362
|
+
subdir = []
|
363
|
+
errors = 0
|
364
|
+
files.each do |file|
|
365
|
+
s, d = file.is_a?(Array) ? file : [file, file]
|
366
|
+
dest = to + d
|
367
|
+
unless subdir.include?((target = dest.dirname).to_s)
|
368
|
+
target.mkpath
|
369
|
+
subdir << target.to_s
|
370
|
+
end
|
371
|
+
begin
|
372
|
+
FileUtils.cp(path + s, dest, verbose: verbose.is_a?(Numeric) && verbose > 0)
|
373
|
+
rescue StandardError => e
|
374
|
+
print_error e
|
375
|
+
errors += 1
|
376
|
+
end
|
377
|
+
end
|
378
|
+
rescue StandardError => e
|
379
|
+
on_error e, :copy
|
380
|
+
else
|
381
|
+
puts message(to, subdir.size, files.size - errors) if verbose
|
382
|
+
end
|
383
|
+
next
|
384
|
+
end
|
339
385
|
glob = Array(glob || '**/*')
|
340
386
|
target = []
|
387
|
+
from = path + from
|
341
388
|
if workspace
|
342
389
|
Dir.glob(from + '*').each do |path|
|
343
390
|
next unless (path = Pathname.new(path)).directory?
|
@@ -361,16 +408,14 @@ module Squared
|
|
361
408
|
end
|
362
409
|
end
|
363
410
|
else
|
364
|
-
target << [from, dest.join(into, scope ||
|
411
|
+
target << [from, dest.join(into, scope || npmname)]
|
365
412
|
end
|
366
413
|
target.each do |src, to|
|
367
414
|
glob.each { |val| log.info "cp #{from + val} #{to}" }
|
368
415
|
begin
|
369
416
|
copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
|
370
417
|
rescue StandardError => e
|
371
|
-
|
372
|
-
ret = on(:error, :copy, e)
|
373
|
-
raise if exception && ret != true
|
418
|
+
on_error e, :copy
|
374
419
|
end
|
375
420
|
end
|
376
421
|
end
|
@@ -384,7 +429,19 @@ module Squared
|
|
384
429
|
workspace.rev_clear(name, sync: sync)
|
385
430
|
return update if !flag && env('NODE_UPDATE')
|
386
431
|
|
387
|
-
|
432
|
+
pnpm = pnpm?
|
433
|
+
yarn = pnpm ? 0 : dependtype(:yarn)
|
434
|
+
if @pm[:__] && !pnpm && yarn == 0
|
435
|
+
case @pm[:__]
|
436
|
+
when 'pnpm'
|
437
|
+
pnpm = true
|
438
|
+
when 'yarn'
|
439
|
+
yarn = 1
|
440
|
+
when 'berry'
|
441
|
+
yarn = 2
|
442
|
+
end
|
443
|
+
end
|
444
|
+
if yarn > 0
|
388
445
|
cmd = session 'yarn'
|
389
446
|
if flag == :add
|
390
447
|
cmd << 'add'
|
@@ -394,7 +451,7 @@ module Squared
|
|
394
451
|
cmd << 'install'
|
395
452
|
cmd << '--ignore-engines' if yarn == 1 && !option('ignore-engines', equals: '0')
|
396
453
|
end
|
397
|
-
elsif pnpm
|
454
|
+
elsif pnpm
|
398
455
|
cmd = session 'pnpm'
|
399
456
|
if flag == :add
|
400
457
|
cmd << 'add' << "--save-#{save}"
|
@@ -436,19 +493,14 @@ module Squared
|
|
436
493
|
log.info cmd.to_s
|
437
494
|
on :first, :outdated
|
438
495
|
end
|
439
|
-
banner = format_banner(cmd.temp(dryrun ? '
|
496
|
+
banner = format_banner(cmd.temp(dryrun ? '--dry-run' : nil))
|
440
497
|
print_item banner if sync
|
441
498
|
begin
|
442
499
|
data = pwd_set { `#{cmd.temp('--json', '--loglevel=error')}` }
|
443
500
|
doc = dependfile.read
|
444
501
|
json = JSON.parse(doc)
|
445
502
|
rescue StandardError => e
|
446
|
-
|
447
|
-
unless dryrun
|
448
|
-
ret = on(:error, :outdated, e)
|
449
|
-
raise if exception && ret != true
|
450
|
-
end
|
451
|
-
warn log_message(Logger::WARN, e) if warning?
|
503
|
+
on_error(e, :outdated, dryrun: dryrun)
|
452
504
|
return
|
453
505
|
else
|
454
506
|
dep1 = json['dependencies'] || {}
|
@@ -599,16 +651,16 @@ module Squared
|
|
599
651
|
package('update', from: :update)
|
600
652
|
end
|
601
653
|
|
602
|
-
def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil,
|
654
|
+
def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, access: nil, dryrun: nil)
|
603
655
|
if !version || read_packagemanager(:private)
|
604
656
|
warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: version ? 'private' : nil)
|
605
657
|
return
|
606
658
|
end
|
607
659
|
cmd = session 'npm', 'publish'
|
608
|
-
cmd << basic_option('otp', otp) if otp
|
609
|
-
cmd << basic_option('tag', tag) if tag
|
610
|
-
cmd << basic_option('access', access) if access
|
611
|
-
dryrun
|
660
|
+
cmd << basic_option('otp', otp) if otp &&= option('otp')
|
661
|
+
cmd << basic_option('tag', tag) if tag &&= option('tag')
|
662
|
+
cmd << basic_option('access', access) if access &&= option('access')
|
663
|
+
dryrun &&= dryrun?('npm')
|
612
664
|
if dryrun
|
613
665
|
cmd << '--dry-run'
|
614
666
|
else
|
@@ -616,7 +668,7 @@ module Squared
|
|
616
668
|
log.info cmd.to_s
|
617
669
|
end
|
618
670
|
if sync
|
619
|
-
run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(
|
671
|
+
run(from: from, sync: sync, interactive: !dryrun && "Publish #{sub_style(npmname, styles: theme[:active])}")
|
620
672
|
else
|
621
673
|
on :first, from
|
622
674
|
pwd_set(from: :publish, dryrun: dryrun) do
|
@@ -697,15 +749,18 @@ module Squared
|
|
697
749
|
when :major
|
698
750
|
if seg[0] != '0' || seg[2].nil?
|
699
751
|
seg[0] = seg[0].succ
|
752
|
+
seg[2] = '0'
|
700
753
|
else
|
701
754
|
seg[2] = seg[2].succ
|
702
755
|
end
|
756
|
+
seg[4] = '0'
|
703
757
|
when :minor
|
704
758
|
if seg[0] == '0'
|
705
759
|
seg[4] &&= seg[4].succ
|
706
760
|
else
|
707
761
|
seg[2] = seg[2].succ
|
708
762
|
end
|
763
|
+
seg[4] = '0'
|
709
764
|
when :patch
|
710
765
|
seg[4] &&= seg[4].succ
|
711
766
|
end
|
@@ -735,9 +790,7 @@ module Squared
|
|
735
790
|
raise_error('version not found', hint: dependfile)
|
736
791
|
end
|
737
792
|
rescue StandardError => e
|
738
|
-
|
739
|
-
ret = on(:error, :bump, e)
|
740
|
-
raise if exception && ret != true
|
793
|
+
on_error e, :bump
|
741
794
|
end
|
742
795
|
end
|
743
796
|
|
@@ -876,7 +929,7 @@ module Squared
|
|
876
929
|
end
|
877
930
|
|
878
931
|
def version
|
879
|
-
|
932
|
+
@version ||= read_packagemanager(:version)
|
880
933
|
end
|
881
934
|
|
882
935
|
def packagename
|
@@ -902,7 +955,7 @@ module Squared
|
|
902
955
|
else
|
903
956
|
if key
|
904
957
|
@pm[key]
|
905
|
-
elsif (ret = @pm[:_]) && !
|
958
|
+
elsif (ret = @pm[:_]) && (!version || semgte?(ret[(ret.index('@') + 1)..-1], version))
|
906
959
|
ret
|
907
960
|
end
|
908
961
|
end
|
@@ -967,6 +1020,10 @@ module Squared
|
|
967
1020
|
'package.json' if parent&.has?('outdated', Node.ref)
|
968
1021
|
end
|
969
1022
|
|
1023
|
+
def npmname
|
1024
|
+
packagename || project
|
1025
|
+
end
|
1026
|
+
|
970
1027
|
def npmnotice
|
971
1028
|
[
|
972
1029
|
{ pat: /^(npm error )(code|\d+)(.+)$/, styles: color(:cyan), index: 2 },
|
@@ -87,7 +87,6 @@ module Squared
|
|
87
87
|
initialize_build(Python.ref, **kwargs)
|
88
88
|
initialize_env(**kwargs)
|
89
89
|
end
|
90
|
-
@verbose = verbose.size if verbose.is_a?(String) && verbose.match?(/\Av+\z/)
|
91
90
|
dependfile_set DEP_PYTHON
|
92
91
|
editable_set editable
|
93
92
|
venv_set kwargs[:venv]
|
@@ -95,7 +94,7 @@ module Squared
|
|
95
94
|
|
96
95
|
subtasks({
|
97
96
|
'venv' => %i[exec create remove show].freeze,
|
98
|
-
'pip' => %i[uninstall freeze].freeze,
|
97
|
+
'pip' => %i[upgrade uninstall freeze].freeze,
|
99
98
|
'install' => %i[user force upgrade target editable].freeze,
|
100
99
|
'outdated' => %i[major minor patch].freeze,
|
101
100
|
'build' => %i[python poetry pdm hatch].freeze,
|
@@ -104,17 +103,26 @@ module Squared
|
|
104
103
|
'exec' => nil
|
105
104
|
})
|
106
105
|
|
106
|
+
def verbose=(val)
|
107
|
+
case val
|
108
|
+
when /\Av+\z/
|
109
|
+
@verbose = val.size
|
110
|
+
else
|
111
|
+
super
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
107
115
|
def ref
|
108
116
|
Python.ref
|
109
117
|
end
|
110
118
|
|
111
119
|
def populate(*, **)
|
112
120
|
super
|
113
|
-
return unless outdated? && ref?(Python.ref)
|
121
|
+
return unless (outdated? && ref?(Python.ref)) || @only
|
114
122
|
|
115
123
|
namespace name do
|
116
124
|
Python.subtasks do |action, flags|
|
117
|
-
next if
|
125
|
+
next if task_pass?(action)
|
118
126
|
|
119
127
|
if flags.nil?
|
120
128
|
case action
|
@@ -159,7 +167,7 @@ module Squared
|
|
159
167
|
found |= 1
|
160
168
|
run(pdm_session('run', val), from: :run)
|
161
169
|
else
|
162
|
-
raise_error
|
170
|
+
raise_error "script: #{val}" if exception
|
163
171
|
found |= 2
|
164
172
|
log.warn "run script \"#{val}\" (not indexed)"
|
165
173
|
end
|
@@ -183,7 +191,7 @@ module Squared
|
|
183
191
|
elsif i || args.empty?
|
184
192
|
readline('Enter command', force: true)
|
185
193
|
else
|
186
|
-
if (val = command_args(args, prefix: 'python'))
|
194
|
+
if (val = command_args(args, min: 1, prefix: 'python'))
|
187
195
|
args << val
|
188
196
|
end
|
189
197
|
args.join(' ')
|
@@ -234,6 +242,14 @@ module Squared
|
|
234
242
|
end
|
235
243
|
when 'pip'
|
236
244
|
case flag
|
245
|
+
when :upgrade
|
246
|
+
format_desc action, flag, 'opts*'
|
247
|
+
task flag do |_, args|
|
248
|
+
args = args.to_a
|
249
|
+
args.unshift('upgrade')
|
250
|
+
args << 'pip'
|
251
|
+
install flag, args
|
252
|
+
end
|
237
253
|
when :freeze
|
238
254
|
format_desc action, flag, "file?=#{DEP_PYTHON[4]},opts*"
|
239
255
|
task flag do |_, args|
|
@@ -287,7 +303,7 @@ module Squared
|
|
287
303
|
when 'build'
|
288
304
|
case flag
|
289
305
|
when :poetry
|
290
|
-
next unless
|
306
|
+
next unless poetry?
|
291
307
|
when :pdm
|
292
308
|
next unless build_backend == 'pdm.backend'
|
293
309
|
when :hatch
|
@@ -325,8 +341,8 @@ module Squared
|
|
325
341
|
elsif outdated?
|
326
342
|
venv_init
|
327
343
|
workspace.rev_clear(name, sync: sync)
|
328
|
-
if !flag &&
|
329
|
-
cmd = poetry_session 'install
|
344
|
+
if !flag && poetry?
|
345
|
+
cmd = poetry_session 'install -n'
|
330
346
|
cmd << '--no-root' if option('no-root')
|
331
347
|
else
|
332
348
|
cmd = pip_session 'install'
|
@@ -351,7 +367,7 @@ module Squared
|
|
351
367
|
end
|
352
368
|
|
353
369
|
def outdated(flag = nil, opts = [], sync: invoked_sync?('outdated'))
|
354
|
-
cmd = pip_session 'list
|
370
|
+
cmd = pip_session 'list --outdated'
|
355
371
|
append_global
|
356
372
|
cmd = session_done cmd
|
357
373
|
log.info cmd
|
@@ -366,7 +382,11 @@ module Squared
|
|
366
382
|
pwd_set(from: :outdated) do
|
367
383
|
buffer = []
|
368
384
|
out = ->(val) { sync ? puts(val) : buffer << val }
|
369
|
-
|
385
|
+
if workspace.windows?
|
386
|
+
(venv ? command(runenv, cmd) : `#{cmd}`).lines
|
387
|
+
else
|
388
|
+
IO.popen(runenv || {}, cmd)
|
389
|
+
end.each do |line|
|
370
390
|
next if line.match?(/^[ -]+$/)
|
371
391
|
|
372
392
|
if start > 0
|
@@ -454,6 +474,11 @@ module Squared
|
|
454
474
|
cmd << '--user' if user
|
455
475
|
cmd << basic_option('upgrade-strategy', strategy) if strategy
|
456
476
|
append_value out
|
477
|
+
if workspace.windows?
|
478
|
+
pip = cmd.to_a.drop(1)
|
479
|
+
cmd = python_session '-m pip'
|
480
|
+
cmd.merge(pip)
|
481
|
+
end
|
457
482
|
end
|
458
483
|
run(from: :install)
|
459
484
|
end
|
@@ -488,7 +513,7 @@ module Squared
|
|
488
513
|
if srcdir
|
489
514
|
args = flag == :pdm ? ['d', 'dest'] : ['o', 'output']
|
490
515
|
if op.arg?(*args)
|
491
|
-
op.
|
516
|
+
op.push(srcdir)
|
492
517
|
else
|
493
518
|
op << quote_option(args.last, path + srcdir)
|
494
519
|
end
|
@@ -502,7 +527,7 @@ module Squared
|
|
502
527
|
end
|
503
528
|
op << basic_option('p', project) unless ENV['HATCH_PROJECT'] || op.arg?('p', 'project')
|
504
529
|
end
|
505
|
-
op
|
530
|
+
op.add_path(srcdir) if srcdir
|
506
531
|
op.clear
|
507
532
|
run(from: :"#{flag}:build")
|
508
533
|
end
|
@@ -531,7 +556,7 @@ module Squared
|
|
531
556
|
case flag
|
532
557
|
when :hatch, :twine
|
533
558
|
if op.empty?
|
534
|
-
op.
|
559
|
+
op.push("#{dist.call}/*")
|
535
560
|
else
|
536
561
|
op.map! { |val| path + val }
|
537
562
|
end
|
@@ -548,7 +573,7 @@ module Squared
|
|
548
573
|
out = append_pip(nil, opts, from: flag)
|
549
574
|
case flag
|
550
575
|
when :uninstall
|
551
|
-
raise_error('no packages listed', hint:
|
576
|
+
raise_error('no packages listed', hint: flag) if out.empty?
|
552
577
|
cmd.merge(out)
|
553
578
|
when :freeze
|
554
579
|
venv_init
|
@@ -649,9 +674,9 @@ module Squared
|
|
649
674
|
end
|
650
675
|
op.swap
|
651
676
|
if edit
|
652
|
-
edit = path + edit unless %r{
|
677
|
+
edit = path + edit unless %r{\A[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
|
653
678
|
if flag == :editable
|
654
|
-
op.
|
679
|
+
op.push(edit)
|
655
680
|
else
|
656
681
|
target << quote_option('e', edit)
|
657
682
|
end
|
@@ -847,8 +872,8 @@ module Squared
|
|
847
872
|
return if !venv || (venvbin.directory? && !venvbin.empty?)
|
848
873
|
|
849
874
|
puts log_message(Logger::INFO, venv, subject: 'venv', hint: 'init')
|
850
|
-
|
851
|
-
venv_create(venv,
|
875
|
+
opts = @venvopts&.map { |val| OptionPartition.strip(val) }&.flatten
|
876
|
+
venv_create(venv, opts || ["prompt=#{name}", 'upgrade-deps'], env: false, banner: false)
|
852
877
|
puts log_message(Logger::INFO, venv, subject: 'venv', hint: 'created')
|
853
878
|
end
|
854
879
|
|
@@ -862,6 +887,10 @@ module Squared
|
|
862
887
|
puts(dir.directory? ? "Success: #{dir}" : 'Failed') if banner && !status
|
863
888
|
end
|
864
889
|
|
890
|
+
def poetry?
|
891
|
+
build_backend ? build_backend == 'poetry.core.masonry.api' : dependtype == 1
|
892
|
+
end
|
893
|
+
|
865
894
|
def requirements?
|
866
895
|
dependtype == 5
|
867
896
|
end
|