Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add playwright dependency in the correct order #1

Merged
merged 1 commit into from
Jul 27, 2024
Merged
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
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],
};
}, {});
}
Loading