Skip to content

API mismatch between CopyRspackPlugin transform and CopyWebpackPlugin transform #8957

@patricksevat

Description

@patricksevat

Hi all,

First, thanks for creating Rspack!

I'm trying to from Webpack to Rspack and encountered an issue with CopyRspackPlugin's compatibility with CopyWebpackPlugin.

The gist is that in CopyWebpackPlugin, pattern.transform accepts an object whereas CopyRspackPlugin does not (Note: this has been introduced in CopyWebpackPlugin@7)

// CopyWebpackPlugin
type transform =
  | {
      transformer: (input: string, absoluteFilename: string) => string | Buffer;
      cache?: boolean | TransformerCacheObject | undefined;
    }
  | ((input: string, absoluteFilename: string) => string | Buffer);

vs

// CopyRspackPlugin
type Transform = (
  input: Buffer,
  absoluteFilename: string,
) => string | Buffer | Promise<string> | Promise<Buffer>;

This lead to a cryptic error:

 #  rspack-node[77491]: napi_status napi_release_threadsafe_function(napi_threadsafe_function, napi_threadsafe_function_release_mode) at ../src/node_api.cc:1398
  #  Assertion failed: (func) != nullptr

I see two possible solutions:

  1. Accept the API difference, and update the migration docs from Webpack to Rspack relating CopyWebpackPlugin
    a. possibly extended with some configuration validation which would throw a more informative error
  2. Update CopyRspackPlugin to align the APIs

Minimal reproduction example: rstackjs/rstack-examples@main...patricksevat:rspack-examples:feat/copy-webpack-plugin-transform-obj-config

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions