kneden icon indicating copy to clipboard operation
kneden copied to clipboard

Usage alongside babel-preset-stage-*

Open julien-f opened this issue 9 years ago • 21 comments
trafficstars

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 avatar Mar 10 '16 15:03 julien-f

https://github.com/julien-f/kneden-stage-0

julien-f avatar Mar 10 '16 15:03 julien-f

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

ewnd9 avatar Mar 10 '16 15:03 ewnd9

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

julien-f avatar Mar 14 '16 13:03 julien-f

@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
});

developit avatar Mar 18 '16 13:03 developit

@developit Nice! :)

julien-f avatar Mar 18 '16 13:03 julien-f

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

marten-de-vries avatar Mar 25 '16 14:03 marten-de-vries

I will try to publish the recursive preset fix ASAP.

developit avatar Mar 25 '16 16:03 developit

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"
  ]
}

brigand avatar Mar 29 '16 07:03 brigand

@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 avatar Mar 29 '16 13:03 developit

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

developit avatar Mar 30 '16 14:03 developit

@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)

brigand avatar Mar 30 '16 18:03 brigand

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

developit avatar Mar 30 '16 18:03 developit

I have it installed directly.

brigand avatar Mar 30 '16 19:03 brigand

I want kneden 😫

nodegin avatar Jun 22 '16 03:06 nodegin

Tried below piece of code

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

But no luck for me

nodegin avatar Jun 22 '16 03:06 nodegin

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

nodegin avatar Jun 22 '16 06:06 nodegin

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

developit avatar Jun 22 '16 10:06 developit

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

nodegin avatar Jun 22 '16 10:06 nodegin

What do you mean?

developit avatar Jun 22 '16 10:06 developit

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

nodegin avatar Jun 22 '16 11:06 nodegin

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.

developit avatar Jun 22 '16 11:06 developit