Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using pionxzh/wakaru instead of/alongside webcrack #3

Open
0xdevalias opened this issue Nov 13, 2023 · 4 comments
Open

Consider using pionxzh/wakaru instead of/alongside webcrack #3

0xdevalias opened this issue Nov 13, 2023 · 4 comments

Comments

@0xdevalias
Copy link

I only came across webcrack, wakaru, and this project today; but in some basic tests I was doing between webpack and wakaru, I found that the latter seemed to produce much nicer output by default when used on webpacked files:

I wonder if it would make a good addition to this humanify tool?

@jehna
Copy link
Owner

jehna commented Nov 13, 2023

That's a great addition, thanks! I was searching for similar tools like webcrack, but I think I've missed wakaru. I'll definitely give it a try!

@jehna
Copy link
Owner

jehna commented Nov 13, 2023

It seems that wakaru does not yet have a (functioning) npm package, which makes usage harder. I'll add an issue to their repo about it. I think I can come up with a PoC without a package too, but for official support it would be better to have a sane way to have it as a dependency 😅

@0xdevalias
Copy link
Author

0xdevalias commented Nov 13, 2023

That's a great addition, thanks! I was searching for similar tools like webcrack, but I think I've missed wakaru

@jehna No worries :) Yeah, I was looking pretty deep in this space only like 4 months ago and didn't come across webcrack or wakaru (or humanify 😜), so was exciting to be able to update my gist with a bunch of new resources today!

I think I can come up with a PoC without a package too, but for official support it would be better to have a sane way to have it as a dependency

@jehna Yeah, definitely agree.

@0xdevalias
Copy link
Author

NPM package has been released. You can check the README for more information.

Originally posted by @pionxzh in pionxzh/wakaru#39 (comment)


https://github.com/pionxzh/wakaru#-using-the-api

📦 Using the API

npm install @wakaru/unpacker @wakaru/unminify
# or
pnpm install @wakaru/unpacker @wakaru/unminify
# or
yarn add @wakaru/unpacker @wakaru/unminify

@wakaru/unpacker

import { unpack } from '@wakaru/unpacker';

const { modules, moduleIdMapping } = await unpack(sourceCode);
for (const mod of modules) {
  const filename = moduleIdMapping[mod.id] ?? `module-${mod.id}.js`;
  fs.writeFileSync(outputPath, mod.code, 'utf-8');
}

@wakaru/unminify

import { runDefaultTransformation, runTransformations } from '@wakaru/unminify';

const file = {
  source: '...', // source code
  path: '...',   // path to the file, used for advanced usecases. Can be empty.
}
// This function will apply all rules that are enabled by default.
const { code } = await runDefaultTransformation(file);

// You can also specify the rules to apply. Order matters.
const rules = [
  'un-esm',
  ...
]
const { code } = await runTransformations(file, rules);

You can check all the rules at /unminify/src/transformations/index.ts.

Please aware that this project is still in early development. The API might change in the future.

And the bundle size of these packages are huge. It might be reduced in the future. Use with caution on the browser (Yes, like the playground, it can run on the browser).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants