From e742eb09fc97853052783596c25271d9f98dbbd2 Mon Sep 17 00:00:00 2001 From: lizhouze Date: Mon, 14 Mar 2022 17:43:14 +0800 Subject: [PATCH] lizhouze@huawei.com Signed-off-by: lizhouze --- src/script.js | 2 +- src/util.js | 20 +++++++++++++++++++- 2 files changed, 20 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 1334e65..579f85f 100644 --- a/src/util.js +++ b/src/util.js @@ -270,7 +270,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 @@ -286,6 +286,7 @@ export function parseRequireModule (source) { } source = source.replace(requireReg, (item, item1) => { if (libReg.test(item1)) { + addSoFilesInfo(item1, resourcePath); item = `requireNapi("${item1.replace(libReg, '$1')}", true)` } return item @@ -293,6 +294,23 @@ export function parseRequireModule (source) { return source } +function addSoFilesInfo(item, resourcePath) { + const soFilesInfoPath = process.env.aceSoPath; + if (soFilesInfoPath) { + const parent = path.join(soFilesInfoPath, '..'); + if (!(fs.existsSync(parent) && fs.statSync(parent).isDirectory())) { + mkDir(parent); + } + let infos = {}; + if (fs.existsSync(soFilesInfoPath)) { + infos = JSON.parse(fs.readFileSync(soFilesInfoPath, 'utf-8')); + } + infos[resourcePath] = infos[resourcePath] || [] + infos[resourcePath].push(item); + fs.writeFileSync(soFilesInfoPath, JSON.stringify(infos, null, '\n')); + } +} + export function jsonLoaders (type, customLoader, isVisual, queryType) { let loaders = [] -- Gitee