|
| 1 | +/** |
| 2 | + * Fix nested packages not using workspace version |
| 3 | + * |
| 4 | + * For example, these will download from npm registry rather than using local workspaces, |
| 5 | + * the changes won't be reflected during tests if not symlink to worksapces. |
| 6 | + * node_modules/ember-cli-fastboot-testing/node_modules/fastboot |
| 7 | + * packages/ember-cli-fastboot/node_modules/fastboot-express-middleware |
| 8 | + * packages/ember-cli-fastboot/node_modules/fastboot |
| 9 | + */ |
| 10 | + |
| 11 | +import path from 'path'; |
| 12 | +import fs from 'fs-extra'; |
| 13 | +import { fileURLToPath } from 'url'; |
| 14 | +import execa from 'execa'; |
| 15 | +import chalk from 'chalk'; |
| 16 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 17 | + |
| 18 | +const projectRoot = path.resolve(__dirname, '..'); |
| 19 | +const packagesDir = path.resolve(projectRoot, 'packages'); |
| 20 | +const packages = fs.readdirSync(packagesDir); |
| 21 | +const extraDirs = [ |
| 22 | + path.resolve(projectRoot, 'node_modules/ember-cli-fastboot-testing'), |
| 23 | + path.resolve(projectRoot, 'node_modules/ember-fetch'), |
| 24 | +]; |
| 25 | + |
| 26 | +[...packages, ...extraDirs].forEach(packageName => { |
| 27 | + const packageNodeModules = path.resolve(packagesDir, packageName, 'node_modules'); |
| 28 | + console.log(chalk.grey(`Inspecting ${packageNodeModules} ...`)); |
| 29 | + packages.forEach(packageNameToLink => { |
| 30 | + const nodeModulesPackageDir = path.join(packageNodeModules, packageNameToLink); |
| 31 | + const workspacesPackageDir = path.resolve(packagesDir, packageNameToLink); |
| 32 | + if (fs.existsSync(nodeModulesPackageDir)) { |
| 33 | + console.log(chalk.green(`symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}`)); |
| 34 | + fs.removeSync(nodeModulesPackageDir); |
| 35 | + fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir'); |
| 36 | + } |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
0 commit comments