Unverified Commit 3f393037 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

codemod: unify comments prefix for dynamic api (#70970)

Co-authored-by: 's avatarSebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
parent f6906fcf
...@@ -2,7 +2,7 @@ import { cookies } from "next/headers"; ...@@ -2,7 +2,7 @@ import { cookies } from "next/headers";
async function MyComponent() { async function MyComponent() {
function asyncFunction() { function asyncFunction() {
callSomething(/* TODO: please manually await this call, if it's a server component, you can turn it to async function */ callSomething(/* Next.js Dynamic Async API Codemod: Manually await this call, if it's a Server Component */
cookies()); cookies());
} }
} }
import { cookies } from "next/headers"; import { cookies } from "next/headers";
function MyComponent() { function MyComponent() {
callSomething(/* TODO: please manually await this call, if it's a server component, you can turn it to async function */ callSomething(/* Next.js Dynamic Async API Codemod: Manually await this call, if it's a Server Component */
cookies()); cookies());
} }
...@@ -4,4 +4,4 @@ function myFunc() { ...@@ -4,4 +4,4 @@ function myFunc() {
nextHeaders.cookies() nextHeaders.cookies()
} }
const nextHeaders2 = /* The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers') const nextHeaders2 = /* Next.js Dynamic Async API Codemod: The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers')
\ No newline at end of file \ No newline at end of file
const nextHeaders = /* The APIs under 'next/headers' are async now, need to be manually awaited. */ const nextHeaders = /* Next.js Dynamic Async API Codemod: The APIs under 'next/headers' are async now, need to be manually awaited. */
import('next/headers') import('next/headers')
function myFunc() { function myFunc() {
nextHeaders.cookies() nextHeaders.cookies()
} }
const nextHeaders2 = /* The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers') const nextHeaders2 = /* Next.js Dynamic Async API Codemod: The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers')
\ No newline at end of file \ No newline at end of file
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
} from 'next/headers' } from 'next/headers'
export function MyDraftComponent() { export function MyDraftComponent() {
if (/* TODO: please manually await this call, if it's a server component, you can turn it to async function */ if (/* Next.js Dynamic Async API Codemod: Manually await this call, if it's a Server Component */
draftMode().isEnabled) { draftMode().isEnabled) {
return null return null
} }
...@@ -15,13 +15,13 @@ draftMode().isEnabled) { ...@@ -15,13 +15,13 @@ draftMode().isEnabled) {
} }
export function MyCookiesComponent() { export function MyCookiesComponent() {
const c = /* TODO: please manually await this call, if it's a server component, you can turn it to async function */ const c = /* Next.js Dynamic Async API Codemod: Manually await this call, if it's a Server Component */
cookies() cookies()
return c.get('name') return c.get('name')
} }
export function MyHeadersComponent() { export function MyHeadersComponent() {
const h = /* TODO: please manually await this call, if it's a server component, you can turn it to async function */ const h = /* Next.js Dynamic Async API Codemod: Manually await this call, if it's a Server Component */
headers() headers()
return ( return (
<p>{h.get('x-foo')}</p> <p>{h.get('x-foo')}</p>
......
export default function Page(props: any) { export default function Page(props: any) {
callback(/* 'props' is passed as an argument. Any asynchronous properties of 'props' must be awaited when accessed. */ callback(/* Next.js Dynamic Async API Codemod: 'props' is passed as an argument. Any asynchronous properties of 'props' must be awaited when accessed. */
props, 1) props, 1)
} }
export function generateMetadata(props) { export function generateMetadata(props) {
callback2(/* 'props' is passed as an argument. Any asynchronous properties of 'props' must be awaited when accessed. */ callback2(/* Next.js Dynamic Async API Codemod: 'props' is passed as an argument. Any asynchronous properties of 'props' must be awaited when accessed. */
props) props)
} }
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
insertCommentOnce, insertCommentOnce,
} from './utils' } from './utils'
const DYNAMIC_IMPORT_WARN_COMMENT = ` The APIs under 'next/headers' are async now, need to be manually awaited. ` const DYNAMIC_IMPORT_WARN_COMMENT = ` Next.js Dynamic Async API Codemod: The APIs under 'next/headers' are async now, need to be manually awaited. `
function findDynamicImportsAndComment(root: Collection<any>, j: API['j']) { function findDynamicImportsAndComment(root: Collection<any>, j: API['j']) {
let modified = false let modified = false
...@@ -187,7 +187,7 @@ export function transformDynamicAPI( ...@@ -187,7 +187,7 @@ export function transformDynamicAPI(
root, root,
filePath, filePath,
insertedTypes, insertedTypes,
` TODO: please manually await this call, if it's a server component, you can turn it to async function ` ` Next.js Dynamic Async API Codemod: Manually await this call, if it's a Server Component `
) )
} }
} else { } else {
...@@ -198,7 +198,7 @@ export function transformDynamicAPI( ...@@ -198,7 +198,7 @@ export function transformDynamicAPI(
root, root,
filePath, filePath,
insertedTypes, insertedTypes,
' TODO: please manually await this call, codemod cannot transform due to undetermined async scope ' ' Next.js Dynamic Async API Codemod: please manually await this call, codemod cannot transform due to undetermined async scope '
) )
} }
modified = true modified = true
......
...@@ -406,7 +406,7 @@ export function transformDynamicProps( ...@@ -406,7 +406,7 @@ export function transformDynamicProps(
const propPassedAsArg = args.find( const propPassedAsArg = args.find(
(arg) => j.Identifier.check(arg) && arg.name === argName (arg) => j.Identifier.check(arg) && arg.name === argName
) )
const comment = ` '${argName}' is passed as an argument. Any asynchronous properties of 'props' must be awaited when accessed. ` const comment = ` Next.js Dynamic Async API Codemod: '${argName}' is passed as an argument. Any asynchronous properties of 'props' must be awaited when accessed. `
insertCommentOnce(propPassedAsArg, j, comment) insertCommentOnce(propPassedAsArg, j, comment)
modified = true modified = true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment