@strapi/upgrade 5.0.0-rc.10 → 5.0.0-rc.12
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 +59 -33
- package/dist/cli.js.map +1 -1
- package/dist/index.js +65 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -37
- package/dist/index.mjs.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 +5 -5
- package/resources/codemods/5.0.0/change-useAPIErrorHandler-import.code.ts +21 -0
- package/resources/codemods/5.0.0/comment-out-lifecycle-files.code.ts +63 -0
- package/resources/codemods/5.0.0/useRBAC-hook-import-change.code.ts +21 -0
- package/resources/utils/change-import.ts +96 -0
package/dist/index.js
CHANGED
|
@@ -385,8 +385,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
385
385
|
jsonRunnerFactory
|
|
386
386
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
387
387
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
388
|
-
const
|
|
389
|
-
const
|
|
388
|
+
const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
|
|
389
|
+
const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
|
|
390
|
+
const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
|
|
391
|
+
const PROJECT_CODE_EXTENSIONS = [
|
|
390
392
|
// Source files
|
|
391
393
|
"js",
|
|
392
394
|
"mjs",
|
|
@@ -395,22 +397,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
395
397
|
"jsx",
|
|
396
398
|
"tsx"
|
|
397
399
|
];
|
|
398
|
-
const
|
|
399
|
-
const
|
|
400
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
401
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
402
|
-
];
|
|
403
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
400
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
401
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
404
402
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
405
403
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
406
404
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
407
405
|
__proto__: null,
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
406
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
407
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
408
|
+
PROJECT_CODE_EXTENSIONS,
|
|
409
|
+
PROJECT_JSON_EXTENSIONS,
|
|
413
410
|
PROJECT_PACKAGE_JSON,
|
|
411
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
412
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
414
413
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
415
414
|
STRAPI_DEPENDENCY_NAME
|
|
416
415
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -420,11 +419,13 @@ class Project {
|
|
|
420
419
|
files;
|
|
421
420
|
packageJSONPath;
|
|
422
421
|
packageJSON;
|
|
423
|
-
|
|
422
|
+
paths;
|
|
423
|
+
constructor(cwd, config) {
|
|
424
424
|
if (!fse__default.default.pathExistsSync(cwd)) {
|
|
425
425
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
426
426
|
}
|
|
427
427
|
this.cwd = cwd;
|
|
428
|
+
this.paths = config.paths;
|
|
428
429
|
this.refresh();
|
|
429
430
|
}
|
|
430
431
|
getFilesByExtensions(extensions) {
|
|
@@ -452,12 +453,8 @@ class Project {
|
|
|
452
453
|
return reports2;
|
|
453
454
|
}
|
|
454
455
|
createProjectCodemodsRunners(dry = false) {
|
|
455
|
-
const jsonExtensions =
|
|
456
|
-
|
|
457
|
-
);
|
|
458
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
459
|
-
(ext) => `.${ext}`
|
|
460
|
-
);
|
|
456
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
457
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
461
458
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
462
459
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
463
460
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -465,7 +462,7 @@ class Project {
|
|
|
465
462
|
parser: "ts",
|
|
466
463
|
runInBand: true,
|
|
467
464
|
babel: true,
|
|
468
|
-
extensions:
|
|
465
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
469
466
|
// Don't output any log coming from the runner
|
|
470
467
|
print: false,
|
|
471
468
|
silent: true,
|
|
@@ -486,23 +483,30 @@ class Project {
|
|
|
486
483
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
487
484
|
}
|
|
488
485
|
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
486
|
const scanner = fileScannerFactory(this.cwd);
|
|
498
|
-
this.files = scanner.scan(
|
|
487
|
+
this.files = scanner.scan(this.paths);
|
|
499
488
|
}
|
|
500
489
|
}
|
|
501
490
|
class AppProject extends Project {
|
|
502
491
|
strapiVersion;
|
|
503
492
|
type = "application";
|
|
493
|
+
/**
|
|
494
|
+
* Returns an array of allowed file paths for a Strapi application
|
|
495
|
+
*
|
|
496
|
+
* The resulting paths include app default files and the root package.json file.
|
|
497
|
+
*/
|
|
498
|
+
static get paths() {
|
|
499
|
+
const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
|
|
500
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
501
|
+
return [
|
|
502
|
+
// App default files
|
|
503
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
504
|
+
// Root package.json file
|
|
505
|
+
PROJECT_PACKAGE_JSON
|
|
506
|
+
];
|
|
507
|
+
}
|
|
504
508
|
constructor(cwd) {
|
|
505
|
-
super(cwd);
|
|
509
|
+
super(cwd, { paths: AppProject.paths });
|
|
506
510
|
this.refreshStrapiVersion();
|
|
507
511
|
}
|
|
508
512
|
refresh() {
|
|
@@ -557,6 +561,28 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
557
561
|
};
|
|
558
562
|
class PluginProject extends Project {
|
|
559
563
|
type = "plugin";
|
|
564
|
+
/**
|
|
565
|
+
* Returns an array of allowed file paths for a Strapi plugin
|
|
566
|
+
*
|
|
567
|
+
* The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
|
|
568
|
+
*/
|
|
569
|
+
static get paths() {
|
|
570
|
+
const allowedRootPaths = formatGlobCollectionPattern(
|
|
571
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
|
|
572
|
+
);
|
|
573
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
574
|
+
return [
|
|
575
|
+
// Plugin default files
|
|
576
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
577
|
+
// Root package.json file
|
|
578
|
+
PROJECT_PACKAGE_JSON,
|
|
579
|
+
// Plugin root files
|
|
580
|
+
...PROJECT_PLUGIN_ROOT_FILES
|
|
581
|
+
];
|
|
582
|
+
}
|
|
583
|
+
constructor(cwd) {
|
|
584
|
+
super(cwd, { paths: PluginProject.paths });
|
|
585
|
+
}
|
|
560
586
|
}
|
|
561
587
|
const isPlugin = (cwd) => {
|
|
562
588
|
const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -571,10 +597,7 @@ const isPlugin = (cwd) => {
|
|
|
571
597
|
};
|
|
572
598
|
const projectFactory = (cwd) => {
|
|
573
599
|
fse__default.default.accessSync(cwd);
|
|
574
|
-
|
|
575
|
-
return new PluginProject(cwd);
|
|
576
|
-
}
|
|
577
|
-
return new AppProject(cwd);
|
|
600
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
578
601
|
};
|
|
579
602
|
const isPluginProject = (project) => {
|
|
580
603
|
return project instanceof PluginProject;
|
|
@@ -627,6 +650,9 @@ const version = (version2) => {
|
|
|
627
650
|
const codemodUID = (uid) => {
|
|
628
651
|
return chalk__default.default.bold.cyan(uid);
|
|
629
652
|
};
|
|
653
|
+
const projectDetails = (project) => {
|
|
654
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
655
|
+
};
|
|
630
656
|
const projectType = (type) => chalk__default.default.cyan(type);
|
|
631
657
|
const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
|
|
632
658
|
const transform = (transformFilePath) => chalk__default.default.cyan(transformFilePath);
|
|
@@ -693,6 +719,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
693
719
|
durationMs,
|
|
694
720
|
highlight,
|
|
695
721
|
path,
|
|
722
|
+
projectDetails,
|
|
696
723
|
projectType,
|
|
697
724
|
reports,
|
|
698
725
|
transform,
|
|
@@ -1228,6 +1255,7 @@ const upgrade = async (options) => {
|
|
|
1228
1255
|
const { logger, codemodsTarget } = options;
|
|
1229
1256
|
const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
|
|
1230
1257
|
const project = projectFactory(cwd);
|
|
1258
|
+
logger.debug(projectDetails(project));
|
|
1231
1259
|
if (!isApplicationProject(project)) {
|
|
1232
1260
|
throw new Error(
|
|
1233
1261
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1282,7 +1310,7 @@ const runCodemods = async (options) => {
|
|
|
1282
1310
|
const cwd = resolvePath(options.cwd);
|
|
1283
1311
|
const project = projectFactory(cwd);
|
|
1284
1312
|
const range = findRangeFromTarget(project, options.target);
|
|
1285
|
-
logger.debug(
|
|
1313
|
+
logger.debug(projectDetails(project));
|
|
1286
1314
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1287
1315
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1288
1316
|
let report;
|
|
@@ -1303,7 +1331,7 @@ const listCodemods = async (options) => {
|
|
|
1303
1331
|
const cwd = resolvePath(options.cwd);
|
|
1304
1332
|
const project = projectFactory(cwd);
|
|
1305
1333
|
const range = findRangeFromTarget(project, target);
|
|
1306
|
-
logger.debug(
|
|
1334
|
+
logger.debug(projectDetails(project));
|
|
1307
1335
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1308
1336
|
const repo = codemodRepositoryFactory();
|
|
1309
1337
|
repo.refresh();
|