UNPKG

@nx/react-native

Version:

The Nx Plugin for React Native contains generators for managing React Native applications and libraries within an Nx workspace. It provides: -Integration with libraries such as Jest, Detox, and Storybook. -Scaffolding for creating buildable libraries th

28 lines (27 loc) 1.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ensureNodeModulesSymlink = ensureNodeModulesSymlink; const node_fs_1 = require("node:fs"); const os_1 = require("os"); const path_1 = require("path"); /** * This function symlink workspace node_modules folder with app project's node_mdules folder. * For yarn and npm, it will symlink the entire node_modules folder. * If app project's node_modules already exist, it will remove it first then symlink it. * For pnpm, it will go through the package.json' dependencies and devDependencies, and also the required packages listed above. * @param workspaceRoot path of the workspace root * @param projectRoot path of app project root */ function ensureNodeModulesSymlink(workspaceRoot, projectRoot) { const worksapceNodeModulesPath = (0, path_1.join)(workspaceRoot, 'node_modules'); if (!(0, node_fs_1.existsSync)(worksapceNodeModulesPath)) { throw new Error(`Cannot find ${worksapceNodeModulesPath}`); } const appNodeModulesPath = (0, path_1.join)(workspaceRoot, projectRoot, 'node_modules'); // `mklink /D` requires admin privilege in Windows so we need to use junction const symlinkType = (0, os_1.platform)() === 'win32' ? 'junction' : 'dir'; if ((0, node_fs_1.existsSync)(appNodeModulesPath)) { (0, node_fs_1.rmSync)(appNodeModulesPath, { recursive: true, force: true }); } (0, node_fs_1.symlinkSync)(worksapceNodeModulesPath, appNodeModulesPath, symlinkType); }