Skip to content

Commit 5f1ec20

Browse files
authored
Merge pull request #202 from kreuzerk/feature/esm
fix(esm): deliver correct esm files
2 parents cbea9e2 + a16137d commit 5f1ec20

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

package-lock.json

Lines changed: 26 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"ora": "^5.1.0",
100100
"prettier": "^1.19.1",
101101
"svgo": "^2.7.0",
102-
"typescript": "^3.7.2"
102+
"typescript": "^4.9.4"
103103
},
104104
"devDependencies": {
105105
"@commitlint/cli": "^11.0.0",

src/lib/compiler/typescript-compiler.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { lstatSync, readdirSync, renameSync } from 'fs';
12
import * as ts from 'typescript';
23

34
export const compileToEsNext = (filePaths: string[], outputDir: string): void => {
@@ -11,6 +12,26 @@ export const compileToEsNext = (filePaths: string[], outputDir: string): void =>
1112
};
1213

1314
ts.createProgram(filePaths, compilerOptionsNext).emit();
15+
renameJsFilesToMJs(outputDir);
16+
};
17+
18+
export const renameJsFilesToMJs = (outputDir: string) => {
19+
const children = readdirSync(outputDir);
20+
21+
if (children.length === 0) {
22+
return;
23+
}
24+
25+
children.forEach(file => {
26+
const path = `${outputDir}/${file}`;
27+
if (lstatSync(path).isDirectory()) {
28+
renameJsFilesToMJs(path);
29+
} else {
30+
if (file.endsWith('.js')) {
31+
renameSync(path, path.replace('.js', '.mjs'));
32+
}
33+
}
34+
});
1435
};
1536

1637
export const compileToUMD = (filePaths: string[], outputDir: string): void => {

0 commit comments

Comments
 (0)