@strapi/upgrade 5.0.0-rc.2 → 5.0.0-rc.20

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
@@ -10,7 +10,7 @@ const utils = require("@strapi/utils");
10
10
  const fp = require("lodash/fp");
11
11
  const fse = require("fs-extra");
12
12
  const assert = require("node:assert");
13
- const glob = require("glob");
13
+ const fastglob = require("fast-glob");
14
14
  const Runner = require("jscodeshift/src/Runner");
15
15
  const node = require("esbuild-register/dist/node");
16
16
  const CliTable3 = require("cli-table3");
@@ -23,6 +23,7 @@ const path__default = /* @__PURE__ */ _interopDefault(path$1);
23
23
  const simpleGit__default = /* @__PURE__ */ _interopDefault(simpleGit);
24
24
  const fse__default = /* @__PURE__ */ _interopDefault(fse);
25
25
  const assert__default = /* @__PURE__ */ _interopDefault(assert);
26
+ const fastglob__default = /* @__PURE__ */ _interopDefault(fastglob);
26
27
  const CliTable3__default = /* @__PURE__ */ _interopDefault(CliTable3);
27
28
  class Logger {
28
29
  isDebug;
@@ -339,7 +340,9 @@ class FileScanner {
339
340
  this.cwd = cwd;
340
341
  }
341
342
  scan(patterns) {
342
- const filenames = glob.glob.sync(patterns, { cwd: this.cwd });
343
+ const filenames = fastglob__default.default.sync(patterns, {
344
+ cwd: this.cwd
345
+ });
343
346
  return filenames.map((filename) => path__default.default.join(this.cwd, filename));
344
347
  }
345
348
  }
@@ -425,8 +428,10 @@ const jsonRunnerFactory = (paths, configuration) => {
425
428
  return new JSONRunner(paths, configuration);
426
429
  };
427
430
  const PROJECT_PACKAGE_JSON = "package.json";
