@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/index.mjs CHANGED
@@ -375,8 +375,10 @@ const index$b = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
375
375
  jsonRunnerFactory
376
376
  }, Symbol.toStringTag, { value: "Module" }));
377
377
  const PROJECT_PACKAGE_JSON = "package.json";
378
- const PROJECT_DEFAULT_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
379
- const PROJECT_DEFAULT_CODE_EXTENSIONS = [
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 = [
380
382
  // Source files
381
383
  "js",
382
384
  "mjs",
@@ -385,22 +387,19 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
385
387
  "jsx",
386
388
  "tsx"
387
389
  ];
388
- const PROJECT_DEFAULT_JSON_EXTENSIONS = ["json"];
389
- const PROJECT_DEFAULT_ALLOWED_EXTENSIONS = [
390
- ...PROJECT_DEFAULT_CODE_EXTENSIONS,
391
- ...PROJECT_DEFAULT_JSON_EXTENSIONS
392
- ];
393
- const PROJECT_DEFAULT_PATTERNS = ["package.json"];
390
+ const PROJECT_JSON_EXTENSIONS = ["json"];
391
+ const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
394
392
  const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
395
393
  const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
396
394
  const constants$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
397
395
  __proto__: null,
398
- PROJECT_DEFAULT_ALLOWED_EXTENSIONS,
399
- PROJECT_DEFAULT_ALLOWED_ROOT_PATHS,
400
- PROJECT_DEFAULT_CODE_EXTENSIONS,
401
- PROJECT_DEFAULT_JSON_EXTENSIONS,
402
- PROJECT_DEFAULT_PATTERNS,
396
+ PROJECT_ALLOWED_EXTENSIONS,
397
+ PROJECT_APP_ALLOWED_ROOT_PATHS,
398
+ PROJECT_CODE_EXTENSIONS,
399
+ PROJECT_JSON_EXTENSIONS,
403
400
  PROJECT_PACKAGE_JSON,
401
+ PROJECT_PLUGIN_ALLOWED_ROOT_PATHS,
402
+ PROJECT_PLUGIN_ROOT_FILES,
404
403
  SCOPED_STRAPI_PACKAGE_PREFIX,
405
404
  STRAPI_DEPENDENCY_NAME
406
405
  }, Symbol.toStringTag, { value: "Module" }));
