From 72bd23b740759e87a33c6579638313510e5317a3 Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 10 Jan 2023 10:39:48 -0700 Subject: [PATCH] [sort-package-json] always ensure 2-space indent is used --- packages/kbn-sort-package-json/index.js | 54 +++++++++++++------------ 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/packages/kbn-sort-package-json/index.js b/packages/kbn-sort-package-json/index.js index 326d6bc8317b..f6ca06d969f6 100644 --- a/packages/kbn-sort-package-json/index.js +++ b/packages/kbn-sort-package-json/index.js @@ -13,29 +13,33 @@ import sorter from 'sort-package-json'; * @returns */ export function sortPackageJson(json) { - return sorter(typeof json === 'string' ? json : JSON.stringify(json, null, 2), { - // top level keys in the order they were written when this was implemented - sortOrder: [ - 'name', - 'description', - 'keywords', - 'private', - 'version', - 'branch', - 'main', - 'browser', - 'types', - 'tsdocMetadata', - 'build', - 'homepage', - 'bugs', - 'license', - 'kibana', - 'author', - 'scripts', - 'repository', - 'engines', - 'resolutions', - ], - }); + return sorter( + // always parse and stringify the json to make sure it's using 2 space indentation + JSON.stringify(typeof json === 'string' ? JSON.parse(json) : json, null, 2), + { + // top level keys in the order they were written when this was implemented + sortOrder: [ + 'name', + 'description', + 'keywords', + 'private', + 'version', + 'branch', + 'main', + 'browser', + 'types', + 'tsdocMetadata', + 'build', + 'homepage', + 'bugs', + 'license', + 'kibana', + 'author', + 'scripts', + 'repository', + 'engines', + 'resolutions', + ], + } + ); }