{"library":"rscute","title":"rscute: In-memory TypeScript Bundler and Executor","description":"rscute is an in-memory TypeScript bundler and executor, leveraging `@swc/core` for high-performance AST transformation and compilation. Currently at stable version 1.2.2, it exhibits an active release cadence with frequent updates. Its core functionality involves intercepting Node.js `require` calls, recursively resolving TypeScript and JavaScript dependencies, and evaluating them as a single, flattened bundle entirely within memory. Key differentiators include its transparent runtime execution capabilities for TypeScript files, a dedicated API for in-memory bundling without execution, and automatic symbol mangling to prevent name collisions in the flattened module scope. It supports various entry points, including a CLI, a Node.js `-r` flag hook, and dedicated programmatic APIs for code execution in a sandboxed VM context or for bundling to a string.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install rscute"],"cli":{"name":"rscute","version":null}},"imports":["const { register } = require('rscute/register');","import { execute } from 'rscute/vm';","import { bundle } from 'rscute/bundle';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { bundle } from 'rscute/bundle';\nimport { execute } from 'rscute/vm';\nimport path from 'path';\nimport fs from 'fs';\n\n// Create a temporary script.ts for the example\nconst tempScriptContent = `\n  export const getMessage = (name: string): string => {\n    return \\`Hello, \\${name} from bundled code!\\`;\n  };\n  export const someValue = 42;\n`;\nconst tempScriptPath = path.resolve(__dirname, 'temp-script.ts');\nfs.writeFileSync(tempScriptPath, tempScriptContent);\n\ntry {\n  // 1. Bundle the TypeScript file into a single JavaScript string\n  console.log('Bundling temp-script.ts...');\n  const bundledCode = bundle(tempScriptPath);\n  console.log('\\n--- Bundled Code (truncated) ---');\n  console.log(bundledCode.substring(0, 200) + '...');\n\n  // 2. Execute the bundled code in a VM context\n  console.log('\\nExecuting bundled code in VM...');\n  const moduleExports = execute(bundledCode);\n\n  // 3. Use the exports from the executed code\n  if (moduleExports && typeof moduleExports.getMessage === 'function') {\n    console.log(`Result from executed bundle: ${moduleExports.getMessage('rscute user')}`);\n    console.log(`Exported value: ${moduleExports.someValue}`);\n  } else {\n    console.error('Failed to get expected exports from bundled code.');\n  }\n} catch (error) {\n  console.error('An error occurred:', error);\n} finally {\n  // Clean up the temporary file\n  fs.unlinkSync(tempScriptPath);\n}\n","lang":"typescript","description":"This example demonstrates how to use `rscute` programmatically to first bundle a TypeScript file and its dependencies into a single JavaScript string, and then execute that bundled string within an isolated Node.js `vm.Context` to access its exports. It highlights `rscute`'s capabilities for both in-memory compilation and runtime execution.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}