@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.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { packageManager } from "@strapi/utils";
|
|
|
6
6
|
import { cloneDeep, get, has, merge, set, omit, isEqual, groupBy, size } from "lodash/fp";
|
|
7
7
|
import fse from "fs-extra";
|
|
8
8
|
import assert from "node:assert";
|
|
9
|
-
import
|
|
9
|
+
import fastglob from "fast-glob";
|
|
10
10
|
import { run } from "jscodeshift/src/Runner";
|
|
11
11
|
import { register } from "esbuild-register/dist/node";
|
|
12
12
|
import CliTable3 from "cli-table3";
|
|
@@ -277,7 +277,9 @@ class FileScanner {
|
|
|
277
277
|
this.cwd = cwd;
|
|
278
278
|
}
|
|
279
279
|
scan(patterns) {
|
|
280
|
-
const filenames =
|
|
280
|
+
const filenames = fastglob.sync(patterns, {
|
|
281
|
+
cwd: this.cwd
|
|
282
|
+
});
|
|
281
283
|
return filenames.map((filename) => path$1.join(this.cwd, filename));
|
|
282
284
|
}
|
|
283
285
|
}
|
|
@@ -326,7 +328,11 @@ const transformJSON = async (codemodPath, paths, config) => {
|
|
|
326
328
|
timeElapsed: "",
|
|
327
329
|
stats: {}
|
|
328
330
|
};
|
|
329
|
-
const esbuildOptions = {
|
|
331
|
+
const esbuildOptions = {
|
|
332
|
+
extensions: [".js", ".mjs", ".ts"],
|
|
333
|
+
hookIgnoreNodeModules: false,
|
|
334
|
+
hookMatcher: isEqual(codemodPath)
|
|
335
|
+
};
|
|
330
336
|
const { unregister } = register(esbuildOptions);
|
|
331
337
|
const module = require(codemodPath);
|
|
332
338
|
unregister();
|
|
@@ -371,8 +377,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
371
377
|
jsonRunnerFactory
|
|
372
378
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
373
379
|
const PROJECT_PACKAGE_JSON = "package.json";
|
|
374
|
-
const
|
|
375
|
-
const
|
|
380
|
+
const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
|
|
381
|
+
const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
|
|
382
|
+
const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
|
|
383
|
+
const PROJECT_CODE_EXTENSIONS = [
|
|
376
384
|
// Source files
|
|
377
385
|
"js",
|
|
378
386
|
"mjs",
|
|
@@ -381,22 +389,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
|
|
|
381
389
|
"jsx",
|
|
382
390
|
"tsx"
|
|
383
391
|
];
|
|
384
|
-
const
|
|
385
|
-
const
|
|
386
|
-
...PROJECT_DEFAULT_CODE_EXTENSIONS,
|
|
387
|
-
...PROJECT_DEFAULT_JSON_EXTENSIONS
|
|
388
|
-
];
|
|
389
|
-
const PROJECT_DEFAULT_PATTERNS = ["package.json"];
|
|
392
|
+
const PROJECT_JSON_EXTENSIONS = ["json"];
|
|
393
|
+
const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
|
|
390
394
|
const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
|
|
391
395
|
const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
|
|
392
396
|
const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
393
397
|
__proto__: null,
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
PROJECT_DEFAULT_PATTERNS,
|
|
398
|
+
PROJECT_ALLOWED_EXTENSIONS,
|
|
399
|
+
PROJECT_APP_ALLOWED_ROOT_PATHS,
|
|
400
|
+
PROJECT_CODE_EXTENSIONS,
|
|
401
|
+
PROJECT_JSON_EXTENSIONS,
|
|
399
402
|
PROJECT_PACKAGE_JSON,
|
|
403
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
|
|
404
|
+
PROJECT_PLUGIN_ROOT_FILES,
|
|
400
405
|
SCOPED_STRAPI_PACKAGE_PREFIX,
|
|
401
406
|
STRAPI_DEPENDENCY_NAME
|
|
402
407
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
@@ -406,11 +411,13 @@ class Project {
|
|
|
406
411
|
files;
|
|
407
412
|
packageJSONPath;
|
|
408
413
|
packageJSON;
|
|
409
|
-
|
|
414
|
+
paths;
|
|
415
|
+
constructor(cwd, config) {
|
|
410
416
|
if (!fse.pathExistsSync(cwd)) {
|
|
411
417
|
throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
|
|
412
418
|
}
|
|
413
419
|
this.cwd = cwd;
|
|
420
|
+
this.paths = config.paths;
|
|
414
421
|
this.refresh();
|
|
415
422
|
}
|
|
416
423
|
getFilesByExtensions(extensions) {
|
|
@@ -438,12 +445,8 @@ class Project {
|
|
|
438
445
|
return reports2;
|
|
439
446
|
}
|
|
440
447
|
createProjectCodemodsRunners(dry = false) {
|
|
441
|
-
const jsonExtensions =
|
|
442
|
-
|
|
443
|
-
);
|
|
444
|
-
const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
|
|
445
|
-
(ext) => `.${ext}`
|
|
446
|
-
);
|
|
448
|
+
const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
|
|
449
|
+
const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
|
|
447
450
|
const jsonFiles = this.getFilesByExtensions(jsonExtensions);
|
|
448
451
|
const codeFiles = this.getFilesByExtensions(codeExtensions);
|
|
449
452
|
const codeRunner = codeRunnerFactory(codeFiles, {
|
|
@@ -451,7 +454,7 @@ class Project {
|
|
|
451
454
|
parser: "ts",
|
|
452
455
|
runInBand: true,
|
|
453
456
|
babel: true,
|
|
454
|
-
extensions:
|
|
457
|
+
extensions: PROJECT_CODE_EXTENSIONS.join(","),
|
|
455
458
|
// Don't output any log coming from the runner
|
|
456
459
|
print: false,
|
|
457
460
|
silent: true,
|
|
@@ -472,23 +475,32 @@ class Project {
|
|
|
472
475
|
this.packageJSON = JSON.parse(packageJSONBuffer.toString());
|
|
473
476
|
}
|
|
474
477
|
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
478
|
const scanner = fileScannerFactory(this.cwd);
|
|
484
|
-
this.files = scanner.scan(
|
|
479
|
+
this.files = scanner.scan(this.paths);
|
|
485
480
|
}
|
|
486
481
|
}
|
|
487
482
|
class AppProject extends Project {
|
|
488
483
|
strapiVersion;
|
|
489
484
|
type = "application";
|
|
485
|
+
/**
|
|
486
|
+
* Returns an array of allowed file paths for a Strapi application
|
|
487
|
+
*
|
|
488
|
+
* The resulting paths include app default files and the root package.json file.
|
|
489
|
+
*/
|
|
490
|
+
static get paths() {
|
|
491
|
+
const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
|
|
492
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
493
|
+
return [
|
|
494
|
+
// App default files
|
|
495
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
496
|
+
`!./**/node_modules/**/*`,
|
|
497
|
+
`!./**/dist/**/*`,
|
|
498
|
+
// Root package.json file
|
|
499
|
+
PROJECT_PACKAGE_JSON
|
|
500
|
+
];
|
|
501
|
+
}
|
|
490
502
|
constructor(cwd) {
|
|
491
|
-
super(cwd);
|
|
503
|
+
super(cwd, { paths: AppProject.paths });
|
|
492
504
|
this.refreshStrapiVersion();
|
|
493
505
|
}
|
|
494
506
|
refresh() {
|
|
@@ -543,6 +555,30 @@ const formatGlobCollectionPattern = (collection) => {
|
|
|
543
555
|
};
|
|
544
556
|
class PluginProject extends Project {
|
|
545
557
|
type = "plugin";
|
|
558
|
+
/**
|
|
559
|
+
* Returns an array of allowed file paths for a Strapi plugin
|
|
560
|
+
*
|
|
561
|
+
* The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
|
|
562
|
+
*/
|
|
563
|
+
static get paths() {
|
|
564
|
+
const allowedRootPaths = formatGlobCollectionPattern(
|
|
565
|
+
PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
|
|
566
|
+
);
|
|
567
|
+
const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
|
|
568
|
+
return [
|
|
569
|
+
// Plugin default files
|
|
570
|
+
`./${allowedRootPaths}/**/*.${allowedExtensions}`,
|
|
571
|
+
`!./**/node_modules/**/*`,
|
|
572
|
+
`!./**/dist/**/*`,
|
|
573
|
+
// Root package.json file
|
|
574
|
+
PROJECT_PACKAGE_JSON,
|
|
575
|
+
// Plugin root files
|
|
576
|
+
...PROJECT_PLUGIN_ROOT_FILES
|
|
577
|
+
];
|
|
578
|
+
}
|
|
579
|
+
constructor(cwd) {
|
|
580
|
+
super(cwd, { paths: PluginProject.paths });
|
|
581
|
+
}
|
|
546
582
|
}
|
|
547
583
|
const isPlugin = (cwd) => {
|
|
548
584
|
const packageJSONPath = path$1.join(cwd, PROJECT_PACKAGE_JSON);
|
|
@@ -557,10 +593,7 @@ const isPlugin = (cwd) => {
|
|
|
557
593
|
};
|
|
558
594
|
const projectFactory = (cwd) => {
|
|
559
595
|
fse.accessSync(cwd);
|
|
560
|
-
|
|
561
|
-
return new PluginProject(cwd);
|
|
562
|
-
}
|
|
563
|
-
return new AppProject(cwd);
|
|
596
|
+
return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
|
|
564
597
|
};
|
|
565
598
|
const isPluginProject = (project) => {
|
|
566
599
|
return project instanceof PluginProject;
|
|
@@ -613,6 +646,9 @@ const version = (version2) => {
|
|
|
613
646
|
const codemodUID = (uid) => {
|
|
614
647
|
return chalk.bold.cyan(uid);
|
|
615
648
|
};
|
|
649
|
+
const projectDetails = (project) => {
|
|
650
|
+
return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
|
|
651
|
+
};
|
|
616
652
|
const projectType = (type) => chalk.cyan(type);
|
|
617
653
|
const versionRange = (range) => chalk.italic.yellow(range.raw);
|
|
618
654
|
const transform = (transformFilePath) => chalk.cyan(transformFilePath);
|
|
@@ -679,6 +715,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
679
715
|
durationMs,
|
|
680
716
|
highlight,
|
|
681
717
|
path,
|
|
718
|
+
projectDetails,
|
|
682
719
|
projectType,
|
|
683
720
|
reports,
|
|
684
721
|
transform,
|
|
@@ -1214,6 +1251,7 @@ const upgrade = async (options) => {
|
|
|
1214
1251
|
const { logger, codemodsTarget } = options;
|
|
1215
1252
|
const cwd = path$1.resolve(options.cwd ?? process.cwd());
|
|
1216
1253
|
const project = projectFactory(cwd);
|
|
1254
|
+
logger.debug(projectDetails(project));
|
|
1217
1255
|
if (!isApplicationProject(project)) {
|
|
1218
1256
|
throw new Error(
|
|
1219
1257
|
`The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
|
|
@@ -1268,7 +1306,7 @@ const runCodemods = async (options) => {
|
|
|
1268
1306
|
const cwd = resolvePath(options.cwd);
|
|
1269
1307
|
const project = projectFactory(cwd);
|
|
1270
1308
|
const range = findRangeFromTarget(project, options.target);
|
|
1271
|
-
logger.debug(
|
|
1309
|
+
logger.debug(projectDetails(project));
|
|
1272
1310
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1273
1311
|
const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
|
|
1274
1312
|
let report;
|
|
@@ -1289,7 +1327,7 @@ const listCodemods = async (options) => {
|
|
|
1289
1327
|
const cwd = resolvePath(options.cwd);
|
|
1290
1328
|
const project = projectFactory(cwd);
|
|
1291
1329
|
const range = findRangeFromTarget(project, target);
|
|
1292
|
-
logger.debug(
|
|
1330
|
+
logger.debug(projectDetails(project));
|
|
1293
1331
|
logger.debug(`Range: set to ${versionRange(range)}`);
|
|
1294
1332
|
const repo = codemodRepositoryFactory();
|
|
1295
1333
|
repo.refresh();
|