Skip to content

Commit

Permalink
Fixed exports field order (#3703, #3755).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Feb 16, 2023
1 parent ddaa87a commit 085a905
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion src.ts/_admin/update-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 10 additions & 2 deletions src.ts/_admin/utils/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion tsconfig.commonjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
],
"extends": "./tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"module": "commonjs",
"outDir": "./lib.commonjs"
}
Expand Down

0 comments on commit 085a905

Please sign in to comment.