Scribunto Bundler

0.2.7 · active · verified Tue Apr 21

scribunto-bundler is a TypeScript-written Lua bundler specifically designed for MediaWiki's Scribunto extension. It automates the process of resolving `require` statements within Lua modules, consolidating them into a single output file suitable for deployment on MediaWiki wikis. The current stable version is 0.2.7, with the project demonstrating a rapid release cadence, frequently publishing patch and minor versions, suggesting active development and iterative improvements. Key differentiators include its explicit support for Scribunto environments, automatic `require` statement detection, and compatibility with both `.lua` and `.luau` file extensions. It offers a command-line interface for scaffolding new projects and bundling existing ones, configurable via a `bundler.config.js` file, which is type-hinted for improved developer experience.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to set up, configure, and perform a programmatic bundle of a basic Scribunto Lua project. It outlines both CLI setup and direct API usage for advanced scenarios.

import { bundle } from 'scribunto-bundler';
import fs from 'node:fs/promises';

// 1. Install globally for CLI, then locally for project-specific use
// npm install -g scribunto-bundler
// npx scribunto-bundler --create // Creates project and installs locally

// 2. Configure bundler.config.js (example)
/*
// bundler.config.js
/** @type {import("scribunto-bundler").Config} */
/*
export default {
  prefix: '-- Bundled by scribunto-bundler\n', // Optional prefix text
  suffix: '\n-- End of bundle', // Optional suffix text
  main: 'src/main.lua', // Path to your main Lua module
  out: 'dist/bundled.lua', // Output path for the bundled file
};
*/

// 3. Example of a programmatic bundle (alternative to `npm run bundle`)
async function runBundleProgrammatically() {
  // In a real scenario, you'd read from bundler.config.js
  const config = {
    prefix: '-- My Awesome Scribunto Module\n', // Example prefix
    suffix: '\n-- Generated: ' + new Date().toISOString(), // Example suffix
    main: 'src/main.lua', // Your main Lua file
    out: 'dist/bundled-programmatic.lua', // Output file
  };

  // Ensure source files exist for demonstration
  await fs.mkdir('src', { recursive: true });
  await fs.writeFile('src/main.lua', 'local myutil = require(\'myutil\'); return myutil.add(1, 2)');
  await fs.writeFile('src/myutil.lua', 'local M = {}; function M.add(a, b) return a + b end; return M;');

  try {
    await bundle(config);
    console.log(`Successfully bundled to ${config.out}`);
    const bundledCode = await fs.readFile(config.out, 'utf-8');
    console.log('Bundled Code:\n', bundledCode);
  } catch (error) {
    console.error('Bundling failed:', error);
  }
}

runBundleProgrammatically();

view raw JSON →