diff --git a/@types/main.d.ts b/@types/main.d.ts index e3068f4..e643a60 100644 --- a/@types/main.d.ts +++ b/@types/main.d.ts @@ -19,11 +19,4 @@ export declare class GlobsUglifyJs { private uglifyItem(file); private buildOutFilePath(filePath); private uglifyFile(file, options?); - /** - * Asynchronously return files list by pattern. - * - * @param {string} pattern - * @param {glob.IOptions} [options={}] - */ - private getGlobFilesList(pattern, options?); } diff --git a/@types/utils/directories.d.ts b/@types/utils/directories.d.ts index 50f7235..4975c92 100644 --- a/@types/utils/directories.d.ts +++ b/@types/utils/directories.d.ts @@ -1,3 +1,2 @@ -export declare function Exists(path: string): Promise; export declare function RemoveEmptyDirectories(directoryPath: string): Promise; export declare function MakeTree(filePath: string): Promise; diff --git a/dist/main.js b/dist/main.js index 2318ac1..b0e9dac 100644 --- a/dist/main.js +++ b/dist/main.js @@ -8,10 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); const uglifyjs = require("uglify-js"); -const glob = require("glob"); +const globby = require("globby"); const path = require("path"); const options_1 = require("./options"); -const fs = require("mz/fs"); +const fs = require("fs-extra"); const rejection_error_1 = require("./rejection-error"); const Directories = require("./utils/directories"); const JS_EXTENSION = ".js"; @@ -49,7 +49,7 @@ class GlobsUglifyJs { } let filesList; try { - filesList = yield this.getGlobFilesList(this.globPattern, this.globOptions); + filesList = yield globby(this.globPattern, this.globOptions); } catch (error) { if (this.options.Debug && !this.options.Silence) { @@ -202,6 +202,9 @@ class GlobsUglifyJs { let outputData; try { outputData = yield this.uglifyFile(file, this.options.MinifyOptions); + if (outputData.error != null) { + throw outputData.error; + } } catch (error) { throw new rejection_error_1.RejectionError(error, "uglifyFile", file); @@ -238,35 +241,16 @@ class GlobsUglifyJs { } uglifyFile(file, options) { return __awaiter(this, void 0, void 0, function* () { - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { try { - let outputData = uglifyjs.minify(file, options); + const inputData = yield fs.readFile(file, "UTF-8"); + const outputData = uglifyjs.minify(inputData, options); resolve(outputData); } catch (error) { reject(error); } - }); - }); - } - /** - * Asynchronously return files list by pattern. - * - * @param {string} pattern - * @param {glob.IOptions} [options={}] - */ - getGlobFilesList(pattern, options = {}) { - return __awaiter(this, void 0, void 0, function* () { - return new Promise((resolve, reject) => { - glob(pattern, options, (err, matches) => { - if (err != null) { - reject(err); - } - else { - resolve(matches); - } - }); - }); + })); }); } } diff --git a/dist/utils/directories.js b/dist/utils/directories.js index 5d75645..c80023c 100644 --- a/dist/utils/directories.js +++ b/dist/utils/directories.js @@ -8,24 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); -const fs = require("mz/fs"); -const mkdirp = require("mkdirp"); -function Exists(path) { - return __awaiter(this, void 0, void 0, function* () { - try { - const stat = yield fs.stat(path); - return stat.isDirectory(); - } - catch (error) { - return false; - } - }); -} -exports.Exists = Exists; +const fs = require("fs-extra"); function RemoveEmptyDirectories(directoryPath) { return __awaiter(this, void 0, void 0, function* () { - const isExist = yield Exists(directoryPath); - if (!isExist) { + const stat = yield fs.stat(directoryPath); + if (!stat.isDirectory()) { return; } let files = yield fs.readdir(directoryPath); @@ -44,16 +31,9 @@ function RemoveEmptyDirectories(directoryPath) { exports.RemoveEmptyDirectories = RemoveEmptyDirectories; function MakeTree(filePath) { return __awaiter(this, void 0, void 0, function* () { - return new Promise((resolve, reject) => { - const dirname = path.dirname(filePath); - mkdirp(dirname, (error, data) => { - if (error) { - reject(error); - return; - } - resolve(data); - }); - }); + const dirname = path.dirname(filePath); + yield fs.ensureDir(dirname); + return dirname; }); } exports.MakeTree = MakeTree; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..27d6844 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,551 @@ +{ + "name": "glob-uglifyjs", + "version": "2.0.0-beta.4", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/fs-extra": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-4.0.3.tgz", + "integrity": "sha512-cUE7dc4RJsRPCk8mbrgMAaglugcJbf1Oxp7DYi/aOj4+ggCxzddDQFZwCKWnqrLv4LJ89apyNJ7Y3pN79tAPVg==", + "requires": { + "@types/node": "8.0.47" + } + }, + "@types/glob": { + "version": "5.0.33", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-5.0.33.tgz", + "integrity": "sha512-BcD4yyWz+qmCggaYMSFF0Xn7GkO6tgwm3Fh9Gxk/kQmEU3Z7flQTnVlMyKBUNvXXNTCCyjqK4XT4/2hLd1gQ2A==", + "requires": { + "@types/minimatch": "3.0.1", + "@types/node": "8.0.47" + } + }, + "@types/globby": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@types/globby/-/globby-6.1.0.tgz", + "integrity": "sha512-j3XSDNoK4LO5T+ZviQD6PqfEjm07QFEacOTbJR3hnLWuWX0ZMLJl9oRPgj1PyrfGbXhfHFkksC9QZ9HFltJyrw==", + "requires": { + "@types/glob": "5.0.33" + } + }, + "@types/minimatch": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.1.tgz", + "integrity": "sha512-rUO/jz10KRSyA9SHoCWQ8WX9BICyj5jZYu1/ucKEJKb4KzLZCKMURdYbadP157Q6Zl1x0vHsrU+Z/O0XlhYQDw==" + }, + "@types/node": { + "version": "8.0.47", + "resolved": "https://registry.npmjs.org/@types/node/-/node-8.0.47.tgz", + "integrity": "sha512-kOwL746WVvt/9Phf6/JgX/bsGQvbrK5iUgzyfwZNcKVFcjAUVSpF9HxevLTld2SG9aywYHOILj38arDdY1r/iQ==" + }, + "@types/source-map": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/@types/source-map/-/source-map-0.5.2.tgz", + "integrity": "sha512-++w4WmMbk3dS3UeHGzAG+xJOSz5Xqtjys/TBkqG3qp3SeWE7Wwezqe5eB7B51cxUyh4PW7bwVotpsLdBK0D8cw==" + }, + "@types/uglify-js": { + "version": "2.6.29", + "resolved": "https://registry.npmjs.org/@types/uglify-js/-/uglify-js-2.6.29.tgz", + "integrity": "sha512-BdFLCZW0GTl31AbqXSak8ss/MqEZ3DN2MH9rkAyGoTuzK7ifGUlX+u0nfbWeTsa7IPcZhtn8BlpYBXSV+vqGhQ==", + "requires": { + "@types/source-map": "0.5.2" + } + }, + "@types/yargs": { + "version": "6.6.0", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-6.6.0.tgz", + "integrity": "sha1-kfjiWAqAgwSfeDEcBZqlfWlJ32s=", + "dev": true + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + }, + "array-union": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-1.0.2.tgz", + "integrity": "sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk=", + "requires": { + "array-uniq": "1.0.3" + } + }, + "array-uniq": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.3.tgz", + "integrity": "sha1-r2rId6Jcx/dOBYiUdThY39sk/bY=" + }, + "balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "brace-expansion": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", + "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", + "requires": { + "balanced-match": "1.0.0", + "concat-map": "0.0.1" + } + }, + "builtin-modules": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz", + "integrity": "sha1-Jw8HbFpywC9bZaR9+Uxf46J4iS8=" + }, + "code-point-at": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" + }, + "commander": { + "version": "2.11.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", + "integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==" + }, + "concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + }, + "error-ex": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.1.tgz", + "integrity": "sha1-+FWobOYa3E6GIcPNoh56dhLDqNw=", + "requires": { + "is-arrayish": "0.2.1" + } + }, + "find-up": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-1.1.2.tgz", + "integrity": "sha1-ay6YIrGizgpgq2TWEOzK1TyyTQ8=", + "requires": { + "path-exists": "2.1.0", + "pinkie-promise": "2.0.1" + } + }, + "fs-extra": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.2.tgz", + "integrity": "sha1-+RcExT0bRh+JNFKwwwfZmXZHq2s=", + "requires": { + "graceful-fs": "4.1.11", + "jsonfile": "4.0.0", + "universalify": "0.1.1" + } + }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "get-caller-file": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.2.tgz", + "integrity": "sha1-9wLmMSfn4jHBYKgMFVSstw1QR+U=" + }, + "glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "requires": { + "fs.realpath": "1.0.0", + "inflight": "1.0.6", + "inherits": "2.0.3", + "minimatch": "3.0.4", + "once": "1.4.0", + "path-is-absolute": "1.0.1" + } + }, + "globby": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz", + "integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=", + "requires": { + "array-union": "1.0.2", + "glob": "7.1.2", + "object-assign": "4.1.1", + "pify": "2.3.0", + "pinkie-promise": "2.0.1" + } + }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "hosted-git-info": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz", + "integrity": "sha512-pNgbURSuab90KbTqvRPsseaTxOJCZBD0a7t+haSN33piP9cCM4l0CqdzAif2hUqm716UovKB2ROmiabGAKVXyg==" + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "1.4.0", + "wrappy": "1.0.2" + } + }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "invert-kv": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-1.0.0.tgz", + "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" + }, + "is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=" + }, + "is-builtin-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz", + "integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=", + "requires": { + "builtin-modules": "1.1.1" + } + }, + "is-fullwidth-code-point": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", + "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "requires": { + "number-is-nan": "1.0.1" + } + }, + "is-utf8": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz", + "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=" + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "4.1.11" + } + }, + "lcid": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/lcid/-/lcid-1.0.0.tgz", + "integrity": "sha1-MIrMr6C8SDo4Z7S28rlQYlHRuDU=", + "requires": { + "invert-kv": "1.0.0" + } + }, + "load-json-file": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", + "requires": { + "graceful-fs": "4.1.11", + "parse-json": "2.2.0", + "pify": "2.3.0", + "pinkie-promise": "2.0.1", + "strip-bom": "2.0.0" + } + }, + "minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "requires": { + "brace-expansion": "1.1.8" + } + }, + "normalize-package-data": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz", + "integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==", + "requires": { + "hosted-git-info": "2.5.0", + "is-builtin-module": "1.0.0", + "semver": "5.4.1", + "validate-npm-package-license": "3.0.1" + } + }, + "number-is-nan": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "requires": { + "wrappy": "1.0.2" + } + }, + "os-locale": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", + "requires": { + "lcid": "1.0.0" + } + }, + "parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha1-9ID0BDTvgHQfhGkJn43qGPVaTck=", + "requires": { + "error-ex": "1.3.1" + } + }, + "path-exists": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-2.1.0.tgz", + "integrity": "sha1-D+tsZPD8UY2adU3V77YscCJ2H0s=", + "requires": { + "pinkie-promise": "2.0.1" + } + }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, + "path-type": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-1.1.0.tgz", + "integrity": "sha1-WcRPfuSR2nBNpBXaWkBwuk+P5EE=", + "requires": { + "graceful-fs": "4.1.11", + "pify": "2.3.0", + "pinkie-promise": "2.0.1" + } + }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=" + }, + "pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=" + }, + "pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", + "requires": { + "pinkie": "2.0.4" + } + }, + "read-pkg": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-1.1.0.tgz", + "integrity": "sha1-9f+qXs0pyzHAR0vKfXVra7KePyg=", + "requires": { + "load-json-file": "1.1.0", + "normalize-package-data": "2.4.0", + "path-type": "1.1.0" + } + }, + "read-pkg-up": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-1.0.1.tgz", + "integrity": "sha1-nWPBMnbAZZGNV/ACpX9AobZD+wI=", + "requires": { + "find-up": "1.1.2", + "read-pkg": "1.1.0" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-main-filename": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-1.0.1.tgz", + "integrity": "sha1-l/cXtp1IeE9fUmpsWqj/3aBVpNE=" + }, + "semver": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.4.1.tgz", + "integrity": "sha512-WfG/X9+oATh81XtllIo/I8gOiY9EXRdv1cQdyykeXK17YcUW3EXUAi2To4pcH6nZtJPr7ZOpM5OMyWJZm+8Rsg==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, + "spdx-correct": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-1.0.2.tgz", + "integrity": "sha1-SzBz2TP/UfORLwOsVRlJikFQ20A=", + "requires": { + "spdx-license-ids": "1.2.2" + } + }, + "spdx-expression-parse": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-1.0.4.tgz", + "integrity": "sha1-m98vIOH0DtRH++JzJmGR/O1RYmw=" + }, + "spdx-license-ids": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz", + "integrity": "sha1-yd96NCRZSt5r0RkA1ZZpbcBrrFc=" + }, + "string-width": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "requires": { + "code-point-at": "1.1.0", + "is-fullwidth-code-point": "1.0.0", + "strip-ansi": "3.0.1" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "2.1.1" + } + }, + "strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "requires": { + "is-utf8": "0.2.1" + } + }, + "typescript": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.6.1.tgz", + "integrity": "sha1-7znN6ierrAtQAkLWcmq5DgyEZjE=", + "dev": true + }, + "uglify-js": { + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.1.6.tgz", + "integrity": "sha512-/rseyxEKEVMBo8279lqpoJgD6C/i/CIi+9TJDvWmb+Xo6mqMKwjA8Io3IMHlcXQzj99feR6zrN8m3wqqvm/nYA==", + "requires": { + "commander": "2.11.0", + "source-map": "0.6.1" + } + }, + "universalify": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", + "integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=" + }, + "validate-npm-package-license": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz", + "integrity": "sha1-KAS6vnEq0zeUWaz74kdGqywwP7w=", + "requires": { + "spdx-correct": "1.0.2", + "spdx-expression-parse": "1.0.4" + } + }, + "which-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-1.0.0.tgz", + "integrity": "sha1-u6Y8qGGUiZT/MHc2CJ47lgJsKk8=" + }, + "wrap-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-2.1.0.tgz", + "integrity": "sha1-2Pw9KE3QV5T+hJc8rs3Rz4JP3YU=", + "requires": { + "string-width": "1.0.2", + "strip-ansi": "3.0.1" + } + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + }, + "y18n": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", + "integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=" + }, + "yargs": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-7.1.0.tgz", + "integrity": "sha1-a6MY6xaWFyf10oT46gA+jWFU0Mg=", + "requires": { + "camelcase": "3.0.0", + "cliui": "3.2.0", + "decamelize": "1.2.0", + "get-caller-file": "1.0.2", + "os-locale": "1.4.0", + "read-pkg-up": "1.0.1", + "require-directory": "2.1.1", + "require-main-filename": "1.0.1", + "set-blocking": "2.0.0", + "string-width": "1.0.2", + "which-module": "1.0.0", + "y18n": "3.2.1", + "yargs-parser": "5.0.0" + }, + "dependencies": { + "camelcase": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz", + "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" + }, + "cliui": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz", + "integrity": "sha1-EgYBU3qRbSmUD5NNo7SNWFo5IT0=", + "requires": { + "string-width": "1.0.2", + "strip-ansi": "3.0.1", + "wrap-ansi": "2.1.0" + } + } + } + }, + "yargs-parser": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-5.0.0.tgz", + "integrity": "sha1-J17PDX/+Bcd+ZOfIbkzZS/DhIoo=", + "requires": { + "camelcase": "3.0.0" + }, + "dependencies": { + "camelcase": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-3.0.0.tgz", + "integrity": "sha1-MvxLn82vhF/N9+c7uXysImHwqwo=" + } + } + } + } +} diff --git a/package.json b/package.json index fd17c80..5463193 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "glob-uglifyjs", - "version": "1.0.0", + "version": "2.0.0-beta.4", "description": "Uglify JS files with glob pattern.", "main": "dist/main.js", "types": "@types/main.d.ts", @@ -24,7 +24,10 @@ "@types", "**/*.md" ], - "author": "Giedrius Grabauskas (https://github.com/GiedriusGrabauskas)", + "author": "SimplrJS (https://github.com/simplrjs)", + "contributors": [ + "Giedrius Grabauskas (https://github.com/GiedriusGrabauskas)" + ], "bugs": "https://github.com/SimplrJS/glob-uglifyjs/issues", "repository": "SimplrJS/glob-uglifyjs", "homepage": "https://github.com/SimplrJS/glob-uglifyjs", @@ -33,19 +36,17 @@ "node": ">=6.0.0" }, "devDependencies": { - "@types/glob": "^5.0.30", - "@types/mkdirp": "^0.3.29", - "@types/mz": "0.0.31", "@types/yargs": "6.6.0", - "fs-extra": "^2.1.2", - "typescript": "^2.2.2" + "typescript": "^2.6.1" }, "dependencies": { + "@types/glob": "^5.0.33", + "@types/globby": "^6.1.0", + "@types/fs-extra": "^4.0.3", "@types/uglify-js": "^2.6.28", - "glob": "^7.1.1", - "mkdirp": "^0.5.1", - "mz": "^2.6.0", - "uglify-js": "^2.8.21", + "fs-extra": "^4.0.2", + "globby": "^6.1.0", + "uglify-js": "^3.1.6", "yargs": "^7.0.2" }, "bin": { diff --git a/src/main.ts b/src/main.ts index 9a4fcc8..37b9d3e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,9 @@ import * as uglifyjs from "uglify-js"; -import * as glob from "glob"; +import * as globby from "globby"; +import { IOptions } from "glob"; import * as path from "path"; import { Options, OptionsDto } from "./options"; -import * as fs from "mz/fs"; +import * as fs from "fs-extra"; import { RejectionError } from "./rejection-error"; import * as Directories from "./utils/directories"; @@ -37,7 +38,7 @@ export class GlobsUglifyJs { this.globPattern = path.join(this.options.RootDir, globPattern); } - private globOptions: glob.IOptions | undefined; + private globOptions: IOptions | undefined; private globPattern: string; @@ -55,7 +56,7 @@ export class GlobsUglifyJs { } let filesList: string[]; try { - filesList = await this.getGlobFilesList(this.globPattern, this.globOptions); + filesList = await globby(this.globPattern, this.globOptions); } catch (error) { if (this.options.Debug && !this.options.Silence) { console.error(error); @@ -218,9 +219,12 @@ export class GlobsUglifyJs { private async uglifyItem(file: string): Promise { - let outputData: uglifyjs.MinifyOutput; + let outputData: uglifyjs.MinifyOutput & { error?: Error }; try { - outputData = await this.uglifyFile(file, this.options.MinifyOptions) + outputData = await this.uglifyFile(file, this.options.MinifyOptions); + if (outputData.error != null) { + throw outputData.error; + } } catch (error) { throw new RejectionError(error, "uglifyFile", file); } @@ -260,31 +264,14 @@ export class GlobsUglifyJs { } private async uglifyFile(file: string, options?: uglifyjs.MinifyOptions): Promise { - return new Promise((resolve, reject) => { + return new Promise(async (resolve, reject) => { try { - let outputData = uglifyjs.minify(file, options); + const inputData = await fs.readFile(file, "UTF-8"); + const outputData = uglifyjs.minify(inputData, options); resolve(outputData); } catch (error) { reject(error); } }); } - - /** - * Asynchronously return files list by pattern. - * - * @param {string} pattern - * @param {glob.IOptions} [options={}] - */ - private async getGlobFilesList(pattern: string, options: glob.IOptions = {}): Promise { - return new Promise((resolve, reject) => { - glob(pattern, options, (err, matches) => { - if (err != null) { - reject(err); - } else { - resolve(matches); - } - }); - }); - } } diff --git a/src/utils/directories.ts b/src/utils/directories.ts index 5123b6a..dcfbadf 100644 --- a/src/utils/directories.ts +++ b/src/utils/directories.ts @@ -1,19 +1,9 @@ import * as path from "path"; -import * as fs from "mz/fs"; -import * as mkdirp from "mkdirp"; - -export async function Exists(path: string) { - try { - const stat = await fs.stat(path); - return stat.isDirectory(); - } catch (error) { - return false; - } -} +import * as fs from "fs-extra"; export async function RemoveEmptyDirectories(directoryPath: string) { - const isExist = await Exists(directoryPath); - if (!isExist) { + const stat = await fs.stat(directoryPath); + if (!stat.isDirectory()) { return; } let files = await fs.readdir(directoryPath); @@ -30,14 +20,7 @@ export async function RemoveEmptyDirectories(directoryPath: string) { } export async function MakeTree(filePath: string): Promise { - return new Promise((resolve, reject) => { - const dirname = path.dirname(filePath); - mkdirp(dirname, (error, data) => { - if (error) { - reject(error); - return; - } - resolve(data); - }); - }); + const dirname = path.dirname(filePath); + await fs.ensureDir(dirname); + return dirname; }