diff --git a/desktop/pkg-lib/src/__tests__/getWatchFolders.node.ts b/desktop/pkg-lib/src/__tests__/getWatchFolders.node.ts index ed886c641..1123d3b53 100644 --- a/desktop/pkg-lib/src/__tests__/getWatchFolders.node.ts +++ b/desktop/pkg-lib/src/__tests__/getWatchFolders.node.ts @@ -44,6 +44,11 @@ describe('getWatchFolders', () => { fb_plugin_module_2: mockfs.symlink({ path: '../plugins/fb/fb_plugin_module_2', }), + '@scoped': { + local_module_3: mockfs.symlink({ + path: '../../local_module_3', + }), + }, }, local_module_1: { 'package.json': '{"dependencies": {"installed_module_1": "1.0.0"}}', @@ -52,9 +57,13 @@ describe('getWatchFolders', () => { 'package.json': '{"dependencies": {"fb_plugin_module_1": "1.0.0", "plugin_module_1": "1.0.0"}}', }, + local_module_3: { + 'package.json': '{"dependencies": {"installed_module_1": "1.0.0"}}', + }, plugins: { plugin_module_1: { - 'package.json': '{"dependencies": {"local_module_2": "1.0.0"}}', + 'package.json': + '{"dependencies": {"local_module_2": "1.0.0", "@scoped/local_module_3": "1.0.0"}}', }, plugin_module_2: { 'package.json': '{"dependencies": {"fb_plugin_module_1": "1.0.0"}}', @@ -102,6 +111,7 @@ describe('getWatchFolders', () => { "/test/root/plugins/fb/node_modules", "/test/root/plugins/plugin_module_1", "/test/root/plugins/plugin_module_2", + "/test/root/local_module_3", ] `); } finally { diff --git a/desktop/pkg-lib/src/getWatchFolders.ts b/desktop/pkg-lib/src/getWatchFolders.ts index 0f6ffb8a3..458312d56 100644 --- a/desktop/pkg-lib/src/getWatchFolders.ts +++ b/desktop/pkg-lib/src/getWatchFolders.ts @@ -36,15 +36,23 @@ export default async (packageDir: string): Promise => { if (await fs.pathExists(nodeModulesDir)) { watchDirs.add(nodeModulesDir); for (const moduleName of dependenciesSet) { + const isModuleNameScoped = moduleName.includes('/'); const fullModulePath = path.join(nodeModulesDir, moduleName); if (await fs.pathExists(fullModulePath)) { dependenciesSet.delete(moduleName); const stat = await fs.lstat(fullModulePath); if (stat.isSymbolicLink()) { const targetDir = await fs.readlink(fullModulePath); - const absoluteTargetDir = path.isAbsolute(targetDir) - ? targetDir - : path.resolve(nodeModulesDir, targetDir); + let absoluteTargetDir; + if (path.isAbsolute(targetDir)) { + absoluteTargetDir = targetDir; + } else if (isModuleNameScoped) { + const scope = moduleName.split('/')[0]; + const scopeDir = path.join(nodeModulesDir, scope); + absoluteTargetDir = path.resolve(scopeDir, targetDir); + } else { + absoluteTargetDir = path.resolve(nodeModulesDir, targetDir); + } if (!processedPackages.has(absoluteTargetDir)) { packagesToProcess.push(absoluteTargetDir); processedPackages.add(absoluteTargetDir);