@strapi/upgrade 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.f78dd29ef270559728250589cde1cfb0b9f7343a
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/LICENSE +19 -4
- package/README.md +1 -1
- package/dist/cli.js +13 -1451
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +14 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.js +9 -1428
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -1420
- package/dist/index.mjs.map +1 -1
- package/dist/modules/codemod-repository/constants.d.ts.map +1 -1
- package/dist/modules/error/utils.d.ts +8 -0
- package/dist/modules/error/utils.d.ts.map +1 -1
- package/dist/modules/file-scanner/scanner.d.ts.map +1 -1
- package/dist/modules/format/formats.d.ts +2 -1
- package/dist/modules/format/formats.d.ts.map +1 -1
- package/dist/modules/project/constants.d.ts +6 -5
- package/dist/modules/project/constants.d.ts.map +1 -1
- package/dist/modules/project/project.d.ts +16 -2
- package/dist/modules/project/project.d.ts.map +1 -1
- package/dist/modules/project/types.d.ts +3 -0
- package/dist/modules/project/types.d.ts.map +1 -1
- package/dist/modules/runner/json/transform.d.ts.map +1 -1
- package/dist/modules/upgrader/types.d.ts +6 -0
- package/dist/modules/upgrader/types.d.ts.map +1 -1
- package/dist/modules/upgrader/upgrader.d.ts +4 -0
- package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
- package/dist/modules/version/range.d.ts.map +1 -1
- package/dist/modules/version/types.d.ts +2 -1
- package/dist/modules/version/types.d.ts.map +1 -1
- package/dist/package.json.js +6 -0
- package/dist/package.json.js.map +1 -0
- package/dist/package.json.mjs +4 -0
- package/dist/package.json.mjs.map +1 -0
- package/dist/src/cli/commands/codemods.js +120 -0
- package/dist/src/cli/commands/codemods.js.map +1 -0
- package/dist/src/cli/commands/codemods.mjs +116 -0
- package/dist/src/cli/commands/codemods.mjs.map +1 -0
- package/dist/src/cli/commands/upgrade.js +99 -0
- package/dist/src/cli/commands/upgrade.js.map +1 -0
- package/dist/src/cli/commands/upgrade.mjs +96 -0
- package/dist/src/cli/commands/upgrade.mjs.map +1 -0
- package/dist/src/cli/errors.js +18 -0
- package/dist/src/cli/errors.js.map +1 -0
- package/dist/src/cli/errors.mjs +16 -0
- package/dist/src/cli/errors.mjs.map +1 -0
- package/dist/src/cli/options.js +26 -0
- package/dist/src/cli/options.js.map +1 -0
- package/dist/src/cli/options.mjs +19 -0
- package/dist/src/cli/options.mjs.map +1 -0
- package/dist/src/modules/codemod/codemod.js +44 -0
- package/dist/src/modules/codemod/codemod.js.map +1 -0
- package/dist/src/modules/codemod/codemod.mjs +41 -0
- package/dist/src/modules/codemod/codemod.mjs.map +1 -0
- package/dist/src/modules/codemod/constants.js +17 -0
- package/dist/src/modules/codemod/constants.js.map +1 -0
- package/dist/src/modules/codemod/constants.mjs +11 -0
- package/dist/src/modules/codemod/constants.mjs.map +1 -0
- package/dist/src/modules/codemod/index.js +10 -0
- package/dist/src/modules/codemod/index.js.map +1 -0
- package/dist/src/modules/codemod/index.mjs +4 -0
- package/dist/src/modules/codemod/index.mjs.map +1 -0
- package/dist/src/modules/codemod-repository/constants.js +9 -0
- package/dist/src/modules/codemod-repository/constants.js.map +1 -0
- package/dist/src/modules/codemod-repository/constants.mjs +7 -0
- package/dist/src/modules/codemod-repository/constants.mjs.map +1 -0
- package/dist/src/modules/codemod-repository/index.js +10 -0
- package/dist/src/modules/codemod-repository/index.js.map +1 -0
- package/dist/src/modules/codemod-repository/index.mjs +4 -0
- package/dist/src/modules/codemod-repository/index.mjs.map +1 -0
- package/dist/src/modules/codemod-repository/repository.js +127 -0
- package/dist/src/modules/codemod-repository/repository.js.map +1 -0
- package/dist/src/modules/codemod-repository/repository.mjs +123 -0
- package/dist/src/modules/codemod-repository/repository.mjs.map +1 -0
- package/dist/src/modules/codemod-runner/codemod-runner.js +113 -0
- package/dist/src/modules/codemod-runner/codemod-runner.js.map +1 -0
- package/dist/src/modules/codemod-runner/codemod-runner.mjs +110 -0
- package/dist/src/modules/codemod-runner/codemod-runner.mjs.map +1 -0
- package/dist/src/modules/error/index.js +11 -0
- package/dist/src/modules/error/index.js.map +1 -0
- package/dist/src/modules/error/index.mjs +2 -0
- package/dist/src/modules/error/index.mjs.map +1 -0
- package/dist/src/modules/error/utils.js +33 -0
- package/dist/src/modules/error/utils.js.map +1 -0
- package/dist/src/modules/error/utils.mjs +28 -0
- package/dist/src/modules/error/utils.mjs.map +1 -0
- package/dist/src/modules/file-scanner/index.js +8 -0
- package/dist/src/modules/file-scanner/index.js.map +1 -0
- package/dist/src/modules/file-scanner/index.mjs +2 -0
- package/dist/src/modules/file-scanner/index.mjs.map +1 -0
- package/dist/src/modules/file-scanner/scanner.js +23 -0
- package/dist/src/modules/file-scanner/scanner.js.map +1 -0
- package/dist/src/modules/file-scanner/scanner.mjs +20 -0
- package/dist/src/modules/file-scanner/scanner.mjs.map +1 -0
- package/dist/src/modules/format/formats.js +107 -0
- package/dist/src/modules/format/formats.js.map +1 -0
- package/dist/src/modules/format/formats.mjs +94 -0
- package/dist/src/modules/format/formats.mjs.map +1 -0
- package/dist/src/modules/format/index.js +19 -0
- package/dist/src/modules/format/index.js.map +1 -0
- package/dist/src/modules/format/index.mjs +2 -0
- package/dist/src/modules/format/index.mjs.map +1 -0
- package/dist/src/modules/index.js +32 -0
- package/dist/src/modules/index.js.map +1 -0
- package/dist/src/modules/index.mjs +27 -0
- package/dist/src/modules/index.mjs.map +1 -0
- package/dist/src/modules/json/file.js +16 -0
- package/dist/src/modules/json/file.js.map +1 -0
- package/dist/src/modules/json/file.mjs +13 -0
- package/dist/src/modules/json/file.mjs.map +1 -0
- package/dist/src/modules/json/transform-api.js +38 -0
- package/dist/src/modules/json/transform-api.js.map +1 -0
- package/dist/src/modules/json/transform-api.mjs +35 -0
- package/dist/src/modules/json/transform-api.mjs.map +1 -0
- package/dist/src/modules/logger/index.js +8 -0
- package/dist/src/modules/logger/index.js.map +1 -0
- package/dist/src/modules/logger/index.mjs +2 -0
- package/dist/src/modules/logger/index.mjs.map +1 -0
- package/dist/src/modules/logger/logger.js +76 -0
- package/dist/src/modules/logger/logger.js.map +1 -0
- package/dist/src/modules/logger/logger.mjs +73 -0
- package/dist/src/modules/logger/logger.mjs.map +1 -0
- package/dist/src/modules/npm/constants.js +6 -0
- package/dist/src/modules/npm/constants.js.map +1 -0
- package/dist/src/modules/npm/constants.mjs +4 -0
- package/dist/src/modules/npm/constants.mjs.map +1 -0
- package/dist/src/modules/npm/package.js +55 -0
- package/dist/src/modules/npm/package.js.map +1 -0
- package/dist/src/modules/npm/package.mjs +52 -0
- package/dist/src/modules/npm/package.mjs.map +1 -0
- package/dist/src/modules/project/constants.js +45 -0
- package/dist/src/modules/project/constants.js.map +1 -0
- package/dist/src/modules/project/constants.mjs +35 -0
- package/dist/src/modules/project/constants.mjs.map +1 -0
- package/dist/src/modules/project/index.js +15 -0
- package/dist/src/modules/project/index.js.map +1 -0
- package/dist/src/modules/project/index.mjs +5 -0
- package/dist/src/modules/project/index.mjs.map +1 -0
- package/dist/src/modules/project/project.js +208 -0
- package/dist/src/modules/project/project.js.map +1 -0
- package/dist/src/modules/project/project.mjs +203 -0
- package/dist/src/modules/project/project.mjs.map +1 -0
- package/dist/src/modules/project/utils.js +26 -0
- package/dist/src/modules/project/utils.js.map +1 -0
- package/dist/src/modules/project/utils.mjs +21 -0
- package/dist/src/modules/project/utils.mjs.map +1 -0
- package/dist/src/modules/report/index.js +9 -0
- package/dist/src/modules/report/index.js.map +1 -0
- package/dist/src/modules/report/index.mjs +2 -0
- package/dist/src/modules/report/index.mjs.map +1 -0
- package/dist/src/modules/report/report.js +13 -0
- package/dist/src/modules/report/report.js.map +1 -0
- package/dist/src/modules/report/report.mjs +10 -0
- package/dist/src/modules/report/report.mjs.map +1 -0
- package/dist/src/modules/requirement/index.js +8 -0
- package/dist/src/modules/requirement/index.js.map +1 -0
- package/dist/src/modules/requirement/index.mjs +2 -0
- package/dist/src/modules/requirement/index.mjs.map +1 -0
- package/dist/src/modules/requirement/requirement.js +55 -0
- package/dist/src/modules/requirement/requirement.js.map +1 -0
- package/dist/src/modules/requirement/requirement.mjs +52 -0
- package/dist/src/modules/requirement/requirement.mjs.map +1 -0
- package/dist/src/modules/runner/code/code.js +21 -0
- package/dist/src/modules/runner/code/code.js.map +1 -0
- package/dist/src/modules/runner/code/code.mjs +18 -0
- package/dist/src/modules/runner/code/code.mjs.map +1 -0
- package/dist/src/modules/runner/code/index.js +8 -0
- package/dist/src/modules/runner/code/index.js.map +1 -0
- package/dist/src/modules/runner/code/index.mjs +2 -0
- package/dist/src/modules/runner/code/index.mjs.map +1 -0
- package/dist/src/modules/runner/index.js +10 -0
- package/dist/src/modules/runner/index.js.map +1 -0
- package/dist/src/modules/runner/index.mjs +5 -0
- package/dist/src/modules/runner/index.mjs.map +1 -0
- package/dist/src/modules/runner/json/index.js +8 -0
- package/dist/src/modules/runner/json/index.js.map +1 -0
- package/dist/src/modules/runner/json/index.mjs +2 -0
- package/dist/src/modules/runner/json/index.mjs.map +1 -0
- package/dist/src/modules/runner/json/json.js +21 -0
- package/dist/src/modules/runner/json/json.js.map +1 -0
- package/dist/src/modules/runner/json/json.mjs +18 -0
- package/dist/src/modules/runner/json/json.mjs.map +1 -0
- package/dist/src/modules/runner/json/transform.js +85 -0
- package/dist/src/modules/runner/json/transform.js.map +1 -0
- package/dist/src/modules/runner/json/transform.mjs +83 -0
- package/dist/src/modules/runner/json/transform.mjs.map +1 -0
- package/dist/src/modules/runner/runner.js +22 -0
- package/dist/src/modules/runner/runner.js.map +1 -0
- package/dist/src/modules/runner/runner.mjs +20 -0
- package/dist/src/modules/runner/runner.mjs.map +1 -0
- package/dist/src/modules/timer/constants.js +6 -0
- package/dist/src/modules/timer/constants.js.map +1 -0
- package/dist/src/modules/timer/constants.mjs +4 -0
- package/dist/src/modules/timer/constants.mjs.map +1 -0
- package/dist/src/modules/timer/index.js +10 -0
- package/dist/src/modules/timer/index.js.map +1 -0
- package/dist/src/modules/timer/index.mjs +4 -0
- package/dist/src/modules/timer/index.mjs.map +1 -0
- package/dist/src/modules/timer/timer.js +33 -0
- package/dist/src/modules/timer/timer.js.map +1 -0
- package/dist/src/modules/timer/timer.mjs +30 -0
- package/dist/src/modules/timer/timer.mjs.map +1 -0
- package/dist/src/modules/upgrader/constants.js +6 -0
- package/dist/src/modules/upgrader/constants.js.map +1 -0
- package/dist/src/modules/upgrader/constants.mjs +4 -0
- package/dist/src/modules/upgrader/constants.mjs.map +1 -0
- package/dist/src/modules/upgrader/index.js +10 -0
- package/dist/src/modules/upgrader/index.js.map +1 -0
- package/dist/src/modules/upgrader/index.mjs +4 -0
- package/dist/src/modules/upgrader/index.mjs.map +1 -0
- package/dist/src/modules/upgrader/upgrader.js +266 -0
- package/dist/src/modules/upgrader/upgrader.js.map +1 -0
- package/dist/src/modules/upgrader/upgrader.mjs +263 -0
- package/dist/src/modules/upgrader/upgrader.mjs.map +1 -0
- package/dist/src/modules/version/index.js +20 -0
- package/dist/src/modules/version/index.js.map +1 -0
- package/dist/src/modules/version/index.mjs +5 -0
- package/dist/src/modules/version/index.mjs.map +1 -0
- package/dist/src/modules/version/range.js +81 -0
- package/dist/src/modules/version/range.js.map +1 -0
- package/dist/src/modules/version/range.mjs +75 -0
- package/dist/src/modules/version/range.mjs.map +1 -0
- package/dist/src/modules/version/semver.js +26 -0
- package/dist/src/modules/version/semver.js.map +1 -0
- package/dist/src/modules/version/semver.mjs +20 -0
- package/dist/src/modules/version/semver.mjs.map +1 -0
- package/dist/src/modules/version/types.js +12 -0
- package/dist/src/modules/version/types.js.map +1 -0
- package/dist/src/modules/version/types.mjs +12 -0
- package/dist/src/modules/version/types.mjs.map +1 -0
- package/dist/src/tasks/codemods/list-codemods.js +40 -0
- package/dist/src/tasks/codemods/list-codemods.js.map +1 -0
- package/dist/src/tasks/codemods/list-codemods.mjs +38 -0
- package/dist/src/tasks/codemods/list-codemods.mjs.map +1 -0
- package/dist/src/tasks/codemods/run-codemods.js +36 -0
- package/dist/src/tasks/codemods/run-codemods.js.map +1 -0
- package/dist/src/tasks/codemods/run-codemods.mjs +34 -0
- package/dist/src/tasks/codemods/run-codemods.mjs.map +1 -0
- package/dist/src/tasks/codemods/utils.js +54 -0
- package/dist/src/tasks/codemods/utils.js.map +1 -0
- package/dist/src/tasks/codemods/utils.mjs +50 -0
- package/dist/src/tasks/codemods/utils.mjs.map +1 -0
- package/dist/src/tasks/index.js +15 -0
- package/dist/src/tasks/index.js.map +1 -0
- package/dist/src/tasks/index.mjs +7 -0
- package/dist/src/tasks/index.mjs.map +1 -0
- package/dist/src/tasks/upgrade/prompts/latest.js +48 -0
- package/dist/src/tasks/upgrade/prompts/latest.js.map +1 -0
- package/dist/src/tasks/upgrade/prompts/latest.mjs +46 -0
- package/dist/src/tasks/upgrade/prompts/latest.mjs.map +1 -0
- package/dist/src/tasks/upgrade/requirements/common.js +40 -0
- package/dist/src/tasks/upgrade/requirements/common.js.map +1 -0
- package/dist/src/tasks/upgrade/requirements/common.mjs +35 -0
- package/dist/src/tasks/upgrade/requirements/common.mjs.map +1 -0
- package/dist/src/tasks/upgrade/requirements/major.js +29 -0
- package/dist/src/tasks/upgrade/requirements/major.js.map +1 -0
- package/dist/src/tasks/upgrade/requirements/major.mjs +26 -0
- package/dist/src/tasks/upgrade/requirements/major.mjs.map +1 -0
- package/dist/src/tasks/upgrade/upgrade.js +69 -0
- package/dist/src/tasks/upgrade/upgrade.js.map +1 -0
- package/dist/src/tasks/upgrade/upgrade.mjs +67 -0
- package/dist/src/tasks/upgrade/upgrade.mjs.map +1 -0
- package/dist/tasks/codemods/utils.d.ts.map +1 -1
- package/dist/tasks/upgrade/prompts/index.d.ts +2 -0
- package/dist/tasks/upgrade/prompts/index.d.ts.map +1 -0
- package/dist/tasks/upgrade/prompts/latest.d.ts +9 -0
- package/dist/tasks/upgrade/prompts/latest.d.ts.map +1 -0
- package/dist/tasks/upgrade/requirements/major.d.ts.map +1 -1
- package/dist/tasks/upgrade/upgrade.d.ts.map +1 -1
- package/package.json +13 -13
- package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
- package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
- package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
- package/resources/codemods/5.0.0/deprecate-helper-plugin.code.ts +192 -0
- package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +0 -1
- package/resources/codemods/5.1.0/dependency-better-sqlite3.json.ts +48 -0
- package/resources/utils/change-import.ts +118 -0
- package/resources/utils/replace-jsx.ts +49 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import type { Transform } from 'jscodeshift';
|
|
2
|
+
import { changeImportSpecifier } from '../../utils/change-import';
|
|
3
|
+
import { replaceJSXElement } from '../../utils/replace-jsx';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This codemods automates all the imports and naming changes
|
|
7
|
+
* for methods or components that used to be imported from '@strapi/helper-plugin'
|
|
8
|
+
*/
|
|
9
|
+
const transform: Transform = (file, api) => {
|
|
10
|
+
const { j } = api;
|
|
11
|
+
|
|
12
|
+
const root = j.withParser('tsx')(file.source);
|
|
13
|
+
|
|
14
|
+
type Replacement = {
|
|
15
|
+
oldName: string;
|
|
16
|
+
oldDependency: string;
|
|
17
|
+
toReplace: boolean;
|
|
18
|
+
toChangeImportSpecifier: boolean;
|
|
19
|
+
newDependency?: string;
|
|
20
|
+
newName?: string;
|
|
21
|
+
newImport?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const replacements: Replacement[] = [
|
|
25
|
+
{
|
|
26
|
+
oldName: 'AnErrorOccurred',
|
|
27
|
+
newImport: 'Page',
|
|
28
|
+
newName: 'Page.Error',
|
|
29
|
+
oldDependency: '@strapi/helper-plugin',
|
|
30
|
+
newDependency: '@strapi/strapi/admin',
|
|
31
|
+
toReplace: true,
|
|
32
|
+
toChangeImportSpecifier: true,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
oldName: 'CheckPagePermissions',
|
|
36
|
+
newImport: 'Page',
|
|
37
|
+
newName: 'Page.Protect',
|
|
38
|
+
oldDependency: '@strapi/helper-plugin',
|
|
39
|
+
newDependency: '@strapi/strapi/admin',
|
|
40
|
+
toReplace: true,
|
|
41
|
+
toChangeImportSpecifier: true,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
oldName: 'ConfirmDialog',
|
|
45
|
+
oldDependency: '@strapi/helper-plugin',
|
|
46
|
+
newDependency: '@strapi/strapi/admin',
|
|
47
|
+
toChangeImportSpecifier: true,
|
|
48
|
+
toReplace: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
oldName: 'DateTimePicker',
|
|
52
|
+
oldDependency: '@strapi/helper-plugin',
|
|
53
|
+
newDependency: '@strapi/design-system',
|
|
54
|
+
toChangeImportSpecifier: true,
|
|
55
|
+
toReplace: false,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
oldName: 'getFetchClient',
|
|
59
|
+
oldDependency: '@strapi/helper-plugin',
|
|
60
|
+
newDependency: '@strapi/strapi/admin',
|
|
61
|
+
toChangeImportSpecifier: true,
|
|
62
|
+
toReplace: false,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
oldName: 'LoadingIndicatorPage',
|
|
66
|
+
newImport: 'Page',
|
|
67
|
+
newName: 'Page.Loading',
|
|
68
|
+
oldDependency: '@strapi/helper-plugin',
|
|
69
|
+
newDependency: '@strapi/strapi/admin',
|
|
70
|
+
toReplace: true,
|
|
71
|
+
toChangeImportSpecifier: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
oldName: 'NoContent',
|
|
75
|
+
newImport: 'EmptyStateLayout',
|
|
76
|
+
newName: 'EmptyStateLayout',
|
|
77
|
+
oldDependency: '@strapi/helper-plugin',
|
|
78
|
+
newDependency: '@strapi/design-system',
|
|
79
|
+
toReplace: true,
|
|
80
|
+
toChangeImportSpecifier: true,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
oldName: 'NoPermissions',
|
|
84
|
+
newImport: 'Page',
|
|
85
|
+
newName: 'Page.NoPermissions',
|
|
86
|
+
oldDependency: '@strapi/helper-plugin',
|
|
87
|
+
newDependency: '@strapi/strapi/admin',
|
|
88
|
+
toReplace: true,
|
|
89
|
+
toChangeImportSpecifier: true,
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
oldName: 'Status',
|
|
93
|
+
oldDependency: '@strapi/helper-plugin',
|
|
94
|
+
newDependency: '@strapi/design-system',
|
|
95
|
+
toChangeImportSpecifier: true,
|
|
96
|
+
toReplace: false,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
oldName: 'translatedErrors',
|
|
100
|
+
oldDependency: '@strapi/helper-plugin',
|
|
101
|
+
newDependency: '@strapi/strapi/admin',
|
|
102
|
+
toChangeImportSpecifier: true,
|
|
103
|
+
toReplace: false,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
oldName: 'useAPIErrorHandler',
|
|
107
|
+
oldDependency: '@strapi/helper-plugin',
|
|
108
|
+
newDependency: '@strapi/strapi/admin',
|
|
109
|
+
toChangeImportSpecifier: true,
|
|
110
|
+
toReplace: false,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
oldName: 'useCallbackRef',
|
|
114
|
+
oldDependency: '@strapi/helper-plugin',
|
|
115
|
+
newDependency: '@strapi/design-system',
|
|
116
|
+
toChangeImportSpecifier: true,
|
|
117
|
+
toReplace: false,
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
oldName: 'useCollator',
|
|
121
|
+
oldDependency: '@strapi/helper-plugin',
|
|
122
|
+
newDependency: '@strapi/design-system',
|
|
123
|
+
toChangeImportSpecifier: true,
|
|
124
|
+
toReplace: false,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
oldName: 'useFetchClient',
|
|
128
|
+
oldDependency: '@strapi/helper-plugin',
|
|
129
|
+
newDependency: '@strapi/strapi/admin',
|
|
130
|
+
toChangeImportSpecifier: true,
|
|
131
|
+
toReplace: false,
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
oldName: 'useFilter',
|
|
135
|
+
oldDependency: '@strapi/helper-plugin',
|
|
136
|
+
newDependency: '@strapi/design-system',
|
|
137
|
+
toChangeImportSpecifier: true,
|
|
138
|
+
toReplace: false,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
oldName: 'useQueryParams',
|
|
142
|
+
oldDependency: '@strapi/helper-plugin',
|
|
143
|
+
newDependency: '@strapi/strapi/admin',
|
|
144
|
+
toChangeImportSpecifier: true,
|
|
145
|
+
toReplace: false,
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
oldName: 'useRBAC',
|
|
149
|
+
oldDependency: '@strapi/helper-plugin',
|
|
150
|
+
newDependency: '@strapi/strapi/admin',
|
|
151
|
+
toChangeImportSpecifier: true,
|
|
152
|
+
toReplace: false,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
oldName: 'SearchURLQuery',
|
|
156
|
+
oldDependency: '@strapi/helper-plugin',
|
|
157
|
+
newDependency: '@strapi/strapi/admin',
|
|
158
|
+
toChangeImportSpecifier: true,
|
|
159
|
+
toReplace: false,
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
oldName: 'useSettingsForm',
|
|
163
|
+
oldDependency: '@strapi/helper-plugin',
|
|
164
|
+
newDependency: '@strapi/strapi/admin',
|
|
165
|
+
toChangeImportSpecifier: true,
|
|
166
|
+
toReplace: false,
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
replacements.forEach((replacement) => {
|
|
171
|
+
if (replacement.toReplace && replacement.newName) {
|
|
172
|
+
replaceJSXElement(root, j, {
|
|
173
|
+
oldElementName: replacement.oldName,
|
|
174
|
+
newElementName: replacement.newName,
|
|
175
|
+
oldDependency: replacement.oldDependency,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (replacement.toChangeImportSpecifier && replacement.newDependency) {
|
|
180
|
+
changeImportSpecifier(root, j, {
|
|
181
|
+
oldMethodName: replacement.oldName,
|
|
182
|
+
newMethodName: replacement.newImport,
|
|
183
|
+
oldDependency: replacement.oldDependency,
|
|
184
|
+
newDependency: replacement.newDependency,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
return root.toSource();
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export default transform;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
import type { modules } from '../../../dist';
|
|
4
|
+
|
|
5
|
+
const DEP_NAME = 'better-sqlite3';
|
|
6
|
+
const DEP_PATH = `dependencies.${DEP_NAME}`;
|
|
7
|
+
const DEP_VERSION = '11.3.0';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
13
|
+
return upgradeIfExists(file, params, DEP_PATH, DEP_VERSION);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default transform;
|
|
17
|
+
|
|
18
|
+
// TODO: move this to a utility once we solve the issue where codemods are not transpiled properly
|
|
19
|
+
const upgradeIfExists = (
|
|
20
|
+
file: modules.runner.json.JSONSourceFile,
|
|
21
|
+
params: modules.runner.json.JSONTransformParams,
|
|
22
|
+
packagePath: string,
|
|
23
|
+
targetVersion: string
|
|
24
|
+
) => {
|
|
25
|
+
const { cwd, json } = params;
|
|
26
|
+
|
|
27
|
+
// Return early if the file path is not the root package.json
|
|
28
|
+
if (file.path !== path.join(cwd, 'package.json')) {
|
|
29
|
+
return file.json;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const packageJson = json(file.json);
|
|
33
|
+
|
|
34
|
+
// Check if the package exists
|
|
35
|
+
if (packageJson.has(packagePath)) {
|
|
36
|
+
const currentVersion = packageJson.get(packagePath);
|
|
37
|
+
// ensure we only upgrade, not downgrade
|
|
38
|
+
if (
|
|
39
|
+
typeof currentVersion === 'string' &&
|
|
40
|
+
semver.valid(currentVersion) &&
|
|
41
|
+
semver.lt(currentVersion, targetVersion)
|
|
42
|
+
) {
|
|
43
|
+
packageJson.set(packagePath, targetVersion);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return packageJson.root();
|
|
48
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { ImportDeclaration, JSCodeshift, Collection } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const changeImportSpecifier = (
|
|
4
|
+
root: Collection,
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
options: {
|
|
7
|
+
oldDependency: string;
|
|
8
|
+
newDependency: string;
|
|
9
|
+
oldMethodName: string;
|
|
10
|
+
newMethodName?: string;
|
|
11
|
+
}
|
|
12
|
+
): void => {
|
|
13
|
+
const { oldMethodName, newMethodName, oldDependency, newDependency } = options;
|
|
14
|
+
const methodNameToReplace = newMethodName ?? oldMethodName;
|
|
15
|
+
|
|
16
|
+
// Flag to check if the method was imported from the old dependency
|
|
17
|
+
let methodImportedFromOldDependency = false;
|
|
18
|
+
const methodAliases: string[] = [];
|
|
19
|
+
|
|
20
|
+
// Remove the method from the old dependency and check if it was imported
|
|
21
|
+
root
|
|
22
|
+
.find(j.ImportDeclaration)
|
|
23
|
+
.filter((path) => path.node.source.value === oldDependency)
|
|
24
|
+
.forEach((path) => {
|
|
25
|
+
const importDeclaration: ImportDeclaration = path.node;
|
|
26
|
+
|
|
27
|
+
// Check if the method is imported from the old dependency
|
|
28
|
+
const methodSpecifiers = importDeclaration.specifiers?.filter(
|
|
29
|
+
(specifier) =>
|
|
30
|
+
specifier.type === 'ImportSpecifier' && specifier.imported.name === oldMethodName
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (methodSpecifiers && methodSpecifiers.length > 0) {
|
|
34
|
+
methodImportedFromOldDependency = true;
|
|
35
|
+
|
|
36
|
+
// Collect all aliases for the method
|
|
37
|
+
methodSpecifiers.forEach((specifier) => {
|
|
38
|
+
if (specifier.local && specifier.local.name !== oldMethodName) {
|
|
39
|
+
methodAliases.push(specifier.local.name);
|
|
40
|
+
} else {
|
|
41
|
+
methodAliases.push(methodNameToReplace);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Remove the method specifiers from the old import
|
|
46
|
+
const updatedSpecifiers = importDeclaration.specifiers?.filter(
|
|
47
|
+
(specifier) =>
|
|
48
|
+
specifier.type !== 'ImportSpecifier' || specifier.imported.name !== oldMethodName
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if (updatedSpecifiers && updatedSpecifiers.length > 0) {
|
|
52
|
+
// Replace the import with the updated specifiers if there are other imports left
|
|
53
|
+
j(path).replaceWith(j.importDeclaration(updatedSpecifiers, j.literal(oldDependency)));
|
|
54
|
+
} else {
|
|
55
|
+
// Remove the entire import statement if the specified method was the only import
|
|
56
|
+
j(path).remove();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Add new import dependency if the method was imported from the old dependency
|
|
62
|
+
if (methodImportedFromOldDependency) {
|
|
63
|
+
const dependencies = root
|
|
64
|
+
.find(j.ImportDeclaration)
|
|
65
|
+
.filter((path) => path.node.source.value === newDependency);
|
|
66
|
+
|
|
67
|
+
if (dependencies.length > 0) {
|
|
68
|
+
// we have to use a flag to prevent adding the method to multiple imports
|
|
69
|
+
let methodAdded = false;
|
|
70
|
+
dependencies.forEach((path) => {
|
|
71
|
+
const importDeclaration: ImportDeclaration = path.node;
|
|
72
|
+
if (!methodAdded) {
|
|
73
|
+
methodAliases.forEach((alias) => {
|
|
74
|
+
// Check if the methodNameToReplace or its alias is already imported
|
|
75
|
+
const specifiersArray = importDeclaration.specifiers || [];
|
|
76
|
+
const methodAlreadyExists = specifiersArray.some(
|
|
77
|
+
(specifier) =>
|
|
78
|
+
specifier.type === 'ImportSpecifier' &&
|
|
79
|
+
specifier.imported.name === methodNameToReplace && // Check if imported method matches
|
|
80
|
+
specifier.local?.name === alias // Check if local alias matches
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
if (!methodAlreadyExists) {
|
|
84
|
+
// If method does not exist, add it
|
|
85
|
+
const newSpecifier = j.importSpecifier(
|
|
86
|
+
j.identifier(methodNameToReplace),
|
|
87
|
+
j.identifier(alias)
|
|
88
|
+
);
|
|
89
|
+
path.get('specifiers').replace([...specifiersArray, newSpecifier]);
|
|
90
|
+
methodAdded = true;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
} else {
|
|
96
|
+
const newSpecifiers = methodAliases.map((alias) =>
|
|
97
|
+
j.importSpecifier(j.identifier(methodNameToReplace), j.identifier(alias))
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const newImportDeclaration = j.importDeclaration(newSpecifiers, j.literal(newDependency));
|
|
101
|
+
|
|
102
|
+
// Find the index of the first non-import declaration
|
|
103
|
+
const body = root.get().node.program.body;
|
|
104
|
+
const lastImportIndex = body.findIndex((node) => node.type !== 'ImportDeclaration');
|
|
105
|
+
|
|
106
|
+
if (lastImportIndex > -1) {
|
|
107
|
+
// Insert the new import declaration just before the first non-import node
|
|
108
|
+
body.splice(lastImportIndex, 0, newImportDeclaration);
|
|
109
|
+
} else {
|
|
110
|
+
// Check if 'use strict' exists at the beginning
|
|
111
|
+
const hasUseStrict =
|
|
112
|
+
body[0]?.type === 'ExpressionStatement' && body[0]?.expression?.value === 'use strict';
|
|
113
|
+
// Add the new import after 'use strict' if it exists, otherwise at the beginning
|
|
114
|
+
body.splice(hasUseStrict ? 1 : 0, 0, newImportDeclaration);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { JSCodeshift, Collection } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
export const replaceJSXElement = (
|
|
4
|
+
root: Collection,
|
|
5
|
+
j: JSCodeshift,
|
|
6
|
+
{
|
|
7
|
+
oldElementName,
|
|
8
|
+
newElementName,
|
|
9
|
+
oldDependency,
|
|
10
|
+
}: {
|
|
11
|
+
oldElementName: string;
|
|
12
|
+
newElementName: string;
|
|
13
|
+
oldDependency: string;
|
|
14
|
+
}
|
|
15
|
+
) => {
|
|
16
|
+
// Find the import declaration for the old dependency
|
|
17
|
+
const importDeclaration = root.find(j.ImportDeclaration, {
|
|
18
|
+
source: { value: oldDependency },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
if (importDeclaration.size() === 0) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Get the local name of the imported element
|
|
26
|
+
const localName = importDeclaration
|
|
27
|
+
.find(j.ImportSpecifier, {
|
|
28
|
+
imported: { name: oldElementName },
|
|
29
|
+
})
|
|
30
|
+
.nodes()[0]?.local?.name;
|
|
31
|
+
|
|
32
|
+
if (!localName) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Replace JSX elements
|
|
37
|
+
root.findJSXElements(localName).forEach((path) => {
|
|
38
|
+
const openingElement = path.node.openingElement;
|
|
39
|
+
const closingElement = path.node.closingElement;
|
|
40
|
+
|
|
41
|
+
if (j.JSXIdentifier.check(openingElement.name)) {
|
|
42
|
+
openingElement.name.name = newElementName;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (closingElement && j.JSXIdentifier.check(closingElement.name)) {
|
|
46
|
+
closingElement.name.name = newElementName;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
};
|