obsidian-plugin-config 1.1.2 → 1.1.3

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.
@@ -86,6 +86,31 @@ function main() {
86
86
  process.exit(1);
87
87
  }
88
88
 
89
+ // Clean NPM artifacts if package-lock.json exists
90
+ const packageLockPath = join(targetPath, 'package-lock.json');
91
+ if (fs.existsSync(packageLockPath)) {
92
+ console.log(`🧹 Installation NPM détectée, nettoyage...`);
93
+
94
+ try {
95
+ // Remove package-lock.json
96
+ fs.unlinkSync(packageLockPath);
97
+ console.log(` 🗑️ package-lock.json supprimé`);
98
+
99
+ // Remove node_modules if it exists
100
+ const nodeModulesPath = join(targetPath, 'node_modules');
101
+ if (fs.existsSync(nodeModulesPath)) {
102
+ fs.rmSync(nodeModulesPath, { recursive: true, force: true });
103
+ console.log(` 🗑️ node_modules supprimé (sera réinstallé avec Yarn)`);
104
+ }
105
+
106
+ console.log(` ✅ Artefacts NPM nettoyés pour éviter les conflits Yarn`);
107
+
108
+ } catch (cleanError) {
109
+ console.error(` ❌ Échec du nettoyage:`, cleanError.message);
110
+ console.log(` 💡 Supprimez manuellement package-lock.json et node_modules`);
111
+ }
112
+ }
113
+
89
114
  // Check if tsx is available locally in target
90
115
  let tsxCommand = 'npx tsx';
91
116
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obsidian-plugin-config",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Système d'injection pour plugins Obsidian autonomes",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -650,6 +650,69 @@ async function ensureTsxAvailable(targetPath: string): Promise<void> {
650
650
  }
651
651
  }
652
652
 
653
+ /**
654
+ * Clean NPM artifacts to avoid conflicts with Yarn
655
+ */
656
+ async function cleanNpmArtifacts(targetPath: string): Promise<void> {
657
+ console.log(`\n🧹 Cleaning NPM artifacts...`);
658
+
659
+ const packageLockPath = path.join(targetPath, "package-lock.json");
660
+ const nodeModulesPath = path.join(targetPath, "node_modules");
661
+
662
+ try {
663
+ // Remove package-lock.json if it exists
664
+ if (fs.existsSync(packageLockPath)) {
665
+ fs.unlinkSync(packageLockPath);
666
+ console.log(` 🗑️ Removed package-lock.json (NPM lock file)`);
667
+ }
668
+
669
+ // Remove node_modules if it exists
670
+ if (fs.existsSync(nodeModulesPath)) {
671
+ fs.rmSync(nodeModulesPath, { recursive: true, force: true });
672
+ console.log(` 🗑️ Removed node_modules (will be reinstalled with Yarn)`);
673
+ }
674
+
675
+ if (!fs.existsSync(packageLockPath) && !fs.existsSync(nodeModulesPath)) {
676
+ console.log(` ✅ No NPM artifacts found`);
677
+ }
678
+
679
+ } catch (error) {
680
+ console.error(` ❌ Failed to clean NPM artifacts: ${error}`);
681
+ console.log(` 💡 You may need to manually remove package-lock.json and node_modules`);
682
+ }
683
+ }
684
+
685
+ /**
686
+ * Clean NPM artifacts if package-lock.json is found (evidence of NPM usage)
687
+ */
688
+ async function cleanNpmArtifactsIfNeeded(targetPath: string): Promise<void> {
689
+ const packageLockPath = path.join(targetPath, "package-lock.json");
690
+
691
+ // Only clean if package-lock.json exists (proof of NPM installation)
692
+ if (fs.existsSync(packageLockPath)) {
693
+ console.log(`\n🧹 NPM installation detected, cleaning artifacts...`);
694
+
695
+ try {
696
+ // Remove package-lock.json
697
+ fs.unlinkSync(packageLockPath);
698
+ console.log(` 🗑️ Removed package-lock.json`);
699
+
700
+ // Remove node_modules if it exists
701
+ const nodeModulesPath = path.join(targetPath, "node_modules");
702
+ if (fs.existsSync(nodeModulesPath)) {
703
+ fs.rmSync(nodeModulesPath, { recursive: true, force: true });
704
+ console.log(` 🗑️ Removed node_modules (will be reinstalled with Yarn)`);
705
+ }
706
+
707
+ console.log(` ✅ NPM artifacts cleaned to avoid Yarn conflicts`);
708
+
709
+ } catch (error) {
710
+ console.error(` ❌ Failed to clean NPM artifacts: ${error}`);
711
+ console.log(` 💡 You may need to manually remove package-lock.json and node_modules`);
712
+ }
713
+ }
714
+ }
715
+
653
716
  /**
654
717
  * Check if tsx is installed locally and install it if needed
655
718
  */
@@ -711,24 +774,27 @@ export async function performInjection(targetPath: string): Promise<void> {
711
774
  console.log(`\n🚀 Starting injection process...`);
712
775
 
713
776
  try {
714
- // Step 1: Ensure tsx is installed
777
+ // Step 1: Clean NPM artifacts if needed
778
+ await cleanNpmArtifactsIfNeeded(targetPath);
779
+
780
+ // Step 2: Ensure tsx is installed
715
781
  await ensureTsxInstalled(targetPath);
716
782
 
717
- // Step 2: Inject scripts
783
+ // Step 3: Inject scripts
718
784
  await injectScripts(targetPath);
719
785
 
720
- // Step 3: Update package.json
786
+ // Step 4: Update package.json
721
787
  console.log(`\n📦 Updating package.json...`);
722
788
  await updatePackageJson(targetPath);
723
789
 
724
- // Step 4: Analyze centralized imports (without modifying)
790
+ // Step 5: Analyze centralized imports (without modifying)
725
791
  await analyzeCentralizedImports(targetPath);
726
792
 
727
- // Step 5: Create required directories
793
+ // Step 6: Create required directories
728
794
  console.log(`\n📁 Creating required directories...`);
729
795
  await createRequiredDirectories(targetPath);
730
796
 
731
- // Step 6: Install dependencies
797
+ // Step 7: Install dependencies
732
798
  await runYarnInstall(targetPath);
733
799
 
734
800
  // Step 6: Create injection info file