From ae19d4dcbb725a9000e0477dc82c1569970765f7 Mon Sep 17 00:00:00 2001 From: BoussonKarel Date: Fri, 12 Sep 2025 15:26:28 +0200 Subject: [PATCH 1/3] sort the addon's package.json and assert it is sorted --- index.js | 53 ++++++++++++++++++++++++++++++ package.json | 4 ++- pnpm-lock.yaml | 41 +++++++++++++++++++++++ tests/smoke-tests/defaults.test.ts | 9 +++++ 4 files changed, 106 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ac579e7..563924b 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,23 @@ 'use strict'; +const path = require('path'); +const { sortPackageJson } = require('sort-package-json'); +const FileInfo = require('@ember-tooling/blueprint-model/utilities/file-info'); + let date = new Date(); const description = 'The default blueprint for Embroider v2 addons.'; +function stringifyAndNormalize(contents) { + return `${JSON.stringify(contents, null, 2)}\n`; +} + +const replacers = { + 'package.json'(content) { + return this.updatePackageJson(content); + }, +}; + module.exports = { description, @@ -60,6 +74,45 @@ module.exports = { return files; }, + + updatePackageJson(content) { + let contents = JSON.parse(content); + return stringifyAndNormalize(sortPackageJson(contents)); + }, + + /** + * @override + * + * This modification of buildFileInfo allows our differing + * input files to output to a single file, depending on the options. + * For example: + * + * for javascript, + * _ts_eslint.config.mjs is deleted + * _js_eslint.config.mjs is renamed to eslint.config.mjs + * + * for typescript, + * _js_eslint.config.mjs is deleted + * _ts_eslint.config.mjs is renamed to eslint.config.mjs + */ + buildFileInfo(intoDir, templateVariables, file, _commandOptions) { + let mappedPath = this.mapFile(file, templateVariables); + let options = { + action: 'write', + outputBasePath: path.normalize(intoDir), + outputPath: path.join(intoDir, mappedPath), + displayPath: path.normalize(mappedPath), + inputPath: this.srcPath(file), + templateVariables, + ui: this.ui, + }; + + if (file in replacers) { + options.replacer = replacers[file].bind(this); + } + + return new FileInfo(options); + }, }; function buildBlueprintOptions(blueprintOptions) { diff --git a/package.json b/package.json index 266ad79..0947784 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,10 @@ "format": "prettier --write ." }, "devDependencies": { + "@ember-tooling/blueprint-model": "^0.3.0", "prettier": "^3.5.3", - "release-plan": "^0.16.0" + "release-plan": "^0.16.0", + "sort-package-json": "^3.4.0" }, "packageManager": "pnpm@10.6.5" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 620ac20..af8ddc1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,12 +8,18 @@ importers: .: devDependencies: + '@ember-tooling/blueprint-model': + specifier: ^0.3.0 + version: 0.3.0 prettier: specifier: ^3.5.3 version: 3.5.3 release-plan: specifier: ^0.16.0 version: 0.16.0 + sort-package-json: + specifier: ^3.4.0 + version: 3.4.0 tests: devDependencies: @@ -185,6 +191,9 @@ packages: engines: {node: '>=0.1.95'} hasBin: true + '@ember-tooling/blueprint-model@0.3.0': + resolution: {integrity: sha512-z9ZjJNgcPZ/+xLQSeGIUbKFl9aw0MUXZtfFgv++8rrP2EVfI9ibTRDdLEYE9ROhQlD2LTogOigBk9AWIFOXKTw==} + '@esbuild/aix-ppc64@0.25.2': resolution: {integrity: sha512-wCIboOL2yXZym2cgm6mlA742s9QeJ8DjGVaL39dLN4rRwrOgOyYSnOaFPhKZGLb2ngj4EyfAFjsNJwPXZvseag==} engines: {node: '>=18'} @@ -2105,6 +2114,9 @@ packages: git-hooks-list@3.2.0: resolution: {integrity: sha512-ZHG9a1gEhUMX1TvGrLdyWb9kDopCBbTnI8z4JgRMYxsijWipgjSEYoPWqBuIB0DnRnvqlQSEeVmzpeuPm7NdFQ==} + git-hooks-list@4.1.1: + resolution: {integrity: sha512-cmP497iLq54AZnv4YRAEMnEyQ1eIn4tGKbmswqwmFV4GBnAqE8NLtWxxdXa++AalfgL5EBH4IxTPyquEuGY/jA==} + git-repo-info@2.1.1: resolution: {integrity: sha512-8aCohiDo4jwjOwma4FmYFd3i97urZulL8XL24nIPxuE+GZnfsAyy/g2Shqx6OjUiFKUXZM+Yy+KHnOmmA3FVcg==} engines: {node: '>= 4.0'} @@ -3566,6 +3578,11 @@ packages: resolution: {integrity: sha512-9x9+o8krTT2saA9liI4BljNjwAbvUnWf11Wq+i/iZt8nl2UGYnf3TH5uBydE7VALmP7AGwlfszuEeL8BDyb0YA==} hasBin: true + sort-package-json@3.4.0: + resolution: {integrity: sha512-97oFRRMM2/Js4oEA9LJhjyMlde+2ewpZQf53pgue27UkbEXfHJnDzHlUxQ/DWUkzqmp7DFwJp8D+wi/TYeQhpA==} + engines: {node: '>=20'} + hasBin: true + source-map-js@1.2.1: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} @@ -4371,6 +4388,18 @@ snapshots: exec-sh: 0.3.6 minimist: 1.2.8 + '@ember-tooling/blueprint-model@0.3.0': + dependencies: + chalk: 4.1.2 + diff: 7.0.0 + isbinaryfile: 5.0.4 + lodash: 4.17.21 + promise.hash.helper: 1.0.8 + quick-temp: 0.1.8 + silent-error: 1.1.1 + transitivePeerDependencies: + - supports-color + '@esbuild/aix-ppc64@0.25.2': optional: true @@ -6487,6 +6516,8 @@ snapshots: git-hooks-list@3.2.0: {} + git-hooks-list@4.1.1: {} + git-repo-info@2.1.1: {} github-changelog@2.0.0: @@ -8055,6 +8086,16 @@ snapshots: sort-object-keys: 1.1.3 tinyglobby: 0.2.12 + sort-package-json@3.4.0: + dependencies: + detect-indent: 7.0.1 + detect-newline: 4.0.1 + git-hooks-list: 4.1.1 + is-plain-obj: 4.1.0 + semver: 7.7.1 + sort-object-keys: 1.1.3 + tinyglobby: 0.2.12 + source-map-js@1.2.1: {} source-map-resolve@0.5.3: diff --git a/tests/smoke-tests/defaults.test.ts b/tests/smoke-tests/defaults.test.ts index 69271a9..f20f287 100644 --- a/tests/smoke-tests/defaults.test.ts +++ b/tests/smoke-tests/defaults.test.ts @@ -13,9 +13,11 @@ import { assertGeneratedCorrectly, dirContents, matchesFixture, + packageJsonAt, SUPPORTED_PACKAGE_MANAGERS, } from '../helpers.js'; import { existsSync } from 'node:fs'; +import sortPackageJson from 'sort-package-json'; /** * NOTE: tests run sequentially @@ -108,6 +110,13 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) { expect(exitCode).toEqual(0); }); + it('has a sorted package.json', async () => { + const originalPackageJson = await packageJsonAt(addonDir); + const sortedPackageJson = await sortPackageJson(originalPackageJson); + + expect(JSON.stringify(sortedPackageJson)).toEqual(JSON.stringify(originalPackageJson)); + }); + describe('with fixture', () => { beforeEach(async () => { let addonFixture = fixturify.readSync('./fixtures/addon'); From 8539e79ef792e738d0a68f0fb5a6d26ff5d90f2c Mon Sep 17 00:00:00 2001 From: BoussonKarel Date: Fri, 12 Sep 2025 15:51:37 +0200 Subject: [PATCH 2/3] improve sort package.json, use super to build fileInfo --- index.js | 19 ++++--------------- package.json | 5 +++-- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 563924b..8b2b6d1 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,6 @@ 'use strict'; -const path = require('path'); const { sortPackageJson } = require('sort-package-json'); -const FileInfo = require('@ember-tooling/blueprint-model/utilities/file-info'); let date = new Date(); @@ -95,23 +93,14 @@ module.exports = { * _js_eslint.config.mjs is deleted * _ts_eslint.config.mjs is renamed to eslint.config.mjs */ - buildFileInfo(intoDir, templateVariables, file, _commandOptions) { - let mappedPath = this.mapFile(file, templateVariables); - let options = { - action: 'write', - outputBasePath: path.normalize(intoDir), - outputPath: path.join(intoDir, mappedPath), - displayPath: path.normalize(mappedPath), - inputPath: this.srcPath(file), - templateVariables, - ui: this.ui, - }; + buildFileInfo(_intoDir, _templateVariables, file, _commandOptions) { + let fileInfo = this._super.buildFileInfo.apply(this, arguments); if (file in replacers) { - options.replacer = replacers[file].bind(this); + fileInfo.replacer = replacers[file].bind(this); } - return new FileInfo(options); + return fileInfo; }, }; diff --git a/package.json b/package.json index 0947784..5953875 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,10 @@ "format": "prettier --write ." }, "devDependencies": { - "@ember-tooling/blueprint-model": "^0.3.0", "prettier": "^3.5.3", - "release-plan": "^0.16.0", + "release-plan": "^0.16.0" + }, + "dependencies": { "sort-package-json": "^3.4.0" }, "packageManager": "pnpm@10.6.5" From 3f03e3833bfb53d69dd13f558a8d1fe53a26738d Mon Sep 17 00:00:00 2001 From: BoussonKarel Date: Mon, 15 Sep 2025 09:03:12 +0200 Subject: [PATCH 3/3] fix outdated lockfile --- pnpm-lock.yaml | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index af8ddc1..4912304 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,19 +7,17 @@ settings: importers: .: + dependencies: + sort-package-json: + specifier: ^3.4.0 + version: 3.4.0 devDependencies: - '@ember-tooling/blueprint-model': - specifier: ^0.3.0 - version: 0.3.0 prettier: specifier: ^3.5.3 version: 3.5.3 release-plan: specifier: ^0.16.0 version: 0.16.0 - sort-package-json: - specifier: ^3.4.0 - version: 3.4.0 tests: devDependencies: @@ -191,9 +189,6 @@ packages: engines: {node: '>=0.1.95'} hasBin: true - '@ember-tooling/blueprint-model@0.3.0': - resolution: {integrity: sha512-z9ZjJNgcPZ/+xLQSeGIUbKFl9aw0MUXZtfFgv++8rrP2EVfI9ibTRDdLEYE9ROhQlD2LTogOigBk9AWIFOXKTw==} - '@esbuild/aix-ppc64@0.25.2': resolution: {integrity: sha512-wCIboOL2yXZym2cgm6mlA742s9QeJ8DjGVaL39dLN4rRwrOgOyYSnOaFPhKZGLb2ngj4EyfAFjsNJwPXZvseag==} engines: {node: '>=18'} @@ -4388,18 +4383,6 @@ snapshots: exec-sh: 0.3.6 minimist: 1.2.8 - '@ember-tooling/blueprint-model@0.3.0': - dependencies: - chalk: 4.1.2 - diff: 7.0.0 - isbinaryfile: 5.0.4 - lodash: 4.17.21 - promise.hash.helper: 1.0.8 - quick-temp: 0.1.8 - silent-error: 1.1.1 - transitivePeerDependencies: - - supports-color - '@esbuild/aix-ppc64@0.25.2': optional: true