From 92daba2f63bdb2d97dc8228a8dc26938582a5bc1 Mon Sep 17 00:00:00 2001 From: lizhouze Date: Mon, 21 Mar 2022 22:09:29 +0800 Subject: [PATCH 1/2] 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 From 3f9c5260b63959e7fcfdf6713fe2826ba1e268c9 Mon Sep 17 00:00:00 2001 From: lizhouze Date: Tue, 22 Mar 2022 21:21:40 +0800 Subject: [PATCH 2/2] lizhouze@huawei.com Signed-off-by: lizhouze --- src/util.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/util.js b/src/util.js index 87e7829..6e07aa0 100644 --- a/src/util.js +++ b/src/util.js @@ -63,27 +63,27 @@ export function logWarn (loader, logs) { logs.forEach(log => { if (log.reason.startsWith('NOTE') && parseInt(process.env.logLevel) <= 1) { if (log.line && log.column) { - loader.emitWarning('noteStartNOTE File:' + loader.resourcePath + ':' + + loader.emitWarning('noteStartNOTE File:' + loader.resourcePath + ':' + log.line + ':' + log.column + '\n ' + log.reason.replace('NOTE: ', '') + 'noteEnd') } else { - loader.emitWarning('noteStartNOTE File:' + loader.resourcePath + + loader.emitWarning('noteStartNOTE File:' + loader.resourcePath + '\n ' + log.reason.replace('NOTE: ', '') + 'noteEnd') } } else if (log.reason.startsWith('WARN') && parseInt(process.env.logLevel) <= 2) { if (log.line && log.column) { - loader.emitWarning('warnStartWARNING File:' + loader.resourcePath + ':' + + loader.emitWarning('warnStartWARNING File:' + loader.resourcePath + ':' + log.line + ':' + log.column + '\n ' + log.reason.replace('WARNING: ', '') + 'warnEnd') } else { - loader.emitWarning('warnStartWARNING File:' + loader.resourcePath + + loader.emitWarning('warnStartWARNING File:' + loader.resourcePath + '\n ' + log.reason.replace('WARNING: ', '') + 'warnEnd') } } else if (log.reason.startsWith('ERROR') && parseInt(process.env.logLevel) <= 3) { flag = true if (log.line && log.column) { - loader.emitError('errorStartERROR File:' + loader.resourcePath + ':' + + loader.emitError('errorStartERROR File:' + loader.resourcePath + ':' + log.line + ':' + log.column + '\n ' + log.reason.replace('ERROR: ', '') + 'errorEnd') } else { - loader.emitError('errorStartERROR File:' + loader.resourcePath + + loader.emitError('errorStartERROR File:' + loader.resourcePath + '\n ' + log.reason.replace('ERROR: ', '') + 'errorEnd') } } -- Gitee