Skip to content

Commit bfd92ef

Browse files
authored
Include parent component (#5)
Signed-off-by: Prabhu Subramanian <prabhu@appthreat.com>
1 parent af4ebe8 commit bfd92ef

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@appthreat/caxa",
3-
"version": "2.0.8",
3+
"version": "2.0.9",
44
"description": "Package Node.js applications into executable binaries",
55
"author": "Team AppThreat <cloud@appthreat.com>",
66
"homepage": "https://github.com/appthreat/caxa",

source/index.mts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ export default async function caxa({
187187
input,
188188
output,
189189
command,
190+
metadataFile = "binary-metadata.json",
190191
force = true,
191192
exclude = defaultExcludes,
192193
includeNode = true,
@@ -207,6 +208,7 @@ export default async function caxa({
207208
input: string;
208209
output: string;
209210
command: string[];
211+
metadataFile: string;
210212
force?: boolean;
211213
exclude?: string[];
212214
filter?: fs.CopyFilterSync | fs.CopyFilterAsync;
@@ -240,16 +242,26 @@ export default async function caxa({
240242
interface Component {
241243
group: string;
242244
name: string;
245+
description: string;
246+
license: string;
243247
version: string;
244248
purl: string;
249+
author: string;
245250
_rawDeps?: Record<string, string>;
246251
}
247252

248253
interface DependencyGraphEntry {
249254
ref: string;
250255
dependsOn: string[];
251256
}
252-
257+
const parentName = path.basename(output).replace(path.extname(output), "");
258+
const parentComponent = {
259+
group: "",
260+
name: parentName,
261+
version: undefined,
262+
purl: `pkg:generic/${parentName}`,
263+
"bom-ref": `pkg:generic/${parentName}`,
264+
};
253265
const components: Component[] = [];
254266
const purlLookup = new Map<string, string>();
255267
if (includeNode) {
@@ -274,14 +286,22 @@ export default async function caxa({
274286
purl += `${encodeURIComponent(namespace)}/`;
275287
}
276288
purl += `${name}@${pkg.version}`;
277-
278289
purlLookup.set(pkg.name, purl);
279-
290+
const author = pkg.author;
291+
const authorString =
292+
author instanceof Object
293+
? `${author.name}${author.email ? ` <${author.email}>` : ""}${
294+
author.url ? ` (${author.url})` : ""
295+
}`
296+
: author;
280297
components.push({
281298
group: namespace,
282299
name: name,
300+
description: pkg.description,
301+
license: pkg.license,
283302
version: pkg.version,
284303
purl: purl,
304+
author: authorString,
285305
_rawDeps: pkg.dependencies,
286306
});
287307
}
@@ -304,18 +324,17 @@ export default async function caxa({
304324
}
305325
delete comp._rawDeps;
306326
}
307-
308327
if (childPurls.length > 0) {
309328
dependencies.push({
310329
ref: comp.purl,
311330
dependsOn: childPurls,
312331
});
313332
}
314333
}
315-
316334
await fs.writeJson(
317-
path.join(path.dirname(output), "binary-metadata.json"),
335+
path.join(path.dirname(output), metadataFile),
318336
{
337+
parentComponent,
319338
components,
320339
dependencies,
321340
},
@@ -510,6 +529,11 @@ if (url.fileURLToPath(import.meta.url) === (await fs.realpath(process.argv[1])))
510529
"-o, --output <output>",
511530
"Path where the executable will be produced.",
512531
)
532+
.option(
533+
"--metadata-file",
534+
"Metadata file name for capturing npm components and dependencies in the bundled binary.",
535+
"binary-metadata.json",
536+
)
513537
.option("-F, --no-force", "Don’t overwrite output if it exists.")
514538
.option("-e, --exclude <path...>", "Paths to exclude from the build.")
515539
.option("-N, --no-include-node", "Don’t copy the Node.js executable.")

test/e2e.test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ test("caxa v2 e2e: globby exclude patterns and directories", async (t) => {
9999
fs.renameSync("binary-metadata.json", metadataPath);
100100
}
101101
const metadataObj = JSON.parse(fs.readFileSync(metadataPath));
102+
assert.ok(metadataObj.parentComponent);
103+
assert.equal(
104+
metadataObj.parentComponent.purl,
105+
"pkg:generic/test-output-excludes",
106+
);
102107
assert.ok(metadataObj.components);
103108
assert.strictEqual(metadataObj.components[0].name, "node");
104109
assert.ok(metadataObj.components[0].version);

0 commit comments

Comments
 (0)