From 97bfdf383f5a738deaa44ccd8ceb71d8ef3e278a Mon Sep 17 00:00:00 2001 From: "Yonghyun Kim (Freddy)" Date: Thu, 22 Jan 2026 04:24:26 +0900 Subject: [PATCH] chore: remove wasm directory and add wasm release trigger - Remove wasm/ directory (moved to type-ruby/t-ruby-wasm) - Add trigger-wasm-release job to release workflow Closes #31 --- .github/workflows/release.yml | 17 ++++ wasm/build.sh | 70 --------------- wasm/moon.yml | 25 ------ wasm/package-lock.json | 82 ------------------ wasm/package.json | 38 -------- wasm/src/bootstrap.rb | 82 ------------------ wasm/src/index.ts | 157 ---------------------------------- wasm/tsconfig.json | 15 ---- 8 files changed, 17 insertions(+), 469 deletions(-) delete mode 100755 wasm/build.sh delete mode 100644 wasm/moon.yml delete mode 100644 wasm/package-lock.json delete mode 100644 wasm/package.json delete mode 100644 wasm/src/bootstrap.rb delete mode 100644 wasm/src/index.ts delete mode 100644 wasm/tsconfig.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1c067d2..a08b696 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -135,3 +135,20 @@ jobs: --field changed_files="${{ steps.changed.outputs.files }}" env: GH_TOKEN: ${{ secrets.CROSS_REPO_PAT }} + + # WASM 패키지 릴리스 트리거 + trigger-wasm-release: + name: Trigger WASM Release + runs-on: ubuntu-latest + needs: create-release + + steps: + - name: Trigger wasm workflow + run: | + VERSION=${GITHUB_REF#refs/tags/v} + gh workflow run release.yml \ + --repo type-ruby/t-ruby-wasm \ + --field version=$VERSION \ + --field t_ruby_version=$VERSION + env: + GH_TOKEN: ${{ secrets.CROSS_REPO_PAT }} diff --git a/wasm/build.sh b/wasm/build.sh deleted file mode 100755 index 9603110..0000000 --- a/wasm/build.sh +++ /dev/null @@ -1,70 +0,0 @@ -#!/bin/bash -set -e - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" - -echo "=== T-Ruby WASM Build ===" -echo "Script directory: $SCRIPT_DIR" -echo "Project root: $PROJECT_ROOT" - -# Create dist directory -rm -rf "$SCRIPT_DIR/dist" -mkdir -p "$SCRIPT_DIR/dist/lib/t_ruby" - -# Copy only the core compilation files needed for WASM -# Excluded: lsp_server, watcher, cli, cache, package_manager, bundler_integration, benchmark, doc_generator -# These require external gems (listen, etc.) not available in WASM -echo "" -echo "=== Copying T-Ruby core compilation files ===" - -CORE_FILES=( - "version.rb" - "config.rb" - "ir.rb" - "parser_combinator.rb" - "smt_solver.rb" - "type_alias_registry.rb" - "parser.rb" - "union_type_parser.rb" - "generic_type_parser.rb" - "intersection_type_parser.rb" - "type_erasure.rb" - "error_handler.rb" - "declaration_generator.rb" - "compiler.rb" - "constraint_checker.rb" - "type_inferencer.rb" - "runtime_validator.rb" - "type_checker.rb" -) - -for file in "${CORE_FILES[@]}"; do - echo " Copying: t_ruby/$file" - cp "$PROJECT_ROOT/lib/t_ruby/$file" "$SCRIPT_DIR/dist/lib/t_ruby/" -done - -# Process compiler.rb to remove fileutils require (not available in WASM) -echo "" -echo "=== Processing compiler.rb for WASM compatibility ===" -sed -i.bak 's/^require "fileutils"$/# require "fileutils" # Not available in WASM/' "$SCRIPT_DIR/dist/lib/t_ruby/compiler.rb" -rm -f "$SCRIPT_DIR/dist/lib/t_ruby/compiler.rb.bak" - -# Generate manifest.json with file list -echo "" -echo "=== Generating manifest.json ===" -VERSION=$(node -p "require('$SCRIPT_DIR/package.json').version") -cat > "$SCRIPT_DIR/dist/manifest.json" << EOF -{ - "version": "$VERSION", - "files": [ -$(printf ' "%s",\n' "${CORE_FILES[@]}" | sed '$ s/,$//') - ] -} -EOF - -echo "" -echo "=== Build complete ===" -echo "Output directory: $SCRIPT_DIR/dist/" -ls -la "$SCRIPT_DIR/dist/" -ls -la "$SCRIPT_DIR/dist/lib/t_ruby/" diff --git a/wasm/moon.yml b/wasm/moon.yml deleted file mode 100644 index 56cba4d..0000000 --- a/wasm/moon.yml +++ /dev/null @@ -1,25 +0,0 @@ -# @t-ruby/wasm 패키지 moon 설정 -# 문서: https://moonrepo.dev/docs/config/project - -$schema: 'https://moonrepo.dev/schemas/project.json' - -language: 'javascript' -type: 'library' - -# 프로젝트 메타데이터 -project: - name: 'wasm' - description: 'T-Ruby WASM package for browser' - channel: '#t-ruby' - -# 태스크 정의 -tasks: - # 빌드 - build: - command: 'pnpm run build' - inputs: - - '../lib/**/*' - - 'build.sh' - outputs: - - 'dist/**/*' - platform: 'node' diff --git a/wasm/package-lock.json b/wasm/package-lock.json deleted file mode 100644 index 59800ca..0000000 --- a/wasm/package-lock.json +++ /dev/null @@ -1,82 +0,0 @@ -{ - "name": "t-ruby-wasm", - "version": "0.0.7", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "t-ruby-wasm", - "version": "0.0.7", - "license": "MIT", - "devDependencies": { - "@ruby/3.3-wasm-wasi": "^2.7.0", - "@ruby/wasm-wasi": "^2.7.0", - "typescript": "^5.6.0" - }, - "engines": { - "node": ">=18.0.0" - }, - "peerDependencies": { - "@ruby/3.3-wasm-wasi": ">=2.5.0", - "@ruby/wasm-wasi": ">=2.5.0" - }, - "peerDependenciesMeta": { - "@ruby/3.3-wasm-wasi": { - "optional": false - }, - "@ruby/wasm-wasi": { - "optional": false - } - } - }, - "node_modules/@bjorn3/browser_wasi_shim": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@bjorn3/browser_wasi_shim/-/browser_wasi_shim-0.3.0.tgz", - "integrity": "sha512-FlRBYttPRLcWORzBe6g8nmYTafBkOEFeOqMYM4tAHJzFsQy4+xJA94z85a9BCs8S+Uzfh9LrkpII7DXr2iUVFg==", - "dev": true, - "license": "MIT OR Apache-2.0" - }, - "node_modules/@ruby/3.3-wasm-wasi": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/@ruby/3.3-wasm-wasi/-/3.3-wasm-wasi-2.7.2.tgz", - "integrity": "sha512-NTA/PqrnOKLhjseOD4JsC7LiaNgQ6FGw3OQxKPD4EoqSh0/odIp6clWlPtaforwIKAuxpV/rOdJ+fBb3USN7xQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@ruby/wasm-wasi": "^2.0.0" - } - }, - "node_modules/@ruby/wasm-wasi": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/@ruby/wasm-wasi/-/wasm-wasi-2.7.2.tgz", - "integrity": "sha512-KiVtLRFUC4V9hiiNV+ABzZL8tYQ0/nhBEQw9Lu+wj4zxCOw43RYcu+Yru7hwlb8ADppGRKYSv0CeDQqZ8OSqKw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@bjorn3/browser_wasi_shim": "^0.3.0", - "tslib": "^2.8.1" - } - }, - "node_modules/tslib": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", - "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", - "dev": true, - "license": "0BSD" - }, - "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - } - } -} diff --git a/wasm/package.json b/wasm/package.json deleted file mode 100644 index d6f64ce..0000000 --- a/wasm/package.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name": "@t-ruby/wasm", - "version": "0.0.8", - "description": "T-Ruby compiler library files for WebAssembly - used by the playground to load T-Ruby in the browser", - "type": "module", - "exports": { - "./manifest.json": "./dist/manifest.json", - "./lib/*": "./dist/lib/*" - }, - "files": [ - "dist/" - ], - "scripts": { - "build": "bash ./build.sh", - "prepublishOnly": "npm run build" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/type-ruby/t-ruby.git", - "directory": "wasm" - }, - "keywords": [ - "ruby", - "wasm", - "webassembly", - "compiler", - "t-ruby", - "typescript", - "types", - "static-typing" - ], - "author": "T-Ruby Team", - "license": "MIT", - "bugs": { - "url": "https://github.com/type-ruby/t-ruby/issues" - }, - "homepage": "https://type-ruby.github.io" -} diff --git a/wasm/src/bootstrap.rb b/wasm/src/bootstrap.rb deleted file mode 100644 index 1d2d5a3..0000000 --- a/wasm/src/bootstrap.rb +++ /dev/null @@ -1,82 +0,0 @@ -# frozen_string_literal: true - -# T-Ruby WASM Bootstrap -# This file initializes the T-Ruby compiler in a WebAssembly environment - -require "json" - -# Add T-Ruby lib to load path -$LOAD_PATH.unshift("/t-ruby/lib") - -# Load T-Ruby compiler -require "t_ruby" - -# Global compiler instance (lazy initialized) -$trb_compiler = nil - -def get_compiler - $trb_compiler ||= TRuby::Compiler.new -end - -# Compile T-Ruby code to Ruby and RBS -# -# @param code [String] T-Ruby source code -# @return [String] JSON result with success, ruby, rbs, errors keys -def __trb_compile__(code) - compiler = get_compiler - - begin - result = compiler.compile_string(code) - - { - success: result[:errors].empty?, - ruby: result[:ruby] || "", - rbs: result[:rbs] || "", - errors: result[:errors] || [] - }.to_json - rescue TRuby::ParseError => e - { - success: false, - ruby: "", - rbs: "", - errors: [format_error(e)] - }.to_json - rescue StandardError => e - { - success: false, - ruby: "", - rbs: "", - errors: ["Compilation error: #{e.message}"] - }.to_json - end -end - -# Format error message with line/column info if available -def format_error(error) - if error.respond_to?(:line) && error.respond_to?(:column) - "Line #{error.line}, Column #{error.column}: #{error.message}" - else - error.message - end -end - -# Check if T-Ruby is properly loaded -def __trb_health_check__ - { - loaded: defined?(TRuby) == "constant", - version: defined?(TRuby::VERSION) ? TRuby::VERSION : "unknown", - ruby_version: RUBY_VERSION - }.to_json -end - -# Version info -def __trb_version__ - { - t_ruby: defined?(TRuby::VERSION) ? TRuby::VERSION : "unknown", - ruby: RUBY_VERSION - }.to_json -end - -puts "[T-Ruby WASM] Bootstrap loaded successfully" -puts "[T-Ruby WASM] Ruby version: #{RUBY_VERSION}" -puts "[T-Ruby WASM] T-Ruby version: #{TRuby::VERSION}" if defined?(TRuby::VERSION) diff --git a/wasm/src/index.ts b/wasm/src/index.ts deleted file mode 100644 index 2e490de..0000000 --- a/wasm/src/index.ts +++ /dev/null @@ -1,157 +0,0 @@ -/** - * T-Ruby WASM - Compile T-Ruby (.trb) to Ruby (.rb) in the browser - * - * @example Browser usage: - * ```typescript - * import { DefaultRubyVM } from '@ruby/wasm-wasi/dist/browser'; - * import { initTRubyCompiler, RUBY_WASM_CDN_URL } from 't-ruby-wasm'; - * - * // Load Ruby WASM - * const response = await fetch(RUBY_WASM_CDN_URL); - * const module = await WebAssembly.compileStreaming(response); - * const { vm } = await DefaultRubyVM(module); - * - * // Initialize T-Ruby compiler - * const compiler = await initTRubyCompiler(vm); - * - * // Compile T-Ruby code - * const result = compiler.compile(` - * def greet(name: String): String - * "Hello, #{name}!" - * end - * `); - * - * console.log(result.ruby); // Ruby code without type annotations - * console.log(result.rbs); // RBS type signatures - * ``` - */ - -export interface CompileResult { - success: boolean; - ruby: string; - rbs: string; - errors: string[]; -} - -export interface HealthCheckResult { - loaded: boolean; - version: string; - ruby_version: string; -} - -export interface VersionInfo { - t_ruby: string; - ruby: string; -} - -export interface TRubyCompiler { - compile(code: string): CompileResult; - healthCheck(): HealthCheckResult; - getVersion(): VersionInfo; -} - -export interface InitOptions { - libPath?: string; -} - -/** - * CDN URL for the Ruby WASM binary with stdlib - */ -export const RUBY_WASM_CDN_URL = 'https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.7.0/dist/ruby+stdlib.wasm'; - -/** - * Bootstrap Ruby code for initializing T-Ruby compiler in WASM - */ -const BOOTSTRAP_CODE = ` -require "json" - -$trb_compiler = nil - -def get_compiler - $trb_compiler ||= TRuby::Compiler.new -end - -def __trb_compile__(code) - compiler = get_compiler - - begin - result = compiler.compile_string(code) - - { - success: result[:errors].empty?, - ruby: result[:ruby] || "", - rbs: result[:rbs] || "", - errors: result[:errors] || [] - }.to_json - rescue TRuby::ParseError => e - { - success: false, - ruby: "", - rbs: "", - errors: [e.message] - }.to_json - rescue StandardError => e - { - success: false, - ruby: "", - rbs: "", - errors: ["Compilation error: " + e.message] - }.to_json - end -end - -def __trb_health_check__ - { - loaded: defined?(TRuby) == "constant", - version: defined?(TRuby::VERSION) ? TRuby::VERSION : "unknown", - ruby_version: RUBY_VERSION - }.to_json -end - -def __trb_version__ - { - t_ruby: defined?(TRuby::VERSION) ? TRuby::VERSION : "unknown", - ruby: RUBY_VERSION - }.to_json -end - -puts "[T-Ruby WASM] Compiler initialized" -`; - -/** - * Initialize the T-Ruby compiler with a Ruby VM instance - */ -export async function initTRubyCompiler(vm: any, options: InitOptions = {}): Promise { - const libPath = options.libPath || '/t-ruby/lib'; - - // Add T-Ruby lib to Ruby load path and require it - vm.eval(` - $LOAD_PATH.unshift("${libPath}") - require "t_ruby" - `); - - // Initialize the bootstrap code - vm.eval(BOOTSTRAP_CODE); - - return { - compile(code: string): CompileResult { - const resultJson = vm.eval(`__trb_compile__(${JSON.stringify(code)})`); - return JSON.parse(resultJson.toString()); - }, - - healthCheck(): HealthCheckResult { - const resultJson = vm.eval('__trb_health_check__'); - return JSON.parse(resultJson.toString()); - }, - - getVersion(): VersionInfo { - const resultJson = vm.eval('__trb_version__'); - return JSON.parse(resultJson.toString()); - } - }; -} - -export default { - RUBY_WASM_CDN_URL, - initTRubyCompiler -}; diff --git a/wasm/tsconfig.json b/wasm/tsconfig.json deleted file mode 100644 index e85b3c9..0000000 --- a/wasm/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "module": "ESNext", - "moduleResolution": "node", - "declaration": true, - "outDir": "./dist", - "rootDir": "./src", - "strict": true, - "esModuleInterop": true, - "skipLibCheck": true - }, - "include": ["src/index.ts"], - "exclude": ["node_modules", "dist", "src/bootstrap.rb"] -}