@strapi/upgrade 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.f9cac24ba3b2f6acb12d0fb5669106e5a134174e

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 CHANGED
@@ -2,9 +2,23 @@ Copyright (c) 2015-present Strapi Solutions SAS
2
2
 
3
3
  Portions of the Strapi software are licensed as follows:
4
4
 
5
- - All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined in "ee/LICENSE".
5
+ * All software that resides under an "ee/" directory (the “EE Software”), if that directory exists, is licensed under the license defined below.
6
6
 
7
- - All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
7
+ Enterprise License
8
+
9
+ If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at
10
+ https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you
11
+ represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have
12
+ agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software.
13
+ Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software.
14
+
15
+ BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT.
16
+ IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU
17
+ HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF
18
+ THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS;
19
+ IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS.
20
+
21
+ * All software outside of the above-mentioned directories or restrictions above is available under the "MIT Expat" license as set forth below.
8
22
 
9
23
  MIT Expat License
10
24
 
@@ -18,5 +32,6 @@ furnished to do so, subject to the following conditions:
18
32
  The above copyright notice and this permission notice shall be included in all
19
33
  copies or substantial portions of the Software.
20
34
 
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -39,7 +39,7 @@ Data migrations are not handled by the upgrade tool.
39
39
 
40
40
  For Strapi v4, no data migrations will be allowed and no support is planned (except in extenuating circumstances eg, a critical security issue somehow relating to the database shape)
41
41
 
42
- For Strapi v5, automated data migrations can be added in the `packages/core/database` package of the `v5/main` branch of this repo.
42
+ For Strapi v5, automated data migrations can be added in the `packages/core/database` package of the `develop` branch of this repo.
43
43
 
44
44
  ## Usage
45
45
 
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
  }
@@ -380,7 +383,11 @@ const transformJSON = async (codemodPath, paths, config) => {
380
383
  timeElapsed: "",
381
384
  stats: {}
382
385
  };
383
- const esbuildOptions = { extensions: [".js", ".mjs", ".ts"] };
386
+ const esbuildOptions = {
387
+ extensions: [".js", ".mjs", ".ts"],
388
+ hookIgnoreNodeModules: false,
389
+ hookMatcher: fp.isEqual(codemodPath)
390
+ };
384
391
  const { unregister } = node.register(esbuildOptions);
385
392
  const module = require(codemodPath);
386
393
  unregister();
@@ -421,8 +428,10 @@ const jsonRunnerFactory = (paths, configuration) => {
421
428
  return new JSONRunner(paths, configuration);
422
429
  };
423
430
  const PROJECT_PACKAGE_JSON = "package.json";
