@strapi/upgrade 5.0.0-rc.2 → 5.0.0-rc.20
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/dist/cli.js +68 -35
- package/dist/cli.js.map +1 -1
- package/dist/index.js +74 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +73 -39
- package/dist/index.mjs.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/tasks/upgrade/upgrade.d.ts.map +1 -1
- package/package.json +6 -6
- package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
- package/resources/codemods/5.0.0/dependency-upgrade-react-and-react-dom.json.ts +67 -0
- package/resources/codemods/5.0.0/dependency-upgrade-styled-components.json.ts +49 -0
- package/resources/codemods/5.0.0/deprecate-helper-plugin-check-page-permissions.code.ts +30 -0
- package/resources/codemods/5.0.0/deprecate-helper-plugin-no-content.code.ts +30 -0
- package/resources/codemods/5.0.0/deprecate-helper-plugin-use-api-error-handler.code.ts +21 -0
- package/resources/codemods/5.0.0/deprecate-helper-plugin-use-rbac.code.ts +21 -0
- package/resources/utils/change-import.ts +105 -0
- package/resources/utils/replace-jsx.ts +49 -0
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { packageManager } from "@strapi/utils";
|
|
|
6
6
|
import { cloneDeep, get, has, merge, set, omit, isEqual, groupBy, size } from "lodash/fp";
|
|
7
7
|
import fse from "fs-extra";
|
|
8
8
|
import assert from "node:assert";
|
|
9
|
-
import
|
|
9
|
+
import fastglob from "fast-glob";
|
|
10
10
|
import { run } from "jscodeshift/src/Runner";
|
|
11
11
|
import { register } from "esbuild-register/dist/node";
|
|
12
12
|
import CliTable3 from "cli-table3";
|
|
@@ -277,7 +277,9 @@ class FileScanner {
|
|
|
277
277
|
this.cwd = cwd;
|
|
278
278
|
}
|
|
279
279
|
scan(patterns) {
|
|
280
|
-
const filenames =
|
|
280
|
+
const filenames = fastglob.sync(patterns, {
|
|
281
|
+
cwd: this.cwd
|
|
282
|
+
});
|
|
281
283
|
return filenames.map((filename) => path$1.join(this.cwd, filename));
|
|
282
284
|
}
|
|
283
285
|
}
|
|
@@ -375,8 +377,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
375
377
|
jsonRunnerFactory
|
|
376
378
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
377
379
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
378
|
-
const
|
|
379
|
-
const
|
|
380
|
+
const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
|
|
381
|
+
const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
|
|
382
|
+
const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
|
|
383
|
+
const PROJECT_CODE_EXTENSIONS = [
|
|
380
384
|
// Source files
|
|
381
385
|
"js",
|
|
382
386
|
"mjs",
|
|
@@ -385,22 +389,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
385
389
|
"jsx",
|
|
386
390
|
"tsx"
|
|
387
391
|
];
|
|
388
|
-
const
|
|
389
|
-
const
|
|
390
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
391
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
392
|
-
];
|
|
393
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
392
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
393
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
394
394
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
395
395
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
396
396
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
397
397
|
__proto__: null,
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
398
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
399
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
400
|
+
PROJECT_CODE_EXTENSIONS,
|
|
401
|
+
PROJECT_JSON_EXTENSIONS,
|
|
403
402
|
PROJECT_PACKAGE_JSON,
|
|
403
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
404
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
404
405
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
405
406
|
STRAPI_DEPENDENCY_NAME
|
|
406
407
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -410,11 +411,13 @@ class Project {
|
|
|
410
411
|
files;
|
|
411
412
|
packageJSONPath;
|
|
412
413
|
packageJSON;
|
|
413
|
-
|
|
414
|
+
paths;
|
|
415
|
+
constructor(cwd, config) {
|
|
414
416
|
if (!fse.pathExistsSync(cwd)) {
|
|
415
417
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
416
418
|
}
|
|
417
419
|
this.cwd = cwd;
|
|
420
|
+
this.paths = config.paths;
|
|
418
421
|
this.refresh();
|
|
419
422
|
}
|
|
420
423
|
getFilesByExtensions(extensions) {
|
|
@@ -442,12 +445,8 @@ class Project {
|
|
|
442
445
|
return reports2;
|
|
443
446
|
}
|
|
444
447
|
createProjectCodemodsRunners(dry = false) {
|
|
445
|
-
const jsonExtensions =
|
|
446
|
-
|
|
447
|
-
);
|
|
448
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
449
|
-
(ext) => `.${ext}`
|
|
450
|
-
);
|
|
448
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
449
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
451
450
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
452
451
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
453
452
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -455,7 +454,7 @@ class Project {
|
|
|
455
454
|
parser: "ts",
|
|
456
455
|
runInBand: true,
|
|
457
456
|
babel: true,
|
|
458
|
-
extensions:
|
|
457
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
459
458
|
// Don't output any log coming from the runner
|
|
460
459
|
print: false,
|
|
461
460
|
silent: true,
|
|
@@ -476,23 +475,32 @@ class Project {
|
|
|
476
475
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
477
476
|
}
|
|
478
477
|
refreshProjectFiles() {
|
|
479
|
-
const allowedRootPaths = formatGlobCollectionPattern(
|
|
480
|
-
PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
|
|
481
|
-
);
|
|
482
|
-
const allowedExtensions = formatGlobCollectionPattern(
|
|
483
|
-
PROJECT_DEFAULT_ALLOWED_EXTENSIONS
|
|
484
|
-
);
|
|
485
|
-
const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
|
|
486
|
-
const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
|
|
487
478
|
const scanner = fileScannerFactory(this.cwd);
|
|
488
|
-
this.files = scanner.scan(
|
|
479
|
+
this.files = scanner.scan(this.paths);
|
|
489
480
|
}
|
|
490
481
|
}
|
|
491
482
|
class AppProject extends Project {
|
|
492
483
|
strapiVersion;
|
|
493
484
|
type = "application";
|
|
485
|
+
/**
|
|
486
|
+
* Returns an array of allowed file paths for a Strapi application
|
|
487
|
+
*
|
|
488
|
+
* The resulting paths include app default files and the root package.json file.
|
|
489
|
+
*/
|
|
490
|
+
static get paths() {
|
|
491
|
+
const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
|
|
492
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
493
|
+
return [
|
|
494
|
+
// App default files
|
|
495
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
496
|
+
`!./**/node_modules/**/*`,
|
|
497
|
+
`!./**/dist/**/*`,
|
|
498
|
+
// Root package.json file
|
|
499
|
+
PROJECT_PACKAGE_JSON
|
|
500
|
+
];
|
|
501
|
+
}
|
|
494
502
|
constructor(cwd) {
|
|
495
|
-
super(cwd);
|
|
503
|
+
super(cwd, { paths: AppProject.paths });
|
|
496
504
|
this.refreshStrapiVersion();
|
|
497
505
|
}
|
|
498
506
|
refresh() {
|
|
@@ -547,6 +555,30 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
547
555
|
};
|
|
548
556
|
class PluginProject extends Project {
|
|
549
557
|
type = "plugin";
|
|
558
|
+
/**
|
|
559
|
+
* Returns an array of allowed file paths for a Strapi plugin
|
|
560
|
+
*
|
|
561
|
+
* The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
|
|
562
|
+
*/
|
|
563
|
+
static get paths() {
|
|
564
|
+
const allowedRootPaths = formatGlobCollectionPattern(
|
|
565
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
|
|
566
|
+
);
|
|
567
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
568
|
+
return [
|
|
569
|
+
// Plugin default files
|
|
570
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
571
|
+
`!./**/node_modules/**/*`,
|
|
572
|
+
`!./**/dist/**/*`,
|
|
573
|
+
// Root package.json file
|
|
574
|
+
PROJECT_PACKAGE_JSON,
|
|
575
|
+
// Plugin root files
|
|
576
|
+
...PROJECT_PLUGIN_ROOT_FILES
|
|
577
|
+
];
|
|
578
|
+
}
|
|
579
|
+
constructor(cwd) {
|
|
580
|
+
super(cwd, { paths: PluginProject.paths });
|
|
581
|
+
}
|
|
550
582
|
}
|
|
551
583
|
const isPlugin = (cwd) => {
|
|
552
584
|
const packageJSONPath = path$1.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -561,10 +593,7 @@ const isPlugin = (cwd) => {
|
|
|
561
593
|
};
|
|
562
594
|
const projectFactory = (cwd) => {
|
|
563
595
|
fse.accessSync(cwd);
|
|
564
|
-
|
|
565
|
-
return new PluginProject(cwd);
|
|
566
|
-
}
|
|
567
|
-
return new AppProject(cwd);
|
|
596
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
568
597
|
};
|
|
569
598
|
const isPluginProject = (project) => {
|
|
570
599
|
return project instanceof PluginProject;
|
|
@@ -617,6 +646,9 @@ const version = (version2) => {
|
|
|
617
646
|
const codemodUID = (uid) => {
|
|
618
647
|
return chalk.bold.cyan(uid);
|
|
619
648
|
};
|
|
649
|
+
const projectDetails = (project) => {
|
|
650
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
651
|
+
};
|
|
620
652
|
const projectType = (type) => chalk.cyan(type);
|
|
621
653
|
const versionRange = (range) => chalk.italic.yellow(range.raw);
|
|
622
654
|
const transform = (transformFilePath) => chalk.cyan(transformFilePath);
|
|
@@ -683,6 +715,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
683
715
|
durationMs,
|
|
684
716
|
highlight,
|
|
685
717
|
path,
|
|
718
|
+
projectDetails,
|
|
686
719
|
projectType,
|
|
687
720
|
reports,
|
|
688
721
|
transform,
|
|
@@ -1218,6 +1251,7 @@ const upgrade = async (options) => {
|
|
|
1218
1251
|
const { logger, codemodsTarget } = options;
|
|
1219
1252
|
const cwd = path$1.resolve(options.cwd ?? process.cwd());
|
|
1220
1253
|
const project = projectFactory(cwd);
|
|
1254
|
+
logger.debug(projectDetails(project));
|
|
1221
1255
|
if (!isApplicationProject(project)) {
|
|
1222
1256
|
throw new Error(
|
|
1223
1257
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1272,7 +1306,7 @@ const runCodemods = async (options) => {
|
|
|
1272
1306
|
const cwd = resolvePath(options.cwd);
|
|
1273
1307
|
const project = projectFactory(cwd);
|
|
1274
1308
|
const range = findRangeFromTarget(project, options.target);
|
|
1275
|
-
logger.debug(
|
|
1309
|
+
logger.debug(projectDetails(project));
|
|
1276
1310
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1277
1311
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1278
1312
|
let report;
|
|
@@ -1293,7 +1327,7 @@ const listCodemods = async (options) => {
|
|
|
1293
1327
|
const cwd = resolvePath(options.cwd);
|
|
1294
1328
|
const project = projectFactory(cwd);
|
|
1295
1329
|
const range = findRangeFromTarget(project, target);
|
|
1296
|
-
logger.debug(
|
|
1330
|
+
logger.debug(projectDetails(project));
|
|
1297
1331
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1298
1332
|
const repo = codemodRepositoryFactory();
|
|
1299
1333
|
repo.refresh();
|