rslib icon indicating copy to clipboard operation
rslib copied to clipboard

[Bug]: Adding js extensions for index resolution

Open Timeless0911 opened this issue 1 year ago • 1 comments

Details

input

// folder/index.ts
export const folder = 'folder';
// index.ts
import { folder } from './folder';

export const text = folder;

Output

import * as __WEBPACK_EXTERNAL_MODULE__folder_js__ from "./folder.js";
const src_text = __WEBPACK_EXTERNAL_MODULE__folder_js__.folder;
export { src_text as text };

https://github.com/web-infra-dev/rslib/blob/600937cebd061459a43d4f3e81bf09c96aee0375/packages/core/src/config.ts#L693-L721

In line 710, we directly add a jsExtension in bundless mode to make bundleless esm outputs work.

https://github.com/web-infra-dev/rslib/blob/600937cebd061459a43d4f3e81bf09c96aee0375/packages/core/src/config.ts#L710

  • Modern.js Module forces user to add /index in bundleless mode.
  • Tsup do not add js extensions automatically, it forces user to write extensions in sourcecode

Index resolution is a standard behaviour which takes effects in both nodejs and ts, and Rslib now use default resolve.mainFiles: ['index'] of Rspack.

We should handle when ./folder/index.ts and ./folder.ts exists at the same time, there may also be .ts, .tsx, .jsx existing.

Timeless0911 avatar Sep 26 '24 09:09 Timeless0911

Feeling like we really need getResolve param in function external type.

fi3ework avatar Sep 26 '24 10:09 fi3ework