@@ -410,11 +409,13 @@ class Project {
410
409
  files;
411
410
  packageJSONPath;
412
411
  packageJSON;
413
- constructor(cwd) {
412
+ paths;
413
+ constructor(cwd, config) {
414
414
  if (!fse.pathExistsSync(cwd)) {
415
415
  throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
416
416
  }
417
417
  this.cwd = cwd;
418
+ this.paths = config.paths;
418
419
  this.refresh();
419
420
  }
420
421
  getFilesByExtensions(extensions) {
@@ -442,12 +443,8 @@ class Project {
442
443
  return reports2;
443
444
  }
444
445
  createProjectCodemodsRunners(dry = false) {
445
- const jsonExtensions = PROJECT_DEFAULT_JSON_EXTENSIONS.map(
446
- (ext) => `.${ext}`
447
- );
448
- const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
449
- (ext) => `.${ext}`
450
- );
446
+ const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
447
+ const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
451
448
  const jsonFiles = this.getFilesByExtensions(jsonExtensions);
452
449
  const codeFiles = this.getFilesByExtensions(codeExtensions);
453
450
  const codeRunner = codeRunnerFactory(codeFiles, {
@@ -455,7 +452,7 @@ class Project {
455
452
  parser: "ts",
456
453
  runInBand: true,
457
454
  babel: true,
458
- extensions: PROJECT_DEFAULT_CODE_EXTENSIONS.join(","),
455
+ extensions: PROJECT_CODE_EXTENSIONS.join(","),
459
456
  // Don't output any log coming from the runner
460
457
  print: false,
461
458
  silent: true,
@@ -476,23 +473,30 @@ class Project {
476
473
  this.packageJSON = JSON.parse(packageJSONBuffer.toString());
477
474
  }
478
475
  refreshProjectFiles() {
479
- const allowedRootPaths = formatGlobCollectionPattern(
480
- PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
481
- );
482
- const allowedExtensions = formatGlobCollectionPattern(
483
- PROJECT_DEFAULT_ALLOWED_EXTENSIONS
484
- );
485
- const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
486
- const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
487
476
  const scanner = fileScannerFactory(this.cwd);
488
- this.files = scanner.scan(patterns);
477
+ this.files = scanner.scan(this.paths);
489
478
  }
490
479
  }
491
480
  class AppProject extends Project {
492
481
  strapiVersion;
493
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
+ }
494
498
  constructor(cwd) {
495
- super(cwd);
499
+ super(cwd, { paths: AppProject.paths });
496
500
  this.refreshStrapiVersion();
497
501
  }
498
502
  refresh() {
@@ -547,6 +551,28 @@ const formatGlobCollectionPattern = (collection) => {
547
551
  };
548
552
  class PluginProject extends Project {
549
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
+ }
550
576
  }
551
577
  const isPlugin = (cwd) => {
552
578
  const packageJSONPath = path$1.join(cwd, PROJECT_PACKAGE_JSON);
@@ -561,10 +587,7 @@ const isPlugin = (cwd) => {
561
587
  };
562
588
  const projectFactory = (cwd) => {
563
589
  fse.accessSync(cwd);
564
- if (isPlugin(cwd)) {
565
- return new PluginProject(cwd);
566
- }
567
- return new AppProject(cwd);
590
+ return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
568
591
  };
569
592
  const isPluginProject = (project) => {
570
593
  return project instanceof PluginProject;
@@ -617,6 +640,9 @@ const version = (version2) => {
617
640
  const codemodUID = (uid) => {
618
641
  return chalk.bold.cyan(uid);
619
642
  };
643
+ const projectDetails = (project) => {
644
+ return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
645
+ };
620
646
  const projectType = (type) => chalk.cyan(type);
621
647
  const versionRange = (range) => chalk.italic.yellow(range.raw);
622
648
  const transform = (transformFilePath) => chalk.cyan(transformFilePath);
@@ -683,6 +709,7 @@ const index$8 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
683
709
  durationMs,
684
710
  highlight,
685
711
  path,
712
+ projectDetails,
686
713
  projectType,
687
714
  reports,
688
715
  transform,
@@ -1218,6 +1245,7 @@ const upgrade = async (options) => {
1218
1245
  const { logger, codemodsTarget } = options;
1219
1246
  const cwd = path$1.resolve(options.cwd ?? process.cwd());
1220
1247
  const project = projectFactory(cwd);
1248
+ logger.debug(projectDetails(project));
1221
1249
  if (!isApplicationProject(project)) {
1222
1250
  throw new Error(
1223
1251
  `The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
@@ -1272,7 +1300,7 @@ const runCodemods = async (options) => {
1272
1300
  const cwd = resolvePath(options.cwd);
1273
1301
  const project = projectFactory(cwd);
1274
1302
  const range = findRangeFromTarget(project, options.target);
1275
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1303
+ logger.debug(projectDetails(project));
1276
1304
  logger.debug(`Range: set to ${versionRange(range)}`);
1277
1305
  const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
1278
1306
  let report;
@@ -1293,7 +1321,7 @@ const listCodemods = async (options) => {
1293
1321
  const cwd = resolvePath(options.cwd);
1294
1322
  const project = projectFactory(cwd);
1295
1323
  const range = findRangeFromTarget(project, target);
1296
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1324
+ logger.debug(projectDetails(project));
1297
1325
  logger.debug(`Range: set to ${versionRange(range)}`);
1298
1326
  const repo = codemodRepositoryFactory();
1299
1327
  repo.refresh();