Skip to content

Commit 98a6997

Browse files
committed
Append .js to export statements as well
1 parent 79db65a commit 98a6997

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ class Main {
163163
this.#_helpers.extensions.add(fullPath);
164164
} else if (file.endsWith('.js')) {
165165
let content = fs.readFileSync(fullPath, 'utf8');
166+
167+
// Regex to match import statements
166168
content = content.replace(/(import\s+.*\s+from\s+['"])(.*)(['"];)/g, (match, p1, p2, p3) => {
167169
if (!p2.endsWith('.js') && !p2.startsWith('.') && !p2.startsWith('/')) {
168170
return match; // Skip non-relative imports
@@ -173,6 +175,19 @@ class Main {
173175
}
174176
return `${p1}${p2}.js${p3}`;
175177
});
178+
179+
// Regex to match export statements
180+
content = content.replace(/(export\s+\{\s*.*\s*}\s+from\s+['"])(.*)(['"];)/g, (match, p1, p2, p3) => {
181+
if (!p2.endsWith('.js') && !p2.startsWith('.') && !p2.startsWith('/')) {
182+
return match; // Skip non-relative exports
183+
}
184+
const lastPart = p2.split('/').pop();
185+
if (lastPart.includes('.') && lastPart.split('.').length > 1) {
186+
return match; // Skip if last part already has an extension
187+
}
188+
return `${p1}${p2}.js${p3}`;
189+
});
190+
176191
fs.writeFileSync(fullPath, content, 'utf8');
177192
}
178193
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nasriya/postbuild",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "A package that does some tasks after compilation",
55
"main": "main.js",
66
"type": "module",

0 commit comments

Comments
 (0)