fis-prepackager-m2c
Advanced tools
Comparing version 1.0.12 to 1.0.13
164
index.js
@@ -1,142 +0,60 @@ | ||
var Cache = require('./lib/cache.js'); | ||
var jsm2c = require('jsm2c'); | ||
var pth = require('path'); | ||
var fs = require('fs'); | ||
module.exports = function (ret, conf, settings, opt) { | ||
var jConf = {}; | ||
var alp = require('alpaca-sm'); | ||
jsConf = fis.util.merge(settings, { | ||
root: fis.project.getProjectPath(), | ||
compress: opt.optimize, | ||
fileBasedRoot: true | ||
}); | ||
module.exports = function(ret, conf, settings, opt) { | ||
var alpConf = {}, | ||
cache = new Cache(!!opt.optimize, ret), | ||
allFiles = {}, | ||
filename = 'm2c-op-conf.js', | ||
wlPath, | ||
whiteList, | ||
blackList; | ||
jsm2c.setGetContentHandler(function (path) { | ||
var p = '/' + this.subpath.replace(/\.(less|scss|sass)$/i, '.css'); | ||
if (p in ret.src) { | ||
return ret.src[p].getContent(); | ||
} | ||
settings['isOptimizer'] = !!opt.optimize; | ||
}) | ||
alpConf = fis.util.merge(alpConf, settings); | ||
alpConf.root = fis.project.getProjectPath(); | ||
wlPath = alpConf.root + '/' + filename; | ||
if (fis.util.exists(wlPath)) { | ||
require(wlPath); | ||
} | ||
whiteList = fis.config.get('m2c-white-list') || []; | ||
blackList = fis.config.get('m2c-black-list') || []; | ||
alpConf.fileBasedRoot = true; | ||
alpConf.include = whiteList.concat(alpConf.include || []); | ||
alpConf.exclude = blackList.concat(alpConf.exclude || []); | ||
alpConf.readable = { | ||
css: false, | ||
cssInHTML: false | ||
}; | ||
alp.config.merge(alpConf); | ||
fis.util.map(ret.src, function (id, file) { | ||
var _cache; | ||
var jsm2cFile; | ||
try { | ||
if (file.isHtmlLike || file.isJsLike) { | ||
// if (file.realpath.indexOf('result.html') >= 0) { | ||
// if ('save' in file.cache) { | ||
// console.log(file.cache.cacheInfo) | ||
// } | ||
// } | ||
jsm2cFile = jsm2c.parse(file.realpath, jsConf); | ||
if (!file.isHtmlLike && !file.isCssLike && !file.isJsLike) { | ||
return; | ||
} | ||
id = id.replace(/^[\/]*/, ''); | ||
allFiles[id] = { | ||
file: file, | ||
rawContent: file.getContent() | ||
}; | ||
if (jsm2cFile) { | ||
file.setContent(jsm2cFile.getContent()); | ||
if (file.cache) { | ||
var fisCache = require(file.cache.cacheInfo); | ||
jsm2cFile.adeps.forEach(function (v) { | ||
var path = pth.resolve(jsConf.root, v); | ||
if (fs.existsSync(path)) { | ||
fisCache.deps[path] = fis.util.mtime(path).getTime(); | ||
} | ||
}); | ||
if (!fis.util.filter(file.realpath, fis.config.get('m2c-white-list'), fis.config.get('m2c-black-list'))) { | ||
cache.del(id); | ||
return; | ||
} | ||
fis.util.write(file.cache.cacheInfo, JSON.stringify(fisCache, null, 0)); | ||
} | ||
_cache = cache.read(id); | ||
//解决文件内容依赖其它文件的情况比如使用了inline方式 | ||
if (!file.cache || fis.util.isEmpty(_cache)) { | ||
_cache = {}; | ||
} | ||
if (!fis.util.isEmpty(_cache)) { | ||
file.rawContent = file.getContent(); | ||
file.setContent(_cache._content); | ||
!file.isHtmlLike && ret.map.res[id] && (ret.map.res[id].adeps = _cache.aRequires); | ||
} else { | ||
alp.processor({ | ||
src: file.realpath, | ||
contentProcessor: function (file) { | ||
var retObj; | ||
retObj = ret.src['/' + file.subpath]; | ||
if (retObj) { | ||
return retObj.rawContent || retObj.getContent(); | ||
} else { | ||
return file.getRawContent(); | ||
} | ||
} | ||
}); | ||
file.rawContent = file.getContent(); | ||
file.setContent(alp.storage[id].getContent()); | ||
} | ||
}); | ||
writeCache(alp.storage); | ||
cache.flush(); | ||
function writeCache(storage) { | ||
for (var k in storage) { | ||
cache.write(k, storage[k], function (k, cfile) { | ||
var file, | ||
aFile, | ||
deps = []; | ||
deps = cfile.aRequires; | ||
aFile = allFiles[k]; | ||
file = aFile.file; | ||
for (var i = 0, len = deps.length, _dep; i < len; i++) { | ||
_dep = deps[i]; | ||
file.cache.addDeps(_dep); | ||
} | ||
deps.length && file.cache.save(aFile.rawContent, { | ||
requires: file.requires, | ||
extras: file.extras | ||
}); | ||
}); | ||
ret.ids[k] && ret.ids[k].setContent(storage[k].getContent()); | ||
if (ret.map.res[k]) { | ||
ret.map.res[k].adeps = storage[k].aRequires; | ||
} else { | ||
ret.map[k] = { | ||
type: storage[k].rExt, | ||
url: '/' + k, | ||
deps: storage[k].requires, | ||
adeps: storage[k].aRequires | ||
} | ||
} | ||
} catch (e) { | ||
console.dir(e); | ||
} | ||
} | ||
}; | ||
}); | ||
} |
{ | ||
"name": "fis-prepackager-m2c", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "A modular analysis tool", | ||
@@ -20,3 +20,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"alpaca-sm": "^2.0.0" | ||
"jsm2c": "0.1.5" | ||
}, | ||
@@ -23,0 +23,0 @@ "devDependencies": {}, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
9361
170
2
1
+ Addedjsm2c@0.1.5
+ Addedesquery@0.4.0(transitive)
+ Addedimmutable@3.8.1(transitive)
+ Addedjsm2c@0.1.5(transitive)
- Removedalpaca-sm@^2.0.0
- Removedalpaca-sm@2.1.2(transitive)
- Removedcolors@1.1.2(transitive)
- Removediconv-lite@0.4.13(transitive)