Repository: pahen/madge Branch: master Commit: 456057b85c2d Files: 135 Total size: 102.6 KB Directory structure: gitextract_7o211m2x/ ├── .editorconfig ├── .eslintrc ├── .github/ │ └── workflows/ │ └── nodejs.yml ├── .gitignore ├── .nvmrc ├── .release-it.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin/ │ └── cli.js ├── lib/ │ ├── api.js │ ├── cyclic.js │ ├── graph.js │ ├── log.js │ ├── output.js │ └── tree.js ├── package.json └── test/ ├── amd/ │ ├── amdes6.js │ ├── circular/ │ │ ├── a.js │ │ ├── b.js │ │ ├── c.js │ │ ├── d.js │ │ ├── e.js │ │ ├── f.js │ │ ├── g.js │ │ ├── h.js │ │ └── main.js │ ├── circularAlias/ │ │ ├── config.js │ │ ├── dos.js │ │ └── x86.js │ ├── circularRelative/ │ │ ├── a.js │ │ └── foo/ │ │ └── b.js │ ├── nested/ │ │ ├── a.js │ │ ├── b.js │ │ └── main.js │ ├── ok/ │ │ ├── a.js │ │ ├── d.js │ │ ├── e.js │ │ └── sub/ │ │ ├── b.js │ │ └── c.js │ ├── plugin.js │ └── requirejs/ │ ├── a.js │ ├── config.js │ ├── orphans/ │ │ ├── a.js │ │ ├── b.js │ │ └── c.js │ └── vendor/ │ ├── baz.js │ ├── jquery-2.0.3.js │ ├── jquery.bar-1.0.js │ ├── jquery.foo-1.0.js │ └── quux.js ├── amd.js ├── api.js ├── cjs/ │ ├── a.js │ ├── b.js │ ├── both.js │ ├── c.js │ ├── chained.js │ ├── circular/ │ │ ├── a.js │ │ ├── b.js │ │ ├── c.js │ │ ├── d.js │ │ ├── foo.js │ │ └── foo.json │ ├── core.js │ ├── error.js │ ├── missing.js │ ├── multibase/ │ │ ├── 1/ │ │ │ └── a.js │ │ └── 2/ │ │ └── b.js │ ├── nested.js │ ├── normal/ │ │ ├── a.js │ │ ├── d.js │ │ └── sub/ │ │ ├── b.js │ │ └── c.js │ ├── npm.js │ ├── strings.js │ └── word.js ├── cjs.js ├── es6/ │ ├── absolute/ │ │ ├── a.js │ │ └── b.js │ ├── absolute.js │ ├── circular/ │ │ ├── a.js │ │ ├── b.js │ │ └── c.js │ ├── error.js │ ├── re-export/ │ │ ├── a.js │ │ ├── b-default.js │ │ ├── b-named.js │ │ ├── b-star.js │ │ └── c.js │ └── webpack/ │ ├── src/ │ │ └── sub/ │ │ ├── abs.js │ │ ├── index.js │ │ └── rel.js │ └── webpack.config.js ├── es6.js ├── es7/ │ ├── async.js │ └── other.js ├── es7.js ├── flow/ │ ├── cjs/ │ │ ├── calc.js │ │ ├── geometry.js │ │ └── math.js │ └── es/ │ ├── calc.js │ └── math.js ├── flow.js ├── git/ │ ├── .git_tmp/ │ │ └── d.js │ ├── a.js │ ├── b.js │ └── c.js ├── jsx/ │ ├── basic.jsx │ └── other.jsx ├── jsx.js ├── output.sh ├── typescript/ │ ├── custom-paths/ │ │ ├── import.ts │ │ ├── subfolder/ │ │ │ ├── index.ts │ │ │ └── require.tsx │ │ └── subfolder2/ │ │ └── export.ts │ ├── export-x.tsx │ ├── export.ts │ ├── import.ts │ ├── mixed.ts │ ├── require-x.tsx │ ├── require.ts │ └── with-config/ │ ├── index.ts │ ├── tsconfig.base.json │ └── tsconfig.json ├── typescript.js ├── vue/ │ ├── BasicComponent.vue │ ├── BasicComponentTs.vue │ ├── OneNested.vue │ ├── OneNestedTs.vue │ ├── ThreeNested.vue │ ├── TwoNested.vue │ ├── one.ts │ └── two.js └── vue.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ ; http://editorconfig.org root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,.travis.yml,.github/**/*.yml}] indent_style = space indent_size = 2 ================================================ FILE: .eslintrc ================================================ { "extends": "@aptoma/eslint-config", "parserOptions": { "ecmaVersion": 9 }, "env": { "node": true, "mocha": true, "es6": true } } ================================================ FILE: .github/workflows/nodejs.yml ================================================ name: ci on: [pull_request] jobs: build: strategy: matrix: os: [ubuntu-latest] node-version: [18.x, 20.x] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: ${{ matrix.os }} / Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - name: npm install, build, and test run: | sudo apt install -y --no-install-recommends graphviz npm i -g npm@9 npm ci npm run test npm run debug npm run generate ================================================ FILE: .gitignore ================================================ /node_modules .DS_Store .vscode .madgerc *.sublime-project *.sublime-workspace .idea ================================================ FILE: .nvmrc ================================================ 20 ================================================ FILE: .release-it.json ================================================ { "pkgFiles": ["package.json", "package-lock.json"], "git": { "requireCleanWorkingDir": false }, "hooks": { "after:bump": "auto-changelog --hide-credit --package" } } ================================================ FILE: CHANGELOG.md ================================================ ### Changelog All notable changes to this project will be documented in this file. Dates are displayed in UTC. #### [v8.0.0](https://github.com/pahen/madge/compare/v7.0.0...v8.0.0) - chore: edit test/output.sh comply with POSIX [`#391`](https://github.com/pahen/madge/pull/391) - Update ts-graphviz@2.1.2 and typescript@5.4.4 [`#424`](https://github.com/pahen/madge/pull/424) - Remove not required dep on precinct [`#421`](https://github.com/pahen/madge/pull/421) - Cleanup README and remove Travis config [`#422`](https://github.com/pahen/madge/pull/422) - Correct engine requirements [`#419`](https://github.com/pahen/madge/pull/419) - Add tests for Vue [`#418`](https://github.com/pahen/madge/pull/418) - Update to dependency-tree@11 [`#417`](https://github.com/pahen/madge/pull/417) - Add empty TS config to fix the tests [`0163dc4`](https://github.com/pahen/madge/commit/0163dc469b3a52af423540ea75301d2f6e01b018) - Add comment [`3a52fae`](https://github.com/pahen/madge/commit/3a52fae6cf4ad3018c3a8c43be4e361cbf4679ec) - Remove integrated npm cache [`e25fa64`](https://github.com/pahen/madge/commit/e25fa6440631af238edafe02706f3a4616862ffa) ### [v7.0.0](https://github.com/pahen/madge/compare/v6.1.0...v7.0.0) > 8 April 2024 - devDeps: release-it@^15.6.0->^16.2.1 [`#393`](https://github.com/pahen/madge/pull/393) - ci: Run build & test scripts on GitHub Actions [`#394`](https://github.com/pahen/madge/pull/394) - chore: bump and align dependencies; dedupe typescript [`#379`](https://github.com/pahen/madge/pull/379) - Adding option to not print the circular file count [`#387`](https://github.com/pahen/madge/pull/387) - Update README, explaining to how ignore typed imports on .tsx files [`#389`](https://github.com/pahen/madge/pull/389) - docs: update README to include ignore dynamic imports FAQ [`#360`](https://github.com/pahen/madge/pull/360) - docs: fix donate anchor [`#362`](https://github.com/pahen/madge/pull/362) - Release 6.1.0 [`#378`](https://github.com/pahen/madge/pull/378) - chore: check in package-lock.json [`2137846`](https://github.com/pahen/madge/commit/2137846544697e3cdad9fb9d3599875f241dcb3d) - devDeps: release-it@^16.1.5->^16.2.1 [`1bcdc12`](https://github.com/pahen/madge/commit/1bcdc12093131b0a92fc9dc76a701cfccdf03867) - ci: add build/test workflow for GitHub Actions [`fa34634`](https://github.com/pahen/madge/commit/fa34634e06116572d606e6035f7402a7d276ab6e) #### [v6.1.0](https://github.com/pahen/madge/compare/v6.0.0...v6.1.0) > 4 June 2023 - constrain and bump typescript versions [`#376`](https://github.com/pahen/madge/pull/376) - Disable spinner when running in CI [`#356`](https://github.com/pahen/madge/pull/356) - Remove deploy to NPM from Travis build [`#354`](https://github.com/pahen/madge/pull/354) - feat: support for rankdir in CLI [`#311`](https://github.com/pahen/madge/pull/311) - Move typescript to peer dependencies [`#350`](https://github.com/pahen/madge/pull/350) - Release 6.0.0 [`#352`](https://github.com/pahen/madge/pull/352) - Release 6.1.0 [`66bb0c3`](https://github.com/pahen/madge/commit/66bb0c30798b31557d239ca61b2a43ffa6f53fba) - install and use ci-info [`c35da47`](https://github.com/pahen/madge/commit/c35da472e7352340209f4537d020b2702f9e67e7) - remove ci-info and change isEnabled setting [`a771115`](https://github.com/pahen/madge/commit/a771115ce570c8ea8d4c3ca68300dcfa0b5759ea) ### [v6.0.0](https://github.com/pahen/madge/compare/v5.0.2...v6.0.0) > 29 January 2023 - Handle collect tsconfig's extends fileds [`#349`](https://github.com/pahen/madge/pull/349) - Update packages detective-* to latest [`#348`](https://github.com/pahen/madge/pull/348) - chore: bump 'detective-typescript' package to allow newer TS versions [`#321`](https://github.com/pahen/madge/pull/321) - Replace to ts-graphviz package [`#341`](https://github.com/pahen/madge/pull/341) - chore: bump detective-postcss to v6 [`#319`](https://github.com/pahen/madge/pull/319) - Drop support Node.js EOL versions(<14) [`#342`](https://github.com/pahen/madge/pull/342) - handle collect tsconfig's extends fileds [`#323`](https://github.com/pahen/madge/issues/323) - Changed to depend on the ts-graphviz package [`9b9ae87`](https://github.com/pahen/madge/commit/9b9ae878622be4a58951c5fcb9d46cc0c44e4593) - Release 6.0.0 [`2aa75b2`](https://github.com/pahen/madge/commit/2aa75b2aba279d02dd7cf7640a0fcd6236322228) - update packages detective-* to latest [`60b6557`](https://github.com/pahen/madge/commit/60b6557efc5a1da04452dfc0f0b1a0281f9c8776) #### [v5.0.2](https://github.com/pahen/madge/compare/v5.0.1...v5.0.2) > 27 January 2023 - Add NPM task and docs for creating a release [`#346`](https://github.com/pahen/madge/pull/346) - Fix broken link to Travis in README [`#345`](https://github.com/pahen/madge/pull/345) - docs: fix subtrees typo in README [`#325`](https://github.com/pahen/madge/pull/325) - minor typo in README.md [`#300`](https://github.com/pahen/madge/pull/300) - Release 5.0.2 [`614d44d`](https://github.com/pahen/madge/commit/614d44d5f1ab3cc9e9875e67d1e46f4b971d660a) - minor typos in README.md [`edc27c8`](https://github.com/pahen/madge/commit/edc27c85c5257df65184fd44c80549ffd0346360) - minor type in README.md [`9f5514c`](https://github.com/pahen/madge/commit/9f5514c568aa1d3944a17c459daee93c2948e144) #### [v5.0.1](https://github.com/pahen/madge/compare/v5.0.0...v5.0.1) > 23 June 2021 - Fix issue with command line options stopped working [`512c2cb`](https://github.com/pahen/madge/commit/512c2cbfec1db53068e9b805e181ec1b38d30a41) - Update README [`8e98136`](https://github.com/pahen/madge/commit/8e98136c5597f87acfa93cdae18c477cbf8a30da) ### [v5.0.0](https://github.com/pahen/madge/compare/v4.0.2...v5.0.0) > 22 June 2021 - Improve Graphviz support detection [`#274`](https://github.com/pahen/madge/pull/274) - Update list of donations [`aa49a0a`](https://github.com/pahen/madge/commit/aa49a0a94fd966be25141c92c75f97d90ad73dc6) - Update deps [`820c9b8`](https://github.com/pahen/madge/commit/820c9b827b3ec1c51e454b0ce7ea6f2427f3b6da) #### [v4.0.2](https://github.com/pahen/madge/compare/v4.0.1...v4.0.2) > 8 March 2021 - Bump detective-typescript [`e6985d2`](https://github.com/pahen/madge/commit/e6985d25518ea48f816ee007d0bde519ce6a3106) #### [v4.0.1](https://github.com/pahen/madge/compare/v4.0.0...v4.0.1) > 5 March 2021 - Fix potential command injection vulnerability [`da5cbc9`](https://github.com/pahen/madge/commit/da5cbc9ab30372d687fa7c324b22af7ffa5c6332) ### [v4.0.0](https://github.com/pahen/madge/compare/v3.12.0...v4.0.0) > 5 January 2021 - Upgrade dependencies & raise minimum Node.js version [`#269`](https://github.com/pahen/madge/pull/269) - Upgrade core dependencies [`fe8a186`](https://github.com/pahen/madge/commit/fe8a186b18a08a6e6f69d49d95f156660f575851) - Upgrade commander to version 6 [`5ca410c`](https://github.com/pahen/madge/commit/5ca410c4b4332c67a3104b7e851d0976be78de9e) - Require Node.js 10.13 [`eee3dc0`](https://github.com/pahen/madge/commit/eee3dc0540ce3592fbbbada8586cf5b59e5ba33d) #### [v3.12.0](https://github.com/pahen/madge/compare/v3.11.0...v3.12.0) > 2 November 2020 - Remove pify again [`#264`](https://github.com/pahen/madge/pull/264) - Update ora to version 5 [`#262`](https://github.com/pahen/madge/pull/262) - Replace pify with util.promisify [`#263`](https://github.com/pahen/madge/pull/263) - Update README [`e4be868`](https://github.com/pahen/madge/commit/e4be868c6c057be3799d8b8fd0c9fa928bbc9b80) - Bump dependency-tree to 7.2.2 [`0eaccb7`](https://github.com/pahen/madge/commit/0eaccb728dbdcf36e67850fc89a552361c69a200) #### [v3.11.0](https://github.com/pahen/madge/compare/v3.10.0...v3.11.0) > 1 October 2020 - Add support for combining --circular and --dot [`d2ce3f7`](https://github.com/pahen/madge/commit/d2ce3f7ac0dec928eaee37ab8d768d291fa24f84) #### [v3.10.0](https://github.com/pahen/madge/compare/v3.9.2...v3.10.0) > 14 September 2020 - Add support for combining --image and --circular [`7a4bd3b`](https://github.com/pahen/madge/commit/7a4bd3be2fbefab3e9468272c912991602360562) #### [v3.9.2](https://github.com/pahen/madge/compare/v3.9.1...v3.9.2) > 16 June 2020 - Bump dependencies [`a8e3674`](https://github.com/pahen/madge/commit/a8e367464f5a4bc1586c4a21735691253406ddb4) - Downgrade to ESLint 6.8.0 [`bc539af`](https://github.com/pahen/madge/commit/bc539afcda79291b5f694c0b8ab8423356f0d53e) #### [v3.9.1](https://github.com/pahen/madge/compare/v3.9.0...v3.9.1) > 8 June 2020 - chore: significant speedup by skipping filing-cabinet ts-config parsing [`#237`](https://github.com/pahen/madge/pull/237) - Clarification for mixed projects (with JS and TS) [`#246`](https://github.com/pahen/madge/pull/246) #### [v3.9.0](https://github.com/pahen/madge/compare/v3.8.0...v3.9.0) > 7 May 2020 - Remove info about Patreon and Open Collective [`a57eeff`](https://github.com/pahen/madge/commit/a57eeffd27efdf18dbd3d5f941bb23a1aab18f48) - Update list of backers [`545be08`](https://github.com/pahen/madge/commit/545be086dec854fd46024cf6a1f6df2c9d710d5e) - Update dependencies [`ffa4fdd`](https://github.com/pahen/madge/commit/ffa4fdd64695b22002adaf2add100f1a3da028bc) #### [v3.8.0](https://github.com/pahen/madge/compare/v3.7.0...v3.8.0) > 9 March 2020 - Add `leaves` option to show modules that do not have dependencies [`97ed27f`](https://github.com/pahen/madge/commit/97ed27f846f3e53dc127c577e6667f5faf6a814b) - Update README [`9c1f7d2`](https://github.com/pahen/madge/commit/9c1f7d2d9a23b42582caebd529cf73753a3226cc) - Updated list of donations [`899f15f`](https://github.com/pahen/madge/commit/899f15f1d4b7673d0a7f35b74ae171517eaad5a9) #### [v3.7.0](https://github.com/pahen/madge/compare/v3.6.0...v3.7.0) > 30 January 2020 - feat: support package.json config [`#236`](https://github.com/pahen/madge/pull/236) - review [`0acebb7`](https://github.com/pahen/madge/commit/0acebb7417ea17a0980630685ee4dfe182fbcdbb) - Drop Node.js 8 support [`2cba3e1`](https://github.com/pahen/madge/commit/2cba3e1a93e45b74cf680119e3affffc0feaa695) - Drop Node.JS 6 support [`ca3c555`](https://github.com/pahen/madge/commit/ca3c5553e72457d7f96fefa828ef03f6a1cbe0b8) #### [v3.6.0](https://github.com/pahen/madge/compare/v3.5.1...v3.6.0) > 11 November 2019 - Add test for TypeScript with mixed import syntax [`50c1c10`](https://github.com/pahen/madge/commit/50c1c10c1e7d369c5e7d1017463451f8d270cdf9) - Update deps [`f1125d0`](https://github.com/pahen/madge/commit/f1125d0af5da27510f709a4b8a2e84b45ff5f578) #### [v3.5.1](https://github.com/pahen/madge/compare/v3.5.0...v3.5.1) > 7 November 2019 - Add funding to package.json [`8ee9126`](https://github.com/pahen/madge/commit/8ee91265973985eee08b873eff0e5104d48d4f61) #### [v3.5.0](https://github.com/pahen/madge/compare/v3.4.4...v3.5.0) > 28 October 2019 - Add an .svg public method to the API [`#171`](https://github.com/pahen/madge/pull/171) - Respect graphVizOptions in DOT output [`4edf82a`](https://github.com/pahen/madge/commit/4edf82a3578639972229034aed4ebe1d51ae2bdf) - Added credits to README [`9287c3c`](https://github.com/pahen/madge/commit/9287c3c1f1f51ffdb6c27a890c51f32f383b9c5c) - Add .svg() in API to export the svg as a Buffer [`d01f6f3`](https://github.com/pahen/madge/commit/d01f6f33a67ecfb7072667b08f6c6550d52a5043) #### [v3.4.4](https://github.com/pahen/madge/compare/v3.4.3...v3.4.4) > 12 February 2019 - [Fixes #203] Exclude test folder from npm registry [`#205`](https://github.com/pahen/madge/pull/205) - Merge pull request #205 from SethDavenport/chore(exclude-test-folder-from-npm) [`#203`](https://github.com/pahen/madge/issues/203) - Add NPM releasing from Travis [`97f060b`](https://github.com/pahen/madge/commit/97f060b1b0f19c6d08b0fc53c24494df7fdd6cdc) - Exclude test folder from npm registry [`41f94f2`](https://github.com/pahen/madge/commit/41f94f22f5521bde0523ec7df17fbdf43e587e33) #### [v3.4.3](https://github.com/pahen/madge/compare/v3.4.2...v3.4.3) > 17 January 2019 - Add link to my Patreon page in README [`9ee722a`](https://github.com/pahen/madge/commit/9ee722a8d4708f978042c17ffc172409470dfa86) - Add info about --orphans to CLI docs [`925c57e`](https://github.com/pahen/madge/commit/925c57efcbe2357f49131e51050107e9ad54eab1) - Bump dependency-tree [`c2ce2ac`](https://github.com/pahen/madge/commit/c2ce2ac17888c71aa020ac7da5277535ffaacdac) #### [v3.4.2](https://github.com/pahen/madge/compare/v3.4.1...v3.4.2) > 10 January 2019 - Eslint should not be a dev dependency [`3165988`](https://github.com/pahen/madge/commit/316598895e64bbca42654ae263422dba0d365772) #### [v3.4.1](https://github.com/pahen/madge/compare/v3.4.0...v3.4.1) > 10 January 2019 - Update eslint (peer dependency for typescript-eslint-parser) [`2e6643a`](https://github.com/pahen/madge/commit/2e6643af90b70cc055e37725942a2177f3e05bdd) #### [v3.4.0](https://github.com/pahen/madge/compare/v3.3.0...v3.4.0) > 7 January 2019 - Support .tsx files and specifying a tsconfig [`#193`](https://github.com/pahen/madge/pull/193) - README: improve instructions related to Graphviz [`#183`](https://github.com/pahen/madge/pull/183) #### [v3.3.0](https://github.com/pahen/madge/compare/v3.2.0...v3.3.0) > 31 October 2018 - Update dependencies & test on Node.js 10 [`#176`](https://github.com/pahen/madge/pull/176) - Add --no-spinner option [`b1ad3eb`](https://github.com/pahen/madge/commit/b1ad3eb5d878e31f1f87d99f6b3de713003079c1) - Update dependencies [`9b1293e`](https://github.com/pahen/madge/commit/9b1293e4f7c990efd1e58cd9f069bdd3a6b36fb7) - Update dev dependencies [`2260b61`](https://github.com/pahen/madge/commit/2260b613ecddb6f623584b82b1a30542b01c90e7) #### [v3.2.0](https://github.com/pahen/madge/compare/v3.1.1...v3.2.0) > 26 June 2018 - Plot nodes as boxes [`#165`](https://github.com/pahen/madge/pull/165) - Document new graph settings [`c6e742f`](https://github.com/pahen/madge/commit/c6e742f97a065a452445702645ec06c1ea91ea07) - aesthetic changes: plot rounded boxes, prefer left to right. [`7a7ed8c`](https://github.com/pahen/madge/commit/7a7ed8c2f9f4f189d0ba1372d30b06fef7e50cc4) - fix incorrect hex. 5 -> 6 digits. [`e8e330c`](https://github.com/pahen/madge/commit/e8e330c9f5b70c3d925ec1674c7d62253750196e) #### [v3.1.1](https://github.com/pahen/madge/compare/v3.1.0...v3.1.1) > 24 May 2018 #### [v3.1.0](https://github.com/pahen/madge/compare/v3.0.1...v3.1.0) > 22 May 2018 - Bind all dependencies to latest version [`#161`](https://github.com/pahen/madge/pull/161) - Update ora to version 2 [`#155`](https://github.com/pahen/madge/pull/155) - Remove mz as a production dependency. Instead use pify for promisifying. [`#154`](https://github.com/pahen/madge/pull/154) - Remove package-lock.json [`8fd1859`](https://github.com/pahen/madge/commit/8fd18595a9b8bf28f67c01795b3ed182eb2d4b8d) - Bind all dependencies to latest version, It fixes security issue in rc => deep-extend library. And added .idea project files to gitignore [`147d431`](https://github.com/pahen/madge/commit/147d431e506dac03230fedb2cf12be5a11e79c7d) - Use caret ranges for all dependencies [`b0e334a`](https://github.com/pahen/madge/commit/b0e334ac22059edcf3bee059ba075cd1b12da985) #### [v3.0.1](https://github.com/pahen/madge/compare/v3.0.0...v3.0.1) > 5 February 2018 - Fix broken link [`#149`](https://github.com/pahen/madge/pull/149) - Update deps [`3ba103c`](https://github.com/pahen/madge/commit/3ba103c8afa978b9163e9958d3197b294f9a93ce) - Fix issue with short CLI options not working properly [`f73704d`](https://github.com/pahen/madge/commit/f73704dc3bd88fbc6308f1799319825d10251505) ### [v3.0.0](https://github.com/pahen/madge/compare/v2.2.0...v3.0.0) > 22 January 2018 - chore: upgrade dependency-tree to 6.0.0 to address warning [`#147`](https://github.com/pahen/madge/pull/147) - Update dev-dependencies [`#144`](https://github.com/pahen/madge/pull/144) - Use caret ranges for all dependencies [`#141`](https://github.com/pahen/madge/pull/141) - Update chalk to 2.3.0 [`#140`](https://github.com/pahen/madge/pull/140) - Updates dependencies (not dev-dependencies) [`#134`](https://github.com/pahen/madge/pull/134) - deps: Update debug to fix security issue [`#130`](https://github.com/pahen/madge/pull/130) - Regenerate package-lock.json [`5d26187`](https://github.com/pahen/madge/commit/5d261874f7471cf66898205b83c967401c050fd3) - dependency-tree@5.11.1 [`c35174c`](https://github.com/pahen/madge/commit/c35174c39c58ed7a5cf4e9560c1d16407870c4ea) - Updat eslint to 4.13.0 and @aptoma/eslint-config to 7.0.1. [`b184021`](https://github.com/pahen/madge/commit/b184021cf758eeffad2eb7f590e218c463e191dc) #### [v2.2.0](https://github.com/pahen/madge/compare/v2.1.0...v2.2.0) > 29 August 2017 #### [v2.1.0](https://github.com/pahen/madge/compare/v2.0.0...v2.1.0) > 26 August 2017 - Support for TypeScript [`#124`](https://github.com/pahen/madge/pull/124) - Add tests for TypeScript [`50eb3ca`](https://github.com/pahen/madge/commit/50eb3ca5a884ce7cf23118755b8ed13f2ccf01a1) - Center badges in README [`5b981cd`](https://github.com/pahen/madge/commit/5b981cd637787241e119587207ef09a878650136) - Create LICENSE [`741cd76`](https://github.com/pahen/madge/commit/741cd761d4d0358022fee20ad3312f5230708603) ### [v2.0.0](https://github.com/pahen/madge/compare/v1.6.0...v2.0.0) > 15 July 2017 - Add —-orphans to show modules that no one is depending on [`#121`](https://github.com/pahen/madge/pull/121) - Fix typo [`#119`](https://github.com/pahen/madge/pull/119) - fix typo in `.image()` example [`#113`](https://github.com/pahen/madge/pull/113) - Always include file extension [`b6cac48`](https://github.com/pahen/madge/commit/b6cac48c9162736a40e1f6b7aa9dd3a8d225d6da) - Fix bug with --extensions not working [`fc4acce`](https://github.com/pahen/madge/commit/fc4acce1517514dc7e34e7a6fb569e83047251b4) - Support for Less [`d2d4b96`](https://github.com/pahen/madge/commit/d2d4b96cd160b4bea3d24b8399100a0030158feb) #### [v1.6.0](https://github.com/pahen/madge/compare/v1.5.0...v1.6.0) > 8 February 2017 - Show CLI spinner with the currently processed file [`f57480a`](https://github.com/pahen/madge/commit/f57480aaaa4e70e9d9afcab78f425ee0ee6f5754) - Add support for dependencyFilter function [`eac8591`](https://github.com/pahen/madge/commit/eac85914a69e8359aca3dd737ff1d6026419f79b) - Add script for testing output [`e74df55`](https://github.com/pahen/madge/commit/e74df55c6a5d1f16eda3ef708b1f43bddb7a25d9) #### [v1.5.0](https://github.com/pahen/madge/compare/v1.4.6...v1.5.0) > 13 January 2017 - Tweak output colors and error messages [`60d59a6`](https://github.com/pahen/madge/commit/60d59a664dda42d98a4cd7f772afb9acbb38da70) - Support running —circular with —-warning [`b8a0371`](https://github.com/pahen/madge/commit/b8a0371c2695dbd4afbade785b87e9be42182ca7) - Update changelog [`fa7cc99`](https://github.com/pahen/madge/commit/fa7cc99a09cf4e1af9f9a6664dd57eda1f862fa0) #### [v1.4.6](https://github.com/pahen/madge/compare/v1.4.5...v1.4.6) > 9 January 2017 - Update circular dependency check output [`4ec6322`](https://github.com/pahen/madge/commit/4ec6322ec50b5e8bdd16fc0a697fd0f68e803ba7) - Update changelog [`d718612`](https://github.com/pahen/madge/commit/d718612b0d00e3bf382a8042ce97aa76fa232de4) - Bump dependency-tree [`3bc9689`](https://github.com/pahen/madge/commit/3bc9689c903b2431e0dee3e6796fa23b3bd7886f) #### [v1.4.5](https://github.com/pahen/madge/compare/v1.4.4...v1.4.5) > 7 January 2017 - Keep file extension in module paths until we output the graph [`bd980cf`](https://github.com/pahen/madge/commit/bd980cfdbafa1952607df442ca771e68d58a4757) - Update changelog [`0492763`](https://github.com/pahen/madge/commit/04927633ce7223980dbbc4818e6e1fbb533737b3) #### [v1.4.4](https://github.com/pahen/madge/compare/v1.4.3...v1.4.4) > 4 January 2017 - Add tests for resolving using webpack resolve.root [`8452575`](https://github.com/pahen/madge/commit/8452575bb2ea567593ef1488e6148f96f82acd26) - Update changelog [`13648c7`](https://github.com/pahen/madge/commit/13648c709886dfaf8bff1bd4fa24624d12d769ba) - Bump dependencies [`c9b1795`](https://github.com/pahen/madge/commit/c9b17951afd7e9caeaa00cd5b61d4ebdd262a937) #### [v1.4.3](https://github.com/pahen/madge/compare/v1.4.2...v1.4.3) > 12 October 2016 - Fix bug with CLI —-require-config and --webpack-config not working [`386d710`](https://github.com/pahen/madge/commit/386d71055e263f04cc05779ebd259979c1415b7b) - Update changelog [`cc4cb9e`](https://github.com/pahen/madge/commit/cc4cb9ea38f60341b1a57996a52036da1626f9a2) - Update changelog [`97ba4c2`](https://github.com/pahen/madge/commit/97ba4c2cb78568766593fabbe89eec738ea4f65d) #### [v1.4.2](https://github.com/pahen/madge/compare/v1.4.1...v1.4.2) > 6 October 2016 - Rename —-show-skipped to —-warning [`a2d7c99`](https://github.com/pahen/madge/commit/a2d7c99d9b8e8c04e982a9505e1c95f682f22dc4) #### [v1.4.1](https://github.com/pahen/madge/compare/v1.4.0...v1.4.1) > 6 October 2016 - Don’t show warnings about skipped files by default [`2cfa8d7`](https://github.com/pahen/madge/commit/2cfa8d74d7fad3d85225523515a9c36addbe0b3a) #### [v1.4.0](https://github.com/pahen/madge/compare/v1.3.2...v1.4.0) > 6 October 2016 - Show skipped files as warnings (disable with —-no-warning) [`#108`](https://github.com/pahen/madge/pull/108) - Update changelog [`4cb2c4c`](https://github.com/pahen/madge/commit/4cb2c4c806cfe87db8dabbc32920ac8f539e3dcc) #### [v1.3.2](https://github.com/pahen/madge/compare/v1.3.1...v1.3.2) > 3 October 2016 - Bump dependency-tree [`6fb76b2`](https://github.com/pahen/madge/commit/6fb76b2fe29a760b4652edf60724880f10518dda) #### [v1.3.1](https://github.com/pahen/madge/compare/v1.3.0...v1.3.1) > 1 October 2016 - Allow to pass options to detectives [`#105`](https://github.com/pahen/madge/pull/105) - Bump dependency-tree to 5.7.0 [`d5c5de2`](https://github.com/pahen/madge/commit/d5c5de26c1c12f716d58fb0a780094ea939ed954) #### [v1.3.0](https://github.com/pahen/madge/compare/v1.2.0...v1.3.0) > 6 September 2016 - Improve performance on large codebase [`#104`](https://github.com/pahen/madge/pull/104) - Cache paths when converting tree for better performance [`fc67d00`](https://github.com/pahen/madge/commit/fc67d0060d3050357f161cf5a86973a53b82910c) - Rename commonjs to cjs [`8c56037`](https://github.com/pahen/madge/commit/8c56037570f53ed0c0560fcff391efe05227dc1b) - Remove unnecessary mapping of CLI args to config [`93f19da`](https://github.com/pahen/madge/commit/93f19da023ff3ddfd52b89854272555640b3104e) #### [v1.2.0](https://github.com/pahen/madge/compare/v1.1.0...v1.2.0) > 1 September 2016 - Add option —-stdin for piping predefined tree [`#103`](https://github.com/pahen/madge/pull/103) - Cleanup in tests [`75dce71`](https://github.com/pahen/madge/commit/75dce7194059337163632f284e78c6e4dd795883) - Add missing test file [`1ce0c01`](https://github.com/pahen/madge/commit/1ce0c015269b56f32994621226753579ddac2c64) #### [v1.1.0](https://github.com/pahen/madge/compare/v1.0.0...v1.1.0) > 23 August 2016 - Fix failing tests on Windows [`#98`](https://github.com/pahen/madge/pull/98) - Support for setting custom GraphViz options. Fixes #94 [`#94`](https://github.com/pahen/madge/issues/94) - Replace parsers with dependency-tree module [`4be7db2`](https://github.com/pahen/madge/commit/4be7db2f096c6695ac1b8eacfd0095c5fa7ac7fb) - Use promises in API [`dbad4b6`](https://github.com/pahen/madge/commit/dbad4b6ba89a05168be8eb702340f9887e1bf46a) - Move tree generation to tree.js and add support folders [`07a36ed`](https://github.com/pahen/madge/commit/07a36edb65d84a84096ef3bb7228f4b9448df37d) ### [v1.0.0](https://github.com/pahen/madge/compare/0.6.0...v1.0.0) > 19 August 2016 - Version 1.0 [`#96`](https://github.com/pahen/madge/pull/96) #### [0.6.0](https://github.com/pahen/madge/compare/0.5.5...0.6.0) > 6 July 2016 - Convert classes to ES6. [`8134400`](https://github.com/pahen/madge/commit/8134400915e1e6bef99fc3bceb5c790e7aa2caa7) - Convert tests to ES6. [`4a9797e`](https://github.com/pahen/madge/commit/4a9797eac699df69e86d36a12ae92beb28836395) - Use ES6 internally. [`6a0e2ca`](https://github.com/pahen/madge/commit/6a0e2ca5838ceb509ba3330fa4031ea1a6f7f7e5) #### [0.5.5](https://github.com/pahen/madge/compare/0.5.4...0.5.5) > 3 July 2016 - Fix matching absolute path [`#80`](https://github.com/pahen/madge/pull/80) - Support for es6 re-export syntax [`#91`](https://github.com/pahen/madge/pull/91) - AMD: Support files with embedded es6 [`#90`](https://github.com/pahen/madge/pull/90) - Improve readme circular return object [`#85`](https://github.com/pahen/madge/pull/85) - AMD: Support files with embedded es6 (#90) [`#84`](https://github.com/pahen/madge/issues/84) - Update code to pass ESLint rules. [`e0866d5`](https://github.com/pahen/madge/commit/e0866d56e6b7dc7112f71616ac22dc7c0d954ea2) - Remove react-tools since detective-es6 handles it now. [`b16f946`](https://github.com/pahen/madge/commit/b16f94625846436859ef7a5a5f68545305db509e) - Move RequireJS specific code into amd.js [`374d14c`](https://github.com/pahen/madge/commit/374d14c1742a1feba2e6fb7805ab1d510b78d661) #### [0.5.4](https://github.com/pahen/madge/compare/0.5.3...0.5.4) > 13 June 2016 - Bump detective-es6 for JSX and ES7 support [`#83`](https://github.com/pahen/madge/pull/83) - Don't use sudo to install the package [`#76`](https://github.com/pahen/madge/pull/76) - Correct CLI API for mainRequireModule [`#72`](https://github.com/pahen/madge/pull/72) - Bump detective-es6 for JSX and ES7 support [`#81`](https://github.com/pahen/madge/issues/81) [`#61`](https://github.com/pahen/madge/issues/61) - Update status icons in README. [`61429de`](https://github.com/pahen/madge/commit/61429ded932c32426b20c86552ff5096d715d726) - Update releasenotes. [`bf0e987`](https://github.com/pahen/madge/commit/bf0e987b7da6d2d84e142a3cbb5388e7a2e0659c) - Bump to version 0.5.4 [`38c40ac`](https://github.com/pahen/madge/commit/38c40ac17d653103187bcc1c5e2512aa3c5b0c4c) #### [0.5.3](https://github.com/pahen/madge/compare/0.5.2...0.5.3) > 25 November 2015 - Correct regex on CommonJS parser to detect a core module [`#71`](https://github.com/pahen/madge/pull/71) - Update README.md [`#70`](https://github.com/pahen/madge/pull/70) - List "es6" format in CLI help [`#66`](https://github.com/pahen/madge/pull/66) - Update releasenotes. [`153235d`](https://github.com/pahen/madge/commit/153235dba6df0b40b4305c1331fa7856b9a9bd25) - Bump to version 0.5.3 [`c00dd70`](https://github.com/pahen/madge/commit/c00dd70f684cb71c651a7e57eeeb89728cb9434c) - Correct regex on CJS parser to detect a core module [`67a449a`](https://github.com/pahen/madge/commit/67a449a276d250950dd839ffb37bb2b9bb7a82bd) #### [0.5.2](https://github.com/pahen/madge/compare/0.5.1...0.5.2) > 16 October 2015 - Update resolve to latest version. [`21f787c`](https://github.com/pahen/madge/commit/21f787ced85df3002508a1de4fc3b4fe23fbfc06) - Bump to version 0.5.2 [`95faed0`](https://github.com/pahen/madge/commit/95faed027d21af80e58697588f061787b2f8592f) #### [0.5.1](https://github.com/pahen/madge/compare/0.5.0...0.5.1) > 15 October 2015 - Update modules without any change to the code [`#65`](https://github.com/pahen/madge/pull/65) - Update all dependencies that will not break tests [`65dcaf3`](https://github.com/pahen/madge/commit/65dcaf318defa3140222c9774b35d51373bd5aa1) - Update shrinkwrap [`08ad266`](https://github.com/pahen/madge/commit/08ad266ea7e922762798b5a5bacc103c7d6b9762) - Update releasenotes. [`774f8d8`](https://github.com/pahen/madge/commit/774f8d855bf77da0211df97c97b97dc2d44cab69) #### [0.5.0](https://github.com/pahen/madge/compare/0.4.1...0.5.0) > 2 April 2015 - Add 'comma separated' to -p usage for clarity [`#49`](https://github.com/pahen/madge/pull/49) - Add ES6 module support [`d5b0b60`](https://github.com/pahen/madge/commit/d5b0b60cff78aa473e60cf81322a9cfc716643a4) - Use npm-shrinkwrap instead of “npm shrinkwrap” to get consistent “resolved” fields. [`082abcb`](https://github.com/pahen/madge/commit/082abcb83a34aec2db0edeb728b85cf2e0be2e0b) - Cleanup after PL. [`a0d18ff`](https://github.com/pahen/madge/commit/a0d18ffdf8530ca10ebc6ab8e4e86f160b4b524c) #### [0.4.1](https://github.com/pahen/madge/compare/0.4.0...0.4.1) > 19 December 2014 - Move method to proper file. [`f17a64a`](https://github.com/pahen/madge/commit/f17a64ae0f1c1e506a99fe739b2bc4a6ef2013cc) - Fix bug with absolute paths for module IDs in Windows. [`f64697a`](https://github.com/pahen/madge/commit/f64697a25718ca16e5af5aa21594cfd98bc23701) - Fix issues with absolute paths for modules IDs in Windows (all tests should now pass on Windows too). [`9d524e4`](https://github.com/pahen/madge/commit/9d524e4cc044533029ca6a67e1fba1fac1532984) #### [0.4.0](https://github.com/pahen/madge/compare/0.3.5...0.4.0) > 19 December 2014 - Update NPM shrinkwrap file. [`a23178c`](https://github.com/pahen/madge/commit/a23178c990c87556e2f126a548005ce2a8f35b37) - Resolve the module IDs from the RequireJS paths-config properly. [`41b54e2`](https://github.com/pahen/madge/commit/41b54e2ecde61972ea1f2dfd1a75904ec1029d5a) - Add support for JSX (React) and additional module paths. [`858cd72`](https://github.com/pahen/madge/commit/858cd7290d87477ada8b588d85c93f32a6b932e9) #### [0.3.5](https://github.com/pahen/madge/compare/0.3.3...0.3.5) > 22 September 2014 - IMPROVED: correctly detect circular dependencies when using path aliases (amd) [`324b12b`](https://github.com/pahen/madge/commit/324b12b7a04c7f3bfd431b057e1487e6cf0e6442) - Clear generated graph nodes on each render of a graph. [`4bd4f00`](https://github.com/pahen/madge/commit/4bd4f0035ea2989e7c59249d0ef54be762fbaad5) - Update releasenotes. [`d3df3ab`](https://github.com/pahen/madge/commit/d3df3ab7e22234a21a229296811c8171ee3beefb) #### [0.3.3](https://github.com/pahen/madge/compare/0.3.2...0.3.3) > 11 July 2014 - Use path.resolve() to resolve relative paths in AMD dependencies instead of substack’s resolve lib since it works as expected (fixes #33). [`#33`](https://github.com/pahen/madge/issues/33) - Use amdetective infavor of parse.js for parsing AMD dependencies. [`28e462d`](https://github.com/pahen/madge/commit/28e462d6a016f5b44aa1324392532073d8442005) - Bump to version 0.3.3 [`dc35cf4`](https://github.com/pahen/madge/commit/dc35cf45fa7bacc23f31c5cd0cc5888806624ddc) #### [0.3.2](https://github.com/pahen/madge/compare/0.3.1...0.3.2) > 25 June 2014 - convert spaces to tabs [`#30`](https://github.com/pahen/madge/pull/30) - Code cleanup. [`a235a00`](https://github.com/pahen/madge/commit/a235a0074ba9fb3ca7e6a02aedc6d96c40c8ad5b) - Added failing test cases. [`d095e6a`](https://github.com/pahen/madge/commit/d095e6af71093c16ed0ba704a11f8eed05f76912) - Added code to pass the tests. [`b2276f5`](https://github.com/pahen/madge/commit/b2276f5fc8a121d87d9d38a94b5a894e5103d7dc) #### [0.3.1](https://github.com/pahen/madge/compare/0.3.0...0.3.1) > 3 June 2014 - Apply exclude to RequireJS shim dependencies [`02f3d28`](https://github.com/pahen/madge/commit/02f3d28f26af12d0b0ade3c56df42451161b3882) - Update releasenotes. [`8dd4fb2`](https://github.com/pahen/madge/commit/8dd4fb2168c357e9ccdfabe68c5d62b13e654c26) - Bump to version 0.3.1 [`c41987b`](https://github.com/pahen/madge/commit/c41987b0ad5c952af9554552bcbbddb87139b2e6) #### [0.3.0](https://github.com/pahen/madge/compare/0.2.0...0.3.0) > 26 May 2014 - Lock down dependencies. [`9dcc9b7`](https://github.com/pahen/madge/commit/9dcc9b71348b733aad12e5373f9955158d085509) - make pluggbable by adding onParseFile and onAddModule options that hook into these events with returned madge as the bound context [`ee04d41`](https://github.com/pahen/madge/commit/ee04d418a0cfc61cffbf210edd60129ca609be98) - Add some documentation about onParseFile and onAddModule options. [`dfa9c2b`](https://github.com/pahen/madge/commit/dfa9c2b4491bd34e6444b0f602bc329eb6c80639) #### 0.2.0 > 18 April 2014 - Update README.md [`#13`](https://github.com/pahen/madge/pull/13) - Using require() to get version number instead of version.js [`#11`](https://github.com/pahen/madge/pull/11) - Complete path in circular dependencies is now printed (and marked as red in image graphs). Fixes #4 [`#4`](https://github.com/pahen/madge/issues/4) - Fixed Node.js v0.8 issues. Closes #2 [`#2`](https://github.com/pahen/madge/issues/2) - first commit [`c730a52`](https://github.com/pahen/madge/commit/c730a52ac6eb49c7a5813146c42ef9861c364aee) - Added support for CoffeeScript. Files with extension .coffee will automatically be compiled on-the-fly. [`67fa4ec`](https://github.com/pahen/madge/commit/67fa4ec53d2ae2a85ed0c83ea656dd20364f7f03) - Some code cleanup. [`d976942`](https://github.com/pahen/madge/commit/d9769421ad0aa8e5a3109158f33ce80ea926881b) ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Patrik Henningsson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================

