New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-cube

Package Overview
Dependencies
Maintainers
1
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-cube - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

6

index.js

@@ -45,4 +45,4 @@ /*!

* - processors {Array} [optional] set the extenal processors
* - httpPath {String} [optional] the http base for resource
* - scope {String} [optional] set the module
* - resBase {String} [optional] the http base for resource
* - scope {String} [optional] set the module scope, like '@ali'
*

@@ -187,3 +187,3 @@ */

Cube.prototype.fixupResPath= function (dir, code) {
var base = this.config.httpPath || '';
var base = this.config.resBase || '';
return code.replace(/url\( *([\'\"]*)([^\'\"\)]+)\1 *\)/ig, function (m0, m1, m2) {

@@ -190,0 +190,0 @@ if (!m2) {

@@ -242,7 +242,7 @@ /*!

tmp.forEach(function (item) {
res.push(line.substr(offset, item.col + 1));
res.push(line.substring(offset, item.col + 1));
res.push(item.name);
offset = item.col + item.offset + 1;
});
res.push(line.substr(offset));
res.push(line.substring(offset));
arr[i] = res.join('');

@@ -254,2 +254,85 @@ }

/**
* get the most left node in binary expression
* @param {AST_Node} node
* @return {AST_Node}
*/
function getTheLeftNode(node) {
while (node.left) {
node = node.left;
}
return node;
}
function fillMap(node, tarv, map) {
var v = node.start.value;
var col = node.start.col;
var line = node.start.line - 1;
if (!map[line]) {
map[line] = [{col: col, offset: v.length, name: tarv}];
} else {
map[line].push({col: col, offset: v.length, name: tarv});
}
}
/**
* fix the left part, from relpath to abspath
* @param {String} str
* @return {String}
*/
function fixLeftPart(cube, root, filepath, node, release, map) {
var v = node.value;
var abspath = path.join(root, filepath);
var err, tmp;
if (v.indexOf('/') === 0) { // abs path
return ;
} else if (/^\w/.test(v)) { // the node_module
tmp = path.dirname(abspath);
while (true) {
tmp = path.join(tmp, 'node_modules');
if (fs.existsSync(tmp)) {
break;
}
tmp = path.dirname(tmp);
if (tmp.length <= root.length) {
err = new Error('node_modules not found when loading dynamic module');
err.name = 'CUBE_EXCEPTION';
throw err;
}
}
tmp = tmp.substr(root.length);
node.value = tmp;
} else if (v.indexOf('.') === 0) { // the relative path
tmp = path.dirname(filepath, v);
if (/\/$/.test(v) && !/\/$/.test(tmp)) {
tmp += '/';
}
node.value = tmp;
} else {
err = new Error('unknow error when loading dynamic module');
err.name = 'CUBE_EXCEPTION';
throw err;
}
fillMap(node, tmp, map);
}
/**
* fix the right part, change the suffix
* @return {String}
*/
function fixRightPart(cube, root, filepath, node, release, map) {
var sufix = node.value.match(/\.\w+$/);
var tmp, type;
if (!sufix) {
tmp = node.value + '.js';
} else {
sufix = sufix[0];
type = cube.processors.map[sufix];
if (!type) {
tmp = node.value + '.js';
} else {
tmp = utils.moduleName(node.value, type, release);
}
}
node.value = tmp;
fillMap(node, tmp, map);
}
/**
* Class JsProcessor

@@ -347,2 +430,24 @@ * @param {Object} cube the cube instance

}
// check if Binary express, like `async('./abc' + vars + '.js');`
if (node.args[0].TYPE === 'Binary') {
if (node.expression === 'require') {
var err = new Error('require not support variable');
err.name = 'CUBE_EXCEPTION';
throw err;
}
var args0 = node.args[0];
// get the right and the
var theRight = args0.right;
var theLeft = getTheLeftNode(args0);
if (theLeft.TYPE === 'String') {
// 处理left前缀
fixLeftPart(cube, root, filepath, theLeft, options.release, requiresMap);
}
if (theRight.TYPE === 'String') {
// 处理right后缀,
fixRightPart(cube, root, filepath, theRight, options.release, requiresMap);
}
}
var v = node.args[0].value;

@@ -349,0 +454,0 @@ if (!v || typeof v !== 'string') {

@@ -5,3 +5,3 @@ {

"description": "a new way to write js in browser",
"version": "0.1.4",
"version": "0.1.5",
"homepage": "https://github.com/fishbar/cube",

@@ -8,0 +8,0 @@ "repository": {

@@ -128,9 +128,9 @@ Cube

{
root: //静态资源路径
port: //需要监听的端口
root: // 静态资源路径
port: // 需要监听的端口
middleware: // 是否中间件模式
base: //所有文件的前缀路径
httpPath: //css中图片路径的前缀路径
scope:
maxAge: // 浏览器端文件缓存时间,最终会应用到http头:Cache-Control: public, maxAge=xxx
base: // 所有文件的前缀路径
resBase: // css中图片等资源的前缀路径
scope: // 模块的scope,like `@ali`, 暂未使用
maxAge: // 浏览器端文件缓存时间,最终会应用到http头:Cache-Control: public, maxAge=xxx
}

@@ -150,2 +150,13 @@ ```

build参数:
```
-h, --help output usage information
-p, --processors [value] build in modules, tell cube ignore them, 关插件
-o, --output [value] set the output path 指定输出目录
-b, --base [value] set the cube base 指定代码库base
--with-source create source file 指定是否输出源文件
-r, --resbase [value] the http base for resouce 指定css中的资源文件 http路径的base
--merge if merged dependences into on file 是否合并
```
在静态资源目录下,编写 `.cubeignore`来排除不需要被处理的文件,格式和.gitignore一样

@@ -152,0 +163,0 @@

@@ -88,3 +88,10 @@ var xfs = require('xfs');

}
/**
* processFile
* @param {Cube} cube cube instance
* @param {Path} source the abs source file
* @param {Path} dest this abs target file
* @param {Object} opts
* @param {Function} cb(err, res)
*/
function processFile(cube, source, dest, opts, cb) {

@@ -91,0 +98,0 @@ if (!dest) {

Sorry, the diff of this file is not supported yet

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