coderaiser / putout

🐊 Pluggable and configurable JavaScript Linter, code transformer and formatter, drop-in ESLint superpower replacement πŸ’ͺ with built-in support for js, jsx, typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way 😏
https://putout.cloudcmd.io/
MIT License
698 stars 40 forks source link

babel config is not loaded. #201

Closed krzysztofpniak closed 4 months ago

krzysztofpniak commented 5 months ago

How can I load babel.config.js? I have a code:

const source = "a |> b";

putout(source, {
      plugins: ['remove-unused-variables'],
    });

I got This experimental syntax requires enabling the parser plugin: "pipelineOperator". (1:2)

coderaiser commented 5 months ago

There is no way to load babel config, anyways everything works good for me https://putout.cloudcmd.io/#/gist/aa57aef60816b5d7875536b9271a701b/73337bbf9ac4cf9df51460ceaa9415ce742a7f19

What version of 🐊Putout are you using?

krzysztofpniak commented 5 months ago

I'm using the latest.

This is not working for me: https://putout.cloudcmd.io/#/gist/790e78f476c01dfe478cf1b8adae54e8/41e70353c72502710d7de340d001ae8cfa142031

export const report = () => `Use 'if condition' instead of 'pipeline operator'`;

export const replace = () => ({
    '__a |> __b |> __c': 'if (__a) __b; else __c;'
});
coderaiser commented 5 months ago

Yes, this construction is’n supported now in Replacer (good idea for PR to @putout/engine-parser), you can use Traverser instead. What result do you want to achieve: please provide input and output, and I try to help you.

coderaiser commented 5 months ago

It is easy to enable parsing of pipelineOperator, but what kind of topic to set?

It is also stage-2 so lots things can be changed and it is not supported by any runtime as I know. Are you using pipelineOperator in production and want to get rid of it?

It is also easy to transform such code since this is just BinaryExpression:

image
krzysztofpniak commented 5 months ago

Exactly, I'm using pipeline in production for 3 years and I want to get rid of it.

I would like to transform: expr1 |> expr2 |> expr_n to: wrap(expr1).pipe(expr2).pipe(expr_n).value

coderaiser commented 5 months ago

image

What kind of topics have you used?

Right now I have an error:

image

I don't mind to help you converting your codebase, but I need to seed your babel config, and I think is better to add hack:

image

Also if this is one-time transformation you can update babel parser plugins inside @putout/engine-parser to enable anything you need.

krzysztofpniak commented 5 months ago

I'm using

[
      '@babel/plugin-proposal-pipeline-operator',
      {proposal: 'minimal'},
],
coderaiser commented 5 months ago

Do you need any additional help for this?

krzysztofpniak commented 5 months ago

Yes, I tried Traverser and it gave me the same error.

export const report = () => `replace pipelines`;

export const traverse = ({push}) => ({
  BinaryExpression: path => console.log('path', path),
});
coderaiser commented 4 months ago

Did you update babel plugins?

krzysztofpniak commented 4 months ago

Yes, this construction is’n supported now in Replacer (good idea for PR to @putout/engine-parser), you can use Traverser instead. What result do you want to achieve: please provide input and output, and I try to help you.

You mentioned that it will work in Traverser. However, it seems that manual changes are required in the plugins within the node_modules directory each time, and on every machine I need to use it. Do you have any better ideas on how I can achieve this?

coderaiser commented 4 months ago

https://www.npmjs.com/package/patch-package can help with this, but why don't you want to run transform once and commit to git repository. Do you need to run it every time you write code?

krzysztofpniak commented 4 months ago

patch-packages + change in @putout/engine-parser solves all my issues. Thanks for your help.