Giter Club home page Giter Club logo

async-migrator's Introduction

async migrator

REUSE status

About this project

Use it to migrate a JavaScript project source code to async-await model by replacing sync function calls to await statements. The list of functions that must be replaced is configurable.

Example source code:

var conn = $.hdb.getConnection();
var result = conn.execute('select * from MY_TABLE');

It will be migrated to:

var conn = await $.hdb.getConnection();
var result = await conn.execute('select * from MY_TABLE');

Use cases

A typical use case, for example, is a sync program using fibers or fibrous. Since they are not working in Node 16+, this implies a big problem to JS projects willing to run on Node 16+. There's a good logical reason for these packages to not be supported by Node.js anymore: the async-await programming model is implemented in Node 16+ and works like a charm.

The async-await programming model gives the development experience of a sync programs - short, logical workflow, no callbacks, without complex workarounds like using fibers/fibrous, and without killing performace with blocking sync functions.

Another use case could be to replace a blocking sync function (which is blocking in C-layer) with an async-await function. For example:

  • fs.readFile - this function has a callback
  • fs.readFileSync - this function is convenient but blocking
  • fs.promises.readFile - this function is both convenient and non-blocking, i.e. based on the async-await programming model

How to use the migrator

In the command line, execute:

node src/index.js <source directory> <target directory> --map <function map JSON>

The function map JSON is a simple string (string map), which maps a sync function name to an async function name. There is no "default" function map, since that is very project specific.

Samples

Each sample migration shall have a specific functionmap.json Check sampes in the samples/ folder.

Requirements and Setup

Required is Node.js runtime version 14 or higher.

git clone https://github.com/SAP/async-migrator.git
cd async-migrator
npm install . 

Support, Feedback, Contributing

This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.

Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright (c)2023 SAP SE or an SAP affiliate company and contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

async-migrator's People

Contributors

szeort avatar priyankashivakumar avatar annaaal avatar christianneu avatar ospo-bot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.