madge

Last version Donate

**Madge** is a developer tool for generating a visual graph of your module dependencies, finding circular dependencies, and giving you other useful info. Joel Kemp's awesome [dependency-tree](https://github.com/mrjoelkemp/node-dependency-tree) is used for extracting the dependency tree. * Works for JavaScript (AMD, CommonJS, and ES6 modules) * Also works for CSS preprocessors (Sass, Stylus, and Less) * NPM installed dependencies are excluded by default (can be enabled) * All core Node.js modules (assert, path, fs, etc) are excluded * Will traverse child dependencies automatically Read the [changelog](CHANGELOG.md) for latest changes. > I've worked with Madge on my free time for the last couple of years and it's been a great experience. It started as an experiment but turned out to be a very useful tool for many developers. I have many ideas for the project and it would definitely be easier to dedicate more time to it with some [financial support](#donations-%EF%B8%8F) 🙏 > > Regardless of your contribution, thanks for your support! ## Examples > Graph generated from madge's own code and dependencies. graph > A graph with circular dependencies. Blue has dependencies, green has no dependencies, and red has circular dependencies. graph-circular ## See it in action in-action # Installation ```sh npm -g install madge ``` ## Graphviz (optional) > [Graphviz](http://www.graphviz.org/) is only required if you want to generate visual graphs (e.g. in SVG or DOT format). ### Mac OS X ```sh brew install graphviz || port install graphviz ``` ### Ubuntu ```sh apt-get install graphviz ``` # API ## madge(path: string|array|object, config: object) > `path` is a single file or directory, or an array of files/directories to read. A predefined tree can also be passed in as an object. > `config` is optional and should be the [configuration](#configuration) to use. > Returns a `Promise` resolved with the Madge instance object. ## Functions #### .obj() > Returns an `Object` with all dependencies. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.obj()); }); ``` #### .warnings() > Returns an `Object` of warnings. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.warnings()); }); ``` #### .circular() > Returns an `Array` of all modules that have circular dependencies. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.circular()); }); ``` #### .circularGraph() > Returns an `Object` with only circular dependencies. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.circularGraph()); }); ``` #### .depends() > Returns an `Array` of all modules that depend on a given module. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.depends('lib/log.js')); }); ``` #### .orphans() > Return an `Array` of all modules that no one is depending on. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.orphans()); }); ``` #### .leaves() > Return an `Array` of all modules that have no dependencies. ```javascript const madge = require('madge'); madge('path/to/app.js').then((res) => { console.log(res.leaves()); }); ``` #### .dot([circularOnly: boolean]) > Returns a `Promise` resolved with a DOT representation of the module dependency graph. Set `circularOnly` to only include circular dependencies. ```javascript const madge = require('madge'); madge('path/to/app.js') .then((res) => res.dot()) .then((output) => { console.log(output); }); ``` #### .image(imagePath: string, [circularOnly: boolean]) > Write the graph as an image to the given image path. Set `circularOnly` to only include circular dependencies. The [image format](http://www.graphviz.org/content/output-formats) to use is determined from the file extension. Returns a `Promise` resolved with a full path to the written image. ```javascript const madge = require('madge'); madge('path/to/app.js') .then((res) => res.image('path/to/image.svg')) .then((writtenImagePath) => { console.log('Image written to ' + writtenImagePath); }); ``` #### .svg() > Return a `Promise` resolved with the XML SVG representation of the dependency graph as a `Buffer`. ```javascript const madge = require('madge'); madge('path/to/app.js') .then((res) => res.svg()) .then((output) => { console.log(output.toString()); }); ``` # Configuration Property | Type | Default | Description --- | --- | --- | --- `baseDir` | String | null | Base directory to use instead of the default `includeNpm` | Boolean | false | If shallow NPM modules should be included `fileExtensions` | Array | ['js'] | Valid file extensions used to find files in directories `excludeRegExp` | Array | false | An array of RegExp for excluding modules `requireConfig` | String | null | RequireJS config for resolving aliased modules `webpackConfig` | String | null | Webpack config for resolving aliased modules `tsConfig` | String\|Object | null | TypeScript config for resolving aliased modules - Either a path to a tsconfig file or an object containing the config `layout` | String | dot | Layout to use in the graph `rankdir` | String | LR | Sets the [direction](https://graphviz.gitlab.io/_pages/doc/info/attrs.html#d:rankdir) of the graph layout `fontName` | String | Arial | Font name to use in the graph `fontSize` | String | 14px | Font size to use in the graph `backgroundColor` | String | #000000 | Background color for the graph `nodeShape` | String | box | A string specifying the [shape](https://graphviz.gitlab.io/_pages/doc/info/attrs.html#k:shape) of a node in the graph `nodeStyle` | String | rounded | A string specifying the [style](https://graphviz.gitlab.io/_pages/doc/info/attrs.html#k:style) of a node in the graph `nodeColor` | String | #c6c5fe | Default node color to use in the graph `noDependencyColor` | String | #cfffac | Color to use for nodes with no dependencies `cyclicNodeColor` | String | #ff6c60 | Color to use for circular dependencies `edgeColor` | String | #757575 | Edge color to use in the graph `graphVizOptions` | Object | false | Custom Graphviz [options](https://graphviz.gitlab.io/_pages/doc/info/attrs.html) `graphVizPath` | String | null | Custom Graphviz path `detectiveOptions` | Object | false | Custom `detective` options for [dependency-tree](https://github.com/dependents/node-dependency-tree) and [precinct](https://github.com/dependents/node-precinct#usage) `dependencyFilter` | Function | false | Function called with a dependency filepath (exclude subtrees by returning false) You can use configuration file either in `.madgerc` in your project or home folder or directly in `package.json`. Look [here](https://github.com/dominictarr/rc#standards) for alternative locations for the file. > .madgerc ```json { "fontSize": "10px", "graphVizOptions": { "G": { "rankdir": "LR" } } } ``` > package.json ```json { "name": "foo", "version": "0.0.1", ... "madge": { "fontSize": "10px", "graphVizOptions": { "G": { "rankdir": "LR" } } } } ``` # CLI ## Examples > List dependencies from a single file ```sh madge path/src/app.js ``` > List dependencies from multiple files ```sh madge path/src/foo.js path/src/bar.js ``` > List dependencies from all *.js files found in a directory ```sh madge path/src ``` > List dependencies from multiple directories ```sh madge path/src/foo path/src/bar ``` > List dependencies from all \*.js and \*.jsx files found in a directory ```sh madge --extensions js,jsx path/src ``` > Finding circular dependencies ```sh madge --circular path/src/app.js ``` > Show modules that depends on a given module ```sh madge --depends wheels.js path/src/app.js ``` > Show modules that no one is depending on ```sh madge --orphans path/src/ ``` > Show modules that have no dependencies ```sh madge --leaves path/src/ ``` > Excluding modules ```sh madge --exclude '^(foo|bar)\.js$' path/src/app.js ``` > Save graph as a SVG image (requires [Graphviz](#graphviz-optional)) ```sh madge --image graph.svg path/src/app.js ``` > Save graph with only circular dependencies ```sh madge --circular --image graph.svg path/src/app.js ``` > Save graph as a [DOT](http://en.wikipedia.org/wiki/DOT_language) file for further processing (requires [Graphviz](#graphviz-optional)) ```sh madge --dot path/src/app.js > graph.gv ``` > Using pipe to transform tree (this example will uppercase all paths) ```sh madge --json path/src/app.js | tr '[a-z]' '[A-Z]' | madge --stdin ``` # Debugging > To enable debugging output if you encounter problems, run madge with the `--debug` option then throw the result in a gist when creating issues on GitHub. ```sh madge --debug path/src/app.js ``` # Running tests ```sh npm install npm test ``` # Creating a release ```sh npm run release ``` # FAQ ## Missing dependencies? It could happen that the files you're not seeing have been skipped due to errors or that they can't be resolved. Run madge with the `--warning` option to see skipped files. If you need even more info run with the `--debug` option. ## Using both Javascript and Typescript in your project? Madge uses [dependency-tree](https://www.npmjs.com/package/dependency-tree) which uses [filing-cabinet](https://www.npmjs.com/package/filing-cabinet) to resolve modules. However it requires configurations for each file type (js/jsx) and (ts/tsx). So provide both `webpackConfig` and `tsConfig` options to madge. ## Using mixed import syntax in the same file? Only one syntax is used by default. You can use both though if you're willing to take the degraded performance. Put this in your madge config to enable mixed imports. For ES6 + CommonJS: ```json { "detectiveOptions": { "es6": { "mixedImports": true } } } ``` For TypeScript + CommonJS: ```json { "detectiveOptions": { "ts": { "mixedImports": true } } } ``` ## How to ignore `import type` statements in ES6 + Flow? Put this in your madge config. ```json { "detectiveOptions": { "es6": { "skipTypeImports": true } } } ``` ## How to ignore `import` in type annotations in TypeScript? Put this in your madge config. ```json { "detectiveOptions": { "ts": { "skipTypeImports": true } } } ``` ## How to ignore dynamic imports in Typescript? Put this in your madge config. ```json { "detectiveOptions": { "ts": { "skipAsyncImports": true }, "tsx": { "skipAsyncImports": true } } } ``` Note: `tsx` is optional, use this when working with JSX. ## Mixing TypesScript and Javascript imports? Ensure you have this in your `.tsconfig` file. ```json { "compilerOptions": { "module": "commonjs", "allowJs": true } } ``` ## What's the "Error: write EPIPE" when exporting graph to image? Ensure you have [installed Graphviz](#graphviz-optional). If you're running Windows, note that Graphviz is not added to the `PATH` variable during install. You should add the folder of `gvpr.exe` (typically `%Graphviz_folder%/bin`) to the `PATH` variable manually. ## How do I fix the "Graphviz not built with triangulation library" error when using sfdp layout? Homebrew doesn't include GTS by default. Fix this by doing: ```sh brew uninstall graphviz brew install gts brew install graphviz ``` ## The image produced by madge is very hard to read, what's wrong? Try running madge with a different layout, here's a list of the ones you can try: * **dot** "hierarchical" or layered drawings of directed graphs. This is the default tool to use if edges have directionality. * **neato** "spring model'' layouts. This is the default tool to use if the graph is not too large (about 100 nodes) and you don't know anything else about it. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling. * **fdp** "spring model'' layouts similar to those of neato, but does this by reducing forces rather than working with energy. * **sfdp** multiscale version of fdp for the layout of large graphs. * **twopi** radial layouts, after Graham Wills 97. Nodes are placed on concentric circles depending their distance from a given root node. * **circo** circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures, such as certain telecommunications networks. # Credits ## Contributors This project exists thanks to all the people who contribute. Contributors ## Donations ❤️ Thanks to the awesome people below for making donations! 🙏[Donate](https://paypal.me/pahen)

