shuji

repository·main·Indexed 22 days ago

https://github.com/paazmaya/shuji

A command-line utility and programmatic library (version 0.8.0) used to reverse engineer original JavaScript and CSS source files from sourcemaps. It provides a CLI for extracting sources from files or directories with options to preserve folder structure and filter files via regular expressions, as well as a handleInput function for programmatic use.

Tokens
1.1K
Snippets
3
Records
7
Agent score
78%

What's inside shuji

  1. Install the shuji CLI

    main

    Install the shuji command line utility globally using npm. Depending on your platform, you may need to use sudo to grant elevated privileges.

    Prerequisites:

    • Node.js version 24.12.0 or higher (the active LTS version).
    npm install --global shuji
  2. Reverse engineer sources from sourcemaps with shuji

    main

    Use the shuji command to reconstruct original JavaScript and CSS source files from a provided sourcemap file or directory.

    Basic Usage:

    shuji <file|directory> [options]

    Example: To extract sources from file.js.map into a directory named folder:

    shuji file.js.map -o folder
  3. Command line options for shuji

    main

    The shuji CLI provides several options to control the extraction process:

    OptionLong FlagDescription
    -h--helpHelp and usage instructions
    -o <String>--output-dir <String>Output directory (default: .)
    -p--preservePreserve the sourcemap's original folder structure
    -M <String>--match <String>Regular expression for matching and filtering files (default: \.map$)
    -v--verboseVerbose output; prints which file is currently being processed
    -V--versionDisplay version number
    shuji - Reverse engineering JavaScript and CSS sources from sourcemaps
    Usage: shuji [options] <file|directory>
    
      -h, --help               Help and usage instructions
      -o, --output-dir String  Output directory - default: .
      -p, --preserve           Preserve sourcemap's original folder structure.
      -M, --match String       Regular expression for matching and filtering files -
                               default: \.map$
      -v, --verbose            Verbose output, will print which file is currently being
                               processed
      -V, --version            Version number
  4. Reverse engineer sources using handleInput

    main

    The handleInput function is the primary programmatic entrypoint for shuji. It takes a path to a source map file and extracts the original JavaScript or CSS source contents.

    It returns an array of [filename, content] pairs representing the recovered source files. If no source map is found or no sources can be extracted, it returns an empty array and logs an error to console.error.

  5. Reference the shuji CLI options

    main

    The following options are available for the shuji command:

    OptionAliasTypeDefaultDescription
    --help-hBooleanfalseHelp and usage instructions
    --version-VBooleanfalseVersion number
    --verbose-vBooleanfalseVerbose output, will print which file is currently being processed
    --output-dir-oString'.'Output directory
    --preserve-pBooleanfalsePreserve the original folder structure under the current directory
    --match-MString'\.map$'Regular expression for matching and filtering files
  6. Configure handleInput options

    main

    When calling handleInput, you can provide an options object to control the extraction process:

    OptionTypeDefaultDescription
    verbosebooleanfalseIf true, logs processing progress to the console.
    preservebooleanfalseIf true, attempts to preserve the original folder structure of the source files.
  7. Use the shuji CLI to reverse engineer sourcemaps

    main

    The shuji command-line tool allows you to reverse engineer JavaScript and CSS sources from sourcemaps. You can provide a single file or a directory as input. The tool will find matching sourcemaps and extract the original source files into a specified output directory.

    Basic Usage:

    shuji [options] <file|directory>

    Example: To process all .map files in a directory named dist and output the results to a folder named recovered-sources while preserving the original folder structure:

    shuji -o recovered-sources -p dist