11import { readdir , readFile , writeFile } from "fs/promises" ;
2- import { join } from "path" ;
2+ import { dirname , join } from "path" ;
33
44import type { PackageJSON } from "../../helpers/packages-json.js" ;
55
@@ -53,8 +53,9 @@ const findPackageJsonFiles = async (
5353 * 1. Finds all package.json files in the workspace (excluding node_modules and dist)
5454 * 2. Identifies packages that have @vitnode/core as a dependency
5555 * 3. Adds the new plugin as a dependency with the appropriate workspace reference
56- * 4. Skips packages in the plugins folder (except the new plugin itself)
57- * 5. Respects the package manager's workspace protocol
56+ * 4. Skips other packages in the same parent directory as the plugin (e.g., other plugins)
57+ * 5. Works with any folder structure (apps/, applications/, sandbox/, etc.)
58+ * 6. Respects the package manager's workspace protocol
5859 *
5960 * @param packageManager - The package manager being used (pnpm, npm, yarn, bun)
6061 * @param pluginName - The name of the plugin to add (e.g., "@my-org/my-plugin")
@@ -71,17 +72,19 @@ export const addPluginToWorkspace = async ({
7172 // Find all package.json files in the workspace
7273 const packageJsonFiles = await findPackageJsonFiles ( rootPath ) ;
7374
75+ // Get the parent directory of the plugin (e.g., "plugins", "packages", etc.)
76+ const pluginParentDir = dirname ( pluginPath ) ;
77+
7478 for ( const packageJsonPath of packageJsonFiles ) {
7579 // Skip if this is the plugin's own package.json
7680 if ( packageJsonPath === join ( pluginPath , "package.json" ) ) {
7781 continue ;
7882 }
7983
80- // Skip if this is in the plugins folder (excluding the new plugin itself)
81- if (
82- packageJsonPath . includes ( "/plugins/" ) &&
83- ! packageJsonPath . startsWith ( pluginPath )
84- ) {
84+ // Skip other packages in the same parent directory as the plugin
85+ // (e.g., if plugin is in "plugins/my-plugin", skip "plugins/other-plugin")
86+ const packageDir = dirname ( dirname ( packageJsonPath ) ) ; // Get parent of package folder
87+ if ( packageDir === pluginParentDir ) {
8588 continue ;
8689 }
8790
0 commit comments