babel-deps
Advanced tools
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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6549
92
1
40
+ Addedbabel-code-frame@6.26.0(transitive)
+ Addedbabel-core@6.26.3(transitive)
+ Addedbabel-generator@6.26.1(transitive)
+ Addedbabel-helpers@6.24.1(transitive)
+ Addedbabel-messages@6.23.0(transitive)
+ Addedbabel-register@6.26.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedbabel-template@6.26.0(transitive)
+ Addedbabel-traverse@6.26.0(transitive)
+ Addedbabel-types@6.26.0(transitive)
+ Addedbabylon@6.18.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddetect-indent@4.0.0(transitive)
+ Addedglobals@9.18.0(transitive)
+ Addedhome-or-tmp@2.0.0(transitive)
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@3.0.2(transitive)
+ Addedjsesc@1.3.0(transitive)
+ Addedjson5@0.5.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedos-homedir@1.0.2(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
+ Addedrepeating@2.0.1(transitive)
+ Addedsource-map-support@0.4.18(transitive)
- Removedacorn@5.7.4(transitive)
- Removedalign-text@0.1.4(transitive)
- Removedalter@0.2.0(transitive)
- Removedamdefine@1.0.1(transitive)
- Removedast-traverse@0.1.1(transitive)
- Removedast-types@0.8.120.9.6(transitive)
- Removedbabel-core@5.8.38(transitive)
- Removedbabel-plugin-constant-folding@1.0.1(transitive)
- Removedbabel-plugin-dead-code-elimination@1.0.2(transitive)
- Removedbabel-plugin-eval@1.0.1(transitive)
- Removedbabel-plugin-inline-environment-variables@1.0.1(transitive)
- Removedbabel-plugin-jscript@1.0.4(transitive)
- Removedbabel-plugin-member-expression-literals@1.0.1(transitive)
- Removedbabel-plugin-property-literals@1.0.1(transitive)
- Removedbabel-plugin-proto-to-assign@1.0.4(transitive)
- Removedbabel-plugin-react-constant-elements@1.0.3(transitive)
- Removedbabel-plugin-react-display-name@1.0.3(transitive)
- Removedbabel-plugin-remove-console@1.0.1(transitive)
- Removedbabel-plugin-remove-debugger@1.0.1(transitive)
- Removedbabel-plugin-runtime@1.0.7(transitive)
- Removedbabel-plugin-undeclared-variables-check@1.0.2(transitive)
- Removedbabel-plugin-undefined-to-void@1.1.6(transitive)
- Removedbabylon@5.8.38(transitive)
- Removedbluebird@2.11.0(transitive)
- Removedbreakable@1.0.0(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedcliui@2.1.0(transitive)
- Removedcommander@2.20.3(transitive)
- Removedcommoner@0.10.8(transitive)
- Removedcore-js@1.2.7(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddefined@1.0.1(transitive)
- Removeddefs@1.1.1(transitive)
- Removeddetect-indent@3.0.1(transitive)
- Removeddetective@4.7.1(transitive)
- Removedesprima@2.7.33.1.3(transitive)
- Removedesprima-fb@15001.1001.0-dev-harmony-fb(transitive)
- Removedfs-readdir-recursive@0.1.2(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-stdin@4.0.1(transitive)
- Removedglob@5.0.15(transitive)
- Removedglobals@6.4.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhome-or-tmp@1.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-core-module@2.16.0(transitive)
- Removedis-integer@1.0.7(transitive)
- Removedjs-tokens@1.0.1(transitive)
- Removedjsesc@0.5.0(transitive)
- Removedjson5@0.4.0(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlcid@1.0.0(transitive)
- Removedleven@1.0.2(transitive)
- Removedlodash@3.10.1(transitive)
- Removedlongest@1.0.1(transitive)
- Removedminimatch@2.0.10(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedoutput-file-sync@1.1.2(transitive)
- Removedpath-exists@1.0.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedq@1.5.1(transitive)
- Removedrecast@0.10.330.11.23(transitive)
- Removedregenerate@1.4.2(transitive)
- Removedregenerator@0.8.40(transitive)
- Removedregexpu@1.3.0(transitive)
- Removedregjsgen@0.2.0(transitive)
- Removedregjsparser@0.1.5(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedrepeating@1.1.3(transitive)
- Removedresolve@1.22.10(transitive)
- Removedright-align@0.1.3(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedshebang-regex@1.0.0(transitive)
- Removedsimple-fmt@0.1.0(transitive)
- Removedsimple-is@0.2.0(transitive)
- Removedsource-map@0.1.32(transitive)
- Removedsource-map-support@0.2.10(transitive)
- Removedstable@0.1.8(transitive)
- Removedstringmap@0.2.2(transitive)
- Removedstringset@0.2.1(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedthrough@2.3.8(transitive)
- Removedtry-resolve@1.0.1(transitive)
- Removedtryor@0.1.2(transitive)
- Removeduser-home@1.1.1(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwordwrap@0.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyargs@3.27.0(transitive)
Updatedbabel-core@^6.3.0