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 250767308c8cbcc6d94f7993f682283a4d743e45..6e07aa07920dda759b66dc75e10c40233e144224 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(/\..*$/, '') @@ -62,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') } } @@ -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 })