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

babel-deps

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-deps - npm Package Compare versions

Comparing version 2.0.0-babel5 to 2.0.0

99

index.js

@@ -8,26 +8,22 @@ 'use strict';

var cache = {};
var filesToCompile = [];
var hasFile = {};
function compileFiles(files, opt_options) {
hasFile = {};
for (var i = 0; i < files.length; i++) {
assertFilenameOption(files[i]);
hasFile[files[i].options.filename] = true;
}
function addDependencies(result, resolveModuleToPath) {
var imports = result.babel.metadata.modules.imports;
imports.forEach(function(importData) {
addDependency(importData.source, result.path, resolveModuleToPath);
});
}
var options = opt_options || {};
var results = [];
filesToCompile = files.concat();
for (var j = 0; j < filesToCompile.length; j++) {
var file = filesToCompile[j];
var currOptions = merge({}, options);
currOptions.babel = merge({}, currOptions.babel, file.options);
results.push({
babel: babel.transform(file.contents, currOptions.babel),
path: file.options.filename
function addDependency(source, filename, resolveModuleToPath) {
resolveModuleToPath = resolveModuleToPath || getFullPath;
var fullPath = resolveModuleToPath(source, filename);
if (!hasFile[fullPath]) {
filesToCompile.push({
options: {filename: fullPath}
});
fetchDependencies(results[j], options.resolveModuleToPath);
hasFile[fullPath] = true;
}
return results;
}

@@ -41,23 +37,28 @@

function fetchDependencies(result, resolveModuleToPath) {
var imports = result.babel.metadata.modules.imports;
imports.forEach(function(importData) {
fetchDependency(importData.source, result.path, resolveModuleToPath);
});
function clearCache() {
cache = {};
}
function fetchDependency(source, filename, resolveModuleToPath) {
resolveModuleToPath = resolveModuleToPath || getFullPath;
var fullPath = resolveModuleToPath(source, filename);
if (!hasFile[fullPath]) {
if (fs.existsSync(fullPath)) {
filesToCompile.push({
contents: fs.readFileSync(fullPath, 'utf8'),
options: {filename: fullPath}
function compileFiles(files, opt_options) {
hasFile = {};
for (var i = 0; i < files.length; i++) {
assertFilenameOption(files[i]);
hasFile[files[i].options.filename] = true;
}
var options = opt_options || {};
var results = [];
filesToCompile = files.concat();
for (var j = 0; j < filesToCompile.length; j++) {
var file = filesToCompile[j];
var transformed = transform(file, options);
if (transformed) {
results.push({
babel: transformed,
path: file.options.filename
});
} else {
console.warn('Could not find ' + fullPath);
addDependencies(results[results.length - 1], options.resolveModuleToPath);
}
hasFile[fullPath] = true;
}
return results;
}

@@ -76,3 +77,33 @@

function transform(file, options) {
var filePath = file.options.filename;
var cached = cache[filePath];
if (options.cache && cached && (!file.contents || cached.contents === file.contents)) {
// We have the file on cache and its contents didn't change.
return options.skipCachedFiles ? null : cached.babel;
}
if (!file.contents) {
if (fs.existsSync(filePath)) {
file.contents = fs.readFileSync(filePath, 'utf8');
} else {
console.warn('Could not find ' + filePath);
return null;
}
}
var currOptions = merge({}, options.babel, file.options);
var result = babel.transform(file.contents, currOptions);
if (options.cache) {
cache[filePath] = {
babel: result,
contents: file.contents
};
}
return result;
}
module.exports = compileFiles;
module.exports.getFullPath = getFullPath;
module.exports.clearCache = clearCache;
{
"name": "babel-deps",
"version": "2.0.0-babel5",
"version": "2.0.0",
"description": "Compiles javascript files and all their dependencies with babel.",

@@ -30,3 +30,3 @@ "license": "MIT",

"dependencies": {
"babel-core": "^5.4.2",
"babel-core": "^6.3.0",
"merge": "^1.2.0"

@@ -33,0 +33,0 @@ },

@@ -37,2 +37,4 @@ babel-deps

- `babel` **(Object)** An object with babel options that should be used for all files. File specific options will be merged with this before the file is compiled, so they have higher priority.
- `cache` **(boolean)** A flag indicating if the compiled results for dependencies should be cached in memory and reused on later calls. This is useful when the contents of dependency files aren't expected to change, speeding up the results.
- `resolveModuleToPath` **(function(string, string))** Function that should be called to convert a dependency module source to its path, so it can be fetched. If this is not given, a default function will assume that the module sources already are valid paths.
- `skipCachedFiles` **{boolean}** A flag indicating if files that cause a cache hit should be skipped when returning the results. Only used when `cache` is set to true.
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