pionxzh / wakaru

🔪📦 Javascript decompiler for modern frontend
https://wakaru.vercel.app/
MIT License
306 stars 18 forks source link

CLI: add support for config files #116

Open milahu opened 8 months ago

milahu commented 8 months ago

i want to disable some rules for the wakaru unminify command

something like

wakaru unminify --config wakaru.json input.js

wakaru.json would be similar to .eslintrc.json

example: disable the un-jsx rule

{
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": "latest",
  },
  "rules": {
    "un-jsx": "off"
  },
}

continue #113

i dont see a way to disable rules

You can disable it on the playground. CLI has not supported configuring the rules yet.

i guess that transforming document.createElement to JSX can be desired so i would be happy with a

pionxzh commented 8 months ago

Let me share the big picture in my mind.

This wakaru.json should support configuring rule orders and their enabled status. Users should be able to pass some advanced options to rules. (This is not even presented in the playground right now).

The format of eslintrc can be a reference of how this config file should structured.


Parser won't be configurable, it's fixed.

pionxzh commented 8 months ago

For the user interaction part, how to generate or provide the config file is also something that needs some consideration.

milahu commented 8 months ago

should support configuring rule orders

then rules would be an array

{
  "rules": [
    ["un-jsx", "off"]
  ],
}

how to generate or provide the config file

to create a default config file

wakaru unminify --init-config wakaru.json
0xdevalias commented 8 months ago

Potentially could be something like this (object in the array, rather than array in array):

{
  "rules": [
    { rule: "un-jsx", enabled: false }
  ],
}

It's been a while since I looked how eslint handles its config for plugins/etc with extra options:

milahu commented 8 months ago

object in the array

more verbose... plus, the rule name is required, so why not make it a positional argument

in any case, it would be nice to have javascript configs wakaru.js wakaru.cjs wakaru.mjs

0xdevalias commented 8 months ago

Verbosity in a config file doesn't necessarily matter all that much if it makes things more explicit/coherent. But I don't have strong opinions either way.

Eslint seems to use a straight object for the rule config; but then I don't believe it makes use of ordering there. Technically depending how the object is iterated it can have stable ordering, but that might be too 'hidden away'/unobvious for most users.

Perhaps webpack/similar's config patterns are worth modelling on as well.

milahu commented 8 months ago

https://github.com/pionxzh/wakaru/issues/113#issuecomment-1946623485

If you are running this repo in local environment, simply disable it in file packages/unminify/src/transformations/index.ts

i guess the simplest solution would be only javascript config, no json config

// wakaru.config.js

import { transformationRules } from "wakaru/unminify"

export default {
  transformationRules: transformationRules.filter(rule => {
    if (rule.name == "un-jsx") return false
    return true
  }),
}