diff --git a/src/script.js b/src/script.js index 59e0bf80db246ce12c6dda6dc03ebaf6c482ea64..514795660cbd706e7314f2e11a6275513d4cf639 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 1334e65d66593c3026d0e2e6de3a26cc076c1e5a..579f85fa0f810332327809550446421c617fa415 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 = []