Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Adding js extensions for index resolution #238

Open
Timeless0911 opened this issue Sep 26, 2024 · 1 comment
Open

[Bug]: Adding js extensions for index resolution #238

Timeless0911 opened this issue Sep 26, 2024 · 1 comment
Labels
🐞 bug Something isn't working

Comments

@Timeless0911
Copy link
Collaborator

Timeless0911 commented Sep 26, 2024

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 };

if (data.contextInfo.issuer) {
// Node.js ECMAScript module loader does no extension searching.
// Add a file extension according to autoExtension config
// when data.request is a relative path and do not have an extension.
// If data.request already have an extension, we replace it with new extension
// This may result in a change in semantics,
// user should use copy to keep origin file or use another separate entry to deal this
let request = data.request;
if (request[0] === '.') {
if (extname(request)) {
if (JS_EXTENSIONS_PATTERN.test(request)) {
request = request.replace(/\.[^.]+$/, jsExtension);
} else {
// If it does not match jsExtensionsPattern, we should do nothing, eg: ./foo.png
return callback();
}
} else {
request = `${request}${jsExtension}`;
}
}
return callback(null, request);
}
callback();
},
],
},
};
};

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

request = `${request}${jsExtension}`;

  • 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 Timeless0911 added the 🐞 bug Something isn't working label Sep 26, 2024
@fi3ework
Copy link
Member

fi3ework commented Sep 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants