@biffo/cli 0.148.1 → 0.149.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.
- package/dist/index.js +58 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -350,10 +350,11 @@ var coreDiffCommand = new Command("diff").description(
|
|
|
350
350
|
).option("--cwd <path>", "Instance repo root to inspect (defaults to the current directory)").option(
|
|
351
351
|
"--template <path>",
|
|
352
352
|
"Path to a biffo-template checkout to compare against (defaults to the template this CLI ships with)"
|
|
353
|
-
).action(async (options) => {
|
|
353
|
+
).option("--json", "Emit the classification as JSON on stdout instead of the human report").action(async (options) => {
|
|
354
354
|
const cwd = options.cwd ? resolve(options.cwd) : process.cwd();
|
|
355
355
|
const runOptions = { cwd };
|
|
356
356
|
if (options.template) runOptions.templateRoot = resolve(options.template);
|
|
357
|
+
if (options.json) runOptions.json = true;
|
|
357
358
|
try {
|
|
358
359
|
await runCoreDiff(runOptions);
|
|
359
360
|
} catch (err) {
|
|
@@ -368,6 +369,20 @@ async function runCoreDiff(options) {
|
|
|
368
369
|
const instanceVersion = readInstanceCoreVersion(options.cwd);
|
|
369
370
|
const diff = computeCoreDiff(templateRoot, options.cwd, manifest);
|
|
370
371
|
const total = diff.added.length + diff.removed.length + diff.modified.length;
|
|
372
|
+
if (options.json) {
|
|
373
|
+
const payload = {
|
|
374
|
+
schemaVersion: 1,
|
|
375
|
+
instanceCore: instanceVersion ?? null,
|
|
376
|
+
templateCore: templateVersion,
|
|
377
|
+
modified: diff.modified,
|
|
378
|
+
added: diff.added,
|
|
379
|
+
removed: diff.removed,
|
|
380
|
+
instanceOnly: diff.instanceOnly,
|
|
381
|
+
unchanged: diff.unchanged
|
|
382
|
+
};
|
|
383
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
371
386
|
console.log(chalk2.bold("\n Biffo core diff\n"));
|
|
372
387
|
console.log(` instance core: ${instanceVersion ?? chalk2.dim("(unrecorded)")}`);
|
|
373
388
|
console.log(` template core: ${templateVersion}
|
|
@@ -2028,6 +2043,13 @@ function standardArguments(pluginName, handler) {
|
|
|
2028
2043
|
["event_bus_name", "module.events.event_bus_name"],
|
|
2029
2044
|
["core_api_url", "module.api_gateway.api_endpoint"],
|
|
2030
2045
|
["core_api_execution_arn", "module.api_gateway.execution_arn"],
|
|
2046
|
+
// ADR-0021: a user-facing plugin has no Lambda of its own — its module
|
|
2047
|
+
// provisions a frontend S3 origin and REQUIRES the parent distribution's
|
|
2048
|
+
// ARN, with no default. Without this the generated block cannot plan at
|
|
2049
|
+
// all ("No value for required variable"), which is what made #685 break
|
|
2050
|
+
// `terraform plan` for a whole environment. Filtered by declaration below,
|
|
2051
|
+
// so a Lambda-backed legacy module that does not declare it is unaffected.
|
|
2052
|
+
["cdn_distribution_arn", "module.cdn.distribution_arn"],
|
|
2031
2053
|
["tags", "local.tags"]
|
|
2032
2054
|
];
|
|
2033
2055
|
}
|
|
@@ -2113,13 +2135,43 @@ function declaredVariables(moduleDir) {
|
|
|
2113
2135
|
}
|
|
2114
2136
|
return names;
|
|
2115
2137
|
}
|
|
2138
|
+
function declaredOutputs(moduleDir) {
|
|
2139
|
+
const names = /* @__PURE__ */ new Set();
|
|
2140
|
+
let entries;
|
|
2141
|
+
try {
|
|
2142
|
+
entries = readdirSync3(moduleDir, { withFileTypes: true });
|
|
2143
|
+
} catch {
|
|
2144
|
+
return names;
|
|
2145
|
+
}
|
|
2146
|
+
for (const entry of entries) {
|
|
2147
|
+
if (!entry.isFile() || !entry.name.endsWith(".tf")) continue;
|
|
2148
|
+
let contents;
|
|
2149
|
+
try {
|
|
2150
|
+
contents = readFileSync7(join10(moduleDir, entry.name), "utf8");
|
|
2151
|
+
} catch {
|
|
2152
|
+
continue;
|
|
2153
|
+
}
|
|
2154
|
+
for (const match of contents.matchAll(/^\s*output\s+"([^"]+)"/gm)) {
|
|
2155
|
+
names.add(match[1]);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
return names;
|
|
2159
|
+
}
|
|
2116
2160
|
function renderArguments(args, indent) {
|
|
2117
2161
|
const width = Math.max(...args.map(([key]) => key.length));
|
|
2118
2162
|
return args.map(([key, value]) => `${indent}${key.padEnd(width)} = ${value}`).join("\n");
|
|
2119
2163
|
}
|
|
2120
|
-
function renderModuleBlock(pluginName, declared, handler, source) {
|
|
2164
|
+
function renderModuleBlock(pluginName, declared, handler, source, outputs) {
|
|
2121
2165
|
const args = standardArguments(pluginName, handler).filter(([key]) => declared.has(key));
|
|
2122
2166
|
const quoted = JSON.stringify(pluginName);
|
|
2167
|
+
const exported = [...outputs].sort().map(
|
|
2168
|
+
(name) => [
|
|
2169
|
+
`output "plugin_${pluginName}_${name}" {`,
|
|
2170
|
+
` description = "${name} of the ${pluginName} plugin, or null when it is not in enabled_plugins."`,
|
|
2171
|
+
` value = try(module.plugin_${pluginName}[${quoted}].${name}, null)`,
|
|
2172
|
+
"}"
|
|
2173
|
+
].join("\n")
|
|
2174
|
+
);
|
|
2123
2175
|
const lines = [
|
|
2124
2176
|
`module "plugin_${pluginName}" {`,
|
|
2125
2177
|
` source = "${source}"`,
|
|
@@ -2127,11 +2179,7 @@ function renderModuleBlock(pluginName, declared, handler, source) {
|
|
|
2127
2179
|
"",
|
|
2128
2180
|
renderArguments(args, " "),
|
|
2129
2181
|
"}",
|
|
2130
|
-
"",
|
|
2131
|
-
`output "plugin_${pluginName}_function_arn" {`,
|
|
2132
|
-
` description = "Lambda ARN of the ${pluginName} plugin, or null when it is not in enabled_plugins."`,
|
|
2133
|
-
` value = try(module.plugin_${pluginName}[${quoted}].function_arn, null)`,
|
|
2134
|
-
"}"
|
|
2182
|
+
...exported.length > 0 ? ["", exported.join("\n\n")] : []
|
|
2135
2183
|
];
|
|
2136
2184
|
return lines.join("\n");
|
|
2137
2185
|
}
|
|
@@ -2163,7 +2211,8 @@ function renderGeneratedTerraform(plugins) {
|
|
|
2163
2211
|
p.name,
|
|
2164
2212
|
p.declaredVariables,
|
|
2165
2213
|
p.handler ?? DEFAULT_PLUGIN_HANDLER,
|
|
2166
|
-
p.source ?? THIRD_PARTY_TERRAFORM(p.name)
|
|
2214
|
+
p.source ?? THIRD_PARTY_TERRAFORM(p.name),
|
|
2215
|
+
p.declaredOutputs ?? /* @__PURE__ */ new Set()
|
|
2167
2216
|
)
|
|
2168
2217
|
);
|
|
2169
2218
|
return `${GENERATED_HEADER}
|
|
@@ -2184,6 +2233,7 @@ function syncPluginTerraform(cwd) {
|
|
|
2184
2233
|
return {
|
|
2185
2234
|
name,
|
|
2186
2235
|
declaredVariables: declaredVariables(moduleDir),
|
|
2236
|
+
declaredOutputs: declaredOutputs(moduleDir),
|
|
2187
2237
|
source: pluginModuleSource(cwd, name)
|
|
2188
2238
|
};
|
|
2189
2239
|
});
|