Created
September 19, 2024 17:42
-
-
Save reggi/68be8cf9a80f1545e67d0fca0402d696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get the list of dependencies from package.json | |
DEPENDENCIES=$(jq -r '.dependencies | keys[]' package.json) | |
# Loop through each dependency | |
for DEP in $DEPENDENCIES; do | |
# Get the path to the dependency's package.json | |
DEP_PACKAGE_JSON="node_modules/$DEP/package.json" | |
# Check if the dependency's package.json exists | |
if [ -f "$DEP_PACKAGE_JSON" ]; then | |
# Get the type field from the dependency's package.json | |
TYPE=$(jq -r '.type // "not specified"' "$DEP_PACKAGE_JSON") | |
# Check if type is module | |
if [ "$TYPE" == "module" ]; then | |
# Check if exports['.'].require does not exist | |
EXPORTS_REQUIRE_EXISTS=$(jq -r 'if (.exports | type == "object") and .exports["."] and .exports["."].require then "exists" else "not exists" end' "$DEP_PACKAGE_JSON") | |
if [ "$EXPORTS_REQUIRE_EXISTS" == "not exists" ]; then | |
echo "Dependency: $DEP is ESM only" | |
fi | |
fi | |
else | |
echo "Dependency: $DEP, package.json not found!" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment