Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions config/cli/ts-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ EOT
"type": "module"
}
EOT
echo "Adding JSON type assertions for ESM build"
# Following command is designed to be both Mac OS and GNU Linux (Ubuntu) compatible.
#
# Some notes:
# - Usage of both -i and -e is needed for Mac OS compatibility
# https://stackoverflow.com/questions/4247068/sed-command-with-i-option-failing-on-mac-but-works-on-linux
#
# - Then -i option behavior differs between Mac OS and Linux (Mac OS creates backup files with -i'')
# Therefore the explicit addition of -i'.js-e' and the subsequent deletion
#
# - Using sed with a direct path minimally doesn't work using the command within this script on Mac OS
# Therefore the usage with the find command
#
find dist/esm -name "*.js" -exec sed -E -i'.js-e' -e "s/(from '[^']+\.json');/\1 assert { type: \"json\" };/" {} \;
find ./dist/esm -name "*.js-e" -type f -delete
else
echo "Skipping post build fixes (no ESM setup yet)."
fi
Expand Down