Skip to content

Commit 8774f6e

Browse files
authored
Add a script to detect circular dependencies (#2851)
1 parent 4a265e5 commit 8774f6e

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

packages/@react-aria/ssr/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"url": "https://github.com/adobe/react-spectrum"
1818
},
1919
"dependencies": {
20-
"@babel/runtime": "^7.6.2",
21-
"@react-aria/utils": "^3.10.0"
20+
"@babel/runtime": "^7.6.2"
2221
},
2322
"peerDependencies": {
2423
"react": "^16.8.0 || ^17.0.0-rc.1"

packages/@react-aria/ssr/src/SSRProvider.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import React, {ReactNode, useContext, useMemo, useState} from 'react';
14-
import {useLayoutEffect} from '@react-aria/utils';
13+
// We must avoid a circular dependency with @react-aria/utils, and this useLayoutEffect is
14+
// guarded by a check that it only runs on the client side.
15+
// eslint-disable-next-line rulesdir/useLayoutEffectRule
16+
import React, {ReactNode, useContext, useLayoutEffect, useMemo, useState} from 'react';
1517

1618
// To support SSR, the auto incrementing id counter is stored in a context. This allows
1719
// it to be reset on every request to ensure the client and server are consistent.

scripts/findCircularDeps.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const exec = require('child_process').execSync;
2+
3+
let output = exec('yarn workspaces info --json').toString().replace(/^(.|\n)*?\{/, '{').replace(/\}\nDone in .*\n?$/, '}');
4+
let workspaces = JSON.parse(output);
5+
6+
for (let pkg in workspaces) {
7+
addDep(pkg);
8+
}
9+
10+
function addDep(dep, seen = new Set()) {
11+
if (seen.has(dep)) {
12+
let arr = [...seen];
13+
let index = arr.indexOf(dep);
14+
console.log(`Circular dependency detected: ${arr.slice(index).join(' -> ')} -> ${dep}`);
15+
process.exit(1);
16+
}
17+
18+
seen.add(dep);
19+
20+
for (let d of workspaces[dep].workspaceDependencies) {
21+
addDep(d, seen);
22+
}
23+
24+
seen.delete(dep);
25+
}

scripts/lint-packages.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,4 @@ if (errors) {
138138
}
139139

140140
require('./checkPublishedDependencies');
141+
require('./findCircularDeps');

0 commit comments

Comments
 (0)