Skip to content

Instantly share code, notes, and snippets.

@reggi
Created September 19, 2024 17:42
Show Gist options
  • Save reggi/68be8cf9a80f1545e67d0fca0402d696 to your computer and use it in GitHub Desktop.
Save reggi/68be8cf9a80f1545e67d0fca0402d696 to your computer and use it in GitHub Desktop.
#!/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