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";
async function MyComponent() {
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());
}
}
import { cookies } from "next/headers";
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());
}
......@@ -4,4 +4,4 @@ function myFunc() {
nextHeaders.cookies()
}
const nextHeaders2 = /* The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers')
\ No newline at end of file
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
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')
function myFunc() {
nextHeaders.cookies()
}
const nextHeaders2 = /* The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers')
\ No newline at end of file
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
......@@ -6,7 +6,7 @@ import {
} from 'next/headers'
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) {
return null
}
......@@ -15,13 +15,13 @@ draftMode().isEnabled) {
}
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()
return c.get('name')
}
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()
return (
<p>{h.get('x-foo')}</p>
......
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)
}
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)
}
......@@ -11,7 +11,7 @@ import {
insertCommentOnce,
} 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']) {
let modified = false
......@@ -187,7 +187,7 @@ export function transformDynamicAPI(
root,
filePath,
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 {
......@@ -198,7 +198,7 @@ export function transformDynamicAPI(
root,
filePath,
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
......
......@@ -406,7 +406,7 @@ export function transformDynamicProps(
const propPassedAsArg = args.find(
(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)
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