squared 0.4.8 → 0.4.10

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.
@@ -98,9 +98,8 @@ module Squared
98
98
  initialize_build(Node.ref, prod: prod?, **kwargs)
99
99
  initialize_env(**kwargs)
100
100
  end
101
- @buildtype = :run if script?
102
101
  @pm = {}
103
- @dependfile = basepath('package.json')
102
+ @dependfile = @path + 'package.json'
104
103
  end
105
104
 
106
105
  def ref
@@ -192,22 +191,21 @@ module Squared
192
191
  end
193
192
  end
194
193
  when 'publish'
195
- format_desc(action, flag, 'otp?,dry-run?=true', before: flag == :tag ? 'tag' : nil)
194
+ format_desc(action, flag, 'otp?,dry-run?,public|restricted?', before: flag == :tag ? 'tag' : nil)
196
195
  task flag do |_, args|
196
+ args = args.to_a
197
+ dryrun = true if args.delete('dry-run') || args.delete('true') || args.delete('d')
198
+ if args.delete('public') || args.delete('p')
199
+ access = 'public'
200
+ elsif args.delete('restricted') || args.delete('r')
201
+ access = 'restricted'
202
+ end
197
203
  if flag == :latest
198
- otp, dryrun = args.to_a
204
+ otp = args.first
199
205
  else
200
- args = param_guard(action, flag, args: args.to_a)
201
- tag, otp, dryrun = args
202
- end
203
- check = ->(val) { val == 'dry-run' || val == 'true' }
204
- if check.call(otp)
205
- dryrun = true
206
- otp = nil
207
- elsif dryrun
208
- dryrun = check.call(dryrun)
206
+ tag, otp = param_guard(action, flag, args: args)
209
207
  end
210
- publish(flag, otp: otp, tag: tag, dryrun: dryrun)
208
+ publish(flag, otp: otp, tag: tag, dryrun: dryrun, access: access)
211
209
  end
212
210
  end
213
211
  end
@@ -218,7 +216,7 @@ module Squared
218
216
  end
219
217
 
220
218
  def copy(from: 'build', into: 'node_modules', scope: nil, also: nil, create: nil, workspace: false,
221
- link: false, force: false, override: false, **kwargs)
219
+ link: false, force: false, override: false, sync: invoked_sync?('copy'), **kwargs)
222
220
  glob = kwargs[:include]
223
221
  pass = kwargs[:exclude]
224
222
  if @copy && !override
@@ -240,7 +238,7 @@ module Squared
240
238
  items = []
241
239
  if build? && path != @workspace.home && @workspace.home?
242
240
  items << @workspace.home
243
- @workspace.rev_clear(@workspace.find(@workspace.home).name)
241
+ @workspace.rev_clear(@workspace.find(@workspace.home).name, sync: sync)
244
242
  end
245
243
  items.concat(as_a(also)) if also
246
244
  return if items.empty?
@@ -251,13 +249,13 @@ module Squared
251
249
  case dir
252
250
  when Pathname
253
251
  dest = dir
254
- @workspace.rev_clear(dest)
252
+ @workspace.rev_clear(dest, sync: sync)
255
253
  when String
256
- dest = @workspace.rootpath(dir)
257
- @workspace.rev_clear(dest)
254
+ dest = @workspace.root + dir
255
+ @workspace.rev_clear(dest, sync: sync)
258
256
  when Symbol
259
257
  if (proj = @workspace.find(name: dir))
260
- @workspace.rev_clear(proj.name)
258
+ @workspace.rev_clear(proj.name, sync: sync)
261
259
  dest = proj.path
262
260
  else
263
261
  log.warn message("copy project :#{dir}", hint: 'not found')
@@ -275,25 +273,25 @@ module Squared
275
273
  glob = dir[:include]
276
274
  pass = dir[:exclude]
277
275
  dest = items.first unless dest && dest != true
278
- @workspace.rev_clear(dest) unless dest == true
276
+ @workspace.rev_clear(dest, sync: sync) unless dest == true
279
277
  when Project::Base
280
278
  dest = dir.path
281
- @workspace.rev_clear(dir.name)
279
+ @workspace.rev_clear(dir.name, sync: sync)
282
280
  else
283
281
  raise_error "copy: given #{dir}"
