@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.js
CHANGED
|
@@ -336,7 +336,11 @@ const transformJSON = async (codemodPath, paths, config) => {
|
|
|
336
336
|
timeElapsed: "",
|
|
337
337
|
stats: {}
|
|
338
338
|
};
|
|
339
|
-
const esbuildOptions = {
|
|
339
|
+
const esbuildOptions = {
|
|
340
|
+
extensions: [".js", ".mjs", ".ts"],
|
|
341
|
+
hookIgnoreNodeModules: false,
|
|
342
|
+
hookMatcher: fp.isEqual(codemodPath)
|
|
343
|
+
};
|
|
340
344
|
const { unregister } = node.register(esbuildOptions);
|
|
341
345
|
const module2 = require(codemodPath);
|
|
342
346
|
unregister();
|
|
@@ -381,8 +385,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
381
385
|
jsonRunnerFactory
|
|
382
386
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
383
387
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
384
|
-
const
|
|
385
|
-
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 = [
|
|
386
392
|
// Source files
|
|
387
393
|
"js",
|
|
388
394
|
"mjs",
|
|
@@ -391,22 +397,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
391
397
|
"jsx",
|
|
392
398
|
"tsx"
|
|
393
399
|
];
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
397
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
398
|
-
];
|
|
399
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
400
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
401
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
400
402
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
401
403
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
402
404
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
403
405
|
__proto__: null,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
406
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
407
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
408
|
+
PROJECT_CODE_EXTENSIONS,
|
|
409
|
+
PROJECT_JSON_EXTENSIONS,
|
|
409
410
|
PROJECT_PACKAGE_JSON,
|
|
411
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
412
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
410
413
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
411
414
|
STRAPI_DEPENDENCY_NAME
|
|
412
415
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -416,11 +419,13 @@ class Project {
|
|
|
416
419
|
files;
|
|
417
420
|
packageJSONPath;
|
|
418
421
|
packageJSON;
|
|
419
|
-
|
|
422
|
+
paths;
|
|
423
|
+
constructor(cwd, config) {
|
|
420
424
|
if (!fse__default.default.pathExistsSync(cwd)) {
|
|
421
425
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
422
426
|
}
|
|
423
427
|
this.cwd = cwd;
|
|
428
|
+
this.paths = config.paths;
|
|
424
429
|
this.refresh();
|
|
425
430
|
}
|
|
426
431
|
getFilesByExtensions(extensions) {
|
|
@@ -448,12 +453,8 @@ class Project {
|
|
|
448
453
|
return reports2;
|
|
449
454
|
}
|
|
450
455
|
createProjectCodemodsRunners(dry = false) {
|
|
451
|
-
const jsonExtensions =
|
|
452
|
-
|
|
453
|
-
);
|
|
454
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
455
|
-
(ext) => `.${ext}`
|
|
456
|
-
);
|
|
456
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
457
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
457
458
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
458
459
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
459
460
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -461,7 +462,7 @@ class Project {
|
|
|
461
462
|
parser: "ts",
|
|
462
463
|
runInBand: true,
|
|
463
464
|
babel: true,
|
|
464
|
-
extensions:
|
|
465
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
465
466
|
// Don't output any log coming from the runner
|
|
466
467
|
print: false,
|
|
467
468
|
silent: true,
|
|
@@ -482,23 +483,30 @@ class Project {
|
|
|
482
483
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
483
484
|
}
|
|
484
485
|
refreshProjectFiles() {
|
|
485
|
-
const allowedRootPaths = formatGlobCollectionPattern(
|
|
486
|
-
PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
|
|
487
|
-
);
|
|
488
|
-
const allowedExtensions = formatGlobCollectionPattern(
|
|
489
|
-
PROJECT_DEFAULT_ALLOWED_EXTENSIONS
|
|
490
|
-
);
|
|
491
|
-
const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
|
|
492
|
-
const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
|
|
493
486
|
const scanner = fileScannerFactory(this.cwd);
|
|
494
|
-
this.files = scanner.scan(
|
|
487
|
+
this.files = scanner.scan(this.paths);
|
|
495
488
|
}
|
|
496
489
|
}
|
|
497
490
|
class AppProject extends Project {
|
|
498
491
|
strapiVersion;
|
|
499
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
|
+
}
|
|
500
508
|
constructor(cwd) {
|
|
501
|
-
super(cwd);
|
|
509
|
+
super(cwd, { paths: AppProject.paths });
|
|
502
510
|
this.refreshStrapiVersion();
|
|
503
511
|
}
|
|
504
512
|
refresh() {
|
|
@@ -553,6 +561,28 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
553
561
|
};
|
|
554
562
|
class PluginProject extends Project {
|
|
555
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
|
+
}
|
|
556
586
|
}
|
|
557
587
|
const isPlugin = (cwd) => {
|
|
558
588
|
const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -567,10 +597,7 @@ const isPlugin = (cwd) => {
|
|
|
567
597
|
};
|
|
568
598
|
const projectFactory = (cwd) => {
|
|
569
599
|
fse__default.default.accessSync(cwd);
|
|
570
|
-
|
|
571
|
-
return new PluginProject(cwd);
|
|
572
|
-
}
|
|
573
|
-
return new AppProject(cwd);
|
|
600
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
574
601
|
};
|
|
575
602
|
const isPluginProject = (project) => {
|
|
576
603
|
return project instanceof PluginProject;
|
|
@@ -623,6 +650,9 @@ const version = (version2) => {
|
|
|
623
650
|
const codemodUID = (uid) => {
|
|
624
651
|
return chalk__default.default.bold.cyan(uid);
|
|
625
652
|
};
|
|
653
|
+
const projectDetails = (project) => {
|
|
654
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
655
|
+
};
|
|
626
656
|
const projectType = (type) => chalk__default.default.cyan(type);
|
|
627
657
|
const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
|
|
628
658
|
const transform = (transformFilePath) => chalk__default.default.cyan(transformFilePath);
|
|
@@ -689,6 +719,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
689
719
|
durationMs,
|
|
690
720
|
highlight,
|
|
691
721
|
path,
|
|
722
|
+
projectDetails,
|
|
692
723
|
projectType,
|
|
693
724
|
reports,
|
|
694
725
|
transform,
|
|
@@ -1224,6 +1255,7 @@ const upgrade = async (options) => {
|
|
|
1224
1255
|
const { logger, codemodsTarget } = options;
|
|
1225
1256
|
const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
|
|
1226
1257
|
const project = projectFactory(cwd);
|
|
1258
|
+
logger.debug(projectDetails(project));
|
|
1227
1259
|
if (!isApplicationProject(project)) {
|
|
1228
1260
|
throw new Error(
|
|
1229
1261
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1278,7 +1310,7 @@ const runCodemods = async (options) => {
|
|
|
1278
1310
|
const cwd = resolvePath(options.cwd);
|
|
1279
1311
|
const project = projectFactory(cwd);
|
|
1280
1312
|
const range = findRangeFromTarget(project, options.target);
|
|
1281
|
-
logger.debug(
|
|
1313
|
+
logger.debug(projectDetails(project));
|
|
1282
1314
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1283
1315
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1284
1316
|
let report;
|
|
@@ -1299,7 +1331,7 @@ const listCodemods = async (options) => {
|
|
|
1299
1331
|
const cwd = resolvePath(options.cwd);
|
|
1300
1332
|
const project = projectFactory(cwd);
|
|
1301
1333
|
const range = findRangeFromTarget(project, target);
|
|
1302
|
-
logger.debug(
|
|
1334
|
+
logger.debug(projectDetails(project));
|
|
1303
1335
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1304
1336
|
const repo = codemodRepositoryFactory();
|
|
1305
1337
|
repo.refresh();
|