From 2f4e82fd4e7035de591e0355be52075b12556f90 Mon Sep 17 00:00:00 2001 From: zhaozhuobin Date: Thu, 16 Mar 2023 19:57:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=95=E8=8E=B7modules=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E6=97=B6import=E5=A4=B1=E8=B4=A5=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/env/index.ts | 12 ++++++++++-- src/utils/typedImport.ts | 8 ++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 66f3568..32d6e4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lisa-plugin/zephyr", - "version": "1.7.1-beta.5", + "version": "1.7.1-beta.6", "description": "LISA plugin for Zephyr", "main": "./lib/main.js", "engines": { diff --git a/src/env/index.ts b/src/env/index.ts index 09805d2..3b53096 100644 --- a/src/env/index.ts +++ b/src/env/index.ts @@ -74,11 +74,19 @@ export async function loadBinaries(bundles?: Bundle[]): Promise = {}; for (const name of BUILTIN_BINARIES) { const unprefixedName = name.split('/').slice(1).join('/'); - binaries[unprefixedName] = await typedImport(name); + try { + binaries[unprefixedName] = await typedImport(name); + } catch (error) { + binaries[unprefixedName] = {} + } } for (const bundle of bundles || []) { for (const name of bundle.binaries || []) { - binaries[name] = await typedImport(`${PACKAGE_MODULES_DIR}/@binary/${name}`); + try { + binaries[name] = await typedImport(`${PACKAGE_MODULES_DIR}/@binary/${name}`); + } catch (error) { + binaries[name] = {}; + } } } return binaries; diff --git a/src/utils/typedImport.ts b/src/utils/typedImport.ts index 4e11c64..ee0a751 100644 --- a/src/utils/typedImport.ts +++ b/src/utils/typedImport.ts @@ -3,10 +3,6 @@ interface Module { } export default async function typedImport(name: string): Promise { - try { - const mod = await import(name) as Module; - return mod.default; - } catch (error) { - return {} - } + const mod = await import(name) as Module; + return mod.default; }