@valbuild/init 0.69.3 → 0.71.0

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.
@@ -504,7 +504,7 @@ function transformNextAppRouterValProvider(fileInfo, api, options) {
504
504
 
505
505
  var packageJson = {
506
506
  name: "@valbuild/init",
507
- version: "0.69.3",
507
+ version: "0.71.0",
508
508
  description: "Initialize a new val.build project",
509
509
  exports: {
510
510
  "./main": {
@@ -603,6 +603,15 @@ function info(message) {
603
603
  console.log(message);
604
604
  }
605
605
 
606
+ function addEslintPluginToEslintMjs(fileInfo, api, options) {
607
+ if (!options.configImportPath) {
608
+ throw new Error("configImportPath is required");
609
+ }
610
+ var root = api.jscodeshift(fileInfo.source);
611
+ root.findVariableDeclarators("eslintConfig").find(j__default["default"].ArrayExpression).find(j__default["default"].SpreadElement).find(j__default["default"].CallExpression).find(j__default["default"].Literal).at(-1).insertAfter(j__default["default"].literal("plugin:@valbuild/recommended"));
612
+ return root.toSource();
613
+ }
614
+
606
615
  var MIN_VAL_VERSION = packageJson.version;
607
616
  var MIN_NEXT_VERSION = "13.4.0";
608
617
  var maxResetLength = 0;
@@ -739,6 +748,16 @@ var analyze = /*#__PURE__*/function () {
739
748
  analysis.isValEslintRulesConfigured = analysis.eslintRcJsText.includes("plugin:@valbuild/recommended");
740
749
  }
741
750
  }
751
+ analysis.eslintRcMjsPath = files.find(function (file) {
752
+ return file.endsWith("eslint.config.mjs");
753
+ });
754
+ if (analysis.eslintRcMjsPath) {
755
+ analysis.eslintRcMjsText = fs__default["default"].readFileSync(analysis.eslintRcMjsPath, "utf8");
756
+ if (analysis.eslintRcMjsText) {
757
+ // TODO: Evaluate and extract config?
758
+ analysis.isValEslintRulesConfigured = analysis.eslintRcMjsText.includes("@valbuild");
759
+ }
760
+ }
742
761
  analysis.eslintRcJsonPath = files.find(function (file) {
743
762
  return file.endsWith(".eslintrc.json");
744
763
  }) || files.find(function (file) {
@@ -776,15 +795,15 @@ var analyze = /*#__PURE__*/function () {
776
795
  analysis.appRouterPath = path__default["default"].dirname(appRouterLayoutPath);
777
796
  analysis.srcDir = path__default["default"].dirname(analysis.appRouterPath);
778
797
  }
779
- _context.prev = 34;
798
+ _context.prev = 36;
780
799
  git = simpleGit__default["default"](root);
781
- _context.next = 38;
800
+ _context.next = 40;
782
801
  return git.status([]);
783
- case 38:
802
+ case 40:
784
803
  gitStatus = _context.sent;
785
- _context.next = 41;
804
+ _context.next = 43;
786
805
  return git.remote(["-v"]);
787
- case 41:
806
+ case 43:
788
807
  gitRemoteOrigin = _context.sent;
789
808
  analysis.hasGit = true;
790
809
  analysis.isGitHub = gitRemoteOrigin ? !!gitRemoteOrigin.includes("github.com") : false;
@@ -800,21 +819,21 @@ var analyze = /*#__PURE__*/function () {
800
819
  repo: repo
801
820
  };
802
821
  }
803
- _context.next = 50;
822
+ _context.next = 52;
804
823
  break;
805
- case 48:
806
- _context.prev = 48;
807
- _context.t1 = _context["catch"](34);
808
824
  case 50:
825
+ _context.prev = 50;
826
+ _context.t1 = _context["catch"](36);
827
+ case 52:
809
828
  gitIgnorePath = path__default["default"].join(root, ".gitignore");
810
829
  analysis.gitIgnorePath = gitIgnorePath;
811
830
  analysis.gitIgnoreFile = fs__default["default"].readFileSync(gitIgnorePath, "utf-8");
812
831
  return _context.abrupt("return", analysis);
813
- case 54:
832
+ case 56:
814
833
  case "end":
815
834
  return _context.stop();
816
835
  }
817
- }, _callee, null, [[8, 19], [34, 48]]);
836
+ }, _callee, null, [[8, 19], [36, 50]]);
818
837
  }));
