Skip to content

Instantly share code, notes, and snippets.

@hanford
Created October 10, 2022 17:40
Show Gist options
  • Save hanford/39680e8183942e41d8bac1b7602dc61f to your computer and use it in GitHub Desktop.
Save hanford/39680e8183942e41d8bac1b7602dc61f to your computer and use it in GitHub Desktop.
// Append "'client';" to beginnging of all Pages
export const parser = "tsx";
export default function transformer(file, api) {
const j = api.jscodeshift;
const root = j(file.source);
const clientCommentBlock = j.expressionStatement(j.stringLiteral("client"));
const firstNode = root.find(j.Program).get("body", 0);
if (firstNode.comments) {
clientCommentBlock.comments = firstNode.comments;
}
firstNode.insertBefore(clientCommentBlock);
return root.toSource();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment