@next/codemod 15.0.0-canary.177 → 15.0.0-canary.178

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/codemod",
3
- "version": "15.0.0-canary.177",
3
+ "version": "15.0.0-canary.178",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -144,6 +144,30 @@ function transformDynamicAPI(source, api, filePath) {
144
144
  }
145
145
  }
146
146
  });
147
+ // Handle type usage of async API, e.g. `type Cookie = ReturnType<typeof cookies>`
148
+ // convert it to `type Cookie = Awaited<ReturnType<typeof cookies>>`
149
+ root
150
+ .find(j.TSTypeReference, {
151
+ typeName: {
152
+ type: 'Identifier',
153
+ name: 'ReturnType',
154
+ },
155
+ })
156
+ .forEach((path) => {
157
+ const typeParam = path.node.typeParameters?.params[0];
158
+ // Check if the ReturnType is for 'cookies'
159
+ if (typeParam &&
160
+ j.TSTypeQuery.check(typeParam) &&
161
+ j.Identifier.check(typeParam.exprName) &&
162
+ typeParam.exprName.name === asyncRequestApiName) {
163
+ // Replace ReturnType<typeof cookies> with Awaited<ReturnType<typeof cookies>>
164
+ const awaitedTypeReference = j.tsTypeReference(j.identifier('Awaited'), j.tsTypeParameterInstantiation([
165
+ j.tsTypeReference(j.identifier('ReturnType'), j.tsTypeParameterInstantiation([typeParam])),
166
+ ]));
167
+ j(path).replaceWith(awaitedTypeReference);
168
+ modified = true;
169
+ }
170
+ });
147
171
  }
148
172
  const isClientComponent = (0, utils_1.determineClientDirective)(root, j);
149
173
  // Only transform the valid calls in server or shared components