New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

little-byte

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

little-byte

Node.js bytecode compiler

latest
Source
npmnpm
Version
0.1.4
Version published
Weekly downloads
8
300%
Maintainers
1
Weekly downloads
 
Created
Source

little-byte

Compile Node.js code into bytecode.

中文文档 | Chinese Docs

typescript npm version Test Suite

Install

$ npm install --save-dev little-byte

Compile App

Prepare Build Script

Create build/index.js

const { walker } = require('little-byte').default;
const path = require('path');

walker.start({
  inputDir: path.join(__dirname, '../src'),
  outputDir: path.join(__dirname, '../dist'),
  onFile(fileInfo, defaultAction) {
    if (fileInfo.relativePath.startsWith('foobar/')) {
      return 'ignore';
    }

    if (fileInfo.ext === '.jpg') {
      return 'ignore';
    }

    if (fileInfo.name === 'my-dog.txt') {
      return 'ignore';
    }

    if (fileInfo.isScript) {
      return 'compile';
    } else {
      // copy none-js files to dist folder
      return 'copy';
    }
  }
});

Build

$ node build/index.js

Run Compiled App

Create app-entry.js


require('little-byte');

// now you can require *.bytecode
require('./dist/index');

Limitations

Using same Node.js version for building and running bytecode

The format of bytecode might change over Node.js versions.

Bytecode does not protect constant values

It's possible to recover constant strings from bytecode with hex editor.

API


littleByte.compiler.compileFile(filePath: string, outputDir?: string): Promise<void>

littleByte.loader.loadBytecode(filePath: string): vm.Script;

littleByte.loader.execByteCode(filePath: string): any;


type WalkAction = 'ignore' | 'compile' | 'copy';

type FileInfo = {
    path: string;
    relativePath: string;
    name: string;
    ext: string;
    isScript: boolean;
};

interface WalkOptions {
    silent?: boolean;
    inputDir: string;
    outputDir: string;
    onFile: (fileinfo: FileInfo, defaultAction: WalkAction) => WalkAction;
}

littleByte.walker.start(options: WalkOptions): Promise<void>;

Principles of protecting Node.js source code through bytecode

Source code and Bytecode performance test

Node.js bytecode source related issues completed

Powered By Google Translate

Keywords

node.js

FAQs

Package last updated on 10 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts