@next/codemod 15.0.0-canary.19 → 15.0.0-canary.190

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.
Files changed (32) hide show
  1. package/bin/next-codemod.js +41 -3
  2. package/bin/transform.js +124 -0
  3. package/bin/upgrade.js +290 -0
  4. package/lib/cra-to-next/global-css-transform.js +5 -5
  5. package/lib/cra-to-next/index-to-component.js +5 -5
  6. package/lib/handle-package.js +63 -0
  7. package/lib/install.js +2 -3
  8. package/lib/parser.js +28 -0
  9. package/lib/run-jscodeshift.js +18 -2
  10. package/lib/utils.js +115 -0
  11. package/package.json +12 -6
  12. package/transforms/add-missing-react-import.js +4 -3
  13. package/transforms/app-dir-runtime-config-experimental-edge.js +34 -0
  14. package/transforms/built-in-next-font.js +4 -3
  15. package/transforms/cra-to-next.js +238 -236
  16. package/transforms/lib/async-request-api/index.js +16 -0
  17. package/transforms/lib/async-request-api/next-async-dynamic-api.js +274 -0
  18. package/transforms/lib/async-request-api/next-async-dynamic-prop.js +715 -0
  19. package/transforms/lib/async-request-api/utils.js +374 -0
  20. package/transforms/metadata-to-viewport-export.js +4 -3
  21. package/transforms/name-default-component.js +6 -6
  22. package/transforms/new-link.js +9 -7
  23. package/transforms/next-async-request-api.js +9 -0
  24. package/transforms/next-dynamic-access-named-export.js +66 -0
  25. package/transforms/next-image-experimental.js +12 -15
  26. package/transforms/next-image-to-legacy-image.js +8 -9
  27. package/transforms/next-og-import.js +4 -3
  28. package/transforms/next-request-geo-ip.js +339 -0
  29. package/transforms/url-to-withrouter.js +1 -1
  30. package/transforms/withamp-to-config.js +1 -1
  31. package/bin/cli.js +0 -216
  32. package/lib/uninstall-package.js +0 -32
@@ -3,12 +3,28 @@ 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) {
9
10
  // we run jscodeshift in the same process to be able to
10
11
  // share state between the main CRA transform and sub-transforms
11
- 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
+ return Runner_1.default.run(transformerPath, files, {
13
+ ignorePattern: [
14
+ '**/node_modules/**',
15
+ '**/.next/**',
16
+ '**/build/**',
17
+ // test files
18
+ '**/*.test.*',
19
+ '**/*.spec.*',
20
+ '**/__tests__/**',
21
+ '**/__mocks__/**',
22
+ ],
23
+ extensions: 'tsx,ts,jsx,js',
24
+ parser: 'tsx',
25
+ verbose: 2,
26
+ runInBand: true,
27
+ ...flags,
28
+ });
12
29
  }
13
- exports.default = runJscodeshift;
14
30
  //# sourceMappingURL=run-jscodeshift.js.map
package/lib/utils.js ADDED
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TRANSFORMER_INQUIRER_CHOICES = void 0;
7
+ exports.checkGitStatus = checkGitStatus;
8
+ exports.onCancel = onCancel;
9
+ const picocolors_1 = require("picocolors");
10
+ const is_git_clean_1 = __importDefault(require("is-git-clean"));
11
+ function checkGitStatus(force) {
12
+ let clean = false;
13
+ let errorMessage = 'Unable to determine if git directory is clean';
14
+ try {
15
+ clean = is_git_clean_1.default.sync(process.cwd());
16
+ errorMessage = 'Git directory is not clean';
17
+ }
18
+ catch (err) {
19
+ if (err && err.stderr && err.stderr.includes('Not a git repository')) {
20
+ clean = true;
21
+ }
22
+ }
23
+ if (!clean) {
24
+ if (force) {
25
+ console.log(`WARNING: ${errorMessage}. Forcibly continuing.`);
26
+ }
27
+ else {
28
+ console.log('Thank you for using @next/codemod!');
29
+ console.log((0, picocolors_1.yellow)('\nBut before we continue, please stash or commit your git changes.'));
30
+ console.log('\nYou may use the --force flag to override this safety check.');
31
+ process.exit(1);
32
+ }
33
+ }
34
+ }
35
+ function onCancel() {
36
+ process.exit(1);
37
+ }
38
+ exports.TRANSFORMER_INQUIRER_CHOICES = [
39
+ {
40
+ title: 'Transform the deprecated automatically injected url property on top level pages to using withRouter',
41
+ value: 'url-to-withrouter',
42
+ version: '6.0.0',
43
+ },
44
+ {
45
+ title: 'Transforms the withAmp HOC into Next.js 9 page configuration',
46
+ value: 'withamp-to-config',
47
+ version: '8.0.0',
48
+ },
49
+ {
50
+ title: 'Transforms anonymous components into named components to make sure they work with Fast Refresh',
51
+ value: 'name-default-component',
52
+ version: '9.0.0',
53
+ },
54
+ {
55
+ title: 'Transforms files that do not import `React` to include the import in order for the new React JSX transform',
56
+ value: 'add-missing-react-import',
57
+ version: '10.0.0',
58
+ },
59
+ {
60
+ title: 'Automatically migrates a Create React App project to Next.js (experimental)',
61
+ value: 'cra-to-next',
62
+ version: '11.0.0',
63
+ },
64
+ {
65
+ title: 'Ensures your <Link> usage is backwards compatible',
66
+ value: 'new-link',
67
+ version: '13.0.0',
68
+ },
69
+ {
70
+ title: 'Dangerously migrates from `next/legacy/image` to the new `next/image` by adding inline styles and removing unused props (experimental)',
71
+ value: 'next-image-experimental',
72
+ version: '13.0.0',
73
+ },
74
+ {
75
+ title: 'Safely migrate Next.js 10, 11, 12 applications importing `next/image` to the renamed `next/legacy/image` import in Next.js 13',
76
+ value: 'next-image-to-legacy-image',
77
+ version: '13.0.0',
78
+ },
79
+ {
80
+ title: 'Uninstall `@next/font` and transform imports to `next/font`',
81
+ value: 'built-in-next-font',
82
+ version: '13.2.0',
83
+ },
84
+ {
85
+ title: 'Migrates certain viewport related metadata from the `metadata` export to a new `viewport` export',
86
+ value: 'metadata-to-viewport-export',
87
+ version: '14.0.0',
88
+ },
89
+ {
90
+ title: 'Transforms imports from `next/server` to `next/og` for usage of Dynamic OG Image Generation',
91
+ value: 'next-og-import',
92
+ version: '14.0.0',
93
+ },
94
+ {
95
+ title: 'Transform `next/dynamic` imports accessing named exports to return an object with a `default` property',
96
+ value: 'next-dynamic-access-named-export',
97
+ version: '15.0.0-canary.44',
98
+ },
99
+ {
100
+ title: 'Install `@vercel/functions` to replace `geo` and `ip` properties on `NextRequest`',
101
+ value: 'next-request-geo-ip',
102
+ version: '15.0.0-canary.153',
103
+ },
104
+ {
105
+ title: 'Transforms usage of Next.js async Request APIs',
106
+ value: 'next-async-request-api',
107
+ version: '15.0.0-canary.171',
108
+ },
109
+ {
110
+ title: 'Transform App Router Route Segment Config `runtime` value from `experimental-edge` to `edge`',
111
+ value: 'app-dir-runtime-config-experimental-edge',
112
+ version: '15.0.0-canary.179',
113
+ },
114
+ ];
115
+ //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/codemod",
3
- "version": "15.0.0-canary.19",
3
+ "version": "15.0.0-canary.190",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,16 +9,19 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "cheerio": "1.0.0-rc.9",
12
+ "commander": "12.1.0",
12
13
  "execa": "4.0.3",
14
+ "find-up": "4.1.0",
13
15
  "globby": "11.0.1",
14
- "inquirer": "7.3.3",
15
16
  "is-git-clean": "1.1.0",
