Socket
Socket
Sign inDemoInstall

@hh.ru/babel-plugin-static-value-extractor

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hh.ru/babel-plugin-static-value-extractor - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

127

lib/index.js

@@ -67,5 +67,24 @@ "use strict";

var traceToPageComponent = function traceToPageComponent(file) {
var parents = [file];
var nextParents = [];
var pageComponents = [];
while (parents.length > 0) {
parents.forEach(function (file) {
var _nextParents;
var reverseImports = cachedFiles[file].reverseImports;
reverseImports === null ? pageComponents.push(file) : (_nextParents = nextParents).push.apply(_nextParents, _toConsumableArray(reverseImports));
});
parents = _toConsumableArray(new Set(nextParents));
nextParents = [];
}
return pageComponents;
};
var prepareCache = function prepareCache(opts) {
var basePath = opts.basePath;
var invalidFiles = [];
var invalidFiles = new Set();
Object.keys(cachedFiles).forEach(function (filePath) {

@@ -77,9 +96,22 @@ var cachedMtime = cachedFiles[filePath].cachedMtime;

if (!_fs["default"].existsSync(fullPath) || cachedMtime !== _fs["default"].statSync(fullPath).mtimeMs) {
invalidFiles.push.apply(invalidFiles, [filePath].concat(_toConsumableArray(cachedFiles[filePath].reverseImports)));
invalidFiles.add(filePath);
}
});
var uniqueFiles = new Set(invalidFiles);
uniqueFiles.forEach(function (filePath) {
delete cachedFiles[filePath];
var invalidPageComponents = [];
invalidFiles.forEach(function (filePath) {
cachedFiles[filePath].importsDeclarations.forEach(function (file) {
if (cachedFiles[file]) {
cachedFiles[file].reverseImports = cachedFiles[file].reverseImports.filter(function (file) {
return file !== filePath;
});
}
});
invalidPageComponents.push.apply(invalidPageComponents, _toConsumableArray(traceToPageComponent(filePath)));
});
invalidFiles.forEach(function (filePath) {
return delete cachedFiles[filePath];
});
new Set(invalidPageComponents).forEach(function (filePath) {
return delete cachedFiles[filePath];
});
(0, _persistentCache.savePersistentCache)(cachedFiles);

@@ -90,8 +122,2 @@ };

var removeDuplicates = function removeDuplicates(key) {
Object.keys(cachedFiles).forEach(function (file) {
cachedFiles[file][key] = _toConsumableArray(new Set(cachedFiles[file][key]));
});
};
var extractStaticValueFromFile = function extractStaticValueFromFile(file) {

@@ -117,10 +143,6 @@ var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

var extractStaticValueImportedFilesFromFile = function extractStaticValueImportedFilesFromFile(file) {
var extractStaticValueImportedFilesFromFile = function extractStaticValueImportedFilesFromFile(topLevelFile) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var cb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : noop;
var importPaths = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
var propNames = Object.keys(opts.propsToExtract);
var relativePath = _path["default"].relative(opts.basePath, file);
var staticPropsList = propNames.reduce(function (agg, name) {

@@ -130,35 +152,25 @@ return _objectSpread({}, agg, _defineProperty({}, name, []));

var _fs$statSync = _fs["default"].statSync(file),
mtimeMs = _fs$statSync.mtimeMs;
function _extractStaticValueImportedFilesFromFile(file, opts) {
var parentFile = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
function _extractStaticValueImportedFilesFromFile(file, opts, importPaths) {
if (opts.include && !opts.include.find(function (includePath) {
return file.search(includePath) !== -1;
})) {
return;
}
if (cachedFiles[file]) {
mergeProps(propNames, staticPropsList, cachedFiles[file].propsList);
cachedFiles[file].reverseImports && cachedFiles[file].reverseImports.push(parentFile);
} else {
if (opts.include && !opts.include.find(function (includePath) {
return file.search(includePath) !== -1;
})) {
return;
}
var _fs$statSync2 = _fs["default"].statSync(file),
mtimeMs = _fs$statSync2.mtimeMs;
var _fs$statSync = _fs["default"].statSync(file),
mtimeMs = _fs$statSync.mtimeMs;
var relativePath = _path["default"].relative(opts.basePath, file);
var importsDeclarations = [];
if (cachedFiles[relativePath]) {
var _cachedFiles$relative;
mergeProps(propNames, staticPropsList, cachedFiles[relativePath].propsList);
importsDeclarations = cachedFiles[relativePath].importsDeclarations;
(_cachedFiles$relative = cachedFiles[relativePath].reverseImports).push.apply(_cachedFiles$relative, _toConsumableArray(importPaths));
} else {
extractStaticValueFromFile(file, opts, function (_staticPropsList, _importsDeclarations) {
extractStaticValueFromFile(file, opts, function (_staticPropsList, importsDeclarations) {
mergeProps(propNames, staticPropsList, _staticPropsList);
importsDeclarations = _importsDeclarations;
cachedFiles[relativePath] = {
cachedFiles[file] = {
cachedMtime: mtimeMs,
propsList: _staticPropsList,
importsDeclarations: importsDeclarations,
reverseImports: importPaths
reverseImports: [parentFile]
};

@@ -168,21 +180,18 @@ });

importsDeclarations.forEach(function (file) {
_extractStaticValueImportedFilesFromFile(file, opts, [].concat(_toConsumableArray(importPaths), [relativePath]));
cachedFiles[file].importsDeclarations.forEach(function (f) {
return _extractStaticValueImportedFilesFromFile(f, opts, file);
});
}
if (cachedFiles[relativePath]) {
var _cachedFiles$relative2;
if (!cachedFiles[topLevelFile]) {
var _fs$statSync2 = _fs["default"].statSync(topLevelFile),
mtimeMs = _fs$statSync2.mtimeMs;
staticPropsList = cachedFiles[relativePath].propsList;
_extractStaticValueImportedFilesFromFile(topLevelFile, opts);
(_cachedFiles$relative2 = cachedFiles[relativePath].reverseImports).push.apply(_cachedFiles$relative2, _toConsumableArray(importPaths));
} else {
_extractStaticValueImportedFilesFromFile(file, opts, [].concat(_toConsumableArray(importPaths), [relativePath]));
cachedFiles[relativePath] = {
cachedFiles[topLevelFile] = {
cachedMtime: mtimeMs,
propsList: staticPropsList,
importsDeclarations: [],
reverseImports: importPaths
reverseImports: null
};

@@ -192,6 +201,6 @@ }

propNames.forEach(function (name) {
cachedFiles[relativePath].propsList[name] = _toConsumableArray(new Set(cachedFiles[relativePath].propsList[name]));
cachedFiles[topLevelFile].propsList[name] = _toConsumableArray(new Set(cachedFiles[topLevelFile].propsList[name]));
});
cb(cachedFiles[relativePath].propsList);
return cachedFiles[relativePath].propsList;
cb(cachedFiles[topLevelFile].propsList);
return cachedFiles[topLevelFile].propsList;
};

@@ -211,3 +220,3 @@

var staticValues = _globAll["default"].sync(globArr).reduce(function (globObject, file) {
var staticValues = extractStaticValueImportedFilesFromFile(file, opts);
var staticValues = extractStaticValueImportedFilesFromFile(_path["default"].relative(opts.basePath, file), opts);

@@ -242,3 +251,5 @@ var dir = _path["default"].parse(file).dir;

});
removeDuplicates('reverseImports');
Object.keys(cachedFiles).forEach(function (file) {
return cachedFiles[file].reverseImports = cachedFiles[file].reverseImports === null ? null : _toConsumableArray(new Set(cachedFiles[file].reverseImports));
});
(0, _persistentCache.savePersistentCache)(cachedFiles);

@@ -245,0 +256,0 @@ };

@@ -26,3 +26,3 @@ "use strict";

return _path["default"].join(cacheDir, 'files.json');
return _path["default"].join(cacheDir, 'files_v2.json');
};

@@ -29,0 +29,0 @@

{
"name": "@hh.ru/babel-plugin-static-value-extractor",
"version": "1.1.0",
"version": "1.1.1",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "devDependencies": {

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