Skip to content

Commit 2f646f2

Browse files
authored
Merge pull request #476 from humbertogontijo/eslint
feat(barrels): use eslint sorting order
2 parents 4ca05d7 + b4e4958 commit 2f646f2

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/barrels/bin/generate-barrel.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import {join as joinPosix} from "node:path/posix";
44

55
import {globby} from "globby";
66

7+
function preprocess(str) {
8+
return str.replace(/\./g, "\u0001").replace(/\//g, "\u0002");
9+
}
10+
11+
function compare(a, b) {
12+
const pa = preprocess(a);
13+
const pb = preprocess(b);
14+
return pa < pb ? -1 : pa > pb ? 1 : 0;
15+
}
16+
717
async function generateIndex(directory, {cwd, excluded, noSemicolon, singleQuotes}) {
818
const baseIndex = join(cwd, directory?.path ?? directory);
919

@@ -13,7 +23,7 @@ async function generateIndex(directory, {cwd, excluded, noSemicolon, singleQuote
1323
const quote = singleQuotes ? "'" : '"';
1424

1525
const exports = files
16-
.sort((a, b) => a.localeCompare(b))
26+
.sort((a, b) => compare(a, b))
1727
.map((file) => {
1828
// TODO set .js after all configuration are ok to resolve .js
1929
return `export * from ${quote}./${file.replace(".ts", ".js")}${quote}${noSemicolon ? "" : ";"}`;

0 commit comments

Comments
 (0)