Skip to content

Commit 8248a13

Browse files
fix: Refactor renaming to .mjs extension
1 parent 53c42c6 commit 8248a13

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

fix-imports.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ async function processFiles(directory) {
1717
await processFiles(fullPath);
1818
} else if (entry.isFile() && entry.name.endsWith(".js")) {
1919
const data = await readFile(fullPath, "utf8");
20-
const updatedData = data.replace(/\.js"/g, '.mjs"');
20+
const updatedData = data
21+
.split("\n")
22+
.map((line) => {
23+
if (line.trim().startsWith("import")) {
24+
return line.replace(/\.js"/g, '.mjs"');
25+
}
26+
return line;
27+
})
28+
.join("\n");
2129
const { dir, name } = parse(fullPath);
2230
const newFullPath = join(dir, `${name}.mjs`);
2331

src/frameworks/slsFramework.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ export class SlsFramework implements IFramework {
6565
resolveConfigurationPath = (
6666
await import(
6767
//@ts-ignore
68-
"serverless/lib/cli/resolve-configuration-path." + "js" // hack for avoiding renaming to .mjs by build script
68+
"serverless/lib/cli/resolve-configuration-path.js"
6969
)
7070
).default;
7171
readConfiguration = (
7272
await import(
7373
//@ts-ignore
74-
"serverless/lib/configuration/read." + "js" // hack for avoiding renaming to .mjs by build script
74+
"serverless/lib/configuration/read.js"
7575
)
7676
).default;
7777

src/nodeEsBuild.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ async function getBuild(functionId: string) {
7171
Logger.verbose(`[Function ${functionId}] Build complete`);
7272
}
7373

74-
const artifactFile = Object.keys(result.metafile?.outputs!).find(
75-
(key) => key.endsWith("." + "js") // hack for avoiding renaming to .mjs by build script
74+
const artifactFile = Object.keys(result.metafile?.outputs!).find((key) =>
75+
key.endsWith(".js")
7676
);
7777

7878
if (!artifactFile) {

0 commit comments

Comments
 (0)