@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.js
CHANGED
|
@@ -8,7 +8,7 @@ const utils = require("@strapi/utils");
|
|
|
8
8
|
const fp = require("lodash/fp");
|
|
9
9
|
const fse = require("fs-extra");
|
|
10
10
|
const assert = require("node:assert");
|
|
11
|
-
const
|
|
11
|
+
const fastglob = require("fast-glob");
|
|
12
12
|
const Runner = require("jscodeshift/src/Runner");
|
|
13
13
|
const node = require("esbuild-register/dist/node");
|
|
14
14
|
const CliTable3 = require("cli-table3");
|
|
@@ -19,6 +19,7 @@ const chalk__default = /* @__PURE__ */ _interopDefault(chalk);
|
|
|
19
19
|
const semver__default = /* @__PURE__ */ _interopDefault(semver);
|
|
20
20
|
const fse__default = /* @__PURE__ */ _interopDefault(fse);
|
|
21
21
|
const assert__default = /* @__PURE__ */ _interopDefault(assert);
|
|
22
|
+
const fastglob__default = /* @__PURE__ */ _interopDefault(fastglob);
|
|
22
23
|
const CliTable3__default = /* @__PURE__ */ _interopDefault(CliTable3);
|
|
23
24
|
class Requirement {
|
|
24
25
|
isRequired;
|
|
@@ -287,7 +288,9 @@ class FileScanner {
|
|
|
287
288
|
this.cwd = cwd;
|
|
288
289
|
}
|
|
289
290
|
scan(patterns) {
|
|
290
|
-
const filenames =
|
|
291
|
+
const filenames = fastglob__default.default.sync(patterns, {
|
|
292
|
+
cwd: this.cwd
|
|
293
|
+
});
|
|
291
294
|
return filenames.map((filename) => path__default.default.join(this.cwd, filename));
|
|
292
295
|
}
|
|
293
296
|
}
|
|
@@ -385,8 +388,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
385
388
|
jsonRunnerFactory
|
|
386
389
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
387
390
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
388
|
-
const
|
|
389
|
-
const
|
|
391
|
+
const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
|
|
392
|
+
const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
|
|
393
|
+
const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
|
|
394
|
+
const PROJECT_CODE_EXTENSIONS = [
|
|
390
395
|
// Source files
|
|
391
396
|
"js",
|
|
392
397
|
"mjs",
|
|
@@ -395,22 +400,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
395
400
|
"jsx",
|
|
396
401
|
"tsx"
|
|
397
402
|
];
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
401
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
402
|
-
];
|
|
403
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
403
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
404
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
404
405
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
405
406
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
406
407
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
407
408
|
__proto__: null,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
409
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
410
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
411
|
+
PROJECT_CODE_EXTENSIONS,
|
|
412
|
+
PROJECT_JSON_EXTENSIONS,
|
|
413
413
|
PROJECT_PACKAGE_JSON,
|
|
414
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
415
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
414
416
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
415
417
|
STRAPI_DEPENDENCY_NAME
|
|
416
418
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -420,11 +422,13 @@ class Project {
|
|
|
420
422
|
files;
|
|
421
423
|
packageJSONPath;
|
|
422
424
|
packageJSON;
|
|
423
|
-
|
|
425
|
+
paths;
|
|
426
|
+
constructor(cwd, config) {
|
|
424
427
|
if (!fse__default.default.pathExistsSync(cwd)) {
|
|
425
428
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
426
429
|
}
|
|
427
430
|
this.cwd = cwd;
|
|
431
|
+
this.paths = config.paths;
|
|
428
432
|
this.refresh();
|
|
429
433
|
}
|
|
430
434
|
getFilesByExtensions(extensions) {
|
|
@@ -452,12 +456,8 @@ class Project {
|
|
|
452
456
|
return reports2;
|
|
453
457
|
}
|
|
454
458
|
createProjectCodemodsRunners(dry = false) {
|
|
455
|
-
const jsonExtensions =
|
|
456
|
-
|
|
457
|
-
);
|
|
458
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
459
|
-
(ext) => `.${ext}`
|
|
460
|
-
);
|
|
459
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
460
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
461
461
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
462
462
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
463
463
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -465,7 +465,7 @@ class Project {
|
|
|
465
465
|
parser: "ts",
|
|
466
466
|
runInBand: true,
|
|
467
467
|
babel: true,
|
|
468
|
-
extensions:
|
|
468
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
469
469
|
// Don't output any log coming from the runner
|
|
470
470
|
print: false,
|
|
471
471
|
silent: true,
|
|
@@ -486,23 +486,32 @@ class Project {
|
|
|
486
486
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
487
487
|
}
|
|
488
488
|
refreshProjectFiles() {
|
|
489
|
-
const allowedRootPaths = formatGlobCollectionPattern(
|
|
490
|
-
PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
|
|
491
|
-
);
|
|
492
|
-
const allowedExtensions = formatGlobCollectionPattern(
|
|
493
|
-
PROJECT_DEFAULT_ALLOWED_EXTENSIONS
|
|
494
|
-
);
|
|
495
|
-
const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
|
|
496
|
-
const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
|
|
497
489
|
const scanner = fileScannerFactory(this.cwd);
|
|
498
|
-
this.files = scanner.scan(
|
|
490
|
+
this.files = scanner.scan(this.paths);
|
|
499
491
|
}
|
|
500
492
|
}
|
|
501
493
|
class AppProject extends Project {
|
|
502
494
|
strapiVersion;
|
|
503
495
|
type = "application";
|
|
496
|
+
/**
|
|
497
|
+
* Returns an array of allowed file paths for a Strapi application
|
|
498
|
+
*
|
|
499
|
+
* The resulting paths include app default files and the root package.json file.
|
|
500
|
+
*/
|
|
501
|
+
static get paths() {
|
|
502
|
+
const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
|
|
503
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
504
|
+
return [
|
|
505
|
+
// App default files
|
|
506
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
507
|
+
`!./**/node_modules/**/*`,
|
|
508
|
+
`!./**/dist/**/*`,
|
|
509
|
+
// Root package.json file
|
|
510
|
+
PROJECT_PACKAGE_JSON
|
|
511
|
+
];
|
|
512
|
+
}
|
|
504
513
|
constructor(cwd) {
|
|
505
|
-
super(cwd);
|
|
514
|
+
super(cwd, { paths: AppProject.paths });
|
|
506
515
|
this.refreshStrapiVersion();
|
|
507
516
|
}
|
|
508
517
|
refresh() {
|
|
@@ -557,6 +566,30 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
557
566
|
};
|
|
558
567
|
class PluginProject extends Project {
|
|
559
568
|
type = "plugin";
|
|
569
|
+
/**
|
|
570
|
+
* Returns an array of allowed file paths for a Strapi plugin
|
|
571
|
+
*
|
|
572
|
+
* The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
|
|
573
|
+
*/
|
|
574
|
+
static get paths() {
|
|
575
|
+
const allowedRootPaths = formatGlobCollectionPattern(
|
|
576
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
|
|
577
|
+
);
|
|
578
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
579
|
+
return [
|
|
580
|
+
// Plugin default files
|
|
581
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
582
|
+
`!./**/node_modules/**/*`,
|
|
583
|
+
`!./**/dist/**/*`,
|
|
584
|
+
// Root package.json file
|
|
585
|
+
PROJECT_PACKAGE_JSON,
|
|
586
|
+
// Plugin root files
|
|
587
|
+
...PROJECT_PLUGIN_ROOT_FILES
|
|
588
|
+
];
|
|
589
|
+
}
|
|
590
|
+
constructor(cwd) {
|
|
591
|
+
super(cwd, { paths: PluginProject.paths });
|
|
592
|
+
}
|
|
560
593
|
}
|
|
561
594
|
const isPlugin = (cwd) => {
|
|
562
595
|
const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -571,10 +604,7 @@ const isPlugin = (cwd) => {
|
|
|
571
604
|
};
|
|
572
605
|
const projectFactory = (cwd) => {
|
|
573
606
|
fse__default.default.accessSync(cwd);
|
|
574
|
-
|
|
575
|
-
return new PluginProject(cwd);
|
|
576
|
-
}
|
|
577
|
-
return new AppProject(cwd);
|
|
607
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
578
608
|
};
|
|
579
609
|
const isPluginProject = (project) => {
|
|
580
610
|
return project instanceof PluginProject;
|
|
@@ -627,6 +657,9 @@ const version = (version2) => {
|
|
|
627
657
|
const codemodUID = (uid) => {
|
|
628
658
|
return chalk__default.default.bold.cyan(uid);
|
|
629
659
|
};
|
|
660
|
+
const projectDetails = (project) => {
|
|
661
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
662
|
+
};
|
|
630
663
|
const projectType = (type) => chalk__default.default.cyan(type);
|
|
631
664
|
const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
|
|
632
665
|
const transform = (transformFilePath) => chalk__default.default.cyan(transformFilePath);
|
|
@@ -693,6 +726,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
693
726
|
durationMs,
|
|
694
727
|
highlight,
|
|
695
728
|
path,
|
|
729
|
+
projectDetails,
|
|
696
730
|
projectType,
|
|
697
731
|
reports,
|
|
698
732
|
transform,
|
|
@@ -1228,6 +1262,7 @@ const upgrade = async (options) => {
|
|
|
1228
1262
|
const { logger, codemodsTarget } = options;
|
|
1229
1263
|
const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
|
|
1230
1264
|
const project = projectFactory(cwd);
|
|
1265
|
+
logger.debug(projectDetails(project));
|
|
1231
1266
|
if (!isApplicationProject(project)) {
|
|
1232
1267
|
throw new Error(
|
|
1233
1268
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1282,7 +1317,7 @@ const runCodemods = async (options) => {
|
|
|
1282
1317
|
const cwd = resolvePath(options.cwd);
|
|
1283
1318
|
const project = projectFactory(cwd);
|
|
1284
1319
|
const range = findRangeFromTarget(project, options.target);
|
|
1285
|
-
logger.debug(
|
|
1320
|
+
logger.debug(projectDetails(project));
|
|
1286
1321
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1287
1322
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1288
1323
|
let report;
|
|
@@ -1303,7 +1338,7 @@ const listCodemods = async (options) => {
|
|
|
1303
1338
|
const cwd = resolvePath(options.cwd);
|
|
1304
1339
|
const project = projectFactory(cwd);
|
|
1305
1340
|
const range = findRangeFromTarget(project, target);
|
|
1306
|
-
logger.debug(
|
|
1341
|
+
logger.debug(projectDetails(project));
|
|
1307
1342
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1308
1343
|
const repo = codemodRepositoryFactory();
|
|
1309
1344
|
repo.refresh();
|