284
282
  end
285
283
  next unless from && dest&.directory?
286
284
 
287
- from = basepath(from)
285
+ from = path + from
288
286
  glob = as_a(glob || '**/*')
289
287
  target = []
290
288
  if workspace
291
- Dir.glob(from.join('*')).each do |path|
289
+ Dir.glob(from + '*').each do |path|
292
290
  next unless (path = Pathname.new(path)).directory?
293
291
 
294
292
  sub = if (proj = @workspace.find(path))
295
293
  proj.packagename
296
- elsif (file = path.join('package.json')).exist?
294
+ elsif (file = path + 'package.json').exist?
297
295
  begin
298
296
  doc = JSON.parse(file.read)
299
297
  rescue StandardError => e
@@ -313,7 +311,7 @@ module Squared
313
311
  target << [from, dest.join(into, scope || project)]
314
312
  end
315
313
  target.each do |src, to|
316
- glob.each { |val| log.info "cp #{from.join(val)} #{to}" }
314
+ glob.each { |val| log.info "cp #{from + val} #{to}" }
317
315
  begin
318
316
  copy_dir(src, to, glob, create: create, link: link, force: force, pass: pass, verbose: verbose)
319
317
  rescue StandardError => e
@@ -330,7 +328,7 @@ module Squared
330
328
  if @depend && !flag
331
329
  super
332
330
  elsif outdated?
333
- workspace.rev_clear(name)
331
+ workspace.rev_clear(name, sync: sync)
334
332
  return update if !flag && env('NODE_UPDATE')
335
333
 
336
334
  if (yarn = dependtype(:yarn)) > 0
@@ -428,8 +426,8 @@ module Squared
428
426
  want = rev == :major && !latest[SEM_VER, 6] ? latest : val['wanted']
429
427
  next unless (current != want || file != want) && (want.match?(SEM_VER) || !file.match?(SEM_VER))
430
428
 
431
- f = semscan(file)
432
- w = semscan(want)
429
+ f = semscan file
430
+ w = semscan want
433
431
  a = f[0]
434
432
  b = f[2]
435
433
  c = w[0]
@@ -549,7 +547,7 @@ module Squared
549
547
  package 'update'
550
548
  end
551
549
 
552
- def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil, **)
550
+ def publish(flag = nil, *, sync: invoked_sync?('publish', flag), otp: nil, tag: nil, dryrun: nil, access: nil)
553
551
  if read_packagemanager(:private)
554
552
  if warning?
555
553
  warn log_message(Logger::WARN, 'invalid task "publish"', subject: name, hint: 'private', pass: true)
@@ -559,11 +557,10 @@ module Squared
559
557
  return unless version
560
558
 
561
559
  cmd = session 'npm', 'publish'
562
- otp = option('otp') if otp.nil?
563
- tag = option('tag') if tag.nil?
564
560
  dryrun = dryrun?('npm') if dryrun.nil?
565
- cmd << basic_option('otp', otp) if otp
566
- cmd << shell_option('tag', tag) if tag
561
+ cmd << basic_option('otp', otp) if otp ||= option('otp')
562
+ cmd << basic_option('tag', tag) if tag ||= option('tag')
563
+ cmd << basic_option('access', access) if access ||= option('access')
567
564
  if verbose
568
565
  if dryrun
569
566
  cmd << '--dry-run'
@@ -623,7 +620,7 @@ module Squared
623
620
  if opt =~ op.values
624
621
  case $1
625
622
  when 'w', 'workspace'
626
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
623
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
627
624
  end
628
625
  elsif opt.include?('=')
629
626
  op.errors << opt
@@ -704,7 +701,7 @@ module Squared
704
701
  cmd = session dependbin, 'pack'
705
702
  if dependtype(:yarn) > 1
706
703
  op = OptionPartition.new(opts, OPT_BERRY[:pack], cmd, project: self)
707
- op << quote_option('out', Pathname.pwd.join("#{project}-#{version}.tgz")) unless op.arg?('out')
704
+ op << quote_option('out', Pathname.pwd + "#{project}-#{version}.tgz") unless op.arg?('out')
708
705
  else
709
706
  op = OptionPartition.new(opts, pnpm? ? OPT_PNPM[:pack] : OPT_NPM[:pack] + OPT_NPM[:common], cmd,
710
707
  project: self)
