@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 CHANGED
@@ -425,8 +425,10 @@ const jsonRunnerFactory = (paths, configuration) => {
425
425
  return new JSONRunner(paths, configuration);
426
426
  };
427
427
  const PROJECT_PACKAGE_JSON = "package.json";
428
- const PROJECT_DEFAULT_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
429
- const PROJECT_DEFAULT_CODE_EXTENSIONS = [
428
+ const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
429
+ const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
430
+ const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
431
+ const PROJECT_CODE_EXTENSIONS = [
430
432
  // Source files
431
433
  "js",
432
434
  "mjs",
@@ -435,12 +437,8 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
435
437
  "jsx",
436
438
  "tsx"
437
439
  ];
438
- const PROJECT_DEFAULT_JSON_EXTENSIONS = ["json"];
439
- const PROJECT_DEFAULT_ALLOWED_EXTENSIONS = [
440
- ...PROJECT_DEFAULT_CODE_EXTENSIONS,
441
- ...PROJECT_DEFAULT_JSON_EXTENSIONS
442
- ];
443
- const PROJECT_DEFAULT_PATTERNS = ["package.json"];
440
+ const PROJECT_JSON_EXTENSIONS = ["json"];
441
+ const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
444
442
  const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
445
443
  const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
446
444
  class Project {
@@ -449,11 +447,13 @@ class Project {
449
447
  files;
450
448
  packageJSONPath;
451
449
  packageJSON;
452
- constructor(cwd) {
450
+ paths;
451
+ constructor(cwd, config) {
453
452
  if (!fse__default.default.pathExistsSync(cwd)) {
454
453
  throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
455
454
  }
456
455
  this.cwd = cwd;
456
+ this.paths = config.paths;
457
457
  this.refresh();
458
458
  }
459
459
  getFilesByExtensions(extensions) {
@@ -481,12 +481,8 @@ class Project {
481
481
  return reports2;
482
482
  }
483
483
  createProjectCodemodsRunners(dry = false) {
484
- const jsonExtensions = PROJECT_DEFAULT_JSON_EXTENSIONS.map(
485
- (ext) => `.${ext}`
486
- );
487
- const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
488
- (ext) => `.${ext}`
489
- );
484
+ const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
485
+ const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
490
486
  const jsonFiles = this.getFilesByExtensions(jsonExtensions);
491
487
  const codeFiles = this.getFilesByExtensions(codeExtensions);
492
488
  const codeRunner = codeRunnerFactory(codeFiles, {
@@ -494,7 +490,7 @@ class Project {
494
490
  parser: "ts",
495
491
  runInBand: true,
496
492
  babel: true,
497
- extensions: PROJECT_DEFAULT_CODE_EXTENSIONS.join(","),
493
+ extensions: PROJECT_CODE_EXTENSIONS.join(","),
498
494
  // Don't output any log coming from the runner
499
495
  print: false,
500
496
  silent: true,
@@ -515,23 +511,30 @@ class Project {
515
511
  this.packageJSON = JSON.parse(packageJSONBuffer.toString());
516
512
  }
517
513
  refreshProjectFiles() {
518
- const allowedRootPaths = formatGlobCollectionPattern(
519
- PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
520
- );
521
- const allowedExtensions = formatGlobCollectionPattern(
522
- PROJECT_DEFAULT_ALLOWED_EXTENSIONS
523
- );
524
- const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
525
- const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
526
514
  const scanner = fileScannerFactory(this.cwd);
527
- this.files = scanner.scan(patterns);
515
+ this.files = scanner.scan(this.paths);
528
516
  }
529
517
  }
530
518
  class AppProject extends Project {
531
519
  strapiVersion;
532
520
  type = "application";
521
+ /**
522
+ * Returns an array of allowed file paths for a Strapi application
523
+ *
524
+ * The resulting paths include app default files and the root package.json file.
525
+ */
526
+ static get paths() {
527
+ const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
528
+ const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
529
+ return [
530
+ // App default files
531
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
532
+ // Root package.json file
533
+ PROJECT_PACKAGE_JSON
534
+ ];
535
+ }
533
536
  constructor(cwd) {
534
- super(cwd);
537
+ super(cwd, { paths: AppProject.paths });
535
538
  this.refreshStrapiVersion();
536
539
  }
537
540
  refresh() {
@@ -586,6 +589,28 @@ const formatGlobCollectionPattern = (collection) => {
586
589
  };
587
590
  class PluginProject extends Project {
588
591
  type = "plugin";
592
+ /**
593
+ * Returns an array of allowed file paths for a Strapi plugin
594
+ *
595
+ * The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
596
+ */
597
+ static get paths() {
598
+ const allowedRootPaths = formatGlobCollectionPattern(
599
+ PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
600
+ );
601
+ const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
602
+ return [
603
+ // Plugin default files
604
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
605
+ // Root package.json file
606
+ PROJECT_PACKAGE_JSON,
607
+ // Plugin root files
608
+ ...PROJECT_PLUGIN_ROOT_FILES
609
+ ];
610
+ }
611
+ constructor(cwd) {
612
+ super(cwd, { paths: PluginProject.paths });
613
+ }
589
614
  }
590
615
  const isPlugin = (cwd) => {
591
616
  const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
@@ -600,10 +625,7 @@ const isPlugin = (cwd) => {
600
625
  };
601
626
  const projectFactory = (cwd) => {
602
627
  fse__default.default.accessSync(cwd);
603
- if (isPlugin(cwd)) {
604
- return new PluginProject(cwd);
605
- }
606
- return new AppProject(cwd);
628
+ return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
607
629
  };
608
630
  const isApplicationProject = (project) => {
609
631
  return project instanceof AppProject;
@@ -629,6 +651,9 @@ const version$1 = (version2) => {
629
651
  const codemodUID = (uid) => {
630
652
  return chalk__default.default.bold.cyan(uid);
631
653
  };
654
+ const projectDetails = (project) => {
655
+ return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
656
+ };
632
657
  const projectType = (type) => chalk__default.default.cyan(type);
633
658
  const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
634
659
  const highlight = (arg) => chalk__default.default.bold.underline(arg);
@@ -1184,6 +1209,7 @@ const upgrade$1 = async (options) => {
1184
1209
  const { logger, codemodsTarget } = options;
1185
1210
  const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
1186
1211
  const project = projectFactory(cwd);
1212
+ logger.debug(projectDetails(project));
1187
1213
  if (!isApplicationProject(project)) {
1188
1214
  throw new Error(
1189
1215
  `The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
@@ -1238,7 +1264,7 @@ const runCodemods$1 = async (options) => {
1238
1264
  const cwd = resolvePath(options.cwd);
1239
1265
  const project = projectFactory(cwd);
1240
1266
  const range = findRangeFromTarget(project, options.target);
1241
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1267
+ logger.debug(projectDetails(project));
1242
1268
  logger.debug(`Range: set to ${versionRange(range)}`);
1243
1269
  const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
1244
1270
  let report;
@@ -1259,7 +1285,7 @@ const listCodemods$1 = async (options) => {
1259
1285
  const cwd = resolvePath(options.cwd);
1260
1286
  const project = projectFactory(cwd);
1261
1287
  const range = findRangeFromTarget(project, target);
1262
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1288
+ logger.debug(projectDetails(project));
1263
1289
  logger.debug(`Range: set to ${versionRange(range)}`);
1264
1290
  const repo = codemodRepositoryFactory();
1265
1291
  repo.refresh();
@@ -1444,7 +1470,7 @@ When executed on a Strapi plugin project, it shows every codemods.
1444
1470
  return listCodemods(options);
1445
1471
  });
1446
1472
  };
1447
- const version = "5.0.0-rc.10";
1473
+ const version = "5.0.0-rc.12";
1448
1474
  register$1(commander.program);
1449
1475
  register(commander.program);
1450
1476
  commander.program.usage("<command> [options]").on("command:*", ([invalidCmd]) => {