{"id":15117145,"url":"https://github.com/codemodsquad/jscodeshift-add-imports","last_synced_at":"2025-08-05T06:11:55.807Z","repository":{"id":38175921,"uuid":"188081504","full_name":"codemodsquad/jscodeshift-add-imports","owner":"codemodsquad","description":"add imports/requires if not already present with jscodeshift","archived":false,"fork":false,"pushed_at":"2024-07-19T16:40:34.000Z","size":1443,"stargazers_count":26,"open_issues_count":23,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-28T09:45:54.132Z","etag":null,"topics":["codemods","imports","jscodeshift","refactoring"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/codemodsquad.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-22T17:07:55.000Z","updated_at":"2024-12-19T15:12:57.000Z","dependencies_parsed_at":"2025-07-10T05:05:33.231Z","dependency_job_id":null,"html_url":"https://github.com/codemodsquad/jscodeshift-add-imports","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/codemodsquad/jscodeshift-add-imports","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-add-imports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-add-imports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-add-imports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-add-imports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codemodsquad","download_url":"https://codeload.github.com/codemodsquad/jscodeshift-add-imports/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codemodsquad%2Fjscodeshift-add-imports/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268844815,"owners_count":24316055,"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","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["codemods","imports","jscodeshift","refactoring"],"created_at":"2024-09-26T01:45:51.025Z","updated_at":"2025-08-05T06:11:55.770Z","avatar_url":"https://github.com/codemodsquad.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# jscodeshift-add-imports\n\n[![CircleCI](https://circleci.com/gh/codemodsquad/jscodeshift-add-imports.svg?style=svg)](https://circleci.com/gh/codemodsquad/jscodeshift-add-imports)\n[![Coverage Status](https://codecov.io/gh/codemodsquad/jscodeshift-add-imports/branch/master/graph/badge.svg)](https://codecov.io/gh/codemodsquad/jscodeshift-add-imports)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/jscodeshift-add-imports.svg)](https://badge.fury.io/js/jscodeshift-add-imports)\n\nEasily add import and require statements with jscodeshift. If something is already\nimported, returns the locally bound identifier, and avoids name conflicts.\n\n# Usage\n\n```\nnpm install --save jscodeshift-add-imports\n```\n\n```js\nconst j = require('jscodeshift')\nconst addImports = require('jscodeshift-add-imports')\n\nconst { statement } = j.template\n\nconst code = `\n// @flow\nimport {foo, type bar} from 'foo'\nimport baz from 'baz'\n`\n\nconst root = j(code)\nconst result = addImports(root, [\n  statement`import type {bar, baz} from 'foo'`,\n  statement`import blah, {type qux} from 'qux'`,\n])\nconsole.log(result)\nconsole.log(root.toSource())\n```\n\nOutput code:\n\n```js\n// @flow\nimport { foo, type bar } from 'foo'\nimport baz from 'baz'\nimport type { baz as baz1 } from 'foo'\nimport blah, { type qux } from 'qux'\n```\n\nReturn value:\n\n```js\n{\n  bar: 'bar',\n  baz: 'baz1',\n  blah: 'blah',\n  qux: 'qux',\n}\n```\n\n# Compatibility\n\nCurrently tested on `jscodeshift@0.11.0` with the following parsers:\n\n- `babylon`\n- `ts`\n\nThere are currently issues with the `babel` and `flow` parsers.\n\nIt won't likely work with other custom parsers unless they output nodes in the same format as\nBabel for import declarations, variable declarations, require calls, and object patterns.\n\n# `addImports(root, statments)`\n\n## Arguments\n\n### `root`\n\nThe jscodeshift-wrapped AST of your source code\n\n### `statements`\n\nThe AST of an import declaration or variable declaration with requires to add,\nor an array of them.\n\n## Return value\n\nAn object where the key is the local identifier you requested in `statements`,\nand the value is the resulting local identifier used in the modified\ncode (which could be the existing local identifier already imported in the code or\nthe local identifier chosen to avoid name conflicts with an existing binding)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemodsquad%2Fjscodeshift-add-imports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodemodsquad%2Fjscodeshift-add-imports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodemodsquad%2Fjscodeshift-add-imports/lists"}