Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-rc-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/rc": patch
---

fix(rc): explicitly write the configuration on disk in write() since @openally/config 2.1.0 no longer does it on close()
1 change: 1 addition & 0 deletions workspaces/rc/src/functions/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export async function write(
const newPayloadValue = partialUpdate ? Object.assign(cfg.payload, payload) : payload as RC;
cfg.payload = newPayloadValue;

await cfg.writeOnDisk();
await cfg.close();

return Ok(void 0);
Expand Down
10 changes: 7 additions & 3 deletions workspaces/scanner/src/registry/PackumentExtractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Packument } from "@nodesecure/npm-types";
import { packageJSONIntegrityHash } from "@nodesecure/mama";
import { toContactWithMetadata } from "@nodesecure/contact";
import { parseAuthor, type ParsedMaintainer } from "@nodesecure/utils";

// Import Internal Dependencies
import type {
Expand Down Expand Up @@ -40,6 +41,8 @@ export class PackumentExtractor {
this.#packument.versions[version],
{ isFromRemoteRegistry: true }
);
// The registry can return the author as a raw string (e.g. "GitLab")
const author = parseAuthor(this.#packument.author);

return {
homepage: this.#packument.homepage || null,
Expand All @@ -53,18 +56,19 @@ export class PackumentExtractor {
},
...this.#extractMaintainers(
this.#packument,
this.#packument.author?.name ?? null
author
)
};
}

#extractMaintainers(
packument: Packument,
authorName: string | null
author: ParsedMaintainer | null
) {
const authorName = author?.name ?? null;
const publishers = new Set();
const result: Pick<Dependency["metadata"], "author" | "publishers" | "maintainers" | "hasManyPublishers"> = {
author: packument.author ? toContactWithMetadata(packument.author) : null,
author: author ? toContactWithMetadata(author) : null,
publishers: [],
maintainers: packument.maintainers?.map(toContactWithMetadata) ?? [],
hasManyPublishers: false
Expand Down
61 changes: 61 additions & 0 deletions workspaces/scanner/test/PackumentExtractor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Import Node.js Dependencies
import { test, describe } from "node:test";
import assert from "node:assert";

// Import Third-party Dependencies
import type { Packument } from "@nodesecure/npm-types";

// Import Internal Dependencies
import { PackumentExtractor } from "../src/registry/PackumentExtractor.ts";

function createPackument(author: unknown): Packument {
return {
name: "foo",
author,
"dist-tags": { latest: "1.0.0" },
time: { "1.0.0": "2024-01-01T00:00:00.000Z" },
maintainers: [],
versions: {
"1.0.0": {
name: "foo",
version: "1.0.0",
dist: { integrity: "", shasum: "", tarball: "" },
_npmUser: { name: "publisher", email: "publisher@example.com" }
}
}
} as unknown as Packument;
}

describe("PackumentExtractor", () => {
describe("getMetadata", () => {
test("should parse the author when the registry returns it as a string", () => {
const extractor = new PackumentExtractor(
createPackument("GitLab <gitlab@example.com>")
);

const metadata = extractor.getMetadata("1.0.0");

assert.deepEqual(metadata.author, {
name: "GitLab",
email: "gitlab@example.com",
flags: []
});
assert.strictEqual(metadata.hasManyPublishers, true);
});

test("should keep the author when the registry returns it as an object", () => {
const extractor = new PackumentExtractor(
createPackument({ name: "publisher", email: "publisher@example.com" })
);

const metadata = extractor.getMetadata("1.0.0");

assert.deepEqual(metadata.author, {
name: "publisher",
email: "publisher@example.com",
flags: []
});
assert.strictEqual(metadata.hasManyPublishers, false);
});
});
});
10 changes: 4 additions & 6 deletions workspaces/scanner/test/depWalker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ describe("depWalker", { concurrency: 2 }, () => {
"@nodesecure/npm-types",
"@openally/httpie",
"@openally/result",
"lru-cache",
"nanodelay",
"nanoevents",
"nanoid",
Expand All @@ -186,21 +185,20 @@ describe("depWalker", { concurrency: 2 }, () => {
assert.strictEqual(typeof metadata.startedAt, "number");
assert.strictEqual(typeof metadata.executionTime, "number");
assert.strictEqual(Array.isArray(metadata.apiCalls), true);
assert.strictEqual(metadata.apiCallsCount, 57);
assert.strictEqual(metadata.apiCallsCount, 53);
assert.strictEqual(metadata.errorCount, 2);
assert.strictEqual(metadata.errors.length, 2);
assert.strictEqual(statsCount(), 55);
assert.strictEqual(statsCount(), 51);
assert.deepEqual(metadata.apiCalls.flatMap(({ name, tarball }) => (name.startsWith("tarball.scanDirOrArchive") ?
[tarball] : [])).sort(byFilesCount),
[{ path: "All", filesCount: 37 },
{ path: "EntryFileAnalyser", filesCount: 5 },
{ path: "EntryFileAnalyser", filesCount: 11 },
{ path: "EntryFileAnalyser", filesCount: 5 },
{ path: "NONE", filesCount: 3 },
{ path: "EntryFileAnalyser", filesCount: 6 },
{ path: "EntryFileAnalyser", filesCount: 17 },
{ path: "EntryFileAnalyser", filesCount: 47 },
{ path: "EntryFileAnalyser", filesCount: 30 },
{ path: "EntryFileAnalyser", filesCount: 67 },
{ path: "EntryFileAnalyser", filesCount: 95 },
{ path: "EntryFileAnalyser", filesCount: 214 }].sort(byFilesCount));
});

Expand Down