From 68711407cd1f5bc46dc4b8a8f85f5d33236102d5 Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 27 Apr 2020 21:01:08 +0300 Subject: [PATCH] import fixes + umd --- lib/umd/index.js | 2 +- package-lock.json | 59 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++-- rollup.config.js | 10 ++++---- tests/umd.html | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 tests/umd.html diff --git a/lib/umd/index.js b/lib/umd/index.js index 83c7f05..2ea4d52 100644 --- a/lib/umd/index.js +++ b/lib/umd/index.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("browser-hrtime")):"function"==typeof define&&define.amd?define(["exports","browser-hrtime"],t):t((e=e||self)["Elapssed-logger"]={},e.hrtime)}(this,(function(e,t){"use strict";t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var o=function(){function e(){this._timer=t()}return e.prototype.end=function(e){void 0===e&&(e="");var t=this.get();console.log((e?e+" ":"")+t)},e.prototype._diff=function(){return t(this._timer)},e.prototype.get=function(){var e=this._diff();return this.parse(e)},e.prototype.parse=function(e){var t="",o=(1e9*e[0]+e[1])/1e6,r=Math.round(o%1e3),n=Math.round(100*(o/1e3%60+Number.EPSILON))/100,i=Math.floor(o/6e4%60),u=Math.floor(o/36e5%24);return u>0&&(t+=u+" hours "),i>0&&(t+=i+" minutes "),n>=1&&(t+=n+" seconds "),0===i&&0===u&&n<1&&r>0&&(t+=r+"ms"),t},e}(),r=new Map,n=function(e){void 0===e&&(e=null);var t=new o;return e?(r.set(e,t),t):t},i=function(e,t){void 0===t&&(t=null);var o=u(e);!1!==o&&(console.log((t||e)+" "+o),r.delete(e))},u=function(e){var t=r.get(e);return t?t.get():(console.warn("No such label '"+e+"' for ElapsedLogger"),!1)},s={get:u,end:i,start:n};e.default=s,e.end=i,e.get=u,e.start=n,Object.defineProperty(e,"__esModule",{value:!0})})); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).Elapsed_logger={})}(this,(function(e){"use strict";var t="undefined"!=typeof process&&void 0!==process.hrtime?process.hrtime:function(e){var t=Math.floor(.001*(Date.now()-performance.now())),o=.001*performance.now(),n=Math.floor(o)+t,r=Math.floor(o%1*1e9);return e&&(n-=e[0],(r-=e[1])<0&&(n--,r+=1e9)),[n,r]},o=function(){function e(){this._timer=t()}return e.prototype.end=function(e){void 0===e&&(e="");var t=this.get();console.log((e?e+" ":"")+t)},e.prototype._diff=function(){return t(this._timer)},e.prototype.get=function(){var e=this._diff();return this.parse(e)},e.prototype.parse=function(e){var t="",o=(1e9*e[0]+e[1])/1e6,n=Math.round(o%1e3),r=Math.round(100*(o/1e3%60+Number.EPSILON))/100,f=Math.floor(o/6e4%60),i=Math.floor(o/36e5%24);return i>0&&(t+=i+" hours "),f>0&&(t+=f+" minutes "),r>=1&&(t+=r+" seconds "),0===f&&0===i&&r<1&&n>0&&(t+=n+"ms"),t},e}(),n=new Map,r=function(e){void 0===e&&(e=null);var t=new o;return e?(n.set(e,t),t):t},f=function(e,t){void 0===t&&(t=null);var o=i(e);!1!==o&&(console.log((t||e)+" "+o),n.delete(e))},i=function(e){var t=n.get(e);return t?t.get():(console.warn("No such label '"+e+"' for ElapsedLogger"),!1)},s={get:i,end:f,start:r};e.default=s,e.end=f,e.get=i,e.start=r,Object.defineProperty(e,"__esModule",{value:!0})})); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 56aa915..b0be645 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1001,6 +1001,38 @@ "@types/node": ">= 8" } }, + "@rollup/plugin-node-resolve": { + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-7.1.3.tgz", + "integrity": "sha512-RxtSL3XmdTAE2byxekYLnx+98kEUOrPHF/KRVjLH+DEIHy6kjIw7YINQzn+NXiH/NTrQLAwYs0GWB+csWygA9Q==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8", + "@types/resolve": "0.0.8", + "builtin-modules": "^3.1.0", + "is-module": "^1.0.0", + "resolve": "^1.14.2" + }, + "dependencies": { + "builtin-modules": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", + "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", + "dev": true + } + } + }, + "@rollup/pluginutils": { + "version": "3.0.9", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.0.9.tgz", + "integrity": "sha512-TLZavlfPAZYI7v33wQh4mTP6zojne14yok3DNSLcjoG/Hirxfkonn6icP5rrNWRn8nZsirJBFFpijVOJzkUHDg==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "micromatch": "^4.0.2" + } + }, "@sindresorhus/is": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-2.1.1.tgz", @@ -1084,6 +1116,12 @@ "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==", "dev": true }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/http-cache-semantics": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz", @@ -1148,6 +1186,15 @@ "integrity": "sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ==", "dev": true }, + "@types/resolve": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", + "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/responselike": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", @@ -2475,6 +2522,12 @@ "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", "dev": true }, + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -3441,6 +3494,12 @@ "integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==", "dev": true }, + "is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", + "dev": true + }, "is-npm": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/is-npm/-/is-npm-4.0.0.tgz", diff --git a/package.json b/package.json index 45e3d60..df5835a 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,6 @@ "description": "Similiar to console.time() but returns readable elapsed time e.g Label: 1 hour 20 minutes 10.3 seconds", "main": "lib/cjs/index.js", "module": "lib/esm/index.js", - "browser": "lib/umd/index.js", "types": "lib/index.d.ts", "files": [ "lib/**/*" @@ -16,7 +15,7 @@ "build:cjs": "tsc --module commonjs --target es5 --outDir lib/cjs", "build:umd": "rollup -c", "build:umd:min": "cd lib/umd && terser --compress --mangle --comments -o index.js -- index.js", - "watch": "tsc --watch", + "watch": "npm run build:cjs -- --watch", "format": "prettier --write \"src/**/*.ts\" \"src/**/*.ts\"", "lint": "tslint -p tsconfig.json", "release": "dotenv release-it" @@ -59,6 +58,7 @@ "browser-hrtime": "^1.0.0" }, "devDependencies": { + "@rollup/plugin-node-resolve": "^7.1.3", "@types/node": "^13.13.0", "coveralls": "^3.1.0", "dotenv-cli": "^3.1.0", diff --git a/rollup.config.js b/rollup.config.js index 81be582..219d175 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,14 +1,12 @@ +import resolve from '@rollup/plugin-node-resolve'; + export default { input: 'lib/esm/index.js', - output: 'lib/umd/index.js', output: { - name: 'Elapssed-logger', + name: 'Elapsed_logger', file: 'lib/umd/index.js', format: 'umd', exports: "named", - globals: { - 'browser-hrtime': 'hrtime', - } }, - external: [ 'browser-hrtime' ] + plugins: [resolve()] }; \ No newline at end of file diff --git a/tests/umd.html b/tests/umd.html new file mode 100644 index 0000000..35ea781 --- /dev/null +++ b/tests/umd.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + \ No newline at end of file