Skip to content

Static optimizer for QuickJS-bridged expensive API calls using TS type info + JSON whitelist

License

Notifications You must be signed in to change notification settings

Bedrock-OSS/qjs-opt

Repository files navigation

qjs-opt

Static optimizer for QuickJS-bridged expensive API calls using TS type info + JSON whitelist.

QuickJS performs native calls for most property or method access on native objects. qjs-opt rewrites Minecraft Bedrock addon code so repeated lookups on @minecraft/server native objects are cached in local variables.

CLI Usage

npx @bedrock-oss/qjs-opt [options] <file-or-folder>

Key scenarios:

  • Single file with pre-installed types:

    npx @bedrock-oss/qjs-opt src/loop.js
    
  • Single file with dependencies to install into a temporary workspace:

    npx @bedrock-oss/qjs-opt --deps @minecraft/server@^2.2.0 src/loop.js
    
  • Project directory that already has a tsconfig.json:

    npx @bedrock-oss/qjs-opt ./addon
    
  • Project directory without a tsconfig.json (dependencies required):

    npx @bedrock-oss/qjs-opt --deps @minecraft/server@^2.2.0 ./scripts
    

Useful flags:

  • --config <path> – path to a JSON config.
  • --config-mode <default|merge|override> – how to combine the supplied config with the built-in defaults.
  • --deps <a,b,...> – packages to install into the temporary workspace.
  • --tsconfig <path> – force a specific tsconfig file for folder runs.
  • --workspace <path> – reuse a pre-created workspace directory.

Config Modes

  • default – use the built-in defaults only.
  • merge – default behaviour; merge user rules with defaults.
  • override – use only the supplied rules. A config must be provided.

Library API

import { optimize, resolveConfig, defaultConfig } from "qjs-opt";

const result = optimize({
  targetPath: "./addon",
  config: "./my-config.json",
  configMode: "merge",
});

console.log(result.changed, "files updated");

About

Static optimizer for QuickJS-bridged expensive API calls using TS type info + JSON whitelist

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published