Skip to content

feat: migrate custom extensions to scratch-vm monorepo (Phase 2)#1

Merged
takaokouji merged 3 commits into
developfrom
feature/phase2-migrate-scratch-vm
Jan 18, 2026
Merged

feat: migrate custom extensions to scratch-vm monorepo (Phase 2)#1
takaokouji merged 3 commits into
developfrom
feature/phase2-migrate-scratch-vm

Conversation

@takaokouji
Copy link
Copy Markdown

Summary

Migrated Smalruby-specific extensions and core file modifications from the standalone scratch-vm repository to the monorepo structure (Phase 2 of Issue #29).

Extensions Added

High Priority Extensions

scratch3_mesh_v2: GraphQL/AppSync-based mesh networking

  • Mesh client, service, and rate limiter
  • GQL operations and utility functions
  • Environment variable configuration support

microbitMore: Enhanced micro:bit support

  • BLE and Serial communication
  • Tilt, touch, and gesture blocks
  • Extended sensor support

Medium Priority Extensions

scratch3_mesh: Legacy mesh networking (P2P WebRTC)

  • Mesh host, peer, and service
  • Backward compatibility support

koshien: Koshien programming contest extension

  • Contest-specific blocks and functionality

scratch3_smalrubot_s1: Smalrubot S1 robot control

  • Robot control blocks and commands

Core File Updates

extension-manager.js

  • Registered custom extensions
  • Added mesh, meshV2, smalrubotS1 to builtinExtensions
  • Added microbitMore and koshien with formatMessage support

runtime.js

  • Added BEFORE_STEP event
  • Added getPeripheralConnectedMessage method
  • Debug logging for broadcast events

Other Core Files

  • virtual-machine.js: VM core functionality extensions
  • block-utility.js: Custom utility functions
  • blocks.js: Block processing extensions
  • target.js: Target management changes

Utility Files

  • debug-logger.js: Debug logging utility
  • task-queue.js: Task queue implementation
  • Modified util files for Smalruby-specific needs

Configuration

.env.example

Environment variable template for:

  • Mesh V2 GraphQL endpoint configuration
  • AppSync API key and AWS region
  • Data update and sync intervals

Lint Fixes

  • Fixed all ESLint errors (102 → 0)
  • Added /* global process */ comments for Node.js environment variables
  • Auto-fixed code style issues (indentation, formatting)
  • Remaining warnings are JSDoc-related (consistent with upstream)

Test Coverage

# Build test
npm run build -w @scratch/scratch-vm

# Lint test
npm run lint -w @scratch/scratch-vm

Build and lint passed successfully.

Changes

  • 32 files changed
  • 11,836 insertions(+)
  • 307 deletions(-)

Related Issues

Part of #29 (Phase 2: scratch-vm migration)

🤖 Generated with Claude Code

Migrated Smalruby-specific extensions and core file modifications from
the standalone scratch-vm repository to the monorepo structure.

## Extensions Added

### High Priority Extensions
- **scratch3_mesh_v2**: GraphQL/AppSync-based mesh networking
  - Mesh client, service, and rate limiter
  - GQL operations and utility functions
  - Environment variable configuration support

- **microbitMore**: Enhanced micro:bit support
  - BLE and Serial communication
  - Tilt, touch, and gesture blocks
  - Extended sensor support

### Medium Priority Extensions
- **scratch3_mesh**: Legacy mesh networking (P2P WebRTC)
  - Mesh host, peer, and service
  - Backward compatibility support

- **koshien**: Koshien programming contest extension
  - Contest-specific blocks and functionality

- **scratch3_smalrubot_s1**: Smalrubot S1 robot control
  - Robot control blocks and commands

## Core File Updates

- **extension-manager.js**: Registered custom extensions
  - Added mesh, meshV2, smalrubotS1 to builtinExtensions
  - Added microbitMore and koshien with formatMessage support

- **runtime.js**: Mesh functionality integration
  - Added BEFORE_STEP event
  - Added getPeripheralConnectedMessage method
  - Debug logging for broadcast events

- **virtual-machine.js**: VM core functionality extensions
- **block-utility.js**: Custom utility functions
- **blocks.js**: Block processing extensions
- **target.js**: Target management changes

## Utility Files

- **debug-logger.js**: Debug logging utility
- **task-queue.js**: Task queue implementation
- Modified util files for Smalruby-specific needs

## Configuration

- **.env.example**: Environment variable template
  - Mesh V2 GraphQL endpoint configuration
  - AppSync API key and AWS region
  - Data update and sync intervals

## Lint Fixes

- Fixed all ESLint errors (102 → 0)
- Added `/* global process */` comments for Node.js environment variables
- Auto-fixed code style issues (indentation, formatting)
- Remaining warnings are JSDoc-related (consistent with upstream)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
takaokouji and others added 2 commits January 18, 2026 22:05
Updated ESLint configuration to match upstream and reverted core files
to upstream state, then re-applied only Smalruby-specific customizations.
This ensures easier upstream tracking and reduces unnecessary diffs.

## Changes

### ESLint Configuration
- Updated `eslint-config-scratch` from 12.0.44 to 12.0.45 (upstream version)
- This aligns linting rules with upstream scratch-editor

### Core Files Alignment
Reverted the following files to upstream state, then re-applied only
Smalruby customizations:

**block-utility.js**
- Added `lastInstance` tracking for extension use

**target.js**
- Added `setVariableValue()` method

**virtual-machine.js**
- Modified PERIPHERAL_CONNECTED/DISCONNECTED event listeners to pass data
- Removed EXTENSION_DATA_LOADING event listener
- Added `getPeripheralConnectedMessage()` method

**runtime.js**
- Added `BEFORE_STEP` event constant
- Removed `EXTENSION_DATA_LOADING` constant and related emit calls
- Added `getPeripheralConnectedMessage()` method
- Added `BEFORE_STEP` event emission in _step() method

**blocks.js**
- Fully reverted to upstream (no Smalruby customizations)

## Benefits

- Upstream code style is preserved (no unnecessary parentheses removal, etc.)
- Only Smalruby-specific functional changes remain in diffs
- Future upstream merges will be cleaner and easier
- Lint still passes with 0 errors, 753 warnings (same as upstream)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Removed src/util/task-queue.js as it is not used in the codebase.

## Reason

- task-queue.js exists in upstream scratch-vm but is not actively used
- The monorepo now has packages/task-herder with TaskQueue.ts
  (TypeScript implementation with enhanced features)
- No references to task-queue.js found in scratch-vm source code
- Keeping unused files makes upstream tracking harder

## Verification

Confirmed no usage with:
```bash
grep -r "task-queue" packages/scratch-vm/src --include="*.js"
```

Result: No matches (0 usage)

Note: debug-logger.js is kept as it's used by Smalruby extensions:
- scratch3_smalrubot_s1
- scratch3_mesh
- scratch3_mesh/mesh-host
- scratch3_mesh/mesh-service

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@takaokouji takaokouji merged commit 1aede47 into develop Jan 18, 2026
@takaokouji takaokouji deleted the feature/phase2-migrate-scratch-vm branch January 18, 2026 13:19
takaokouji pushed a commit that referenced this pull request Mar 8, 2026
* fix: run stacks in response to stack click events

* refactor: listen for regular click events to run block stacks
takaokouji pushed a commit that referenced this pull request Mar 8, 2026
takaokouji added a commit that referenced this pull request Apr 12, 2026
- Add next-steps guidance after student joins classroom (#1)
- Add submit hint for students who haven't submitted yet (#2)
- Add STAGE !== 'prod' failsafe for DEV_BYPASS_TOKEN (#3)
- Add fullscreen tooltip to join code expand button (#4)
- Improve member grid prompt to clarify clickable seats (#5)
- Remove window._classroomIdToken debug variable (#8)

Closes #495

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant