@cloudflare/autoconfig 0.4.3 → 0.4.5

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.js CHANGED
@@ -44554,8 +44554,24 @@ function getViteConfigPath(projectPath) {
44554
44554
  }
44555
44555
  __name(getViteConfigPath, "getViteConfigPath");
44556
44556
  var knownIncompatiblePlugins = ["nitro", "nitroV2Plugin", "netlify"];
44557
+ function hasIdentifierOutsideImport(program, identifierName) {
44558
+ let hasIdentifier = false;
44559
+ recast6.types.visit(program, {
44560
+ visitIdentifier(n) {
44561
+ const parent = n.parentPath.node;
44562
+ if (n.node.name === identifierName && !t.ImportSpecifier.check(parent) && !t.ImportDefaultSpecifier.check(parent) && !t.ImportNamespaceSpecifier.check(parent)) {
44563
+ hasIdentifier = true;
44564
+ return false;
44565
+ }
44566
+ this.traverse(n);
44567
+ }
44568
+ });
44569
+ return hasIdentifier;
44570
+ }
44571
+ __name(hasIdentifierOutsideImport, "hasIdentifierOutsideImport");
44557
44572
  function transformViteConfig(projectPath, options = {}) {
44558
44573
  const filePath = getViteConfigPath(projectPath);
44574
+ const removedIncompatiblePlugins = /* @__PURE__ */ new Set();
44559
44575
  transformFile(filePath, {
44560
44576
  visitProgram(n) {
44561
44577
  const lastImportIndex = n.node.body.findLastIndex(
@@ -44571,7 +44587,17 @@ function transformViteConfig(projectPath, options = {}) {
44571
44587
  )) {
44572
44588
  lastImport.insertAfter(importAst);
44573
44589
  }
44574
- return this.traverse(n);
44590
+ this.traverse(n);
44591
+ n.node.body = n.node.body.filter((statement) => {
44592
+ if (!t.ImportDeclaration.check(statement) || !statement.specifiers?.length) {
44593
+ return true;
44594
+ }
44595
+ statement.specifiers = statement.specifiers.filter(
44596
+ (specifier) => !t.Identifier.check(specifier.local) || !removedIncompatiblePlugins.has(specifier.local.name) || hasIdentifierOutsideImport(n.node, specifier.local.name)
44597
+ );
44598
+ return statement.specifiers.length > 0;
44599
+ });
44600
+ return false;
44575
44601
  },
44576
44602
  visitCallExpression: /* @__PURE__ */ __name(function(n) {
44577
44603
  const callee = n.node.callee;
@@ -44648,6 +44674,7 @@ function transformViteConfig(projectPath, options = {}) {
44648
44674
  ];
44649
44675
  pluginsProp.value.elements = pluginsProp.value.elements.filter((el) => {
44650
44676
  if (el?.type === "CallExpression" && el.callee.type === "Identifier" && incompatibleVitePlugins.includes(el.callee.name)) {
44677
+ removedIncompatiblePlugins.add(el.callee.name);
44651
44678
  return false;
44652
44679
  }
44653
44680
  return true;