diff --git a/.changeset/khaki-cloths-join.md b/.changeset/khaki-cloths-join.md new file mode 100644 index 00000000..1bdf0c19 --- /dev/null +++ b/.changeset/khaki-cloths-join.md @@ -0,0 +1,5 @@ +--- +"@nodesecure/mama": patch +--- + +Add optional location path in ManifestManager.class.ts diff --git a/workspaces/mama/src/ManifestManager.class.ts b/workspaces/mama/src/ManifestManager.class.ts index 04cd7eb7..9653ec83 100644 --- a/workspaces/mama/src/ManifestManager.class.ts +++ b/workspaces/mama/src/ManifestManager.class.ts @@ -50,6 +50,10 @@ export type ManifestManagerDocument = WorkspacesPackageJSON | PackumentVersion; +export interface ManifestManagerOptions { + location?: string; +} + export class ManifestManager< MetadataDef extends Record = Record > { @@ -65,6 +69,7 @@ export class ManifestManager< ManifestManagerDocument, NonOptionalPackageJSONProperties >; + public location?: string; public flags = Object.seal({ hasUnsafeScripts: false, @@ -72,12 +77,14 @@ export class ManifestManager< }); 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, @@ -211,7 +218,8 @@ export class ManifestManager< ) as PackageJSON | WorkspacesPackageJSON; return new ManifestManager( - packageJSON + packageJSON, + { location: packageLocation } ); } catch (cause) { diff --git a/workspaces/mama/test/ManifestManager.spec.ts b/workspaces/mama/test/ManifestManager.spec.ts index f0010810..c487b13f 100644 --- a/workspaces/mama/test/ManifestManager.spec.ts +++ b/workspaces/mama/test/ManifestManager.spec.ts @@ -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", () => {