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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions workspaces/conformance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"node-estree": "^4.0.0"
},
"dependencies": {
"@nodesecure/mama": "^1.0.0",
"@openally/result": "^1.2.1",
"fastest-levenshtein": "^1.0.16",
"spdx-expression-parse": "^4.0.0"
Expand Down
22 changes: 13 additions & 9 deletions workspaces/conformance/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as path from "node:path";
import * as fsSync from "node:fs";
import * as fs from "node:fs/promises";

// Import Third-party Dependencies
import { ManifestManager } from "@nodesecure/mama";

// Import Internal Dependencies
import * as utils from "./utils/index.js";
import {
Expand All @@ -14,6 +17,7 @@ import {

// CONSTANTS
const kManifestFileName = "package.json";
const kInvalidLicense = "invalid license";

export interface ExtractAsyncOptions {
fsEngine?: typeof fs;
Expand All @@ -25,16 +29,15 @@ export async function extractLicenses(
): Promise<SpdxExtractedResult> {
const { fsEngine = fs } = options;

const packageStr = await fsEngine.readFile(
path.join(location, kManifestFileName), "utf-8"
const mama = await ManifestManager.fromPackageJSON(
location
);
const packageJSON = JSON.parse(packageStr);

const licenseData = new LicenseResult();
licenseData.addLicenseID(
utils.parsePackageLicense(packageJSON),
kManifestFileName
);
const licenseData = new LicenseResult()
.addLicenseID(
mama.license ?? kInvalidLicense,
kManifestFileName
);

const dirents = await fsEngine.readdir(location, {
withFileTypes: true
Expand Down Expand Up @@ -66,10 +69,11 @@ export function extractLicensesSync(
path.join(location, kManifestFileName), "utf-8"
);
const packageJSON = JSON.parse(packageStr);
const mama = new ManifestManager(packageJSON);

const licenseData = new LicenseResult();
licenseData.addLicenseID(
utils.parsePackageLicense(packageJSON),
mama.license ?? kInvalidLicense,
kManifestFileName
);

Expand Down
1 change: 0 additions & 1 deletion workspaces/conformance/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./parsePackageLicense.js";
export * from "./extractDirentLicenses.js";
export * from "./spdx.js";
45 changes: 0 additions & 45 deletions workspaces/conformance/src/utils/parsePackageLicense.ts

This file was deleted.

67 changes: 0 additions & 67 deletions workspaces/conformance/test/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,73 +65,6 @@ describe("extractDirentLicenses", () => {
});
});

describe("parsePackageLicense", () => {
it("should return 'MIT' for parsePackageLicense license MIT", () => {
const result = utils.parsePackageLicense({
license: "MIT"
});
assert.strictEqual(result, "MIT");
});

it("should return 'MIT AND (CC0-1.0 OR ISC)' for parsePackageLicense of Object", () => {
const result = utils.parsePackageLicense({
license: {
type: "MIT AND (CC0-1.0 OR ISC)"
}
});
assert.strictEqual(result, "MIT AND (CC0-1.0 OR ISC)");
});

test("parsePackageLicense of payload with licenses property", () => {
const result = utils.parsePackageLicense({
licenses: {
type: "MIT AND (CC0-1.0 OR ISC)"
}
});
assert.strictEqual(result, "MIT AND (CC0-1.0 OR ISC)");
});

test("parsePackageLicense of payload with licenses property as Array", () => {
const result = utils.parsePackageLicense({
licenses: [
{
type: "ISC"
}
]
});
assert.strictEqual(result, "ISC");
});

it("should return 'invalid license' for a PackageJSON with no licenses", () => {
const result = utils.parsePackageLicense({});
assert.strictEqual(result, "invalid license");
});
});

describe("handleUndefinedAndNull", () => {
it("should return 'invalid license' for null or undefined", () => {
assert.strictEqual(
utils.handleUndefinedAndNull(),
"invalid license"
);
assert.strictEqual(
utils.handleUndefinedAndNull(undefined),
"invalid license"
);
assert.strictEqual(
utils.handleUndefinedAndNull(null),
"invalid license"
);
});

it("should return provided string primitive", () => {
assert.strictEqual(
utils.handleUndefinedAndNull("MIT"),
"MIT"
);
});
});

function createDirent(name: string, isFile = true) {
return {
isFile: () => isFile,
Expand Down
6 changes: 5 additions & 1 deletion workspaces/conformance/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"outDir": "dist",
},
"include": ["src"],
"references": []
"references": [
{
"path": "../mama"
}
]
}