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

@vkontakte/graph-cache-js

Package Overview
Dependencies
Maintainers
5
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vkontakte/graph-cache-js - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

tests/fixtures/test_require.js

61

lib/parser.js

@@ -129,28 +129,49 @@ const Graph = require('graphlib').Graph;

function _addEdge(resolveName, g, filePath, edgePath) {
return resolveName(filePath, edgePath).then(async (newName) => {
const exist = await fileExist(newName);
if (!exist) {
const parsed = path.parse(newName);
newName = parsed.dir + path.sep + parsed.name + path.sep + 'index.js';
}
// we already handled this file as dep
if (g.hasEdge(newName, filePath)) {
return false;
}
if (!g.hasEdge(filePath, newName)) {
g.setEdge(newName, filePath);
return newName;
}
// this is a cyclic dep
g.setEdge(newName, filePath);
return false;
})
}
function buildTree(resolveName, ast, g, filePath) {
const state = [];
const addEdge = _addEdge.bind(null, resolveName, g)
walk.simple(ast, {
ImportDeclaration(node, state) {
state.push(resolveName(filePath, node.source.value).then(async (newName) => {
const exist = await fileExist(newName);
state.push(addEdge(filePath, node.source.value));
},
ExpressionStatement(node, state) {
const { expression } = node;
if (!exist) {
const parsed = path.parse(newName);
newName = parsed.dir + path.sep + parsed.name + path.sep + 'index.js';
}
if (node.expression.callee.name === 'require') {
state.push(addEdge(filePath, expression.arguments[0].value));
}
},
VariableDeclaration(node, state) {
const expression = node.declarations[0].init;
// we already handled this file as dep
if (g.hasEdge(newName, filePath)) {
return false;
}
if (!g.hasEdge(filePath, newName)) {
g.setEdge(newName, filePath);
return newName;
}
// this is a cyclic dep
g.setEdge(newName, filePath);
return false;
}));
if (expression.callee && expression.callee.name === 'require') {
state.push(addEdge(filePath, expression.arguments[0].value));
}
}

@@ -157,0 +178,0 @@ }, state);

{
"name": "@vkontakte/graph-cache-js",
"version": "2.0.0",
"version": "2.0.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -192,3 +192,21 @@ /* eslint-env mocha */

});
it('supports require statement', () => {
return createGraphFromFile(createPath('test_require'), s, {})
.then((g) => verifyGraph(g, [
'test_require', 'test2'
], [
{ v: 'test2', w: 'test_require' }
]));
});
it('supports require statement with declaration', () => {
return createGraphFromFile(createPath('test_require2'), s, {})
.then((g) => verifyGraph(g, [
'test_require2', 'test2'
], [
{ v: 'test2', w: 'test_require2' }
]));
});
});
});
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