Webcrack's pipeline consists of six stages: Parse, Prepare, Deobfuscate, Transpile/Unminify, JSX/Unpack, and Generate. You can hook into these stages using the plugins option.
Supported Plugin Stages:
afterParseafterPrepareafterDeobfuscateafterUnminifyafterUnpack
Plugin API:
Plugins follow a pattern similar to Babel plugins. The plugin function receives an object containing utility libraries:
parse (babel-parser)types (babel-types)traverse (babel-traverse)template (babel-template)matchers (codemod/matchers)
Writing a Plugin:
Plugins can implement pre(), visitor, and post() methods.
function myPlugin({ types: t }) {
return {
pre() {
console.log('Running before traversal');
},
visitor: {
NumericLiteral(path) {
path.replaceWith(t.stringLiteral('x'));
},
},
post() {
console.log('Running after traversal');
},
};
}
const result = await webcrack('1 + 1', {
plugins: {
afterParse: [myPlugin],
},
});
Using Babel Plugins:
Most Babel plugins are compatible if they only use the supported API.
import removeConsole from 'babel-plugin-transform-remove-console';
const result = await webcrack('consol.log(a), b()', {
plugins: {
afterUnminify: [removeConsole],
},
});
import { webcrack } from 'webcrack';
function myPlugin({ types: t }) {
return {
pre() {
console.log('Running before traversal');
},
visitor: {
NumericLiteral(path) {
console.log('Found a number:', path.node.value);
path.replaceWith(t.stringLiteral('x'));
},
},
post() {
console.log('Running after traversal');
},
};
}
const result = await webcrack('1 + 1', {
plugins: {
afterParse: [myPlugin],
},
});
console.log(result.code); // '"xx"'