broccoli-module-normalizer
Advanced tools
Comparing version 1.2.0 to 1.3.0
77
index.js
@@ -7,4 +7,4 @@ 'use strict'; | ||
const symlinkOrCopy = require('symlink-or-copy'); | ||
const walkSync = require('walk-sync'); | ||
const rimraf = require('rimraf'); | ||
const MergeTrees = require('merge-trees'); | ||
@@ -24,3 +24,3 @@ module.exports = class ModuleNormalizer extends Plugin { | ||
build() { | ||
if (this._hasRan && symlinkOrCopy.canSymlink) { | ||
if (this._noChange && symlinkOrCopy.canSymlink) { | ||
return; | ||
@@ -31,13 +31,18 @@ } | ||
let outputPath = this.outputPath; | ||
let inputModulesPath = path.join(inputPath, 'modules'); | ||
let outputModulesPath = path.join(outputPath, 'modules'); | ||
let modulesPath = path.join(inputPath, 'modules'); | ||
let modules; | ||
if (fs.existsSync(modulesPath)) { | ||
modules = fs.readdirSync(modulesPath); | ||
if (!fs.existsSync(inputModulesPath)) { | ||
if (this._hasRan) { | ||
fs.unlinkSync(outputPath); | ||
} else { | ||
fs.rmdirSync(outputPath); | ||
} | ||
if (this.options.callback) { | ||
this.options.callback(); | ||
} | ||
} else { | ||
modules = []; | ||
symlinkOrCopy.sync(inputPath, outputPath); | ||
this._noChange = true; | ||
this._hasRan = true; | ||
return; | ||
} | ||
@@ -50,41 +55,19 @@ | ||
let dirs = fs.readdirSync(inputPath).filter(dir => dir !== 'modules'); | ||
let intersection = dirs.filter(dir => modules.indexOf(dir) !== -1); | ||
let modulesOnly = modules.filter(dir => dirs.indexOf(dir) === -1); | ||
let nonModules = dirs.filter(dir => modules.indexOf(dir) === -1); | ||
for (let dir of intersection) { | ||
let files = [[dir, dir]] | ||
.concat(walkSync(path.join(modulesPath, dir)).map(file => [path.join('modules', dir, file), path.join(dir, file)])) | ||
.concat(walkSync(path.join(inputPath, dir)).map(file => [path.join(dir, file), path.join(dir, file)])); | ||
let visited = new Set(); | ||
for (let pair of files) { | ||
if (visited.has(pair[1])) { | ||
continue; | ||
} | ||
let inputFilePath = path.join(inputPath, pair[0]); | ||
let outputFilePath = path.join(outputPath, pair[1]); | ||
if (fs.statSync(inputFilePath).isDirectory()) { | ||
fs.mkdirSync(outputFilePath); | ||
} else { | ||
symlinkOrCopy.sync(inputFilePath, outputFilePath); | ||
} | ||
visited.add(pair[1]); | ||
let mergeTrees = new MergeTrees( | ||
[ | ||
inputPath, | ||
inputModulesPath | ||
], | ||
this.outputPath, | ||
{ | ||
overwrite: true, | ||
annotation: this.options.annotation | ||
} | ||
} | ||
); | ||
mergeTrees.merge(); | ||
let files = modulesOnly.map(file => [path.join('modules', file), file]) | ||
.concat(nonModules.map(file => [file, file])); | ||
rimraf.sync(outputModulesPath); | ||
for (let pair of files) { | ||
let inputDirPath = path.join(inputPath, pair[0]); | ||
let outputDirPath = path.join(outputPath, pair[1]); | ||
symlinkOrCopy.sync(inputDirPath, outputDirPath); | ||
if (this.options.callback) { | ||
this.options.callback(); | ||
} | ||
@@ -91,0 +74,0 @@ |
{ | ||
"name": "broccoli-module-normalizer", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Broccoli plugin to remove `modules/` subdirectory from legacy ember-cli addons.", | ||
@@ -11,3 +11,3 @@ "main": "index.js", | ||
"prelint": "eslint --version", | ||
"lint": "eslint index.js test/index.js" | ||
"lint": "eslint index.js test" | ||
}, | ||
@@ -21,8 +21,11 @@ "contributors": [ | ||
"license": "MIT", | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"files": [], | ||
"dependencies": { | ||
"broccoli-plugin": "^1.3.0", | ||
"merge-trees": "^1.0.1", | ||
"rimraf": "^2.6.2", | ||
"symlink-or-copy": "^1.1.8", | ||
"walk-sync": "^0.3.2" | ||
"symlink-or-copy": "^1.1.8" | ||
}, | ||
@@ -36,2 +39,3 @@ "devDependencies": { | ||
"eslint-plugin-mocha": "^4.11.0", | ||
"eslint-plugin-node": "^6.0.0", | ||
"eslint-plugin-prefer-let": "^1.0.1", | ||
@@ -38,0 +42,0 @@ "mocha": "^5.0.0", |
4572
10
58
+ Addedmerge-trees@^1.0.1
+ Addedcan-symlink@1.0.0(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedfs-tree-diff@0.5.9(transitive)
+ Addedheimdalljs@0.2.6(transitive)
+ Addedheimdalljs-logger@0.1.10(transitive)
+ Addedmerge-trees@1.0.1(transitive)
+ Addedms@2.0.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedpath-posix@1.0.0(transitive)
+ Addedrsvp@3.2.1(transitive)
+ Addedtmp@0.0.28(transitive)
- Removedwalk-sync@^0.3.2
- Removedensure-posix-path@1.1.1(transitive)
- Removedmatcher-collection@1.1.2(transitive)
- Removedrsvp@3.6.2(transitive)
- Removedwalk-sync@0.3.4(transitive)