From 0e96c1ef190a37dddf3382bf9da1b82b633b49ed Mon Sep 17 00:00:00 2001 From: lizhouze Date: Mon, 21 Mar 2022 17:18:28 +0800 Subject: [PATCH] lizhouze@huawei.com Signed-off-by: lizhouze --- src/script.js | 2 +- src/util.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index 59e0bf8..5147956 100644 --- a/src/script.js +++ b/src/script.js @@ -39,7 +39,7 @@ module.exports = function (source, map) { if (log && log.length) { logWarn(this, log) } - parsed = parseRequireModule(parsed) + parsed = parseRequireModule(parsed, this.resourcePath); if (process.env.DEVICE_LEVEL === DEVICE_LEVEL.RICH || process.env.DEVICE_LEVEL === 'card') { const appName = process.env.abilityType === 'page' ? 'app.js' : `${process.env.abilityType}.js` if (path.basename(this.resourcePath) !== appName) { diff --git a/src/util.js b/src/util.js index 2507673..87e7829 100644 --- a/src/util.js +++ b/src/util.js @@ -27,6 +27,7 @@ import { } from 'source-map' const { DEVICE_LEVEL } = require('./lite/lite-enum') +export const useOSFiles = new Set(); export function getNameByPath (resourcePath) { return path.basename(resourcePath).replace(/\..*$/, '') @@ -270,7 +271,7 @@ function requireModule(moduleName) { return target; } ` -export function parseRequireModule (source) { +export function parseRequireModule (source, resourcePath) { const requireMethod = process.env.DEVICE_LEVEL === DEVICE_LEVEL.LITE ? methodForLite : methodForOthers source = `${source}\n${requireMethod}` const requireReg = /require\(['"]([^()]+)['"]\)/g @@ -287,6 +288,9 @@ export function parseRequireModule (source) { source = source.replace(requireReg, (item, item1) => { if (libReg.test(item1)) { item = `requireNapi("${item1.replace(libReg, '$1')}", true)` + if (resourcePath) { + useOSFiles.add(resourcePath); + } } return item }) -- Gitee