{"id":13532239,"url":"https://github.com/sgilroy/async-await-codemod","last_synced_at":"2025-04-01T20:31:40.294Z","repository":{"id":46945323,"uuid":"139923461","full_name":"sgilroy/async-await-codemod","owner":"sgilroy","description":"Codemod script for migrating promise-based functions to use async/await syntax ","archived":false,"fork":false,"pushed_at":"2022-12-07T20:41:13.000Z","size":1086,"stargazers_count":29,"open_issues_count":18,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-02T19:34:02.558Z","etag":null,"topics":["async","async-await","codemod","es2017","es8","jscodeshift"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sgilroy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-06T02:30:00.000Z","updated_at":"2024-07-25T23:53:22.000Z","dependencies_parsed_at":"2023-01-24T22:16:18.526Z","dependency_job_id":null,"html_url":"https://github.com/sgilroy/async-await-codemod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgilroy%2Fasync-await-codemod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgilroy%2Fasync-await-codemod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgilroy%2Fasync-await-codemod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sgilroy%2Fasync-await-codemod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sgilroy","download_url":"https://codeload.github.com/sgilroy/async-await-codemod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246709923,"owners_count":20821297,"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":["async","async-await","codemod","es2017","es8","jscodeshift"],"created_at":"2024-08-01T07:01:09.326Z","updated_at":"2025-04-01T20:31:35.281Z","avatar_url":"https://github.com/sgilroy.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"## async-await-codemod\n\n[![Build Status](https://img.shields.io/travis/sgilroy/async-await-codemod.svg?style=flat-square)](https://travis-ci.org/sgilroy/async-await-codemod) [![Code Style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\nThis repository contains a codemod script for use with\n[JSCodeshift](https://github.com/facebook/jscodeshift) that migrates promise-based functions to use async/await syntax.\n\nThe excellent [sinon-codemod](https://github.com/hurrymaplelad/sinon-codemod) repository was used as inspiration and served as a template for this repository.\n\nThis codemod is based in part on work done by @cpojer https://github.com/cpojer/js-codemod/pull/49/commits/19ed546d8a47127d3d115f933d924106c98e1b8b\nand the further work of @cassilup https://github.com/cassilup/async-await-codemod-demo\n\n### Setup \u0026 Run\n\n- `npm install -g jscodeshift`\n- `git clone https://github.com/sgilroy/async-await-codemod.git` or download a zip file\n  from `https://github.com/sgilroy/async-await-codemod/archive/master.zip`\n- Run `npm install` in the async-await-codemod directory\n  - Alternatively, run [`yarn`](https://yarnpkg.com/) to install in the\n    async-await-codemod directory\n- `jscodeshift -t \u003ccodemod-script\u003e \u003cpath\u003e`\n- Use the `-d` option for a dry-run and use `-p` to print the output\n  for comparison\n\n### async-await\n\nES2017 natively supports a special syntax for working with promises called \"async/await\".\n\nWith promises:\n\n```js\nfunction makeRequest() {\n  return getJSON().then(data =\u003e {\n    console.log(data);\n    return 'done';\n  });\n}\n```\n\nWith async/await:\n\n```js\nasync function makeRequestFunction() {\n  const data = await getJSON();\n  console.log(data);\n  return 'done';\n}\n```\n\n### Included Scripts\n\n#### `async-await`\n\nConverts each asynchronous function (a function which contains a `.then()` call) to `async`, and uses `await` instead\nof `.then()` to simplify the behavior of using promises synchronously.\n\n```sh\njscodeshift -t async-await-codemod/async-await.js \u003cpath\u003e\n```\n\n#### `await-promise-chain`\n\nUnravels chained promise calls of the style `foo.then().then()` as multiple `await` calls. Note that this changes the\nstructure and scope of blocks of code and can thus result in different behavior, such as by variables being in scope\nthat otherwise would not.\n\nThis should generally be used after the `async-await` codemod, and the changes should be examined and tested carefully\nto avoid unwanted bugs or subtle problems.\n\n```sh\njscodeshift -t async-await-codemod/await-promise-chain.js \u003cpath\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgilroy%2Fasync-await-codemod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsgilroy%2Fasync-await-codemod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsgilroy%2Fasync-await-codemod/lists"}