Skip to content

Commit

Permalink
fix: add playwright dependency in the correct order
Browse files Browse the repository at this point in the history
Currently, the schematics adds playwright at the end of the dev dependencies.
This updates the schematic to insert it ar the proper place (with the same code used by the angular-eslint schematics).
  • Loading branch information
cexbrayat committed Jul 26, 2024
1 parent 02625c1 commit ec22aa7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/schematics/ng-add/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ describe('ng-add', () => {

const packageJSON = JSON.parse(tree.readContent('/package.json'));
expect(packageJSON.devDependencies['@playwright/test']).toBeTruthy();
// check that the dependency is added in the correct place
expect(Object.keys(packageJSON.devDependencies)).toEqual(
Object.keys(packageJSON.devDependencies).sort(),
);
});
});
15 changes: 15 additions & 0 deletions src/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function addPackageToPackageJson(
if (!json.devDependencies[pkg]) {
json.devDependencies[pkg] = version;
}
json.devDependencies = sortObjectByKeys(json.devDependencies);
tree.overwrite('package.json', JSON.stringify(json, null, 2));

return tree;
Expand All @@ -123,3 +124,17 @@ function addPlaywright(tree: Tree, context: SchematicContext) {
PLAYWRIGHT_TEST_VERSION,
);
}

function sortObjectByKeys(
obj: Record<string, unknown>,
): Record<string, unknown> {
return Object.keys(obj)
.sort()
.reduce((result, key) => {
return {
// biome-ignore lint/performance/noAccumulatingSpread: small object, no perf cost
...result,
[key]: obj[key],
};
}, {});
}

0 comments on commit ec22aa7

Please sign in to comment.