or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-angular-devkit--build-ng-packagr

Angular Build Architect builder for ng-packagr library packaging (deprecated)

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@angular-devkit/build-ng-packagr@0.1002.x

To install, run

npx @tessl/cli install tessl/npm-angular-devkit--build-ng-packagr@0.1002.0

index.mddocs/

@angular-devkit/build-ng-packagr

The @angular-devkit/build-ng-packagr package provides an Angular Build Architect builder for ng-packagr, enabling the compilation and packaging of Angular libraries within the Angular CLI's build system. This package serves as a wrapper around the ng-packagr tool, integrating it seamlessly into Angular workspaces.

⚠️ Deprecation Notice: This package has been deprecated since Angular CLI 10.1. Use the ng-packagr builder from @angular-devkit/build-angular instead.

Package Information

  • Package Name: @angular-devkit/build-ng-packagr
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @angular-devkit/build-ng-packagr
  • Status: Deprecated (use @angular-devkit/build-angular instead)

Core Imports

import { execute, NgPackagrBuilderOptions } from "@angular-devkit/build-ng-packagr";

For the default builder (typically not imported directly):

import builder from "@angular-devkit/build-ng-packagr";

For CommonJS:

const { execute, NgPackagrBuilderOptions } = require("@angular-devkit/build-ng-packagr");

Basic Usage

The package is primarily used as an Angular CLI builder through the angular.json configuration:

{
  "projects": {
    "my-lib": {
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-ng-packagr:build",
          "options": {
            "project": "projects/my-lib/ng-package.json"
          }
        }
      }
    }
  }
}

Programmatic usage:

import { execute, NgPackagrBuilderOptions } from "@angular-devkit/build-ng-packagr";
import { BuilderContext } from "@angular-devkit/architect";

const options: NgPackagrBuilderOptions = {
  project: "ng-package.json",
  tsConfig: "tsconfig.lib.json",
  watch: false
};

// Execute the builder (requires proper BuilderContext)
const result = execute(options, context);
result.subscribe(buildResult => {
  if (buildResult.success) {
    console.log("Build completed successfully");
  }
});

Architecture

The package is built around the Angular Architect system and consists of:

  • Builder Integration: Implements the Angular Architect builder pattern for seamless CLI integration
  • ng-packagr Wrapper: Provides a clean interface to the ng-packagr library for Angular library building
  • Configuration Schema: JSON schema-based validation for build options
  • Observable-based Execution: Uses RxJS observables for build process handling

Capabilities

Builder Execution

Main entry point for executing the ng-packagr build process within the Angular Architect system.

/**
 * Execute the ng-packagr builder with the provided options
 * @deprecated Since 10.1 use executeNgPackagrBuilder from @angular-devkit/build-angular instead
 * @param options - Builder configuration options
 * @param context - Angular Architect build context
 * @returns Observable that emits build result
 */
export function execute(
  options: NgPackagrBuilderOptions,
  context: BuilderContext
): Observable<BuilderOutput>;

Usage Example:

import { execute } from "@angular-devkit/build-ng-packagr";
import { BuilderContext, BuilderOutput } from "@angular-devkit/architect";

// This would typically be called by the Angular CLI
const buildResult: Observable<BuilderOutput> = execute(
  {
    project: "ng-package.json",
    tsConfig: "tsconfig.lib.json",
    watch: false
  },
  context
);

buildResult.subscribe(result => {
  console.log(`Build ${result.success ? 'succeeded' : 'failed'}`);
});

Configuration Options

Interface defining the configuration options for the ng-packagr builder.

/**
 * Configuration options for the ng-packagr builder
 * @deprecated Since 10.1 use NgPackagrBuilderOptions from @angular-devkit/build-angular instead
 */
interface NgPackagrBuilderOptions {
  /** 
   * Path to the ng-packagr configuration file, relative to workspace root
   * This file (typically ng-package.json) contains the ng-packagr build configuration
   */
  project: string;
  
  /** 
   * Path to the TypeScript configuration file, relative to workspace root
   * Optional override for the TypeScript compiler configuration
   */
  tsConfig?: string;
  
  /** 
   * Enable watch mode for development
   * When true, the builder will watch for file changes and rebuild automatically
   * @default false
   */
  watch?: boolean;
}

Builder Registration

The package exports a pre-configured builder that integrates with the Angular CLI.

/**
 * Pre-configured Angular Architect builder for ng-packagr
 * This is the default export created using createBuilder(execute) and used by the Angular CLI
 * when the builder is specified in builders.json/angular.json
 */
export default createBuilder<Record<string, string> & NgPackagrBuilderOptions>(execute);

Types

Core Interfaces

/**
 * Type alias for Schema interface (generated from JSON schema)
 * @deprecated Since 10.1 use types from @angular-devkit/build-angular instead
 */
export type NgPackagrBuilderOptions = Schema;

/**
 * Generated interface from src/build/schema.json  
 * Contains the configuration options for the ng-packagr builder
 */
interface Schema {
  /** The file path for the ng-packagr configuration file, relative to the current workspace */
  project: string;
  /** The full path for the TypeScript configuration file, relative to the current workspace */
  tsConfig?: string; 
  /** Run build when files change */
  watch?: boolean;
}

External Dependencies

This package relies on external types from Angular DevKit and RxJS:

// From @angular-devkit/architect
interface BuilderContext {
  workspaceRoot: string;
  // Additional properties from Angular Architect
}

interface BuilderOutput {
  success: boolean;
  error?: string;
}

// From rxjs
interface Observable<T> {
  subscribe(observer: (value: T) => void): Subscription;
  // Additional Observable methods
}

Error Handling

The builder handles errors through the BuilderOutput interface. Common error scenarios include:

  • Missing ng-packagr dependency: The builder requires ng-packagr as a peer dependency
  • Invalid configuration: Schema validation ensures configuration options are valid
  • Build failures: ng-packagr build errors are propagated through the Observable

Migration Path

Since this package is deprecated, migrate to the replacement:

// Old (deprecated)
import { execute, NgPackagrBuilderOptions } from "@angular-devkit/build-ng-packagr";

// New (recommended)
import { executeNgPackagrBuilder, NgPackagrBuilderOptions } from "@angular-devkit/build-angular";

Update angular.json:

{
  "builder": "@angular-devkit/build-angular:ng-packagr"
}