@strapi/upgrade 0.0.0-experimental.e60ec1829240dae21c1e1d29076681c322288813 → 0.0.0-experimental.e9122b401c96877b6707775c4f893660eab93ae3
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 +19 -4
- package/dist/cli.js +64 -34
- package/dist/cli.js.map +1 -1
- package/dist/index.js +70 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -38
- 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/modules/runner/json/transform.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/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/nocontent-migrate-to-emptystatelayout.code.ts +30 -0
- package/resources/codemods/5.0.0/useRBAC-hook-import-change.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
|
@@ -326,7 +326,11 @@ const transformJSON = async (codemodPath, paths, config) => {
|
|
|
326
326
|
timeElapsed: "",
|
|
327
327
|
stats: {}
|
|
328
328
|
};
|
|
329
|
-
const esbuildOptions = {
|
|
329
|
+
const esbuildOptions = {
|
|
330
|
+
extensions: [".js", ".mjs", ".ts"],
|
|
331
|
+
hookIgnoreNodeModules: false,
|
|
332
|
+
hookMatcher: isEqual(codemodPath)
|
|
333
|
+
};
|
|
330
334
|
const { unregister } = register(esbuildOptions);
|
|
331
335
|
const module = require(codemodPath);
|
|
332
336
|
unregister();
|
|
@@ -371,8 +375,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
371
375
|
jsonRunnerFactory
|
|
372
376
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
373
377
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
374
|
-
const
|
|
375
|
-
const
|
|
378
|
+
const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
|
|
379
|
+
const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
|
|
380
|
+
const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
|
|
381
|
+
const PROJECT_CODE_EXTENSIONS = [
|
|
376
382
|
// Source files
|
|
377
383
|
"js",
|
|
378
384
|
"mjs",
|
|
@@ -381,22 +387,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
381
387
|
"jsx",
|
|
382
388
|
"tsx"
|
|
383
389
|
];
|
|
384
|
-
const
|
|
385
|
-
const
|
|
386
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
387
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
388
|
-
];
|
|
389
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
390
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
391
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
390
392
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
391
393
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
392
394
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
393
395
|
__proto__: null,
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
396
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
397
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
398
|
+
PROJECT_CODE_EXTENSIONS,
|
|
399
|
+
PROJECT_JSON_EXTENSIONS,
|
|
399
400
|
PROJECT_PACKAGE_JSON,
|
|
401
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
402
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
400
403
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
401
404
|
STRAPI_DEPENDENCY_NAME
|
|
402
405
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -406,11 +409,13 @@ class Project {
|
|
|
406
409
|
files;
|
|
407
410
|
packageJSONPath;
|
|
408
411
|
packageJSON;
|
|
409
|
-
|
|
412
|
+
paths;
|
|
413
|
+
constructor(cwd, config) {
|
|
410
414
|
if (!fse.pathExistsSync(cwd)) {
|
|
411
415
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
412
416
|
}
|
|
413
417
|
this.cwd = cwd;
|
|
418
|
+
this.paths = config.paths;
|
|
414
419
|
this.refresh();
|
|
415
420
|
}
|
|
416
421
|
getFilesByExtensions(extensions) {
|
|
@@ -438,12 +443,8 @@ class Project {
|
|
|
438
443
|
return reports2;
|
|
439
444
|
}
|
|
440
445
|
createProjectCodemodsRunners(dry = false) {
|
|
441
|
-
const jsonExtensions =
|
|
442
|
-
|
|
443
|
-
);
|
|
444
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
445
|
-
(ext) => `.${ext}`
|
|
446
|
-
);
|
|
446
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
447
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
447
448
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
448
449
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
449
450
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -451,7 +452,7 @@ class Project {
|
|
|
451
452
|
parser: "ts",
|
|
452
453
|
runInBand: true,
|
|
453
454
|
babel: true,
|
|
454
|
-
extensions:
|
|
455
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
455
456
|
// Don't output any log coming from the runner
|
|
456
457
|
print: false,
|
|
457
458
|
silent: true,
|
|
@@ -472,23 +473,30 @@ class Project {
|
|
|
472
473
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
473
474
|
}
|
|
474
475
|
refreshProjectFiles() {
|
|
475
|
-
const allowedRootPaths = formatGlobCollectionPattern(
|
|
476
|
-
PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
|
|
477
|
-
);
|
|
478
|
-
const allowedExtensions = formatGlobCollectionPattern(
|
|
479
|
-
PROJECT_DEFAULT_ALLOWED_EXTENSIONS
|
|
480
|
-
);
|
|
481
|
-
const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
|
|
482
|
-
const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
|
|
483
476
|
const scanner = fileScannerFactory(this.cwd);
|
|
484
|
-
this.files = scanner.scan(
|
|
477
|
+
this.files = scanner.scan(this.paths);
|
|
485
478
|
}
|
|
486
479
|
}
|
|
487
480
|
class AppProject extends Project {
|
|
488
481
|
strapiVersion;
|
|
489
482
|
type = "application";
|
|
483
|
+
/**
|
|
484
|
+
* Returns an array of allowed file paths for a Strapi application
|
|
485
|
+
*
|
|
486
|
+
* The resulting paths include app default files and the root package.json file.
|
|
487
|
+
*/
|
|
488
|
+
static get paths() {
|
|
489
|
+
const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
|
|
490
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
491
|
+
return [
|
|
492
|
+
// App default files
|
|
493
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
494
|
+
// Root package.json file
|
|
495
|
+
PROJECT_PACKAGE_JSON
|
|
496
|
+
];
|
|
497
|
+
}
|
|
490
498
|
constructor(cwd) {
|
|
491
|
-
super(cwd);
|
|
499
|
+
super(cwd, { paths: AppProject.paths });
|
|
492
500
|
this.refreshStrapiVersion();
|
|
493
501
|
}
|
|
494
502
|
refresh() {
|
|
@@ -543,6 +551,28 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
543
551
|
};
|
|
544
552
|
class PluginProject extends Project {
|
|
545
553
|
type = "plugin";
|
|
554
|
+
/**
|
|
555
|
+
* Returns an array of allowed file paths for a Strapi plugin
|
|
556
|
+
*
|
|
557
|
+
* The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
|
|
558
|
+
*/
|
|
559
|
+
static get paths() {
|
|
560
|
+
const allowedRootPaths = formatGlobCollectionPattern(
|
|
561
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
|
|
562
|
+
);
|
|
563
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
564
|
+
return [
|
|
565
|
+
// Plugin default files
|
|
566
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
567
|
+
// Root package.json file
|
|
568
|
+
PROJECT_PACKAGE_JSON,
|
|
569
|
+
// Plugin root files
|
|
570
|
+
...PROJECT_PLUGIN_ROOT_FILES
|
|
571
|
+
];
|
|
572
|
+
}
|
|
573
|
+
constructor(cwd) {
|
|
574
|
+
super(cwd, { paths: PluginProject.paths });
|
|
575
|
+
}
|
|
546
576
|
}
|
|
547
577
|
const isPlugin = (cwd) => {
|
|
548
578
|
const packageJSONPath = path$1.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -557,10 +587,7 @@ const isPlugin = (cwd) => {
|
|
|
557
587
|
};
|
|
558
588
|
const projectFactory = (cwd) => {
|
|
559
589
|
fse.accessSync(cwd);
|
|
560
|
-
|
|
561
|
-
return new PluginProject(cwd);
|
|
562
|
-
}
|
|
563
|
-
return new AppProject(cwd);
|
|
590
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
564
591
|
};
|
|
565
592
|
const isPluginProject = (project) => {
|
|
566
593
|
return project instanceof PluginProject;
|
|
@@ -613,6 +640,9 @@ const version = (version2) => {
|
|
|
613
640
|
const codemodUID = (uid) => {
|
|
614
641
|
return chalk.bold.cyan(uid);
|
|
615
642
|
};
|
|
643
|
+
const projectDetails = (project) => {
|
|
644
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
645
|
+
};
|
|
616
646
|
const projectType = (type) => chalk.cyan(type);
|
|
617
647
|
const versionRange = (range) => chalk.italic.yellow(range.raw);
|
|
618
648
|
const transform = (transformFilePath) => chalk.cyan(transformFilePath);
|
|
@@ -679,6 +709,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
679
709
|
durationMs,
|
|
680
710
|
highlight,
|
|
681
711
|
path,
|
|
712
|
+
projectDetails,
|
|
682
713
|
projectType,
|
|
683
714
|
reports,
|
|
684
715
|
transform,
|
|
@@ -1214,6 +1245,7 @@ const upgrade = async (options) => {
|
|
|
1214
1245
|
const { logger, codemodsTarget } = options;
|
|
1215
1246
|
const cwd = path$1.resolve(options.cwd ?? process.cwd());
|
|
1216
1247
|
const project = projectFactory(cwd);
|
|
1248
|
+
logger.debug(projectDetails(project));
|
|
1217
1249
|
if (!isApplicationProject(project)) {
|
|
1218
1250
|
throw new Error(
|
|
1219
1251
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1268,7 +1300,7 @@ const runCodemods = async (options) => {
|
|
|
1268
1300
|
const cwd = resolvePath(options.cwd);
|
|
1269
1301
|
const project = projectFactory(cwd);
|
|
1270
1302
|
const range = findRangeFromTarget(project, options.target);
|
|
1271
|
-
logger.debug(
|
|
1303
|
+
logger.debug(projectDetails(project));
|
|
1272
1304
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1273
1305
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1274
1306
|
let report;
|
|
@@ -1289,7 +1321,7 @@ const listCodemods = async (options) => {
|
|
|
1289
1321
|
const cwd = resolvePath(options.cwd);
|
|
1290
1322
|
const project = projectFactory(cwd);
|
|
1291
1323
|
const range = findRangeFromTarget(project, target);
|
|
1292
|
-
logger.debug(
|
|
1324
|
+
logger.debug(projectDetails(project));
|
|
1293
1325
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1294
1326
|
const repo = codemodRepositoryFactory();
|
|
1295
1327
|
repo.refresh();
|