or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

cli.mdenvironment.mdfilesystem.mdgenerator-discovery.mdgenerator-management.mdindex.mdmodule-lookup.md
tile.json

tessl/npm-yeoman-environment

Handles the lifecycle and bootstrapping of generators in a specific environment

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/yeoman-environment@4.4.x

To install, run

npx @tessl/cli install tessl/npm-yeoman-environment@4.4.0

index.mddocs/

Yeoman Environment

Yeoman Environment is a TypeScript library that handles the lifecycle and bootstrapping of generators in a specific environment. It provides a high-level API to discover, create, and run generators with advanced configuration options for resolver behavior and runtime environment management. The package serves as the core infrastructure for Yeoman's scaffolding system, providing the runtime environment that coordinates between generators and the user's development workspace.

Package Information

  • Package Name: yeoman-environment
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install yeoman-environment

Core Imports

import Environment, { 
  createEnv, 
  EnvironmentBase,
  YeomanCommand,
  lookupGenerator,
  addEnvironmentOptions,
  prepareCommand,
  prepareGeneratorCommand,
  commitSharedFsTask,
  packageManagerInstallTask,
  removePropertiesWithNullishValues,
  moduleLookupSync,
  findPackagesIn,
  getNpmPaths,
  defaultExtensions,
  UNKNOWN_NAMESPACE,
  UNKNOWN_RESOLVED,
  defaultQueues
} from "yeoman-environment";

For CommonJS:

const Environment = require("yeoman-environment").default;
const { 
  createEnv, 
  EnvironmentBase,
  YeomanCommand,
  lookupGenerator,
  addEnvironmentOptions,
  prepareCommand,
  prepareGeneratorCommand,
  commitSharedFsTask,
  packageManagerInstallTask,
  removePropertiesWithNullishValues,
  moduleLookupSync,
  findPackagesIn,
  getNpmPaths,
  defaultExtensions,
  UNKNOWN_NAMESPACE,
  UNKNOWN_RESOLVED,
  defaultQueues
} = require("yeoman-environment");

Basic Usage

import { createEnv } from "yeoman-environment";

// Create environment instance
const env = createEnv();

// Search for installed generators
await env.lookup();

// Run a generator
await env.run("angular", { skipInstall: true });

// Execute a specific generator with arguments
await env.execute("app:component", ["UserCard", "--style=css"]);

Architecture

Yeoman Environment is built around several key components:

  • Environment Classes: Core environment management (Environment, EnvironmentBase)
  • Generator Registry: Storage and metadata system for discovered generators
  • Lookup System: Discovery mechanisms for finding installed generators
  • Command Integration: CLI support via Commander.js extensions
  • File System Management: Memory filesystem integration for generator operations
  • Package Manager Integration: Automatic dependency installation handling
  • Conflict Resolution: File conflict handling and resolution strategies

Capabilities

Environment Management

Core environment functionality for managing generator lifecycles, registration, and execution.

function createEnv(options?: EnvironmentOptions): Environment;

class Environment extends EnvironmentBase {
  constructor(options?: EnvironmentOptions);
  help(name?: string): string;
  execute(generatorNamespace: string, args?: string[]): Promise<void>;
  requireGenerator(namespace: string): Promise<BaseGeneratorConstructor | undefined>;
  installLocalGenerators(packages: Record<string, string | undefined>): Promise<boolean>;
  lookupLocalPackages(packagesToLookup?: string[]): Promise<void>;
  run(args?: string[], options?: any): Promise<void>;
}

interface EnvironmentOptions extends BaseEnvironmentOptions {
  adapter?: InputOutputAdapter;
  logCwd?: string;
  command?: YeomanCommand;
  yeomanRepository?: string;
  arboristRegistry?: string;
  nodePackageManager?: string;
}

Environment Management

Generator Discovery

Generator discovery and lookup system for finding installed generators across various locations.

function lookupGenerator(
  namespace: string,
  options?: ModuleLookupOptions & {
    packagePath?: boolean;
    generatorPath?: boolean;
  }
): string | string[];

interface LookupOptions extends LookupOptionsApi {
  lookups?: string[];
  localOnly?: boolean;
  packagePaths?: string | string[];
  npmPaths?: string | string[];
  filePatterns?: string | string[];
  packagePatterns?: string | string[];
  singleResult?: boolean;
}

Generator Discovery

Generator Management

Registration, instantiation, and execution of generators with metadata management.

interface BaseEnvironment {
  register(pathOrStub: unknown, meta?: Partial<BaseGeneratorMeta>): GeneratorMeta;
  get<C>(namespaceOrPath: string | YeomanNamespace): Promise<C | undefined>;
  create<G>(namespaceOrPath: string | GetGeneratorConstructor<G>, ...args: any[]): Promise<G>;
  instantiate<G>(generator: GetGeneratorConstructor<G>, ...args: any[]): Promise<G>;
  composeWith<G>(generator: string | GetGeneratorConstructor<G>, ...args: any[]): Promise<G>;
  runGenerator(generator: BaseGenerator): Promise<void>;
  queueGenerator<G>(generator: G, queueOptions?: { schedule?: boolean }): Promise<G>;
}

Generator Management

Command Line Interface

CLI command creation and management with Commander.js integration for generator commands.

class YeomanCommand extends Command {
  env?: BaseEnvironment;
  createCommand(name?: string): YeomanCommand;
  addOption(option: Option): YeomanCommand;
  registerGenerator(generator: any): YeomanCommand;
  addGeneratorArguments(generatorArgs: any[]): YeomanCommand;
  addGeneratorOptions(options: Record<string, any>): YeomanCommand;
}

function addEnvironmentOptions(command?: YeomanCommand): YeomanCommand;
function prepareCommand(options: CommandPreparation): Promise<YeomanCommand>;
function prepareGeneratorCommand(options: CommandPreparation): Promise<YeomanCommand>;

interface CommandPreparation {
  resolved?: string;
  command?: YeomanCommand;
  generator?: BaseGeneratorConstructor;
  namespace?: string;
}

Command Line Interface

File System Operations

Memory filesystem operations, conflict resolution, and file transforms for generator output.

function commitSharedFsTask(options: {
  adapter: InputOutputAdapter;
  conflicterOptions?: ConflicterOptions;
  sharedFs: Store<MemFsEditorFile>;
}): Promise<void>;

function packageManagerInstallTask(options: PackageManagerInstallTaskOptions): Promise<boolean>;

interface PackageManagerInstallTaskOptions {
  memFs: Store<MemFsEditorFile>;
  packageJsonLocation: string;
  adapter: InputOutputAdapter;
  nodePackageManager?: string;
  customInstallTask?: boolean | ((nodePackageManager: string | undefined, defaultTask: () => Promise<boolean>) => void | Promise<void>);
  skipInstall?: boolean;
}

File System Operations

Utility Functions

Utility functions for data manipulation and environment operations.

function removePropertiesWithNullishValues(object: Record<string, any>): Record<string, any>;

Module Discovery

Module and package discovery utilities for finding generators in npm packages.

function moduleLookupSync(patterns: string | string[], options?: {
  packageJson?: boolean;
  singleResult?: boolean;
  lookups?: string[];
  npmPaths?: string | string[];
}): string | string[];

function findPackagesIn(
  patterns: string | string[],
  searchPaths: string[]
): string[];

function getNpmPaths(paths?: string | string[]): string[];

Module Discovery

Constants

Predefined constants used throughout the environment system.

const defaultExtensions: string[];
const UNKNOWN_NAMESPACE: string;
const UNKNOWN_RESOLVED: string;
const defaultQueues: string[];

Common Types

interface BaseGeneratorMeta {
  namespace: string;
  resolved?: string;
  packagePath?: string;
}

interface GeneratorMeta extends BaseGeneratorMeta {
  instantiate(...args: any[]): Promise<BaseGenerator>;
  instantiateHelp(): Promise<BaseGenerator>;
}

interface EnvironmentLookupOptions extends LookupOptions {
  registerToScope?: string;
  customizeNamespace?: (ns?: string) => string | undefined;
}

type YeomanNamespace = {
  packageNamespace: string;
  generator?: string;
  scope?: string;
  instanceId?: string;
};

interface BaseEnvironmentOptions {
  cwd?: string;
  skipInstall?: boolean;
  forceInstall?: boolean;
  skipCache?: boolean;
  skipLocalCache?: boolean;
  skipParseOptions?: boolean;
  localConfigOnly?: boolean;
  askAnswered?: boolean;
}

interface LookupOptionsApi {
  lookups?: string[];
  localOnly?: boolean;
  packagePaths?: string | string[];
  npmPaths?: string | string[];
  filePatterns?: string | string[];
  packagePatterns?: string | string[];
  singleResult?: boolean;
}

interface InputOutputAdapter {
  log: {
    write(message?: string): void;
    writeln(message?: string): void;
    ok(message?: string): void;
    error(message?: string): void;
    info(message?: string): void;
    warning(message?: string): void;
  };
  prompt: (questions: any) => Promise<any>;
}

interface BaseGeneratorConstructor {
  new (...args: any[]): BaseGenerator;
}

interface BaseGenerator {
  arguments: string[];
  options: Record<string, any>;
  run(): Promise<void>;
}

interface Store<T> {
  add(file: T): void;
  get(path: string): T | undefined;
  each(callback: (file: T, path: string) => void): void;
}

interface ConflicterOptions {
  force?: boolean;
  bail?: boolean;
  ignoreWhitespace?: boolean;
  regenerateFiles?: boolean;
}