diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c2f57aae0..63d7d919e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -114,5 +114,4 @@ jobs: yarn install --ignore-engines --frozen-lockfile - name: Run Mocha Tests run: | - node scripts/fix-node-modules.mjs yarn workspace ember-cli-fastboot test:mocha diff --git a/package.json b/package.json index ae900d830..d01babec3 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,6 @@ "test-packages/*" ], "scripts": { - "pretest": "node scripts/fix-node-modules.mjs", "test": "npm-run-all test:*", "test:ember-cli-fastboot": "yarn workspace ember-cli-fastboot test:ember", "test:fastboot": "yarn workspace fastboot test", @@ -20,9 +19,6 @@ "test:extra": "yarn workspace basic-app test:mocha && yarn workspace custom-fastboot-app test:mocha" }, "devDependencies": { - "chalk": "^4.1.2", - "execa": "^5.1.1", - "fs-extra": "^10.0.0", "npm-run-all": "^4.1.5", "release-it": "^14.2.2", "release-it-lerna-changelog": "^3.1.0", diff --git a/packages/ember-cli-fastboot/fix-node-modules.mjs b/packages/ember-cli-fastboot/fix-node-modules.mjs new file mode 100644 index 000000000..9375bec7e --- /dev/null +++ b/packages/ember-cli-fastboot/fix-node-modules.mjs @@ -0,0 +1,47 @@ +/** + * Fix nested packages not using workspace version + * ember-cli-addon-tests will link ember-cli-fastboot and run npm install in the test apps, + * the installation will install fastboot from npm registry rather than workspace version + * + */ + +import path from 'path'; +import fs from 'fs-extra'; +import { fileURLToPath } from 'url'; +import chalk from 'chalk'; +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const packagesDir = path.resolve(__dirname, '../../packages'); +const nodeModulesDir = path.resolve(__dirname, 'node_modules'); + +// eslint-disable-next-line no-undef +const shouldRestore = process.argv[2]; +if (shouldRestore === '--help' || shouldRestore === '-h') { + console.log(`Usage: node fix-node-modules.mjs [arguments] +Options: + -h, --help print this message + -r, --restore restore node_modules by removing symlinks`); +} else if (shouldRestore === '-r' || shouldRestore === '--restore') { + run(true); +} else { + run(false); +} + +function run(shouldRestore) { + ['fastboot', 'fastboot-express-middleware'].forEach((packageName) => { + const nodeModulesPackageDir = path.join(nodeModulesDir, packageName); + const workspacesPackageDir = path.resolve(packagesDir, packageName); + if (fs.existsSync(nodeModulesPackageDir)) { + console.log(chalk.blue(`remove ${nodeModulesPackageDir}`)); + fs.removeSync(nodeModulesPackageDir); + } + if (!shouldRestore) { + console.log( + chalk.green( + `symlink ${nodeModulesPackageDir} -> ${workspacesPackageDir}` + ) + ); + fs.symlinkSync(workspacesPackageDir, nodeModulesPackageDir, 'dir'); + } + }); +} diff --git a/packages/ember-cli-fastboot/package.json b/packages/ember-cli-fastboot/package.json index 4ee754a39..b59db3a9b 100644 --- a/packages/ember-cli-fastboot/package.json +++ b/packages/ember-cli-fastboot/package.json @@ -23,7 +23,7 @@ "lint:js:fix": "eslint . --fix", "start": "ember serve", "test": "npm-run-all lint test:*", - "test:mocha": "mocha", + "test:mocha": "node fix-node-modules.mjs && mocha && node fix-node-modules.mjs -r", "test:ember": "ember test", "test:precook": "node node_modules/ember-cli-addon-tests/scripts/precook-node-modules.js" }, @@ -34,7 +34,7 @@ "broccoli-merge-trees": "^3.0.1", "broccoli-plugin": "^1.3.1", "broccoli-persistent-filter": "^3.1.2", - "chalk": "^2.4.1", + "chalk": "^4.1.2", "ember-cli-babel": "^7.26.3", "ember-cli-htmlbars": "^5.7.1", "ember-cli-lodash-subset": "2.0.1", @@ -43,7 +43,7 @@ "fastboot": "3.2.0-beta.2", "fastboot-express-middleware": "3.2.0-beta.2", "fastboot-transform": "^0.1.3", - "fs-extra": "^7.0.0", + "fs-extra": "^10.0.0", "jsdom": "^16.2.2", "json-stable-stringify": "^1.0.1", "md5-hex": "^2.0.0", diff --git a/packages/ember-cli-fastboot/test/fixtures/customized-outputpaths/app/index.html b/packages/ember-cli-fastboot/test/fixtures/customized-outputpaths/app/index.html new file mode 100644 index 000000000..8392fc505 --- /dev/null +++ b/packages/ember-cli-fastboot/test/fixtures/customized-outputpaths/app/index.html @@ -0,0 +1,26 @@ + + +
+ + +