Fixed exports field order (#3703, #3755).

This commit is contained in:
Richard Moore 2023-02-16 09:44:13 -05:00
parent ddaa87a2e6
commit 085a9054f3
3 changed files with 18 additions and 4 deletions

@ -67,7 +67,14 @@ function writeVersion(version: string): void {
pkgInfo.gitHead = gitHead;
// Save the package.json
saveJson(pkgPath, pkgInfo, true);
const check: Record<string, number> = { "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);

@ -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;

@ -4,7 +4,6 @@
],
"extends": "./tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"outDir": "./lib.commonjs"
}