@next/codemod 15.0.0-canary.6 → 15.0.0-canary.61

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/bin/cli.js CHANGED
@@ -12,7 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.run = exports.runTransform = exports.checkGitStatus = exports.transformerDirectory = exports.jscodeshiftExecutable = void 0;
15
+ exports.transformerDirectory = exports.jscodeshiftExecutable = void 0;
16
+ exports.checkGitStatus = checkGitStatus;
17
+ exports.runTransform = runTransform;
18
+ exports.run = run;
16
19
  const globby_1 = __importDefault(require("globby"));
17
20
  const inquirer_1 = __importDefault(require("inquirer"));
18
21
  const meow_1 = __importDefault(require("meow"));
@@ -47,7 +50,6 @@ function checkGitStatus(force) {
47
50
  }
48
51
  }
49
52
  }
50
- exports.checkGitStatus = checkGitStatus;
51
53
  function runTransform({ files, flags, transformer }) {
52
54
  const transformerPath = path_1.default.join(exports.transformerDirectory, `${transformer}.js`);
53
55
  if (transformer === 'cra-to-next') {
@@ -92,7 +94,6 @@ function runTransform({ files, flags, transformer }) {
92
94
  }
93
95
  }
94
96
  }
95
- exports.runTransform = runTransform;
96
97
  const TRANSFORMER_INQUIRER_CHOICES = [
97
98
  {
98
99
  name: 'name-default-component: Transforms anonymous components into named components to make sure they work with Fast Refresh',
@@ -126,6 +127,10 @@ const TRANSFORMER_INQUIRER_CHOICES = [
126
127
  name: 'metadata-to-viewport-export: Migrates certain viewport related metadata from the `metadata` export to a new `viewport` export.',
127
128
  value: 'metadata-to-viewport-export',
128
129
  },
130
+ {
131
+ name: 'next-dynamic-access-named-export: Transforms dynamic imports that return the named export itself to a module like object.',
132
+ value: 'next-dynamic-access-named-export',
133
+ },
129
134
  {
130
135
  name: 'next-image-to-legacy-image: safely migrate Next.js 10, 11, 12 applications importing `next/image` to the renamed `next/legacy/image` import in Next.js 13',
131
136
  value: 'next-image-to-legacy-image',
@@ -212,5 +217,4 @@ function run() {
212
217
  });
213
218
  });
214
219
  }
215
- exports.run = run;
216
220
  //# sourceMappingURL=cli.js.map
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.globalCssContext = void 0;
7
+ exports.default = transformer;
7
8
  const path_1 = __importDefault(require("path"));
8
9
  exports.globalCssContext = {
9
10
  cssImports: new Set(),
@@ -52,5 +53,4 @@ function transformer(file, api, options) {
52
53
  ? root.toSource(options)
53
54
  : null;
54
55
  }
55
- exports.default = transformer;
56
56
  //# sourceMappingURL=global-css-transform.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.indexContext = void 0;
4
+ exports.default = transformer;
4
5
  exports.indexContext = {
5
6
  multipleRenderRoots: false,
6
7
  nestedRender: false,
@@ -73,5 +74,4 @@ function transformer(file, api, options) {
73
74
  // }).remove()
74
75
  return hasModifications ? root.toSource(options) : null;
75
76
  }
76
- exports.default = transformer;
77
77
  //# sourceMappingURL=index-to-component.js.map
package/lib/install.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.install = void 0;
6
+ exports.install = install;
7
7
  /* eslint-disable import/no-extraneous-dependencies */
8
8
  const picocolors_1 = require("picocolors");
9
9
  const cross_spawn_1 = __importDefault(require("cross-spawn"));
@@ -95,5 +95,4 @@ function install(root, dependencies, { useYarn, isOnline, devDependencies }) {
95
95
  });
96
96
  });
97
97
  }
98
- exports.install = install;
99
98
  //# sourceMappingURL=install.js.map
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = runJscodeshift;
6
7
  // @ts-ignore internal module
7
8
  const Runner_1 = __importDefault(require("jscodeshift/src/Runner"));
8
9
  function runJscodeshift(transformerPath, flags, files) {
@@ -10,5 +11,4 @@ function runJscodeshift(transformerPath, flags, files) {
10
11
  // share state between the main CRA transform and sub-transforms
11
12
  return Runner_1.default.run(transformerPath, files, Object.assign({ ignorePattern: ['**/node_modules/**', '**/.next/**', '**/build/**'], extensions: 'tsx,ts,jsx,js', parser: 'tsx', verbose: 2, runInBand: true }, flags));
12
13
  }
13
- exports.default = runJscodeshift;
14
14
  //# sourceMappingURL=run-jscodeshift.js.map
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.uninstallPackage = void 0;
6
+ exports.uninstallPackage = uninstallPackage;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const execa_1 = __importDefault(require("execa"));
@@ -28,5 +28,4 @@ function uninstallPackage(packageToUninstall) {
28
28
  }
29
29
  execa_1.default.sync(pkgManager, [command, packageToUninstall], { stdio: 'inherit' });
30
30
  }
31
- exports.uninstallPackage = uninstallPackage;
32
31
  //# sourceMappingURL=uninstall-package.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/codemod",
3
- "version": "15.0.0-canary.6",
3
+ "version": "15.0.0-canary.61",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function addReactImport(j, root) {
4
5
  // We create an import specifier, this is the value of an import, eg:
5
6
  // import React from 'react'
@@ -60,5 +61,4 @@ function transformer(file, api, options) {
60
61
  }
61
62
  return root.toSource(options);
62
63
  }
63
- exports.default = transformer;
64
64
  //# sourceMappingURL=add-missing-react-import.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function transformer(file, api, options) {
4
5
  const j = api.jscodeshift.withParser('tsx');
5
6
  const root = j(file.source);
@@ -36,5 +37,4 @@ function transformer(file, api, options) {
36
37
  });
37
38
  return hasChanges ? root.toSource(options) : file.source;
38
39
  }
39
- exports.default = transformer;
40
40
  //# sourceMappingURL=built-in-next-font.js.map
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.default = transformer;
15
16
  const fs_1 = __importDefault(require("fs"));
16
17
  const path_1 = __importDefault(require("path"));
17
18
  const execa_1 = __importDefault(require("execa"));
@@ -440,5 +441,4 @@ function transformer(files, flags) {
440
441
  }
441
442
  });
442
443
  }
443
- exports.default = transformer;
444
444
  //# sourceMappingURL=cra-to-next.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function transformer(file, api) {
4
5
  const j = api.jscodeshift;
5
6
  const root = j(file.source);
@@ -56,5 +57,4 @@ function transformer(file, api) {
56
57
  }
57
58
  return root.toSource();
58
59
  }
59
- exports.default = transformer;
60
60
  //# sourceMappingURL=metadata-to-viewport-export.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  const path_1 = require("path");
4
5
  const camelCase = (value) => {
5
6
  const val = value.replace(/[-_\s.]+(.)?/g, (_match, chr) => chr ? chr.toUpperCase() : '');
@@ -62,5 +63,4 @@ function transformer(file, api, options) {
62
63
  root.find(j.ExportDefaultDeclaration).forEach(nameFunctionComponent);
63
64
  return hasModifications ? root.toSource(options) : null;
64
65
  }
65
- exports.default = transformer;
66
66
  //# sourceMappingURL=name-default-component.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function transformer(file, api) {
4
5
  const j = api.jscodeshift.withParser('tsx');
5
6
  const $j = j(file.source);
@@ -86,5 +87,4 @@ function transformer(file, api) {
86
87
  })
87
88
  .toSource();
88
89
  }
