GithubHelp home page GithubHelp logo

1egoman / debundle Goto Github PK

View Code? Open in Web Editor NEW
702.0 14.0 145.0 571 KB

:card_file_box: A javascript debundler. Takes a Browserify or Webpack bundle and recreates the initial, pre-bundled source.

Home Page: https://www.npmjs.com/package/debundle

JavaScript 99.39% Shell 0.61%
ast bundle debundle webpack-bundle browserify reverse-engineering

debundle's Introduction

Debundle

debundle

This is a tool built to unpack javascript bundles prudiced by webpack and browserify.

Build Status


๐Ÿ‰ HERE BE DRAGONS! ๐Ÿ‰

This was a research project that is no longer maintained. I built to help me understand how javascript bundles are strutured. It works in a labratory environment most of the time, but often fails on real-world javascript bundles. It's been a while since I worked on this project so if you run into issues, I might not really be able to help you out all that much.


Why would I want to debundle my code?

Reasons vary, but this tool was originally developed to help me with a reverse engineering project. Needless to say, sifting through minified bundles to try and figure out how a service works isn't fun and is a lot easier when that bundle is broken into files and those files have semantic names.

Installation

npm i -g debundle

Running

$ debundle
Usage: debundle [input file] {OPTIONS}

Options:
   --input,  -i  Bundle to debundle
   --output, -o  Directory to debundle code into.
   --config, -c  Configuration file

$ curl https://raw.githubusercontent.com/1egoman/debundle/master/test_bundles/browserify/bundle.js > bundle.js
$ curl https://raw.githubusercontent.com/1egoman/debundle/master/test_bundles/browserify/debundle.config.json > debundle.config.json
$ cat debundle.config.json
{
  "type": "browserify",
  "knownPaths": {}
}
$ debundle -i bundle.js -o dist/ -c debundle.config.json
$ tree dist/
dist/
โ”œโ”€โ”€ index.js
โ””โ”€โ”€ node_modules
    โ”œโ”€โ”€ number
    โ”‚ย ย  โ””โ”€โ”€ index.js
    โ””โ”€โ”€ uuid
        โ”œโ”€โ”€ index.js
        โ”œโ”€โ”€ lib
        โ”‚ย ย  โ”œโ”€โ”€ bytesToUuid.js
        โ”‚ย ย  โ””โ”€โ”€ rng.js
        โ”œโ”€โ”€ v1.js
        โ””โ”€โ”€ v4.js
4 directories, 7 files

Configuration

Simple configuration

{
  "type": "browserify",
  "entryPoint": 1,
  "knownPaths": {}
}

(To debundle a simple Webpack bundle, replace browserify the above configuration with webpack)

A configuration can have a number of flags - they are documented in DOCS.md.

FAQ

Is debundling lossless? Ie, if I bundle my code then debundle, will I get the same source that was originally bundled?

No. There a bunch of metadata that's lost when bundling:

  • Any custom package.json settings for each node_module and the root package.
  • In a webpack bundle, the names of modules aren't in the bundle. By default, debundling will produce files named after the module id (ie, 1.js) unless manually overridden.
  • If your code was minified, the output files from the debundling process will also be minified (ie, no whitespace, single letter variables, etc). It's up to you to run source through other tools to make it look nicer.

My debundled code can't be run!

  • Make sure that either when rebundling or running with node that you're using the correct file as your entrypoint.
  • Read through all the configuration options. Some of them have caveats.
  • You could have run into an edge case that I haven't seen yet. Feel free to open an issue if you believe that to be the case.

Does this tool support bundles made by tools other than Browserify and Webpack?

Not officially. However, if a bundle shares the same type module layout as Browserify or Webpack it may be possible to set the moduleAst configuration option to point to the location of the modules.

