From 5ad3c897e7409f0f827e80f08091c9d7603e1d57 Mon Sep 17 00:00:00 2001 From: feisun Date: Thu, 3 Aug 2023 19:31:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(jsx2mp-loader):=20script-loader?= =?UTF-8?q?=E5=85=BC=E5=AE=B9pk=20g.json=20=E4=B8=AD=E4=B8=8D=E5=B8=A6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=E7=9A=84main=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/jsx2mp-loader/src/script-loader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jsx2mp-loader/src/script-loader.js b/packages/jsx2mp-loader/src/script-loader.js index 3fde2066..a8c3d50e 100644 --- a/packages/jsx2mp-loader/src/script-loader.js +++ b/packages/jsx2mp-loader/src/script-loader.js @@ -167,7 +167,7 @@ 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 || ''); + const npmMainPath = require.resolve(join(sourcePackagePath, pkg.main || '')); // change pkg.main short path to absolute path like `lib/index` to /xxx.../lib/index.js const isUsingMainMiniappComponent = pkg.hasOwnProperty(MINIAPP_CONFIG_FIELD) && this.resourcePath === npmMainPath; // Is miniapp compatible component. From 3437b8173462e351b7b10529badfebc97ae520ca Mon Sep 17 00:00:00 2001 From: feisun Date: Thu, 3 Aug 2023 19:59:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(jsx2mp-loader):=20=E6=97=A0=E6=B3=95res?= =?UTF-8?q?olve=E7=9A=84main=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=81=9A=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/jsx2mp-loader/src/script-loader.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/jsx2mp-loader/src/script-loader.js b/packages/jsx2mp-loader/src/script-loader.js index a8c3d50e..e3780383 100644 --- a/packages/jsx2mp-loader/src/script-loader.js +++ b/packages/jsx2mp-loader/src/script-loader.js @@ -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 = require.resolve(join(sourcePackagePath, pkg.main || '')); // change pkg.main short path to absolute path like `lib/index` to /xxx.../lib/index.js - + 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) {