@@ -714,7 +711,7 @@ module Squared
714
711
 
715
712
  case $1
716
713
  when 'w', 'workspace'
717
- op << ($2.match?(%r{[\\/]}) ? quote_option($1, basepath($2)) : shell_option($1, $2))
714
+ op << ($2.match?(%r{[\\/]}) ? quote_option($1, path + $2) : shell_option($1, $2))
718
715
  op.found << opt
719
716
  end
720
717
  end
@@ -725,7 +722,7 @@ module Squared
725
722
  run(from: :pack)
726
723
  end
727
724
 
728
- def compose(target, opts = nil, script: false, args: nil, from: :run, **)
725
+ def compose(target, opts = nil, script: false, args: nil, from: nil, **)
729
726
  return unless target
730
727
 
731
728
  if script
@@ -761,6 +758,10 @@ module Squared
761
758
  outdated?
762
759
  end
763
760
 
761
+ def refresh?
762
+ !Node.prod?
763
+ end
764
+
764
765
  def yarn?
765
766
  (@pm[:yarn] ||= if rootpath('yarn.lock', ascend: dependext).exist?
766
767
  if (rc = rootpath('.yarnrc.yml', ascend: dependext)).exist?
@@ -10,13 +10,13 @@ module Squared
10
10
  common: %w[b B d E h i I O OO P q s S u v x c=q m=b W=b X=q check-hash-based-pycs=b].freeze,
11
11
  build: %w[n|no-isolation s|sdist v|verbose w|wheel x|skip-dependency-check C|config-setting=q installer=b
12
12
  o|outdir=p].freeze,
13
- venv: %w[clear copies symlinks system-site-packages upgrade upgrade-deps without-scm-ignore-files
14
- without-pip prompt=q].freeze
13
+ venv: %w[clear copies symlinks system-site-packages upgrade upgrade-deps without-scm-ignore-files without-pip
14
+ prompt=q].freeze
15
15
  }.freeze
16
16
  OPT_PIP = {
17
17
  common: %w[debug disable-pip-version-check isolated no-cache-dir no-color no-input no-python-version-warning
18
- q|quiet require-virtualenv v|verbose cache-dir=p cert=p client-cert=p exists-action=b log=p
19
- proxy=q python=q retries=i timeout=i trusted-host=b use-deprecated=b use-feature=b].freeze,
18
+ q|quiet require-virtualenv v|verbose cache-dir=p cert=p client-cert=p exists-action=b log=p proxy=q
19
+ python=q retries=i timeout=i trusted-host=b use-deprecated=b use-feature=b].freeze,
20
20
  install: %w[break-system-packages check-build-dependencies compile dry-run force-reinstall I|ignore-installed
21
21
  ignore-requires-python no-build-isolation no-clean no-compile no-deps no-index no-warn-conflicts
22
22
  no-warn-script-location pre prefer-binary require-hashes U|upgrade use-pep517 user abi=b
@@ -34,7 +34,7 @@ module Squared
34
34
  u|username=b].freeze
35
35
  }.freeze
