Skip to content

Commit

Permalink
ESM support
Browse files Browse the repository at this point in the history
  • Loading branch information
ilovepixelart committed Dec 5, 2023
1 parent 70858d6 commit 1f2c00f
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 150 deletions.
19 changes: 19 additions & 0 deletions bash/esm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Define the directory to start the search
root_directory="dist/esm"

echo "Adding .js extension to relative imports in files:"
# Find all JavaScript files and iterate through them and add the .js extension to relative imports
find "$root_directory" -type f -name "*.js" | while read -r file; do
if awk '!/export {};|\/\/# sourceMappingURL:|^[[:space:]]*\/\//' "$file" | grep -q "import .* from '[.]\{0,2\}\/[^']*'"; then
sed -i.bak -E "s/(import .* from '[.]{0,2}\/[^']*)'/\1.js'/g" "$file" && echo "- $file"
fi
done

# Remove all backup files
find "$root_directory" -type f -name "*.bak" -exec rm {} +

echo -e "\nCreating package.json file in $root_directory"
# Create a package.json file to indicate that this is an ESM package
echo '{ "type": "module" }' > "$root_directory/package.json"
3 changes: 1 addition & 2 deletions config/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"rootDir": "../src",
"outDir": "../dist/cjs",
"declarationDir": "../dist/cjs/types",
"module": "commonjs",
"moduleResolution": "node",
"module": "CommonJS"
}
}
3 changes: 1 addition & 2 deletions config/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"rootDir": "../src",
"outDir": "../dist/esm",
"declarationDir": "../dist/esm/types",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"module": "ESNext"
}
}
Loading

0 comments on commit 1f2c00f

Please sign in to comment.