Skip to content

Conversation

@Timeless0911
Copy link
Contributor

@Timeless0911 Timeless0911 commented Dec 12, 2025

Highlights 💡

New JavaScript API

This release introduces a new, comprehensive JavaScript API for Rslib.

Caution

This is a Breaking Change. The previously exposed informal API has been removed. You can switch to the new JavaScript API and refer to the docs below to re-integrate.

See the API docs for details:

Usage

  1. Install Rslib: install the @rslib/core package:
npm add @rslib/core -D
  1. Create an Rslib instance: call the createRslib method to create an Rslib instance:
import { createRslib } from '@rslib/core';

const rslib = await createRslib();
  1. Call Rslib instance methods: use the rslib.build method which will build production outputs:
await rslib.build();

Summary

  • Provide a comprehensive JavaScript API

    Type:

     type RslibInstance = {
         build(options?: BuildOptions): Promise<BuildResult>;
         inspectConfig(options?: InspectConfigOptions): Promise<InspectConfigResult>;
         startMFDevServer(options?: StartMFDevServerOptions): Promise<StartServerResult>;
         getRslibConfig(): Readonly<RslibConfig>;
         onAfterCreateRsbuild(callback: OnAfterCreateRsbuildFn): void;
     };
     
     function createRslib(options?: CreateRslibOptions): Promise<RslibInstance>;

    Example:

     const rslib = await createRslib({
       config: {
         // Rslib configuration
       },
     });
    
     await rslib.build();
  • Refactor public API

    Core methods:

    • runCLI
    • createRslib
    • defineConfig
    • loadConfig
    • loadEnv
    • mergeRslibConfig
  • Verbose Rslib/Rsbuild/Rspack configurations when running with DEBUG=rslib

  • Add --no-env cli options to control disable loading of .env files after refactor

Related Links

close: #1040
close: #967

Checklist

  • PR Description
  • Tests updated (or not required).
  • JS Doc
  • Documentation updated (or not required).
  • Breaking changes and release notes

Copilot AI review requested due to automatic review settings December 12, 2025 08:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the CLI initialization and error handling to improve user experience. The main changes include renaming the public API from runCli to runCLI (following proper casing convention), consolidating CLI setup logic, and implementing smarter output formatting for different package managers. The refactor also adds a process title for easier identification and simplifies build error logging.

Key changes:

  • Renamed public API runCli to runCLI and consolidated CLI initialization logic into a new /cli/index.ts file
  • Removed the prepareCli function and integrated its functionality into the main CLI entry point
  • Enhanced package manager detection to handle output formatting for npx, Bun, and Node.js --run command
  • Introduced RSPACK_BUILD_ERROR constant to conditionally suppress redundant error messages
  • Renamed internal function initConfig to init for better clarity

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/src/index.ts Updated public API exports: renamed runCli to runCLI and removed prepareCli export
packages/core/src/cli/prepare.ts Deleted file - functionality moved to /cli/index.ts
packages/core/src/cli/init.ts Renamed function from initConfig to init
packages/core/src/cli/index.ts New file consolidating CLI initialization with improved package manager detection and greeting logic
packages/core/src/cli/commands.ts Added RSPACK_BUILD_ERROR constant and error filtering logic; renamed import from initConfig to init; updated import path
packages/core/bin/rslib.js Simplified entry point to call runCLI directly without try-catch wrapper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Timeless0911 Timeless0911 marked this pull request as draft December 12, 2025 09:20
@Timeless0911 Timeless0911 changed the title refactor!: enhance CLI behaviour and logs feat!: add JavaScript API and enhance CLI behaviour Dec 15, 2025
@netlify
Copy link

netlify bot commented Dec 17, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit df0a98f
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/694bea62872ece0008bbcafa
😎 Deploy Preview https://deploy-preview-1394--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Timeless0911 Timeless0911 force-pushed the js-api branch 7 times, most recently from 8320ba4 to e2d7a37 Compare December 24, 2025 08:53
@Timeless0911 Timeless0911 marked this pull request as ready for review December 24, 2025 08:53
@Timeless0911 Timeless0911 force-pushed the js-api branch 3 times, most recently from 59330fc to f61d16c Compare December 24, 2025 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: expose stats result for build command by js api [Feature]: stabilize public JS API

3 participants