Last active
June 13, 2023 16:24
-
-
Save ammmze/ce38fc64ecb257a8bfd3f98cbf6db8e6 to your computer and use it in GitHub Desktop.
Surfaces "use client" and "use server" directives to the top of the file. Workaround for https://github.com/swc-project/swc/issues/7315
This file contains hidden or 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
#!/usr/bin/env sh | |
# Workaround for https://github.com/swc-project/swc/issues/7315 | |
DIR="${1}" | |
if [ -z "${DIR}" ]; then | |
echo "Missing path to search" | |
echo "Usage: ${0} ./path-to-search" | |
exit 1 | |
fi | |
# Default case for Linux sed, just use "-i" | |
sedi=(-i) | |
case "$(uname)" in | |
# For macOS, use two parameters | |
Darwin*) sedi=(-i "") | |
esac | |
find "${DIR}" -type f -print \ | |
| xargs grep -l '"use client";' \ | |
| xargs -I{} sed "${sedi[@]}" -e '/^"use client";$/d' -e '1 i\ | |
"use client";' '{}' | |
find "${DIR}" -type f -print \ | |
| xargs grep -l '"use server";' \ | |
| xargs -I{} sed "${sedi[@]}" -e '/^"use server";$/d' -e '1 i\ | |
"use server";' '{}' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment