Git Product home page Git Product logo

retidy's Introduction

Retidy

GitHub stars npm npm downloads license

Extract, unminify, and beautify ("retidy") each file from a webpack/parcel bundle

⚠️ No Unit Tests, may have unexpected side effects ⚠️

Installation

npm install -g retidy

Usage

CLI

retidy \
    -i <bundle_file> \
    -o <out_dir> \
    -t <bundle_type> \
    -b <bundle_ast_reference>

see

retidy --help

API

import retidy from "retidy"

retidy(bundleCode[, options])
retidy(bundleCode: string, options?: Options): Promise<string[]>

If set options.writeFiles = true (by default), retidy will write extracted code files into the file system (under options.outDir directory, ./retidy-out/ by default).

Options

see src/options.ts

Example

import retidy from "retidy"
import fs from "fs"

const code = fs.readFileSync("path/to/webpack-bundle.js", "utf-8")

retidy(code, { type: "webpack", outDir: "./out/", bundleAstReferenceKeys: ["body", 0, "expression", "right"] })

License

MIT

Legal note

Some companies specify in their terms of service that their code cannot be "reverse engineered".
Hope you understand what you are doing so you don't break any agreements.

retidy's People

Contributors

idevjoe avatar xmader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

retidy's Issues

Support for WebpackJsonp

Hello, it would be fantastic to have support for files in the form of

(window.webpackJsonp = window.webpackJsonp || []).push(/* ... */);

Any way of making this work, please? 🙏🏻

TypeError: Cannot redefine property: i

run retidy -i document.min.js -entryPoint 0



/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs-parser/index.js:495
        Object.defineProperty(argvReturn, key, {
               ^

TypeError: Cannot redefine property: i
    at Function.defineProperty (<anonymous>)
    at /home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs-parser/index.js:495:16
    at Array.forEach (<anonymous>)
    at setArg (/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs-parser/index.js:494:12)
    at parse (/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs-parser/index.js:272:11)
    at Function.Parser.detailed (/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs-parser/index.js:1022:10)
    at Object.parseArgs [as _parseArgs] (/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs/build/lib/yargs.js:998:31)
    at Object.get [as argv] (/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/node_modules/yargs/build/lib/yargs.js:986:25)
    at Object.<anonymous> (/home/i/.nvm/versions/node/v13.11.0/lib/node_modules/retidy/cli/cli.js:47:48)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)

Running a retidy test app: TypeError: not a webpackBootstrap function call AST

Hello,
I'm trying to debundle a very short react file using retidy.
This is my test.js file:

test.js

import retidy from "retidy"
import fs from "fs"
const code = fs.readFileSync("vendor-bundle.js", "utf-8")
retidy.retidy(code, { type: "webpack-jsonp", outDir: "./out/", bundleAstReferenceKeys: ["body", 0, "expression"] })

This is the file to be unbundled:

vendor-bundle.js
!function(e){function n(t){if(r[t])return r[t].exports;var o=r[t]={exports:{},id:t,loaded:!1};return e[t].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var t=window.webpackJsonp;window.webpackJsonp=function(a,l){for(var p,c,s=0,i=[];s<a.length;s++)c=a[s],o[c]&&i.push.apply(i,o[c]),o[c]=0;for(p in l)e[p]=l[p];for(t&&t(a,l);i.length;)i.shift().call(null,n);return l[0]?(r[0]=0,n(0)):void 0};var r={},o={4:0,6:0};n.e=function(e,t){if(0===o[e])return t.call(null,n);if(void 0!==o[e])o[e].push(t);else{o[e]=[t];var r=document.getElementsByTagName("head")[0],a=document.createElement("script");a.type="text/javascript",a.charset="utf-8",a.async=!0,a.src=n.p+""+e+"."+({5:"bundle",6:"common-bundle"}[e]||e)+".js",r.appendChild(a)}},n.m=e,n.c=r,n.p=""}([]);

This is my package.json:

package.json

{
  "name": "testapp",
  "version": "1.0.0",
  "type": "module",
  "description": "",
  "main": "test.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "retidy": "^1.5.1"
  }
}

And I have a common-bundle.js file:
common-bundle.js
webpackJsonp([6,4],[]);

This is the error i get running node --trace-warnings test.js:

(node:9928) UnhandledPromiseRejectionWarning: TypeError: not a webpackBootstrap function call AST.
    at Object.exports.notWebpackBootstrapAstErr (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\webpack\extract-modules.js:17:58)
    at Object.exports.extractModules (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\webpack\extract-modules.js:41:23)
    at exports.webpackExtractor (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\webpack\webpack-extractor.js:6:43)
    at Object.exports.extractor (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\extractor.js:20:12)
    at C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:124:46
    at step (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:33:23)
    at Object.next (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:14:53)
    at fulfilled (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:5:58)
    at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
    at processPromiseRejections (internal/process/promises.js:247:11)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:9928) TypeError: not a webpackBootstrap function call AST.
    at Object.exports.notWebpackBootstrapAstErr (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\webpack\extract-modules.js:17:58)
    at Object.exports.extractModules (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\webpack\extract-modules.js:41:23)
    at exports.webpackExtractor (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\webpack\webpack-extractor.js:6:43)
    at Object.exports.extractor (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\extractor\extractor.js:20:12)
    at C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:124:46
    at step (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:33:23)
    at Object.next (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:14:53)
    at fulfilled (C:\Users\Roberto\Desktop\retidy\node_modules\retidy\dist\index.js:5:58)
(node:9928) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
    at emitDeprecationWarning (internal/process/promises.js:180:11)
    at processPromiseRejections (internal/process/promises.js:249:13)
    at processTicksAndRejections (internal/process/task_queues.js:94:32)

I'm doing something wrong for sure, but I don't know what.
And I have no idea of what to write in the bundleAstReferenceKeys (and maybe in entryPoint option too)
Could someone help me?
Thanks

unminifyIfStatements causes bug

unminify-if-statements.ts

return x || a() -> if (!x) { return a() }

when x is true, it returns undefined

I disabled this transformer to make it work

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.