web-infra-dev / rslib

Create JavaScript libraries in a simple and intuitive way.
https://lib.rsbuild.dev/
MIT License
392 stars 20 forks source link

[Bug]: extension of js request is not correct when using `autoExtension: false` along with `output.filename.js` #362

Open xc2 opened 2 days ago

xc2 commented 2 days ago

Version


  System:
    OS: macOS 15.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 79.05 MB / 32.00 GB
    Shell: 3.7.1 - /opt/homebrew/bin/fish
  Browsers:
    Chrome: 130.0.6723.92
    Safari: 18.1
  npmPackages:
    @rslib/core: ^0.0.15 => 0.0.15

Details

Cannot even set output.filename.js when autoExtension is false

Setup

package.json of workspace

{ "type": "module" }

rslib.config.ts

// ...
  format: 'esm',
  autoExtension: false,
  output: {
    filename: {
      js: '[name].mjs'
    }
  }
// ...
  format: 'cjs',
  autoExtension: false,
  output: {
    filename: {
      js: '[name].cjs'
    }
  }
// ...

Exepected

But got

Reproduce link

https://github.com/xc2/jbpr/blob/auto-extension-repro/sources/BUILD.ts

Reproduce Steps

ESM:

run pnpm rslib build -- //sources:esm and look into dist/lib

CJS:

run pnpm rslib build -- //sources:cjs and look into dist/lib

fi3ework commented 2 days ago

Supposed to be a bug here https://github.com/web-infra-dev/rslib/blob/2e8b298c4bad888f3e923a1e17b5558944017dc5/packages/core/src/config.ts#L890. User's explicit relative import extension is in conflict with the real file extension.

xc2 commented 2 days ago

If the template filename is too complicated to determine the js extension, I’d prefer an option like jsExtension: string | "auto"

Timeless0911 commented 1 day ago

We can add a redirect.extension configuration to handle this scene which is in our plan.