Skip to content

Commit

Permalink
codemod: unify comments prefix for dynamic api (#70970)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian "Sebbie" Silbermann <[email protected]>
  • Loading branch information
2 people authored and kdy1 committed Oct 10, 2024
1 parent de28b60 commit a1947e8
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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());
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
const nextHeaders2 = /* Next.js Dynamic Async API Codemod: The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers')
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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')
const nextHeaders2 = /* Next.js Dynamic Async API Codemod: The APIs under 'next/headers' are async now, need to be manually awaited. */ import('next/headers')
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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)
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1947e8

Please sign in to comment.