16
- "jscodeshift": "0.13.1",
17
- "meow": "7.0.1",
18
- "picocolors": "1.0.0"
17
+ "jscodeshift": "17.0.0",
18
+ "picocolors": "1.0.0",
19
+ "prompts": "2.4.2",
20
+ "semver": "7.6.3"
19
21
  },
20
22
  "files": [
21
23
  "transforms/*.js",
24
+ "transforms/lib/**/*.js",
22
25
  "bin/*.js",
23
26
  "lib/**/*.js",
24
27
  "lib/cra-to-next/gitignore"
@@ -31,6 +34,9 @@
31
34
  },
32
35
  "bin": "./bin/next-codemod.js",
33
36
  "devDependencies": {
34
- "@types/jscodeshift": "0.11.0"
37
+ "@types/find-up": "4.0.0",
38
+ "@types/jscodeshift": "0.11.0",
39
+ "@types/prompts": "2.4.2",
40
+ "@types/semver": "7.3.1"
35
41
  }
36
42
  }
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ const parser_1 = require("../lib/parser");
3
5
  function addReactImport(j, root) {
4
6
  // We create an import specifier, this is the value of an import, eg:
5
7
  // import React from 'react'
@@ -33,8 +35,8 @@ function addReactImport(j, root) {
33
35
  node.value.body.unshift(ReactImport);
34
36
  });
35
37
  }
36
- function transformer(file, api, options) {
37
- const j = api.jscodeshift.withParser('tsx');
38
+ function transformer(file, _api, options) {
39
+ const j = (0, parser_1.createParserFromPath)(file.path);
38
40
  const root = j(file.source);
39
41
  const hasReactImport = (r) => {
40
42
  return (r.find(j.ImportDefaultSpecifier, {
@@ -60,5 +62,4 @@ function transformer(file, api, options) {
60
62
  }
61
63
  return root.toSource(options);
62
64
  }
63
- exports.default = transformer;
64
65
  //# sourceMappingURL=add-missing-react-import.js.map
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = transformer;
4
+ const parser_1 = require("../lib/parser");
5
+ function transformer(file, _api) {
6
+ if (process.env.NODE_ENV !== 'test' &&
7
+ !/[/\\]app[/\\].*?(page|layout|route)\.[^/\\]+$/.test(file.path)) {
8
+ return file.source;
9
+ }
10
+ const j = (0, parser_1.createParserFromPath)(file.path);
11
+ const root = j(file.source);
12
+ const runtimeExport = root.find(j.ExportNamedDeclaration, {
13
+ declaration: {
14
+ type: 'VariableDeclaration',
15
+ declarations: [
16
+ {
17
+ id: { name: 'runtime' },
18
+ },
19
+ ],
20
+ },
21
+ });
22
+ if (runtimeExport.size() !== 1) {
23
+ return file.source;
24
+ }
25
+ const runtimeValue = runtimeExport.find(j.StringLiteral, {
26
+ value: 'experimental-edge',
27
+ });
28
+ if (runtimeValue.size() !== 1) {
29
+ return file.source;
30
+ }
31
+ runtimeValue.replaceWith(j.stringLiteral('edge'));
32
+ return root.toSource();
33
+ }
34
+ //# sourceMappingURL=app-dir-runtime-config-experimental-edge.js.map
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- function transformer(file, api, options) {
4
- const j = api.jscodeshift.withParser('tsx');
3
+ exports.default = transformer;
4
+ const parser_1 = require("../lib/parser");
5
+ function transformer(file, _api, options) {
6
+ const j = (0, parser_1.createParserFromPath)(file.path);
5
7
  const root = j(file.source);
6
8
  let hasChanges = false;
7
9
  // Before: import { ... } from '@next/font'
@@ -36,5 +38,4 @@ function transformer(file, api, options) {
36
38
  });
37
39
  return hasChanges ? root.toSource(options) : file.source;
38
40
  }
39
- exports.default = transformer;
40
41
  //# sourceMappingURL=built-in-next-font.js.map