squared 0.6.9 → 0.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +74 -2
- data/README.md +239 -200
- data/lib/squared/common/format.rb +7 -10
- data/lib/squared/common/prompt.rb +23 -24
- data/lib/squared/common/shell.rb +16 -17
- data/lib/squared/common/system.rb +29 -20
- data/lib/squared/common/utils.rb +43 -54
- data/lib/squared/config.rb +17 -16
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +290 -175
- data/lib/squared/workspace/project/base.rb +542 -442
- data/lib/squared/workspace/project/docker.rb +151 -131
- data/lib/squared/workspace/project/git.rb +178 -144
- data/lib/squared/workspace/project/node.rb +89 -87
- data/lib/squared/workspace/project/python.rb +236 -139
- data/lib/squared/workspace/project/ruby.rb +395 -281
- data/lib/squared/workspace/project/support/class.rb +12 -6
- data/lib/squared/workspace/project/support/optionpartition.rb +58 -41
- data/lib/squared/workspace/project/support/utils.rb +68 -0
- data/lib/squared/workspace/project.rb +0 -7
- data/lib/squared/workspace/repo.rb +234 -169
- data/lib/squared/workspace/series.rb +91 -86
- data/lib/squared/workspace/support/base.rb +15 -1
- metadata +2 -1
|
@@ -149,11 +149,11 @@ module Squared
|
|
|
149
149
|
'pack' => nil
|
|
150
150
|
})
|
|
151
151
|
|
|
152
|
-
def initialize(*,
|
|
152
|
+
def initialize(*, ts: 'tsconfig.json', asdf: 'nodejs', **kwargs)
|
|
153
153
|
super
|
|
154
154
|
if @pass.include?(Node.ref)
|
|
155
155
|
initialize_ref Node.ref
|
|
156
|
-
initialize_logger
|
|
156
|
+
initialize_logger kwargs[:log]
|
|
157
157
|
else
|
|
158
158
|
initialize_build(Node.ref, prod: prod?, **kwargs)
|
|
159
159
|
initialize_env(**kwargs)
|
|
@@ -161,7 +161,7 @@ module Squared
|
|
|
161
161
|
@dependname = 'package.json'
|
|
162
162
|
dependfile_set [@dependname]
|
|
163
163
|
@tsfile = basepath! ts
|
|
164
|
-
@pm = { __: init }
|
|
164
|
+
@pm = { __: kwargs[:init] }
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
def ref
|
|
@@ -201,23 +201,24 @@ module Squared
|
|
|
201
201
|
format_list(list, "run[#{indexchar}N]", 'scripts', grep: args.extras, from: dependfile)
|
|
202
202
|
else
|
|
203
203
|
args = param_guard(action, 'script', args: args.to_a)
|
|
204
|
-
opts = []
|
|
205
|
-
args.each do |val|
|
|
204
|
+
opts = args.each_with_object([]) do |val, out|
|
|
206
205
|
if (n, extra = indexitem(val))
|
|
207
206
|
if (item = list[n.pred])
|
|
208
207
|
run compose([item.first, extra].compact.join(' '), script: true)
|
|
209
208
|
elsif exception
|
|
210
209
|
indexerror n, list
|
|
211
210
|
else
|
|
212
|
-
|
|
211
|
+
log.warn "run script #{n} of #{list.size}".subhint('out of range')
|
|
212
|
+
next
|
|
213
213
|
end
|
|
214
214
|
else
|
|
215
|
-
|
|
215
|
+
out << val
|
|
216
216
|
end
|
|
217
217
|
end
|
|
218
218
|
next if opts.empty?
|
|
219
219
|
|
|
220
|
-
|
|
220
|
+
yarn = dependtype(:yarn)
|
|
221
|
+
list = if yarn > 0
|
|
221
222
|
yarn == 1 ? OPT_YARN[:run] + OPT_YARN[:common] : OPT_BERRY[:run]
|
|
222
223
|
elsif pnpm?
|
|
223
224
|
pnpmopts :run, :common_filter
|
|
@@ -260,14 +261,20 @@ module Squared
|
|
|
260
261
|
run(from: :exec)
|
|
261
262
|
end
|
|
262
263
|
when 'nvm'
|
|
263
|
-
next unless ENV['NVM_DIR']
|
|
264
|
+
next unless ENV['NVM_DIR'] && !workspace.windows?
|
|
264
265
|
|
|
265
|
-
format_desc action, nil, 'version
|
|
266
|
+
format_desc action, nil, 'version?,args*'
|
|
266
267
|
task action, [:version] do |_, args|
|
|
267
|
-
|
|
268
|
+
path = ->(s) { File.join(ENV['NVM_DIR'], s) }
|
|
269
|
+
unless (version = args.version)
|
|
270
|
+
cmd = ". #{path.call('nvm.sh')} && nvm list --no-colors --no-alias"
|
|
271
|
+
version = pwd_set(from: :nvm) do
|
|
272
|
+
choice_index('Select a version', IO.popen(cmd).map { |line| line[/\s(v\S+)/, 1] }, series: true)
|
|
273
|
+
end
|
|
274
|
+
end
|
|
268
275
|
args = args.extras
|
|
269
276
|
args << readline('Enter command', force: true) if args.empty?
|
|
270
|
-
args.unshift(
|
|
277
|
+
args.unshift(path.call('nvm-exec'))
|
|
271
278
|
run(args.join(' '), { 'NODE_VERSION' => version }, banner: false, from: :nvm)
|
|
272
279
|
end
|
|
273
280
|
when 'pack'
|
|
@@ -423,11 +430,12 @@ module Squared
|
|
|
423
430
|
begin
|
|
424
431
|
unless packed
|
|
425
432
|
require 'open3'
|
|
426
|
-
|
|
427
|
-
|
|
433
|
+
cmd = session_output 'npm', 'pack --dry-run --no-color', npmname
|
|
434
|
+
files = pwd_set(cmd, from: :'npm:pack') do
|
|
435
|
+
Open3.capture2e(cmd.to_s)
|
|
428
436
|
.first
|
|
429
437
|
.scan(/^npm notice \d+(?:\.\d+)?[a-z]+ (.+)$/i)
|
|
430
|
-
.map
|
|
438
|
+
.map { |item| Pathname.new(item.first) }
|
|
431
439
|
.select(&:exist?)
|
|
432
440
|
end.concat(Array(files))
|
|
433
441
|
packed = true
|
|
@@ -435,21 +443,21 @@ module Squared
|
|
|
435
443
|
base = dest.join(into, npmname)
|
|
436
444
|
base.mkpath
|
|
437
445
|
log.info "cp npm:#{npmname} #{base}"
|
|
438
|
-
subdir = []
|
|
439
446
|
errors = 0
|
|
440
|
-
files.
|
|
441
|
-
s, d = file.is_a?(Array) ? file : [file
|
|
447
|
+
subdir = files.each_with_object([]) do |file, out|
|
|
448
|
+
s, d = file.is_a?(Array) ? file : [file] * 2
|
|
442
449
|
dest = base + d
|
|
443
|
-
|
|
450
|
+
target = dest.dirname
|
|
451
|
+
unless out.include?(dirname = target.to_s)
|
|
444
452
|
target.mkpath
|
|
445
|
-
|
|
453
|
+
out << dirname
|
|
446
454
|
end
|
|
447
455
|
FileUtils.cp(basepath(s), dest, verbose: !silent?)
|
|
448
|
-
rescue
|
|
449
|
-
print_error e
|
|
456
|
+
rescue => e
|
|
457
|
+
print_error(Logger::ERROR, e, subject: name)
|
|
450
458
|
errors += 1
|
|
451
459
|
end
|
|
452
|
-
rescue
|
|
460
|
+
rescue => e
|
|
453
461
|
on_error e, :copy
|
|
454
462
|
else
|
|
455
463
|
puts message(base, subdir.size, files.size - errors) unless silent?
|
|
@@ -469,9 +477,8 @@ module Squared
|
|
|
469
477
|
begin
|
|
470
478
|
doc = JSON.parse(file.read)
|
|
471
479
|
doc['name']
|
|
472
|
-
rescue
|
|
473
|
-
|
|
474
|
-
raise if exception
|
|
480
|
+
rescue => e
|
|
481
|
+
print_error(Logger::ERROR, e, subject: proj.name)
|
|
475
482
|
end
|
|
476
483
|
end
|
|
477
484
|
if sub
|
|
@@ -486,8 +493,8 @@ module Squared
|
|
|
486
493
|
target.each do |src, to|
|
|
487
494
|
glob.each { |val| log.info "cp #{from + val} #{to}" }
|
|
488
495
|
copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: !silent?)
|
|
489
|
-
rescue
|
|
490
|
-
on_error e
|
|
496
|
+
rescue => e
|
|
497
|
+
on_error e
|
|
491
498
|
end
|
|
492
499
|
end
|
|
493
500
|
on :last, :copy
|
|
@@ -499,7 +506,7 @@ module Squared
|
|
|
499
506
|
super
|
|
500
507
|
elsif outdated?
|
|
501
508
|
workspace.rev_clear(name, sync: sync)
|
|
502
|
-
return update if !flag && env('NODE_UPDATE')
|
|
509
|
+
return update if !flag && (env('UPDATE') || env('NODE_UPDATE'))
|
|
503
510
|
|
|
504
511
|
add = flag == :add
|
|
505
512
|
if add
|
|
@@ -526,13 +533,14 @@ module Squared
|
|
|
526
533
|
rm = lambda do |target|
|
|
527
534
|
return if remove.empty?
|
|
528
535
|
|
|
529
|
-
run(target.temp(*remove).sub!(/ (?:add|install) /, ' remove '),
|
|
536
|
+
run(target.temp(*remove).sub!(/ (?:add|install) /, ' remove '), sync: sync, from: :remove)
|
|
530
537
|
end
|
|
531
|
-
|
|
538
|
+
yarn = dependtype(:yarn)
|
|
539
|
+
if yarn > 0
|
|
532
540
|
cmd = session('yarn', flag || 'install')
|
|
533
541
|
append_loglevel
|
|
534
542
|
if yarn == 1
|
|
535
|
-
cmd << '--ignore-engines'
|
|
543
|
+
cmd << '--ignore-engines' if option('ignore-engines')
|
|
536
544
|
cmd << '--ignore-scripts' if option('ignore-scripts')
|
|
537
545
|
cmd << '--force' if option('force')
|
|
538
546
|
else
|
|
@@ -549,7 +557,7 @@ module Squared
|
|
|
549
557
|
end
|
|
550
558
|
end
|
|
551
559
|
if add
|
|
552
|
-
cmd << '-W' if yarn == 1 &&
|
|
560
|
+
cmd << '-W' if yarn == 1 && option('w', 'ignore-workspace-root-check', notequals: '0')
|
|
553
561
|
rm.call(cmd)
|
|
554
562
|
om.call(cmd)
|
|
555
563
|
cmd << '--exact' if exact
|
|
@@ -606,7 +614,7 @@ module Squared
|
|
|
606
614
|
|
|
607
615
|
cmd.merge(packages.quote!)
|
|
608
616
|
end
|
|
609
|
-
run(from: flag || :depend
|
|
617
|
+
run(sync: sync, from: flag || :depend)
|
|
610
618
|
end
|
|
611
619
|
end
|
|
612
620
|
|
|
@@ -620,14 +628,14 @@ module Squared
|
|
|
620
628
|
banner = format_banner(cmd.temp(('--dry-run' if dryrun)))
|
|
621
629
|
print_item banner if sync
|
|
622
630
|
begin
|
|
623
|
-
data = pwd_set(dryrun: dryrun) { `#{cmd.temp('--json --loglevel=error')}` }
|
|
631
|
+
data = pwd_set(cmd, dryrun: dryrun) { `#{cmd.temp('--json --loglevel=error')}` }
|
|
624
632
|
doc = dependfile.read
|
|
625
633
|
json = JSON.parse(doc)
|
|
626
634
|
dep1 = json['dependencies'] || {}
|
|
627
635
|
dep2 = json['devDependencies'] || {}
|
|
628
636
|
target = json['name']
|
|
629
|
-
rescue
|
|
630
|
-
on_error(e,
|
|
637
|
+
rescue => e
|
|
638
|
+
on_error(e, dryrun: dryrun)
|
|
631
639
|
return
|
|
632
640
|
end
|
|
633
641
|
found = []
|
|
@@ -858,7 +866,7 @@ module Squared
|
|
|
858
866
|
end
|
|
859
867
|
return
|
|
860
868
|
end
|
|
861
|
-
return print_error(
|
|
869
|
+
return print_error("version: #{dependname}", subject: name, hint: 'not found') unless version
|
|
862
870
|
|
|
863
871
|
cmd = session 'npm', 'publish'
|
|
864
872
|
cmd << basic_option('otp', otp) if otp ||= option('otp')
|
|
@@ -881,8 +889,9 @@ module Squared
|
|
|
881
889
|
else
|
|
882
890
|
require 'open3'
|
|
883
891
|
on :first, from
|
|
884
|
-
pwd_set(
|
|
885
|
-
|
|
892
|
+
pwd_set(cmd, dryrun: dryrun) do
|
|
893
|
+
cmd = session_done cmd
|
|
894
|
+
Open3.popen2e(cmd) do |_, out|
|
|
886
895
|
write_lines(out, banner: format_banner(cmd),
|
|
887
896
|
sub: npmnotice(opt_style(color(:bright_blue), /^(.+)(Tarball .+)$/, 2)))
|
|
888
897
|
end
|
|
@@ -927,7 +936,7 @@ module Squared
|
|
|
927
936
|
end, cmd, project: self)
|
|
928
937
|
if yarn == 1 && flag != :reinstall
|
|
929
938
|
op << '--no-lockfile' if nolockfile?('yarn')
|
|
930
|
-
op << '--ignore-engines'
|
|
939
|
+
op << '--ignore-engines' if option('ignore-engines')
|
|
931
940
|
end
|
|
932
941
|
else
|
|
933
942
|
args = if pnpm?
|
|
@@ -942,22 +951,18 @@ module Squared
|
|
|
942
951
|
flag = :install
|
|
943
952
|
end
|
|
944
953
|
flags = [flag]
|
|
945
|
-
unless flag == :rebuild
|
|
946
|
-
|
|
947
|
-
|
|
954
|
+
flags << :install_a unless flag == :rebuild
|
|
955
|
+
unless flag == :dedupe
|
|
956
|
+
flags << :common_filter
|
|
957
|
+
unless flag == :add
|
|
958
|
+
flags << :install_b
|
|
959
|
+
flags << :common_cpu unless flag == :update
|
|
960
|
+
end
|
|
948
961
|
end
|
|
962
|
+
no = OPT_PNPM[:no][flag]
|
|
949
963
|
[
|
|
950
964
|
opts,
|
|
951
|
-
flags
|
|
952
|
-
unless flag == :dedupe
|
|
953
|
-
out << :common_filter
|
|
954
|
-
unless flag == :add
|
|
955
|
-
out << :install_b
|
|
956
|
-
out << :common_cpu unless flag == :update
|
|
957
|
-
end
|
|
958
|
-
end
|
|
959
|
-
pnpmopts(*out)
|
|
960
|
-
end,
|
|
965
|
+
pnpmopts(*flags),
|
|
961
966
|
session('pnpm', flag)
|
|
962
967
|
]
|
|
963
968
|
else
|
|
@@ -979,12 +984,12 @@ module Squared
|
|
|
979
984
|
unless flag == :dedupe
|
|
980
985
|
%w[save ignore-scripts strict-peer-deps].each do |key|
|
|
981
986
|
option(key, prefix: 'npm', ignore: false) do |val|
|
|
982
|
-
opts << case val
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
987
|
+
opts << basic_option(key, case val
|
|
988
|
+
when '0', 'false'
|
|
989
|
+
false
|
|
990
|
+
else
|
|
991
|
+
true
|
|
992
|
+
end)
|
|
988
993
|
end
|
|
989
994
|
end
|
|
990
995
|
flags << :install_b
|
|
@@ -1016,15 +1021,14 @@ module Squared
|
|
|
1016
1021
|
op.found << (spec == 2 && (n = opt.index('@')) ? opt[0, n] : opt)
|
|
1017
1022
|
end
|
|
1018
1023
|
end
|
|
1019
|
-
op.swap
|
|
1020
|
-
.concat(packages)
|
|
1024
|
+
op.swap.concat(packages)
|
|
1021
1025
|
raise_error ArgumentError, 'no packages to add' if op.empty? && spec == 1
|
|
1022
1026
|
op.append(quote: true)
|
|
1023
1027
|
.clear(errors: true)
|
|
1024
1028
|
else
|
|
1025
1029
|
op.clear
|
|
1026
1030
|
end
|
|
1027
|
-
run(from: from ||
|
|
1031
|
+
run(from: from || symjoin('package', flag))
|
|
1028
1032
|
end
|
|
1029
1033
|
|
|
1030
1034
|
def bump(flag, val = nil)
|
|
@@ -1054,8 +1058,8 @@ module Squared
|
|
|
1054
1058
|
else
|
|
1055
1059
|
raise_error 'version not found', hint: dependfile
|
|
1056
1060
|
end
|
|
1057
|
-
rescue
|
|
1058
|
-
on_error(e,
|
|
1061
|
+
rescue => e
|
|
1062
|
+
on_error(e, dryrun: dryrun?)
|
|
1059
1063
|
end
|
|
1060
1064
|
|
|
1061
1065
|
def pack(opts = [])
|
|
@@ -1115,11 +1119,9 @@ module Squared
|
|
|
1115
1119
|
print_run(cmd, banner, **kwargs)
|
|
1116
1120
|
session 'npx', cmd
|
|
1117
1121
|
start = time_epoch if kwargs.fetch(:verbose, verbose? && !stdin?)
|
|
1118
|
-
run(sync: sync, banner: banner, exception: kwargs.fetch(:exception, exception), from: from)
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
print_status(name, subject: 'tsc', start: start, from: :completed)
|
|
1122
|
-
end
|
|
1122
|
+
ret = run(sync: sync, banner: banner, exception: kwargs.fetch(:exception, exception?), from: from)
|
|
1123
|
+
print_status(name, subject: 'tsc', start: start) if success?(ret, banner, start.nil?) && start
|
|
1124
|
+
ret
|
|
1123
1125
|
end
|
|
1124
1126
|
|
|
1125
1127
|
def compose(target, opts = nil, script: false, args: nil, from: nil, **)
|
|
@@ -1239,7 +1241,7 @@ module Squared
|
|
|
1239
1241
|
private
|
|
1240
1242
|
|
|
1241
1243
|
def read_package(key = 'packageManager', update: false)
|
|
1242
|
-
|
|
1244
|
+
unless !update && @pm.key?(key)
|
|
1243
1245
|
doc = JSON.parse(dependfile.read)
|
|
1244
1246
|
@pm[key] = case key
|
|
1245
1247
|
when 'packageManager'
|
|
@@ -1256,7 +1258,7 @@ module Squared
|
|
|
1256
1258
|
@pm[:_] = true
|
|
1257
1259
|
end
|
|
1258
1260
|
end
|
|
1259
|
-
rescue
|
|
1261
|
+
rescue => e
|
|
1260
1262
|
log.debug e
|
|
1261
1263
|
@pm[key] = nil
|
|
1262
1264
|
else
|
|
@@ -1299,7 +1301,7 @@ module Squared
|
|
|
1299
1301
|
else
|
|
1300
1302
|
1
|
|
1301
1303
|
end
|
|
1302
|
-
rescue
|
|
1304
|
+
rescue => e
|
|
1303
1305
|
return 0 if exist
|
|
1304
1306
|
|
|
1305
1307
|
log.debug e
|
|
@@ -1318,7 +1320,7 @@ module Squared
|
|
|
1318
1320
|
else
|
|
1319
1321
|
4
|
|
1320
1322
|
end
|
|
1321
|
-
rescue
|
|
1323
|
+
rescue => e
|
|
1322
1324
|
if exist
|
|
1323
1325
|
%w[pnpm-lock.yaml pnpm-workspace.yaml].any? { |val| exist?(val) } ? 4 : 0
|
|
1324
1326
|
else
|
|
@@ -1336,7 +1338,7 @@ module Squared
|
|
|
1336
1338
|
puts
|
|
1337
1339
|
print_error(e, hint: modules, pass: true)
|
|
1338
1340
|
exit 1
|
|
1339
|
-
rescue
|
|
1341
|
+
rescue => e
|
|
1340
1342
|
print_error(e, pass: true)
|
|
1341
1343
|
false
|
|
1342
1344
|
else
|
|
@@ -1417,23 +1419,23 @@ module Squared
|
|
|
1417
1419
|
end
|
|
1418
1420
|
|
|
1419
1421
|
def lockfile(delete = false)
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
if
|
|
1422
|
+
ret = basepath(if yarn?
|
|
1423
|
+
'yarn.lock'
|
|
1424
|
+
else
|
|
1425
|
+
pnpm? ? 'pnpm-lock.yaml' : 'package-lock.json'
|
|
1426
|
+
end)
|
|
1427
|
+
if ret.exist?
|
|
1426
1428
|
if delete
|
|
1427
|
-
|
|
1429
|
+
ret.delete
|
|
1428
1430
|
return
|
|
1429
1431
|
end
|
|
1430
|
-
|
|
1431
|
-
elsif (
|
|
1432
|
-
|
|
1432
|
+
ret
|
|
1433
|
+
elsif (ret = rootpath(ret.basename, ascend: dependroot)).exist?
|
|
1434
|
+
ret
|
|
1433
1435
|
end
|
|
1434
|
-
rescue
|
|
1436
|
+
rescue => e
|
|
1435
1437
|
log.debug e
|
|
1436
|
-
|
|
1438
|
+
ret
|
|
1437
1439
|
end
|
|
1438
1440
|
|
|
1439
1441
|
def nolockfile?(prefix = dependbin)
|