36
36
  OPT_HATCH = {
37
- common: %w[color interactive no-color no-interactive cache-dir=p config=p data-dir=p e|env=b p|project=e
37
+ common: %w[color interactive no-color no-interactive cache-dir=p config=p data-dir=p e|env=b p|project=b
38
38
  q|quiet v|verbose].freeze,
39
39
  build: %w[clean-hooks-after ext hooks-only no-hooks c|clean t|target=b].freeze,
40
40
  publish: %w[initialize-auth n|no-prompt y|yes a|auth=q ca-cert=p client-cert=p client-key=p o|option=q
@@ -81,8 +81,8 @@ module Squared
81
81
  initialize_env(**kwargs)
82
82
  end
83
83
  @dependindex = DEP_PYTHON.index { |file| basepath(file).exist? }
84
- @dependfile = basepath(DEP_PYTHON[@dependindex || 0])
85
- @verbose = $1.size if verbose.is_a?(String) && verbose =~ /^(v+)$/
84
+ @dependfile = @path + DEP_PYTHON[@dependindex || 0]
85
+ @verbose = verbose.size if verbose.is_a?(String) && verbose.match?(/\Av+\z/)
86
86
  @editable = case editable
87
87
  when '.', Pathname
88
88
  editable
@@ -119,12 +119,12 @@ module Squared
119
119
  if flag == :create
120
120
  format_desc action, flag, 'dir,opts*'
121
121
  task flag, [:dir] do |_, args|
122
- dir = basepath(param_guard(action, flag, args: args, key: :dir))
122
+ dir = path + param_guard(action, flag, args: args, key: :dir)
123
123
  cmd, opts = python_session('-m venv', opts: args.extras)
124
124
  op = OptionPartition.new(opts, OPT_PYTHON[:venv], cmd, project: self)
125
125
  op.append(dir, delim: true)
126
126
  .clear(pass: false)
127
- v = op.arg?(/^-v+$/, 'verbose')
127
+ v = op.arg?(/\A-v+\z/, 'verbose')
128
128
  run(exception: true)
129
129
  puts(dir.directory? ? "Success: #{dir}" : 'Failed') unless v
130
130
  end
@@ -142,7 +142,8 @@ module Squared
142
142
  when :run
143
143
  format_desc action, flag, 'args+'
144
144
  task flag do |_, args|
145
- args = param_guard(action, flag, args: args.to_a)
145
+ args = args.to_a
146
+ args = readline('Enter command', force: true).split(' ', 2) if args.empty?
146
147
  venv_init
147
148
  run session(*args, path: false)
148
149
  end
@@ -170,12 +171,9 @@ module Squared
170
171
  end
171
172
  when 'install'
172
173
  format_desc(action, flag, 'opts*', before: case flag
173
- when :target
174
- 'dir'
175
- when :editable
176
- 'path/url?'
177
- when :upgrade
178
- 'strategy?,package+'
174
+ when :target then 'dir'
175
+ when :editable then 'path/url?'
176
+ when :upgrade then 'strategy?,package+'
179
177
  end)
180
178
  case flag
181
179
  when :editable
@@ -205,20 +203,16 @@ module Squared
205
203
  end
206
204
  when 'build'
207
205
  format_desc(action, flag, 'opts*', after: case flag
208
- when :python
209
- 'srcdir?'
210
- when :hatch
211
- 'location?'
206
+ when :python then 'srcdir?'
207
+ when :hatch then 'location?'
212
208
  end)
213
209
  task flag do |_, args|
214
210
  build! flag, args.to_a
215
211
  end
216
212
  when 'publish'
217
213
  format_desc(action, flag, 'opts*', after: case flag
218
- when :hatch
219
- 'artifacts?'
220
- when :twine
221
- 'dist?'
214
+ when :hatch then 'artifacts?'
215
+ when :twine then 'dist?'
222
216
  end)
223
217
  task flag do |_, args|
224
218
  publish flag, args.to_a
@@ -235,7 +229,7 @@ module Squared
235
229
  super
236
230
  elsif outdated?
237
231
  venv_init
238
- workspace.rev_clear(name)
232
+ workspace.rev_clear(name, sync: sync)
239
233
  if !flag && dependtype == 1
240
234
  cmd = poetry_session 'install', '-n'
241
235
  cmd << '--no-root' if option('no-root')
@@ -246,7 +240,7 @@ module Squared
246
240
  when :user
247
241
  cmd << '--user'
248
242
  when :target
249
- cmd << quote_option('target', basepath(target))
243
+ cmd << quote_option('target', path + target)
250
244
  when :force
251
245
  cmd << '--force-reinstall'
252
246
  end
@@ -264,10 +258,10 @@ module Squared
264
258
  def outdated(*, sync: invoked_sync?('outdated'))
265
259
  cmd = pip_session 'list', '--outdated'
266
260
  append_global
267
- cmd = session_done(cmd)
261
+ cmd = session_done cmd
268
262
  log.info cmd
269
263
  on :first, :outdated
270
- banner = format_banner(cmd)
264
+ banner = format_banner cmd
271
265
  print_item banner if sync
272
266
  start = 0
273
267
  found = 0
@@ -285,8 +279,8 @@ module Squared
285
279
 
286
280
  latest = lat.join
287
281
  current = cur.join
288
- semver(cur)
289
- semver(lat)
282
+ semver cur
283
+ semver lat
290
284
  if semmajor?(cur, lat)
291
285
  type = 2
292
286
  major += 1
@@ -378,7 +372,7 @@ module Squared
378
372
  if op.arg?('o', 'output')
379
373
  op.extras << srcdir
380
374
  else
381
- op << quote_option('output', basepath(srcdir))
375
+ op << quote_option('output', path + srcdir)
382
376
  end
383
377
  srcdir = nil
384
378
  end
@@ -390,7 +384,7 @@ module Squared
390
384
  end
391
385
  op << basic_option('p', project) unless ENV['HATCH_PROJECT'] || op.arg?('p', 'project')
392
386
  end
393
- op << shell_quote(basepath(srcdir)) if srcdir
387
+ op << shell_quote(path + srcdir) if srcdir
394
388
  op.clear
395
389
  run(from: :"#{flag}:build")
396
390
  end
@@ -409,7 +403,7 @@ module Squared
409
403
  end
410
404
  op = OptionPartition.new(opts, list, @session, project: self, single: singleopt(flag))
411
405
  if op.empty?
412
- dist = basepath.join('dist')
406
+ dist = path + 'dist'
413
407
  raise_error('no source files found', hint: dist) unless dist.directory? && !dist.empty?
414
408
  op.extras << "#{dist}/*" unless flag == :poetry
415
409
  end
@@ -468,7 +462,7 @@ module Squared
468
462
  def python_session(*cmd, opts: nil)
469
463
  return session('python', *preopts(quiet: false), *cmd, path: venv.nil?) unless opts
470
464
 
471
- op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: /^v+$/)
465
+ op = OptionPartition.new(opts, OPT_PYTHON[:common], project: self, single: /\Av+\z/)
472
466
  ret = session('python', *op.to_a, *cmd, path: venv.nil?)
473
467
  [ret, op.extras]
474
468
  end
@@ -476,7 +470,7 @@ module Squared
476
470
  def poetry_session(*cmd)
477
471
  ret = session('poetry', *cmd, *preopts)
478
472
  if (val = option('project', ignore: false))
479
- ret << quote_option('project', basepath(val))
473
+ ret << quote_option('project', path + val)
480
474
  end
481
475
  ret
482
476
  end
@@ -513,7 +507,7 @@ module Squared
513
507
  end
514
508
  op.swap
515
509
  if edit
516
- edit = basepath(edit) unless %r{^[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
510
+ edit = path + edit unless %r{^[a-z]+(?:\+[a-z]+)?://}i.match?(edit)
517
511
  if flag == :editable
518
512
  op.extras << edit
519
513
  else
@@ -541,7 +535,7 @@ module Squared
541
535
  when '0', 'false'
542
536
  return
543
537
  else
544
- val = basepath(val)
538
+ val = path + val
545
539
  end
546
540
  elsif session_arg?('e', 'editable', target: target) || !(val = editable)
547
541
  return
@@ -555,22 +549,22 @@ module Squared
555
549
  when '0', 'false'
556
550
  '--no-cache-dir'
557
551
  else
558
- quote_option('cache-dir', basepath(val))
552
+ quote_option('cache-dir', path + val)
559
553
  end
560
554
  end
561
555
  target << shell_option('proxy', val) if (val = option('proxy', target: target))
562
- target << quote_option('python', basepath(val)) if (val = option('python', target: target))
556
+ target << quote_option('python', path + val) if (val = option('python', target: target))
563
557
  append_nocolor(target: target)
564
558
  end
565
559
 
566
560
  def singleopt(flag = nil)
567
561
  case flag
568
562
  when :python
569
- /^(?:v+|q+|b+)$/
563
+ /\A(?:v+|q+|b+)\z/
570
564
  when :twine
571
565
  nil
572
566
  else
573
- /^(?:v+|q+)$/
567
+ /\A(?:v+|q+)\z/
574
568
  end
575
569
  end
576
570
 
@@ -605,7 +599,7 @@ module Squared
605
599
 
606
600
  def venv_set(val)
607
601
  @venv = Pathname.new(val)
608
- @venv = basepath(@venv) unless @venv.absolute?
602
+ @venv = @path + @venv unless @venv.absolute?
609
603
  if projectpath?(@venv)
610
604
  if @venv.exist?
611
605
  log.debug "venv found: #{@venv}"