Skip to content

Commit

Permalink
Fixed order of dim.json contents when updating by name
Browse files Browse the repository at this point in the history
  • Loading branch information
ryo-ma committed Aug 24, 2022
1 parent 7480f30 commit d9dea01
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions libs/accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ export class DimFileAccessor {
catalogUrl,
catalogResourceId,
postProcesses,
headers: headers,
headers,
};
// Override the existing content.
const currentContents = this.dimJSON.contents.filter((c) =>
c.name !== content.name
const contents = this.dimJSON.contents;
const contentIndex = this.dimJSON.contents.findIndex((c) =>
c.name === name
);
const contents = new Array<Content>(...currentContents, content);
if (contentIndex !== -1) {
// Override the existing content.
contents.splice(contentIndex, 1, content);
} else {
contents.push(content);
}
await this.writeToDimFile({
fileVersion: DIM_FILE_VERSION,
contents: contents,
Expand Down Expand Up @@ -114,11 +119,16 @@ export class DimLockFileAccessor {
if (this.dimLockJSON === undefined) {
return;
}
// Override the existing content.
const currentContents = this.dimLockJSON.contents.filter((c) =>
c.name !== content.name
const contents = this.dimLockJSON.contents;
const contentIndex = this.dimLockJSON.contents.findIndex((c) =>
c.name === content.name
);
const contents = new Array<LockContent>(...currentContents, content);
if (contentIndex !== -1) {
// Override the existing content.
contents.splice(contentIndex, 1, content);
} else {
contents.push(content);
}
await this.writeToDimLockFile({
lockFileVersion: DIM_LOCK_FILE_VERSION,
contents: contents,
Expand Down

0 comments on commit d9dea01

Please sign in to comment.