Merge pull request #945 from Cooldude2606/fix/duplicate-instances

Setting filepath on config makes it dirty
This commit is contained in:
Daniel authored and GitHub committed 2026-07-18 21:14:56 +02:00
commit 5758cd94b6
2 files changed
+32 -1

No files matched your search

+10 -1
View File
@@ -251,7 +251,7 @@ export class Config<
constructor(
public location: ConfigLocation,
fields?: Static<typeof Config.jsonSchema>,
public filepath?: string,
private _filepath?: string,
) {
if (typeof location !== "string") {
throw new Error("location must be a string");
@@ -273,6 +273,15 @@ export class Config<
}
}
get filepath() {
return this._filepath;
}
set filepath(filepath: string | undefined) {
this.dirty = true;
this._filepath = filepath;
}
/** A staging version of the config with changes tracked, invalided by revertStaging */
private _staging?: { config: Config<Fields>, changes: Set<string>};
+22
View File
@@ -176,6 +176,28 @@ describe("lib/config/classes", function() {
});
});
describe("get filepath", function() {
it("returns the current filepath for the config", function() {
const testInstance = new TestConfig("local", undefined, "foo/bar");
assert.equal(testInstance.filepath, "foo/bar");
});
});
describe("set filepath", function() {
it("sets the current filepath for the config", function() {
const testInstance = new TestConfig("local");
assert.equal(testInstance.filepath, undefined);
testInstance.filepath = "foo/bar";
assert.equal(testInstance.filepath, "foo/bar");
});
it("sets the dirty flag", function() {
const testInstance = new TestConfig("local");
assert.equal(testInstance.dirty, false);
testInstance.filepath = "foo/bar";
assert.equal(testInstance.dirty, true);
});
});
describe(".toJSON()", function() {
it("should serialize a basic config", function() {
const testInstance = new TestConfig("local");