{"id":22423284,"url":"https://github.com/prantlf/requirejs-dependencies","last_synced_at":"2025-10-15T21:15:48.748Z","repository":{"id":57354403,"uuid":"267264930","full_name":"prantlf/requirejs-dependencies","owner":"prantlf","description":"Finds direct and indirect dependencies of one or more RequireJS modules.","archived":false,"fork":false,"pushed_at":"2020-07-03T07:23:15.000Z","size":295,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-03T01:46:15.221Z","etag":null,"topics":["amd","amdjs","dependencies","module","requirejs","trace","tracer"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-27T08:33:19.000Z","updated_at":"2020-07-03T07:21:50.000Z","dependencies_parsed_at":"2022-09-12T06:00:44.110Z","dependency_job_id":null,"html_url":"https://github.com/prantlf/requirejs-dependencies","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Frequirejs-dependencies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Frequirejs-dependencies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Frequirejs-dependencies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Frequirejs-dependencies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/requirejs-dependencies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791897,"owners_count":20672667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amd","amdjs","dependencies","module","requirejs","trace","tracer"],"created_at":"2024-12-05T18:09:52.676Z","updated_at":"2025-10-06T02:33:50.316Z","avatar_url":"https://github.com/prantlf.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# requirejs-dependencies\n\n[![npm](https://img.shields.io/npm/v/requirejs-dependencies)](https://www.npmjs.com/package/requirejs-dependencies#top)\n[![Build Status](https://travis-ci.org/prantlf/requirejs-dependencies.svg?branch=master)](https://travis-ci.org/prantlf/requirejs-dependencies)\n[![Dependency Status](https://david-dm.org/prantlf/requirejs-dependencies.svg)](https://david-dm.org/prantlf/requirejs-dependencies)\n[![devDependency Status](https://david-dm.org/prantlf/requirejs-dependencies/dev-status.svg)](https://david-dm.org/prantlf/requirejs-dependencies#info=devDependencies)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nFinds direct and indirect dependencies of a RequireJS module. Can be used to find all or only common dependencies of more modules, for example:\n\n```\nrequirejs-dependencies -r src -c src/config.js --common src/store src/shell\n```\n\nThis package supports RequireJS specifics like plugins and bundles. If multiple bundles are used, dependencies between bundles can be represented by imploding modules from a single bundle to the single bundle name in the traced output.\n\n## Synopsis\n\n```\n$ requirejs-dependencies -r src -c src/config.js src/main\nsrc/main.js\nsrc/utils.js\nsrc/main traced in 5.742ms\n```\n\n```js\nimport { traceSingle } from 'requirejs-dependencies'\nconst { traced } = await traceSingle({\n  module: 'src/main', rootDir: 'src', config: 'src/config.js'\n})\nfor (const { id } of traced) console.log(id)\n// Prints src/main.js and src/utils.js\n```\n\n## Installation\n\nIf you want to use the command-line tool, install this package globally using your package manager:\n\n```\nnpm i -g requirejs-dependencies\nyarn global add requirejs-dependencies\npnpm i -g requirejs-dependencies\n```\n\nIf you want to use this package programmatically, install it locally using your package manager:\n\n```\nnpm i requirejs-dependencies\nyarn add requirejs-dependencies\npnpm i requirejs-dependencies\n```\n\nIf you want to render graphs to `png` on the command line, install the peer dependency `canvas` in the same way as you did the module `requirejs-dependencies` above.\n\nIf you want to use the web application (argument `--serve`) install the peer dependency `graphviz-webcomponent` in the same way as you did the module `requirejs-dependencies` above.\n\n## API\n\n### traceSingle(options: object): Promise\\\u003cobject\\\u003e\n\nFinds direct and indirect dependencies of a RequireJS module.\n\n```js\nimport { traceSingle } from 'requirejs-dependencies'\nconst { traced, time } = await traceSingle({\n  module: 'src/main', rootDir: 'src', config: 'src/config.js'\n})\nfor (const { id, path, deps, dependents } of traced) { ... }\n```\n\nAvailable options:\n\n|  name             |  type    | description                                     |\n|-------------------|----------|-------------------------------------------------|\n| `module`          | `string` | module name recognized by RequireJS (mandatory) |\n| `rootDir`         | `string` | source root directory (mandatory)               |\n| `config`          | `string` | configuration file for RequireJS (optional)     |\n\nPromised result properties:\n\n|  name     |  type      | description                                |\n|-----------|------------|--------------------------------------------|\n| `traced`  | `object[]` | list of dependencies                       |\n| `time`    | `number`   | time needed to trace the dependencies [ms] |\n\nProperties of a dependency:\n\n|  name        |  type      | description                                    |\n|--------------|------------|------------------------------------------------|\n| `id`         | `string`   | module name used in `define()` or `require()`  |\n| `path`       | `string`   | path to the module in the file system          |\n| `deps`       | `string[]` | dependencies of the module (optional)          |\n| `dependents` | `string[]` | dependents of the module (optional)            |\n\n### traceMany(options: object): Promise\\\u003cobject\\\u003e\n\nFinds direct and indirect dependencies for more a RequireJS modules.\n\n```js\nimport { traceMany } from 'requirejs-dependencies'\nconst { traced, time } = await traceMany({\n  modules: ['src/store', 'src/shell'], rootDir: 'src', config: 'src/config.js'\n})\nfor (const { id, path, deps, dependents } of traced['src/store']) { ... }\nfor (const { id, path, deps, dependents } of traced['src/shell']) { ... }\n```\n\nAvailable options:\n\n|  name     |  type      | description                                      |\n|-----------|------------|--------------------------------------------------|\n| `modules` | `string[]` | module names recognized by RequireJS (mandatory) |\n\nOther options are the same as for [`traceSingle`], except for the missing `module`.\n\nPromised result properties:\n\n|  name     |  type    | description                                |\n|-----------|----------|--------------------------------------------|\n| `traced`  | `object` | map of module names and their dependencies |\n| `time`    | `number` | time needed to trace the dependencies [ms] |\n\nThe `traced` object contains input module names as keys and arrays of their dependencies as values. The array of the dependencies is the same as `traced` from the promised properties from [`traceSingle`].\n\n### getUnion (manyModules: object[][] | object{[key: string]: object[]}): object[]\n\nReturns an array of distinct dependencies after dropping duplicates from the input. The input can be either array of arrays of dependencies, or an object, where keys are module names and values arrays of dependencies. A single array of the dependencies is the same as `traced` from the promised properties from [`traceSingle`].\n\n```js\nimport { traceMany } from 'requirejs-dependencies'\nlet { traced, time } = await traceMany({\n  modules: ['src/store', 'src/shell'], rootDir: 'src', config: 'src/config.js'\n})\nfor (const { id, path, deps, dependents } of getUnion(traced)) { ... }\n```\n\n### getIntersection (manyModules: object[][] | object{[key: string]: object[]}): object[]\n\nReturns an array of modles that each input module depends on, directly or indirectly. The input can be either array of arrays of dependencies, or an object, where keys are module names and values arrays of dependencies. A single array of the dependencies is the same as `traced` from the promised properties from [`traceSingle`].\n\n```js\nimport { traceMany } from 'requirejs-dependencies'\nlet { traced, time } = await traceMany({\n  modules: ['src/store', 'src/shell'], rootDir: 'src', config: 'src/config.js'\n})\nfor (const { id, path, dependents } of getIntersection(traced)) { ... }\n```\n\n### implodeBundleDependencies (options: object): object[]\n\nReplaces module names in module dependencies with parent bundle names of the particular modules. Then the dependencies are pruned so that each bundle occurs only once there. An array of the dependencies is the same as `traced` from the promised properties from [`traceSingle`]. The parameter `bundles` is in the same format as the bundle configuration for RequireJS. The parameter `tracedBundle` is necessary if the parameter `traced` is just an array of traced dependencies without information what is the current bundle.\n\nAvailable options:\n\n|  name                  |  type                                        | description                  |\n|------------------------|----------------------------------------------|-----------------------------|\n| `traced`               | `object[] | object{[key: string]: object[]}` | output of `traceSingle` or `traceMany` |\n| `bundles`              | `object{[key: string]: string[]}`            | bundle configuration for RequireJS  |\n| `explodeBundles`       | `string[]` | bundles that should be exploded to modules (optional) |\n| `implodeCurrentBundle` | `boolean`  | hide module dependencies from the same bundle (optional) |\n| `tracedBundle`         | `string`   | parent bundle of plain array of traced modules (optional) |\n\n```js\nimport { traceSingle } from 'requirejs-dependencies'\nlet { traced, config, time } = await traceSingle({\n  module: 'src/store', rootDir: 'src', config: 'src/config.js'\n})\ntraced = implodeBundleDependencies({\n  traced, bundles: config.bundles, tracedBundle: 'src/data'\n})\nfor (const { id, path, dependents } of traced) { ... }\n```\n\n### function loadConfig (path: string): object\n\nReturns the RequiteJS configuration as an object. The configuration is usually set by a `require.config` statement in a separate file. It is not exported from the file. This method extracts it without applying it to global RequireJS.\n\n```js\nimport trace from 'amodro-trace'\nimport { loadConfig } from 'requirejs-dependencies'\nconst config = loadConfig(config)\nconst { traced } = await trace({ id, rootDir }, config)\nfor (const { id } of traced) console.log(id)\n```\n\n### function formatMilliseconds (duration: number): string\n\nFormats a number of milliseconds to a readable duration as a string.\n\n```js\nimport { traceSingle, formatMilliseconds } from 'requirejs-dependencies'\nconst { traced, time } = await traceSingle({\n  module: 'src/main', rootDir: 'src', config: 'src/config.js'\n})\nfor (const { id } of traced) console.log(id)\nconsole.log(`\"src/main\" traced in ${formatMilliseconds(time)}`)\n```\n\n## Command-line\n\n```\n$ requirejs-dependencies -h\n\nPrints direct and indirect dependencies of one or more RequireJS modules.\n\nUsage: requirejs-dependencies [option...] \u003cmodule\u003e...\n\nOptions:\n  -r|--rootdir \u003cpath\u003e       source root directory\n  -c|--config \u003cpath\u003e        configuration file for RequireJS\n  --serve                   start server for interactive module inspection\n  --implode-bundles         print bundles as dependencies instead of modules\n  --explode-bundles \u003clist\u003e  specify bundles which modules will remain listed\n  --implode-current-bundle  do not list dependencies from the same bundle\n  -l|--layout layout        graph layout (dot,neato,fdp,twopi,circo,osage)\n  --emphasize-directs       render direct dependencies with different colour\n  --cluster-directs         cluster direct dependencies together\n  --common                  print only common dependencies for more modules\n  --tree                    print module dependencies as a tree\n  --image \u003cpath\u003e            generate image with dependency graph\n  -V|--version              print version number\n  -h|--help                 print usage instructions\n\nIf you enable the option implode-bundles, you need to include bundles\nin your config, so that relations module \u003c--\u003e bundle can be built.\n\nIf no arguments are provided, usage instructions will be printed out.\nErrors and timing are printed on standard error. Dependencies, usage\ninstructions and version number are printed on standard output.\n\nA non-zero exit code is returned in case of error.\n\nExamples:\n  requirejs-dependencies -r src -c src/config.js src/main\n  requirejs-dependencies -r src --common src/store src/shell\n```\n\n## License\n\nCopyright (c) 2020 Ferdinand Prantl\n\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Frequirejs-dependencies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Frequirejs-dependencies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Frequirejs-dependencies/lists"}