Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

Usage alongside babel-preset-stage-* #37

Open
julien-f opened this issue Mar 10, 2016 · 21 comments
Open

Usage alongside babel-preset-stage-* #37

julien-f opened this issue Mar 10, 2016 · 21 comments

Comments

@julien-f
Copy link

I could not get kneden working with babel-preset-stage-0 despite my efforts, does anyone know of the proper way to achieve that?

@julien-f
Copy link
Author

@ewnd9
Copy link

ewnd9 commented Mar 10, 2016

You could simply include all plugins from stage-0, stage-1, stage-2, stage-3 except of transform-async-to-generator alongside with kneden

@julien-f
Copy link
Author

I know but it's far from perfect, I know have to monitor changes in stage-* by myself to reflect them in my project…

@developit
Copy link
Member

@julien-f I will be releasing a reasonably decent solution for this issue soon. Crawls a babel preset tree and serializes it to relative filepaths, which you can then mutate as you please via modify-babel-preset:

var modify = require('modify-babel-preset');
module.exports = modify('stage-0', {
  'transform-async-to-generator': false,   // remove it
  'kneden': true   // add it
});

@julien-f
Copy link
Author

@developit Nice! :)

@marten-de-vries
Copy link
Collaborator

@developit 's solution looks great, would be nice to add a note on it to the README.

@developit
Copy link
Member

I will try to publish the recursive preset fix ASAP.

@brigand
Copy link

brigand commented Mar 29, 2016

The solution there isn't working for me. It continues to transform it using generators. If I remove the modified-stage-1-preset then it works (but of course, I lose the other stuff in stages 1-3).

// dev/modified-stage-1-preset.js
var modify = require('modify-babel-preset');
module.exports = modify('stage-1', {
  'transform-async-to-generator': false,   // remove it
});
// .babelrc
{
  "presets": [
    "es2015",
    "./dev/modified-stage-1-preset.js",
    "react"
  ],
  "plugins": [
    "babel-plugin-async-to-promises"
  ]
}

@developit
Copy link
Member

@brigand Correct, the current version of modify-babel-preset does not support recursive transformations. Since the stage-0 stage-1 or stage-2 babel presets all rely on recursion (eg: stage-1 includes 2, which includes 3), we are all waiting on me to release the update.

Perhaps it'd be worth skipping the last test replication I've been having issues with and publishing it under a beta tag? The new version would support exactly what you described.

@developit
Copy link
Member

@brigand Just a note, I've published modify-babel-preset@beta (2.0.0), which should support what you posted.

@brigand
Copy link

brigand commented Mar 30, 2016

@developit Getting an error. Same code as I posted above.

resolve failed:  [TypeError: Cannot read property 'substring' of undefined] undefined
/Users/fb/github/client2/node_modules/modify-babel-preset/lib/serialize.js:76
    if (!mod) throw new Error('Preset "'+name+'" not found.');
              ^

Error: Preset "undefined" not found.
    at loadPreset (/Users/fb/github/client2/node_modules/modify-babel-preset/lib/serialize.js:76:18)

@developit
Copy link
Member

@brigand Do you have babel-preset-stage-1 installed directly in /Users/fb/github/client2, or is it installed within babel-preset-stage-0?

@brigand
Copy link

brigand commented Mar 30, 2016

I have it installed directly.

@nodegin
Copy link

nodegin commented Jun 22, 2016

I want kneden 😫

@nodegin
Copy link

nodegin commented Jun 22, 2016

Tried below piece of code

  "babel": {
    "plugins": ["async-to-promises"],
    "presets": ["react", "es2015", "stage-0-kneden"],
  }

But no luck for me

@nodegin
Copy link

nodegin commented Jun 22, 2016

Hi everyone, I solved this issue by creating a custom preset.

https://github.com/nodegin/babel-preset-stage-0-promises

In your .babelrc:

{
  "babel": {
    "presets": ["react", "es2015", "stage-0-promises"]
  }
}

Now the plugin works perfectly

@developit
Copy link
Member

@nodegin nice work! It's even using modify-babel-preset 😍

@nodegin
Copy link

nodegin commented Jun 22, 2016

@developit lol thanks but why you don't update your preset

@developit
Copy link
Member

What do you mean?

@nodegin
Copy link

nodegin commented Jun 22, 2016

@developit I mean the babel-preset-stage-0-kneden

@developit
Copy link
Member

Ah - so it was broken when using modify-babel-preset 1.x, which lead me down the rabbit hole that resulted in 2.x, but I never went back and updated it haha.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants