Skip to content

Commit 82a1485

Browse files
committed
Added support for standalone imports (import 'destination')
1 parent ab7ae02 commit 82a1485

File tree

4 files changed

+103
-26
lines changed

4 files changed

+103
-26
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# Ignore node_modules folder
22
node_modules/
3-
.vscode/
3+
.vscode/
4+
.history

main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ class Main {
160160
} else if (file.endsWith('.js')) {
161161
let content = fs.readFileSync(fullPath, 'utf8');
162162

163-
// Regex to match import statements
164-
content = content.replace(/(import\s+.*\s+from\s+['"])(.*)(['"];)/g, (match, p1, p2, p3) => {
165-
if (!p2.endsWith('.js') && !p2.startsWith('.') && !p2.startsWith('/')) {
166-
return match; // Skip non-relative imports
167-
}
168-
const lastPart = p2.split('/').pop();
169-
if (lastPart.includes('.') && lastPart.split('.').length > 1) {
170-
return match; // Skip if last part already has an extension
163+
// Regex to match import statements with or without named import
164+
content = content.replace(/(import\s+((\w+|\{\s*.*\s*})\s+from\s+['"])(.*)(['"];))/g, (match, p1, p2, p3, p4, p5) => {
165+
// Skip if already has an extension or is not relative
166+
if (!p4.endsWith('.js') && (p4.startsWith('.') || p4.startsWith('/'))) {
167+
const lastPart = p4.split('/').pop();
168+
if (!lastPart.includes('.') || lastPart.split('.').length === 1) {
169+
return `${p1.slice(0, -p5.length)}${p4}.js${p5}`;
170+
}
171171
}
172-
return `${p1}${p2}.js${p3}`;
172+
return match;
173173
});
174174

175175
// Regex to match export statements

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"homepage": "https://github.com/nasriyasoftware/PostBuild#readme",
4040
"devDependencies": {
4141
"@types/jest": "^29.5.12",
42-
"@types/node": "^20.14.2",
42+
"@types/node": "^22.1.0",
4343
"jest": "^29.7.0",
44-
"ts-jest": "^29.1.4"
44+
"ts-jest": "^29.2.4"
4545
}
4646
}

0 commit comments

Comments
 (0)