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

Fix/pkg main short path compat #320

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/jsx2mp-loader/src/script-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ module.exports = function scriptLoader(content) {

const pkg = readJSONSync(sourcePackageJSONPath);
const npmName = pkg.name; // Update to real npm name, for that tnpm will create like `_rax-view@1.0.2@rax-view` folders.
const npmMainPath = join(sourcePackagePath, pkg.main || '');

let npmMainPath = join(sourcePackagePath, pkg.main || '');
try {
// compat pkg.main without suffix like `lib/index`
npmMainPath = require.resolve(npmMainPath);
} catch (e) {
// can't resolve npmMainPath
}
const isUsingMainMiniappComponent = pkg.hasOwnProperty(MINIAPP_CONFIG_FIELD) && this.resourcePath === npmMainPath;
// Is miniapp compatible component.
if (isUsingMainMiniappComponent || isRelativeMiniappComponent || isThirdMiniappComponent) {
Expand Down