Skip to content

Commit

Permalink
Fixed exports field order (ethers-io#3703, ethers-io#3755).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent fb452cb commit f287f6f
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 f287f6f

Please sign in to comment.