yarn spinner loader for bundlers
Go to file
hypercross dd43bb1a1d feat: impl 2026-04-14 15:24:54 +08:00
src feat: impl 2026-04-14 15:24:54 +08:00
tests feat: impl 2026-04-14 15:24:54 +08:00
.gitignore feat: impl 2026-04-14 15:24:54 +08:00
README.md feat: impl 2026-04-14 15:24:54 +08:00
package-lock.json feat: impl 2026-04-14 15:24:54 +08:00
package.json feat: impl 2026-04-14 15:24:54 +08:00
tsconfig.json feat: impl 2026-04-14 15:24:54 +08:00
tsup.config.ts feat: impl 2026-04-14 15:24:54 +08:00
vitest.config.ts feat: impl 2026-04-14 15:24:54 +08:00

README.md

Yarn Spinner Loader

Load and compile Yarn Spinner project files (.yarnproject) for various build tools (esbuild, rollup, webpack, vite).

Features

  • Parse and validate .yarnproject files against the official JSON schema
  • Load and compile .yarn dialogue files using glob patterns
  • Support for multiple build tools (esbuild, rollup, webpack, vite)
  • TypeScript support with full type definitions
  • Comprehensive test coverage with real fixtures

Installation

npm install yarn-spinner-loader

Usage

Core API

import { loadYarnProject } from 'yarn-spinner-loader';

const result = await loadYarnProject('path/to/project.yarnproject');

console.log(result.project.projectName);
console.log(result.yarnFiles); // Array of parsed Yarn documents

With esbuild

import { build } from 'esbuild';
import { yarnSpinnerPlugin } from 'yarn-spinner-loader/esbuild';

build({
  entryPoints: ['src/index.ts'],
  plugins: [yarnSpinnerPlugin()],
  bundle: true,
  outfile: 'dist/bundle.js',
});

With Vite

// vite.config.ts
import { defineConfig } from 'vite';
import { yarnSpinnerVite } from 'yarn-spinner-loader/vite';

export default defineConfig({
  plugins: [yarnSpinnerVite()],
});

With Rollup

// rollup.config.js
import { yarnSpinnerRollup } from 'yarn-spinner-loader/rollup';

export default {
  input: 'src/main.js',
  plugins: [yarnSpinnerRollup()],
  output: {
    file: 'dist/bundle.js',
    format: 'es',
  },
};

With Webpack

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /\.yarnproject$/,
        use: 'yarn-spinner-loader/webpack',
      },
    ],
  },
};

API Reference

loadYarnProject(path, options?)

Load and compile a .yarnproject file and all its referenced .yarn files.

Parameters:

  • path: Path to the .yarnproject file
  • options.baseDir: Base directory for resolving glob patterns (default: directory of .yarnproject file)

Returns: Promise<LoadResult>

interface LoadResult {
  project: YarnProject;
  baseDir: string;
  yarnFiles: Array<{
    relativePath: string;
    absolutePath: string;
    document: YarnDocument;
  }>;
}

loadYarnProjectSync(path, options?)

Synchronous version of loadYarnProject.

validateYarnProject(config)

Validate a parsed .yarnproject object against the JSON schema.

Returns:

{ valid: true; data: YarnProject } | { valid: false; errors: ValidationError[] }

Project Structure

yarn-spinner-loader/
├── src/
│   ├── loader/           # Core loader implementation
│   │   ├── index.ts      # YarnProjectLoader
│   │   ├── validator.ts  # JSON Schema validation
│   │   └── types.ts      # TypeScript types
│   ├── plugins/          # Build tool plugins
│   │   ├── esbuild.ts
│   │   ├── rollup.ts
│   │   ├── vite.ts
│   │   └── webpack.ts
│   ├── yarn-spinner/     # Yarn Spinner parser (existing)
│   └── index.ts          # Main entry point
├── tests/
│   ├── fixtures/         # Test fixtures
│   │   ├── simple/
│   │   ├── localised/
│   │   └── complex/
│   ├── validator.test.ts
│   └── loader.test.ts
└── package.json

Testing

Run tests with vitest:

npm test          # Watch mode
npm run test:run  # Run once

License

MIT