{"id":24548248,"url":"https://github.com/qwerqy/scan-imports","last_synced_at":"2025-04-15T18:42:15.849Z","repository":{"id":190838166,"uuid":"683447588","full_name":"qwerqy/scan-imports","owner":"qwerqy","description":"Node.js package designed to extract and analyze import statements from TypeScript and TypeScript JSX files. It provides a simple and efficient way to scan your codebase for import declarations, making it useful for various code analysis and refactoring tasks.","archived":false,"fork":false,"pushed_at":"2025-01-29T10:44:36.000Z","size":114,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T05:40:01.508Z","etag":null,"topics":["cli","imports","javascript","node","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/qwerqy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-26T15:54:01.000Z","updated_at":"2025-02-13T14:08:59.000Z","dependencies_parsed_at":"2023-08-27T10:20:52.825Z","dependency_job_id":null,"html_url":"https://github.com/qwerqy/scan-imports","commit_stats":null,"previous_names":["qwerqy/import-scanner","qwerqy/scan-imports"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwerqy%2Fscan-imports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwerqy%2Fscan-imports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwerqy%2Fscan-imports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwerqy%2Fscan-imports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qwerqy","download_url":"https://codeload.github.com/qwerqy/scan-imports/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249131112,"owners_count":21217673,"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":["cli","imports","javascript","node","typescript"],"created_at":"2025-01-22T23:16:37.996Z","updated_at":"2025-04-15T18:42:15.827Z","avatar_url":"https://github.com/qwerqy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Import Scanner 🕵️‍♀️\n\nThe **Import Scanner** is a Node.js package designed to extract and analyze\nimport statements from TypeScript and TypeScript JSX files. It provides a simple\nand efficient way to scan your codebase for import declarations, making it\nuseful for various code analysis and refactoring tasks.\n\n## Installation\n\n`scan-imports` does not require you to install locally to your node modules.\nJust run\n\n```bash\nnpx scan-imports@latest scan -d \u003cdirectory\u003e -i \u003cimportModule\u003e -ext \u003cfileExtension\u003e\n```\n\n## Usage\n\n| Argument                | Description                                                                                                             | Default Value | Required |\n| ----------------------- | ----------------------------------------------------------------------------------------------------------------------- | ------------- | -------- |\n| `-d` or `--directory`   | The directory to scan for import statements.                                                                            | -             | Yes      |\n| `-i` or `--import`      | The import module to search for.                                                                                        | -             | Yes      |\n| `-ext` or `--extension` | The file extension to scan for. Separate by commas for multiple extensions                                              | `.ts`         | No       |\n| `-det` or `--details`   | Whether to show details of the import statements.                                                                       | `false`       | No       |\n| `-a` or `--alpha`       | By default results are **sorted by count**. But if you want it to sort alphabetically, add a `--alpha` flag statements. | `false`       | No       |\n| `-f` or `--format`      | The format of the output. Currently only supports `json` and `csv`. Using this flag will automatically export to a file | -             | No       |\n\n## Example\n\nIf I run this command in the root directory of this project:\n\n```bash\nnpx scan-imports@latest scan -d src -i fs -ext .tsx,.ts\n```\n\nI will get the following output:\n\n```bash\nFound 2 files with \"fs\" imports across directory /Users/aminroslan/Projects/scan-imports/src:\n{\n  \"default\": {\n    \"fs\": 2\n  },\n  \"named\": {}\n}\n\n```\n\nI can see that there are 2 files that import `fs` from the `src` directory.\n\nIf I need more information about each import statement, I can add the `-det` or\n`--details` flag to the command:\n\n```bash\nscan -d src -i fs -ext .tsx,.ts -det\n```\n\nThis will give me the following output:\n\n```bash\nFound 2 files with \"fs\" imports across directory /Users/aminroslan/Projects/scan-imports/src:\n{\n  \"default\": {\n    \"fs\": 2\n  },\n  \"named\": {}\n}\n[\n  {\n    \"path\": \"/Users/aminroslan/Projects/scan-imports/src/utils/file-contains-import.ts\",\n    \"statement\": \"import fs from 'fs'\",\n    \"hasDefault\": true,\n    \"hasNamed\": false,\n    \"defaultImport\": \"fs\",\n    \"namedImports\": []\n  },\n  {\n    \"path\": \"/Users/aminroslan/Projects/scan-imports/src/utils/scan-directories.ts\",\n    \"statement\": \"import fs from 'fs'\",\n    \"hasDefault\": true,\n    \"hasNamed\": false,\n    \"defaultImport\": \"fs\",\n    \"namedImports\": []\n  }\n]\n```\n\nNow, I can see that both files import the default export from `fs`.\n\n### Exporting to a file\n\nIf `-f` or `--format` is specified, the output will be exported to a file. The\noutput will look like this:\n\n#### CSV\n\n```csv\nname, usage\nfs, 4\nappendFileSync, 1\n```\n\n#### JSON\n\n```json\n{\n\t\"fs\": 4,\n\t\"appendFileSync\": 1\n}\n```\n\nYou can set `-det` or `--details` to `true` to get more details about the import\nstatements, but the output will only be in JSON format.\n\n## Development\n\nTo execute the script locally, run:\n\n```bash\n# Install dependencies\nyarn\n\n# Run dev script to compile TypeScript and watch for changes\nyarn dev\n\n# Execute the script\nnode dist/index.js scan -d src -i fs -ext .tsx,.ts\n```\n\n## Contributing\n\nIf you have any ideas for improvements or find any bugs, please feel free to\nopen an issue or submit a pull request. 😀\n\n## License\n\nThis project is licensed under the MIT License - see the\n[LICENSE.md](LICENSE.md) file for details.\n\n## Todo\n\nTBD.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqwerqy%2Fscan-imports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqwerqy%2Fscan-imports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqwerqy%2Fscan-imports/lists"}