Contributing

  • After cloning down the project, run npm install - that should be it.
  • Debundler entry point is ./src/index.js (that's how you run it!)
  • A bunch of sample bundles are in test_bundles/. A script, test_bundles/run_test.sh can run the debundler against a given bundle and try to debundle it into dist/. (CI will, as part of running tests, debundle all the bundles in that folder.)
  • Make sure any contribution pass the tests: npm test

Legal note

Some companies specify in their terms of service that their code cannot be "reverse engineered". Debundling can definitely (depending on how you're using the code) fall under that umbrella. Understand what you are doing so you don't break any agreements ๐Ÿ˜„

debundle's People

Contributors

1egoman 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

debundle's Issues

Module AST Failed

Reading bundle...
/usr/local/lib/node_modules/debundle/src/index.js:80
    throw new Error(`Locating the module AST failed. Please specifify a valid manual ast path in your config file with the key \`moduleAst\`. We got as far as ${moduleAstPathTriedSoFar.join('.')} before an error occured.`);
    ^

Error: Locating the module AST failed. Please specifify a valid manual ast path in your config file with the key `moduleAst`. We got as far as body.0.expression.arguments before an error occured.

Infer webpack module names from import constants names

@1egoman I think it's possible to infer original module names and folders from other modules that import them, for example:

/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__localization__ = __webpack_require__(47);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_bignumber_js__ = __webpack_require__(2);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_bignumber_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_bignumber_js__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__constants__ = __webpack_require__(4);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__store_account__ = __webpack_require__(15);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__store_system__ = __webpack_require__(6);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__store_book__ = __webpack_require__(9);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_0x_relay_utils__ = __webpack_require__(45);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6_0x_relay_utils___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_6_0x_relay_utils__);

Here you can see that module 4 is "constants.js", module 15 is "store/account.js", etc.

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? ๐Ÿ™๐Ÿป

Error while running the sample

I get the following error while running the sample,
Please help.

debundle -i bundle.js -o dist/ -c debundle.config.json

  • Using default AST location for browserify...
  • Reading bundle...
  • Using auto-discovered browserify entry point...
  • Decoding modules...
  • Discovered module 1
  • Extracted module code for 1
  • Extracted module lookup table for 1
  • Calculated module lookup table for 1
  • Discovered module 2
  • Extracted module code for 2
  • Extracted module lookup table for 2
  • Calculated module lookup table for 2
  • Discovered module 3
  • Extracted module code for 3
  • Extracted module lookup table for 3
  • Calculated module lookup table for 3
  • Discovered module 4
  • Extracted module code for 4
  • Extracted module lookup table for 4
  • Calculated module lookup table for 4
  • Discovered module 5
  • Extracted module code for 5
  • Extracted module lookup table for 5
  • Calculated module lookup table for 5
  • Discovered module 6
  • Extracted module code for 6
  • Extracted module lookup table for 6
  • Calculated module lookup table for 6
  • Discovered module 7
  • Extracted module code for 7
  • Extracted module lookup table for 7
  • Calculated module lookup table for 7
  • Reassembling requires...
  • Reconstructing require path for module 2...
  • 2 => node_modules/uuid/index
    C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\src\utils\getModuleLocation.js:98
    throw new Error(err);
    ^

Error: Don't have enough information to expand bundle into named files. The process requires the path of one of the below to be explicitly defined:
at getModuleLocation (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\src\utils\getModuleLocation.js:98:11)
at node (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\src\transformRequires.js:79:34)
at NodePath.single (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\src\extern\replace-method\index.js:42:20)
at traverse (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:35:26)
at C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:48:13
at C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\types.js:612:18
at Array.forEach (native)
at Object.exports.eachField (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\types.js:611:27)
at NodePath.traverse (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:42:15)
at NodePath.Pp.each (C:\Users\Wong\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\path.js:89:22)

node_modules within a bundle that have a custom entry point are unable to be debundled correctly.

$ tree .
.
โ”œโ”€โ”€ foo.js (will be bundle entry point)
โ”œโ”€โ”€ bar
โ”‚   โ””โ”€โ”€ baz.js
โ””โ”€โ”€ node_modules
    โ””โ”€โ”€ mypackage
        โ”œโ”€โ”€ package.json (has `main` set to `foo.js`)
        โ””โ”€โ”€ foo.js (this is the entry point for the module `mypackage`)
$ browserify foo.js > bundle.js
$ cat debundle-config.json
{
  "type": "browserify",
  "knownPaths": {}
}
$ debundle -i bundle.js -o dist/ -c debundle-config.json
$ tree dist/
.
โ”œโ”€โ”€ foo.js (is bundle entry point)
โ”œโ”€โ”€ bar
โ”‚   โ””โ”€โ”€ baz.js
โ””โ”€โ”€ node_modules
    โ””โ”€โ”€ mypackage
       (no package.json)
        โ””โ”€โ”€ index.js (this is the entry point for the module `mypackage`, not using a custom entry point though)

The above demonstrates the issue. When the entry points happen to be at the same level, everything is fine (ie, foo.js => index.js) However, if the initial entry point is some/long/nested/directory/that/ends/in/index.js, and this is collapsed to index.js, all the requires will be off because they expect that nested structure.

A package where this is the case is @blueprintjs/core, where the entry point is dist/index.js. Therefore, a bundle with blueprint in it s currently unable to be rebundled after debundling.

The root level IIFE didn't have an array for it's first parameter, aborting...

@1egoman

In order to troubleshoot, I need:

A bundle that doesn't work, preferably as minimal as possible. Upload it to pastebin.com:

Link: https://pastebin.com/eg22rLqE

Any commands you ran prior to debundling:

mkdir debundle-test1 && cd debundle-test1
npm init -y
npm i --save-dev debundle

Your configuration that you passed with the -c argument when debundling.

{
  "type": "webpack",
  "entryPoint": 1,
  "knownPaths": {}
}

The EXACT command you ran to debundle.

node ./node_modules/debundle/src/index.js -i ext-bundle.js -o ext-dist/ -c debundle.config.json

Tell me what the issue is:

Error: The root level IIFE didn't have an array for it's first parameter, aborting...
    at webpackDecoder (~\debundle-test1\node_modules\debundle\src\decoders\webpack.js
:19:11)
    at Object.<anonymous> (~\debundle-test1\node_modules\debundle\src\index.js:104:13
)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)

