{"id":15811,"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.","status":"active","version":"1.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/refirst11/rscute","tags":["javascript","swc","bundler","executor","typescript","cli","runtime","node","cjs"],"install":[{"cmd":"npm install rscute","lang":"bash","label":"npm"},{"cmd":"yarn add rscute","lang":"bash","label":"yarn"},{"cmd":"pnpm add rscute","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for high-performance TypeScript compilation and AST transformation.","package":"@swc/core","optional":false}],"imports":[{"note":"The `register` function is specifically designed for CommonJS environments as a Node.js runtime hook, typically used with `node -r` or directly via `require()`.","wrong":"import { register } from 'rscute/register';","symbol":"register","correct":"const { register } = require('rscute/register');"},{"note":"The `execute` API, introduced in v1.1.0, is primarily intended for use in ESM contexts to compile and run code in a VM sandbox.","wrong":"const { execute } = require('rscute/vm');","symbol":"execute","correct":"import { execute } from 'rscute/vm';"},{"note":"The `bundle` API was introduced in v1.2.0 for programmatic in-memory bundling and is designed for ESM module usage.","wrong":"const { bundle } = require('rscute/bundle');","symbol":"bundle","correct":"import { bundle } from 'rscute/bundle';"}],"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."},"warnings":[{"fix":"Review release notes for `v1.2.0` and update programmatic usage to leverage the new `rscute/bundle` API or `rscute/vm` module as demonstrated in the documentation.","message":"Version 1.2.0 introduced a major architectural refactoring, cleanly separating the core AST engine from execution environments. While new APIs (`rscute/bundle`) were added, this change may affect applications relying on older undocumented programmatic interfaces or internal structures.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Thoroughly test your codebase after upgrading to `v1.0.0` or later, especially if using complex or experimental TypeScript features. Report any regressions to the `rscute` maintainers.","message":"Version 1.0.0 replaced regular expression processing with full AST parsing. While this generally improves accuracy and robustness, it might introduce subtle breaking changes for projects with highly specific or unusual TypeScript syntax that was implicitly handled (or mishandled) by the previous regex-based approach.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use `pnpm exec rscute` instead of `npx rscute` for running CLI commands with pnpm.","message":"When using `pnpm` as your package manager, direct `npx rscute` commands may not work as expected due to how `npx` resolves packages with `pnpm`.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure your module resolution paths are explicit or adjust your project's import statements if they were implicitly relying on `baseUrl` behavior removed in `rscute@1.2.2`. Consider using `paths` mapping in `tsconfig.json` for explicit resolution.","message":"Version 1.2.2 removed `baseUrl` logic for TS6. This change might impact projects that rely on specific `baseUrl` configurations within their `tsconfig.json` for module resolution, potentially leading to \"Cannot find module\" errors.","severity":"breaking","affected_versions":">=1.2.2"},{"fix":"Use `require('rscute/register')` for the CommonJS hook. Use `import { ... } from 'rscute/vm'` or `rscute/bundle` within an ESM module context (e.g., `\"type\": \"module\"` in `package.json` or `.mjs` files).","message":"`rscute` provides both CommonJS (`rscute/register`) and ESM-focused (`rscute/vm`, `rscute/bundle`) APIs. Mixing `require()` for ESM-only modules or `import` for CommonJS-only modules will lead to errors.","severity":"gotcha","affected_versions":">=1.2.0"},{"fix":"Upgrade to `rscute@1.1.5` or newer immediately to benefit from security improvements.","message":"Version 1.1.5 included a \"supply-chain security update\" and enabled npm provenance. While specific details were not provided, users on older versions should upgrade to `>=1.1.5` to ensure they receive critical security patches related to the package's integrity.","severity":"breaking","affected_versions":"<1.1.5"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Verify the module path is correct relative to the importing file or `filePath` option. Ensure dependencies are installed. If using `baseUrl`, review your `tsconfig.json` and module resolution after `rscute@1.2.2`.","cause":"`rscute` could not resolve an imported module's path, possibly due to incorrect `baseUrl` settings (especially after v1.2.2), missing `node_modules` entry, or incorrect relative paths.","error":"Error: Cannot find module 'some-module' from 'path/to/file.ts'"},{"fix":"For CommonJS, ensure `const { register } = require('rscute/register');` is used. The `register` API is primarily a CommonJS hook.","cause":"Attempting to use `import { register } from 'rscute/register'` in an ESM context, or trying to access `register` without destructuring in CommonJS.","error":"TypeError: register is not a function"},{"fix":"Ensure your Node.js project is configured for ESM by setting `\"type\": \"module\"` in `package.json` or by using `.mjs` file extensions for files containing `import` statements.","cause":"Running a file with `import` statements (e.g., `rscute/vm` or `rscute/bundle` APIs) in a Node.js environment configured for CommonJS.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Replace `require()` calls with `import` statements where appropriate, or ensure you are in a CommonJS context if `require()` is necessary.","cause":"Attempting to use `require()` within an ESM module context (e.g., a file with `import`s or a `.mjs` file).","error":"ReferenceError: require is not defined"},{"fix":"Review the specific SWC error message for details. Check your TypeScript code for syntax errors. Ensure `@swc/core` is up-to-date and compatible with your Node.js version.","cause":"An error occurred during the SWC transformation process, often due to invalid TypeScript syntax, unsupported language features, or configuration issues.","error":"SWC compilation error: [specific SWC error message]"}],"ecosystem":"npm"}