Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fis-prepackager-m2c

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fis-prepackager-m2c - npm Package Compare versions

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": {},

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc