|
|
||
|---|---|---|
| src | ||
| tests | ||
| .gitignore | ||
| README.md | ||
| package-lock.json | ||
| package.json | ||
| tsconfig.json | ||
| tsup.config.ts | ||
| vitest.config.ts | ||
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
.yarnprojectfiles against the official JSON schema - ✅ Load and compile
.yarndialogue 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.program); // Merged IRProgram from all .yarn files
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.yarnprojectfileoptions.baseDir: Base directory for resolving glob patterns (default: directory of.yarnprojectfile)
Returns: Promise<LoadResult>
interface LoadResult {
project: YarnProject;
baseDir: string;
program: IRProgram;
}
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