Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-redux-saga

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-redux-saga

Babel plugin for code instrumenting by extending `redux-saga` code fragments with additional meta-data. Meta-data contains information about code fragment location and other details, that could be consumed by developer tools or libraries. Adding the plugi

  • 1.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.6K
decreased by-6.37%
Maintainers
3
Weekly downloads
 
Created
Source

NOTE: plugin is still in beta, so use it on your own risk. It does not work on React Native

Babel plugin for code instrumenting by extending redux-saga code fragments with additional meta-data. Meta-data contains information about code fragment location and other details, that could be consumed by developer tools or libraries. Adding the plugin improve logging for errors thrown in your sagas. Example of setup and demo are available here

Example

Error message without plugin

The above error occurred in task throwAnErrorSaga
    created by errorInCallAsyncSaga
    created by takeEvery(ACTION_ERROR_IN_CALL_ASYNC, errorInCallAsyncSaga)
    created by rootSaga

Error message with the plugin

The above error occurred in task throwAnErrorSaga  src/sagas/index.js?16
    created by errorInCallAsyncSaga  src/sagas/index.js?25
    created by takeEvery(ACTION_ERROR_IN_CALL_ASYNC, errorInCallAsyncSaga)
    created by rootSaga  src/sagas/index.js?78

Install

npm i --save-dev babel-plugin-redux-saga

Usage

  1. with babel
    plugins: [
        'babel-plugin-redux-saga'
    ]
  1. with webpack and babel-loader:
    loader: 'babel-loader',
    options: {
        plugins: [
            'babel-plugin-redux-saga'
        ]
    }

Options

All options are optional.

useAbsolutePath
  • Type: Boolean
  • Default: false

By default plugin generates relative to the current cwd file paths. But for some reasons absolute path may be required, for such cases configure useAbsolutePath option. For example, if option is not set:

    fileName: "path/to/filename.js"

But if useAbsolutePath is set to true,

    fileName: "/Users/name/git/project/path/to/filename.js"

How it transforms my code

Source:

// src/sagas/index.js
function* saga1(){
    yield call(foo, 1, 2, 3);
}

function* saga2(){
    yield 2;
}

Result:

function* saga1() {
    yield Object.defineProperty(call(foo, 1, 2, 3), "@@redux-saga/LOCATION", {
        value: {
            fileName: "src/sagas/index.js",
            lineNumber: 1,
            code: "call(foo, 1, 2, 3)"
        }
    })
}

Object.defineProperty(saga1, "@@redux-saga/LOCATION", {
  value: {
    fileName: "src/sagas/index.js",
    lineNumber: 1
  }
})
function* saga2() {
    yield 2;
}
Object.defineProperty(saga2, "@@redux-saga/LOCATION", {
  value: {
    fileName: "src/sagas/index.js",
    lineNumber: 5
  }
})

Problem solving

My source code became ugly, I can't read it anymore

Use source maps. It can't be set up in babel settings.

It also can be set up in your building tools setting. See webpack config for example.

Keywords

FAQs

Package last updated on 20 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc