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

assetgraph

Package Overview
Dependencies
Maintainers
1
Versions
569
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assetgraph - npm Package Compare versions

Comparing version 0.3.18 to 0.3.19

lib/assets/Stylus.js

14

lib/assets/Html.js

@@ -145,10 +145,20 @@ var util = require('util'),

if (node.hasAttribute('src')) {
if (isRelationUrl(node.getAttribute('src'))) {
var src = node.getAttribute('src');
if (isRelationUrl(src)) {
outgoingRelations.push(new relations.HtmlScript({
from: this,
to: {
url: node.getAttribute('src')
url: src
},
node: node
}));
if (/(^|\/)require\.js$/.test(src) && node.hasAttribute('data-main')) {
outgoingRelations.push(new relations.HtmlRequireJsMain({
from: this,
to: {
url: node.getAttribute('data-main') + '.js'
},
node: node
}));
}
}

@@ -155,0 +165,0 @@ } else {

@@ -68,3 +68,2 @@ var util = require('util'),

var outgoingRelations = [],
stack = [],
errors = [];

@@ -89,3 +88,17 @@

var traverse = function (node) {
this.parseTree[1]._parent = this.parseTree;
var queue = [this.parseTree[1]],
queueIndex = 0;
while (queueIndex < queue.length) {
var node = queue[queueIndex];
queueIndex += 1;
for (var i = 0 ; i < node.length ; i++) {
if (Array.isArray(node[i])) {
node[i]._parent = node;
queue.push(node[i]);
}
}
if (node[0] === 'call' && node[1][0] === 'dot' && node[1][1][0] === 'name' && node[1][1][1] === 'one') {

@@ -97,9 +110,9 @@ // one.<something>()

parentNode;
if (stack[stack.length - 1][0] === 'seq') {
if (node._parent[0] === 'seq') {
detachableNode = node;
parentNode = stack[stack.length - 1];
parentNode = node._parent;
} else {
// Assume ['stat', ['call', ...]]
detachableNode = stack[stack.length - 1];
parentNode = stack[stack.length - 2];
detachableNode = node._parent;
parentNode = node._parent._parent;
}

@@ -126,3 +139,3 @@ outgoingRelations.push(new relations.JavaScriptOneInclude({

node: node,
parentNode: stack[stack.length - 1]
parentNode: node._parent
}));

@@ -216,3 +229,3 @@ } else {

},
extRequireStatParentNode: stack[stack.length - 1],
extRequireStatParentNode: node._parent,
extRequireStatNode: node,

@@ -225,16 +238,66 @@ node: stringNode

}
}
// Depth-first
for (var i = 0 ; i < node.length ; i++) {
if (Array.isArray(node[i])) {
stack.push(node);
traverse(node[i]);
stack.pop();
} else if (node[0] === 'call' && node[1][0] === 'name' && node[1][1] === 'require' &&
((node[2].length === 2 && node[2][1][0] === 'function') || node[2].length === 1) &&
node[2][0][0] === 'array') {
var arrayNode = node[2][0];
arrayNode[1].forEach(function (arrayItemAst) {
if (arrayItemAst[0] === 'string') {
var outgoingRelation = new relations.JavaScriptAmdRequire({
from: this,
callNode: node,
arrayNode: arrayNode,
node: arrayItemAst
});
outgoingRelation.to = {url: outgoingRelation.href};
outgoingRelations.push(outgoingRelation);
} else {
console.warn('Skipping non-string JavaScriptAmdRequire item: ' + uglify.uglify.gen_code(node));
}
}, this);
} else if (node[0] === 'call' && node[1][0] === 'name' && node[1][1] === 'define') {
var arrayNode;
if (node[2].length === 3 && node[2][0][0] === 'string' && node[2][1][0] === 'array') {
arrayNode = node[2][1];
} else if (node[2].length === 2 && node[2][0][0] === 'array') {
arrayNode = node[2][0];
}
if (arrayNode) {
arrayNode[1].forEach(function (arrayItemAst) {
if (arrayItemAst[0] === 'string') {
var outgoingRelation = new relations.JavaScriptAmdDefine({
from: this,
callNode: node,
arrayNode: arrayNode,
node: arrayItemAst
});
outgoingRelation.to = {url: outgoingRelation.href};
outgoingRelations.push(outgoingRelation);
} else {
console.warn('Skipping non-string JavaScriptAmdDefine item: ' + uglify.uglify.gen_code(node));
}
}, this);
}
} else if (node[0] === 'call' && node[1][0] === 'name' && node[1][1] === 'require' &&
node[2].length === 1 && node[2][0][0] === 'string') {
var baseUrl = this.nonInlineAncestor.url;
if (/^file:/.test(baseUrl)) {
var Module = require('module'),
path = require('path'),
fileName = urlTools.fileUrlToFsPath(baseUrl),
fakeModule = new Module(fileName);
fakeModule.filename = fileName;
fakeModule.paths = Module._nodeModulePaths(path.dirname(fakeModule.fileName));
outgoingRelations.push(new relations.JavaScriptCommonJsRequire({
from: this,
to: {
url: urlTools.fsFilePathToFileUrl(Module._resolveFilename(node[2][0][1], fakeModule)[0])
},
node: node
}));
} else {
console.warn('Skipping JavaScriptCommonJsRequire (only supported from file: urls): ' + uglify.uglify.gen_code(node));
}
}
}.bind(this);
}
traverse(this.parseTree);
if (errors.length) {

@@ -241,0 +304,0 @@ throw new Error(_.pluck(errors, 'message').join("\n"));

58

lib/transforms/flattenStaticIncludes.js

@@ -8,12 +8,38 @@ var _ = require('underscore'),

var addedAssetsById = {}; // Only add one <link rel='stylesheet'> / <script> per asset.
assetGraph.findRelations({from: initialAsset, type: 'HtmlScript'}).forEach(function (htmlScriptRelation) {
var htmlStyleInsertionPoint,
existingHtmlStyleRelations = assetGraph.findRelations({type: 'HtmlStyle', from: initialAsset}, true); // includeUnpopulated
assetGraph.findRelations({from: initialAsset, type: ['HtmlScript', 'HtmlRequireJsMain']}).forEach(function (htmlScriptRelation) {
var existingHtmlStyleRelations = assetGraph.findRelations({type: 'HtmlStyle', from: initialAsset}, true), // includeUnpopulated
pathByAssetId = {},
htmlStyleInsertionPoint,
htmlScriptInsertionPoint;
if (existingHtmlStyleRelations.length > 0) {
htmlStyleInsertionPoint = existingHtmlStyleRelations[existingHtmlStyleRelations.length - 1];
}
var pathByAssetId = {};
function processRelation(relation) {
if (!(relation.to.id in addedAssetsById)) {
if (relation.to.type === 'Css') {
var newHtmlStyle = new relations.HtmlStyle({to: relation.to});
if (htmlStyleInsertionPoint) {
newHtmlStyle.attach(initialAsset, 'after', htmlStyleInsertionPoint);
} else {
newHtmlStyle.attach(initialAsset, 'first');
}
htmlStyleInsertionPoint = newHtmlStyle;
} else if (relation.to.type === 'JavaScript') {
var newHtmlScript = new relations.HtmlScript({to: relation.to});
if (htmlScriptInsertionPoint) {
newHtmlScript.attach(initialAsset, 'after', htmlScriptInsertionPoint);
} else {
// The RequireJS loader must come before the scripts that use it:
newHtmlScript.attach(initialAsset, htmlScriptRelation.type === 'HtmlRequireJsMain' ? 'after' : 'before', htmlScriptRelation);
}
htmlScriptInsertionPoint = newHtmlScript;
}
addedAssetsById[relation.to.id] = true;
}
}
(function traversePostorder(asset) {
pathByAssetId[asset.id] = true;
assetGraph.findRelations({from: asset, type: ['JavaScriptOneInclude', 'JavaScriptExtJsRequire']}).forEach(function (relation) {
assetGraph.findRelations({from: asset, type: ['JavaScriptOneInclude', 'JavaScriptExtJsRequire', 'JavaScriptAmdRequire', 'JavaScriptAmdDefine']}).forEach(function (relation) {
if (relation.to.id in pathByAssetId) {

@@ -23,19 +49,3 @@ console.warn("transforms.flattenStaticIncludes: Cycle detected: " + relation);

traversePostorder(relation.to);
if (!(relation.to.id in addedAssetsById)) {
if (relation.to.type === 'Css') {
var htmlStyle = new relations.HtmlStyle({to: relation.to});
if (htmlStyleInsertionPoint) {
htmlStyle.attach(initialAsset, 'after', htmlStyleInsertionPoint);
} else {
htmlStyle.attach(initialAsset, 'first');
}
htmlStyleInsertionPoint = htmlStyle;
} else if (relation.to.type === 'JavaScript') {
new relations.HtmlScript({to: relation.to}).attach(initialAsset, 'before', htmlScriptRelation);
} else if (relation.to.type !== 'I18n') {
// Don't do anything for relations to I18n assets.
throw new Error("transforms.flattenStaticIncludes assertion error: Relation to " + relation.to.type + " not supported");
}
addedAssetsById[relation.to.id] = true;
}
processRelation(relation);
if (asset === htmlScriptRelation.to && relation.type === 'JavaScriptOneInclude') {

@@ -50,2 +60,6 @@ relation.detach();

}(htmlScriptRelation.to));
if (htmlScriptRelation.type === 'HtmlRequireJsMain') {
processRelation(htmlScriptRelation);
htmlScriptRelation.detach();
}
});

@@ -52,0 +66,0 @@ });

@@ -15,3 +15,3 @@ var fs = require('fs'),

fs.mkdir(dir, permissions, function (err) {
if (err && err.errno === constants.EEXIST) {
if (err && (err.code === 'EEXIST' || err.errno === constants.EEXIST)) {
// Success!

@@ -25,3 +25,3 @@ return cb();

fs.mkdir(dir, permissions, function (err) {
if (!err || err.errno === constants.EEXIST) {
if (!err || err.code === 'EEXIST' || err.errno === constants.EEXIST) {
// Success!

@@ -42,3 +42,3 @@ return cb();

fs.writeFile(fileName, contents, encoding, function (err) {
if (err && err.errno === constants.ENOENT) {
if (err && (err.code === 'ENOENT' || err.errno === constants.ENOENT)) {
fsTools.mkpath(Path.dirname(fileName), passError(cb, function () {

@@ -45,0 +45,0 @@ fs.writeFile(fileName, contents, encoding, cb);

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

"repository": "git://github.com/One-com/assetgraph.git",
"version": "0.3.18",
"version": "0.3.19",
"maintainers": [

@@ -18,13 +18,14 @@ {

"cssmin": "= 0.3.0",
"cssom-papandreou": "= 0.2.0-patch1",
"glob": "= 2.1.0",
"cssom-papandreou": "= 0.2.1-patch1",
"glob": ">= 2.0.9",
"graphviz": "= 0.0.3",
"iconv": "= 1.1.2",
"jsdom": "= 0.2.9",
"jsdom": "= 0.2.10",
"less": "= 1.1.5",
"optimist": "= 0.2.6",
"request": "= 2.1.1",
"request": "= 2.2.5",
"seq": "= 0.3.5",
"stylus": "= 0.19.3",
"temp": "= 0.2.0",
"uglify-js": "= 1.1.0",
"uglify-js": "= 1.1.1",
"underscore": "= 1.2.0",

@@ -34,6 +35,6 @@ "yui-compressor": "= 0.1.3"

"devDependencies": {
"vows": ">=0.5.6"
"vows": ">= 0.6.0"
},
"engines": {
"node": ">=0.4.8"
"node": ">= 0.4.8"
},

@@ -40,0 +41,0 @@ "directories": {

@@ -25,3 +25,3 @@ var vows = require('vows'),

},
'the graph should contain one Css assets': function (assetGraph) {
'the graph should contain one Css asset': function (assetGraph) {
assert.equal(assetGraph.findAssets({type: 'Css'}).length, 1);

@@ -28,0 +28,0 @@ },

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