broccoli-es6-module-transpiler
Advanced tools
Comparing version 0.2.3 to 0.3.0
86
index.js
'use strict'; | ||
var fs = require('fs'), | ||
path = require('path'), | ||
util = require('util'), | ||
mkdirp = require('mkdirp'), | ||
quickTemp = require('quick-temp'), | ||
walkSync = require('walk-sync'), | ||
helpers = require('broccoli-kitchen-sink-helpers'), | ||
Writer = require('broccoli-writer'); | ||
var fs = require('fs'), | ||
path = require('path'), | ||
util = require('util'), | ||
mkdirp = require('mkdirp'), | ||
quickTemp = require('quick-temp'), | ||
symlinkOrCopy = require('symlink-or-copy'), | ||
walkSync = require('walk-sync'), | ||
helpers = require('broccoli-kitchen-sink-helpers'), | ||
Writer = require('broccoli-writer'); | ||
@@ -19,2 +20,7 @@ var transpiler = require('es6-module-transpiler'), | ||
// ----------------------------------------------------------------------------- | ||
var hashFile = helpers.hashTree; | ||
var hashStrings = helpers.hashStrings; | ||
// -- CompileModules ----------------------------------------------------------- | ||
@@ -72,16 +78,12 @@ | ||
function hash(filePaths) { | ||
Array.isArray(filePaths) || (filePaths = [filePaths]); | ||
if (Array.isArray(filePaths)) { | ||
return hashStrings(filePaths.map(function (filePath) { | ||
return hashFile(path.join(srcDir, filePath)); | ||
})); | ||
} | ||
return filePaths.map(function (filePath) { | ||
return hashFile(path.join(srcDir, filePath)); | ||
}).join(','); | ||
return hashFile(path.join(srcDir, filePaths)); | ||
} | ||
walkSync(srcDir).forEach(function (relPath) { | ||
// Keep track of all the JavaScript modules. | ||
if (path.extname(relPath) === '.js') { | ||
modules.push(relPath); | ||
return; | ||
} | ||
// Skip doing anything with dir entries. When outputting a bundle | ||
@@ -94,2 +96,10 @@ // format some dirs may go away. For non-JavaScript files, their | ||
// Keep track of all the JavaScript modules. | ||
// path.extname does not take into account the trailing '/' when | ||
// checking for the file's extension. | ||
if (path.extname(relPath) === '.js') { | ||
modules.push(relPath); | ||
return; | ||
} | ||
var srcPath = path.join(srcDir, relPath), | ||
@@ -99,7 +109,4 @@ destPath = path.join(destDir, relPath); | ||
// Copy over non-JavaScript files to the `destDir`. | ||
// | ||
// TODO: switch to `symlinkOrCopySync()` after: | ||
// https://github.com/broccolijs/broccoli/issues/179 | ||
mkdirp.sync(path.dirname(destPath)); | ||
helpers.copyPreserveSync(srcPath, destPath); | ||
symlinkOrCopy.sync(srcPath, destPath); | ||
}); | ||
@@ -129,4 +136,4 @@ | ||
// file, so we have to visit all the modules. The CacheResolver | ||
// will make sure we don't have to read-and-parse the modules | ||
// that are unchanged. | ||
// will make sure we don't have to re-read the modules that are | ||
// unchanged. | ||
modulesToCompile = modules; | ||
@@ -186,3 +193,3 @@ } | ||
var outputHash = [], | ||
var outputHashes = [], | ||
cacheEntry, outputFile; | ||
@@ -206,3 +213,3 @@ | ||
if (outputIsFile) { | ||
outputHash.push(hash); | ||
outputHashes.push(hash); | ||
return; | ||
@@ -228,5 +235,6 @@ } | ||
// Create a cache entry for the entire bundle output file and copy it | ||
// from the cache to the `outputPath`. | ||
// from the cache to the `outputPath`. Compute the hash as a hash of | ||
// hashes. | ||
cacheEntry = cache[outputFile] = { | ||
hash: outputHash.join(','), | ||
hash: hashStrings(outputHashes), | ||
dir : cacheDir, | ||
@@ -251,6 +259,4 @@ | ||
// TODO: switch to `symlinkOrCopySync()` after: | ||
// https://github.com/broccolijs/broccoli/issues/179 | ||
mkdirp.sync(path.dirname(destPath)); | ||
helpers.copyPreserveSync(cachePath, destPath); | ||
symlinkOrCopy.sync(cachePath, destPath); | ||
}); | ||
@@ -330,19 +336,1 @@ }; | ||
util.inherits(CachedModule, Module); | ||
// -- Utilities ---------------------------------------------------------------- | ||
var hashFile = helpers.hashTree; | ||
// TODO: Determine if this impl is needed after: | ||
// https://github.com/broccolijs/broccoli/issues/179 | ||
// | ||
// Wrapper around `hashTree()` to dereference symbolic links within the Broccoli | ||
// build chain, so when new symlinks are created they won't be considered as | ||
// changed files, unless the real file they are pointing to hashes differently. | ||
// function hashFile(path) { | ||
// if (fs.lstatSync(path).isSymbolicLink()) { | ||
// path = fs.realpathSync(path); | ||
// } | ||
// | ||
// return helpers.hashTree(path); | ||
// } |
{ | ||
"name": "broccoli-es6-module-transpiler", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Broccoli plugin for Square's ES6 Module Transpiler", | ||
@@ -30,3 +30,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"broccoli-kitchen-sink-helpers": "^0.2.4", | ||
"broccoli-kitchen-sink-helpers": "^0.2.5", | ||
"broccoli-writer": "^0.1.1", | ||
@@ -36,6 +36,7 @@ "es6-module-transpiler": "^0.6.2", | ||
"quick-temp": "^0.1.2", | ||
"walk-sync": "^0.1.2" | ||
"symlink-or-copy": "^1.0.0", | ||
"walk-sync": "^0.1.3" | ||
}, | ||
"devDependencies": { | ||
"broccoli": "^0.12.3", | ||
"broccoli": "^0.13.1", | ||
"expect.js": "^0.3.1", | ||
@@ -42,0 +43,0 @@ "mocha": "^1.20.1" |
@@ -43,2 +43,15 @@ var fs = require('fs'); | ||
}); | ||
describe('transpiling directory ending with .js', function() { | ||
it('should transpile to CommonJS', function() { | ||
var testName = 'dir_with_extension'; | ||
var tree = transpile(getSourcePath(testName), { formatter: 'commonjs' }); | ||
builder = new broccoli.Builder(tree); | ||
return builder.build().then(function(node) { | ||
expect(readTranspiled(node.directory, 'index.js')).to.be(readExpected(testName, 'index.js')); | ||
expect(readTranspiled(node.directory, 'accounting.js/accounting.js')).to.be(readExpected(testName, 'accounting.js/accounting.js')); | ||
}); | ||
}); | ||
}); | ||
}); |
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
18962
15
339
7
+ Addedsymlink-or-copy@^1.0.0
+ Addedsymlink-or-copy@1.3.1(transitive)
Updatedwalk-sync@^0.1.3