|
| 1 | +/** |
| 2 | + * Fix nested packages not using workspace version |
| 3 | + * ember-cli-addon-tests will link ember-cli-fastboot and run npm install in the test apps, |
| 4 | + * the installation will install fastboot from npm registry rather than workspace version |
| 5 | + */ |
| 6 | + |
| 7 | +import path from 'path'; |
| 8 | +import fs from 'fs-extra'; |
| 9 | +import { fileURLToPath } from 'url'; |
| 10 | +import chalk from 'chalk'; |
| 11 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 12 | + |
| 13 | +const packagesDir = path.resolve(__dirname, '../../packages'); |
| 14 | +const nodeModulesDir = path.resolve(__dirname, 'node_modules'); |
| 15 | + |
| 16 | +// eslint-disable-next-line no-undef |
| 17 | +const shouldRestore = process.argv[2]; |
| 18 | +if (shouldRestore === '--help' || shouldRestore === '-h') { |
| 19 | + console.log(`Usage: node fix-node-modules.mjs [arguments] |
| 20 | +Options: |
| 21 | + -h, --help print this message |
| 22 | + -r, --restore restore node_modules by removing symlinks`); |
| 23 | +} else if (shouldRestore === '-r' || shouldRestore === '--restore') { |
| 24 | + run(true); |
| 25 | +} else { |
| 26 | + run(false); |
| 27 | +} |
| 28 | + |
| 29 | +function run(shouldRestore) { |
| 30 | + ['fastboot', 'fastboot-express-middleware'].forEach((packageName) => { |
| 31 | + const nodeModulesPackageDir = path.join(nodeModulesDir, packageName); |
| 32 | + const workspacesPackageDir = path.resolve(packagesDir, packageName); |
| 33 | + if (fs.existsSync(nodeModulesPackageDir)) { |
| 34 | + console.log(chalk.blue(`remove ${nodeModulesPackageDir}`)); |
| 35 | + fs.removeSync(nodeModulesPackageDir); |
| 36 | + } |
| 37 | + if (!shouldRestore) { |
| 38 | + console.log( |
| 39 | + chalk.green( |
| 40 | + `symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}` |
| 41 | + ) |
| 42 | + ); |
| 43 | + fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir'); |
| 44 | + } |
| 45 | + }); |
| 46 | +} |
0 commit comments