@strapi/upgrade 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.f8a68bc03b751aa0a66c4dcfaf83553c9b6adf2b
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 +73 -36
- package/dist/cli.js.map +1 -1
- package/dist/index.js +79 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -40
- 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/modules/runner/json/transform.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.code.ts +192 -0
- package/resources/utils/change-import.ts +118 -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
|
}
|
|
@@ -336,7 +339,11 @@ const transformJSON = async (codemodPath, paths, config) => {
|
|
|
336
339
|
timeElapsed: "",
|
|
337
340
|
stats: {}
|
|
338
341
|
};
|
|
339
|
-
const esbuildOptions = {
|
|
342
|
+
const esbuildOptions = {
|
|
343
|
+
extensions: [".js", ".mjs", ".ts"],
|
|
344
|
+
hookIgnoreNodeModules: false,
|
|
345
|
+
hookMatcher: fp.isEqual(codemodPath)
|
|
346
|
+
};
|
|
340
347
|
const { unregister } = node.register(esbuildOptions);
|
|
341
348
|
const module2 = require(codemodPath);
|
|
342
349
|
unregister();
|
|
@@ -381,8 +388,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
381
388
|
jsonRunnerFactory
|
|
382
389
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
383
390
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
384
|
-
const
|
|
385
|
-
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 = [
|
|
386
395
|
// Source files
|
|
387
396
|
"js",
|
|
388
397
|
"mjs",
|
|
@@ -391,22 +400,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
391
400
|
"jsx",
|
|
392
401
|
"tsx"
|
|
393
402
|
];
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
397
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
398
|
-
];
|
|
399
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
403
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
404
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
400
405
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
401
406
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
402
407
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
403
408
|
__proto__: null,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
409
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
410
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
411
|
+
PROJECT_CODE_EXTENSIONS,
|
|
412
|
+
PROJECT_JSON_EXTENSIONS,
|
|
409
413
|
PROJECT_PACKAGE_JSON,
|
|
414
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
415
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
410
416
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
411
417
|
STRAPI_DEPENDENCY_NAME
|
|
412
418
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -416,11 +422,13 @@ class Project {
|
|
|
416
422
|
files;
|
|
417
423
|
packageJSONPath;
|
|
418
424
|
packageJSON;
|
|
419
|
-
|
|
425
|
+
paths;
|
|
426
|
+
constructor(cwd, config) {
|
|
420
427
|
if (!fse__default.default.pathExistsSync(cwd)) {
|
|
421
428
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
422
429
|
}
|
|
423
430
|
this.cwd = cwd;
|
|
431
|
+
this.paths = config.paths;
|
|
424
432
|
this.refresh();
|
|
425
433
|
}
|
|
426
434
|
getFilesByExtensions(extensions) {
|
|
@@ -448,12 +456,8 @@ class Project {
|
|
|
448
456
|
return reports2;
|
|
449
457
|
}
|
|
450
458
|
createProjectCodemodsRunners(dry = false) {
|
|
451
|
-
const jsonExtensions =
|
|
452
|
-
|
|
453
|
-
);
|
|
454
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
455
|
-
(ext) => `.${ext}`
|
|
456
|
-
);
|
|
459
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
460
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
457
461
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
458
462
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
459
463
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -461,7 +465,7 @@ class Project {
|
|
|
461
465
|
parser: "ts",
|
|
462
466
|
runInBand: true,
|
|
463
467
|
babel: true,
|
|
464
|
-
extensions:
|
|
468
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
465
469
|
// Don't output any log coming from the runner
|
|
466
470
|
print: false,
|
|
467
471
|
silent: true,
|
|
@@ -482,23 +486,32 @@ class Project {
|
|
|
482
486
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
483
487
|
}
|
|
484
488
|
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
489
|
const scanner = fileScannerFactory(this.cwd);
|
|
494
|
-
this.files = scanner.scan(
|
|
490
|
+
this.files = scanner.scan(this.paths);
|
|
495
491
|
}
|
|
496
492
|
}
|
|
497
493
|
class AppProject extends Project {
|
|
498
494
|
strapiVersion;
|
|
499
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
|
+
}
|
|
500
513
|
constructor(cwd) {
|
|
501
|
-
super(cwd);
|
|
514
|
+
super(cwd, { paths: AppProject.paths });
|
|
502
515
|
this.refreshStrapiVersion();
|
|
503
516
|
}
|
|
504
517
|
refresh() {
|
|
@@ -553,6 +566,30 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
553
566
|
};
|
|
554
567
|
class PluginProject extends Project {
|
|
555
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
|
+
}
|
|
556
593
|
}
|
|
557
594
|
const isPlugin = (cwd) => {
|
|
558
595
|
const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -567,10 +604,7 @@ const isPlugin = (cwd) => {
|
|
|
567
604
|
};
|
|
568
605
|
const projectFactory = (cwd) => {
|
|
569
606
|
fse__default.default.accessSync(cwd);
|
|
570
|
-
|
|
571
|
-
return new PluginProject(cwd);
|
|
572
|
-
}
|
|
573
|
-
return new AppProject(cwd);
|
|
607
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
574
608
|
};
|
|
575
609
|
const isPluginProject = (project) => {
|
|
576
610
|
return project instanceof PluginProject;
|
|
@@ -623,6 +657,9 @@ const version = (version2) => {
|
|
|
623
657
|
const codemodUID = (uid) => {
|
|
624
658
|
return chalk__default.default.bold.cyan(uid);
|
|
625
659
|
};
|
|
660
|
+
const projectDetails = (project) => {
|
|
661
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
662
|
+
};
|
|
626
663
|
const projectType = (type) => chalk__default.default.cyan(type);
|
|
627
664
|
const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
|
|
628
665
|
const transform = (transformFilePath) => chalk__default.default.cyan(transformFilePath);
|
|
@@ -689,6 +726,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
689
726
|
durationMs,
|
|
690
727
|
highlight,
|
|
691
728
|
path,
|
|
729
|
+
projectDetails,
|
|
692
730
|
projectType,
|
|
693
731
|
reports,
|
|
694
732
|
transform,
|
|
@@ -1224,6 +1262,7 @@ const upgrade = async (options) => {
|
|
|
1224
1262
|
const { logger, codemodsTarget } = options;
|
|
1225
1263
|
const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
|
|
1226
1264
|
const project = projectFactory(cwd);
|
|
1265
|
+
logger.debug(projectDetails(project));
|
|
1227
1266
|
if (!isApplicationProject(project)) {
|
|
1228
1267
|
throw new Error(
|
|
1229
1268
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1278,7 +1317,7 @@ const runCodemods = async (options) => {
|
|
|
1278
1317
|
const cwd = resolvePath(options.cwd);
|
|
1279
1318
|
const project = projectFactory(cwd);
|
|
1280
1319
|
const range = findRangeFromTarget(project, options.target);
|
|
1281
|
-
logger.debug(
|
|
1320
|
+
logger.debug(projectDetails(project));
|
|
1282
1321
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1283
1322
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1284
1323
|
let report;
|
|
@@ -1299,7 +1338,7 @@ const listCodemods = async (options) => {
|
|
|
1299
1338
|
const cwd = resolvePath(options.cwd);
|
|
1300
1339
|
const project = projectFactory(cwd);
|
|
1301
1340
|
const range = findRangeFromTarget(project, target);
|
|
1302
|
-
logger.debug(
|
|
1341
|
+
logger.debug(projectDetails(project));
|
|
1303
1342
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1304
1343
|
const repo = codemodRepositoryFactory();
|
|
1305
1344
|
repo.refresh();
|