Skip to content
Closed
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/khaki-cloths-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/mama": patch
---

Add optional location path in ManifestManager.class.ts
12 changes: 10 additions & 2 deletions workspaces/mama/src/ManifestManager.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ export type ManifestManagerDocument =
WorkspacesPackageJSON |
PackumentVersion;

export interface ManifestManagerOptions {
location?: string;
}

export class ManifestManager<
MetadataDef extends Record<string, any> = Record<string, any>
> {
Expand All @@ -65,19 +69,22 @@ export class ManifestManager<
ManifestManagerDocument,
NonOptionalPackageJSONProperties
>;
public location?: string;

public flags = Object.seal({
hasUnsafeScripts: false,
isNative: false
});

constructor(
document: ManifestManagerDocument
document: ManifestManagerDocument,
options: ManifestManagerOptions = {}
) {
this.document = Object.assign(
{ ...ManifestManager.Default },
structuredClone(document)
);
this.location = typeof options.location === "string" ? path.dirname(options.location) : this.location;

this.flags.isNative = [
...this.dependencies,
Expand Down Expand Up @@ -211,7 +218,8 @@ export class ManifestManager<
) as PackageJSON | WorkspacesPackageJSON;

return new ManifestManager(
packageJSON
packageJSON,
{ location: packageLocation }
);
}
catch (cause) {
Expand Down
11 changes: 11 additions & 0 deletions workspaces/mama/test/ManifestManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ describe("ManifestManager", () => {
}
);
});

it("Should store location if provided", () => {
const location = "package.json";
const mama = new ManifestManager(kMinimalPackageJSON, { location });
assert.strictEqual(mama.location, path.dirname(location));
});

it("Should have location undefined if not provided", () => {
const mama = new ManifestManager(kMinimalPackageJSON);
assert.strictEqual(mama.location, undefined);
});
});

describe("get dependencies", () => {
Expand Down