uilint 0.2.110 → 0.2.111

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.
@@ -721,9 +721,42 @@ async function createProvidersAndModifyLayout(projectPath, appRoot) {
721
721
  const providersExt = isTypeScript ? ".tsx" : ".jsx";
722
722
  const providersPath = join4(projectPath, appRoot, `providers${providersExt}`);
723
723
  if (existsSync4(providersPath)) {
724
- throw new Error(
725
- `providers${providersExt} already exists. Please select it from the list instead.`
726
- );
724
+ const original = readFileSync4(providersPath, "utf-8");
725
+ let mod;
726
+ try {
727
+ mod = parseModule(original);
728
+ } catch {
729
+ throw new Error(
730
+ `Unable to parse existing ${relative3(projectPath, providersPath)} as JavaScript/TypeScript.`
731
+ );
732
+ }
733
+ const program = mod.$ast;
734
+ const hasDevtoolsImport = !!findImportDeclaration(program, "uilint-react/devtools");
735
+ const hasOldImport = !!findImportDeclaration(program, "uilint-react");
736
+ const alreadyConfigured = (hasDevtoolsImport || hasOldImport) && hasUILintDevtoolsJsx(program);
737
+ if (alreadyConfigured) {
738
+ return {
739
+ providersFile: relative3(projectPath, providersPath),
740
+ layoutFile: relative3(projectPath, layoutPath),
741
+ modified: false,
742
+ alreadyConfigured: true
743
+ };
744
+ }
745
+ let changed = false;
746
+ const importRes = ensureSideEffectImport(program, "uilint-react/devtools");
747
+ if (importRes.changed) changed = true;
748
+ const addRes = addDevtoolsToClientComponent(program);
749
+ if (addRes.changed) changed = true;
750
+ if (changed) {
751
+ const updatedCode = generateCode(mod).code;
752
+ writeFileSync(providersPath, updatedCode, "utf-8");
753
+ }
754
+ return {
755
+ providersFile: relative3(projectPath, providersPath),
756
+ layoutFile: relative3(projectPath, layoutPath),
757
+ modified: changed,
758
+ alreadyConfigured: !changed
759
+ };
727
760
  }
728
761
  const providersContent = generateProvidersContent(isTypeScript);
729
762
  writeFileSync(providersPath, providersContent, "utf-8");
@@ -757,13 +790,17 @@ async function installReactUILintOverlay(opts) {
757
790
  const modifiedFiles = [];
758
791
  if (result.modified) {
759
792
  modifiedFiles.push(join4(opts.projectPath, result.providersFile));
760
- modifiedFiles.push(join4(opts.projectPath, result.layoutFile));
793
+ if (!result.alreadyConfigured) {
794
+ modifiedFiles.push(join4(opts.projectPath, result.layoutFile));
795
+ }
761
796
  }
762
797
  return {
763
798
  targetFile: result.providersFile,
764
799
  modified: result.modified,
765
- createdFile: result.providersFile,
766
- layoutModified: result.layoutFile,
800
+ alreadyConfigured: result.alreadyConfigured,
801
+ // Only set createdFile if we actually created a new file
802
+ createdFile: result.alreadyConfigured ? void 0 : result.providersFile,
803
+ layoutModified: result.alreadyConfigured ? void 0 : result.layoutFile,
767
804
  modifiedFiles
768
805
  };
769
806
  }
@@ -4075,4 +4112,4 @@ export {
4075
4112
  analyze,
4076
4113
  execute
4077
4114
  };
4078
- //# sourceMappingURL=chunk-GUL4IJOO.js.map
4115
+ //# sourceMappingURL=chunk-EBTY4AR3.js.map