Skip to content

Commit 8c75a4e

Browse files
committed
Fix nested packages in node_modules not using workspaces
1 parent 2a9d3d0 commit 8c75a4e

File tree

5 files changed

+78
-9
lines changed

5 files changed

+78
-9
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ jobs:
109109
uses: volta-cli/action@v1
110110
with:
111111
node-version: ${{ matrix.node-version }}
112-
113-
# Remove test-packages folder so that we don't leak node_modules between apps
114-
- name: Remove test-packages
115-
run: |
116-
rm -rf test-packages
117112
- name: Yarn Install
118-
working-directory: ./packages/ember-cli-fastboot
119113
run: |
120114
yarn install --ignore-engines --frozen-lockfile
121115
- name: Run Mocha Tests
122116
run: |
123-
npm --version
117+
node scripts/fix-node-modules.mjs
124118
yarn workspace ember-cli-fastboot test:mocha

jsconfig.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"experimentalDecorators": true
5+
},
6+
"exclude": [
7+
"node_modules",
8+
"packages/**/node_modules",
9+
"test-packages/**/node_modules",
10+
"bower_components",
11+
"tmp",
12+
"vendor",
13+
".git",
14+
"dist"
15+
]
16+
}

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test-packages/*"
1111
],
1212
"scripts": {
13+
"pretest": "node scripts/fix-node-modules.mjs",
1314
"test": "npm-run-all test:*",
1415
"test:ember-cli-fastboot": "yarn workspace ember-cli-fastboot test:ember",
1516
"test:fastboot": "yarn workspace fastboot test",
@@ -19,6 +20,9 @@
1920
"test:extra": "yarn workspace basic-app test:mocha && yarn workspace custom-fastboot-app test:mocha"
2021
},
2122
"devDependencies": {
23+
"chalk": "^4.1.2",
24+
"execa": "^5.1.1",
25+
"fs-extra": "^10.0.0",
2226
"npm-run-all": "^4.1.5",
2327
"release-it": "^14.2.2",
2428
"release-it-lerna-changelog": "^3.1.0",

scripts/fix-node-modules.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+

yarn.lock

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6372,6 +6372,14 @@ chalk@^4.1.1:
63726372
ansi-styles "^4.1.0"
63736373
supports-color "^7.1.0"
63746374

6375+
chalk@^4.1.2:
6376+
version "4.1.2"
6377+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
6378+
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
6379+
dependencies:
6380+
ansi-styles "^4.1.0"
6381+
supports-color "^7.1.0"
6382+
63756383
changelog-filename-regex@^1.1.0:
63766384
version "1.1.2"
63776385
resolved "https://registry.yarnpkg.com/changelog-filename-regex/-/changelog-filename-regex-1.1.2.tgz#19e98e38248cff0c1cf3ae3bf51bfb22c48592d6"
@@ -9642,7 +9650,7 @@ execa@^4.0.2, execa@^4.0.3:
96429650
signal-exit "^3.0.2"
96439651
strip-final-newline "^2.0.0"
96449652

9645-
execa@^5.0.0:
9653+
execa@^5.0.0, execa@^5.1.1:
96469654
version "5.1.1"
96479655
resolved "https://registry.yarnpkg.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
96489656
integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==
@@ -10335,6 +10343,15 @@ fs-extra@^0.30.0:
1033510343
path-is-absolute "^1.0.0"
1033610344
rimraf "^2.2.8"
1033710345

10346+
fs-extra@^10.0.0:
10347+
version "10.0.0"
10348+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
10349+
integrity sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==
10350+
dependencies:
10351+
graceful-fs "^4.2.0"
10352+
jsonfile "^6.0.1"
10353+
universalify "^2.0.0"
10354+
1033810355
fs-extra@^4.0.2, fs-extra@^4.0.3:
1033910356
version "4.0.3"
1034010357
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"

0 commit comments

Comments
 (0)