If you omit any of these parts, I can't help you!

Can you give me an webpack example?

My English is poor. When I want to decompile webpack with debundle, I don't know how to operate it.
Generally, Vue compiled by webpack has 3 files.
Manifest..js
Vendor.
.js
App.****.js
Can you give me an example of how to decompile webpack compiled Vue files?

TypeError: Cannot read property '2' of undefined

@1egoman

Now (same setup as in #5), when I run the command:

debundle -i public/assets/frontend/js/modules/scripts.js -o public/assets/frontend/js/modules/unpacked/ -c public/assets/frontend/js/modules/debundle.config.json

I get:

* Using default AST location for browserify...
* Reading bundle...
* Using auto-discovered browserify entry point...
/usr/local/lib/node_modules/debundle/src/index.js:63
  config.entryPoint = ast.body[0].expression.arguments[2].elements[0].value;
                                                      ^
TypeError: Cannot read property '2' of undefined
    at Object.<anonymous> (/usr/local/lib/node_modules/debundle/src/index.js:63:55)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.runMain (module.js:590:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

not work in windows!

The path.join method is used to connect paths. The main purpose of this method is to use the path separator of the current system correctly. The Unix system is "/" and the Windows system is "\".

image

This place always throws an error !!!

How to set the debundle.config.json

I download the code,
file "debundle.config.json"
{
"type": "webpack",
"entryPoint": 8,
"knownPaths": {
"8": "./index",
"4": "./foo",
"0": "uuid"
}
}

when just index.js foo.js in /src directory

Num 8 4 0 are just random ID?

Can you give me some example? The DOCS.md file confused me.

Potential reownership?

I'm aware you're no longer interested in maintaining this project, however I'd like to peak your interest in adopting this package and working on keeping it stable. I do have personal uses for this, but rather build one from scratch, I figured I'd try to get your permsission to hand off the project to my R&D organization.

I greatly respect the progress you've made, please consider my request.

How to recover a built file to its original source

I have a problem with the hard disk, so all the files I've worked with on Vue-cli are gone,
There are only build files left on FTP.
I tried using the chrome source view, but the problem is that the file that separated the script and style did not appear as the original source.
You can use debundle to restore files built with Webpack to their original source.
https://www.npmjs.com/package/debundle
https://github.com/1egoman/debundle
Is it possible to work with vue?
If possible,
bundle.js
debundle.config.json
I do not know how to set this up. The ones I received as samples did not work well ...
I would like to know if there is an example of how to do this with bundile.js, debundle.config.json.
Thank you.

Error: Locating the module AST failed.

In order to troubleshoot, I need:

  • A bundle that doesn't work, preferably as minimal as possible.
  • Your configuration that you passed with the -c argument when debundling.
  • The EXACT command you ran to debundle.

Hi 1egoman, I'm trying to reverse a bundle that I've created some time ago and I lost the original files.

The bundle was made with webpack, and the configuration that I used with your instructions was this:

{
"type": "webpack",
"entryPoint": 0,
"knownPaths": {
"0": "./",
"2": "./",
"3": "./"
}
}

Command: $ debundle -i pageBikini.bundle.js -o dist/ -c debundle.config.json

TypeError: Cannot read properties of undefined (reading 'elements') at Object.<anonymous> (/usr/local/lib/node_modules/debundle/src/index.js:63:59)

  • Using default AST location for browserify...
  • Reading bundle...
  • Using auto-discovered browserify entry point...
    /usr/local/lib/node_modules/debundle/src/index.js:63
    config.entryPoint = ast.body[0].expression.arguments[2].elements[0].value;
    ^

TypeError: Cannot read properties of undefined (reading 'elements')
at Object. (/usr/local/lib/node_modules/debundle/src/index.js:63:59)
at Module._compile (node:internal/modules/cjs/loader:1119:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1173:10)
at Module.load (node:internal/modules/cjs/loader:997:32)
at Module._load (node:internal/modules/cjs/loader:838:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:18:47

Node.js v18.8.0

Error: did not recognize object of type "AssignmentPattern"

@1egoman I get this error while running debundle on a webpack (non-minified) bundle:

.....
* No lookup tabie for module 510, so using identifier as require path...
* 510 => 510
assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: did not recognize object of type "AssignmentPattern"
    at getFieldNames (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/types.js:581:12)
    at Object.exports.eachField (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/types.js:611:5)
    at NodePath.traverse (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/traverse.js:42:15)
    at NodePath.Pp.each (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/path.js:89:22)
    at traverse (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/traverse.js:30:18)
    at /usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/traverse.js:48:13
    at /usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/types.js:612:18
    at Array.forEach (<anonymous>)
    at Object.exports.eachField (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/types.js:611:27)
    at traverse (/usr/local/lib/node_modules/debundle/node_modules/ast-types/lib/traverse.js:42:15)

Variables renaming

hi i noticed that in webpack a lot of variables get renamed to module, exports, require any way around that?
Also on windows debundler fails at getModuleLocation when it checks if (!filePath.startsWith(pathPrefix))
removing the check gets the output

running out of memory? memory leak?

In order to troubleshoot, I need:

  • A bundle that doesn't work, preferably as minimal as possible.
  • Your configuration that you passed with the -c argument when debundling.
  • The EXACT command you ran to debundle.

I was trying to debundle http://pdfkit.org/demo/bundle.js with a configuration of { "type": "browserify", "entryPoint": 1, "knownPaths": { } }
I noticed it was running out of ram, so I gave it all I got by executing: node --max_old_space_size=15000 C:\Users\roshkins\AppData\Roaming\npm\node_modules\debundle\src\ index.js -i .\bundle.js -o .\debundle\ -c .\debundle.config.json but it seemed to just eat up a lot of ram :( and it feels liek a memory leak. I hope @1egoman can figure it out, because I can't seem to get the build process for pdfkit working with react.

Cannot read property 'id' of undefined

Hi,
I'm trying to debundle a webpack bundeled JS file which starts with:

webpackJsonp([ 0 ], {
    11: function(e, t, n) {
        "use strict";
        Object.defineProperty(t, "__esModule", {
            value: true
        });

Is there any special configuration I need to notice?

I have the defaults for webpack:

{
  "type": "webpack",
  "entryPoint": 1,
  "knownPaths": {}
}

Not sure what else is missing.

Update:
Tried the same with another file in the repo which starts with:

(function(e) {
    var t = window["webpackJsonp"];
    window["webpackJsonp"] = function n(s, i, d) {

and got this error:

* Using default AST location for webpack...
* Reading bundle...
* Decoding modules...
* Reassembling requires...
* No lookup tabie for module 0, so using identifier as require path...
* 0 => 0
C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\utils\getModuleLocation.js:98
    throw new Error(err);
    ^

Error: Don't have enough information to expand bundle into named files. The process requires the path of one of the below to be explicitly defined:
    at getModuleLocation (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\utils\getModuleLocation.js:98:11)
    at node (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\transformRequires.js:79:34)
    at NodePath.single (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\src\extern\replace-method\index.js:42:20)
    at traverse (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:35:26)
    at C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:48:13
    at C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\types.js:612:18
    at Array.forEach (<anonymous>)
    at Object.exports.eachField (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\types.js:611:27)
    at traverse (C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:42:15)
    at C:\Users\Wonderer\AppData\Roaming\npm\node_modules\debundle\node_modules\ast-types\lib\traverse.js:48:13

Hi there!

Is it possible to debundle when i have .map files? Some tools for this? Thank you!

Error: Locating the module AST failed.

@1egoman

In order to troubleshoot, I need:

A bundle that doesn't work, preferably as minimal as possible. Upload it to pastebin.com:

Link:
https://pastebin.com/TEbhjypb
Any commands you ran prior to debundling:

debundle -i tmp/js/commons-bundle.184afa95.js -o ./debundle -c ./debundle.config.json 

Your configuration that you passed with the -c argument when debundling.

{
  "type": "webpack",
  "entryPoint": 0,
  "moduleAst": 
  "knownPaths": {
    "0": "./cities"
  }
}

The EXACT command you ran to debundle.

debundle -i tmp/js/commons-bundle.184afa95.js -o ./debundle -c ./debundle.config.json

Tell me what the issue is: Getting an error

$ debundle -i tmp/js/commons-bundle.184afa95.js -o ./debundle -c ./debundle.config.json 
* Using default AST location for webpack...
* Reading bundle...
/Users/jessespencer/.nvm/versions/node/v8.1.2/lib/node_modules/debundle/src/index.js:80
    throw new Error(`Locating the module AST failed. Please specifify a valid manual ast path in your config file with the key \`moduleAst\`. We got as far as ${moduleAstPathTriedSoFar.join('.')} before an error occured.`);
    ^

Error: Locating the module AST failed. Please specifify a valid manual ast path in your config file with the key `moduleAst`. We got as far as body.0.expression.arguments before an error occured.
    at Object.<anonymous> (/Users/jessespencer/.nvm/versions/node/v8.1.2/lib/node_modules/debundle/src/index.js:80:11)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:575:3

If you omit any of these parts, I can't help you!

hello,

image
I have a question, can I help me?

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Hello @1egoman,

Commands I run triggering the issue:

debundle -i public/assets/frontend/js/modules/scripts.js -o public/assets/frontend/js/modules/unpacked/ -c public/assets/frontend/js/modules/debundle.config.json

or just

debundle

Content of debundle.config.json:

{
  "type": "browserify",
  "knownPaths": {}
}

Error I get:

/usr/local/lib/node_modules/debundle/src/index.js:58
let ast = acorn.parse(bundleContents, {});
^^^
SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

The bundle I try to debundle:

!function t(e, i, r) {
    function n(s, a) {
        if (!i[s]) {
            if (!e[s]) {
                var l = "function" == typeof require && require;
                if (!a && l)
                    return l(s, !0);
                if (o)
                    return o(s, !0);
                var u = new Error("Cannot find module '" + s + "'");
                throw u.code = "MODULE_NOT_FOUND",
                u
            }
            var h = i[s] = {
                exports: {}
            };
            e[s][0].call(h.exports, function(t) {
                var i = e[s][1][t];
                return n(i ? i : t)
            }, h, h.exports, t, e, i, r)
        }
        return i[s].exports
    }
    for (var o = "function" == typeof require && require, s = 0; s < r.length; s++)
        n(r[s]);
    return n
}
({
    1: [function(t, e, i) {
        "use strict";
        function r(t, e) {
            Array.isArray(t) ? t.forEach(function(t) {
                r(t, e)
            }) : (t.jquery || 1 === t.nodeType || "string" == typeof t) && TweenMax.set(t, {
                clearProps: e
            })
        }
        i.__esModule = !0,
        i.default = function(t) {
            t.getChildren().forEach(function(t) {
                var e = !t.vars.data || void 0 === t.vars.data.clear || t.vars.data.clear === !0;
                if (t.target && t.vars && t.vars.css && e) {
                    var i;
                    for (var n in t.vars.css)
                        i ? i += "," : i = "",
                        "autoAlpha" === n && (n = "opacity,visibility"),
                        i += n;
                    i && r(t.target, i)
                }
            })
        }
    }
    , {}],
    2: [function(t, e, i) {
        "use strict";
        function r(t, e) {
            if (!(t instanceof e))
                throw new TypeError("Cannot call a class as a function")
        }
        i.__esModule = !0;
        var n = function() {
            function t() {
                r(this, t)
            }
            return t.prototype.init = function() {
                this.element = $("#lang")
            },
            t.prototype.one = function(t) {
                //
            }
            ,
            t.prototype.two = function() {
                //
            },
            t
        }();
        i.default = new n
    }
    , {}]
}, {}, [1]);

Is it supposed to debundle babelified code too? I would like the debundled file to have the nice ES6 classes.

Let me know if I can provide more info, and thanks for open sourcing debundle!

If a bundle is minified, debundle will replace identifiers globally not following scoping rules.

Given a bundle that contains this module:

function(a, b, c) { 
  a.foo = 1; // Used as expected
  {
    // A different scope!
    let a = 5;
    a = 6;
  };
}

This project will replace globally in the whole file all occurrences of the symbol a, even in cases where the symbol is overwritten in a nested lexical context.

The above code will be transformed into:

function(module, exports, require) { 
  module.foo = 1; // Transformed as expected
  {
   // BAD! Should have kept those identifiers as `a`!
    let module = 5;
    module = 6;
  };
}

Debundler V2. Weird error

I know @1egoman most likely won't update this project anymore (debundle v2), but if someone can help then please:

I installed the project, changed directory to it and ran npm install it installed some packages and once i tested it with this command: node src/index.js bundle.js it gave me this error (full log):

PS D:\Downloads\debundle-2\debundle-2> node src/index.js bundle.js
[LOG] Read bundle D:\Downloads\debundle-2\debundle-2\bundle.js (1721650 bytes)
[LOG] Looking for webpackBootstrap in bundle...
[LOG] Found webpackBootstrap!
[LOG] webpackBootstrap module call expression: __webpack_modules__[moduleId].call(module.exports, module, module.exports
, __webpack_require__)
D:\Downloads\debundle-2\debundle-2\node_modules\escope\lib\referencer.js:226
                this.currentScope().__define(node.id, new _definition.Definition(_variable2.default.FunctionName, node.i
d, node, null, null, null));
                                   ^

TypeError: Cannot read properties of null (reading '__define')
    at Referencer.visitFunction (D:\Downloads\debundle-2\debundle-2\node_modules\escope\lib\referencer.js:226:36)
    at Referencer.FunctionDeclaration (D:\Downloads\debundle-2\debundle-2\node_modules\escope\lib\referencer.js:564:18)
    at Visitor.visit (D:\Downloads\debundle-2\debundle-2\node_modules\esrecurse\esrecurse.js:104:34)
    at Object.analyze (D:\Downloads\debundle-2\debundle-2\node_modules\escope\lib\index.js:153:16)
    at new WebpackBootstrap (D:\Downloads\debundle-2\debundle-2\src\subcomponents\WebpackBootstrap.js:9:32)
    at Bundle._findWebpackBootstrap (D:\Downloads\debundle-2\debundle-2\src\subcomponents\Bundle.js:247:29)
    at Bundle.parse (D:\Downloads\debundle-2\debundle-2\src\subcomponents\Bundle.js:78:10)
    at Object.<anonymous> (D:\Downloads\debundle-2\debundle-2\src\index.js:38:8)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)

Node.js v20.16.0

which I think is releated to referencer.js and not to this project, so can anyone help?

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.