424
- const PROJECT_DEFAULT_ALLOWED_ROOT_PATHS = ["src", "config", "public"];
425
- 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 = [
426
435
  // Source files
427
436
  "js",
428
437
  "mjs",
@@ -431,12 +440,8 @@ const PROJECT_DEFAULT_CODE_EXTENSIONS = [
431
440
  "jsx",
432
441
  "tsx"
433
442
  ];
434
- const PROJECT_DEFAULT_JSON_EXTENSIONS = ["json"];
435
- const PROJECT_DEFAULT_ALLOWED_EXTENSIONS = [
436
- ...PROJECT_DEFAULT_CODE_EXTENSIONS,
437
- ...PROJECT_DEFAULT_JSON_EXTENSIONS
438
- ];
439
- const PROJECT_DEFAULT_PATTERNS = ["package.json"];
443
+ const PROJECT_JSON_EXTENSIONS = ["json"];
444
+ const PROJECT_ALLOWED_EXTENSIONS = [...PROJECT_CODE_EXTENSIONS, ...PROJECT_JSON_EXTENSIONS];
440
445
  const SCOPED_STRAPI_PACKAGE_PREFIX = "@strapi/";
441
446
  const STRAPI_DEPENDENCY_NAME = `${SCOPED_STRAPI_PACKAGE_PREFIX}strapi`;
442
447
  class Project {
@@ -445,11 +450,13 @@ class Project {
445
450
  files;
446
451
  packageJSONPath;
447
452
  packageJSON;
448
- constructor(cwd) {
453
+ paths;
454
+ constructor(cwd, config) {
449
455
  if (!fse__default.default.pathExistsSync(cwd)) {
450
456
  throw new Error(`ENOENT: no such file or directory, access '${cwd}'`);
451
457
  }
452
458
  this.cwd = cwd;
459
+ this.paths = config.paths;
453
460
  this.refresh();
454
461
  }
455
462
  getFilesByExtensions(extensions) {
@@ -477,12 +484,8 @@ class Project {
477
484
  return reports2;
478
485
  }
479
486
  createProjectCodemodsRunners(dry = false) {
480
- const jsonExtensions = PROJECT_DEFAULT_JSON_EXTENSIONS.map(
481
- (ext) => `.${ext}`
482
- );
483
- const codeExtensions = PROJECT_DEFAULT_CODE_EXTENSIONS.map(
484
- (ext) => `.${ext}`
485
- );
487
+ const jsonExtensions = PROJECT_JSON_EXTENSIONS.map((ext) => `.${ext}`);
488
+ const codeExtensions = PROJECT_CODE_EXTENSIONS.map((ext) => `.${ext}`);
486
489
  const jsonFiles = this.getFilesByExtensions(jsonExtensions);
487
490
  const codeFiles = this.getFilesByExtensions(codeExtensions);
488
491
  const codeRunner = codeRunnerFactory(codeFiles, {
@@ -490,7 +493,7 @@ class Project {
490
493
  parser: "ts",
491
494
  runInBand: true,
492
495
  babel: true,
493
- extensions: PROJECT_DEFAULT_CODE_EXTENSIONS.join(","),
496
+ extensions: PROJECT_CODE_EXTENSIONS.join(","),
494
497
  // Don't output any log coming from the runner
495
498
  print: false,
496
499
  silent: true,
@@ -511,23 +514,32 @@ class Project {
511
514
  this.packageJSON = JSON.parse(packageJSONBuffer.toString());
512
515
  }
513
516
  refreshProjectFiles() {
514
- const allowedRootPaths = formatGlobCollectionPattern(
515
- PROJECT_DEFAULT_ALLOWED_ROOT_PATHS
516
- );
517
- const allowedExtensions = formatGlobCollectionPattern(
518
- PROJECT_DEFAULT_ALLOWED_EXTENSIONS
519
- );
520
- const projectFilesPattern = `./${allowedRootPaths}/**/*.${allowedExtensions}`;
521
- const patterns = [projectFilesPattern, ...PROJECT_DEFAULT_PATTERNS];
522
517
  const scanner = fileScannerFactory(this.cwd);
523
- this.files = scanner.scan(patterns);
518
+ this.files = scanner.scan(this.paths);
524
519
  }
525
520
  }
526
521
  class AppProject extends Project {
527
522
  strapiVersion;
528
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
+ }
529
541
  constructor(cwd) {
530
- super(cwd);
542
+ super(cwd, { paths: AppProject.paths });
531
543
  this.refreshStrapiVersion();
532
544
  }
533
545
  refresh() {
@@ -582,6 +594,30 @@ const formatGlobCollectionPattern = (collection) => {
582
594
  };
583
595
  class PluginProject extends Project {
584
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
+ }
585
621
  }
586
622
  const isPlugin = (cwd) => {
587
623
  const packageJSONPath = path__default.default.join(cwd, PROJECT_PACKAGE_JSON);
@@ -596,10 +632,7 @@ const isPlugin = (cwd) => {
596
632
  };
597
633
  const projectFactory = (cwd) => {
598
634
  fse__default.default.accessSync(cwd);
599
- if (isPlugin(cwd)) {
600
- return new PluginProject(cwd);
601
- }
602
- return new AppProject(cwd);
635
+ return isPlugin(cwd) ? new PluginProject(cwd) : new AppProject(cwd);
603
636
  };
604
637
  const isApplicationProject = (project) => {
605
638
  return project instanceof AppProject;
@@ -625,6 +658,9 @@ const version$1 = (version2) => {
625
658
  const codemodUID = (uid) => {
626
659
  return chalk__default.default.bold.cyan(uid);
627
660
  };
661
+ const projectDetails = (project) => {
662
+ return `Project: TYPE=${projectType(project.type)}; CWD=${path(project.cwd)}; PATHS=${project.paths.map(path)}`;
663
+ };
628
664
  const projectType = (type) => chalk__default.default.cyan(type);
629
665
  const versionRange = (range) => chalk__default.default.italic.yellow(range.raw);
630
666
  const highlight = (arg) => chalk__default.default.bold.underline(arg);
@@ -1180,6 +1216,7 @@ const upgrade$1 = async (options) => {
1180
1216
  const { logger, codemodsTarget } = options;
1181
1217
  const cwd = path__default.default.resolve(options.cwd ?? process.cwd());
1182
1218
  const project = projectFactory(cwd);
1219
+ logger.debug(projectDetails(project));
1183
1220
  if (!isApplicationProject(project)) {
1184
1221
  throw new Error(
1185
1222
  `The "${options.target}" upgrade can only be run on a Strapi project; for plugins, please use "codemods".`
@@ -1234,7 +1271,7 @@ const runCodemods$1 = async (options) => {
1234
1271
  const cwd = resolvePath(options.cwd);
1235
1272
  const project = projectFactory(cwd);
1236
1273
  const range = findRangeFromTarget(project, options.target);
1237
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1274
+ logger.debug(projectDetails(project));
1238
1275
  logger.debug(`Range: set to ${versionRange(range)}`);
1239
1276
  const codemodRunner = codemodRunnerFactory(project, range).dry(options.dry ?? false).onSelectCodemods(options.selectCodemods ?? null).setLogger(logger);
1240
1277
  let report;
@@ -1255,7 +1292,7 @@ const listCodemods$1 = async (options) => {
1255
1292
  const cwd = resolvePath(options.cwd);
1256
1293
  const project = projectFactory(cwd);
1257
1294
  const range = findRangeFromTarget(project, target);
1258
- logger.debug(`Project: ${projectType(project.type)} found in ${path(cwd)}`);
1295
+ logger.debug(projectDetails(project));
1259
1296
  logger.debug(`Range: set to ${versionRange(range)}`);
1260
1297
  const repo = codemodRepositoryFactory();
1261
1298
  repo.refresh();
@@ -1440,7 +1477,7 @@ When executed on a Strapi plugin project, it shows every codemods.
1440
1477
  return listCodemods(options);
1441
1478
  });
1442
1479
  };
1443
- const version = "0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78";
1480
+ const version = "0.0.0-experimental.f9cac24ba3b2f6acb12d0fb5669106e5a134174e";
1444
1481
  register$1(commander.program);
1445
1482
  register(commander.program);
1446
1483
  commander.program.usage("<command> [options]").on("command:*", ([invalidCmd]) => {