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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@scratch-code/vm-blocks

v0.1.0

Published

Convert Scratch VM runtime blocks to and from @scratch-code/ast

Downloads

30

Readme

@scratch-code/vm-blocks

Convert Scratch VM's hydrated runtime block array to and from the semantic AST from @scratch-code/ast.

Installation

npm install @scratch-code/vm-blocks @scratch-code/turbowarp-blocks

This package is ESM-only and requires Node.js 22 or newer. A block-spec registry is supplied by the caller; the example below uses the TurboWarp catalog.

import { createTurboWarpBlockRegistry } from '@scratch-code/turbowarp-blocks';
import { deserializeVmBlocks, serializeVmBlocks } from '@scratch-code/vm-blocks';

const registry = createTurboWarpBlockRegistry();
const scripts = deserializeVmBlocks(Object.values(target.blocks._blocks), registry);

await vm.shareBlocksToTarget(serializeVmBlocks(scripts), destination.id);

deserializeVmBlocks() accepts the properties produced by Object.values(target.blocks._blocks) and also tolerates defaults omitted from the minimal objects accepted by shareBlocksToTarget. Missing block specs remain explicit registry errors. The package parses and validates the VM graph directly; it does not depend on the SB3 codec.

serializeVmBlocks() emits complete block, input, and field objects. It derives parent, next, topLevel, input ownership, shadow flags, field name, and variableType from the AST. Empty inputs are omitted. Redundant omitted/null details are canonicalized rather than preserved byte-for-byte. Input array order only determines the stable order of disconnected root Scripts and is otherwise not semantic.

An input shadow edge can infer an omitted block shadow flag, but never overrides an explicit value. A conflicting explicit flag throws InvalidVmBlocksError. Only primitive literal shadow blocks (number, text, color, matrix, and note) fold into scalar AST inputs; variable, list, broadcast, and menu reporters remain normal AST Blocks.

Identity and metadata

Every runtime block must already have a unique non-empty ID. Semantic blocks and menu/reporter blocks use Block.metadata.scratch.id; scalar string, number, color, matrix, and note inputs use Input.metadata.scratch.id. Missing IDs and duplicates throw. The serializer never creates IDs or mutates its input. The VM will replace these IDs when shareBlocksToTarget imports the array.

Procedure mutations use the AST's semantic mutation model. Raw extension and legacy mutations plus block comment IDs live in versioned metadata.vmBlocks; use getVmBlocksBlockMetadata() instead of reading the namespace directly. This package-owned metadata contains only version, an optional raw mutation, and an optional comment ID; it never stores a complete VM block snapshot. Field values remain arbitrary JSON values so historical VM data is not coerced to text.

The package only converts blocks. Extension URL wrappers, variables, lists, broadcast declarations, target comments, assets, and target state remain the caller's responsibility.

Scratch VM validation

After building the workspace, validate against the pinned local VM checkout:

pnpm --filter @scratch-code/vm-blocks test:vm -- /path/to/scratch-vm

An external SB3 corpus can be audited with:

pnpm --filter @scratch-code/vm-blocks test:corpus -- /path/to/scratch-vm /path/to/sb3-projects

Projects requiring block specs absent from the TurboWarp registry are reported and skipped rather than guessed.

License

MIT