Bernard Stojanović (24 Mars, 2021)
BeroBurny

Ole Jørgen Brønner (Oct 8, 2020)
olejorgenb

RxDB (Apr 1, 2020)
RxDB

Peter Verswyvelen (Feb 24, 2020)
Ziriax

Landon Alder (Mar 19, 2019)
landonalder

# License MIT License ================================================ FILE: bin/cli.js ================================================ #!/usr/bin/env node 'use strict'; const path = require('path'); const process = require('process'); const program = require('commander'); const rc = require('rc')('madge'); const version = require('../package.json').version; const ora = require('ora'); const chalk = require('chalk'); const startTime = Date.now(); // Revert https://github.com/tj/commander.js/pull/1409 program.storeOptionsAsProperties(); program .version(version) .usage('[options] ') .option('-b, --basedir ', 'base directory for resolving paths') .option('-s, --summary', 'show dependency count summary') .option('-c, --circular', 'show circular dependencies') .option('-d, --depends ', 'show module dependents') .option('-x, --exclude ', 'exclude modules using RegExp') .option('-j, --json', 'output as JSON') .option('-i, --image ', 'write graph to file as an image') .option('-l, --layout ', 'layout engine to use for graph (dot/neato/fdp/sfdp/twopi/circo)') .option('--orphans', 'show modules that no one is depending on') .option('--leaves', 'show modules that have no dependencies') .option('--dot', 'show graph using the DOT language') .option('--rankdir ', 'set the direction of the graph layout') .option('--extensions ', 'comma separated string of valid file extensions') .option('--require-config ', 'path to RequireJS config') .option('--webpack-config ', 'path to webpack config') .option('--ts-config ', 'path to typescript config') .option('--include-npm', 'include shallow NPM modules', false) .option('--no-color', 'disable color in output and image', false) .option('--no-spinner', 'disable progress spinner', false) .option('--no-count', 'disable circular dependencies counting', false) .option('--stdin', 'read predefined tree from STDIN', false) .option('--warning', 'show warnings about skipped files', false) .option('--debug', 'turn on debug output', false) .parse(process.argv); if (!program.args.length && !program.stdin) { console.log(program.helpInformation()); process.exit(1); } if (program.debug) { process.env.DEBUG = '*'; } if (!program.color) { process.env.DEBUG_COLORS = false; } const log = require('../lib/log'); const output = require('../lib/output'); const madge = require('../lib/api'); let packageConfig = {}; try { packageConfig = require(path.join(process.cwd(), 'package.json')).madge; } catch (e) { } const config = Object.assign(rc, packageConfig); program.options.forEach((opt) => { const name = opt.name(); if (program[name]) { config[name] = program[name]; } }); const spinner = ora({ text: 'Finding files', color: 'white', interval: 100000, isEnabled: program.spinner === 'false' ? false : null }); let exitCode = 0; delete config._; delete config.config; delete config.configs; if (rc.config) { log('using runtime config %s', rc.config); } if (program.basedir) { config.baseDir = program.basedir; } if (program.exclude) { config.excludeRegExp = [program.exclude]; } if (program.extensions) { config.fileExtensions = program.extensions.split(',').map((s) => s.trim()); } if (program.requireConfig) { config.requireConfig = program.requireConfig; } if (program.webpackConfig) { config.webpackConfig = program.webpackConfig; } if (program.tsConfig) { config.tsConfig = program.tsConfig; } if (program.includeNpm) { config.includeNpm = program.includeNpm; } if (!program.color) { config.backgroundColor = '#ffffff'; config.nodeColor = '#000000'; config.noDependencyColor = '#000000'; config.cyclicNodeColor = '#000000'; config.edgeColor = '#757575'; } if (program.rankdir) { config.rankdir = program.rankdir; } function dependencyFilter() { let prevFile; return (dependencyFilePath, traversedFilePath, baseDir) => { if (prevFile !== traversedFilePath) { const relPath = path.relative(baseDir, traversedFilePath); const dir = path.dirname(relPath) + '/'; const file = path.basename(relPath); spinner.text = chalk.grey(dir) + chalk.cyan(file); prevFile = traversedFilePath; } }; } new Promise((resolve, reject) => { if (program.stdin) { let buffer = ''; process.stdin .resume() .setEncoding('utf8') .on('data', (chunk) => { buffer += chunk; }) .on('end', () => { try { resolve(JSON.parse(buffer)); } catch (e) { reject(e); } }); } else { resolve(program.args); } }) .then((src) => { if (!program.json && !program.dot) { spinner.start(); config.dependencyFilter = dependencyFilter(); } return madge(src, config); }) .then((res) => { if (!program.json && !program.dot) { spinner.stop(); output.getResultSummary(res, startTime); } const result = createOutputFromOptions(program, res); if (result !== undefined) { return result; } output.list(res.obj(), { json: program.json }); return res; }) .then((res) => { if (program.warning && !program.json) { output.warnings(res); } if (!program.json && !program.dot) { console.log(''); } process.exit(exitCode); }) .catch((err) => { spinner.stop(); console.log('\n%s %s\n', chalk.red('✖'), err.stack); process.exit(1); }); function createOutputFromOptions(program, res) { if (program.summary) { output.summary(res.obj(), { json: program.json }); return res; } if (program.depends) { output.modules(res.depends(program.depends), { json: program.json }); return res; } if (program.orphans) { output.modules(res.orphans(), { json: program.json }); return res; } if (program.leaves) { output.modules(res.leaves(), { json: program.json }); return res; } if (program.image) { return res.image(program.image, program.circular).then((imagePath) => { spinner.succeed(`${chalk.bold('Image created at')} ${chalk.cyan.bold(imagePath)}`); return res; }); } if (program.dot) { return res.dot(program.circular).then((output) => { process.stdout.write(output); return res; }); } if (program.circular) { const circular = res.circular(); output.circular(spinner, res, circular, { json: program.json, printCount: program.count }); if (circular.length) { exitCode = 1; } return res; } } ================================================ FILE: lib/api.js ================================================ 'use strict'; const path_ = require('path'); const tree = require('./tree'); const cyclic = require('./cyclic'); const graph = require('./graph'); const log = require('./log'); const defaultConfig = { baseDir: null, excludeRegExp: false, fileExtensions: ['js'], includeNpm: false, requireConfig: null, webpackConfig: null, tsConfig: null, rankdir: 'LR', layout: 'dot', fontName: 'Arial', fontSize: '14px', backgroundColor: '#111111', nodeColor: '#c6c5fe', nodeShape: 'box', nodeStyle: 'rounded', noDependencyColor: '#cfffac', cyclicNodeColor: '#ff6c60', edgeColor: '#757575', graphVizOptions: false, graphVizPath: false, dependencyFilter: false }; class Madge { /** * Class constructor. * @constructor * @api public * @param {String|Array|Object} path * @param {Object} config * @return {Promise} */ constructor(path, config) { this.skipped = []; if (!path) { throw new Error('path argument not provided'); } this.config = Object.assign({}, defaultConfig, config); if (typeof this.config.tsConfig === 'string') { const ts = require('typescript'); const tsParsedConfig = ts.readJsonConfigFile(this.config.tsConfig, ts.sys.readFile); const obj = ts.parseJsonSourceFileConfigFileContent(tsParsedConfig, ts.sys, path_.dirname(config.tsConfig)); this.config.tsConfig = { ...obj.raw, compilerOptions: obj.options }; log('using tsconfig %o', this.config.tsConfig); } if (typeof path === 'object' && !Array.isArray(path)) { this.tree = path; log('using predefined tree %o', path); return Promise.resolve(this); } if (typeof path === 'string') { path = [path]; } return tree(path, this.config).then((res) => { this.tree = res.tree; this.skipped = res.skipped; return this; }); } /** * Return the module dependency graph as an object. * @api public * @return {Object} */ obj() { return this.tree; } /** * Return produced warnings. * @api public * @return {Array} */ warnings() { return { skipped: this.skipped }; } /** * Return the modules that has circular dependencies. * @api public * @return {Array} */ circular() { return cyclic(this.tree); } /** * Return circular dependency graph. * @api public * @return {Object} */ circularGraph() { const circularDeps = this.circular(); return Object.entries(this.obj()) .filter(([k]) => circularDeps.some((x) => x.includes(k))) .reduce((acc, [k, v]) => { acc[k] = v.filter((x) => circularDeps.some((y) => y.includes(x))); return acc; }, {}); } /** * Return a list of modules that depends on the given module. * @api public * @param {String} id * @return {Array} */ depends(id) { const tree = this.obj(); return Object .keys(tree) .filter((dep) => tree[dep].indexOf(id) >= 0); } /** * Return a list of modules that no one is depending on. * @api public * @return {Array} */ orphans() { const tree = this.obj(); const map = {}; Object .keys(tree) .forEach((dep) => { tree[dep].forEach((id) => { map[id] = true; }); }); return Object .keys(tree) .filter((dep) => !map[dep]); } /** * Return a list of modules that have no dependencies. * @api public * @return {Array} */ leaves() { const tree = this.obj(); return Object.keys(tree).filter((key) => !tree[key].length); } /** * Return the module dependency graph as DOT output. * @api public * @param {Boolean} circularOnly * @return {Promise} */ dot(circularOnly) { return graph.dot( circularOnly ? this.circularGraph() : this.obj(), this.circular(), this.config ); } /** * Write dependency graph to image. * @api public * @param {String} imagePath * @param {Boolean} circularOnly * @return {Promise} */ image(imagePath, circularOnly) { if (!imagePath) { return Promise.reject(new Error('imagePath not provided')); } return graph.image( circularOnly ? this.circularGraph() : this.obj(), this.circular(), imagePath, this.config ); } /** * Return Buffer with XML SVG representation of the dependency graph. * @api public * @return {Promise} */ svg() { return graph.svg(this.obj(), this.circular(), this.config); } } /** * Expose API. * @param {String|Array} path * @param {Object} config * @return {Promise} */ module.exports = (path, config) => new Madge(path, config); ================================================ FILE: lib/cyclic.js ================================================ 'use strict'; /** * Get path to the circular dependency. * @param {String} parent * @param {Object} unresolved * @return {Array} */ function getPath(parent, unresolved) { let parentVisited = false; return Object.keys(unresolved).filter((module) => { if (module === parent) { parentVisited = true; } return parentVisited && unresolved[module]; }); } /** * A circular dependency is occurring when we see a software package * more than once, unless that software package has all its dependencies resolved. * @param {String} id * @param {Object} modules * @param {Object} circular * @param {Object} resolved * @param {Object} unresolved */ function resolver(id, modules, circular, resolved, unresolved) { unresolved[id] = true; if (modules[id]) { modules[id].forEach((dependency) => { if (!resolved[dependency]) { if (unresolved[dependency]) { circular.push(getPath(dependency, unresolved)); return; } resolver(dependency, modules, circular, resolved, unresolved); } }); } resolved[id] = true; unresolved[id] = false; } /** * Finds all circular dependencies for the given modules. * @param {Object} modules * @return {Array} */ module.exports = function (modules) { const circular = []; const resolved = {}; const unresolved = {}; Object.keys(modules).forEach((id) => { resolver(id, modules, circular, resolved, unresolved); }); return circular; }; ================================================ FILE: lib/graph.js ================================================ 'use strict'; const path = require('path'); const {promisify} = require('util'); const gv = require('ts-graphviz'); const adapter = require('ts-graphviz/adapter'); const toArray = require('stream-to-array'); const exec = promisify(require('child_process').execFile); const writeFile = promisify(require('fs').writeFile); /** * Set color on a node. * @param {Object} node * @param {String} color */ function setNodeColor(node, color) { node.attributes.set('color', color); node.attributes.set('fontcolor', color); } /** * Check if Graphviz is installed on the system. * @param {Object} config * @return {Promise} */ async function checkGraphvizInstalled(config) { const cmd = config.graphVizPath ? path.join(config.graphVizPath, 'gvpr') : 'gvpr'; try { await exec(cmd, ['-V']); } catch (err) { if (err.code === 'ENOENT') { throw new Error(`Graphviz could not be found. Ensure that "gvpr" is in your $PATH. ${err}`); } else { throw new Error(`Unexpected error when calling Graphviz "${cmd}". ${err}`); } } } /** * Return options to use with graphviz digraph. * @param {Object} config * @return {Object} */ function createGraphvizOptions(config) { const graphVizOptions = config.graphVizOptions || {}; return { dotCommand: config.graphVizPath ? config.graphVizPath : null, attributes: { // Graph graph: Object.assign({ overlap: false, pad: 0.3, rankdir: config.rankdir, layout: config.layout, bgcolor: config.backgroundColor }, graphVizOptions.G), // Edge edge: Object.assign({ color: config.edgeColor }, graphVizOptions.E), // Node node: Object.assign({ fontname: config.fontName, fontsize: config.fontSize, color: config.nodeColor, shape: config.nodeShape, style: config.nodeStyle, height: 0, fontcolor: config.nodeColor }, graphVizOptions.N) } }; } /** * Creates the graphviz graph. * @param {Object} modules * @param {Array} circular * @param {Object} config * @param {Object} options * @return {Promise} */ function createGraph(modules, circular, config, options) { const g = gv.digraph('G'); const nodes = {}; const cyclicModules = circular.reduce((a, b) => a.concat(b), []); Object.keys(modules).forEach((id) => { nodes[id] = nodes[id] || g.createNode(id); if (!modules[id].length) { setNodeColor(nodes[id], config.noDependencyColor); } else if (cyclicModules.indexOf(id) >= 0) { setNodeColor(nodes[id], config.cyclicNodeColor); } modules[id].forEach((depId) => { nodes[depId] = nodes[depId] || g.createNode(depId); if (!modules[depId]) { setNodeColor(nodes[depId], config.noDependencyColor); } g.createEdge([nodes[id], nodes[depId]]); }); }); const dot = gv.toDot(g); return adapter .toStream(dot, options) .then(toArray) .then(Buffer.concat); } /** * Return the module dependency graph XML SVG representation as a Buffer. * @param {Object} modules * @param {Array} circular * @param {Object} config * @return {Promise} */ module.exports.svg = function (modules, circular, config) { const options = createGraphvizOptions(config); options.format = 'svg'; return checkGraphvizInstalled(config) .then(() => createGraph(modules, circular, config, options)); }; /** * Creates an image from the module dependency graph. * @param {Object} modules * @param {Array} circular * @param {String} imagePath * @param {Object} config * @return {Promise} */ module.exports.image = function (modules, circular, imagePath, config) { const options = createGraphvizOptions(config); options.format = path.extname(imagePath).replace('.', '') || 'png'; return checkGraphvizInstalled(config) .then(() => { return createGraph(modules, circular, config, options) .then((image) => writeFile(imagePath, image)) .then(() => path.resolve(imagePath)); }); }; /** * Return the module dependency graph as DOT output. * @param {Object} modules * @param {Array} circular * @param {Object} config * @return {Promise} */ module.exports.dot = function (modules, circular, config) { const options = createGraphvizOptions(config); options.format = 'dot'; return checkGraphvizInstalled(config) .then(() => createGraph(modules, circular, config, options)) .then((output) => output.toString('utf8')); }; ================================================ FILE: lib/log.js ================================================ 'use strict'; module.exports = require('debug')('madge'); ================================================ FILE: lib/output.js ================================================ 'use strict'; const chalk = require('chalk'); const pluralize = require('pluralize'); const prettyMs = require('pretty-ms'); /** * Print given object as JSON. * @param {Object} obj * @return {String} */ function printJSON(obj) { return console.log(JSON.stringify(obj, null, ' ')); } /** * Print module dependency graph as indented text (or JSON). * @param {Object} modules * @param {Object} opts * @return {undefined} */ module.exports.list = function (modules, opts) { opts = opts || {}; if (opts.json) { return printJSON(modules); } Object.keys(modules).forEach((id) => { console.log(chalk.cyan.bold(id)); modules[id].forEach((depId) => { console.log(chalk.grey(` ${depId}`)); }); }); }; /** * Print a summary of module dependencies. * @param {Object} modules * @param {Object} opts * @return {undefined} */ module.exports.summary = function (modules, opts) { const o = {}; opts = opts || {}; Object.keys(modules).sort((a, b) => { return modules[b].length - modules[a].length; }).forEach((id) => { if (opts.json) { o[id] = modules[id].length; } else { console.log('%s %s', chalk.cyan.bold(modules[id].length), chalk.grey(id)); } }); if (opts.json) { return printJSON(o); } }; /** * Print the result from Madge.circular(). * @param {Object} spinner * @param {Object} res * @param {Array} circular * @param {Object} opts * @return {undefined} */ module.exports.circular = function (spinner, res, circular, opts) { if (opts.json) { return printJSON(circular); } const cyclicCount = Object.keys(circular).length; if (!circular.length) { spinner.succeed(chalk.bold('No circular dependency found!')); } else { spinner.fail(chalk.red.bold(`Found ${pluralize('circular dependency', cyclicCount, true)}!\n`)); circular.forEach((path, idx) => { if (opts.printCount) { process.stdout.write(chalk.dim(idx + 1 + ') ')); } path.forEach((module, idx) => { if (idx) { process.stdout.write(chalk.dim(' > ')); } process.stdout.write(chalk.cyan.bold(module)); }); process.stdout.write('\n'); }); } }; /** * Print the given modules. * @param {Array} modules * @param {Object} opts * @return {undefined} */ module.exports.modules = function (modules, opts) { if (opts.json) { return printJSON(modules); } modules.forEach((id) => { console.log(chalk.cyan.bold(id)); }); }; /** * Print warnings to the console. * @param {Object} res * @return {undefined} */ module.exports.warnings = function (res) { const skipped = res.warnings().skipped; if (skipped.length) { console.log(chalk.yellow.bold(`\n✖ Skipped ${pluralize('file', skipped.length, true)}\n`)); skipped.forEach((file) => { console.log(chalk.yellow(file)); }); } }; /** * Get a summary from the result. * @param {Object} res * @param {Number} startTime * @return {undefined} */ module.exports.getResultSummary = function (res, startTime) { const warningCount = res.warnings().skipped.length; const fileCount = Object.keys(res.obj()).length; console.log('Processed %s %s %s %s\n', chalk.bold(fileCount), pluralize('file', fileCount), chalk.dim(`(${prettyMs(Date.now() - startTime)})`), warningCount ? '(' + chalk.yellow.bold(pluralize('warning', warningCount, true)) + ')' : '' ); }; ================================================ FILE: lib/tree.js ================================================ 'use strict'; const os = require('os'); const path = require('path'); const {promisify} = require('util'); const commondir = require('commondir'); const walk = require('walkdir'); const dependencyTree = require('dependency-tree'); const log = require('./log'); const stat = promisify(require('fs').stat); /** * Check if running on Windows. * @type {Boolean} */ const isWin = (os.platform() === 'win32'); class Tree { /** * Class constructor. * @constructor * @api public * @param {Array} srcPaths * @param {Object} config * @return {Promise} */ constructor(srcPaths, config) { this.srcPaths = srcPaths.map((s) => path.resolve(s)); log('using src paths %o', this.srcPaths); this.config = config; log('using config %o', this.config); return this.getDirs() .then(this.setBaseDir.bind(this)) .then(this.getFiles.bind(this)) .then(this.generateTree.bind(this)); } /** * Set the base directory (compute the common one if multiple). * @param {Array} dirs */ setBaseDir(dirs) { if (this.config.baseDir) { this.baseDir = path.resolve(this.config.baseDir); } else { this.baseDir = commondir(dirs); } log('using base directory %s', this.baseDir); } /** * Get directories from the source paths * @return {Promise} resolved with an array of directories */ getDirs() { return Promise .all(this.srcPaths.map((srcPath) => { return stat(srcPath) .then((stats) => stats.isDirectory() ? srcPath : path.dirname(path.resolve(srcPath))); })); } /** * Get all files found from the source paths * @return {Promise} resolved with an array of files */ getFiles() { const files = []; return Promise .all(this.srcPaths.map((srcPath) => { return stat(srcPath) .then((stats) => { if (stats.isFile()) { if (this.isGitPath(srcPath)) { return; } files.push(path.resolve(srcPath)); return; } walk.sync(srcPath, (filePath, stat) => { if (this.isGitPath(filePath) || this.isNpmPath(filePath) || !stat.isFile()) { return; } const ext = path.extname(filePath).replace('.', ''); if (files.indexOf(filePath) < 0 && this.config.fileExtensions.indexOf(ext) >= 0) { files.push(filePath); } }); }); })) .then(() => files); } /** * Generate the tree from the given files * @param {Array} files * @return {Object} */ generateTree(files) { const depTree = {}; const visited = {}; const nonExistent = []; const npmPaths = {}; const pathCache = {}; files.forEach((file) => { if (visited[file]) { return; } Object.assign(depTree, dependencyTree({ filename: file, directory: this.baseDir, requireConfig: this.config.requireConfig, webpackConfig: this.config.webpackConfig, tsConfig: this.config.tsConfig, visited: visited, filter: (dependencyFilePath, traversedFilePath) => { let dependencyFilterRes = true; const isNpmPath = this.isNpmPath(dependencyFilePath); if (this.isGitPath(dependencyFilePath)) { return false; } if (this.config.dependencyFilter) { dependencyFilterRes = this.config.dependencyFilter(dependencyFilePath, traversedFilePath, this.baseDir); } if (this.config.includeNpm && isNpmPath) { (npmPaths[traversedFilePath] = npmPaths[traversedFilePath] || []).push(dependencyFilePath); } return !isNpmPath && (dependencyFilterRes || dependencyFilterRes === undefined); }, detective: this.config.detectiveOptions, nonExistent: nonExistent })); }); let tree = this.convertTree(depTree, {}, pathCache, npmPaths); for (const npmKey in npmPaths) { const id = this.processPath(npmKey, pathCache); npmPaths[npmKey].forEach((npmPath) => { tree[id].push(this.processPath(npmPath, pathCache)); }); } if (this.config.excludeRegExp) { tree = this.exclude(tree, this.config.excludeRegExp); } return { tree: this.sort(tree), skipped: nonExistent }; } /** * Convert deep tree produced by dependency-tree to a * shallow (one level deep) tree used by madge. * @param {Object} depTree * @param {Object} tree * @param {Object} pathCache * @return {Object} */ convertTree(depTree, tree, pathCache) { for (const key in depTree) { const id = this.processPath(key, pathCache); if (!tree[id]) { tree[id] = []; for (const dep in depTree[key]) { tree[id].push(this.processPath(dep, pathCache)); } this.convertTree(depTree[key], tree, pathCache); } } return tree; } /** * Process absolute path and return a shorter one. * @param {String} absPath * @param {Object} cache * @return {String} */ processPath(absPath, cache) { if (cache[absPath]) { return cache[absPath]; } let relPath = path.relative(this.baseDir, absPath); if (isWin) { relPath = relPath.replace(/\\/g, '/'); } cache[absPath] = relPath; return relPath; } /** * Check if path is from NPM folder * @param {String} path * @return {Boolean} */ isNpmPath(path) { return path.indexOf('node_modules') >= 0; } /** * Check if path is from .git folder * @param {String} filePath * @return {Boolean} */ isGitPath(filePath) { return filePath.split(path.sep).indexOf('.git') !== -1; } /** * Exclude modules from tree using RegExp. * @param {Object} tree * @param {Array} excludeRegExp * @return {Object} */ exclude(tree, excludeRegExp) { const regExpList = excludeRegExp.map((re) => new RegExp(re)); function regExpFilter(id) { return regExpList.findIndex((regexp) => regexp.test(id)) < 0; } return Object .keys(tree) .filter(regExpFilter) .reduce((acc, id) => { acc[id] = tree[id].filter(regExpFilter); return acc; }, {}); } /** * Sort tree. * @param {Object} tree * @return {Object} */ sort(tree) { return Object .keys(tree) .sort() .reduce((acc, id) => { acc[id] = tree[id].sort(); return acc; }, {}); } } /** * Expose API. * @param {Array} srcPaths * @param {Object} config * @return {Promise} */ module.exports = (srcPaths, config) => new Tree(srcPaths, config); ================================================ FILE: package.json ================================================ { "name": "madge", "version": "8.0.0", "author": "Patrik Henningsson ", "repository": "git://github.com/pahen/madge", "homepage": "https://github.com/pahen/madge", "license": "MIT", "reveal": true, "description": "Create graphs from module dependencies.", "keywords": [ "ES6", "ES7", "AMD", "RequireJS", "require", "module", "circular", "dependency", "dependencies", "graphviz", "graph" ], "engines": { "node": ">=18" }, "main": "./lib/api", "bin": { "madge": "./bin/cli.js" }, "scripts": { "test": "npm run lint && npm run mocha", "mocha": "mocha test/*.js", "watch": "mocha --watch --growl test/*.js", "lint": "eslint bin/cli.js lib test/*.js", "debug": "node bin/cli.js --debug bin lib", "generate": "npm run generate:small && npm run generate:madge", "generate:small": "bin/cli.js --image /tmp/simple.svg test/cjs/circular/a.js", "generate:madge": "bin/cli.js --image /tmp/madge.svg bin lib", "test:output": "./test/output.sh", "release": "npm test && release-it" }, "funding": { "type": "individual", "url": "https://www.paypal.me/pahen" }, "dependencies": { "chalk": "^4.1.2", "commander": "^7.2.0", "commondir": "^1.0.1", "debug": "^4.3.4", "dependency-tree": "^11.0.0", "ora": "^5.4.1", "pluralize": "^8.0.0", "pretty-ms": "^7.0.1", "rc": "^1.2.8", "stream-to-array": "^2.3.0", "ts-graphviz": "^2.1.2", "walkdir": "^0.4.1" }, "peerDependencies": { "typescript": "^5.4.4" }, "peerDependenciesMeta": { "typescript": { "optional": true } }, "devDependencies": { "@aptoma/eslint-config": "^7.0.1", "auto-changelog": "^2.4.0", "eslint": "^7.29.0", "mocha": "^9.0.1", "mz": "^2.7.0", "release-it": "^16.2.1", "should": "^13.2.3", "typescript": "^5.4.4" } } ================================================ FILE: test/amd/amdes6.js ================================================ define([ 'ok/d' ], function(a) { 'use strict'; var x = [1, 2, 3, 4] for (var i of x) { x++; } return x; }); ================================================ FILE: test/amd/circular/a.js ================================================ define(['b', 'c'], function (B, C) { return 'A'; }); ================================================ FILE: test/amd/circular/b.js ================================================ define(['d'], function (D) { return 'B'; }); ================================================ FILE: test/amd/circular/c.js ================================================ define(['a'], function (A) { return 'C'; }); ================================================ FILE: test/amd/circular/d.js ================================================ define(function () { return 'D'; }); ================================================ FILE: test/amd/circular/e.js ================================================ define(['f'], function (F) { return 'E'; }); ================================================ FILE: test/amd/circular/f.js ================================================ define(['g'], function (G) { return 'F'; }); ================================================ FILE: test/amd/circular/g.js ================================================ define(['h'], function (H) { return 'G'; }); ================================================ FILE: test/amd/circular/h.js ================================================ define(['f'], function (F) { return 'H'; }); ================================================ FILE: test/amd/circular/main.js ================================================ define(['a', 'f'], function () { return 'MAIN'; }); ================================================ FILE: test/amd/circularAlias/config.js ================================================ require.config({ paths: { 'cpu': 'x86', 'jsdos':'dos' } }); ================================================ FILE: test/amd/circularAlias/dos.js ================================================ define(['cpu'], function(cpu) { }); ================================================ FILE: test/amd/circularAlias/x86.js ================================================ define(['jsdos'], function(dos) { }); ================================================ FILE: test/amd/circularRelative/a.js ================================================ define('a', ['./foo/b'], function () { return 'A'; }); ================================================ FILE: test/amd/circularRelative/foo/b.js ================================================ define('foo/b', ['../a'], function () { return 'B'; }); ================================================ FILE: test/amd/nested/a.js ================================================ define('a', function () { return 'A'; }); ================================================ FILE: test/amd/nested/b.js ================================================ define('b', function () { return 'b'; }); ================================================ FILE: test/amd/nested/main.js ================================================ define(['require', 'a'], function(require, a) { require(['b'], function (b) { }); }); ================================================ FILE: test/amd/ok/a.js ================================================ define(['sub/b'], function (B) { return 'A'; }); ================================================ FILE: test/amd/ok/d.js ================================================ ================================================ FILE: test/amd/ok/e.js ================================================ define(['sub/c'], function (C) { return 'E'; }); ================================================ FILE: test/amd/ok/sub/b.js ================================================ define(['sub/c'], function (C) { return 'B'; }); ================================================ FILE: test/amd/ok/sub/c.js ================================================ define(['d'], function (D) { return 'C'; }); ================================================ FILE: test/amd/plugin.js ================================================ define(['ok/d', './locale!locales/not/exists'], function (D) { return 'p'; }); ================================================ FILE: test/amd/requirejs/a.js ================================================ define(['jquery'], function ($) { return 'A'; }); ================================================ FILE: test/amd/requirejs/config.js ================================================ require.config({ paths: { 'jquery': 'vendor/jquery-2.0.3', 'jquery.foo': 'vendor/jquery.foo-1.0', 'jquery.bar': 'vendor/jquery.bar-1.0', 'baz': 'vendor/baz', 'quux': 'vendor/quux' }, shim: { 'jquery': { exports: '$' }, 'jquery.foo': { deps: ['jquery'] }, 'jquery.bar': { deps: ['jquery'] }, 'baz': { exports: 'baz', deps: ['quux'] }, 'quux': { exports: 'quux' } } }); ================================================ FILE: test/amd/requirejs/orphans/a.js ================================================ define(['orphans/b'], function () { return 'A'; }); ================================================ FILE: test/amd/requirejs/orphans/b.js ================================================ define([], function () { return 'B'; }); ================================================ FILE: test/amd/requirejs/orphans/c.js ================================================ define([], function () { return 'C'; }); ================================================ FILE: test/amd/requirejs/vendor/baz.js ================================================ ================================================ FILE: test/amd/requirejs/vendor/jquery-2.0.3.js ================================================ ================================================ FILE: test/amd/requirejs/vendor/jquery.bar-1.0.js ================================================ ================================================ FILE: test/amd/requirejs/vendor/jquery.foo-1.0.js ================================================ ================================================ FILE: test/amd/requirejs/vendor/quux.js ================================================ ================================================ FILE: test/amd.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('AMD', () => { const dir = __dirname + '/amd'; it('finds recursive dependencies', (done) => { madge(dir + '/ok/a.js').then((res) => { res.obj().should.eql({ 'a.js': ['sub/b.js'], 'sub/b.js': ['sub/c.js'], 'sub/c.js': ['d.js'], 'd.js': [] }); done(); }).catch(done); }); it('ignores plugins', (done) => { madge(dir + '/plugin.js').then((res) => { res.obj().should.eql({ 'plugin.js': ['ok/d.js'], 'ok/d.js': [] }); done(); }).catch(done); }); it('finds nested dependencies', (done) => { madge(dir + '/nested/main.js').then((res) => { res.obj().should.eql({ 'a.js': [], 'b.js': [], 'main.js': [ 'a.js', 'b.js' ] }); done(); }).catch(done); }); it('finds circular dependencies', (done) => { madge(dir + '/circular/main.js').then((res) => { res.circular().should.eql([ ['a.js', 'c.js'], ['f.js', 'g.js', 'h.js'] ]); done(); }).catch(done); }); it('finds circular dependencies with relative paths', (done) => { madge(dir + '/circularRelative/a.js').then((res) => { res.circular().should.eql([['a.js', 'foo/b.js']]); done(); }).catch(done); }); it('finds circular dependencies with alias', (done) => { madge(dir + '/circularAlias/dos.js', { requireConfig: dir + '/circularAlias/config.js' }).then((res) => { res.circular().should.eql([['dos.js', 'x86.js']]); done(); }).catch(done); }); it('works for files with ES6 code inside', (done) => { madge(dir + '/amdes6.js').then((res) => { res.obj().should.eql({ 'amdes6.js': ['ok/d.js'], 'ok/d.js': [] }); done(); }).catch(done); }); it('uses paths found in RequireJS config', (done) => { madge(dir + '/requirejs/a.js', { requireConfig: dir + '/requirejs/config.js' }).then((res) => { res.obj().should.eql({ 'a.js': ['vendor/jquery-2.0.3.js'], 'vendor/jquery-2.0.3.js': [] }); done(); }).catch(done); }); it('returns modules that no one is depending on', (done) => { madge(dir + '/requirejs/orphans', { requireConfig: dir + '/requirejs/config.js' }).then((res) => { res.orphans().should.eql([ 'a.js', 'c.js' ]); done(); }).catch(done); }); }); ================================================ FILE: test/api.js ================================================ /* eslint-env mocha */ 'use strict'; const os = require('os'); const path = require('path'); const fs = require('mz/fs'); const madge = require('../lib/api'); require('should'); describe('API', () => { it('throws error on missing path argument', () => { (() => { madge(); }).should.throw('path argument not provided'); }); it('returns a Promise', () => { madge(__dirname + '/cjs/a.js').should.be.Promise(); // eslint-disable-line new-cap }); it('throws error if file or directory does not exists', (done) => { madge(__dirname + '/missing.js').catch((err) => { err.message.should.match(/no such file or directory/); done(); }).catch(done); }); it('takes single file as path', (done) => { madge(__dirname + '/cjs/a.js').then((res) => { res.obj().should.eql({ 'a.js': ['b.js', 'c.js'], 'b.js': ['c.js'], 'c.js': [] }); done(); }).catch(done); }); it('takes an array of files as path and combines the result', (done) => { madge([__dirname + '/cjs/a.js', __dirname + '/cjs/normal/d.js']).then((res) => { res.obj().should.eql({ 'a.js': ['b.js', 'c.js'], 'b.js': ['c.js'], 'c.js': [], 'normal/d.js': [] }); done(); }).catch(done); }); it('take a single directory as path and find files in it', (done) => { madge(__dirname + '/cjs/normal').then((res) => { res.obj().should.eql({ 'a.js': ['sub/b.js'], 'd.js': [], 'sub/b.js': ['sub/c.js'], 'sub/c.js': ['d.js'] }); done(); }).catch(done); }); it('takes an array of directories as path and compute the basedir correctly', (done) => { madge([__dirname + '/cjs/multibase/1', __dirname + '/cjs/multibase/2']).then((res) => { res.obj().should.eql({ '1/a.js': [], '2/b.js': [] }); done(); }).catch(done); }); it('takes a predefined tree', (done) => { madge({ a: ['b', 'c', 'd'], b: ['c'], c: [], d: ['a'] }).then((res) => { res.obj().should.eql({ a: ['b', 'c', 'd'], b: ['c'], c: [], d: ['a'] }); done(); }).catch(done); }); it('can exclude modules using RegExp', (done) => { madge(__dirname + '/cjs/a.js', { excludeRegExp: ['^b.js$'] }).then((res) => { res.obj().should.eql({ 'a.js': ['c.js'], 'c.js': [] }); done(); }).catch(done); }); it('extracts dependencies but excludes .git', (done) => { // eslint-disable-next-line no-sync fs.renameSync(`${__dirname}/git/.git_tmp`, `${__dirname}/git/.git`); madge(__dirname + '/git/a.js', {}).then((res) => { res.obj().should.eql({ 'a.js': ['b.js', 'c.js'], 'b.js': ['c.js'], 'c.js': [] }); done(); }).catch(() => { done(); }).finally(() => { // eslint-disable-next-line no-sync fs.renameSync(`${__dirname}/git/.git`, `${__dirname}/git/.git_tmp`); }); }); describe('dependencyFilter', () => { it('will stop traversing when returning false', (done) => { madge(__dirname + '/cjs/a.js', { dependencyFilter: () => { return false; } }).then((res) => { res.obj().should.eql({ 'a.js': [] }); done(); }).catch(done); }); it('will not stop traversing when not returning anything', (done) => { madge(__dirname + '/cjs/a.js', { dependencyFilter: () => {} }).then((res) => { res.obj().should.eql({ 'a.js': ['b.js', 'c.js'], 'b.js': ['c.js'], 'c.js': [] }); done(); }).catch(done); }); it('will pass arguments to the function', (done) => { let counter = 0; madge(__dirname + '/cjs/a.js', { dependencyFilter: (dependencyFilePath, traversedFilePath, baseDir) => { if (counter === 0) { dependencyFilePath.should.match(/test\/cjs\/b\.js$/); traversedFilePath.should.match(/test\/cjs\/a\.js$/); baseDir.should.match(/test\/cjs$/); } if (counter === 1) { dependencyFilePath.should.match(/test\/cjs\/c\.js$/); traversedFilePath.should.match(/test\/cjs\/a\.js$/); baseDir.should.match(/test\/cjs$/); } if (counter === 2) { dependencyFilePath.should.match(/test\/cjs\/c\.js$/); traversedFilePath.should.match(/test\/cjs\/b\.js$/); baseDir.should.match(/test\/cjs$/); } counter++; } }).then(() => { done(); }).catch(done); }); }); describe('obj()', () => { it('returns dependency object', (done) => { madge(__dirname + '/cjs/a.js').then((res) => { res.obj().should.eql({ 'a.js': ['b.js', 'c.js'], 'b.js': ['c.js'], 'c.js': [] }); done(); }).catch(done); }); }); describe('circular()', () => { it('returns list of circular dependencies', (done) => { madge(__dirname + '/cjs/circular/a.js').then((res) => { res.circular().should.eql([ ['a.js', 'd.js'] ]); done(); }).catch(done); }); }); describe('circularGraph()', () => { it('returns graph with only circular dependencies', (done) => { madge(__dirname + '/cjs/circular/a.js').then((res) => { res.circularGraph().should.eql({ 'a.js': ['d.js'], 'd.js': ['a.js'] }); done(); }).catch(done); }); }); describe('warnings()', () => { it('returns an array of skipped files', (done) => { madge(__dirname + '/cjs/missing.js').then((res) => { res.obj().should.eql({ 'missing.js': ['c.js'], 'c.js': [] }); res.warnings().should.eql({ skipped: ['./path/non/existing/file'] }); done(); }).catch(done); }); }); describe('dot()', () => { it('returns a promise resolved with graphviz DOT output', async () => { const res = await madge(__dirname + '/cjs/b.js'); const output = await res.dot(); output.should.match(/digraph G/); output.should.match(/bgcolor="#111111"/); output.should.match(/fontcolor="#c6c5fe"/); output.should.match(/color="#757575"/); output.should.match(/fontcolor="#cfffac"/); }); }); describe('depends()', () => { it('returns modules that depends on another', (done) => { madge(__dirname + '/cjs/a.js').then((res) => { res.depends('c.js').should.eql(['a.js', 'b.js']); done(); }).catch(done); }); }); describe('orphans()', () => { it('returns modules that no one is depending on', (done) => { madge(__dirname + '/cjs/normal').then((res) => { res.orphans().should.eql(['a.js']); done(); }).catch(done); }); }); describe('leaves()', () => { it('returns modules that have no dependencies', (done) => { madge(__dirname + '/cjs/normal').then((res) => { res.leaves().should.eql(['d.js']); done(); }).catch(done); }); }); describe('svg()', () => { it('returns a promise resolved with XML SVG output in a Buffer', (done) => { madge(__dirname + '/cjs/b.js') .then((res) => res.svg()) .then((output) => { output.should.instanceof(Buffer); output.toString().should.match(/ { let imagePath; beforeEach(() => { imagePath = path.join(os.tmpdir(), 'madge_' + Date.now() + '_image.png'); }); afterEach(() => { return fs.unlink(imagePath).catch(() => {}); }); it('rejects if a filename is not supplied', (done) => { madge(__dirname + '/cjs/a.js') .then((res) => res.image()) .catch((err) => { err.message.should.eql('imagePath not provided'); done(); }); }); it('rejects on unsupported image format', (done) => { madge(__dirname + '/cjs/a.js') .then((res) => res.image('image.zyx')) .catch((err) => { err.message.should.match(/Format: "zyx" not recognized/); done(); }); }); it('rejects if graphviz is not installed', (done) => { madge(__dirname + '/cjs/a.js', {graphVizPath: '/invalid/path'}) .then((res) => res.image('image.png')) .catch((err) => { err.message.should.eql('Graphviz could not be found. Ensure that "gvpr" is in your $PATH. Error: spawn /invalid/path/gvpr ENOENT'); done(); }); }); it('writes image to file', (done) => { madge(__dirname + '/cjs/a.js') .then((res) => res.image(imagePath)) .then((writtenImagePath) => { writtenImagePath.should.eql(imagePath); return fs .exists(imagePath) .then((exists) => { if (!exists) { throw new Error(imagePath + ' not created'); } done(); }); }) .catch(done); }); }); }); ================================================ FILE: test/cjs/a.js ================================================ require('./b'); require('./c'); ================================================ FILE: test/cjs/b.js ================================================ require('./c'); ================================================ FILE: test/cjs/both.js ================================================ require('a'); require('b'); require('c'+x); var moo = require('d'+y).moo; ================================================ FILE: test/cjs/c.js ================================================ ================================================ FILE: test/cjs/chained.js ================================================ require('c').hello().goodbye() require('b').hello() require('a') ================================================ FILE: test/cjs/circular/a.js ================================================ var b = require('./b'); var c = require('./c'); var d = require('./d'); ================================================ FILE: test/cjs/circular/b.js ================================================ var c = require('./c'); ================================================ FILE: test/cjs/circular/c.js ================================================ ================================================ FILE: test/cjs/circular/d.js ================================================ var a = require('./a'); ================================================ FILE: test/cjs/circular/foo.js ================================================ require('./foo.json'); ================================================ FILE: test/cjs/circular/foo.json ================================================ {} ================================================ FILE: test/cjs/core.js ================================================ var fs = require('fs'); var a = require('a'); ================================================ FILE: test/cjs/error.js ================================================ if (x) { return; } ================================================ FILE: test/cjs/missing.js ================================================ require('./c'); require('./path/non/existing/file'); ================================================ FILE: test/cjs/multibase/1/a.js ================================================ module.exports = 'A'; ================================================ FILE: test/cjs/multibase/2/b.js ================================================ module.exports = 'B'; ================================================ FILE: test/cjs/nested.js ================================================ if (true) { (function () { require('a'); })(); } if (false) { (function () { var x = 10; switch (x) { case 1 : require('b'); break; default : break; } })() } function qqq () { require ( "c" ); } ================================================ FILE: test/cjs/normal/a.js ================================================ var b = require('./sub/b'); module.exports = 'A'; ================================================ FILE: test/cjs/normal/d.js ================================================ module.exports = 'D'; ================================================ FILE: test/cjs/normal/sub/b.js ================================================ var c = require('./c'); module.exports = 'B'; ================================================ FILE: test/cjs/normal/sub/c.js ================================================ var d = require('../d'); module.exports = 'C'; ================================================ FILE: test/cjs/npm.js ================================================ var a = require('a'); var d = require('./normal/d'); ================================================ FILE: test/cjs/strings.js ================================================ var a = require('a'); var b = require('b'); var c = require('c'); var abc = a.b(c); var EventEmitter = require('events').EventEmitter; var x = require('doom')(5,6,7); x(8,9); c.require('notthis'); var y = require('y') * 100; var EventEmitter2 = require('events2').EventEmitter(); ================================================ FILE: test/cjs/word.js ================================================ var a = load('a'); var b = load('b'); var c = load('c'); var abc = a.b(c); var EventEmitter = load('events').EventEmitter; var x = load('doom')(5,6,7); x(8,9); c.load('notthis'); var y = load('y') * 100; var EventEmitter2 = load('events2').EventEmitter(); ================================================ FILE: test/cjs.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('CommonJS', () => { const dir = __dirname + '/cjs'; it('finds recursive dependencies', (done) => { madge(dir + '/normal/a.js').then((res) => { res.obj().should.eql({ 'a.js': ['sub/b.js'], 'd.js': [], 'sub/b.js': ['sub/c.js'], 'sub/c.js': ['d.js'] }); done(); }).catch(done); }); it('handles path outside directory', (done) => { madge(dir + '/normal/sub/c.js').then((res) => { res.obj().should.eql({ '../d.js': [], 'c.js': ['../d.js'] }); done(); }).catch(done); }); it('finds circular dependencies', (done) => { madge(dir + '/circular/a.js').then((res) => { res.circular().should.eql([ ['a.js', 'd.js'] ]); done(); }).catch(done); }); it('handle extensions when finding circular dependencies', (done) => { madge(dir + '/circular/foo.js').then((res) => { res.circular().should.eql([]); done(); }).catch(done); }); it('excludes core modules by default', (done) => { madge(dir + '/core.js').then((res) => { res.obj().should.eql({ 'core.js': [] }); done(); }).catch(done); }); it('excludes NPM modules by default', (done) => { madge(dir + '/npm.js').then((res) => { res.obj().should.eql({ 'normal/d.js': [], 'npm.js': ['normal/d.js'] }); done(); }).catch(done); }); it('can include shallow NPM modules', (done) => { madge(dir + '/npm.js', { includeNpm: true }).then((res) => { res.obj().should.eql({ 'normal/d.js': [], 'npm.js': ['node_modules/a.js', 'normal/d.js'] }); done(); }).catch(done); }); }); ================================================ FILE: test/es6/absolute/a.js ================================================ import {B} from 'test/es6/absolute/b'; export const A = 'A'; ================================================ FILE: test/es6/absolute/b.js ================================================ export const B = 'B'; ================================================ FILE: test/es6/absolute.js ================================================ import {A} from 'absolute/a'; ================================================ FILE: test/es6/circular/a.js ================================================ import * as B from './b'; ================================================ FILE: test/es6/circular/b.js ================================================ import * as C from './c'; ================================================ FILE: test/es6/circular/c.js ================================================ import * as A from './a'; ================================================ FILE: test/es6/error.js ================================================ if (x) { return; } ================================================ FILE: test/es6/re-export/a.js ================================================ export default 'default export value'; export const named = 'named'; ================================================ FILE: test/es6/re-export/b-default.js ================================================ export someDefault from './a' ================================================ FILE: test/es6/re-export/b-named.js ================================================ export { named } from './a'; ================================================ FILE: test/es6/re-export/b-star.js ================================================ export * from './a' ================================================ FILE: test/es6/re-export/c.js ================================================ import { named } from './b-named' import { someDefault } from './b-default' import star from './b-star' ================================================ FILE: test/es6/webpack/src/sub/abs.js ================================================ ================================================ FILE: test/es6/webpack/src/sub/index.js ================================================ import rel from './rel.js'; ================================================ FILE: test/es6/webpack/src/sub/rel.js ================================================ import abs from 'sub/abs.js'; ================================================ FILE: test/es6/webpack/webpack.config.js ================================================ 'use strict'; const path = require('path'); module.exports = { resolve: { root: path.resolve(__dirname, './src') } }; ================================================ FILE: test/es6.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('ES6', () => { const dir = __dirname + '/es6'; it('extracts dependencies', (done) => { madge(dir + '/absolute.js').then((res) => { res.obj().should.eql({ 'absolute.js': ['absolute/a.js'], 'absolute/a.js': [] }); done(); }).catch(done); }); it('finds circular dependencies', (done) => { madge(dir + '/circular/a.js').then((res) => { res.circular().should.eql([ ['a.js', 'b.js', 'c.js'] ]); done(); }).catch(done); }); it('tackles error in files', (done) => { madge(dir + '/error.js').then((res) => { res.obj().should.eql({ 'error.js': [] }); done(); }).catch(done); }); it('supports export x from "./file"', (done) => { madge(dir + '/re-export/c.js').then((res) => { res.obj().should.eql({ 'a.js': [], 'b-default.js': ['a.js'], 'b-named.js': ['a.js'], 'b-star.js': ['a.js'], 'c.js': [ 'b-default.js', 'b-named.js', 'b-star.js' ] }); done(); }).catch(done); }); it('supports resolve root paths in webpack config', (done) => { madge(dir + '/webpack/src/sub/index.js', { webpackConfig: dir + '/webpack/webpack.config.js' }).then((res) => { res.obj().should.eql({ 'index.js': ['rel.js'], 'abs.js': [], 'rel.js': ['abs.js'] }); done(); }).catch(done); }); }); ================================================ FILE: test/es7/async.js ================================================ import {OTHER} from './other'; async function foo() {} ================================================ FILE: test/es7/other.js ================================================ ================================================ FILE: test/es7.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('ES7', () => { const dir = __dirname + '/es7'; it('extracts dependencies', (done) => { madge(dir + '/async.js').then((res) => { res.obj().should.eql({ 'other.js': [], 'async.js': ['other.js'] }); done(); }).catch(done); }); }); ================================================ FILE: test/flow/cjs/calc.js ================================================ // == calc.js == // import type { Square } from './geometry.js'; var Math = require('./math.js'); var four: number = Math.add(2, 2); ================================================ FILE: test/flow/cjs/geometry.js ================================================ export type Square = { side: number }; ================================================ FILE: test/flow/cjs/math.js ================================================ // == `math.js` == // function add(num1: number, num2: number): number { return num1 + num2; }; // This is how we export the `add()` function in CommonJS exports.add = add; function sub(num1, num2) { return num1 - num2; } var two: number = add(1, 2); var one: number = sub(2, 1); ================================================ FILE: test/flow/es/calc.js ================================================ import {add} from "./math.js"; var four: number = add(2, 2); ================================================ FILE: test/flow/es/math.js ================================================ // == `math.js` == // // This function is exported, so it's available for other modules to import export function add(num1: number, num2: number): number { return num1 + num2; }; // This function isn't exported, so it's only available in the local scope // of this module function sub(num1, num2) { return num1 - num2; } // Note that we can use both exported and non-exported items within this // module var two: number = add(1, 2); var one: number = sub(2, 1); ================================================ FILE: test/flow.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('Flow', () => { const dir = __dirname + '/flow'; it('extracts ES module ependencies', (done) => { madge(dir + '/es/calc.js').then((res) => { res.obj().should.eql({ 'math.js': [], 'calc.js': ['math.js'] }); done(); }).catch(done); }); it('extracts CommonsJS module dependencies', (done) => { madge(dir + '/cjs/calc.js').then((res) => { res.obj().should.eql({ 'geometry.js': [], 'calc.js': ['geometry.js'] }); done(); }).catch(done); }); it('extracts CommonsJS module dependencies with mixed import syntax', (done) => { madge(dir + '/cjs/calc.js', {detectiveOptions: {es6: {mixedImports: true}}}).then((res) => { res.obj().should.eql({ 'geometry.js': [], 'math.js': [], 'calc.js': ['geometry.js', 'math.js'] }); done(); }).catch(done); }); }); ================================================ FILE: test/git/.git_tmp/d.js ================================================ ================================================ FILE: test/git/a.js ================================================ require('./b'); require('./c'); require('./.git/d'); ================================================ FILE: test/git/b.js ================================================ require('./c'); ================================================ FILE: test/git/c.js ================================================ ================================================ FILE: test/jsx/basic.jsx ================================================ import React from 'react'; import other from './other.jsx'; export default React.createClass({ render: function() { return
foo {this.props.children}
} }); ================================================ FILE: test/jsx/other.jsx ================================================ export default 'other'; ================================================ FILE: test/jsx.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('JSX', () => { const dir = __dirname + '/jsx'; it('finds import in JSX files', (done) => { madge(dir + '/basic.jsx').then((res) => { res.obj().should.eql({ 'basic.jsx': ['other.jsx'], 'other.jsx': [] }); done(); }).catch(done); }); }); ================================================ FILE: test/output.sh ================================================ #!/bin/bash make_title() { printf '\033[01;38;5;022m############### %s ###############\033[0m\n' "$1" } make_title "LIST" ./bin/cli.js lib/api.js make_title "SUMMARY" ./bin/cli.js lib/api.js -s make_title "DEPENDS" ./bin/cli.js lib/api.js -d log.js make_title "CIRCULAR (OK)" ./bin/cli.js test/cjs/a.js -c make_title "CIRCULAR (FOUND, NO INDEX COUNTING)" ./bin/cli.js test/cjs/circular/a.js -c --no-count make_title "CIRCULAR (FOUND, WITH INDEX COUNT)" ./bin/cli.js test/cjs/circular/a.js -c make_title "NPM" ./bin/cli.js test/cjs/npm.js --include-npm make_title "STDIN" ./bin/cli.js --json lib/api.js | tr '[a-z]' '[A-Z]' | ./bin/cli.js --stdin make_title "IMAGE" ./bin/cli.js lib/api.js --image /tmp/test.svg make_title "DOT" ./bin/cli.js lib/api.js --dot make_title "JSON" ./bin/cli.js lib/api.js --json make_title "NO COLOR" ./bin/cli.js lib/api.js --no-color make_title "SHOW EXTENSION" ./bin/cli.js lib/api.js --show-extension make_title "WARNINGS (NOTE)" ./bin/cli.js test/cjs/missing.js -c make_title "WARNINGS (LIST)" ./bin/cli.js test/cjs/missing.js -c --warning make_title "ERROR" ./bin/cli.js file/not/found.js make_title "DEBUG" ./bin/cli.js lib/log.js --debug exit 0 ================================================ FILE: test/typescript/custom-paths/import.ts ================================================ import heading from '@shortcut/require'; import fortyTwo from './subfolder'; class ImportClass { constructor(public greeting: string) { } greet() { return "

