@strapi/upgrade 0.0.0-experimental.fc1ac2acd58c8a5a858679956b6d102ac5ee4011 → 0.0.0-experimental.fca58d9b01ba89012d84a58a20556a6fd716cb92
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 +15 -6
- 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 -1199
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -1191
- package/dist/index.mjs.map +1 -1
- package/dist/modules/codemod/codemod.d.ts +4 -2
- package/dist/modules/codemod/codemod.d.ts.map +1 -1
- package/dist/modules/codemod/types.d.ts +8 -1
- package/dist/modules/codemod/types.d.ts.map +1 -1
- package/dist/modules/codemod-repository/constants.d.ts.map +1 -1
- package/dist/modules/codemod-repository/repository.d.ts +6 -5
- package/dist/modules/codemod-repository/repository.d.ts.map +1 -1
- package/dist/modules/codemod-repository/types.d.ts +7 -3
- package/dist/modules/codemod-repository/types.d.ts.map +1 -1
- package/dist/modules/codemod-runner/codemod-runner.d.ts +3 -0
- package/dist/modules/codemod-runner/codemod-runner.d.ts.map +1 -1
- package/dist/modules/codemod-runner/index.d.ts +1 -0
- package/dist/modules/codemod-runner/index.d.ts.map +1 -1
- package/dist/modules/codemod-runner/types.d.ts +1 -0
- package/dist/modules/codemod-runner/types.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 +6 -0
- package/dist/modules/format/formats.d.ts.map +1 -1
- package/dist/modules/project/constants.d.ts +6 -3
- package/dist/modules/project/constants.d.ts.map +1 -1
- package/dist/modules/project/index.d.ts +2 -0
- package/dist/modules/project/index.d.ts.map +1 -1
- package/dist/modules/project/project.d.ts +27 -5
- package/dist/modules/project/project.d.ts.map +1 -1
- package/dist/modules/project/types.d.ts +3 -10
- package/dist/modules/project/types.d.ts.map +1 -1
- package/dist/modules/project/utils.d.ts +6 -0
- package/dist/modules/project/utils.d.ts.map +1 -0
- package/dist/modules/report/report.d.ts.map +1 -1
- package/dist/modules/requirement/types.d.ts +2 -2
- package/dist/modules/requirement/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 +7 -3
- package/dist/modules/upgrader/upgrader.d.ts.map +1 -1
- package/dist/modules/version/range.d.ts +2 -0
- 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/index.d.ts +2 -1
- package/dist/tasks/codemods/index.d.ts.map +1 -1
- package/dist/tasks/codemods/list-codemods.d.ts +3 -0
- package/dist/tasks/codemods/list-codemods.d.ts.map +1 -0
- package/dist/tasks/codemods/run-codemods.d.ts +3 -0
- package/dist/tasks/codemods/run-codemods.d.ts.map +1 -0
- package/dist/tasks/codemods/types.d.ts +9 -3
- package/dist/tasks/codemods/types.d.ts.map +1 -1
- package/dist/tasks/codemods/utils.d.ts +6 -0
- package/dist/tasks/codemods/utils.d.ts.map +1 -0
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.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 +16 -15
- package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
- package/resources/codemods/5.0.0/dependency-remove-strapi-plugin-i18n.json.ts +31 -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-react-router-dom.json.ts +59 -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/entity-service-document-service.code.ts +437 -0
- package/resources/codemods/5.0.0/s3-keys-wrapped-in-credentials.code.ts +1 -1
- package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +5 -3
- package/resources/codemods/5.0.0/strapi-public-interface.code.ts +126 -0
- package/resources/codemods/5.0.0/use-uid-for-config-namespace.code.ts +1 -1
- package/resources/codemods/5.0.0/utils-public-interface.code.ts +320 -0
- package/resources/codemods/5.1.0/dependency-better-sqlite3.json.ts +48 -0
- package/resources/examples/console.log-to-console.info.code.ts +1 -1
- package/resources/examples/disable-jsx-buttons.code.ts +42 -0
- package/resources/utils/change-import.ts +118 -0
- package/resources/utils/replace-jsx.ts +49 -0
- package/dist/_chunks/codemod-runner-oPpELfwO.js +0 -730
- package/dist/_chunks/codemod-runner-oPpELfwO.js.map +0 -1
- package/dist/_chunks/codemods-qc8_QMWD.js +0 -108
- package/dist/_chunks/codemods-qc8_QMWD.js.map +0 -1
- package/dist/_chunks/index-GHKaxdhJ.js +0 -103
- package/dist/_chunks/index-GHKaxdhJ.js.map +0 -1
- package/dist/_chunks/upgrade-4SxXG3Oe.js +0 -357
- package/dist/_chunks/upgrade-4SxXG3Oe.js.map +0 -1
- package/dist/tasks/codemods/codemods.d.ts +0 -3
- package/dist/tasks/codemods/codemods.d.ts.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import semver from 'semver';
|
|
3
|
+
|
|
4
|
+
import type { modules } from '../../../dist';
|
|
5
|
+
|
|
6
|
+
const DEP_NAME = 'styled-components';
|
|
7
|
+
const DEP_PATH = `dependencies.${DEP_NAME}`;
|
|
8
|
+
|
|
9
|
+
const DEP_NEW_VERSION_RANGE = '^6.0.0';
|
|
10
|
+
|
|
11
|
+
const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
12
|
+
const { cwd, json } = params;
|
|
13
|
+
|
|
14
|
+
const rootPackageJsonPath = path.join(cwd, 'package.json');
|
|
15
|
+
|
|
16
|
+
if (file.path !== rootPackageJsonPath) {
|
|
17
|
+
return file.json;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const j = json(file.json);
|
|
21
|
+
|
|
22
|
+
if (j.has(DEP_PATH)) {
|
|
23
|
+
const currentVersion = j.get(DEP_PATH);
|
|
24
|
+
|
|
25
|
+
// If the current version is not a string, then something is wrong, abort
|
|
26
|
+
if (typeof currentVersion !== 'string') {
|
|
27
|
+
return j.root();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const currentSatisfiesNew = semver.satisfies(currentVersion, DEP_NEW_VERSION_RANGE);
|
|
31
|
+
|
|
32
|
+
// if the current version satisfies the new range, keep it as is and abort
|
|
33
|
+
if (currentSatisfiesNew) {
|
|
34
|
+
return j.root();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// else, update the version with the new one
|
|
38
|
+
j.set(DEP_PATH, DEP_NEW_VERSION_RANGE);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// If the dependency is not listed yet, add it
|
|
42
|
+
else {
|
|
43
|
+
j.set(DEP_PATH, DEP_NEW_VERSION_RANGE);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return j.root();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default transform;
|
|
@@ -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,437 @@
|
|
|
1
|
+
import type { Transform, JSCodeshift, ASTPath, ObjectExpression } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
This codemod transforms entity service calls to match the new document service interface.
|
|
5
|
+
It supports all kind of argument parsing, including spread elements & deeply nested objects.
|
|
6
|
+
|
|
7
|
+
Here is a list of scenarios this was tested against
|
|
8
|
+
|
|
9
|
+
const uid = "api::xxx.xxx";
|
|
10
|
+
const entityId = 1;
|
|
11
|
+
|
|
12
|
+
Case: basic call
|
|
13
|
+
|
|
14
|
+
strapi.entityService.findOne(uid, entityId, {
|
|
15
|
+
fields: ["id", "name", "description"],
|
|
16
|
+
populate: ["author", "comments"],
|
|
17
|
+
publicationState: "preview",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Case: using a variable declared somewhere else
|
|
22
|
+
|
|
23
|
+
const objectParam_2 = {
|
|
24
|
+
fields: ["id", "name", "description"],
|
|
25
|
+
populate: ["author", "comments"],
|
|
26
|
+
publicationState: "preview",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
strapi.entityService.findOne(uid, entityId, objectParam_2);
|
|
30
|
+
|
|
31
|
+
Case: using a variable declared somewhere else with a spread element
|
|
32
|
+
|
|
33
|
+
const objectParam_3 = {
|
|
34
|
+
fields: ["id", "name", "description"],
|
|
35
|
+
populate: ["author", "comments"],
|
|
36
|
+
publicationState: "preview",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
strapi.entityService.findOne(uid, entityId, {
|
|
40
|
+
...objectParam_3,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Case: using a variable declared somewhere else with a spread element and overwritten properties
|
|
45
|
+
|
|
46
|
+
const objectParam_4_1 = {
|
|
47
|
+
fields: ["id", "name", "description"],
|
|
48
|
+
populate: ["author", "comments"],
|
|
49
|
+
publicationState: "preview",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const objectParam_4 = {
|
|
53
|
+
publicationState: "live",
|
|
54
|
+
...objectParam_4_1,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
strapi.entityService.findOne(uid, entityId, {
|
|
58
|
+
...objectParam_4,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
Case: using a variable declared somewhere else with a spread array element while that need its 1st element to be moved
|
|
62
|
+
|
|
63
|
+
const objectParam_5 = [
|
|
64
|
+
uid,
|
|
65
|
+
entityId,
|
|
66
|
+
{
|
|
67
|
+
fields: ["id", "name", "description"],
|
|
68
|
+
populate: ["author", "comments"],
|
|
69
|
+
publicationState: "preview",
|
|
70
|
+
},
|
|
71
|
+
];
|
|
72
|
+
|
|
73
|
+
strapi.entityService.findOne(...objectParam_5);
|
|
74
|
+
|
|
75
|
+
Case: using a variable declared somewhere else with a partial spread array
|
|
76
|
+
|
|
77
|
+
const objectParam_6 = [
|
|
78
|
+
entityId,
|
|
79
|
+
{
|
|
80
|
+
fields: ["id", "name", "description"],
|
|
81
|
+
populate: ["author", "comments"],
|
|
82
|
+
publicationState: "preview",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
strapi.entityService.findOne(uid, ...objectParam_6);
|
|
87
|
+
|
|
88
|
+
Case: using a variable declared somewhere else with a partial & nested spread arrays
|
|
89
|
+
|
|
90
|
+
const objectParam_7_1 = [
|
|
91
|
+
{
|
|
92
|
+
fields: ["id", "name", "description"],
|
|
93
|
+
populate: ["author", "comments"],
|
|
94
|
+
publicationState: "preview",
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
|
|
98
|
+
const objectParam_7 = [entityId, ...objectParam_7_1];
|
|
99
|
+
|
|
100
|
+
strapi.entityService.findOne(uid, ...objectParam_7);
|
|
101
|
+
|
|
102
|
+
Case: using a variable declared somewhere else with a partial & nested spread arrays & objects
|
|
103
|
+
|
|
104
|
+
const objectParam_8_1 = {
|
|
105
|
+
publicationState: "preview",
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const objectParam_8 = [
|
|
109
|
+
entityId,
|
|
110
|
+
{
|
|
111
|
+
fields: ["id", "name", "description"],
|
|
112
|
+
populate: ["author", "comments"],
|
|
113
|
+
...objectParam_8_1,
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
|
|
117
|
+
strapi.entityService.findOne(uid, ...objectParam_8);
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
Case: some sort of mix of all the above
|
|
121
|
+
|
|
122
|
+
const objectParam_9_1 = {
|
|
123
|
+
publicationState: "preview",
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const objectParam_9 = {
|
|
127
|
+
fields: ["id", "name", "description"],
|
|
128
|
+
populate: ["author", "comments"],
|
|
129
|
+
...objectParam_9_1,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
strapi.entityService.findOne(uid, ...[entityId, [objectParam_9]]);
|
|
133
|
+
|
|
134
|
+
Case: even more complex
|
|
135
|
+
|
|
136
|
+
const objectParam_10_1 = {
|
|
137
|
+
publicationState: "preview",
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const objectParam_10_2 = [uid, ...[12], ...[objectParam_10_1]];
|
|
141
|
+
const objectParam_10 = [...objectParam_10_2];
|
|
142
|
+
|
|
143
|
+
strapi.entityService.findOne(...[...objectParam_10]);
|
|
144
|
+
|
|
145
|
+
Case: find, create, update, delete with entityId as first argument
|
|
146
|
+
|
|
147
|
+
strapi.entityService.findMany(uid, {
|
|
148
|
+
fields: ["id", "name", "description"],
|
|
149
|
+
populate: ["author", "comments"],
|
|
150
|
+
publicationState: "preview",
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
strapi.entityService.create(uid, {
|
|
154
|
+
data: {
|
|
155
|
+
name: "John Doe",
|
|
156
|
+
age: 30,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
strapi.entityService.update(uid, entityId, {
|
|
161
|
+
data: {
|
|
162
|
+
name: "John Doe",
|
|
163
|
+
age: 30,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
strapi.entityService.delete(uid, entityId);
|
|
168
|
+
strapi.entityService.findOne(uid, entityId);
|
|
169
|
+
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
const movedFunctions = ['findOne', 'findMany', 'count', 'create', 'update', 'delete'];
|
|
173
|
+
|
|
174
|
+
const functionsWithEntityId = ['findOne', 'update', 'delete'];
|
|
175
|
+
|
|
176
|
+
const transformDeclaration = (path: ASTPath<any>, name: any, j: JSCodeshift) => {
|
|
177
|
+
const declaration = findClosestDeclaration(path, name, j);
|
|
178
|
+
|
|
179
|
+
if (!declaration) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
transformElement(path, declaration.init, j);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const transformElement = (path: ASTPath<any>, element: any, j: JSCodeshift) => {
|
|
187
|
+
switch (true) {
|
|
188
|
+
case j.ObjectExpression.check(element): {
|
|
189
|
+
transformObjectParam(path, element, j);
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
case j.Identifier.check(element): {
|
|
194
|
+
transformDeclaration(path, element.name, j);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
case j.SpreadElement.check(element): {
|
|
199
|
+
transformElement(path, element.argument, j);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
case j.ArrayExpression.check(element): {
|
|
204
|
+
element.elements.forEach((element) => {
|
|
205
|
+
transformElement(path, element, j);
|
|
206
|
+
});
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
default: {
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const transformObjectParam = (path: ASTPath<any>, expression: ObjectExpression, j: JSCodeshift) => {
|
|
216
|
+
expression.properties.forEach((prop) => {
|
|
217
|
+
switch (true) {
|
|
218
|
+
case j.ObjectProperty.check(prop): {
|
|
219
|
+
if (!j.Identifier.check(prop.key) && !j.Literal.check(prop.key)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (j.Identifier.check(prop.key) && prop.key.name !== 'publicationState') {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (j.Literal.check(prop.key) && prop.key.value !== 'publicationState') {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (j.Identifier.check(prop.key) && prop.key.name === 'publicationState') {
|
|
232
|
+
if (!prop.computed && !prop.shorthand) {
|
|
233
|
+
prop.key.name = 'status';
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (prop.shorthand && !prop.computed) {
|
|
237
|
+
prop.shorthand = false;
|
|
238
|
+
prop.key = j.identifier('status');
|
|
239
|
+
prop.value = j.identifier('publicationState');
|
|
240
|
+
}
|
|
241
|
+
} else if (j.Literal.check(prop.key) && prop.key.value === 'publicationState') {
|
|
242
|
+
prop.key.value = 'status';
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
switch (true) {
|
|
246
|
+
case j.Literal.check(prop.value): {
|
|
247
|
+
prop.value = prop.value.value === 'live' ? j.literal('published') : j.literal('draft');
|
|
248
|
+
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case j.Identifier.check(prop.value): {
|
|
252
|
+
const declaration = findClosestDeclaration(path, prop.value.name, j);
|
|
253
|
+
|
|
254
|
+
if (!declaration) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (j.Literal.check(declaration.init)) {
|
|
259
|
+
declaration.init =
|
|
260
|
+
declaration.init.value === 'live' ? j.literal('published') : j.literal('draft');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
default: {
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case j.SpreadElement.check(prop): {
|
|
273
|
+
transformElement(path, prop.argument, j);
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
default: {
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const findClosestDeclaration = (path: ASTPath<any>, name: string, j) => {
|
|
284
|
+
// find Identifier declaration
|
|
285
|
+
const scope = path.scope.lookup(name);
|
|
286
|
+
|
|
287
|
+
if (!scope) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return j(scope.path)
|
|
292
|
+
.find(j.VariableDeclarator, { id: { type: 'Identifier', name } })
|
|
293
|
+
.nodes()[0];
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
const transform: Transform = (file, api) => {
|
|
297
|
+
const j = api.jscodeshift;
|
|
298
|
+
|
|
299
|
+
const root = j(file.source);
|
|
300
|
+
|
|
301
|
+
root
|
|
302
|
+
.find(j.CallExpression, {
|
|
303
|
+
callee: {
|
|
304
|
+
type: 'MemberExpression',
|
|
305
|
+
object: {
|
|
306
|
+
type: 'MemberExpression',
|
|
307
|
+
object: {
|
|
308
|
+
type: 'Identifier',
|
|
309
|
+
name: 'strapi',
|
|
310
|
+
},
|
|
311
|
+
property: {
|
|
312
|
+
type: 'Identifier',
|
|
313
|
+
name: 'entityService',
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
property: {
|
|
317
|
+
type: 'Identifier',
|
|
318
|
+
name: (name) => movedFunctions.includes(name),
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
})
|
|
322
|
+
.replaceWith((path) => {
|
|
323
|
+
if (!j.MemberExpression.check(path.value.callee)) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const args = path.value.arguments;
|
|
328
|
+
|
|
329
|
+
if (args.length === 0) {
|
|
330
|
+
// we don't know how to transform this
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
type Args = typeof path.value.arguments;
|
|
335
|
+
|
|
336
|
+
function resolveArgs(args: Args): Args {
|
|
337
|
+
return args.flatMap((arg: Args[number]) => {
|
|
338
|
+
switch (true) {
|
|
339
|
+
case j.Identifier.check(arg):
|
|
340
|
+
case j.Literal.check(arg): {
|
|
341
|
+
return arg;
|
|
342
|
+
}
|
|
343
|
+
case j.SpreadElement.check(arg): {
|
|
344
|
+
switch (true) {
|
|
345
|
+
case j.Identifier.check(arg.argument): {
|
|
346
|
+
const identifier = arg.argument;
|
|
347
|
+
|
|
348
|
+
const declaration = findClosestDeclaration(path, identifier.name, j);
|
|
349
|
+
|
|
350
|
+
if (!declaration) {
|
|
351
|
+
return arg;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
switch (true) {
|
|
355
|
+
case j.ArrayExpression.check(declaration.init): {
|
|
356
|
+
return resolveArgs(declaration.init.elements);
|
|
357
|
+
}
|
|
358
|
+
default:
|
|
359
|
+
return arg;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
case j.ArrayExpression.check(arg.argument): {
|
|
363
|
+
return resolveArgs(arg.argument.elements as Args);
|
|
364
|
+
}
|
|
365
|
+
default: {
|
|
366
|
+
return arg;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
default: {
|
|
371
|
+
return arg;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const resolvedArgs = resolveArgs(args);
|
|
378
|
+
|
|
379
|
+
const [docUID, ...rest] = resolvedArgs;
|
|
380
|
+
|
|
381
|
+
// function with entityId as first argument
|
|
382
|
+
if (
|
|
383
|
+
j.Identifier.check(path.value.callee.property) &&
|
|
384
|
+
functionsWithEntityId.includes(path.value.callee.property.name)
|
|
385
|
+
) {
|
|
386
|
+
rest.splice(0, 1);
|
|
387
|
+
|
|
388
|
+
// in case no extra params are passed in the function e.g delete(uid, entityId)
|
|
389
|
+
if (rest.length === 0) {
|
|
390
|
+
rest.push(
|
|
391
|
+
j.objectExpression.from({
|
|
392
|
+
properties: [],
|
|
393
|
+
})
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const params = rest[0];
|
|
398
|
+
|
|
399
|
+
const placeholder = j.objectProperty(j.identifier('documentId'), j.literal('__TODO__'));
|
|
400
|
+
|
|
401
|
+
// add documentId to params with a placeholder
|
|
402
|
+
if (j.ObjectExpression.check(params)) {
|
|
403
|
+
params.properties.unshift(placeholder);
|
|
404
|
+
} else if (j.Identifier.check(params)) {
|
|
405
|
+
const declaration = findClosestDeclaration(path, params.name, j);
|
|
406
|
+
|
|
407
|
+
if (!declaration) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (j.ObjectExpression.check(declaration.init)) {
|
|
412
|
+
declaration.init.properties.unshift(placeholder);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
path.value.arguments.forEach((arg) => {
|
|
418
|
+
transformElement(path, arg, j);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
return j.callExpression(
|
|
422
|
+
j.memberExpression(
|
|
423
|
+
j.callExpression(j.memberExpression(j.identifier('strapi'), j.identifier('documents')), [
|
|
424
|
+
docUID,
|
|
425
|
+
]),
|
|
426
|
+
path.value.callee.property
|
|
427
|
+
),
|
|
428
|
+
rest
|
|
429
|
+
);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
return root.toSource();
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
export const parser = 'tsx';
|
|
436
|
+
|
|
437
|
+
export default transform;
|
|
@@ -17,18 +17,20 @@ const transform: modules.runner.json.JSONTransform = (file, params) => {
|
|
|
17
17
|
|
|
18
18
|
const j = json(file.json);
|
|
19
19
|
|
|
20
|
+
let removed = false;
|
|
21
|
+
|
|
20
22
|
const targetProperties = ['sqlite3', '@vscode/sqlite3'];
|
|
21
23
|
|
|
22
24
|
targetProperties.forEach((targetProperty) => {
|
|
23
25
|
const oldSqliteDependency = `dependencies.${targetProperty}`;
|
|
24
26
|
if (j.has(oldSqliteDependency)) {
|
|
25
27
|
j.remove(oldSqliteDependency);
|
|
28
|
+
removed = true;
|
|
26
29
|
}
|
|
27
30
|
});
|
|
28
31
|
|
|
29
|
-
if (!j.has('dependencies.better-sqlite3')) {
|
|
30
|
-
|
|
31
|
-
j.set('dependencies.better-sqlite3', '9.0.0');
|
|
32
|
+
if (removed && !j.has('dependencies.better-sqlite3')) {
|
|
33
|
+
j.set('dependencies.better-sqlite3', '9.4.3');
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
return j.root();
|