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

basisjs-tools

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

basisjs-tools - npm Package Compare versions

Comparing version 0.0.32 to 0.0.33

9

lib/build/css/extract.js

@@ -27,5 +27,7 @@

var attrs = html_at.getAttrs(node);
if (/\bstylesheet\b/i.test(attrs.rel))
if (html_at.rel(node, 'stylesheet'))
{
fconsole.log('External style found: <link rel="' + attrs.rel + '">');
// <link rel="stylesheet">');
fconsole.log('External style found: ' + html_at.translate(node));
var styleLinkFile = flow.files.add({

@@ -54,2 +56,3 @@ type: 'style',

// <style> or <style type="text/css">
fconsole.log('Inline style found');

@@ -151,3 +154,3 @@

else
file.ast = csso.parse(file.content, 'stylesheet', true);
file.ast = csso.parse(file.content, 'stylesheet', true) || [{ ln: 1 }, 'stylesheet'];

@@ -154,0 +157,0 @@ // search and extract css files

@@ -21,3 +21,3 @@

prev.ast.push.apply(prev.ast, file.ast.slice(2));
html_at.removeToken(file.htmlNode);
html_at.removeToken(file.htmlNode, true);
}

@@ -24,0 +24,0 @@ else

@@ -10,3 +10,5 @@ var htmlparser = require('htmlparser2');

// prepare parser
var handler = new htmlparser.DefaultHandler();
var handler = new htmlparser.DomHandler(false, {
refParent: true
});
var parser = new htmlparser.Parser(handler, parserConfig);

@@ -17,2 +19,9 @@

this.walk(handler.dom, {
'*': function(node){
if (node.type == 'style' || node.type == 'script')
node.type = 'tag';
}
});
return handler.dom;

@@ -22,8 +31,15 @@ },

return htmlparser.DomUtils.getInnerHTML({
children: ast
children: Array.isArray(ast) ? ast : [ast]
});
},
getText: function(node){
return (node.children && node.children[0] && node.children[0].data) || '';
getText: function getText(node){
var result = '';
if (node.children)
result = node.children.reduce(function(res, node){
return res + (node.type == 'text' ? node.data : getText(node));
}, '');
return result;
},

@@ -33,3 +49,10 @@ getAttrs: function(node){

},
rel: function(node, entry){
var rels = (this.getAttrs(node).rel || '').trim().split(/\s+/);
return entry
? rels.indexOf(entry) != -1
: rels;
},
injectToHead: function(ast, node){

@@ -58,8 +81,8 @@ var insertPoint = ast;

if (type == 'style' || type == 'script')
type = 'tag';
if (handlers.hasOwnProperty(type))
if (typeof handlers[type] == 'function')
handlers[type].call(context, node);
if (typeof handlers['*'] == 'function')
handlers['*'].call(context, node);
if (node.children)

@@ -73,4 +96,18 @@ walkNode(node.children);

removeToken: function(token){
this.replaceToken(token, { type: 'text', data: '' });
removeToken: function(token, remln){
if (remln && token.parent && token.parent.children)
{
var ar = token.parent.children;
var index = ar.indexOf(token);
ar.splice(ar.indexOf(token), 1);
if (index > 0 && ar[index].type == 'text')
ar[index].data = ar[index].data.replace(/(\r\n?|\n\r?)\s*$/, '');
}
else
{
this.replaceToken(token, {
type: 'text',
data: ''
});
}
},

@@ -77,0 +114,0 @@ replaceToken: function(token, cfg){

@@ -5,2 +5,4 @@ /*

var hasOwnProperty = Object.prototype.hasOwnProperty;
//

@@ -57,3 +59,3 @@ // Scope class

{
if (cursor.names.hasOwnProperty(name))
if (hasOwnProperty.call(cursor.names, name)) // hasOwnProperty may be overriden
return cursor;

@@ -60,0 +62,0 @@

var path = require('path');
var at = require('./ast_tools');
var html_at = require('../html/ast_tools');

@@ -16,9 +17,5 @@ module.exports = function(flow){

var basisFile = flow.js.basisScript && flow.files.get(flow.js.basisScript);
var htmlNode;
if (basisFile)
{
htmlNode = basisFile.htmlNode
delete basisFile.htmlNode;
// inject resources

@@ -62,3 +59,5 @@ var inserted = false;

var content = file.jsResourceContent || file.outputContent || file.content;
var content = file.jsResourceContent != null
? file.jsResourceContent
: file.outputContent || file.content;

@@ -106,5 +105,7 @@ if (typeof content == 'function')

{
var packageFiles = packages[name];
var package = packages[name];
// log package file list
fconsole.start('Package ' + name + ':');
packageFiles.forEach(function(f){
package.forEach(function(f){
fconsole.log(f.relpath);

@@ -114,21 +115,52 @@ });

var isCoreFile = basisFile && (flow.options.jsSingleFile || name == 'basis');
var throwCodes = packageFiles.reduce(function(res, file){
res.push.apply(res, file.throwCodes);
return res;
}, isCoreFile && basisFile.throwCodes ? basisFile.throwCodes.slice() : []);
switch (package.layout){
case 'basis':
var isCoreFile = basisFile && (flow.options.jsSingleFile || name == 'basis');
var throwCodes = package.reduce(function(res, file){
res.push.apply(res, file.throwCodes);
return res;
}, []);
var packageFile = flow.files.add({
type: 'script',
outputFilename: name + '.js',
outputContent:
(isCoreFile ? '// resources (' + resourceToc.length + '):\n// ' + resourceToc.join('\n// ') + '\n//\n' : '') +
(throwCodes.length ? '// throw codes:\n// ' + throwCodes.map(function(item){ return item[0] + ' -> ' + at.translate(item[1]) }).join('\n// ') + '\n//\n' : '') +
wrapPackage(packages[name], flow, isCoreFile ? at.translate(basisFile.ast) : '')
});
var packageFile = flow.files.add({
type: 'script',
outputFilename: name + '.js',
outputContent:
(isCoreFile ? '// resources (' + resourceToc.length + '):\n// ' + resourceToc.join('\n// ') + '\n//\n' : '') +
(throwCodes.length ? '// throw codes:\n// ' + throwCodes.map(function(item){ return item[0] + ' -> ' + at.translate(item[1]) }).join('\n// ') + '\n//\n' : '') +
wrapPackage(package.filter(function(file){ return file != basisFile }), flow, isCoreFile ? at.translate(basisFile.ast) : '')
});
packages[name].file = packageFile;
packages[name].file = packageFile;
if (htmlNode)
packageFile.htmlNode = htmlNode;
if (isCoreFile)
{
packageFile.htmlNode = basisFile.htmlNode;
delete basisFile.htmlNode;
}
break;
default:
var htmlNode = null;
var packageFile = flow.files.add({
type: 'script',
outputFilename: name + '.js',
outputContent: package.map(function(file){
if (file.htmlNode)
{
if (!htmlNode)
htmlNode = file.htmlNode;
else
html_at.removeToken(file.htmlNode, true);
delete file.htmlNode;
}
return '//' + file.relpath + '\n' + file.outputContent;
}).join(';\n\n') + ';'
});
packageFile.htmlNode = htmlNode;
packages[name].file = packageFile;
}
}

@@ -171,3 +203,3 @@ }

function wrapPackage(package, flow, contentPrepend){
return !flow.options.buildMode
return !flow.options.jsBuildMode
// source mode

@@ -184,3 +216,3 @@ ? [

package.map(extractSourceContent).join(',\n'),
'].forEach(' + function(module){
'\n].forEach(' + function(module){
var path = module.path;

@@ -187,0 +219,0 @@ var fn = path + module.fn;

var html_at = require('../html/ast_tools');
var at = require('./ast_tools');
var utils = require('../misc/utils');
var NON_WHITESPACE = /[^\s\r\n]/;
module.exports = function(flow){

@@ -34,2 +37,4 @@

var scriptSequenceId = 0;
var inSequence = false;
for (var i = 0, file; file = queue[i]; i++)

@@ -42,3 +47,15 @@ {

html_at.walk(file.ast, {
tag: function(node){
'*': function(node){
// nothing to do if text node contains whitespace only
if (node.type == 'text' && !NON_WHITESPACE.test(node.data))
return;
// scripts with src continue script sequence
if (node.type == 'tag' && node.name == 'script')
return;
scriptSequenceId += inSequence;
inSequence = false;
},
'tag': function(node){
if (node.name != 'script')

@@ -52,3 +69,3 @@ return;

{
fconsole.log('[!] <script> with type ' + attrs.type + ' ignored');
fconsole.log('[!] <script> with unknown type `' + attrs.type + '` ignored\n');
return;

@@ -60,35 +77,65 @@ }

{
fconsole.log('External script found: <script src="' + attrs.src + '">');
var uri = utils.resolveUri(attrs.src);
var scriptFile = flow.files.add({
htmlNode: node,
type: 'script',
filename: file.resolve(attrs.src)
});
if (uri.filename)
{
fconsole.start('External script found: <script src="' + attrs.src + '">');
inSequence = true;
if (!scriptFile)
return;
var scriptFile = flow.files.add({
htmlNode: node,
type: 'script',
filename: file.resolve(attrs.src),
package: 'script' + (scriptSequenceId || '')
});
file.link(scriptFile);
if (!scriptFile)
return;
var configAttr;
file.link(scriptFile);
if (attrs.hasOwnProperty('data-basis-config'))
configAttr = 'data-basis-config';
else
if (attrs.hasOwnProperty('basis-config'))
configAttr = 'basis-config';
var configAttr;
if (configAttr)
if (attrs.hasOwnProperty('data-basis-config'))
configAttr = 'data-basis-config';
else
if (attrs.hasOwnProperty('basis-config'))
configAttr = 'basis-config';
if (configAttr)
{
fconsole.log('[i] basis.js marker found (basis-config attribute)');
scriptFile.htmlFile = file;
scriptFile.basisScript = true;
scriptFile.basisConfig = attrs[configAttr] || '';
scriptFile.namespace = 'basis';
scriptFile.package = 'basis';
}
fconsole.endl();
}
else if (uri.mime == 'text/javascript')
{
fconsole.log('[i] basis.js marker found (basis-config attribute)');
scriptFile.htmlFile = file;
scriptFile.basisScript = true;
scriptFile.basisConfig = attrs[configAttr] || '';
scriptFile.namespace = 'basis';
fconsole.start('Inline script with data uri found');
inSequence = true;
file.link(flow.files.add({
htmlNode: node,
type: 'script',
inline: true,
baseURI: file.baseURI,
content: uri.content,
package: 'script' + (scriptSequenceId || '')
}));
fconsole.endl();
}
else
{
fconsole.log('[!] script ignored: ' + html_at.translate(node) + '\n');
}
}
else
{
fconsole.log('Inline script found');
fconsole.log('Inline script found\n');

@@ -155,3 +202,3 @@ file.link(flow.files.add({

namespace: config.autoload,
package: config.autoload
package: 'basis'//config.autoload
});

@@ -240,3 +287,3 @@ createScope(autoloadFile, flow);

if (flow.options.buildMode)
if (flow.options.jsCutDev)
{

@@ -413,3 +460,3 @@ content = content

namespace: root,
package: root
package: 'basis'//root
});

@@ -416,0 +463,0 @@ flow.js.rootNSFile[root] = rootFile;

@@ -10,5 +10,2 @@

if (flow.js.basisScript)
packages['script'] = []; // TODO: change for real basis package name
for (var i = 0, file; file = queue[i]; i++)

@@ -19,4 +16,10 @@ if (file.type == 'script' && file.package)

if (!package)
{
package = packages[file.package] = [];
var rootFile = flow.js.rootNSFile[file.package];
if (rootFile && rootFile.package == file.package && rootFile.package == rootFile.namespace)
package.layout = 'basis';
}
package.push.apply(package, buildDep(file, file.package));

@@ -23,0 +26,0 @@ }

@@ -12,3 +12,3 @@

{
file.package = 'script';
//file.package = 'script';
fconsole.log(file.package + ' <- ' + file.relpath);

@@ -15,0 +15,0 @@ }

@@ -9,8 +9,8 @@

{
for (var name in packages)
{
var file = packages[name].file;
fconsole.log('Init compression for ' + file.relOutputFilename);
runProcess(file, fconsole, startFn, doneFn);
}
for (var i = 0, file; file = queue[i]; i++)
if (file.type == 'script' && file.htmlNode && file.outputContent)
{
fconsole.log('Init compression for ' + file.relOutputFilename);
runProcess(file, fconsole, startFn, doneFn);
}
}

@@ -31,3 +31,3 @@ else

{
maxBuffer: 10 * 1024 *1024
maxBuffer: 10 * 1024 * 1024
},

@@ -43,3 +43,3 @@ function(error, stdout, stderr){

else
file.outputContent = stdout;
file.outputContent = stdout.replace(/;[\r\n\s]*$/, '');

@@ -46,0 +46,0 @@ doneFn();

@@ -25,22 +25,18 @@

{
html_at.replaceToken(file.htmlNode,
file.outputContent
? {
type: 'script',
name: 'script',
attribs: {
type: 'text/javascript'
},
children: [
{
type: 'text',
data: file.outputContent
}
]
}
: {
if (!file.outputContent)
html_at.removeToken(file.htmlNode, true);
else
html_at.replaceToken(file.htmlNode, {
type: 'script',
name: 'script',
attribs: {
type: 'text/javascript'
},
children: [
{
type: 'text',
data: ''
data: file.outputContent
}
);
]
})
}

@@ -47,0 +43,0 @@ }

@@ -16,3 +16,5 @@ //

file.outputContent = at.translate2(file.ast);
file.outputContent = at.translate2(file.ast, {
inline_script: !file.outputFilename
});

@@ -22,3 +24,3 @@ try {

} catch(e) {
file.jsResourceContent = Function();
file.jsResourceContent = Function('//[ERROR] Compilation error: ' + file.relpath + ' (' + e + ')');
fconsole.log('[ERROR] Compilation error: ' + file.relpath + ' (' + e + ')');

@@ -25,0 +27,0 @@ }

@@ -0,0 +0,0 @@ module.exports = function(flow){

@@ -110,3 +110,5 @@

get baseURI(){
return unixpath(this.filename ? path.dirname(this.filename) + '/' : this.baseURI_ || '');
if (!this.baseURI_)
this.baseURI_ = unixpath(this.filename ? path.dirname(this.filename) + '/' : '');
return this.baseURI_;
},

@@ -126,3 +128,3 @@ set baseURI(uri){

get relOutputFilename(){
return this.outputFilename || '[no output filename]';
return this.outputFilename || ('outputContent' in this ? '[inline ' + this.type + ']' : '[no output]');
},

@@ -160,3 +162,3 @@

var hash = crypto.createHash('md5');
hash.update(this.outputContent || this.content);
hash.update(this.outputContent || this.content || '');
this.digest_ = hash.digest('base64')

@@ -163,0 +165,0 @@ // remove trailing == which always appear on md5 digest, save 2 bytes

@@ -59,2 +59,7 @@

}
else
{
if (key != '_configPath')
console.warn('Unknown key `' + key + '` in config ignored');
}
}

@@ -123,3 +128,3 @@ }

// TODO: remove
options.buildMode = true;
options.jsBuildMode = true;

@@ -126,0 +131,0 @@ return options;

@@ -26,27 +26,44 @@

var attrs = atHtml.getAttrs(node);
var imageUrl = attrs.src;
if (attrs.src)
if (imageUrl)
{
fconsole.log('Found <img src="' + attrs.src + '"/>');
fconsole.log('Found <img src="' + imageUrl + '"/>');
var resFile = files.add({
filename: file.resolve(attrs.src)
});
var imageFile = resolveImage(flow, file, imageUrl);
if (resFile)
if (imageFile)
attrs.src = imageFile.fileRef;
else
console.log('Image reference ignored (is not resolved)');
}
break;
case 'link':
if (atHtml.rel(node, 'icon') ||
atHtml.rel(node, 'apple-touch-icon') ||
atHtml.rel(node, 'apple-touch-icon-precomposed') ||
atHtml.rel(node, 'apple-touch-startup-image'))
{
var attrs = atHtml.getAttrs(node);
var imageUrl = attrs.href;
if (imageUrl)
{
file.link(resFile);
fconsole.log('Found <link rel="' + atHtml.rel(node).join(' ') + '"/>');
resFile.outputFilename = flow.outputResourceDir + resFile.digest + resFile.ext;
resFile.fileRef = resFile.relOutputFilename;
resFile.outputContent = resFile.content;
var imageFile = resolveImage(flow, file, attrs.href);
attrs.src = resFile.fileRef;
if (imageFile)
attrs.href = imageFile.fileRef;
else
console.log('Image reference ignored (is not resolved)');
}
}
break;
break;
}
}
})
});

@@ -67,11 +84,11 @@ fconsole.endl();

{
var resFile = files.add({
filename: file.resolve(uri.filename)
});
file.link(resFile);
resFile.cssResource = true;
resFile.outputFilename = flow.outputResourceDir + resFile.digest + resFile.ext;
resFile.fileRef = resFile.relOutputFilename;
var imageFile = resolveImage(flow, file, uri.filename);
atCss.packUri(resFile.fileRef, token);
if (imageFile)
{
imageFile.cssResource = true;
atCss.packUri(imageFile.fileRef, token);
}
else
console.log('Image reference ignored (is not resolved)');
}

@@ -113,2 +130,19 @@ /*urlMap.push({

module.exports.handlerName = '[res] Extract';
module.exports.handlerName = '[res] Extract';
function resolveImage(flow, file, url){
var imageFile = flow.files.add({
filename: file.resolve(url)
});
if (imageFile)
{
file.link(imageFile);
imageFile.outputFilename = flow.outputResourceDir + imageFile.digest + imageFile.ext;
imageFile.fileRef = imageFile.relOutputFilename;
imageFile.outputContent = imageFile.content;
}
return imageFile;
}

@@ -15,3 +15,6 @@ ;(function(global){

if (typeof console == 'undefined')
console = { log: Function(), warn: Function() };
console = {
log: function(){},
warn: function(){}
};

@@ -100,103 +103,117 @@ //

//
// init part
// script event handlers
//
basis.ready(function(){
// socket.io
basis.dom.appendHead(
basis.dom.createElement({
description: 'script[src="/socket.io/socket.io.js"]',
error: function(){
console.warn('Error on loading ' + this.src);
},
load: function(){
if (typeof io != 'undefined')
{
console.log('Connecting to server via socket.io');
function onError(){
if (this.parentNode)
this.parentNode.removeChild(this);
var socket = io.connect('/');
serverState.update({ isReady: true });
console.warn('Error on loading ' + this.src);
}
var sendToServerOffline = function(){
console.warn('No connection with server :( Trying to send:', arguments);
};
function onLoad(){
if (this.parentNode)
this.parentNode.removeChild(this);
var sendToServerOnline = function(){
console.log('Send to server: ', arguments[0], arguments[1]);
socket.emit.apply(socket, arguments);
};
if (typeof io == 'undefined')
return;
//
// add callbacks on events
//
Object.iterate({
//
// connection events
//
connect: function(){
socket.emit('observe');
sendToServer = sendToServerOnline;
console.log('Connecting to server via socket.io');
serverState.update({ isOnline: true });
},
disconnect: function(){
sendToServer = sendToServerOffline;
var socket = io.connect('/');
serverState.update({ isReady: true });
serverState.update({ isOnline: false });
},
observeReady: function(filelist){
var items = files.getItems();
for (var i = 0, file; file = items[i]; i++)
removeFile(file.filename);
var sendToServerOffline = function(){
console.warn('No connection with server :( Trying to send:', arguments);
};
for (var i = 0, fileData; fileData = filelist[i]; i++)
{
if (fileData.type == 'file')
{
createFile(fileData.filename).update({
content: fileData.content,
type: fileData.type
});
}
}
},
var sendToServerOnline = function(){
console.log('Send to server: ', arguments[0], arguments[1]);
socket.emit.apply(socket, arguments);
};
//
// file events
//
newFile: function(data){
console.log('New file', data);
//
// add callbacks on events
//
Object.iterate({
//
// connection events
//
connect: function(){
socket.emit('observe');
sendToServer = sendToServerOnline;
createFile(data.filename).update({
type: data.type,
content: data.content
});
},
updateFile: function(data){
console.log('File updated', data);
serverState.update({ isOnline: true });
},
disconnect: function(){
sendToServer = sendToServerOffline;
var file = getFile(data.filename);
file.update({
type: data.type,
content: data.content
});
file.setState(STATE.READY);
},
deleteFile: function(data){
console.log('File deleted', data);
serverState.update({ isOnline: false });
},
observeReady: function(filelist){
var items = files.getItems();
for (var i = 0, file; file = items[i]; i++)
removeFile(file.filename);
removeFile(data.filename);
},
//
// common events
//
error: function(data){
console.log('error:', data.operation, data.message);
}
}, socket.on, socket);
for (var i = 0, fileData; fileData = filelist[i]; i++)
{
if (fileData.type == 'file')
{
createFile(fileData.filename).update({
content: fileData.content,
type: fileData.type
});
}
}
})
);
},
//
// file events
//
newFile: function(data){
console.log('New file', data);
createFile(data.filename).update({
type: data.type,
content: data.content
});
},
updateFile: function(data){
console.log('File updated', data);
var file = getFile(data.filename);
file.update({
type: data.type,
content: data.content
});
file.setState(STATE.READY);
},
deleteFile: function(data){
console.log('File deleted', data);
removeFile(data.filename);
},
//
// common events
//
error: function(data){
console.log('error:', data.operation, data.message);
}
}, socket.on, socket);
}
//
// init part
//
basis.ready(function(){
var scriptEl = document.createElement('script');
scriptEl.src = "/socket.io/socket.io.js";
scriptEl.onload = onLoad;
scriptEl.onerror = onError;
document.getElementsByTagName('head')[0].appendChild(scriptEl);
});

@@ -203,0 +220,0 @@

@@ -407,3 +407,3 @@

{
var fileContent = String(data).replace(/<head>/i, '<head><script src="/FDF31FF4-1532-421C-A865-99D0E77ADE04.js"></script>');
var fileContent = String(data).replace(/<script/i, '<script src="/FDF31FF4-1532-421C-A865-99D0E77ADE04.js"></script><script');

@@ -410,0 +410,0 @@ if (options.sync)

{
"name": "basisjs-tools",
"title": "Basis developer tools",
"version": "0.0.32",
"version": "0.0.33",
"homepage": "https://github.com/lahmatiy/basisjs-tools",

@@ -6,0 +6,0 @@ "description": "Developer tools for basis.js framework",

@@ -90,3 +90,3 @@ Developer tools for [basis.js](https://github.com/lahmatiy/basisjs) framework.

$ basis server --help
$ basis build --help

@@ -93,0 +93,0 @@ ## License

@@ -0,0 +0,0 @@ var util = require('util');

@@ -0,0 +0,0 @@ var htmlparser = require("htmlparser2");

@@ -0,0 +0,0 @@ var parse = require('../../../build/js/parse.js');

@@ -0,0 +0,0 @@ var parser = require('uglify-js').parser;

@@ -0,0 +0,0 @@ var parser = require('uglify-js').parser;

@@ -0,0 +0,0 @@ var parse = require('../../../build/tmpl/parse.js');

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