From f287f6f99fca5b473aeddc500d0d5c110350462b Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Thu, 16 Feb 2023 09:44:13 -0500 Subject: [PATCH] Fixed exports field order (#3703, #3755). --- src.ts/_admin/update-version.ts | 9 ++++++++- src.ts/_admin/utils/json.ts | 12 ++++++++++-- tsconfig.commonjs.json | 1 - 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src.ts/_admin/update-version.ts b/src.ts/_admin/update-version.ts index bbf63410f4..c802279a23 100644 --- a/src.ts/_admin/update-version.ts +++ b/src.ts/_admin/update-version.ts @@ -67,7 +67,14 @@ function writeVersion(version: string): void { pkgInfo.gitHead = gitHead; // Save the package.json - saveJson(pkgPath, pkgInfo, true); + const check: Record = { "require": 1, "import": 1, "types": 1 }; + saveJson(pkgPath, pkgInfo, (path: string, a: string, b: string) => { + if (path.startsWith("./") && check[a] && check[b]) { + if (a === "types") { return -1; } + if (b === "types") { return 1; } + } + return a.localeCompare(b); + }); // Save the src.ts/_version.ts writeVersion(pkgInfo.version); diff --git a/src.ts/_admin/utils/json.ts b/src.ts/_admin/utils/json.ts index a21251afd4..8ddc749212 100644 --- a/src.ts/_admin/utils/json.ts +++ b/src.ts/_admin/utils/json.ts @@ -9,7 +9,9 @@ export function loadJson(path: string): any { type Replacer = (key: string, value: any) => any; -export function saveJson(filename: string, data: any, sort?: boolean): any { +export type SortFunc = (parent: string, a: string, b: string) => number; + +export function saveJson(filename: string, data: any, sort?: boolean | SortFunc): any { let replacer: (Replacer | undefined) = undefined; if (sort) { @@ -18,7 +20,13 @@ export function saveJson(filename: string, data: any, sort?: boolean): any { // pass } else if (value && typeof(value) === "object") { const keys = Object.keys(value); - keys.sort(); + let sortFunc: undefined | ((a: string, b: string) => number); + if (typeof(sort) === "function") { + sortFunc = function(a: string, b: string) { + return sort(key, a, b); + } + } + keys.sort(sortFunc); return keys.reduce((accum, key) => { accum[key] = value[key]; return accum; diff --git a/tsconfig.commonjs.json b/tsconfig.commonjs.json index 5b0639f089..b73f1dd6ad 100644 --- a/tsconfig.commonjs.json +++ b/tsconfig.commonjs.json @@ -4,7 +4,6 @@ ], "extends": "./tsconfig.base.json", "compilerOptions": { - "declaration": true, "module": "commonjs", "outDir": "./lib.commonjs" }