From 3271541e3301f192a31b0e9bff61550f47a2a371 Mon Sep 17 00:00:00 2001 From: Ivo Gabe de Wolff Date: Tue, 9 Feb 2016 22:42:30 +0100 Subject: [PATCH] Update LKG --- release/input.js | 26 ++++---------------------- release/output.js | 2 ++ release/project.js | 38 +++++++++++++++++++++++++++++--------- release/utils.js | 21 +++++++++++++++++++++ 4 files changed, 56 insertions(+), 31 deletions(-) diff --git a/release/input.js b/release/input.js index c0cdea5f..2fdab30b 100644 --- a/release/input.js +++ b/release/input.js @@ -57,20 +57,6 @@ var File; } File.getChangeState = getChangeState; })(File = exports.File || (exports.File = {})); -/** - * Finds the common base path of two directories - */ -function getCommonBasePath(a, b) { - var aSplit = a.split(/\\|\//); // Split on '/' or '\'. - var bSplit = b.split(/\\|\//); - var commonLength = 0; - for (var i = 0; i < aSplit.length && i < bSplit.length; i++) { - if (aSplit[i] !== bSplit[i]) - break; - commonLength += aSplit[i].length + 1; - } - return a.substr(0, commonLength); -} var FileDictionary = (function () { function FileDictionary(typescript) { this.files = {}; @@ -123,12 +109,10 @@ var FileDictionary = (function () { get: function () { var _this = this; var fileNames = this.getSourceFileNames(true); - return fileNames - .map(function (fileName) { + return utils.getCommonBasePathOfArray(fileNames.map(function (fileName) { var file = _this.files[utils.normalizePath(fileName)]; return path.resolve(process.cwd(), file.gulp.base); - }) - .reduce(getCommonBasePath); + })); }, enumerable: true, configurable: true @@ -137,12 +121,10 @@ var FileDictionary = (function () { get: function () { var _this = this; var fileNames = this.getSourceFileNames(); - return fileNames - .map(function (fileName) { + return utils.getCommonBasePathOfArray(fileNames.map(function (fileName) { var file = _this.files[utils.normalizePath(fileName)]; return path.dirname(file.fileNameNormalized); - }) - .reduce(getCommonBasePath); + })); }, enumerable: true, configurable: true diff --git a/release/output.js b/release/output.js index b8fe1f92..5f3f7b37 100644 --- a/release/output.js +++ b/release/output.js @@ -201,6 +201,8 @@ var Output = (function () { this.results = results; if (this.project.reporter.finish) this.project.reporter.finish(results); + this.streamJs.emit('finish'); + this.streamDts.emit('finish'); this.streamJs.push(null); this.streamDts.push(null); }; diff --git a/release/project.js b/release/project.js index c1198497..4c59a86c 100644 --- a/release/project.js +++ b/release/project.js @@ -1,4 +1,5 @@ /// +var stream = require('stream'); var ts = require('typescript'); var vfs = require('vinyl-fs'); var path = require('path'); @@ -35,23 +36,42 @@ var Project = (function () { if (this.config.compilerOptions && this.config.compilerOptions.rootDir) { base = path.resolve(configPath, this.config.compilerOptions.rootDir); } - else { - base = configPath; - } if (!this.config.files) { - var files = [path.join(base, '**/*.ts')]; + var files_1 = [path.join(configPath, '**/*.ts')]; if (tsApi.isTS16OrNewer(this.typescript)) { - files.push(path.join(base, '**/*.tsx')); + files_1.push(path.join(configPath, '**/*.tsx')); } if (this.config.exclude instanceof Array) { - files = files.concat( + files_1 = files_1.concat( // Exclude files - this.config.exclude.map(function (file) { return '!' + path.resolve(base, file); }), + this.config.exclude.map(function (file) { return '!' + path.resolve(configPath, file); }), // Exclude directories - this.config.exclude.map(function (file) { return '!' + path.resolve(base, file) + '/**/*'; })); + this.config.exclude.map(function (file) { return '!' + path.resolve(configPath, file) + '/**/*'; })); + } + if (base !== undefined) { + return vfs.src(files_1, { base: base }); } - return vfs.src(files); + var srcStream = vfs.src(files_1); + var sources = new stream.Readable({ objectMode: true }); + sources._read = function () { }; + var resolvedFiles_1 = []; + srcStream.on('data', function (file) { + resolvedFiles_1.push(file); + }); + srcStream.on('finish', function () { + var base = utils.getCommonBasePathOfArray(resolvedFiles_1.map(function (file) { return path.dirname(file.path); })); + for (var _i = 0; _i < resolvedFiles_1.length; _i++) { + var file = resolvedFiles_1[_i]; + file.base = base; + sources.push(file); + } + sources.emit('finish'); + }); + return srcStream; } + var files = this.config.files.map(function (file) { return path.resolve(configPath, file); }); + if (base === undefined) + base = utils.getCommonBasePathOfArray(files.map(function (file) { return path.dirname(file); })); var resolvedFiles = []; var checkMissingFiles = through2.obj(function (file, enc, callback) { this.push(file); diff --git a/release/utils.js b/release/utils.js index 6de3daeb..95eda2d8 100644 --- a/release/utils.js +++ b/release/utils.js @@ -25,3 +25,24 @@ function splitExtension(fileName, knownExtensions) { return [fileName.substr(0, index - 1), ext]; } exports.splitExtension = splitExtension; +/** + * Finds the common base path of two directories + */ +function getCommonBasePath(a, b) { + var aSplit = a.split(/\\|\//); // Split on '/' or '\'. + var bSplit = b.split(/\\|\//); + var commonLength = 0; + for (var i = 0; i < aSplit.length && i < bSplit.length; i++) { + if (aSplit[i] !== bSplit[i]) + break; + commonLength += aSplit[i].length + 1; + } + return a.substr(0, commonLength); +} +exports.getCommonBasePath = getCommonBasePath; +function getCommonBasePathOfArray(paths) { + if (paths.length === 0) + return ''; + return paths.reduce(getCommonBasePath); +} +exports.getCommonBasePathOfArray = getCommonBasePathOfArray;