Skip to content

Commit

Permalink
Merge pull request #851 from ember-fastboot/fix-nm
Browse files Browse the repository at this point in the history
Fix mocha tests nested packages in node_modules not using workspaces
  • Loading branch information
xg-wang authored Aug 22, 2021
2 parents 0ef9404 + 6de4810 commit 22d628b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,9 @@ jobs:
uses: volta-cli/action@v1
with:
node-version: ${{ matrix.node-version }}

# Remove test-packages folder so that we don't leak node_modules between apps
- name: Remove test-packages
run: |
rm -rf test-packages
- name: Yarn Install
working-directory: ./packages/ember-cli-fastboot
run: |
yarn install --ignore-engines --frozen-lockfile
- name: Run Mocha Tests
run: |
npm --version
yarn workspace ember-cli-fastboot test:mocha
17 changes: 16 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}
{
"compilerOptions": {
"target": "es6",
"experimentalDecorators": true
},
"exclude": [
"node_modules",
"packages/**/node_modules",
"test-packages/**/node_modules",
"bower_components",
"tmp",
"vendor",
".git",
"dist"
]
}
46 changes: 46 additions & 0 deletions packages/ember-cli-fastboot/fix-node-modules.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* 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');
}
});
}
6 changes: 3 additions & 3 deletions packages/ember-cli-fastboot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -33,7 +33,7 @@
"broccoli-funnel": "^2.0.1",
"broccoli-merge-trees": "^3.0.1",
"broccoli-plugin": "^1.3.1",
"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",
Expand All @@ -42,7 +42,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",
"json-stable-stringify": "^1.0.1",
"md5-hex": "^2.0.0",
"recast": "^0.19.1",
Expand Down
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6372,6 +6372,14 @@ chalk@^4.1.1:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

changelog-filename-regex@^1.1.0:
version "1.1.2"
resolved "https://registry.yarnpkg.com/changelog-filename-regex/-/changelog-filename-regex-1.1.2.tgz#19e98e38248cff0c1cf3ae3bf51bfb22c48592d6"
Expand Down Expand Up @@ -10335,6 +10343,15 @@ fs-extra@^0.30.0:
path-is-absolute "^1.0.0"
rimraf "^2.2.8"

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"

fs-extra@^4.0.2, fs-extra@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
Expand Down

0 comments on commit 22d628b

Please sign in to comment.