428
- const PROJECT_DEFAULT_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
429
- const PROJECT_DEFAULT_CODE_EXTENSIONS = [
431
+ const PROJECT_APP_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
432
+ const PROJECT_PLUGIN_ALLOWED_ROOT_PATHS = ["admin", "server"];
433
+ const PROJECT_PLUGIN_ROOT_FILES = ["strapi-admin.js", "strapi-server.js"];
434
+ const PROJECT_CODE_EXTENSIONS = [
430
435
  // Source files
431
436
  "js",
432
437
  "mjs",
@@ -435,12 +440,8 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
435
440
  "jsx",
436
441
  "tsx"
437
442
  ];
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"];
443
+ const PROJECT_JSON_EXTENSIONS = ["json"];
444
+ const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
444
445
  const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
445
446
  const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
446
447
  class Project {
@@ -449,11 +450,13 @@ class Project {
449
450
  files;
450
451
  packageJSONPath;
451
452
  packageJSON;
452
- constructor(cwd) {
453
+ paths;
454
+ constructor(cwd, config) {
453
455
  if (!fse__default.default.pathExistsSync(cwd)) {
454
456
  throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
455
457
  }
456
458
  this.cwd = cwd;
459
+ this.paths = config.paths;
457
460
  this.refresh();
458
461
  }
459
462
  getFilesByExtensions(extensions) {
@@ -481,12 +484,8 @@ class Project {
481
484
  return reports2;
482
485
  }
483
486
  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
- );
487
+ const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
488
+ const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
490
489
  const jsonFiles = this.getFilesByExtensions(jsonExtensions);
491
490
  const codeFiles = this.getFilesByExtensions(codeExtensions);
492
491
  const codeRunner = codeRunnerFactory(codeFiles, {
@@ -494,7 +493,7 @@ class Project {
494
493
  parser: "ts",
495
494
  runInBand: true,
496
495
  babel: true,
497
- extensions: PROJECT_DEFAULT_CODE_EXTENSIONS.join(","),
496
+ extensions: PROJECT_CODE_EXTENSIONS.join(","),
498
497
  // Don't output any log coming from the runner
499
498
  print: false,
500
499
  silent: true,
@@ -515,23 +514,32 @@ class Project {
515
514
  this.packageJSON = JSON.parse(packageJSONBuffer.toString());
516
515
  }
517
516
  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
517
  const scanner = fileScannerFactory(this.cwd);
527
- this.files = scanner.scan(patterns);
518
+ this.files = scanner.scan(this.paths);
528
519
  }
529
520
  }
530
521
  class AppProject extends Project {
531
522
  strapiVersion;
532
523
  type = "application";
524
+ /**
525
+ * Returns an array of allowed file paths for a Strapi application
526
+ *
527
+ * The resulting paths include app default files and the root package.json file.
528
+ */
529
+ static get paths() {
530
+ const allowedRootPaths = formatGlobCollectionPattern(PROJECT_APP_ALLOWED_ROOT_PATHS);
531
+ const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
532
+ return [
533
+ // App default files
534
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
535
+ `!./**/node_modules/**/*`,
536
+ `!./**/dist/**/*`,
537
+ // Root package.json file
538
+ PROJECT_PACKAGE_JSON
539
+ ];
540
+ }
533
541
  constructor(cwd) {
534
- super(cwd);
542
+ super(cwd, { paths: AppProject.paths });
535
543
  this.refreshStrapiVersion();
536
544
  }
537
545
  refresh() {
@@ -586,6 +594,30 @@ const formatGlobCollectionPattern = (collection) => {
586
594
  };
587
595
  class PluginProject extends Project {
588
596
  type = "plugin";
597
+ /**
598
+ * Returns an array of allowed file paths for a Strapi plugin
599
+ *
600
+ * The resulting paths include plugin default files, the root package.json file, and plugin-specific files.
601
+ */
602
+ static get paths() {
603
+ const allowedRootPaths = formatGlobCollectionPattern(
604
+ PROJECT_PLUGIN_ALLOWED_ROOT_PATHS
605
+ );
606
+ const allowedExtensions = formatGlobCollectionPattern(PROJECT_ALLOWED_EXTENSIONS);
607
+ return [
608
+ // Plugin default files
609
+ `./${allowedRootPaths}/**/*.${allowedExtensions}`,
610
+ `!./**/node_modules/**/*`,
611
+ `!./**/dist/**/*`,
612
+ // Root package.json file
613
+ PROJECT_PACKAGE_JSON,
614
+ // Plugin root files
615
+ ...PROJECT_PLUGIN_ROOT_FILES
616
+ ];
617
+ }
618
+ constructor(cwd) {
619
+ super(cwd, { paths: PluginProject.paths });
620
+ }
589
621
  }
590
622
  const isPlugin = (cwd) => {
591
623
  const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
@@ -600,10 +632,7 @@ const isPlugin = (cwd) => {
600
632
  };
601
633
  const projectFactory = (cwd) => {
602
634
  fse__default.default.accessSync(cwd);
603
- if (isPlugin(cwd)) {
604
- return new PluginProject(cwd);
605
- }
606
- return new AppProject(cwd);
635
+ return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
607
636
  };
608
637
  const isApplicationProject = (project) => {
609
638
  return project instanceof AppProject;
@@ -629,6 +658,9 @@ const version$1 = (version2) => {
629
658
  const codemodUID = (uid) => {
630
659
  return chalk__default.default.bold.cyan(uid);
631
660
  };
661
+ const projectDetails = (project) => {
662
+ return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
663
+ };
632
664
  const projectType = (type) => chalk__default.default.cyan(type);
633
665
  const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
634
666
  const highlight = (arg) => chalk__default.default.bold.underline(arg);
@@ -1184,6 +1216,7 @@ const upgrade$1 = async (options) => {
1184
1216
  const { logger, codemodsTarget } = options;
1185
1217
  const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
1186
1218
  const project = projectFactory(cwd);
1219
+ logger.debug(projectDetails(project));
1187
1220
  if (!isApplicationProject(project)) {
1188
1221
  throw new Error(
1189
1222
  `The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
@@ -1238,7 +1271,7 @@ const runCodemods$1 = async (options) => {
1238
1271
  const cwd = resolvePath(options.cwd);
1239
1272
  const project = projectFactory(cwd);
1240
1273
  const range = findRangeFromTarget(project, options.target);
1241
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1274
+ logger.debug(projectDetails(project));
1242
1275
  logger.debug(`Range: set to ${versionRange(range)}`);
1243
1276
  const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
1244
1277
  let report;
@@ -1259,7 +1292,7 @@ const listCodemods$1 = async (options) => {
1259
1292
  const cwd = resolvePath(options.cwd);
1260
1293
  const project = projectFactory(cwd);
1261
1294
  const range = findRangeFromTarget(project, target);
1262
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1295
+ logger.debug(projectDetails(project));
1263
1296
  logger.debug(`Range: set to ${versionRange(range)}`);
1264
1297
  const repo = codemodRepositoryFactory();
1265
1298
  repo.refresh();
@@ -1444,7 +1477,7 @@ When executed on a Strapi plugin project, it shows every codemods.
1444
1477
  return listCodemods(options);
1445
1478
  });
1446
1479
  };
1447
- const version = "5.0.0-rc.2";
1480
+ const version = "5.0.0-rc.20";
1448
1481
  register$1(commander.program);
1449
1482
  register(commander.program);
1450
1483
  commander.program.usage("<command> [options]").on("command:*", ([invalidCmd]) => {