Skip to content

Commit

Permalink
fix(esm): deliver correct esm files
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Previously esm files were delivered with a .js ending. Now they will be delivered
with a .mjs ending

#201
  • Loading branch information
nivekcode committed Jan 3, 2023
1 parent cbea9e2 commit a16137d
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
33 changes: 26 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"ora": "^5.1.0",
"prettier": "^1.19.1",
"svgo": "^2.7.0",
"typescript": "^3.7.2"
"typescript": "^4.9.4"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
Expand Down
21 changes: 21 additions & 0 deletions src/lib/compiler/typescript-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { lstatSync, readdirSync, renameSync } from 'fs';
import * as ts from 'typescript';

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

ts.createProgram(filePaths, compilerOptionsNext).emit();
renameJsFilesToMJs(outputDir);
};

export const renameJsFilesToMJs = (outputDir: string) => {
const children = readdirSync(outputDir);

if (children.length === 0) {
return;
}

children.forEach(file => {
const path = `${outputDir}/${file}`;
if (lstatSync(path).isDirectory()) {
renameJsFilesToMJs(path);
} else {
if (file.endsWith('.js')) {
renameSync(path, path.replace('.js', '.mjs'));
}
}
});
};

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

0 comments on commit a16137d

Please sign in to comment.