deloom
v0.1.0
Published
A tool to uncompress and unbundle JavaScript bundles created by webpack, terser, and others.
Readme
deloom
English/中文
deloom is a tool for uncompressing and unbundling JavaScript files produced by bundlers and minifiers like webpack, terser, and others. Using Babel AST transformations, it recovers obfuscated or compressed code into a more readable form and disassembles webpack bundles into standalone CommonJS modules.
Features
- Uncompress — Decompress and beautify a single minified JavaScript file: format code, fold constants, remove dead code, expand conditional expressions, and more.
- Unbundle — Extract the module graph from one or more webpack bundle files (e.g.,
1.js,2.js) into independent.cjsfiles, along with the required webpack runtime helper code. - Based on Babel parser and traversal, supports modern ECMAScript syntax.
- CLI and programmatic API.
Installation
# Using pnpm (recommended)
pnpm add -D deloom
# Or using npm
npm install --save-dev deloomGlobal install:
npm install -g deloomQuick Start
1. Uncompress a Single File
deloom uncompress input.js output.jsReads input.js, beautifies it, and writes to output.js. Prettier is used for secondary formatting by default; pass --no-prettier to disable.
Options:
--no-prettier Disable Prettier formatting
--throw-errors Throw errors during transformation (default: catch and fallback)
--no-timing Disable performance timing output2. Unbundle a Webpack Bundle
deloom unbundle ./dist/chunks ./outputWhere ./dist/chunks is a directory containing one or more bundle files (e.g., 1.js, 2.js), and ./output is the output directory. The tool parses all matched files, extracts the module definitions, and generates standalone .cjs files plus a WebpackHelper.cjs helper module.
Options:
--filter <pattern> File filter pattern, default `*.js`
--no-log Disable console logging
--no-clean Do not clean the output directory before runningAPI Usage
The package exposes two main functions:
formatSource(source, options?)
Beautify a JavaScript string or AST program.
import { formatSource } from 'deloom'
const code = `
var a=1,b=2;console.log(a+b);
`
const result = await formatSource(code, {
usePrettier: true,
throwErrors: false,
})
console.log(result)
// =>
// var a = 1;
// var b = 2;
// console.log(3);unbundle(options)
Unbundle webpack bundle files.
import { unbundle } from 'deloom'
await unbundle({
entries: ['./dist/chunks/1.js', './dist/chunks/2.js'],
output: './output',
log: true,
})How It Works
uncompress Transformations
A pipeline of Babel visitors is applied in order:
- Normalize string / numeric literal representations
- Constant folding (
1 + 2 * 3→7) - Object property shorthand (
{a: a}→{a}) - Function expression to arrow function (
function(){}→() => {}) - Ternary to if/else (
cond ? a() : b()→if/else) - Logical expression to if (
a && b()→if (a) { b() }) - Promise executor parameter renaming (
(a, b)→(resolve, reject)) - try-catch parameter renaming (
e→caughtError) void 0→undefined- Sequence expression splitting (
(a(), b())→a(); b()) - Assignment extraction from expressions
- And many more...
unbundle Workflow
- Parse each bundle file and locate the main module object (a large
ObjectExpressionwhere every property is a module function). - Traverse each module function, identify
require()calls and webpack runtime helpers (require.d,require.r,require.n, etc.). - Rewrite module numeric IDs to relative paths (e.g.,
require(3)→require('./3.cjs')). - Replace webpack runtime helper references with calls to
WebpackHelper.cjs. - Strip the webpack wrapper, keeping only the module body.
- Analyze dependency graphs.
- Emit each module as a separate
.cjsfile with a documentation banner, and generateWebpackHelper.cjs.
Project Structure
├── bin/
│ └── cli.ts # CLI entry point
├── src/
│ ├── index.ts # Exports formatSource and unbundle
│ ├── uncompress.ts # Core uncompression logic (AST transforms)
│ ├── unbundler.ts # Unbundling core (Extractor class)
│ ├── helper.ts # Webpack runtime helper code generation
│ └── deps.d.ts # Type declarations
├── package.json
├── tsconfig.json
├── .prettierrc.json
└── README.mdLicense
Licensed under the MIT License.
This project is intended for learning and research purposes only. Do not use it to infringe upon the copyrights of others.
Notes
- The unbundled output may contain unresolved references or warnings (
Tips); always review the generated files. - Webpack versions and plugin behaviors vary widely — some patterns may not be fully restored. Issues and pull requests are welcome.