819
838
  return function analyze(_x, _x2) {
820
839
  return _ref2.apply(this, arguments);
@@ -862,8 +881,13 @@ function _plan() {
862
881
  _answer9,
863
882
  currentEslintRc,
864
883
  parsedEslint,
884
+ _res,
885
+ _diff,
886
+ _s,
865
887
  _answer10,
866
888
  _answer11,
889
+ _answer12,
890
+ _answer13,
867
891
  vscodeDir,
868
892
  settingsPath,
869
893
  currentSettings,
@@ -1430,7 +1454,7 @@ function _plan() {
1430
1454
  warn(NO_PATCH_WARNING);
1431
1455
  }
1432
1456
  if (!analysis.valEslintVersion) {
1433
- _context3.next = 246;
1457
+ _context3.next = 279;
1434
1458
  break;
1435
1459
  }
1436
1460
  if (!analysis.isValEslintRulesConfigured) {
@@ -1438,53 +1462,58 @@ function _plan() {
1438
1462
  break;
1439
1463
  }
1440
1464
  warn(" @valbuild/eslint-plugin rules: already configured");
1441
- _context3.next = 246;
1465
+ _context3.next = 279;
1442
1466
  break;
1443
1467
  case 220:
1444
1468
  if (!analysis.eslintRcJsPath) {
1445
- _context3.next = 224;
1469
+ _context3.next = 225;
1446
1470
  break;
1447
1471
  }
1448
- warn('Cannot patch eslint: found .eslintrc.js but can only patch JSON files (at the moment).\nAdd the following to your eslint config:\n\n "extends": ["plugin:@valbuild/recommended"]\n');
1449
- _context3.next = 246;
1472
+ _context3.next = 223;
1473
+ return prompts.confirm({
1474
+ message: ' Cannot patch eslint: found .eslintrc.js but can only patch JSON files (at the moment).\nAdd the following to your eslint config:\n\n "extends": ["plugin:@valbuild/recommended"]\n\n',
1475
+ "default": true
1476
+ });
1477
+ case 223:
1478
+ _context3.next = 279;
1450
1479
  break;
1451
- case 224:
1480
+ case 225:
1452
1481
  if (!analysis.eslintRcJsonPath) {
1453
- _context3.next = 245;
1482
+ _context3.next = 246;
1454
1483
  break;
1455
1484
  }
1456
1485
  if (defaultAnswers) {
1457
- _context3.next = 231;
1486
+ _context3.next = 232;
1458
1487
  break;
1459
1488
  }
1460
- _context3.next = 228;
1489
+ _context3.next = 229;
1461
1490
  return prompts.confirm({
1462
1491
  message: "Patch eslintrc.json to use the recommended Val eslint rules?",
1463
1492
  "default": true
1464
1493
  });
1465
- case 228:
1494
+ case 229:
1466
1495
  _context3.t9 = _context3.sent;
1467
- _context3.next = 232;
1496
+ _context3.next = 233;
1468
1497
  break;
1469
- case 231:
1470
- _context3.t9 = true;
1471
1498
  case 232:
1499
+ _context3.t9 = true;
1500
+ case 233:
1472
1501
  _answer9 = _context3.t9;
1473
1502
  if (!_answer9) {
1474
- _context3.next = 243;
1503
+ _context3.next = 244;
1475
1504
  break;
1476
1505
  }
1477
1506
  currentEslintRc = fs__default["default"].readFileSync(analysis.eslintRcJsonPath, "utf-8");
1478
1507
  parsedEslint = JSON.parse(currentEslintRc);
1479
1508
  if (!(_typeof(parsedEslint) !== "object")) {
1480
- _context3.next = 239;
1509
+ _context3.next = 240;
1481
1510
  break;
1482
1511
  }
1483
1512
  error("Could not patch eslint: ".concat(analysis.eslintRcJsonPath, " was not an object"));
1484
1513
  return _context3.abrupt("return", {
1485
1514
  abort: true
1486
1515
  });
1487
- case 239:
1516
+ case 240:
1488
1517
  if (typeof parsedEslint["extends"] === "string") {
1489
1518
  parsedEslint["extends"] = [parsedEslint["extends"]];
1490
1519
  }
@@ -1494,34 +1523,124 @@ function _plan() {
1494
1523
  path: analysis.eslintRcJsonPath,
1495
1524
  source: JSON.stringify(parsedEslint, null, 2) + "\n"
1496
1525
  };
1497
- case 243:
1498
- _context3.next = 246;
1526
+ case 244:
1527
+ _context3.next = 279;
1499
1528
  break;
1500
- case 245:
1501
- warn("Cannot patch eslint: failed to find eslint config file");
1502
1529
  case 246:
1503
- if (!analysis.gitIgnorePath) {
1504
- _context3.next = 258;
1530
+ if (!analysis.eslintRcMjsPath) {
1531
+ _context3.next = 278;
1532
+ break;
1533
+ }
1534
+ if (!analysis.eslintRcMjsText) {
1535
+ _context3.next = 275;
1505
1536
  break;
1506
1537
  }
1538
+ _res = addEslintPluginToEslintMjs({
1539
+ path: analysis.eslintRcMjsPath,
1540
+ source: analysis.eslintRcMjsText
1541
+ }, {
1542
+ j: j__default["default"],
1543
+ jscodeshift: j__default["default"].withParser("tsx"),
1544
+ stats: function stats() {},
1545
+ report: function report() {}
1546
+ }, {
1547
+ configImportPath: path__default["default"].relative(path__default["default"].dirname(analysis.eslintRcMjsPath), valConfigPath).replace(".js", "").replace(".ts", "")
1548
+ });
1549
+ _diff = diff.diffLines(analysis.eslintRcMjsText, _res, {});
1550
+ _s = "";
1551
+ _diff.forEach(function (part) {
1552
+ if (part.added) {
1553
+ _s += chalk__default["default"].green(part.value);
1554
+ } else if (part.removed) {
1555
+ _s += chalk__default["default"].red(part.value);
1556
+ } else {
1557
+ _s += part.value;
1558
+ }
1559
+ });
1507
1560
  if (defaultAnswers) {
1508
- _context3.next = 253;
1561
+ _context3.next = 258;
1509
1562
  break;
1510
1563
  }
1511
- _context3.next = 250;
1564
+ _context3.next = 255;
1512
1565
  return prompts.confirm({
1513
- message: "Append .gitignore entry for Val cache? (recommended)",
1566
+ message: "Automatically patch ".concat(analysis.eslintRcMjsPath, " file?"),
1514
1567
  "default": true
1515
1568
  });
1516
- case 250:
1569
+ case 255:
1517
1570
  _context3.t10 = _context3.sent;
1518
- _context3.next = 254;
1571
+ _context3.next = 259;
1519
1572
  break;
1520
- case 253:
1573
+ case 258:
1521
1574
  _context3.t10 = true;
1522
- case 254:
1575
+ case 259:
1523
1576
  _answer10 = _context3.t10;
1524
- if (_answer10) {
1577
+ if (!_answer10) {
1578
+ _context3.next = 272;
1579
+ break;
1580
+ }
1581
+ if (defaultAnswers) {
1582
+ _context3.next = 267;
1583
+ break;
1584
+ }
1585
+ _context3.next = 264;
1586
+ return prompts.confirm({
1587
+ message: "Do you accept the following patch:\n".concat(_s, "\n"),
1588
+ "default": true
1589
+ });
1590
+ case 264:
1591
+ _context3.t11 = _context3.sent;
1592
+ _context3.next = 268;
1593
+ break;
1594
+ case 267:
1595
+ _context3.t11 = true;
1596
+ case 268:
1597
+ _answer11 = _context3.t11;
1598
+ if (!_answer11) {
1599
+ warn(NO_PATCH_WARNING);
1600
+ plan.updateEslint = false;
1601
+ } else {
1602
+ plan.updateEslint = {
1603
+ path: analysis.eslintRcMjsPath,
1604
+ source: _res
1605
+ };
1606
+ }
1607
+ _context3.next = 273;
1608
+ break;
1609
+ case 272:
1610
+ warn(NO_PATCH_WARNING);
1611
+ case 273:
1612
+ _context3.next = 276;
1613
+ break;
1614
+ case 275:
1615
+ warn(NO_PATCH_WARNING);
1616
+ case 276:
1617
+ _context3.next = 279;
1618
+ break;
1619
+ case 278:
1620
+ warn("Cannot patch eslint: failed to find eslint config file");
1621
+ case 279:
1622
+ if (!analysis.gitIgnorePath) {
1623
+ _context3.next = 291;
1624
+ break;
1625
+ }
1626
+ if (defaultAnswers) {
1627
+ _context3.next = 286;
1628
+ break;
1629
+ }
1630
+ _context3.next = 283;
1631
+ return prompts.confirm({
1632
+ message: "Append .gitignore entry for Val cache? (recommended)",
1633
+ "default": true
1634
+ });
1635
+ case 283:
1636
+ _context3.t12 = _context3.sent;
1637
+ _context3.next = 287;
1638
+ break;
1639
+ case 286:
1640
+ _context3.t12 = true;
1641
+ case 287:
1642
+ _answer12 = _context3.t12;
1643
+ if (_answer12) {
1525
1644
  plan.updateGitIgnore = {
1526
1645
  path: analysis.gitIgnorePath,
1527
1646
  source: (analysis.gitIgnoreFile ? "".concat(analysis.gitIgnoreFile, "\n\n") : "") + "# Val local cache\n.val\n"
@@ -1529,59 +1648,59 @@ function _plan() {
1529
1648
  } else {
1530
1649
  plan.updateGitIgnore = false;
1531
1650
  }
1532
- _context3.next = 259;
1651
+ _context3.next = 292;
1533
1652
  break;
1534
- case 258:
1653
+ case 291:
1535
1654
  plan.updateGitIgnore = false;
1536
- case 259:
1655
+ case 292:
1537
1656
  if (defaultAnswers) {
1538
- _context3.next = 265;
1657
+ _context3.next = 298;
1539
1658
  break;
1540
1659
  }
1541
- _context3.next = 262;
1660
+ _context3.next = 295;
1542
1661
  return prompts.confirm({
1543
1662
  message: "Add the Val Build IntelliSense to .vscode/extensions.json?",
1544
1663
  "default": true
1545
1664
  });
1546
- case 262:
1547
- _context3.t11 = _context3.sent;
1548
- _context3.next = 266;
1665
+ case 295:
1666
+ _context3.t13 = _context3.sent;
1667
+ _context3.next = 299;
1549
1668
  break;
1550
- case 265:
1551
- _context3.t11 = true;
1552
- case 266:
1553
- _answer11 = _context3.t11;
1554
- if (!_answer11) {
1555
- _context3.next = 292;
1669
+ case 298:
1670
+ _context3.t13 = true;
1671
+ case 299:
1672
+ _answer13 = _context3.t13;
1673
+ if (!_answer13) {
1674
+ _context3.next = 325;
1556
1675
  break;
1557
1676
  }
1558
1677
  vscodeDir = path__default["default"].join(analysis.root, ".vscode");
1559
1678
  settingsPath = path__default["default"].join(vscodeDir, "extensions.json");
1560
1679
  currentSettings = {};
1561
- _context3.prev = 271;
1680
+ _context3.prev = 304;
1562
1681
  currentSettingsFile = fs__default["default"].readFileSync(settingsPath, "utf-8");
1563
1682
  if (!currentSettingsFile) {
1564
- _context3.next = 282;
1683
+ _context3.next = 315;
1565
1684
  break;
1566
1685
  }
1567
- _context3.prev = 274;
1686
+ _context3.prev = 307;
1568
1687
  currentSettings = JSON.parse(currentSettingsFile);
1569
- _context3.next = 282;
1688
+ _context3.next = 315;
1570
1689
  break;
1571
- case 278:
1572
- _context3.prev = 278;
1573
- _context3.t12 = _context3["catch"](274);
1574
- warn("Failed to parse VS Code extensions.json found here: ".concat(settingsPath, ".").concat(_context3.t12 instanceof Error ? "Parse error: ".concat(_context3.t12.message) : ""));
1690
+ case 311:
1691
+ _context3.prev = 311;
1692
+ _context3.t14 = _context3["catch"](307);
1693
+ warn("Failed to parse VS Code extensions.json found here: ".concat(settingsPath, ".").concat(_context3.t14 instanceof Error ? "Parse error: ".concat(_context3.t14.message) : ""));
1575
1694
  return _context3.abrupt("return", {
1576
1695
  abort: true
1577
1696
  });
1578
- case 282:
1579
- _context3.next = 286;
1697
+ case 315:
1698
+ _context3.next = 319;
1580
1699
  break;
1581
- case 284:
1582
- _context3.prev = 284;
1583
- _context3.t13 = _context3["catch"](271);
1584
- case 286:
1700
+ case 317:
1701
+ _context3.prev = 317;
1702
+ _context3.t15 = _context3["catch"](304);
1703
+ case 319:
1585
1704
  currentRecommendations =
1586
1705
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1587
1706
  currentSettings.recommendations;
@@ -1595,17 +1714,17 @@ function _plan() {
1595
1714
  path: settingsPath,
1596
1715
  source: JSON.stringify(currentSettings, null, 2)
1597
1716
  };
1598
- _context3.next = 293;
1717
+ _context3.next = 326;
1599
1718
  break;
1600
- case 292:
1719
+ case 325:
1601
1720
  plan.updateVSCodeSettings = false;
1602
- case 293:
1721
+ case 326:
1603
1722
  return _context3.abrupt("return", plan);
1604
- case 294:
1723
+ case 327:
1605
1724
  case "end":
1606
1725
  return _context3.stop();
1607
1726
  }
1608
- }, _callee3, null, [[271, 284], [274, 278]]);
1727
+ }, _callee3, null, [[304, 317], [307, 311]]);
1609
1728
  }));
1610
1729
  return _plan.apply(this, arguments);
1611
1730
  }