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
3 changes: 3 additions & 0 deletions workspaces/mama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ Return true if `workspaces` property is present
> [!NOTE]
> Workspace are described by the interface `WorkspacesPackageJSON` (from @nodesecure/npm-types)

### hasZeroSemver
Return true if `version` is starting with `0.x`

### flags

Since we've created this package for security purposes, the instance contains various flags indicating threats detected in the content:
Expand Down
9 changes: 9 additions & 0 deletions workspaces/mama/src/ManifestManager.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ export class ManifestManager<
.some((script) => kUnsafeNPMScripts.has(script.toLowerCase()));
}

get hasZeroSemver() {
if (typeof this.document.version === "string") {
return /^0(\.\d+)*$/
.test(this.document.version);
}

return false;
}

get nodejsImports() {
return this.document.imports ?? {};
}
Expand Down
40 changes: 40 additions & 0 deletions workspaces/mama/test/ManifestManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,46 @@ describe("ManifestManager", () => {
});
});

describe("get hasZeroSemver", () => {
test("Given a PackageJSON with a semver higher than 1.x.x then it must return false", () => {
const packageJSON: PackageJSON = {
...kMinimalPackageJSON
};

const mama = new ManifestManager(packageJSON);
assert.strictEqual(mama.hasZeroSemver, false);
});

test("Given a PackageJSON with a semver starting with 0.x it must return true", () => {
const packageJSON: PackageJSON = {
name: "foobar",
version: "0.5.5"
};

const mama = new ManifestManager(packageJSON);
assert.ok(mama.hasZeroSemver);
});

test("Given a WorkspacesPackageJSON with no version it must return false", () => {
const packageJSON: WorkspacesPackageJSON = {
workspaces: []
};

const mama = new ManifestManager(packageJSON);
assert.strictEqual(mama.hasZeroSemver, false);
});

test("Given a WorkspacesPackageJSON with a semver starting with 0.x it must return true", () => {
const packageJSON: WorkspacesPackageJSON = {
version: "0.1.2",
workspaces: []
};

const mama = new ManifestManager(packageJSON);
assert.ok(mama.hasZeroSemver);
});
});

describe("get license", () => {
test("Given a minimal PackageJSON with no license field then it must return null", () => {
const mama = new ManifestManager(kMinimalPackageJSON);
Expand Down