89
- exports.default = transformer;
90
90
  //# sourceMappingURL=new-link.js.map
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ function transformer(file, api) {
5
+ var _a, _b, _c;
6
+ const j = api.jscodeshift;
7
+ const root = j(file.source);
8
+ // Find the import declaration for 'next/dynamic'
9
+ const dynamicImportDeclaration = root.find(j.ImportDeclaration, {
10
+ source: { value: 'next/dynamic' },
11
+ });
12
+ // If the import declaration is found
13
+ if (dynamicImportDeclaration.size() > 0) {
14
+ const importDecl = dynamicImportDeclaration.get(0).node;
15
+ const dynamicImportName = (_c = (_b = (_a = importDecl.specifiers) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.local) === null || _c === void 0 ? void 0 : _c.name;
16
+ if (!dynamicImportName) {
17
+ return root.toSource();
18
+ }
19
+ // Find call expressions where the callee is the imported 'dynamic'
20
+ root
21
+ .find(j.CallExpression, {
22
+ callee: { name: dynamicImportName },
23
+ })
24
+ .forEach((path) => {
25
+ var _a;
26
+ const arrowFunction = path.node.arguments[0];
27
+ // Ensure the argument is an ArrowFunctionExpression
28
+ if (arrowFunction && arrowFunction.type === 'ArrowFunctionExpression') {
29
+ const importCall = arrowFunction.body;
30
+ // Ensure the parent of the import call is a CallExpression with a .then
31
+ if (importCall &&
32
+ importCall.type === 'CallExpression' &&
33
+ importCall.callee.type === 'MemberExpression' &&
34
+ 'name' in importCall.callee.property &&
35
+ importCall.callee.property.name === 'then') {
36
+ const thenFunction = importCall.arguments[0];
37
+ // handle case of block statement case `=> { return mod.Component }`
38
+ // transform to`=> { return { default: mod.Component } }`
39
+ if (thenFunction &&
40
+ thenFunction.type === 'ArrowFunctionExpression' &&
41
+ thenFunction.body.type === 'BlockStatement') {
42
+ const returnStatement = thenFunction.body.body[0];
43
+ // Ensure the body of the arrow function has a return statement with a MemberExpression
44
+ if (returnStatement &&
45
+ returnStatement.type === 'ReturnStatement' &&
46
+ ((_a = returnStatement.argument) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression') {
47
+ returnStatement.argument = j.objectExpression([
48
+ j.property('init', j.identifier('default'), returnStatement.argument),
49
+ ]);
50
+ }
51
+ }
52
+ // handle case `=> mod.Component`
53
+ // transform to`=> ({ default: mod.Component })`
54
+ if (thenFunction &&
55
+ thenFunction.type === 'ArrowFunctionExpression' &&
56
+ thenFunction.body.type === 'MemberExpression') {
57
+ thenFunction.body = j.objectExpression([
58
+ j.property('init', j.identifier('default'), thenFunction.body),
59
+ ]);
60
+ }
61
+ }
62
+ }
63
+ });
64
+ }
65
+ return root.toSource();
66
+ }
67
+ //# sourceMappingURL=next-dynamic-access-named-export.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  const path_1 = require("path");
4
5
  const fs_1 = require("fs");
5
6
  function findAndReplaceProps(j, root, tagName) {
@@ -248,5 +249,4 @@ function transformer(file, api, options) {
248
249
  // TODO: do the same transforms for dynamic imports
249
250
  return root.toSource(options);
250
251
  }
251
- exports.default = transformer;
252
252
  //# sourceMappingURL=next-image-experimental.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  function transformer(file, api, options) {
4
5
  const j = api.jscodeshift.withParser('tsx');
5
6
  const root = j(file.source);
@@ -75,5 +76,4 @@ function transformer(file, api, options) {
75
76
  // https://www.codeshiftcommunity.com/docs/import-manipulation/#replacerename-an-import-declaration
76
77
  return root.toSource(options);
77
78
  }
78
- exports.default = transformer;
79
79
  //# sourceMappingURL=next-image-to-legacy-image.js.map
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
3
4
  const importToChange = 'ImageResponse';
4
5
  function transformer(file, api) {
5
6
  const j = api.jscodeshift;
@@ -31,5 +32,4 @@ function transformer(file, api) {
31
32
  .toSource();
32
33
  return file.source;
33
34
  }
34
- exports.default = transformer;
35
35
  //# sourceMappingURL=next-og-import.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // One-time usage file. You can delete me after running the codemod!
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = transformer;
4
5
  function addWithRouterImport(j, root) {
5
6
  // We create an import specifier, this is the value of an import, eg:
6
7
  // import {withRouter} from 'next/router
@@ -317,5 +318,4 @@ function transformer(file, api) {
317
318
  });
318
319
  return root.toSource();
319
320
  }
320
- exports.default = transformer;
321
321
  //# sourceMappingURL=url-to-withrouter.js.map
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  // One-time usage file. You can delete me after running the codemod!
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.default = transformer;
4
5
  function injectAmp(j, o, desiredAmpValue) {
5
6
  const init = o.node.init;
6
7
  switch (init.type) {
@@ -131,5 +132,4 @@ function transformer(file, api) {
131
132
  }
132
133
  return done();
133
134
  }
134
- exports.default = transformer;
135
135
  //# sourceMappingURL=withamp-to-config.js.map