From 545f04362916da22a1993a01d182f612e60ee699 Mon Sep 17 00:00:00 2001 From: Hubert Olender Date: Sun, 17 May 2026 16:32:31 +0200 Subject: [PATCH] refactor: remove sort-package-json dependency - Remove sortPackageJson usage in updatePackageJson - Drop sort-package-json from dependencies - Add tests for package.json update behavior --- index.js | 5 ++--- package.json | 1 - pnpm-lock.yaml | 28 ---------------------------- tests/package-json.test.mjs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 tests/package-json.test.mjs diff --git a/index.js b/index.js index dfdac881..0a9948b9 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,6 @@ const stringUtil = require('ember-cli-string-utils'); const { styleText } = require('node:util'); const directoryForPackageName = require('./lib/directory-for-package-name'); -const { sortPackageJson } = require('sort-package-json'); const { join } = require('path'); const { readFileSync } = require('fs'); const ejs = require('ejs'); @@ -192,9 +191,9 @@ module.exports = { return fileInfo; }, - updatePackageJson(options, content) { + updatePackageJson(_options, content) { let contents = JSON.parse(content); - return stringifyAndNormalize(sortPackageJson(contents)); + return stringifyAndNormalize(contents); }, }; diff --git a/package.json b/package.json index a44c2afc..eab814e2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "ejs": "^3.1.10", "ember-cli-string-utils": "^1.1.0", "lodash": "^4.17.21", - "sort-package-json": "^3.6.0", "walk-sync": "^4.0.1" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 86bee3d5..a95ddca9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,9 +17,6 @@ importers: lodash: specifier: ^4.17.21 version: 4.17.21 - sort-package-json: - specifier: ^3.6.0 - version: 3.6.0 walk-sync: specifier: ^4.0.1 version: 4.0.1 @@ -2148,9 +2145,6 @@ packages: git-hooks-list@3.2.0: resolution: {integrity: sha512-ZHG9a1gEhUMX1TvGrLdyWb9kDopCBbTnI8z4JgRMYxsijWipgjSEYoPWqBuIB0DnRnvqlQSEeVmzpeuPm7NdFQ==} - git-hooks-list@4.2.1: - resolution: {integrity: sha512-WNvqJjOxxs/8ZP9+DWdwWJ7cDsd60NHf39XnD82pDVrKO5q7xfPqpkK6hwEAmBa/ZSEE4IOoR75EzbbIuwGlMw==} - git-repo-info@2.1.1: resolution: {integrity: sha512-8aCohiDo4jwjOwma4FmYFd3i97urZulL8XL24nIPxuE+GZnfsAyy/g2Shqx6OjUiFKUXZM+Yy+KHnOmmA3FVcg==} engines: {node: '>= 4.0'} @@ -3636,18 +3630,10 @@ packages: sort-object-keys@1.1.3: resolution: {integrity: sha512-855pvK+VkU7PaKYPc+Jjnmt4EzejQHyhhF33q31qG8x7maDzkeFhAAThdCYay11CISO+qAMwjOBP+fPZe0IPyg==} - sort-object-keys@2.1.0: - resolution: {integrity: sha512-SOiEnthkJKPv2L6ec6HMwhUcN0/lppkeYuN1x63PbyPRrgSPIuBJCiYxYyvWRTtjMlOi14vQUCGUJqS6PLVm8g==} - sort-package-json@2.15.1: resolution: {integrity: sha512-9x9+o8krTT2saA9liI4BljNjwAbvUnWf11Wq+i/iZt8nl2UGYnf3TH5uBydE7VALmP7AGwlfszuEeL8BDyb0YA==} hasBin: true - sort-package-json@3.6.0: - resolution: {integrity: sha512-fyJsPLhWvY7u2KsKPZn1PixbXp+1m7V8NWqU8CvgFRbMEX41Ffw1kD8n0CfJiGoaSfoAvbrqRRl/DcHO8omQOQ==} - engines: {node: '>=20'} - hasBin: true - source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -6643,8 +6629,6 @@ snapshots: git-hooks-list@3.2.0: {} - git-hooks-list@4.2.1: {} - git-repo-info@2.1.1: {} github-changelog@2.1.4: @@ -8227,8 +8211,6 @@ snapshots: sort-object-keys@1.1.3: {} - sort-object-keys@2.1.0: {} - sort-package-json@2.15.1: dependencies: detect-indent: 7.0.2 @@ -8240,16 +8222,6 @@ snapshots: sort-object-keys: 1.1.3 tinyglobby: 0.2.15 - sort-package-json@3.6.0: - dependencies: - detect-indent: 7.0.2 - detect-newline: 4.0.1 - git-hooks-list: 4.2.1 - is-plain-obj: 4.1.0 - semver: 7.7.3 - sort-object-keys: 2.1.0 - tinyglobby: 0.2.15 - source-map-js@1.2.1: {} source-map-resolve@0.5.3: diff --git a/tests/package-json.test.mjs b/tests/package-json.test.mjs new file mode 100644 index 00000000..35a070b2 --- /dev/null +++ b/tests/package-json.test.mjs @@ -0,0 +1,32 @@ +import { describe, expect, it } from 'vitest'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; + +function isObject(value) { + return value !== null && typeof value === 'object' && !Array.isArray(value); +} + +function sortedCopy(value) { + if (Array.isArray(value)) { + return value.map(sortedCopy); + } + + if (isObject(value)) { + return Object.fromEntries( + Object.keys(value) + .sort() + .map((key) => [key, sortedCopy(value[key])]), + ); + } + + return value; +} + +describe('package.json template', function () { + it('is sorted', function () { + let packageJsonPath = join(__dirname, '..', 'files', 'package.json'); + let packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); + + expect(packageJson).toEqual(sortedCopy(packageJson)); + }); +});