@strapi/upgrade 0.0.0-experimental.e14656d3b8681880212c13260b9a2b340c182f2d → 0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02
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/README.md +1 -1
- package/dist/cli.js +439 -317
- package/dist/cli.js.map +1 -1
- package/dist/index.js +462 -343
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +458 -340
- package/dist/index.mjs.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/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/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 +8 -8
- 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 +36 -14
- package/resources/utils/replace-jsx.ts +49 -0
- package/resources/codemods/5.0.0/change-useAPIErrorHandler-import.code.ts +0 -21
- package/resources/codemods/5.0.0/useRBAC-hook-import-change.code.ts +0 -21
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Version } from '../version';
|
|
2
2
|
import type { Codemod } from '../codemod';
|
|
3
3
|
import type { Report } from '../report';
|
|
4
|
-
import type { FileExtension, MinimalPackageJSON, RunCodemodsOptions } from './types';
|
|
4
|
+
import type { FileExtension, MinimalPackageJSON, ProjectConfig, RunCodemodsOptions } from './types';
|
|
5
5
|
export declare class Project {
|
|
6
6
|
cwd: string;
|
|
7
7
|
files: string[];
|
|
8
8
|
packageJSONPath: string;
|
|
9
9
|
packageJSON: MinimalPackageJSON;
|
|
10
|
-
|
|
10
|
+
readonly paths: string[];
|
|
11
|
+
constructor(cwd: string, config: ProjectConfig);
|
|
11
12
|
getFilesByExtensions(extensions: FileExtension[]): string[];
|
|
12
13
|
refresh(): this;
|
|
13
14
|
runCodemods(codemods: Codemod.List, options: RunCodemodsOptions): Promise<Report.CodemodReport[]>;
|
|
@@ -18,6 +19,12 @@ export declare class Project {
|
|
|
18
19
|
export declare class AppProject extends Project {
|
|
19
20
|
strapiVersion: Version.SemVer;
|
|
20
21
|
readonly type: "application";
|
|
22
|
+
/**
|
|
23
|
+
* Returns an array of allowed file paths for a Strapi application
|
|
24
|
+
*
|
|
25
|
+
* The resulting paths include app default files and the root package.json file.
|
|
26
|
+
*/
|
|
27
|
+
private static get paths();
|
|
21
28
|
constructor(cwd: string);
|
|
22
29
|
refresh(): this;
|
|
23
30
|
private refreshStrapiVersion;
|
|
@@ -26,6 +33,13 @@ export declare class AppProject extends Project {
|
|
|
26
33
|
}
|
|
27
34
|
export declare class PluginProject extends Project {
|
|
28
35
|
readonly type: "plugin";
|
|
36
|
+
/**
|
|
37
|
+
* Returns an array of allowed file paths for a Strapi plugin
|
|
38
|
+
*
|
|
39
|
+
* The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
|
|
40
|
+
*/
|
|
41
|
+
private static get paths();
|
|
42
|
+
constructor(cwd: string);
|
|
29
43
|
}
|
|
30
44
|
export declare const projectFactory: (cwd: string) => AppProject | PluginProject;
|
|
31
45
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/modules/project/project.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/modules/project/project.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,aAAa,EAEb,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,qBAAa,OAAO;IACX,GAAG,EAAE,MAAM,CAAC;IAIZ,KAAK,EAAG,MAAM,EAAE,CAAC;IAEjB,eAAe,EAAG,MAAM,CAAC;IAEzB,WAAW,EAAG,kBAAkB,CAAC;IAExC,SAAgB,KAAK,EAAE,MAAM,EAAE,CAAC;gBAEpB,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa;IAW9C,oBAAoB,CAAC,UAAU,EAAE,aAAa,EAAE;IAQhD,OAAO;IAOD,WAAW,CAAC,QAAQ,EAAE,OA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G,KAAK,CAAC,UAAU,CAAC;AAErB,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB"}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type { NPM } from '../npm';
|
|
2
|
+
import type { AppProject } from '../project';
|
|
1
3
|
import type { Version } from '../version';
|
|
2
4
|
import type { Requirement } from '../requirement';
|
|
3
5
|
import type { Logger } from '../logger';
|
|
4
6
|
import type { ConfirmationCallback } from '../common/types';
|
|
5
7
|
export interface Upgrader {
|
|
8
|
+
getNPMPackage(): NPM.Package;
|
|
9
|
+
getProject(): AppProject;
|
|
10
|
+
getTarget(): Version.SemVer;
|
|
6
11
|
setTarget(target: Version.SemVer): this;
|
|
7
12
|
setRequirements(requirements: Requirement.Requirement[]): this;
|
|
8
13
|
setLogger(logger: Logger): this;
|
|
@@ -10,6 +15,7 @@ export interface Upgrader {
|
|
|
10
15
|
syncCodemodsTarget(): this;
|
|
11
16
|
dry(enabled?: boolean): this;
|
|
12
17
|
onConfirm(callback: ConfirmationCallback | null): this;
|
|
18
|
+
confirm(message: string): Promise<boolean>;
|
|
13
19
|
addRequirement(requirement: Requirement.Requirement): this;
|
|
14
20
|
upgrade(): Promise<UpgradeReport>;
|
|
15
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/upgrader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,WAAW,QAAQ;IACvB,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IACxC,eAAe,CAAC,YAAY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CAAC,MAAM,GAAG,IAAI,CAAC;IACxC,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC;IAC/D,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAEhC,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IACrD,kBAAkB,IAAI,IAAI,CAAC;IAE3B,GAAG,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,SAAS,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,GAAG,IAAI,CAAC;IAEvD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE3C,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,WAAW,GAAG,IAAI,CAAC;IAE3D,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,aAAa,GACrB;IACE,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,IAAI,CAAC;CACb,GACD;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC"}
|
|
@@ -15,6 +15,9 @@ export declare class Upgrader implements UpgraderInterface {
|
|
|
15
15
|
private requirements;
|
|
16
16
|
private confirmationCallback;
|
|
17
17
|
constructor(project: AppProject, target: Version.SemVer, npmPackage: NPM.Package);
|
|
18
|
+
getNPMPackage(): NPM.Package;
|
|
19
|
+
getProject(): AppProject;
|
|
20
|
+
getTarget(): Version.SemVer;
|
|
18
21
|
setRequirements(requirements: Requirement.Requirement[]): this;
|
|
19
22
|
setTarget(target: Version.SemVer): this;
|
|
20
23
|
syncCodemodsTarget(): this;
|
|
@@ -24,6 +27,7 @@ export declare class Upgrader implements UpgraderInterface {
|
|
|
24
27
|
dry(enabled?: boolean): this;
|
|
25
28
|
addRequirement(requirement: Requirement.Requirement): this;
|
|
26
29
|
upgrade(): Promise<UpgradeReport>;
|
|
30
|
+
confirm(message: string): Promise<boolean>;
|
|
27
31
|
private checkRequirements;
|
|
28
32
|
private onSuccessfulRequirement;
|
|
29
33
|
private onFailedRequirement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrader.d.ts","sourceRoot":"","sources":["../../../src/modules/upgrader/upgrader.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,QAAQ,IAAI,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAI5D,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IAErC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAc;IAEzC,OAAO,CAAC,MAAM,CAAiB;IAE/B,OAAO,CAAC,cAAc,CAAkB;IAExC,OAAO,CAAC,KAAK,CAAU;IAEvB,OAAO,CAAC,MAAM,CAAgB;IAE9B,OAAO,CAAC,YAAY,CAA4B;IAEhD,OAAO,CAAC,oBAAoB,CAA8B;gBAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,OAAO;IAehF,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,WAAW,EAAE;IAKvD,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM;IAKhC,kBAAkB;IAqBlB,sBAAsB,CAAC,MAA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AU;IAIxB,SAAS,IAAI,OAAO,CAAC,MAAM;IAI3B,eAAe,CAAC,YAAY,EAAE,WAAW,CAAC,WAAW,EAAE;IAKvD,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM;IAKhC,kBAAkB;IAqBlB,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM;IAU7C,SAAS,CAAC,MAAM,EAAE,MAAM;IAKxB,SAAS,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI;IAK/C,GAAG,CAAC,OAAO,GAAE,OAAc;IAK3B,cAAc,CAAC,WAAW,EAAE,WAAW,CAAC,WAAW;IAW7C,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IAgDjC,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;YAQlC,iBAAiB;YAejB,uBAAuB;YAWvB,mBAAmB;YAyBnB,kBAAkB;IA+BhC,OAAO,CAAC,2BAA2B;YAkBrB,mBAAmB;YAkBnB,WAAW;CAW1B;AAyCD,eAAO,MAAM,eAAe,YACjB,UAAU,UACX,QAAQ,WAAW,GAAG,QAAQ,MAAM,cAChC,IAAI,OAAO,aAUxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/modules/version/range.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,aAE5C,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,QAAQ,MAAM,cAAc,QAAQ,WAAW,
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../../src/modules/version/range.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAGnC,eAAO,MAAM,YAAY,UAAW,MAAM,KAAG,aAE5C,CAAC;AAEF,eAAO,MAAM,oBAAoB,YAAa,QAAQ,MAAM,cAAc,QAAQ,WAAW,iBAiD5F,CAAC;AAEF,eAAO,MAAM,iBAAiB,mBACZ,QAAQ,MAAM,UACtB,QAAQ,WAAW,GAAG,QAAQ,MAAM,iBAW7C,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAAS,MAAM,YAAoC,CAAC;AAExF,eAAO,MAAM,eAAe,UAAW,OAAO,0BAE7C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/version/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,cAAc,GACtB,GAAG,OAAO,EAAE,GACZ,GAAG,OAAO,IAAI,OAAO,EAAE,GACvB,GAAG,OAAO,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,GAAG,OAAO,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;AAE/D,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE5C,oBAAY,WAAW;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/version/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,cAAc,GACtB,GAAG,OAAO,EAAE,GACZ,GAAG,OAAO,IAAI,OAAO,EAAE,GACvB,GAAG,OAAO,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;AAEvC,MAAM,MAAM,aAAa,GAAG,GAAG,OAAO,IAAI,OAAO,IAAI,OAAO,EAAE,CAAC;AAE/D,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE5C,oBAAY,WAAW;IAErB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IAEf,MAAM,WAAW;CAClB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tasks/codemods/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAmD,MAAM,uBAAuB,CAAC;AAEjG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,eAAO,MAAM,WAAW,SAAU,MAAM,WAAuC,CAAC;AAEhF,eAAO,MAAM,kBAAkB,mBACb,QAAQ,MAAM,UACtB,QAAQ,WAAW,GAAG,QAAQ,aAAa,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tasks/codemods/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAmD,MAAM,uBAAuB,CAAC;AAEjG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,eAAO,MAAM,WAAW,SAAU,MAAM,WAAuC,CAAC;AAEhF,eAAO,MAAM,kBAAkB,mBACb,QAAQ,MAAM,UACtB,QAAQ,WAAW,GAAG,QAAQ,aAAa,kBAoBpD,CAAC;AAEF,eAAO,MAAM,mBAAmB,YACrB,OAAO,UACR,QAAQ,WAAW,GAAG,QAAQ,aAAa,GAAG,aAAa,KAClE,aAeF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tasks/upgrade/prompts/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Upgrader } from '../../../modules/upgrader';
|
|
2
|
+
import type { UpgradeOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Handles the upgrade prompts when using the latest tag.
|
|
5
|
+
*
|
|
6
|
+
* - checks if an upgrade involves a major bump, warning and asking for user confirmation before proceeding
|
|
7
|
+
*/
|
|
8
|
+
export declare const latest: (upgrader: Upgrader, options: UpgradeOptions) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=latest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"latest.d.ts","sourceRoot":"","sources":["../../../../src/tasks/upgrade/prompts/latest.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,MAAM,aAAoB,QAAQ,WAAW,cAAc,kBAgDvE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"major.d.ts","sourceRoot":"","sources":["../../../../src/tasks/upgrade/requirements/major.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"major.d.ts","sourceRoot":"","sources":["../../../../src/tasks/upgrade/requirements/major.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,4BAA4B,gEAYxC,CAAC;AAEF,eAAO,MAAM,gCAAgC,gEAmB5C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../../src/tasks/upgrade/upgrade.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../../src/tasks/upgrade/upgrade.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9C,eAAO,MAAM,OAAO,YAAmB,cAAc,kBAuDpD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/upgrade",
|
|
3
|
-
"version": "0.0.0-experimental.
|
|
3
|
+
"version": "0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02",
|
|
4
4
|
"description": "CLI to upgrade Strapi applications effortless",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"strapi",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
"watch": "pack-up watch"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@strapi/utils": "0.0.0-experimental.
|
|
62
|
+
"@strapi/utils": "0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02",
|
|
63
63
|
"chalk": "4.1.2",
|
|
64
64
|
"cli-table3": "0.6.2",
|
|
65
65
|
"commander": "8.3.0",
|
|
66
66
|
"esbuild-register": "3.5.0",
|
|
67
|
+
"fast-glob": "3.3.2",
|
|
67
68
|
"fs-extra": "11.2.0",
|
|
68
|
-
"glob": "10.3.10",
|
|
69
69
|
"jscodeshift": "0.15.1",
|
|
70
70
|
"lodash": "4.17.21",
|
|
71
71
|
"memfs": "4.6.0",
|
|
@@ -75,16 +75,16 @@
|
|
|
75
75
|
"simple-git": "3.21.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@strapi/pack-up": "5.0.
|
|
79
|
-
"@strapi/types": "0.0.0-experimental.
|
|
78
|
+
"@strapi/pack-up": "5.0.2",
|
|
79
|
+
"@strapi/types": "0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02",
|
|
80
80
|
"@types/fs-extra": "11.0.4",
|
|
81
81
|
"@types/jscodeshift": "0.11.10",
|
|
82
|
-
"eslint-config-custom": "0.0.0-experimental.
|
|
82
|
+
"eslint-config-custom": "0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02",
|
|
83
83
|
"rimraf": "5.0.5"
|
|
84
84
|
},
|
|
85
85
|
"engines": {
|
|
86
|
-
"node": ">=18.0.0 <=
|
|
86
|
+
"node": ">=18.0.0 <=22.x.x",
|
|
87
87
|
"npm": ">=6.0.0"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "e350eaa6073e65190102b4b798c32c287053cc02"
|
|
90
90
|
}
|
|
@@ -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
|
+
};
|
|
@@ -3,9 +3,15 @@ import type { ImportDeclaration, JSCodeshift, Collection } from 'jscodeshift';
|
|
|
3
3
|
export const changeImportSpecifier = (
|
|
4
4
|
root: Collection,
|
|
5
5
|
j: JSCodeshift,
|
|
6
|
-
options: {
|
|
6
|
+
options: {
|
|
7
|
+
oldDependency: string;
|
|
8
|
+
newDependency: string;
|
|
9
|
+
oldMethodName: string;
|
|
10
|
+
newMethodName?: string;
|
|
11
|
+
}
|
|
7
12
|
): void => {
|
|
8
|
-
const {
|
|
13
|
+
const { oldMethodName, newMethodName, oldDependency, newDependency } = options;
|
|
14
|
+
const methodNameToReplace = newMethodName ?? oldMethodName;
|
|
9
15
|
|
|
10
16
|
// Flag to check if the method was imported from the old dependency
|
|
11
17
|
let methodImportedFromOldDependency = false;
|
|
@@ -21,7 +27,7 @@ export const changeImportSpecifier = (
|
|
|
21
27
|
// Check if the method is imported from the old dependency
|
|
22
28
|
const methodSpecifiers = importDeclaration.specifiers?.filter(
|
|
23
29
|
(specifier) =>
|
|
24
|
-
specifier.type === 'ImportSpecifier' && specifier.imported.name ===
|
|
30
|
+
specifier.type === 'ImportSpecifier' && specifier.imported.name === oldMethodName
|
|
25
31
|
);
|
|
26
32
|
|
|
27
33
|
if (methodSpecifiers && methodSpecifiers.length > 0) {
|
|
@@ -29,17 +35,17 @@ export const changeImportSpecifier = (
|
|
|
29
35
|
|
|
30
36
|
// Collect all aliases for the method
|
|
31
37
|
methodSpecifiers.forEach((specifier) => {
|
|
32
|
-
if (specifier.local && specifier.local.name !==
|
|
38
|
+
if (specifier.local && specifier.local.name !== oldMethodName) {
|
|
33
39
|
methodAliases.push(specifier.local.name);
|
|
34
40
|
} else {
|
|
35
|
-
methodAliases.push(
|
|
41
|
+
methodAliases.push(methodNameToReplace);
|
|
36
42
|
}
|
|
37
43
|
});
|
|
38
44
|
|
|
39
45
|
// Remove the method specifiers from the old import
|
|
40
46
|
const updatedSpecifiers = importDeclaration.specifiers?.filter(
|
|
41
47
|
(specifier) =>
|
|
42
|
-
specifier.type !== 'ImportSpecifier' || specifier.imported.name !==
|
|
48
|
+
specifier.type !== 'ImportSpecifier' || specifier.imported.name !== oldMethodName
|
|
43
49
|
);
|
|
44
50
|
|
|
45
51
|
if (updatedSpecifiers && updatedSpecifiers.length > 0) {
|
|
@@ -59,20 +65,36 @@ export const changeImportSpecifier = (
|
|
|
59
65
|
.filter((path) => path.node.source.value === newDependency);
|
|
60
66
|
|
|
61
67
|
if (dependencies.length > 0) {
|
|
68
|
+
// we have to use a flag to prevent adding the method to multiple imports
|
|
69
|
+
let methodAdded = false;
|
|
62
70
|
dependencies.forEach((path) => {
|
|
63
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
|
+
);
|
|
64
82
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
94
|
});
|
|
73
95
|
} else {
|
|
74
96
|
const newSpecifiers = methodAliases.map((alias) =>
|
|
75
|
-
j.importSpecifier(j.identifier(
|
|
97
|
+
j.importSpecifier(j.identifier(methodNameToReplace), j.identifier(alias))
|
|
76
98
|
);
|
|
77
99
|
|
|
78
100
|
const newImportDeclaration = j.importDeclaration(newSpecifiers, j.literal(newDependency));
|
|
@@ -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
|
+
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Transform } from 'jscodeshift';
|
|
2
|
-
import { changeImportSpecifier } from '../../utils/change-import';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* change useAPIErrorHandler import from '@strapi/helper-plugin' to '@strapi/strapi/admin'
|
|
6
|
-
*/
|
|
7
|
-
const transform: Transform = (file, api) => {
|
|
8
|
-
const { j } = api;
|
|
9
|
-
|
|
10
|
-
const root = j.withParser('tsx')(file.source);
|
|
11
|
-
|
|
12
|
-
changeImportSpecifier(root, j, {
|
|
13
|
-
methodName: 'useAPIErrorHandler',
|
|
14
|
-
oldDependency: '@strapi/helper-plugin',
|
|
15
|
-
newDependency: '@strapi/strapi/admin',
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return root.toSource();
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default transform;
|