@reventlessdev/reventless-spec 3.0.0-alpha.85 → 3.0.0-alpha.86

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 3.0.0-alpha.86 (2026-07-30)
7
+
8
+ ### Features
9
+
10
+ * **spec,local:** resolve capability manifests beyond the example topology ([8bfadd5](https://github.com/ReventlessDev/reventless-core/commit/8bfadd5beef90c0c9f6f6f3fbb753c8b789469ed))
11
+ * **spec:** semantic branded scalars — Email, Url, Phone, Percent, Color, Bytes, Duration ([2e64ff9](https://github.com/ReventlessDev/reventless-core/commit/2e64ff992e913c038a71659c731c25a104e3c5a9))
12
+
13
+
6
14
  # 3.0.0-alpha.85 (2026-07-30)
7
15
 
8
16
  ### Features
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reventlessdev/reventless-spec",
3
- "version": "3.0.0-alpha.85",
3
+ "version": "3.0.0-alpha.86",
4
4
  "description": "Specifications for Reventless",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -6,11 +6,10 @@
6
6
  // `PlatformCapabilities.res` (see PlatformCodegen). The platform root stays
7
7
  // hand-written and reads `PlatformCapabilities.capabilities`.
8
8
  //
9
- // A plugin path may be the composition package itself (its `src/` carries the
10
- // manifest) or an `-aws` deploy root that delegates to one. The delegation's
11
- // single existing record is the root's own `generate` script —
12
- // `generate-plugin --aws <Namespace> <srcDir>` — so the composition `src/` is
13
- // read from there rather than from a second, hand-typed spelling of the path.
9
+ // A deploy manifest enumerates *deployables*, not plugins, and a plugin's
10
+ // manifest can sit in any of three places. `PlatformManifests` owns both facts —
11
+ // its head comment states the resolution order and why each arm exists; add a
12
+ // fourth arm there, not here.
14
13
 
15
14
  @val external processExit: int => unit = "process.exit"
16
15
  @module("yaml") external parseYaml: string => JSON.t = "parse"
@@ -24,42 +23,6 @@ let asObject = (json: JSON.t): option<dict<JSON.t>> => json->JSON.Decode.object
24
23
  let stringAt = (obj: dict<JSON.t>, field: string): option<string> =>
25
24
  obj->Dict.get(field)->Option.flatMap(JSON.Decode.string)
26
25
 
27
- // Where a plugin keeps its capability manifest. The direct arm covers a plugin
28
- // path that is itself a composition package; the delegated arm follows the
29
- // `-aws` root's `generate-plugin --aws <Namespace> <srcDir>` script to the
30
- // composition `src/` it is generated from.
31
- let manifestPathFor = (~pluginDir: string): option<string> => {
32
- let direct = Generator_Node.join([pluginDir, "src", "capabilities.json"])
33
- if Generator_Node.existsSync(direct) {
34
- Some(direct)
35
- } else {
36
- let packageJsonPath = Generator_Node.join([pluginDir, "package.json"])
37
- if !Generator_Node.existsSync(packageJsonPath) {
38
- None
39
- } else {
40
- let generateScript =
41
- try Generator_Node.readFileSync(packageJsonPath)
42
- ->JSON.parseOrThrow
43
- ->asObject
44
- ->Option.flatMap(pkg => pkg->Dict.get("scripts"))
45
- ->Option.flatMap(asObject)
46
- ->Option.flatMap(scripts => scripts->stringAt("generate")) catch {
47
- | _ => None
48
- }
49
- generateScript
50
- ->Option.flatMap(script => {
51
- let tokens = script->String.split(" ")->Array.filter(t => t != "")
52
- switch tokens {
53
- | ["generate-plugin", "--aws", _namespace, srcDir] =>
54
- Some(Generator_Node.resolve([pluginDir, srcDir, "capabilities.json"]))
55
- | _ => None
56
- }
57
- })
58
- ->Option.filter(Generator_Node.existsSync)
59
- }
60
- }
61
- }
62
-
63
26
  let () = {
64
27
  let manifestArg = Generator_Node.argv->Array.get(2)->Option.getOr("")
65
28
  if manifestArg == "" {
@@ -104,27 +67,43 @@ let () = {
104
67
 
105
68
  switch (platformPath, plugins) {
106
69
  | (Some(platformPath), Some(plugins)) => {
107
- let pluginManifests = plugins->Array.map(((pluginName, pluginPath)) => {
70
+ let pluginManifests = plugins->Array.flatMap(((pluginName, pluginPath)) => {
108
71
  let pluginDir = Generator_Node.resolve([manifestDir, pluginPath])
109
- switch manifestPathFor(~pluginDir) {
110
- | None => {
72
+ if !Generator_Node.existsSync(pluginDir) {
73
+ fail(`plugin "${pluginName}" points at ${pluginDir}, which does not exist`)
74
+ }
75
+ switch PlatformManifests.resolve(~pluginDir) {
76
+ // A stack whose package graph holds no plugin composition — an
77
+ // SdkService, an SPA, a standalone Lambda — has no capabilities to
78
+ // contribute, which is not an error. Said out loud so a plugin
79
+ // skipped by mistake is visible in the generator's output.
80
+ | NotAPlugin => {
81
+ Console.log(`Skipped: ${pluginName} (${pluginDir}) — no plugin composition`)
82
+ []
83
+ }
84
+ | Unbuilt({evidence, expected}) => {
111
85
  fail(
112
86
  `no capabilities.json found for plugin "${pluginName}" (${pluginDir}) — ` ++
113
- `build the plugin first; its build emits src/capabilities.json beside Plugin.res`,
87
+ `build the plugin first; its build emits src/capabilities.json beside Plugin.res ` ++
88
+ `(${evidence}; expected ${expected})`,
114
89
  )
115
- ({pluginName, manifest: {capabilities: []}}: PlatformCodegen.pluginManifest)
90
+ []
116
91
  }
117
- | Some(capabilitiesPath) => {
118
- let manifest = try Generator_Node.readFileSync(capabilitiesPath)
92
+ | Manifests(manifests) =>
93
+ manifests->Array.map(({path, via}) => {
94
+ Console.log(
95
+ `Read: ${pluginName} — ${path} (via ${PlatformManifests.describeVia(via)})`,
96
+ )
97
+ let manifest = try Generator_Node.readFileSync(path)
119
98
  ->JSON.parseOrThrow
120
99
  ->S.parseOrThrow(CapabilityManifest.schema) catch {
121
100
  | _ => {
122
- fail(`could not parse ${capabilitiesPath} as a capability manifest`)
101
+ fail(`could not parse ${path} as a capability manifest`)
123
102
  ({capabilities: []}: CapabilityManifest.t)
124
103
  }
125
104
  }
126
105
  ({pluginName, manifest}: PlatformCodegen.pluginManifest)
127
- }
106
+ })
128
107
  }
129
108
  })
130
109
 
@@ -8,6 +8,7 @@ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
8
8
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
9
9
  import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
10
10
  import * as PlatformCodegen$Reventless from "./PlatformCodegen.res.mjs";
11
+ import * as PlatformManifests$Reventless from "./PlatformManifests.res.mjs";
11
12
  import * as CapabilityManifest$Reventless from "../components/CapabilityManifest.res.mjs";
12
13
 
13
14
  function fail(message) {
@@ -23,39 +24,6 @@ function stringAt(obj, field) {
23
24
  return Stdlib_Option.flatMap(obj[field], Stdlib_JSON.Decode.string);
24
25
  }
25
26
 
26
- function manifestPathFor(pluginDir) {
27
- let direct = Nodepath.join(pluginDir, "src", "capabilities.json");
28
- if (Nodefs.existsSync(direct)) {
29
- return direct;
30
- }
31
- let packageJsonPath = Nodepath.join(pluginDir, "package.json");
32
- if (!Nodefs.existsSync(packageJsonPath)) {
33
- return;
34
- }
35
- let generateScript;
36
- try {
37
- generateScript = Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(JSON.parse(Nodefs.readFileSync(packageJsonPath, "utf8"))), pkg => pkg["scripts"]), asObject), scripts => stringAt(scripts, "generate"));
38
- } catch (exn) {
39
- generateScript = undefined;
40
- }
41
- return Stdlib_Option.filter(Stdlib_Option.flatMap(generateScript, script => {
42
- let tokens = script.split(" ").filter(t => t !== "");
43
- if (tokens.length !== 4) {
44
- return;
45
- }
46
- let match = tokens[0];
47
- if (match !== "generate-plugin") {
48
- return;
49
- }
50
- let match$1 = tokens[1];
51
- if (match$1 !== "--aws") {
52
- return;
53
- }
54
- let srcDir = tokens[3];
55
- return Nodepath.resolve(pluginDir, srcDir, "capabilities.json");
56
- }), prim => Nodefs.existsSync(prim));
57
- }
58
-
59
27
  let manifestArg = Stdlib_Option.getOr(process.argv[2], "");
60
28
 
61
29
  if (manifestArg === "") {
@@ -88,32 +56,39 @@ if (manifestArg === "") {
88
56
  }));
89
57
  if (platformPath !== undefined) {
90
58
  if (plugins !== undefined) {
91
- let pluginManifests = plugins.map(param => {
59
+ let pluginManifests = plugins.flatMap(param => {
92
60
  let pluginName = param[0];
93
61
  let pluginDir = Nodepath.resolve(manifestDir, param[1]);
94
- let capabilitiesPath = manifestPathFor(pluginDir);
95
- if (capabilitiesPath !== undefined) {
96
- let manifest;
97
- try {
98
- manifest = S.parseOrThrow(JSON.parse(Nodefs.readFileSync(capabilitiesPath, "utf8")), CapabilityManifest$Reventless.schema);
99
- } catch (exn) {
100
- fail(`could not parse ` + capabilitiesPath + ` as a capability manifest`);
101
- manifest = {
102
- capabilities: []
62
+ if (!Nodefs.existsSync(pluginDir)) {
63
+ fail(`plugin "` + pluginName + `" points at ` + pluginDir + `, which does not exist`);
64
+ }
65
+ let manifests = PlatformManifests$Reventless.resolve(undefined, pluginDir);
66
+ if (typeof manifests !== "object") {
67
+ console.log(`Skipped: ` + pluginName + ` (` + pluginDir + `) — no plugin composition`);
68
+ return [];
69
+ }
70
+ if (manifests.TAG === "Manifests") {
71
+ return manifests._0.map(param => {
72
+ let path = param.path;
73
+ console.log(`Read: ` + pluginName + ` — ` + path + ` (via ` + PlatformManifests$Reventless.describeVia(param.via) + `)`);
74
+ let manifest;
75
+ try {
76
+ manifest = S.parseOrThrow(JSON.parse(Nodefs.readFileSync(path, "utf8")), CapabilityManifest$Reventless.schema);
77
+ } catch (exn) {
78
+ fail(`could not parse ` + path + ` as a capability manifest`);
79
+ manifest = {
80
+ capabilities: []
81
+ };
82
+ }
83
+ return {
84
+ pluginName: pluginName,
85
+ manifest: manifest
103
86
  };
104
- }
105
- return {
106
- pluginName: pluginName,
107
- manifest: manifest
108
- };
87
+ });
109
88
  }
110
- fail(`no capabilities.json found for plugin "` + pluginName + `" (` + pluginDir + `) — build the plugin first; its build emits src/capabilities.json beside Plugin.res`);
111
- return {
112
- pluginName: pluginName,
113
- manifest: {
114
- capabilities: []
115
- }
116
- };
89
+ let match = manifests._0;
90
+ fail(`no capabilities.json found for plugin "` + pluginName + `" (` + pluginDir + `) — build the plugin first; its build emits src/capabilities.json beside Plugin.res ` + (`(` + match.evidence + `; expected ` + match.expected + `)`));
91
+ return [];
117
92
  });
118
93
  let message = PlatformCodegen$Reventless.render(pluginManifests);
119
94
  if (message.TAG === "Ok") {
@@ -135,6 +110,5 @@ export {
135
110
  fail,
136
111
  asObject,
137
112
  stringAt,
138
- manifestPathFor,
139
113
  }
140
114
  /* manifestArg Not a pure module */
@@ -0,0 +1,203 @@
1
+ // Where a deploy-manifest entry's capability manifests live — and, when it
2
+ // contributes none, whether that is because the entry is not a plugin at all.
3
+ //
4
+ // A deploy manifest enumerates *deployables*, not plugins. An SdkService stack,
5
+ // a static SPA, a standalone ingester Lambda are all legitimate entries with no
6
+ // `pluginStructure` to derive capabilities from; contributing nothing is the
7
+ // right answer for those. A plugin whose manifest is merely unbuilt is the
8
+ // opposite case, and silently skipping it would deprovision the stores it
9
+ // declared. The two are told apart by evidence — something in the package graph
10
+ // that emits a capability manifest — never by falling through the arms below.
11
+ //
12
+ // Resolution order, first arm that yields manifests wins:
13
+ //
14
+ // 1. `<dir>/src/capabilities.json` — the entry is itself a composition
15
+ // package, so its manifest sits beside its composition root.
16
+ // 2. `<dir>`'s own `generate: generate-plugin --aws <Namespace> <srcDir>`
17
+ // script — an `-aws` root generated from a composition `src/` elsewhere in
18
+ // the same repo. The script is the single existing record of that
19
+ // delegation, so no second hand-typed spelling of the path is introduced.
20
+ // 3. `<dir>`'s dependencies — an `-aws` root that *installs* a published
21
+ // composition package, which is the shape the framework recommends and the
22
+ // one arms 1 and 2 both miss. Every plugin dependency contributes: a root
23
+ // deploying two plugins legitimately needs both manifests.
24
+ // 4. Nothing in the package graph emits a manifest — not a plugin stack.
25
+ //
26
+ // I/O goes through `fileSystem` so the arms are testable without a fixture
27
+ // tree; `nodeFileSystem` is what the generator passes.
28
+
29
+ /** How a manifest was found — reported so the resolving arm never has to be
30
+ reconstructed from the output. */
31
+ type via =
32
+ | Composition
33
+ | Generated(string)
34
+ | Dependency(string)
35
+
36
+ type manifest = {path: string, via: via}
37
+
38
+ /** Why the entry counted as a plugin, and where its manifest was looked for. */
39
+ type unbuilt = {evidence: string, expected: string}
40
+
41
+ type t =
42
+ | Manifests(array<manifest>)
43
+ /** Something here emits a capability manifest, but the manifest is not on
44
+ disk: a plugin that has not been built. */
45
+ | Unbuilt(unbuilt)
46
+ /** No plugin composition anywhere in the entry's package graph. */
47
+ | NotAPlugin
48
+
49
+ type fileSystem = {
50
+ exists: string => bool,
51
+ readJson: string => option<JSON.t>,
52
+ }
53
+
54
+ let nodeFileSystem: fileSystem = {
55
+ exists: Generator_Node.existsSync,
56
+ readJson: path =>
57
+ try Some(Generator_Node.readFileSync(path)->JSON.parseOrThrow) catch {
58
+ | _ => None
59
+ },
60
+ }
61
+
62
+ let describeVia = (via: via): string =>
63
+ switch via {
64
+ | Composition => "its own src/"
65
+ | Generated(srcDir) => `its \`generate\` script's ${srcDir}`
66
+ | Dependency(name) => `dependency ${name}`
67
+ }
68
+
69
+ let asObject = (json: JSON.t): option<dict<JSON.t>> => json->JSON.Decode.object
70
+
71
+ let packageJsonAt = (~fs: fileSystem, ~dir: string): option<dict<JSON.t>> =>
72
+ fs.readJson(Generator_Node.join([dir, "package.json"]))->Option.flatMap(asObject)
73
+
74
+ let scriptsOf = (pkg: dict<JSON.t>): array<string> =>
75
+ pkg
76
+ ->Dict.get("scripts")
77
+ ->Option.flatMap(asObject)
78
+ ->Option.mapOr([], scripts =>
79
+ scripts->Dict.valuesToArray->Array.filterMap(JSON.Decode.string)
80
+ )
81
+
82
+ // The composition `src/` an `-aws` root is generated from, read off the script
83
+ // that performs the generation.
84
+ let generatedSrcDir = (pkg: dict<JSON.t>): option<string> =>
85
+ pkg
86
+ ->Dict.get("scripts")
87
+ ->Option.flatMap(asObject)
88
+ ->Option.flatMap(scripts => scripts->Dict.get("generate"))
89
+ ->Option.flatMap(JSON.Decode.string)
90
+ ->Option.flatMap(script => {
91
+ let tokens = script->String.split(" ")->Array.filter(t => t != "")
92
+ switch tokens {
93
+ | ["generate-plugin", "--aws", _namespace, srcDir] => Some(srcDir)
94
+ | _ => None
95
+ }
96
+ })
97
+
98
+ // A package that runs `emit-capabilities` as part of its build is a plugin
99
+ // composition package, whether or not it has been built yet. That is the whole
100
+ // signal G1 needs: it is stated once, by the package that owns the fact, and it
101
+ // is already there in every plugin package — unlike a `kind:` on the deploy
102
+ // manifest, which would restate it a second time.
103
+ //
104
+ // `reventless-local` *provides* the bin under `bin`, and so is correctly not
105
+ // matched here.
106
+ let emitsCapabilities = (pkg: dict<JSON.t>): bool =>
107
+ pkg->scriptsOf->Array.some(script => script->String.includes("emit-capabilities"))
108
+
109
+ let dependencyNames = (pkg: dict<JSON.t>): array<string> => {
110
+ let seen = Dict.make()
111
+ ["dependencies", "devDependencies"]
112
+ ->Array.flatMap(field =>
113
+ pkg->Dict.get(field)->Option.flatMap(asObject)->Option.mapOr([], Dict.keysToArray)
114
+ )
115
+ ->Array.filter(name =>
116
+ switch seen->Dict.get(name) {
117
+ | Some(_) => false
118
+ | None => {
119
+ seen->Dict.set(name, true)
120
+ true
121
+ }
122
+ }
123
+ )
124
+ }
125
+
126
+ /** Node's directory resolution: `<dir>/node_modules/<name>`, then each parent's,
127
+ up to the filesystem root. Walking it rather than binding `require.resolve`
128
+ keeps the lookup on the package directory itself — a package's entry point
129
+ may be anywhere, and it is `src/capabilities.json` that is wanted. */
130
+ let resolvePackageDir = (~fs: fileSystem, ~fromDir: string, ~name: string): option<string> => {
131
+ let rec search = dir => {
132
+ let candidate = Generator_Node.join([dir, "node_modules", name])
133
+ if fs.exists(Generator_Node.join([candidate, "package.json"])) {
134
+ Some(candidate)
135
+ } else {
136
+ let parent = Generator_Node.dirname(dir)
137
+ parent == dir ? None : search(parent)
138
+ }
139
+ }
140
+ search(fromDir)
141
+ }
142
+
143
+ // Arm 3. Unbuilt wins over what was found: a root deploying two plugins needs
144
+ // both manifests, so one of them missing is a failure even though the other
145
+ // resolved.
146
+ let fromDependencies = (~fs: fileSystem, ~pluginDir: string, ~pkg: dict<JSON.t>): t => {
147
+ let found = []
148
+ let unbuilt = ref(None)
149
+ pkg
150
+ ->dependencyNames
151
+ ->Array.forEach(name =>
152
+ switch resolvePackageDir(~fs, ~fromDir=pluginDir, ~name) {
153
+ | None => ()
154
+ | Some(packageDir) => {
155
+ let candidate = Generator_Node.join([packageDir, "src", "capabilities.json"])
156
+ if fs.exists(candidate) {
157
+ found->Array.push({path: candidate, via: Dependency(name)})
158
+ } else if packageJsonAt(~fs, ~dir=packageDir)->Option.mapOr(false, emitsCapabilities) {
159
+ switch unbuilt.contents {
160
+ | Some(_) => ()
161
+ | None =>
162
+ unbuilt :=
163
+ Some({
164
+ evidence: `dependency ${name} emits a capability manifest`,
165
+ expected: candidate,
166
+ })
167
+ }
168
+ }
169
+ }
170
+ }
171
+ )
172
+ switch (unbuilt.contents, found) {
173
+ | (Some({evidence, expected}), _) => Unbuilt({evidence, expected})
174
+ | (None, []) => NotAPlugin
175
+ | (None, manifests) => Manifests(manifests)
176
+ }
177
+ }
178
+
179
+ let resolve = (~fs: fileSystem=nodeFileSystem, ~pluginDir: string): t => {
180
+ let direct = Generator_Node.join([pluginDir, "src", "capabilities.json"])
181
+ if fs.exists(direct) {
182
+ Manifests([{path: direct, via: Composition}])
183
+ } else {
184
+ switch packageJsonAt(~fs, ~dir=pluginDir) {
185
+ | None => NotAPlugin
186
+ | Some(pkg) =>
187
+ switch generatedSrcDir(pkg) {
188
+ | Some(srcDir) => {
189
+ let expected = Generator_Node.resolve([pluginDir, srcDir, "capabilities.json"])
190
+ if fs.exists(expected) {
191
+ Manifests([{path: expected, via: Generated(srcDir)}])
192
+ } else {
193
+ Unbuilt({
194
+ evidence: `its \`generate\` script composes ${srcDir}`,
195
+ expected,
196
+ })
197
+ }
198
+ }
199
+ | None => fromDependencies(~fs, ~pluginDir, ~pkg)
200
+ }
201
+ }
202
+ }
203
+ }
@@ -0,0 +1,212 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as Nodefs from "node:fs";
4
+ import * as Nodepath from "node:path";
5
+ import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
6
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
7
+ import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
8
+
9
+ function nodeFileSystem_exists(prim) {
10
+ return Nodefs.existsSync(prim);
11
+ }
12
+
13
+ function nodeFileSystem_readJson(path) {
14
+ try {
15
+ return JSON.parse(Nodefs.readFileSync(path, "utf8"));
16
+ } catch (exn) {
17
+ return;
18
+ }
19
+ }
20
+
21
+ let nodeFileSystem = {
22
+ exists: nodeFileSystem_exists,
23
+ readJson: nodeFileSystem_readJson
24
+ };
25
+
26
+ function describeVia(via) {
27
+ if (typeof via !== "object") {
28
+ return "its own src/";
29
+ } else if (via.TAG === "Generated") {
30
+ return `its \`generate\` script's ` + via._0;
31
+ } else {
32
+ return `dependency ` + via._0;
33
+ }
34
+ }
35
+
36
+ function asObject(json) {
37
+ return Stdlib_JSON.Decode.object(json);
38
+ }
39
+
40
+ function packageJsonAt(fs, dir) {
41
+ return Stdlib_Option.flatMap(fs.readJson(Nodepath.join(dir, "package.json")), asObject);
42
+ }
43
+
44
+ function scriptsOf(pkg) {
45
+ return Stdlib_Option.mapOr(Stdlib_Option.flatMap(pkg["scripts"], asObject), [], scripts => Stdlib_Array.filterMap(Object.values(scripts), Stdlib_JSON.Decode.string));
46
+ }
47
+
48
+ function generatedSrcDir(pkg) {
49
+ return Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(Stdlib_Option.flatMap(pkg["scripts"], asObject), scripts => scripts["generate"]), Stdlib_JSON.Decode.string), script => {
50
+ let tokens = script.split(" ").filter(t => t !== "");
51
+ if (tokens.length !== 4) {
52
+ return;
53
+ }
54
+ let match = tokens[0];
55
+ if (match !== "generate-plugin") {
56
+ return;
57
+ }
58
+ let match$1 = tokens[1];
59
+ if (match$1 === "--aws") {
60
+ return tokens[3];
61
+ }
62
+ });
63
+ }
64
+
65
+ function emitsCapabilities(pkg) {
66
+ return scriptsOf(pkg).some(script => script.includes("emit-capabilities"));
67
+ }
68
+
69
+ function dependencyNames(pkg) {
70
+ let seen = {};
71
+ return [
72
+ "dependencies",
73
+ "devDependencies"
74
+ ].flatMap(field => Stdlib_Option.mapOr(Stdlib_Option.flatMap(pkg[field], asObject), [], prim => Object.keys(prim))).filter(name => {
75
+ let match = seen[name];
76
+ if (match !== undefined) {
77
+ return false;
78
+ } else {
79
+ seen[name] = true;
80
+ return true;
81
+ }
82
+ });
83
+ }
84
+
85
+ function resolvePackageDir(fs, fromDir, name) {
86
+ let _dir = fromDir;
87
+ while (true) {
88
+ let dir = _dir;
89
+ let candidate = Nodepath.join(dir, "node_modules", name);
90
+ if (fs.exists(Nodepath.join(candidate, "package.json"))) {
91
+ return candidate;
92
+ }
93
+ let parent = Nodepath.dirname(dir);
94
+ if (parent === dir) {
95
+ return;
96
+ }
97
+ _dir = parent;
98
+ continue;
99
+ };
100
+ }
101
+
102
+ function fromDependencies(fs, pluginDir, pkg) {
103
+ let found = [];
104
+ let unbuilt = {
105
+ contents: undefined
106
+ };
107
+ dependencyNames(pkg).forEach(name => {
108
+ let packageDir = resolvePackageDir(fs, pluginDir, name);
109
+ if (packageDir === undefined) {
110
+ return;
111
+ }
112
+ let candidate = Nodepath.join(packageDir, "src", "capabilities.json");
113
+ if (fs.exists(candidate)) {
114
+ found.push({
115
+ path: candidate,
116
+ via: {
117
+ TAG: "Dependency",
118
+ _0: name
119
+ }
120
+ });
121
+ return;
122
+ }
123
+ if (!Stdlib_Option.mapOr(packageJsonAt(fs, packageDir), false, emitsCapabilities)) {
124
+ return;
125
+ }
126
+ let match = unbuilt.contents;
127
+ if (match !== undefined) {
128
+ return;
129
+ } else {
130
+ unbuilt.contents = {
131
+ evidence: `dependency ` + name + ` emits a capability manifest`,
132
+ expected: candidate
133
+ };
134
+ return;
135
+ }
136
+ });
137
+ let match = unbuilt.contents;
138
+ if (match !== undefined) {
139
+ return {
140
+ TAG: "Unbuilt",
141
+ _0: {
142
+ evidence: match.evidence,
143
+ expected: match.expected
144
+ }
145
+ };
146
+ } else if (found.length !== 0) {
147
+ return {
148
+ TAG: "Manifests",
149
+ _0: found
150
+ };
151
+ } else {
152
+ return "NotAPlugin";
153
+ }
154
+ }
155
+
156
+ function resolve(fsOpt, pluginDir) {
157
+ let fs = fsOpt !== undefined ? fsOpt : nodeFileSystem;
158
+ let direct = Nodepath.join(pluginDir, "src", "capabilities.json");
159
+ if (fs.exists(direct)) {
160
+ return {
161
+ TAG: "Manifests",
162
+ _0: [{
163
+ path: direct,
164
+ via: "Composition"
165
+ }]
166
+ };
167
+ }
168
+ let pkg = packageJsonAt(fs, pluginDir);
169
+ if (pkg === undefined) {
170
+ return "NotAPlugin";
171
+ }
172
+ let srcDir = generatedSrcDir(pkg);
173
+ if (srcDir === undefined) {
174
+ return fromDependencies(fs, pluginDir, pkg);
175
+ }
176
+ let expected = Nodepath.resolve(pluginDir, srcDir, "capabilities.json");
177
+ if (fs.exists(expected)) {
178
+ return {
179
+ TAG: "Manifests",
180
+ _0: [{
181
+ path: expected,
182
+ via: {
183
+ TAG: "Generated",
184
+ _0: srcDir
185
+ }
186
+ }]
187
+ };
188
+ } else {
189
+ return {
190
+ TAG: "Unbuilt",
191
+ _0: {
192
+ evidence: `its \`generate\` script composes ` + srcDir,
193
+ expected: expected
194
+ }
195
+ };
196
+ }
197
+ }
198
+
199
+ export {
200
+ nodeFileSystem,
201
+ describeVia,
202
+ asObject,
203
+ packageJsonAt,
204
+ scriptsOf,
205
+ generatedSrcDir,
206
+ emitsCapabilities,
207
+ dependencyNames,
208
+ resolvePackageDir,
209
+ fromDependencies,
210
+ resolve,
211
+ }
212
+ /* node:fs Not a pure module */