@strapi/upgrade 0.0.0-experimental.22e8a4f31c0b65da00cc6c524a94de53fabc7a28
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 +22 -0
- package/README.md +171 -0
- package/bin/upgrade.js +2 -0
- package/dist/_chunks/codemod-runner-6FtEoXzL.js +729 -0
- package/dist/_chunks/codemod-runner-6FtEoXzL.js.map +1 -0
- package/dist/_chunks/codemods-1SG_Nr9F.js +108 -0
- package/dist/_chunks/codemods-1SG_Nr9F.js.map +1 -0
- package/dist/_chunks/index-lX2ZsI17.js +103 -0
- package/dist/_chunks/index-lX2ZsI17.js.map +1 -0
- package/dist/_chunks/upgrade-Qf1t7dYA.js +357 -0
- package/dist/_chunks/upgrade-Qf1t7dYA.js.map +1 -0
- package/dist/cli.js +7 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1199 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1191 -0
- package/dist/index.mjs.map +1 -0
- package/dist/modules/codemod/codemod.d.ts +15 -0
- package/dist/modules/codemod/codemod.d.ts.map +1 -0
- package/dist/modules/codemod/constants.d.ts +6 -0
- package/dist/modules/codemod/constants.d.ts.map +1 -0
- package/dist/modules/codemod/index.d.ts +4 -0
- package/dist/modules/codemod/index.d.ts.map +1 -0
- package/dist/modules/codemod/types.d.ts +19 -0
- package/dist/modules/codemod/types.d.ts.map +1 -0
- package/dist/modules/codemod-repository/constants.d.ts +2 -0
- package/dist/modules/codemod-repository/constants.d.ts.map +1 -0
- package/dist/modules/codemod-repository/index.d.ts +4 -0
- package/dist/modules/codemod-repository/index.d.ts.map +1 -0
- package/dist/modules/codemod-repository/repository.d.ts +21 -0
- package/dist/modules/codemod-repository/repository.d.ts.map +1 -0
- package/dist/modules/codemod-repository/types.d.ts +12 -0
- package/dist/modules/codemod-repository/types.d.ts.map +1 -0
- package/dist/modules/codemod-runner/codemod-runner.d.ts +19 -0
- package/dist/modules/codemod-runner/codemod-runner.d.ts.map +1 -0
- package/dist/modules/codemod-runner/index.d.ts +2 -0
- package/dist/modules/codemod-runner/index.d.ts.map +1 -0
- package/dist/modules/codemod-runner/types.d.ts +19 -0
- package/dist/modules/codemod-runner/types.d.ts.map +1 -0
- package/dist/modules/common/types.d.ts +3 -0
- package/dist/modules/common/types.d.ts.map +1 -0
- package/dist/modules/error/index.d.ts +2 -0
- package/dist/modules/error/index.d.ts.map +1 -0
- package/dist/modules/error/utils.d.ts +5 -0
- package/dist/modules/error/utils.d.ts.map +1 -0
- package/dist/modules/file-scanner/index.d.ts +3 -0
- package/dist/modules/file-scanner/index.d.ts.map +1 -0
- package/dist/modules/file-scanner/scanner.d.ts +8 -0
- package/dist/modules/file-scanner/scanner.d.ts.map +1 -0
- package/dist/modules/file-scanner/types.d.ts +5 -0
- package/dist/modules/file-scanner/types.d.ts.map +1 -0
- package/dist/modules/format/formats.d.ts +11 -0
- package/dist/modules/format/formats.d.ts.map +1 -0
- package/dist/modules/format/index.d.ts +2 -0
- package/dist/modules/format/index.d.ts.map +1 -0
- package/dist/modules/index.d.ts +14 -0
- package/dist/modules/index.d.ts.map +1 -0
- package/dist/modules/json/file.d.ts +4 -0
- package/dist/modules/json/file.d.ts.map +1 -0
- package/dist/modules/json/index.d.ts +4 -0
- package/dist/modules/json/index.d.ts.map +1 -0
- package/dist/modules/json/transform-api.d.ts +15 -0
- package/dist/modules/json/transform-api.d.ts.map +1 -0
- package/dist/modules/json/types.d.ts +11 -0
- package/dist/modules/json/types.d.ts.map +1 -0
- package/dist/modules/logger/index.d.ts +3 -0
- package/dist/modules/logger/index.d.ts.map +1 -0
- package/dist/modules/logger/logger.d.ts +27 -0
- package/dist/modules/logger/logger.d.ts.map +1 -0
- package/dist/modules/logger/types.d.ts +25 -0
- package/dist/modules/logger/types.d.ts.map +1 -0
- package/dist/modules/npm/constants.d.ts +2 -0
- package/dist/modules/npm/constants.d.ts.map +1 -0
- package/dist/modules/npm/index.d.ts +4 -0
- package/dist/modules/npm/index.d.ts.map +1 -0
- package/dist/modules/npm/package.d.ts +18 -0
- package/dist/modules/npm/package.d.ts.map +1 -0
- package/dist/modules/npm/types.d.ts +103 -0
- package/dist/modules/npm/types.d.ts.map +1 -0
- package/dist/modules/project/constants.d.ts +7 -0
- package/dist/modules/project/constants.d.ts.map +1 -0
- package/dist/modules/project/index.d.ts +4 -0
- package/dist/modules/project/index.d.ts.map +1 -0
- package/dist/modules/project/project.d.ts +23 -0
- package/dist/modules/project/project.d.ts.map +1 -0
- package/dist/modules/project/types.d.ts +26 -0
- package/dist/modules/project/types.d.ts.map +1 -0
- package/dist/modules/report/index.d.ts +3 -0
- package/dist/modules/report/index.d.ts.map +1 -0
- package/dist/modules/report/report.d.ts +5 -0
- package/dist/modules/report/report.d.ts.map +1 -0
- package/dist/modules/report/types.d.ts +15 -0
- package/dist/modules/report/types.d.ts.map +1 -0
- package/dist/modules/requirement/index.d.ts +3 -0
- package/dist/modules/requirement/index.d.ts.map +1 -0
- package/dist/modules/requirement/requirement.d.ts +15 -0
- package/dist/modules/requirement/requirement.d.ts.map +1 -0
- package/dist/modules/requirement/types.d.ts +47 -0
- package/dist/modules/requirement/types.d.ts.map +1 -0
- package/dist/modules/runner/code/code.d.ts +10 -0
- package/dist/modules/runner/code/code.d.ts.map +1 -0
- package/dist/modules/runner/code/index.d.ts +3 -0
- package/dist/modules/runner/code/index.d.ts.map +1 -0
- package/dist/modules/runner/code/types.d.ts +11 -0
- package/dist/modules/runner/code/types.d.ts.map +1 -0
- package/dist/modules/runner/index.d.ts +4 -0
- package/dist/modules/runner/index.d.ts.map +1 -0
- package/dist/modules/runner/json/index.d.ts +3 -0
- package/dist/modules/runner/json/index.d.ts.map +1 -0
- package/dist/modules/runner/json/json.d.ts +9 -0
- package/dist/modules/runner/json/json.d.ts.map +1 -0
- package/dist/modules/runner/json/transform.d.ts +4 -0
- package/dist/modules/runner/json/transform.d.ts.map +1 -0
- package/dist/modules/runner/json/types.d.ts +16 -0
- package/dist/modules/runner/json/types.d.ts.map +1 -0
- package/dist/modules/runner/runner.d.ts +11 -0
- package/dist/modules/runner/runner.d.ts.map +1 -0
- package/dist/modules/runner/types.d.ts +14 -0
- package/dist/modules/runner/types.d.ts.map +1 -0
- package/dist/modules/timer/constants.d.ts +2 -0
- package/dist/modules/timer/constants.d.ts.map +1 -0
- package/dist/modules/timer/index.d.ts +4 -0
- package/dist/modules/timer/index.d.ts.map +1 -0
- package/dist/modules/timer/timer.d.ts +12 -0
- package/dist/modules/timer/timer.d.ts.map +1 -0
- package/dist/modules/timer/types.d.ts +12 -0
- package/dist/modules/timer/types.d.ts.map +1 -0
- package/dist/modules/upgrader/constants.d.ts +2 -0
- package/dist/modules/upgrader/constants.d.ts.map +1 -0
- package/dist/modules/upgrader/index.d.ts +4 -0
- package/dist/modules/upgrader/index.d.ts.map +1 -0
- package/dist/modules/upgrader/types.d.ts +23 -0
- package/dist/modules/upgrader/types.d.ts.map +1 -0
- package/dist/modules/upgrader/upgrader.d.ts +36 -0
- package/dist/modules/upgrader/upgrader.d.ts.map +1 -0
- package/dist/modules/version/index.d.ts +4 -0
- package/dist/modules/version/index.d.ts.map +1 -0
- package/dist/modules/version/range.d.ts +6 -0
- package/dist/modules/version/range.d.ts.map +1 -0
- package/dist/modules/version/semver.d.ts +8 -0
- package/dist/modules/version/semver.d.ts.map +1 -0
- package/dist/modules/version/types.d.ts +10 -0
- package/dist/modules/version/types.d.ts.map +1 -0
- package/dist/tasks/codemods/codemods.d.ts +3 -0
- package/dist/tasks/codemods/codemods.d.ts.map +1 -0
- package/dist/tasks/codemods/index.d.ts +2 -0
- package/dist/tasks/codemods/index.d.ts.map +1 -0
- package/dist/tasks/codemods/types.d.ts +13 -0
- package/dist/tasks/codemods/types.d.ts.map +1 -0
- package/dist/tasks/index.d.ts +4 -0
- package/dist/tasks/index.d.ts.map +1 -0
- package/dist/tasks/upgrade/index.d.ts +4 -0
- package/dist/tasks/upgrade/index.d.ts.map +1 -0
- package/dist/tasks/upgrade/requirements/common.d.ts +5 -0
- package/dist/tasks/upgrade/requirements/common.d.ts.map +1 -0
- package/dist/tasks/upgrade/requirements/index.d.ts +3 -0
- package/dist/tasks/upgrade/requirements/index.d.ts.map +1 -0
- package/dist/tasks/upgrade/requirements/major.d.ts +3 -0
- package/dist/tasks/upgrade/requirements/major.d.ts.map +1 -0
- package/dist/tasks/upgrade/types.d.ts +12 -0
- package/dist/tasks/upgrade/types.d.ts.map +1 -0
- package/dist/tasks/upgrade/upgrade.d.ts +3 -0
- package/dist/tasks/upgrade/upgrade.d.ts.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +89 -0
- package/resources/codemods/5.0.0/.gitkeep +0 -0
- package/resources/codemods/5.0.0/s3-keys-wrapped-in-credentials.code.ts +169 -0
- package/resources/codemods/5.0.0/sqlite3-to-better-sqlite3.json.ts +37 -0
- package/resources/examples/console.log-to-console.info.code.ts +37 -0
- package/resources/examples/upgrade-strapi-version.json.ts +29 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015-present Strapi Solutions SAS
|
|
2
|
+
|
|
3
|
+
Portions of the Strapi software are licensed as follows:
|
|
4
|
+
|
|
5
|
+
- All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
|
|
6
|
+
|
|
7
|
+
- All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
|
|
8
|
+
|
|
9
|
+
MIT Expat License
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Strapi Upgrade Tool
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
The Strapi Upgrade Tool is the CLI for facilitating upgrades between Strapi versions.
|
|
6
|
+
|
|
7
|
+
It handles updating a project's package.json with the correct version of Strapi, running the package installer, and running suggested code transforms for breaking changes (in major versions).
|
|
8
|
+
|
|
9
|
+
Once released, it will be the recommended way to update to any major, minor, and patch versions of Strapi instead of manually modifying package.json files.
|
|
10
|
+
|
|
11
|
+
The tool offers the following commands:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
major [options] Upgrade to the next available major version of Strapi
|
|
15
|
+
minor [options] Upgrade to the latest minor and patch version of Strapi for the
|
|
16
|
+
current major
|
|
17
|
+
patch [options] Upgrade to latest patch version of Strapi for the current major
|
|
18
|
+
and minor
|
|
19
|
+
codemods [options] Run a set of available codemods for the selected target version
|
|
20
|
+
without updating the Strapi dependencies
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### What's a codemod / code transform?
|
|
24
|
+
|
|
25
|
+
Codemods are a scripted way to refactor code. Here we are providing and running these scripts for users for any changes necessary in user code between Strapi versions.
|
|
26
|
+
|
|
27
|
+
For example, if we need to rename a package used by Strapi projects, instead of instructing users to change the import, we provide a script that searches through the user's project and does the replacement for them.
|
|
28
|
+
|
|
29
|
+
### Types of Transforms
|
|
30
|
+
|
|
31
|
+
The upgrade tool provides two types of transforms:
|
|
32
|
+
|
|
33
|
+
- `json`: for updating a project's .json files, primarily intended for the `package.json`
|
|
34
|
+
- `code`: codemods; for updating a project's .js and .ts files
|
|
35
|
+
|
|
36
|
+
### Data Migrations
|
|
37
|
+
|
|
38
|
+
Data migrations are not handled by the upgrade tool.
|
|
39
|
+
|
|
40
|
+
For Strapi v4, no data migrations will be allowed and no support is planned (except in extenuating circumstances eg, a critical security issue somehow relating to the database shape)
|
|
41
|
+
|
|
42
|
+
For Strapi v5, automated data migrations can be added in the `packages/core/database` package of the `v5/main` branch of this repo.
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
This package is not yet released, so currently it can be run on a project in the monorepo /examples directory with the following command:
|
|
47
|
+
|
|
48
|
+
`../../packages/utils/upgrade/bin/upgrade`
|
|
49
|
+
|
|
50
|
+
Run the command with the `--help` option to see all the available options.
|
|
51
|
+
|
|
52
|
+
[Coming Soon] The Strapi Upgrade tool will be available using `npx @strapi/upgrade` and an alias for that within a project using `strapi upgrade`
|
|
53
|
+
|
|
54
|
+
## Writing a code transforms
|
|
55
|
+
|
|
56
|
+
To begin your code transform script, create a file `upgrade/resources/codemods/{X.X.X}/{short-description-of-action}.{code|json}.ts` where `X.X.X` is the target version of Strapi the codemod will be run for.
|
|
57
|
+
|
|
58
|
+
For example, all breaking changes for the initial release of Strapi v5 will go in `upgrade/resources/codemods/5.0.0`
|
|
59
|
+
|
|
60
|
+
Note that "short-description-of-action" will be converted to text displayed to the user with hyphens converted to spaces, for example: "short description of action"
|
|
61
|
+
|
|
62
|
+
### 'json' transforms
|
|
63
|
+
|
|
64
|
+
Your transform will be called for every json file in a user's project, and you must return the json object (modified or not) at the end to be passed to the next transform.
|
|
65
|
+
|
|
66
|
+
Here is an example JSON Transform script:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import path from 'node:path';
|
|
70
|
+
|
|
71
|
+
import type { JSONTransform } from '../../..';
|
|
72
|
+
|
|
73
|
+
const transform: JSONTransform = (file, params) => {
|
|
74
|
+
// Extract the json api and the cwd so we can target specific files
|
|
75
|
+
const { cwd, json } = params;
|
|
76
|
+
|
|
77
|
+
// To target only a root level package.json file:
|
|
78
|
+
const rootPackageJsonPath = path.join(cwd, 'package.json');
|
|
79
|
+
if (file.path !== rootPackageJsonPath) {
|
|
80
|
+
// Return the json object unmodified to pass it to the next transform
|
|
81
|
+
return file.json;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Use json() to get useful helpers for performing your transform
|
|
85
|
+
const j = json(file.json);
|
|
86
|
+
|
|
87
|
+
const strapiDepAddress = 'dependencies.@strapi/strapi';
|
|
88
|
+
|
|
89
|
+
// if this file contains a value at dependencies.@strapi/strapi
|
|
90
|
+
if (j.has(strapiDepAddress)) {
|
|
91
|
+
// we set the value to 5.0.0
|
|
92
|
+
j.set(strapiDepAddress, '5.0.0');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// at the end we must return the modified json object
|
|
96
|
+
return j.root();
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default transform;
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
For reference, these are the types for the relevant objects, which can be found in `packages/utils/upgrade/src/modules/json/types.ts`:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
export interface JSONTransformParams {
|
|
106
|
+
cwd: string;
|
|
107
|
+
json: (object: Utils.JSONObject) => JSONTransformAPI;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface JSONTransformAPI {
|
|
111
|
+
get<T extends Utils.JSONValue>(path?: string, defaultValue?: T): T | undefined;
|
|
112
|
+
has(path: string): boolean;
|
|
113
|
+
set(path: string, value: Utils.JSONValue): this;
|
|
114
|
+
merge(other: Utils.JSONObject): this;
|
|
115
|
+
root(): Utils.JSONObject;
|
|
116
|
+
remove(path: string): this;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type JSONTransform = (file: JSONSourceFile, params: JSONTransformParams) => Utils.JSONObject;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The methods available from `json()` are wrappers for the lodash methods of the same name:
|
|
123
|
+
|
|
124
|
+
- **get(path, default)**: get path or default if not found
|
|
125
|
+
- **set(path, value)**: set path (such as 'engines.node', 'dependencies', 'author.name') to value
|
|
126
|
+
- **has(path)**: checks if path exists
|
|
127
|
+
- **merge(obj)**: merges two json objects
|
|
128
|
+
- **root()**: returns the whole json object
|
|
129
|
+
- **remove(path)**: removes the attribute given the path (such as 'dependencies.strapi')
|
|
130
|
+
|
|
131
|
+
### 'code' codemod transforms
|
|
132
|
+
|
|
133
|
+
Codemod transforms use the [`jscodeshift`](https://github.com/facebook/jscodeshift) library to modify code passed in. Please see their documentation for advanced details.
|
|
134
|
+
|
|
135
|
+
The `file` and `api` parameters come directly from the [jsoncodeshift arguments of the same name](https://github.com/facebook/jscodeshift#arguments).
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import type { Transform } from 'jscodeshift';
|
|
139
|
+
|
|
140
|
+
const transform: Transform = (file, api) => {
|
|
141
|
+
// Extract the jscodeshift API
|
|
142
|
+
const { j } = api;
|
|
143
|
+
// Parse the file content
|
|
144
|
+
const root = j(file.source);
|
|
145
|
+
|
|
146
|
+
root
|
|
147
|
+
// Find console.log calls expressions
|
|
148
|
+
.find(j.CallExpression, {
|
|
149
|
+
callee: { object: { name: 'console' }, property: { name: 'log' } },
|
|
150
|
+
})
|
|
151
|
+
// For each call expression
|
|
152
|
+
.forEach((path) => {
|
|
153
|
+
const { callee } = path.node;
|
|
154
|
+
|
|
155
|
+
if (
|
|
156
|
+
// Make sure the callee is a member expression (object/property)
|
|
157
|
+
j.MemberExpression.check(callee) &&
|
|
158
|
+
// Make sure the property is an actual identifier (contains a name property)
|
|
159
|
+
j.Identifier.check(callee.property)
|
|
160
|
+
) {
|
|
161
|
+
// Update the property's identifier name
|
|
162
|
+
callee.property.name = 'info';
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Return the updated file content
|
|
167
|
+
return root.toSource();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export default transform;
|
|
171
|
+
```
|
package/bin/upgrade.js
ADDED