npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xolifydev/xolicompiler

v2.0.0

Published

A minimalist bytecode compiler for Node.js | Uses bytenode

Downloads

46

Readme

Bytenode

A minimalist bytecode compiler for Node.js.

This tool compiles your JavaScript code into V8 bytecode, so that you can protect your source code. It can be used with Node.js, as well as Electron and NW.js.


Install:

Locally:

user@machine:~$ npm install --save bytenode
const Bytenode = require('bytenode');

Or globally:

user@machine:~$ sudo npm install -g bytenode

Breaking Changes in Bytenode v2:

  • Functions .compileCode() and .compileFile() were removed. Use Bytenode.compile() function instead. See Bytenode API below for more details.

  • Function .compileElectronCode() was removed as well. If you want to compile for Electron, pass its executable to Bytenode CLI (using --use flag). See Bytenode CLI below for more details.

  • Functions .runBytecode() and .runBytecodeFile() were removed. Use Bytenode.run() function instead. See Bytenode API below for more details.

  • Bytenode supports Node.js from v8.8 to v16, and it will throw an error when used with an unsupported Node.js version. Future versions will be added in time of their release.

  • The global bytenode variable was removed. Bytenode must be explicitly required and assigned to a variable.


Known Issues and Limitations:

  • In Node 10.x, Bytenode does not work in debug mode. See #29.

  • Any code that depends on Function.prototype.toString() function will break, because Bytenode removes the source code from .jsc files and puts a dummy code instead. See #34.

  • Arrow functions (especially Async arrow functions) cause crash in Puppeteer and in Electron apps if used in render processes. See #106, #47. They also cause an issue with the ndb debugger. See #135. Use the usual Async functions instead.


Bytenode CLI:

  Usage: bytenode [option] [ FILE... | - ] [arguments]

  Options:
    -h, --help                        show help information.
    -v, --version                     show Bytenode version.

        --use     [ EXECUTABLE ]      use this executable instead of the default Node.js.
                                      Electron and NW.js executables can be used.

    -c, --compile [ FILE... | - ]     compile stdin, a file, or a list of files.
    -n, --no-module                   compile without producing commonjs module.

    -l, --loader  [ FILE | PATTERN ]  create a loader file and optionally define
                                      loader filename or pattern using % as filename replacer.
                                      defaults to %.loader.js

  Examples:

  $ bytenode -c script.js             compile `script.js` to `script.jsc`.
  $ bytenode -c src/*.js              compile all `.js` files in `src/` directory.

  $ bytenode -c ./*.js -l %.load.js   create `filename.load.js` loader files along side `.jsc` files

  $ bytenode script.jsc [arguments]   run `script.jsc` with arguments.

  $ bytenode                          open Node REPL where `.jsc` files can be required directly.

  $ echo 'console.log("Hello");' | bytenode --compile - > hello.jsc
                                      compile from stdin and save to `hello.jsc`.

  $ bytenode -c main.js --use ./node_modules/electron/dist/electron
                                      use Electron executable to compile `main.js`.

  $ bytenode -c main.js --use ./node_modules/nw/nwjs/nw
                                      use NW.js executable to compile `main.js`.

CLI Examples:

  • Compile all .js files in ./app directory.
user@machine:~$ bytenode --compile ./app/*.js
  • Compile all .js files in your project. You may need to enable globstar option in bash (you should add it to ~/.bashrc): shopt -s globstar.
user@machine:~$ bytenode --compile ./**/*.js
  • Compile from stdin and save to hello.jsc file.
user@machine:~$ echo 'console.log("Hello");' | bytenode --compile - > hello.jsc
  • Use Electron executable to compile main.js. (electron must be installed first, npm install electron).
user@machine:~$ bytenode -c main.js --use ./node_modules/electron/dist/electron
  • Use NW.js executable to compile main.js. (nw must be installed first, npm install nw).
user@machine:~$ bytenode -c main.js --use ./node_modules/nw/nwjs/nw

Bytenode API:

Bytenode.compile({ code, filename, compileAsModule, createLoader, loaderPattern, output }) ⇒ string | Buffer

Compiles JavaScript code or filename.

Returns: string | Buffer - The path to the compiled file. If output is set deliberatly to null or undefined, the bytecode buffer will be returned instead.

| Param | Type | Description | | --- | --- | --- | | code | string | The source code that will be compiled. | | filename | string | The JavaScript filename. This filename will be used in stack traces produced by this script. If code is not specified, filename will be compiled instead. | | compileAsModule | boolean | whether to compile code or filename as a CommonJs module.Defaults to true. | | createLoader | boolean | Whether to create loader file along side the compiled file.Defaults to false. | | loaderPattern | string | The loader filename or pattern using '%' as filename replacer.Defaults to %.loader.js. | | output | string | The output filename.Defaults to the same path and name as filename, but with .jsc extension. |

Bytenode.run({ bytecode, filename }) ⇒ any

Runs the compiled bytecode and returns its result.

In most cases, you should use require('./script.jsc') instead, as Bytenode.run() function will NOT return module.exports (in case of compileAsModule: true). In case of compileAsModule: false, it runs bytecode in the current context, so any free variables will become global variables. If it is called twice, it will run bytecode twice too, which can lead to issues and might crash the application.

Returns: any - The result of the very last statement executed in the original script.

| Param | Type | Description | | --- | --- | --- | | bytecode | Buffer | The bytecode buffer which will be run. | | filename | string | The path to the bytecode file. |

Bytenode.registerExtension(ext)

Registers the extension ext in Node.js module system, so that they can be required using require() function.

| Param | Type | Description | | --- | --- | --- | | ext | string | A valid extension with a preceding dot (e.g. .jsc or .bin). |