diff --git a/main.js b/main.js index efd1fac..5695bbc 100644 --- a/main.js +++ b/main.js @@ -163,6 +163,8 @@ class Main { this.#_helpers.extensions.add(fullPath); } else if (file.endsWith('.js')) { let content = fs.readFileSync(fullPath, 'utf8'); + + // Regex to match import statements content = content.replace(/(import\s+.*\s+from\s+['"])(.*)(['"];)/g, (match, p1, p2, p3) => { if (!p2.endsWith('.js') && !p2.startsWith('.') && !p2.startsWith('/')) { return match; // Skip non-relative imports @@ -173,6 +175,19 @@ class Main { } return `${p1}${p2}.js${p3}`; }); + + // Regex to match export statements + content = content.replace(/(export\s+\{\s*.*\s*}\s+from\s+['"])(.*)(['"];)/g, (match, p1, p2, p3) => { + if (!p2.endsWith('.js') && !p2.startsWith('.') && !p2.startsWith('/')) { + return match; // Skip non-relative exports + } + const lastPart = p2.split('/').pop(); + if (lastPart.includes('.') && lastPart.split('.').length > 1) { + return match; // Skip if last part already has an extension + } + return `${p1}${p2}.js${p3}`; + }); + fs.writeFileSync(fullPath, content, 'utf8'); } }); diff --git a/package.json b/package.json index 4fa7a3f..59c4809 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nasriya/postbuild", - "version": "1.0.4", + "version": "1.0.5", "description": "A package that does some tasks after compilation", "main": "main.js", "type": "module",