skyward-core 0.2.0 → 0.3.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/README.md +5 -3
- data/lib/skyward/core/cli/executable.rb +24 -0
- data/lib/skyward/core/signatures/inline.rb +77 -0
- data/lib/skyward/core/version.rb +1 -1
- data/sig/generated/skyward/core/cli/executable.rbs +15 -0
- data/sig/generated/skyward/core/signatures/inline.rbs +38 -0
- data/sig/manual/skyward/core/cli/executable.rbs +3 -0
- data/sig/manual/skyward/core/signatures/inline.rbs +3 -0
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 707a5a84c350a7f1277035bfa2f2671a7c8297f5bf620b5c8a34b5d4167a3005
|
|
4
|
+
data.tar.gz: 42857fbc309d41e5dcf1d68be4962766f6022cd8f1429d41e46d763ce05eae58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a4416139d3ffbd9649cc53e7a6040f865c61af299364b81739662e8356bfdd9fbebbb95cc9a76410d10973046c38eb30afb8047d153959626ddabc49c29839e4
|
|
7
|
+
data.tar.gz: e4005e6ceccb54ba121a36c526fe653a866c2129d006f28fcf18ad13109e4ed8e4ba2a377a5d6ddd6f19a1d91b63ca25f8abcb0b979e199d1fc8dbbae30550c1
|
data/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Skyward Core
|
|
2
2
|
|
|
3
3
|
> [!CAUTION]
|
|
4
|
-
>
|
|
4
|
+
> Skyward is pre-1.0. Everything this README describes is built, as [Status](#status) lists, but parts of the [Skyward API](../skyward-api/README.md#status) and [Skyward ORM](../skyward-orm/README.md#status) specs aren't yet. Any release may change the API, so don't run it in production yet.
|
|
5
5
|
|
|
6
6
|
The plumbing that [Skyward API](../skyward-api/README.md) and [Skyward ORM](../skyward-orm/README.md) share. You don't add it to your Gemfile: each of them depends on it, at exactly the same version.
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@ The plumbing that [Skyward API](../skyward-api/README.md) and [Skyward ORM](../s
|
|
|
10
10
|
- **The `Skyward` namespace.** Skyward Core opens it, and every Skyward gem's Zeitwerk loader extends it. Each gem's names live in that gem's own namespace there: `Skyward::Core`, `Skyward::API` and `Skyward::ORM`.
|
|
11
11
|
- **The `skyward` command.** It comes with Skyward Core, so it's there whichever Skyward gems you install. Each gem adds its own commands to it.
|
|
12
12
|
- **Loading RBS signatures.** One loader finds your app's signatures and those of the gems it uses, for every Skyward gem.
|
|
13
|
+
- **Keeping `sig/generated` current.** One function regenerates your app's `sig/generated` from its Ruby with rbs-inline, and the Skyward commands that read types call it first, so you never run rbs-inline by hand. `skyward check` only checks it's current, for CI.
|
|
13
14
|
- **Reading RBS types.** One reader turns a signature into values that Skyward API and Skyward ORM each build their own mappings on, so a `Todo` read from the database and a `Todo` sent as JSON are the same thing.
|
|
14
15
|
- **`Skyward::Core::BootError`**, which every Skyward gem raises when your app can't boot, saying why.
|
|
15
16
|
|
|
@@ -31,9 +32,10 @@ Skyward supports every Ruby that isn't end-of-life (3.3 and later, as of Novembe
|
|
|
31
32
|
|
|
32
33
|
## Status
|
|
33
34
|
|
|
34
|
-
This README is the spec
|
|
35
|
+
This README is the spec, and this section lists each part of it that's built, as it lands. The gem opens the `Skyward` namespace and sets up its loader.
|
|
35
36
|
|
|
36
|
-
- **The `skyward` command.** The executable loads each installed gem's `commands.rb`, `Skyward::Core::CLI.register` adds a command, and `skyward` lists them and runs one, as [Adding commands](#adding-commands) describes.
|
|
37
|
+
- **The `skyward` command.** The executable loads each installed gem's `commands.rb`, `Skyward::Core::CLI.register` adds a command, and `skyward` lists them and runs one, as [Adding commands](#adding-commands) describes. For the commands to run other gems' executables, `Skyward::Core::CLI::Executable.find(name, feature: name)` returns the path of gem `name`'s executable `name` when `feature` can be required in the bundle `skyward` runs in, or `nil` otherwise, and `Skyward::Core::CLI::Executable::CAPTURE` runs a command with an environment in a directory and returns its output, errors included, and whether it succeeded.
|
|
37
38
|
- **Loading RBS signatures.** `Skyward::Core::Signatures.load(directory)` returns an `RBS::DefinitionBuilder` over every `.rbs` file under `directory`, the `sig/` of each Skyward gem that has registered it with `Skyward::Core::Signatures.register(path)`, and the `date` and `time` libraries. Skyward Core registers its own. A directory that doesn't exist contributes nothing. A file that doesn't parse, a name declared twice, or a class whose declarations disagree on its type parameters raises `Skyward::Core::BootError` naming the file and line.
|
|
39
|
+
- **Keeping `sig/generated` current.** `Skyward::Core::Signatures::Inline.generate(directory, rbs_inline:, capture:)` runs the rbs-inline executable at `rbs_inline` through `capture`, in `directory` and in its default opt-in mode, which reads only files marked `# rbs_inline: enabled`, over every `.rb` file there outside `test/`, `spec/`, `vendor/`, `tmp/` and hidden directories, into a scratch directory, as `skyward check` does. It then writes each file whose content differs to `directory`'s `sig/generated`, leaving the others untouched, removes each file there that rbs-inline no longer generates, and any directory that leaves empty, and returns `nil`. When rbs-inline fails, it changes nothing and returns a message with rbs-inline's output, for the command to report. With no `rbs_inline`, as in a bundle without rbs-inline, it runs nothing and returns `nil`, so the app runs with `sig/generated` as committed.
|
|
38
40
|
- **Reading RBS types.** `Skyward::Core::Types::Reader.new(builder)` takes the `RBS::DefinitionBuilder` that `Skyward::Core::Signatures.load` returns, and `read(type)` turns an RBS type into a frozen `Data` value from `Skyward::Core::Types`: a `Scalar` (`:integer`, `:float`, `:string`, `:bool`, `:date`, `:time` or `:untyped`), a `Literal` (a String, Integer, boolean or `nil`), an `Enum` of Symbols, a `Nullable`, an `ArrayOf`, a `HashOf` (a `Hash[String, T]`, of its values' type), a `Record` or `Named` class with `Field`s (a name, a type and whether it's required), or a `Union`. It expands aliases, generic ones included, reads `T?` and `T | nil` as `Nullable` and a union of symbol literals as one `Enum`, and flattens nested unions, dropping duplicates. A class is `Named` when its RBS declares public instance `attr_reader`s, rbs-inline's `Data.define` output included: its fields come from its own declarations, in written order, across every file that reopens it, skipping `private` sections. A type it can't read, such as an interface, a tuple, a proc, a `Hash` whose keys aren't `String`s or a class with no readers, comes back as an `Unreadable` naming the type, the class and reader it was found at (`Todo#tags`) and what to use instead, for the caller to raise `Skyward::Core::BootError` with its own context. A class with no loaded Ruby class, or a type that refers to itself, raises `Skyward::Core::BootError`. `type_name(klass)` finds a Ruby class's RBS declaration (none for an anonymous class), and `method_type(type_name, method)` a method's signature, raising `Skyward::Core::BootError` when RBS can't build the class.
|
|
39
41
|
- **`Skyward::Core::BootError`**, for any Skyward gem to raise when an app can't boot.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::CLI::Executable
|
|
4
|
+
extend self
|
|
5
|
+
|
|
6
|
+
# @rbs! type capture = ^(Hash[String, String] env, Array[String] command, String chdir) -> [String, bool]
|
|
7
|
+
|
|
8
|
+
CAPTURE = lambda do |env, command, chdir|
|
|
9
|
+
# RBS doesn't list the [:child, :out] spelling of this redirect.
|
|
10
|
+
output = IO.popen(env, command, chdir:, err: [:child, 1], &:read)
|
|
11
|
+
# RBS doesn't declare Process.last_status, set by the popen above.
|
|
12
|
+
[output, Process.last_status.success?] # steep:ignore NoMethod
|
|
13
|
+
end #: capture
|
|
14
|
+
|
|
15
|
+
# Under Bundler, Gem.find_files and Gem.bin_path see only the bundle's gems,
|
|
16
|
+
# so a gem installed outside the app's bundle isn't found. Checking first
|
|
17
|
+
# spares rescuing the error bin_path raises for a missing gem.
|
|
18
|
+
# @rbs name: String
|
|
19
|
+
# @rbs feature: String
|
|
20
|
+
# @rbs return: String?
|
|
21
|
+
def find(name, feature: name)
|
|
22
|
+
Gem.bin_path(name, name) unless Gem.find_files("#{feature}.rb").empty?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "fileutils"
|
|
4
|
+
require "tmpdir"
|
|
5
|
+
|
|
6
|
+
module Skyward::Core::Signatures::Inline
|
|
7
|
+
extend self
|
|
8
|
+
|
|
9
|
+
OUTPUT = "sig/generated" #: String
|
|
10
|
+
|
|
11
|
+
# None holds the app's contract: its tests, its installed gems and scratch.
|
|
12
|
+
UNCHECKED = %w[test spec vendor tmp].freeze #: Array[String]
|
|
13
|
+
|
|
14
|
+
# rbs-inline writes to scratch, so a file it no longer generates can be
|
|
15
|
+
# removed, and only a file whose content changed is written: skyward serve
|
|
16
|
+
# reloads on every .rbs file written.
|
|
17
|
+
# @rbs directory: String
|
|
18
|
+
# @rbs rbs_inline: String?
|
|
19
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
20
|
+
# @rbs return: String?
|
|
21
|
+
def generate(directory, rbs_inline:, capture:)
|
|
22
|
+
return unless rbs_inline
|
|
23
|
+
|
|
24
|
+
files = run(directory, rbs_inline:, capture:)
|
|
25
|
+
case files
|
|
26
|
+
when String then "rbs-inline couldn't regenerate #{OUTPUT}:\n#{files}"
|
|
27
|
+
else
|
|
28
|
+
write(File.join(directory, OUTPUT), files)
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @rbs directory: String
|
|
34
|
+
# @rbs rbs_inline: String
|
|
35
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
36
|
+
# @rbs return: Hash[String, String] | String
|
|
37
|
+
def run(directory, rbs_inline:, capture:)
|
|
38
|
+
Dir.mktmpdir("skyward-signatures") do |output|
|
|
39
|
+
log, ok = capture.call({}, [Gem.ruby, rbs_inline, "--output=#{output}", *sources(directory)], directory)
|
|
40
|
+
ok ? rbs_files(output) : log
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @rbs directory: String
|
|
45
|
+
# @rbs return: Array[String]
|
|
46
|
+
def sources(directory)
|
|
47
|
+
roots = Dir.glob("*/", base: directory).map { |root| root.delete_suffix("/") } - UNCHECKED
|
|
48
|
+
files = Dir.glob("*.rb", base: directory)
|
|
49
|
+
[*files, *roots.reject { |root| Dir.glob("#{root}/**/*.rb", base: directory).empty? }].sort
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @rbs directory: String
|
|
53
|
+
# @rbs return: Hash[String, String]
|
|
54
|
+
def rbs_files(directory)
|
|
55
|
+
Dir.glob("**/*.rbs", base: directory).to_h { |file| [file, File.read(File.join(directory, file))] }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# @rbs generated: String
|
|
61
|
+
# @rbs files: Hash[String, String]
|
|
62
|
+
# @rbs return: void
|
|
63
|
+
def write(generated, files)
|
|
64
|
+
current = rbs_files(generated)
|
|
65
|
+
files.reject { |file, source| current[file] == source }.each do |file, source|
|
|
66
|
+
path = File.join(generated, file)
|
|
67
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
68
|
+
File.write(path, source)
|
|
69
|
+
end
|
|
70
|
+
(current.keys - files.keys).each { |file| File.delete(File.join(generated, file)) }
|
|
71
|
+
# Deepest first, so a directory emptied of directories goes too.
|
|
72
|
+
Dir.glob("**/*/", base: generated).sort.reverse_each do |dir|
|
|
73
|
+
path = File.join(generated, dir)
|
|
74
|
+
Dir.rmdir(path) if Dir.empty?(path)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
data/lib/skyward/core/version.rb
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/cli/executable.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::CLI::Executable
|
|
4
|
+
type capture = ^(Hash[String, String] env, Array[String] command, String chdir) -> [ String, bool ]
|
|
5
|
+
|
|
6
|
+
CAPTURE: capture
|
|
7
|
+
|
|
8
|
+
# Under Bundler, Gem.find_files and Gem.bin_path see only the bundle's gems,
|
|
9
|
+
# so a gem installed outside the app's bundle isn't found. Checking first
|
|
10
|
+
# spares rescuing the error bin_path raises for a missing gem.
|
|
11
|
+
# @rbs name: String
|
|
12
|
+
# @rbs feature: String
|
|
13
|
+
# @rbs return: String?
|
|
14
|
+
def find: (String name, ?feature: String) -> String?
|
|
15
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Generated from lib/skyward/core/signatures/inline.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Skyward::Core::Signatures::Inline
|
|
4
|
+
OUTPUT: String
|
|
5
|
+
|
|
6
|
+
# None holds the app's contract: its tests, its installed gems and scratch.
|
|
7
|
+
UNCHECKED: Array[String]
|
|
8
|
+
|
|
9
|
+
# rbs-inline writes to scratch, so a file it no longer generates can be
|
|
10
|
+
# removed, and only a file whose content changed is written: skyward serve
|
|
11
|
+
# reloads on every .rbs file written.
|
|
12
|
+
# @rbs directory: String
|
|
13
|
+
# @rbs rbs_inline: String?
|
|
14
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
15
|
+
# @rbs return: String?
|
|
16
|
+
def generate: (String directory, rbs_inline: String?, capture: Skyward::Core::CLI::Executable::capture) -> String?
|
|
17
|
+
|
|
18
|
+
# @rbs directory: String
|
|
19
|
+
# @rbs rbs_inline: String
|
|
20
|
+
# @rbs capture: Skyward::Core::CLI::Executable::capture
|
|
21
|
+
# @rbs return: Hash[String, String] | String
|
|
22
|
+
def run: (String directory, rbs_inline: String, capture: Skyward::Core::CLI::Executable::capture) -> (Hash[String, String] | String)
|
|
23
|
+
|
|
24
|
+
# @rbs directory: String
|
|
25
|
+
# @rbs return: Array[String]
|
|
26
|
+
def sources: (String directory) -> Array[String]
|
|
27
|
+
|
|
28
|
+
# @rbs directory: String
|
|
29
|
+
# @rbs return: Hash[String, String]
|
|
30
|
+
def rbs_files: (String directory) -> Hash[String, String]
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
# @rbs generated: String
|
|
35
|
+
# @rbs files: Hash[String, String]
|
|
36
|
+
# @rbs return: void
|
|
37
|
+
def write: (String generated, Hash[String, String] files) -> void
|
|
38
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: skyward-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jake Bottrall
|
|
@@ -49,8 +49,10 @@ files:
|
|
|
49
49
|
- lib/skyward/core.rb
|
|
50
50
|
- lib/skyward/core/boot_error.rb
|
|
51
51
|
- lib/skyward/core/cli.rb
|
|
52
|
+
- lib/skyward/core/cli/executable.rb
|
|
52
53
|
- lib/skyward/core/cli/registry.rb
|
|
53
54
|
- lib/skyward/core/signatures.rb
|
|
55
|
+
- lib/skyward/core/signatures/inline.rb
|
|
54
56
|
- lib/skyward/core/signatures/loader.rb
|
|
55
57
|
- lib/skyward/core/types.rb
|
|
56
58
|
- lib/skyward/core/types/reader.rb
|
|
@@ -58,14 +60,18 @@ files:
|
|
|
58
60
|
- sig/generated/skyward/core.rbs
|
|
59
61
|
- sig/generated/skyward/core/boot_error.rbs
|
|
60
62
|
- sig/generated/skyward/core/cli.rbs
|
|
63
|
+
- sig/generated/skyward/core/cli/executable.rbs
|
|
61
64
|
- sig/generated/skyward/core/cli/registry.rbs
|
|
62
65
|
- sig/generated/skyward/core/signatures.rbs
|
|
66
|
+
- sig/generated/skyward/core/signatures/inline.rbs
|
|
63
67
|
- sig/generated/skyward/core/signatures/loader.rbs
|
|
64
68
|
- sig/generated/skyward/core/types.rbs
|
|
65
69
|
- sig/generated/skyward/core/types/reader.rbs
|
|
66
70
|
- sig/generated/skyward/core/version.rbs
|
|
67
71
|
- sig/manual/skyward/core/cli.rbs
|
|
72
|
+
- sig/manual/skyward/core/cli/executable.rbs
|
|
68
73
|
- sig/manual/skyward/core/signatures.rbs
|
|
74
|
+
- sig/manual/skyward/core/signatures/inline.rbs
|
|
69
75
|
homepage: https://github.com/bottrall/skyward
|
|
70
76
|
licenses:
|
|
71
77
|
- MIT
|