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

fis3-hook-lego

Package Overview
Dependencies
Maintainers
4
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fis3-hook-lego - npm Package Compare versions

Comparing version 0.2.9 to 0.2.10

92

index.js

@@ -6,29 +6,73 @@ /**

*/
var lookup = require('./lookup');
var powerLego = require('./powerLego');
var entry = module.exports = function(fis, opts) {
fis.on('lookup:file', function(info, file) {
// 不处理相对路径的文件
// 不能跳过已经有info.id的文件,必须处理
// 例如: abc.js中require('abc') CommonJs的lookup会找到自己,
// 并不一定需要require('./abc'), 此时如果是想要lego_modules下的abc就惨了
if (file.isJsLike && info.rest && info.rest[0] !== '.') {
var ret = lookup(info.rest, opts);
if (ret && ret.file) {
info.id = ret.file.getId();
info.moduleId = ret.file.moduleId;
info.file = ret.file;
}
} else if (opts.powerLego && info.rest && powerLego.reg.test(info.rest) && !info.id) {
// 处理inline和样式
var ret = powerLego.lookup(info.rest, opts);
if (ret && ret.file) {
info.id = ret.file.getId();
info.file = ret.file;
}
}
});
var lookup = require('./lookup'),
powerLego = require('./powerLego'),
opts = null; // running context opts
var entry = module.exports = function(fis, _opts) {
// set opts
opts = _opts;
fis.on('lookup:file', onLookupFile);
opts.hookHtml && fis.on('proccess:start', onProccessStart);
};
function onLookupFile(info, file) {
// 不处理相对路径的文件
// 不能跳过已经有info.id的文件,必须处理
// 例如: abc.js中require('abc') CommonJs的lookup会找到自己,
// 并不一定需要require('./abc'), 此时如果是想要lego_modules下的abc就惨了
if (file.isJsLike && info.rest && info.rest[0] !== '.') {
var ret = lookup(info.rest, opts);
if (ret && ret.file) {
info.id = ret.file.getId();
info.moduleId = ret.file.moduleId;
info.file = ret.file;
}
} else if (opts.powerLego && info.rest && powerLego.reg.test(info.rest) && !info.id) {
// 处理inline和样式
var ret = powerLego.lookup(info.rest, opts);
if (ret && ret.file) {
info.id = ret.file.getId();
info.file = ret.file;
}
}
}
function onProccessStart(file) {
// 处理html中的链接
// fis isPartial标识是否是内嵌部分
if (!file.isPartial && file._likes.isHtmlLike) {
var content = file.getContent();
if (content) {
content = content.replace(
/(<script\s[^>]*src=["'])([^"']+)/g,
function(str) {
var src = RegExp.$2,
before = RegExp.$1;
if (src[0] !== '.' && !src.match(/^\w+:/i)) {
var ret = lookup(src, opts);
if (ret && ret.file) {
return before + ret.file.getId().replace(/^\/?/, '/');
}
}
return str;
}
);
file.setContent(content);
}
}
}
entry.defaultOptions = {
/**
* @type {Boolean}
* 是否处理html script的src <script src="">
*/
hookHtml: false,
/**
* @type {Object}
* 查找路径及类型
*/
paths: [

@@ -35,0 +79,0 @@ {

{
"name": "fis3-hook-lego",
"version": "0.2.9",
"version": "0.2.10",
"description": "lego 包管理模块查找",

@@ -5,0 +5,0 @@ "keywords": [

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