Skip to content

Commit

Permalink
Initial use of madge for circular dependency detection, see phetsims/…
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Feb 7, 2025
1 parent 103d8a4 commit 8969056
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .madgerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"detectiveOptions": {
"ts": {
"skipTypeImports": true
}
},
"tsConfig": "./tsconfig/tsconfig-browser.json"
}
43 changes: 43 additions & 0 deletions js/grunt/tasks/report-circular-dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2025, University of Colorado Boulder

/**
* Checks out circular dependencies within PhET repositories
*
* @author Jonathan Olson <[email protected]>
*/
import _ from 'lodash';
import { isOptionKeyProvided } from './util/getOption.js';
import getRepoList from '../../common/getRepoList.js';
import fs from 'fs';
import execute from '../../common/execute.js';

( async () => {
const isCommonOnly = isOptionKeyProvided( 'common' );

const commonRepos = getRepoList( 'active-common-sim-repos' );
const simRepos = getRepoList( 'active-sims' );
const runnableRepos = getRepoList( 'active-runnables' );

const potentialRepos = _.uniq( [
...commonRepos,

...( isCommonOnly ? [] : simRepos ),
...( isCommonOnly ? [] : runnableRepos )
] ).sort();

const repos = potentialRepos.filter( repo => {
return fs.existsSync( `../${repo}/js` );
} );

const npxCommand = process.platform.startsWith( 'win' ) ? 'npx.cmd' : 'npx';

const result = await execute( npxCommand, [ 'madge', '--warning', '--circular', ...repos.map( repo => `../${repo}/js` ) ], '.', { errors: 'resolve' } );

console.log( result.stdout );
console.log( result.stderr );

// if ( result.code !== 0 ) {
// console.error( 'madge failed - likely has circular dependencies' );
// process.exit( 1 );
// }
} )();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"html-differ": "~1.4.0",
"http-server": "^14.1.1",
"lodash": "~4.17.10",
"madge": "~8.0.0",
"mimelib": "~0.2.19",
"minimist": "~1.2.8",
"ncp": "~2.0.0",
Expand Down

0 comments on commit 8969056

Please sign in to comment.