" + this.greeting + "

"; } }; ================================================ FILE: test/typescript/custom-paths/subfolder/index.ts ================================================ export default 42; ================================================ FILE: test/typescript/custom-paths/subfolder/require.tsx ================================================ import x from '@shortcut2/export'; export default function(props) { return

{props.children}

} ================================================ FILE: test/typescript/custom-paths/subfolder2/export.ts ================================================ class ExportClass { stringLength(s: string) { return s.length; } } export default ExportClass; ================================================ FILE: test/typescript/export-x.tsx ================================================ export default function(props) { return {props.children} } ================================================ FILE: test/typescript/export.ts ================================================ class ExportClass { stringLength(s: string) { return s.length; } } export default ExportClass; ================================================ FILE: test/typescript/import.ts ================================================ import B from './require'; import heading from './require-x'; class ImportClass { constructor(public greeting: string) { } greet() { return "

" + this.greeting + "

"; } }; ================================================ FILE: test/typescript/mixed.ts ================================================ require('./export'); import './export-x'; ================================================ FILE: test/typescript/require-x.tsx ================================================ import * as x from './export'; import SpanWrapper from './export-x'; export default function(props) { return

{props.children}

} ================================================ FILE: test/typescript/require.ts ================================================ import x = require('./export'); export default class RequireClass { stringLength(s: string) { return s.length; } } ================================================ FILE: test/typescript/with-config/index.ts ================================================ ================================================ FILE: test/typescript/with-config/tsconfig.base.json ================================================ { "compilerOptions": { "target": "ES5", "module": "CommonJS" } } ================================================ FILE: test/typescript/with-config/tsconfig.json ================================================ { "extends": "./tsconfig.base.json", "compilerOptions": { "target": "ESNext", "allowJs": true } } ================================================ FILE: test/typescript.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); const ts = require('typescript'); require('should'); describe('TypeScript', () => { const dir = __dirname + '/typescript'; it('extracts module dependencies', (done) => { madge(dir + '/import.ts').then((res) => { res.obj().should.eql({ 'import.ts': ['require-x.tsx', 'require.ts'], 'require.ts': ['export.ts'], 'require-x.tsx': ['export-x.tsx', 'export.ts'], 'export.ts': [], 'export-x.tsx': [] }); done(); }).catch(done); }); it('reads paths from a custom tsConfig', (done) => { const tsConfig = { compilerOptions: { baseUrl: dir, moduleResolution: 'node', paths: { '@shortcut/*': ['custom-paths/subfolder/*'], '@shortcut2/*': ['custom-paths/subfolder2/*'] } } }; madge(dir + '/custom-paths/import.ts', {tsConfig: tsConfig}).then((res) => { res.obj().should.eql({ 'import.ts': ['subfolder/index.ts', 'subfolder/require.tsx'], 'subfolder/index.ts': [], 'subfolder/require.tsx': ['subfolder2/export.ts'], 'subfolder2/export.ts': [] }); done(); }).catch(done); }); it('got tsConfig as a string, "extends" field is interpreted', (done) => { madge(dir + '/custom-paths/import.ts', {tsConfig: dir + '/with-config/tsconfig.json'}).then((res) => { res.config.tsConfig.should.eql({ extends: './tsconfig.base.json', compilerOptions: { target: ts.ScriptTarget.ESNext, module: ts.ModuleKind.CommonJS, allowJs: true, configFilePath: undefined } }); done(); }).catch(done); }); it('supports CJS modules when using mixedImports option', (done) => { madge(dir + '/mixed.ts', {detectiveOptions: {ts: {mixedImports: true}}}).then((res) => { res.obj().should.eql({ 'export-x.tsx': [], 'export.ts': [], 'mixed.ts': ['export-x.tsx', 'export.ts'] }); done(); }).catch(done); }); }); ================================================ FILE: test/vue/BasicComponent.vue ================================================ ================================================ FILE: test/vue/BasicComponentTs.vue ================================================ ================================================ FILE: test/vue/OneNested.vue ================================================ ================================================ FILE: test/vue/OneNestedTs.vue ================================================ ================================================ FILE: test/vue/ThreeNested.vue ================================================ ================================================ FILE: test/vue/TwoNested.vue ================================================ ================================================ FILE: test/vue/one.ts ================================================ // no content ================================================ FILE: test/vue/two.js ================================================ // no content ================================================ FILE: test/vue.js ================================================ /* eslint-env mocha */ 'use strict'; const madge = require('../lib/api'); require('should'); describe('Vue', () => { const dir = __dirname + '/vue'; // this seems necessary to run the tests successfully const emptyTsConfig = {compilerOptions: {}}; it('finds import in Vue files using TS', (done) => { madge(dir + '/BasicComponentTs.vue', {tsConfig: emptyTsConfig}).then((res) => { res.obj().should.eql({ 'one.ts': [], 'BasicComponentTs.vue': ['OneNestedTs.vue', 'TwoNested.vue'], 'OneNestedTs.vue': ['ThreeNested.vue', 'one.ts'], 'ThreeNested.vue': [], 'TwoNested.vue': [] }); done(); }).catch(done); }); it('finds import in Vue files', (done) => { madge(dir + '/BasicComponent.vue', {tsConfig: emptyTsConfig}).then((res) => { res.obj().should.eql({ 'two.js': [], 'BasicComponent.vue': ['OneNested.vue', 'TwoNested.vue'], 'OneNested.vue': ['ThreeNested.vue', 'two.js'], 'ThreeNested.vue': [], 'TwoNested.vue': [] }); done(); }).catch(done); }); });