refactor: split node entry

This commit is contained in:
hypercross 2026-04-14 16:42:10 +08:00
parent 93078f2dd6
commit eaff2ef5da
6 changed files with 139 additions and 24 deletions

View File

@ -12,6 +12,11 @@
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.js",
"require": "./dist/node.cjs"
},
"./esbuild": {
"types": "./dist/plugins/esbuild.d.ts",
"import": "./dist/plugins/esbuild.js",

25
src/core.ts Normal file
View File

@ -0,0 +1,25 @@
/**
* Yarn Spinner Loader - Core API
*
* Pure functions and types for working with Yarn Spinner.
* This module does NOT depend on Node.js modules.
*/
// Re-export yarn-spinner parser
export { parseYarn } from './yarn-spinner/parse/parser';
export { compile } from './yarn-spinner/compile/compiler';
export { YarnRunner } from './yarn-spinner/runtime/runner';
// Re-export types
export type {
LoadOptions,
LoadResult,
LoadedYarnFile,
YarnProject,
SchemaValidationError,
RunnerOptions,
TextResult,
OptionsResult,
CommandResult,
RuntimeResult,
} from './types';

View File

@ -1,31 +1,26 @@
/**
* Yarn Spinner Loader - Main Entry Point
*
* Load and compile Yarn Spinner project files (.yarnproject)
* and their associated .yarn dialogue files.
*
* Pure API for working with Yarn Spinner documents.
* This module does NOT depend on Node.js modules.
* For filesystem operations, use the 'yarn-spinner-loader/node' entry point.
*/
export {
loadYarnProject,
loadYarnProjectSync,
type LoadOptions,
type LoadResult,
type LoadedYarnFile,
LoadError,
ValidationError as LoaderValidationError,
} from './loader/index';
export {
validateYarnProject,
isYarnProject,
type SchemaValidationError,
} from './loader/validator';
export type { YarnProject } from './loader/types';
// Re-export yarn-spinner parser
// Re-export yarn-spinner parser and runtime
export { parseYarn } from './yarn-spinner/parse/parser';
export { compile } from './yarn-spinner/compile/compiler';
export { YarnRunner } from './yarn-spinner/runtime/runner';
export type { RunnerOptions } from './yarn-spinner/runtime/runner';
export type { TextResult, OptionsResult, CommandResult, RuntimeResult } from './yarn-spinner/runtime/results';
// Re-export types
export type {
LoadOptions,
LoadResult,
LoadedYarnFile,
YarnProject,
SchemaValidationError,
RunnerOptions,
TextResult,
OptionsResult,
CommandResult,
RuntimeResult,
} from './types';

24
src/node.ts Normal file
View File

@ -0,0 +1,24 @@
/**
* Yarn Spinner Loader - Node.js API
*
* Functions that depend on Node.js modules (fs, path, fast-glob).
* Use this entry point when you need to load .yarnproject files from the filesystem.
*/
export {
loadYarnProject,
loadYarnProjectSync,
type LoadOptions,
type LoadResult,
type LoadedYarnFile,
LoadError,
ValidationError as LoaderValidationError,
} from './loader/index';
export {
validateYarnProject,
isYarnProject,
type SchemaValidationError,
} from './loader/validator';
export type { YarnProject } from './loader/types';

59
src/types.ts Normal file
View File

@ -0,0 +1,59 @@
/**
* Yarn Spinner Loader - Type Definitions
*
* Pure type definitions that don't depend on Node.js modules.
*/
import type { YarnProject } from './loader/types';
import type { SchemaValidationError } from './loader/validator';
import type { YarnDocument } from './yarn-spinner/model/ast';
import type { RunnerOptions } from './yarn-spinner/runtime/runner';
import type {
TextResult,
OptionsResult,
CommandResult,
RuntimeResult,
} from './yarn-spinner/runtime/results';
export type {
YarnProject,
SchemaValidationError,
YarnDocument,
RunnerOptions,
TextResult,
OptionsResult,
CommandResult,
RuntimeResult,
};
/**
* Options for loading a Yarn project
*/
export interface LoadOptions {
/** Base directory for resolving glob patterns (default: directory of .yarnproject file) */
baseDir?: string;
}
/**
* Loaded Yarn document with metadata
*/
export interface LoadedYarnFile {
/** File path relative to base directory */
relativePath: string;
/** Absolute file path */
absolutePath: string;
/** Parsed Yarn document */
document: YarnDocument;
}
/**
* Result of loading a Yarn project
*/
export interface LoadResult {
/** Parsed .yarnproject configuration */
project: YarnProject;
/** Directory containing the .yarnproject file */
baseDir: string;
/** All loaded and parsed .yarn files */
yarnFiles: LoadedYarnFile[];
}

View File

@ -9,6 +9,13 @@ export default defineConfig([
clean: true,
outDir: 'dist',
},
{
entry: ['src/node.ts'],
format: ['esm', 'cjs'],
dts: true,
sourcemap: true,
outDir: 'dist',
},
{
entry: ['src/plugins/esbuild.ts'],
format: ['esm', 'cjs'],