rollup-plugin-filesize
Advanced tools
| {"version":3,"file":"index.js","sources":["../src/index.js"],"sourcesContent":["import { readFile as origReadFile, existsSync } from \"fs\";\nimport { promisify } from \"util\";\nimport { dirname, resolve as pathResolve, join } from \"path\";\n\nimport fileSize from \"filesize\";\nimport gzip from \"gzip-size\";\nimport terser from \"terser\";\nimport brotli from \"brotli-size\";\nimport pacote from \"pacote\";\n\nconst readFile = promisify(origReadFile);\n\nconst thisDirectory = dirname(new URL(import.meta.url).pathname);\n\nexport default function filesize(options = {}, env) {\n\tlet {\n\t\trender,\n\t\tformat = {},\n\t\ttheme = \"dark\",\n\t\tshowBeforeSizes = \"none\",\n\t\tshowGzippedSize = true,\n\t\tshowBrotliSize = false,\n\t\tshowMinifiedSize = true,\n\t} = options;\n\n\tconst getLoggingData = async function (outputOptions, bundle) {\n\t\tconst { code, fileName } = bundle;\n\t\tconst info = {};\n\n\t\tlet codeBefore;\n\t\tif (showBeforeSizes !== \"none\") {\n\t\t\tlet file = outputOptions.file || outputOptions.dest;\n\t\t\tif (showBeforeSizes !== \"build\") {\n\t\t\t\tconst { name } = await import(join(process.cwd(), \"./package.json\"));\n\t\t\t\ttry {\n\t\t\t\t\tconst output = join(thisDirectory, \"../.cache\");\n\t\t\t\t\tif (!existsSync(output)) {\n\t\t\t\t\t\tawait pacote.extract(`${name}@latest`, output);\n\t\t\t\t\t}\n\t\t\t\t\tfile = join(output, file);\n\t\t\t\t} catch (err) {\n\t\t\t\t\t// Package might not exist\n\t\t\t\t\tfile = null;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (file) {\n\t\t\t\ttry {\n\t\t\t\t\tcodeBefore = await readFile(file, \"utf8\");\n\t\t\t\t} catch (err) {\n\t\t\t\t\t// File might not exist\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tinfo.fileName = fileName;\n\n\t\tinfo.bundleSize = fileSize(Buffer.byteLength(code), format);\n\n\t\tinfo.brotliSize = showBrotliSize\n\t\t\t? fileSize(await brotli(code), format)\n\t\t\t: \"\";\n\n\t\tif (showMinifiedSize || showGzippedSize) {\n\t\t\tconst minifiedCode = terser.minify(code).code;\n\t\t\tinfo.minSize = showMinifiedSize\n\t\t\t\t? fileSize(minifiedCode.length, format)\n\t\t\t\t: \"\";\n\t\t\tinfo.gzipSize = showGzippedSize\n\t\t\t\t? fileSize(gzip.sync(minifiedCode), format)\n\t\t\t\t: \"\";\n\t\t}\n\n\t\tif (codeBefore) {\n\t\t\tinfo.bundleSizeBefore = fileSize(Buffer.byteLength(codeBefore), format);\n\t\t\tinfo.brotliSizeBefore = showBrotliSize\n\t\t\t\t? fileSize(await brotli(codeBefore), format)\n\t\t\t\t: \"\";\n\t\t\tif (showMinifiedSize || showGzippedSize) {\n\t\t\t\tconst minifiedCode = terser.minify(codeBefore).code;\n\t\t\t\tinfo.minSizeBefore = showMinifiedSize\n\t\t\t\t\t? fileSize(minifiedCode.length, format)\n\t\t\t\t\t: \"\";\n\t\t\t\tinfo.gzipSizeBefore = showGzippedSize\n\t\t\t\t\t? fileSize(gzip.sync(minifiedCode), format)\n\t\t\t\t\t: \"\";\n\t\t\t}\n\t\t}\n\n\t\tconst opts = {\n\t\t\tformat,\n\t\t\ttheme,\n\t\t\trender,\n\t\t\tshowBeforeSizes,\n\t\t\tshowGzippedSize,\n\t\t\tshowBrotliSize,\n\t\t\tshowMinifiedSize,\n\t\t};\n\n\t\tif (render) {\n\t\t\tconsole.warn(\n\t\t\t\t\"`render` is now deprecated. Please use `reporter` instead.\"\n\t\t\t);\n\t\t\treturn opts.render(opts, outputOptions, info);\n\t\t}\n\n\t\tconst reporters = options.reporter\n\t\t\t? Array.isArray(options.reporter)\n\t\t\t\t? options.reporter\n\t\t\t\t: [options.reporter]\n\t\t\t: [\"boxen\"];\n\n\t\treturn (\n\t\t\tawait Promise.all(\n\t\t\t\treporters.map(async (reporter) => {\n\t\t\t\t\tif (typeof reporter === \"string\") {\n\t\t\t\t\t\tlet p;\n\t\t\t\t\t\tif (reporter === \"boxen\") {\n\t\t\t\t\t\t\tp = import(\n\t\t\t\t\t\t\t\tdirname(new URL(import.meta.url).pathname) +\n\t\t\t\t\t\t\t\t\t\"/reporters/boxen.js\"\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tp = import(pathResolve(process.cwd(), reporter));\n\t\t\t\t\t\t}\n\t\t\t\t\t\treporter = (await p).default;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn reporter(opts, outputOptions, info);\n\t\t\t\t})\n\t\t\t)\n\t\t).join(\"\");\n\t};\n\n\tif (env === \"test\") {\n\t\treturn getLoggingData;\n\t}\n\n\treturn {\n\t\tname: \"filesize\",\n\t\tasync generateBundle(outputOptions, bundle /* , isWrite */) {\n\t\t\tconst dataStrs = await Promise.all(\n\t\t\t\tObject.keys(bundle)\n\t\t\t\t\t.map((fileName) => bundle[fileName])\n\t\t\t\t\t.filter((currentBundle) => {\n\t\t\t\t\t\tif ({}.hasOwnProperty.call(currentBundle, \"type\")) {\n\t\t\t\t\t\t\treturn currentBundle.type !== \"asset\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn !currentBundle.isAsset;\n\t\t\t\t\t})\n\t\t\t\t\t.map((currentBundle) => {\n\t\t\t\t\t\treturn getLoggingData(outputOptions, currentBundle);\n\t\t\t\t\t})\n\t\t\t);\n\t\t\tdataStrs.forEach((str) => {\n\t\t\t\tif (str) {\n\t\t\t\t\tconsole.log(str);\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n}\n"],"names":["readFile","promisify","origReadFile","thisDirectory","dirname","URL","import","pathname","filesize","options","env","render","format","theme","showBeforeSizes","showGzippedSize","showBrotliSize","showMinifiedSize","getLoggingData","outputOptions","bundle","code","fileName","info","codeBefore","file","dest","name","join","process","cwd","output","existsSync","pacote","extract","err","bundleSize","fileSize","Buffer","byteLength","brotliSize","brotli","minifiedCode","terser","minify","minSize","length","gzipSize","gzip","sync","bundleSizeBefore","brotliSizeBefore","minSizeBefore","gzipSizeBefore","opts","console","warn","reporters","reporter","Array","isArray","Promise","all","map","p","pathResolve","default","generateBundle","dataStrs","Object","keys","filter","currentBundle","hasOwnProperty","call","type","isAsset","forEach","str","log"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,MAAMA,QAAQ,GAAGC,cAAS,CAACC,WAAD,CAA1B;AAEA,MAAMC,aAAa,GAAGC,YAAO,CAAC,IAAIC,GAAJ,CAAQC,mMAAR,EAAyBC,QAA1B,CAA7B;AAEe,SAASC,QAAT,CAAkBC,OAAO,GAAG,EAA5B,EAAgCC,GAAhC,EAAqC;AACnD,MAAI;AACHC,IAAAA,MADG;AAEHC,IAAAA,MAAM,GAAG,EAFN;AAGHC,IAAAA,KAAK,GAAG,MAHL;AAIHC,IAAAA,eAAe,GAAG,MAJf;AAKHC,IAAAA,eAAe,GAAG,IALf;AAMHC,IAAAA,cAAc,GAAG,KANd;AAOHC,IAAAA,gBAAgB,GAAG;AAPhB,MAQAR,OARJ;;AAUA,QAAMS,cAAc,GAAG,gBAAgBC,aAAhB,EAA+BC,MAA/B,EAAuC;AAC7D,UAAM;AAAEC,MAAAA,IAAF;AAAQC,MAAAA;AAAR,QAAqBF,MAA3B;AACA,UAAMG,IAAI,GAAG,EAAb;AAEA,QAAIC,UAAJ;;AACA,QAAIV,eAAe,KAAK,MAAxB,EAAgC;AAC/B,UAAIW,IAAI,GAAGN,aAAa,CAACM,IAAd,IAAsBN,aAAa,CAACO,IAA/C;;AACA,UAAIZ,eAAe,KAAK,OAAxB,EAAiC;AAChC,cAAM;AAAEa,UAAAA;AAAF,YAAW,MAAM,mEAAOC,SAAI,CAACC,OAAO,CAACC,GAAR,EAAD,EAAgB,gBAAhB,CAAX,OAAvB;;AACA,YAAI;AACH,gBAAMC,MAAM,GAAGH,SAAI,CAACzB,aAAD,EAAgB,WAAhB,CAAnB;;AACA,cAAI,CAAC6B,aAAU,CAACD,MAAD,CAAf,EAAyB;AACxB,kBAAME,MAA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vB,UAAAA,OAAO,CAACwB,GAAR,CAAYD,GAAZ;AACA;AACD,OAJD;AAKA;;AArBK,GAAP;AAuBA;;;;"} |
| 'use strict'; | ||
| Object.defineProperty(exports, '__esModule', { value: true }); | ||
| const boxen = require("boxen"); | ||
| const colors = require("colors/safe"); | ||
| async function boxenReporter(opt, outputOptions, info) { | ||
| const primaryColor = opt.theme === "dark" ? "green" : "black"; | ||
| const secondaryColor = opt.theme === "dark" ? "yellow" : "blue"; | ||
| const title = colors[primaryColor].bold; | ||
| const value = colors[secondaryColor]; | ||
| const values = [...(outputOptions.file || outputOptions.dest ? [`${title("Destination: ")}${value(outputOptions.file || outputOptions.dest)}`] : info.fileName ? [`${title("Bundle Name: ")} ${value(info.fileName)}`] : []), ...(info.bundleSizeBefore ? [`${title("Bundle Size: ")} ${value(info.bundleSize)} (was ${value(info.bundleSizeBefore)})`] : [`${title("Bundle Size: ")} ${value(info.bundleSize)}`]), ...(info.minSize ? info.minSizeBefore ? [`${title("Minified Size: ")} ${value(info.minSize)} (was ${value(info.minSizeBefore)})`] : [`${title("Minified Size: ")} ${value(info.minSize)}`] : []), ...(info.gzipSize ? info.gzipSizeBefore ? [`${title("Gzipped Size: ")} ${value(info.gzipSize)} (was ${value(info.gzipSizeBefore)})`] : [`${title("Gzipped Size: ")} ${value(info.gzipSize)}`] : []), ...(info.brotliSize ? info.brotliSizeBefore ? [`${title("Brotli size: ")}${value(info.brotliSize)} (was ${value(info.brotliSizeBefore)})`] : [`${title("Brotli size: ")}${value(info.brotliSize)}`] : [])]; | ||
| return boxen(values.join("\n"), { | ||
| padding: 1 | ||
| }); | ||
| } | ||
| exports.default = boxenReporter; | ||
| //# sourceMappingURL=boxen.js.map |
| {"version":3,"file":"boxen.js","sources":["../../src/reporters/boxen.js"],"sourcesContent":["const boxen = require(\"boxen\");\nconst colors = require(\"colors/safe\");\n\nexport default async function boxenReporter(opt, outputOptions, info) {\n\tconst primaryColor = opt.theme === \"dark\" ? \"green\" : \"black\";\n\tconst secondaryColor = opt.theme === \"dark\" ? \"yellow\" : \"blue\";\n\n\tconst title = colors[primaryColor].bold;\n\tconst value = colors[secondaryColor];\n\n\tconst values = [\n\t\t...(outputOptions.file || outputOptions.dest\n\t\t\t? [\n\t\t\t\t\t`${title(\"Destination: \")}${value(\n\t\t\t\t\t\toutputOptions.file || outputOptions.dest\n\t\t\t\t\t)}`,\n\t\t\t ]\n\t\t\t: info.fileName\n\t\t\t? [`${title(\"Bundle Name: \")} ${value(info.fileName)}`]\n\t\t\t: []),\n\t\t...(info.bundleSizeBefore\n\t\t\t? [\n\t\t\t\t\t`${title(\"Bundle Size: \")} ${value(info.bundleSize)} (was ${value(\n\t\t\t\t\t\tinfo.bundleSizeBefore\n\t\t\t\t\t)})`,\n\t\t\t ]\n\t\t\t: [`${title(\"Bundle Size: \")} ${value(info.bundleSize)}`]),\n\t\t...(info.minSize\n\t\t\t? info.minSizeBefore\n\t\t\t\t? [\n\t\t\t\t\t\t`${title(\"Minified Size: \")} ${value(info.minSize)} (was ${value(\n\t\t\t\t\t\t\tinfo.minSizeBefore\n\t\t\t\t\t\t)})`,\n\t\t\t\t ]\n\t\t\t\t: [`${title(\"Minified Size: \")} ${value(info.minSize)}`]\n\t\t\t: []),\n\t\t...(info.gzipSize\n\t\t\t? info.gzipSizeBefore\n\t\t\t\t? [\n\t\t\t\t\t\t`${title(\"Gzipped Size: \")} ${value(info.gzipSize)} (was ${value(\n\t\t\t\t\t\t\tinfo.gzipSizeBefore\n\t\t\t\t\t\t)})`,\n\t\t\t\t ]\n\t\t\t\t: [`${title(\"Gzipped Size: \")} ${value(info.gzipSize)}`]\n\t\t\t: []),\n\t\t...(info.brotliSize\n\t\t\t? info.brotliSizeBefore\n\t\t\t\t? [\n\t\t\t\t\t\t`${title(\"Brotli size: \")}${value(info.brotliSize)} (was ${value(\n\t\t\t\t\t\t\tinfo.brotliSizeBefore\n\t\t\t\t\t\t)})`,\n\t\t\t\t ]\n\t\t\t\t: [`${title(\"Brotli size: \")}${value(info.brotliSize)}`]\n\t\t\t: []),\n\t];\n\n\treturn boxen(values.join(\"\\n\"), { padding: 1 });\n}\n"],"names":["boxen","require","colors","boxenReporter","opt","outputOptions","info","primaryColor","theme","secondaryColor","title","bold","value","values","file","dest","fileName","bundleSizeBefore","bundleSize","minSize","minSizeBefore","gzipSize","gzipSizeBefore","brotliSize","brotliSizeBefore","join","padding"],"mappings":";;;;AAAA,MAAMA,KAAK,GAAGC,OAAO,CAAC,OAAD,CAArB;;AACA,MAAMC,MAAM,GAAGD,OAAO,CAAC,aAAD,CAAtB;;AAEe,eAAeE,aAAf,CAA6BC,GAA7B,EAAkCC,aAAlC,EAAiDC,IAAjD,EAAuD;AACrE,QAAMC,YAAY,GAAGH,GAAG,CAACI,KAAJ,KAAc,MAAd,GAAuB,OAAvB,GAAiC,OAAtD;AACA,QAAMC,cAAc,GAAGL,GAAG,CAACI,KAAJ,KAAc,MAAd,GAAuB,QAAvB,GAAkC,MAAzD;AAEA,QAAME,KAAK,GAAGR,MAAM,CAACK,YAAD,CAAN,CAAqBI,IAAnC;AACA,QAAMC,KAAK,GAAGV,MAAM,CAACO,cAAD,CAApB;AAEA,QAAMI,MAAM,GAAG,CACd,IAAIR,aAAa,CAACS,IAAd,IAAsBT,aAAa,CAACU,IAApC,GACD,CACC,GAAEL,KAAK,CAAC,eAAD,CAAkB,GAAEE,KAAK,CAChCP,aAAa,CAACS,IAAd,IAAsBT,aAAa,CAACU,IADJ,CAE/B,EAHF,CADC,GAMDT,IAAI,CAACU,QAAL,GACA,CAAE,GAAEN,KAAK,CAAC,eAAD,CAAkB,IAAGE,KAAK,CAACN,IAAI,CAACU,QAAN,CAAgB,EAAnD,CADA,GAEA,EARH,CADc,EAUd,IAAIV,IAAI,CAACW,gBAAL,GACD,CACC,GAAEP,KAAK,CAAC,eAAD,CAAkB,IAAGE,KAAK,CAACN,IAAI,CAACY,UAAN,CAAkB,SAAQN,KAAK,CAChEN,IAAI,CAACW,gBAD2D,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AACA;;;;"} |
| const boxen = require("boxen"); | ||
| const colors = require("colors/safe"); | ||
| export default async function boxenReporter(opt, outputOptions, info) { | ||
| const primaryColor = opt.theme === "dark" ? "green" : "black"; | ||
| const secondaryColor = opt.theme === "dark" ? "yellow" : "blue"; | ||
| const title = colors[primaryColor].bold; | ||
| const value = colors[secondaryColor]; | ||
| const values = [ | ||
| ...(outputOptions.file || outputOptions.dest | ||
| ? [ | ||
| `${title("Destination: ")}${value( | ||
| outputOptions.file || outputOptions.dest | ||
| )}`, | ||
| ] | ||
| : info.fileName | ||
| ? [`${title("Bundle Name: ")} ${value(info.fileName)}`] | ||
| : []), | ||
| ...(info.bundleSizeBefore | ||
| ? [ | ||
| `${title("Bundle Size: ")} ${value(info.bundleSize)} (was ${value( | ||
| info.bundleSizeBefore | ||
| )})`, | ||
| ] | ||
| : [`${title("Bundle Size: ")} ${value(info.bundleSize)}`]), | ||
| ...(info.minSize | ||
| ? info.minSizeBefore | ||
| ? [ | ||
| `${title("Minified Size: ")} ${value(info.minSize)} (was ${value( | ||
| info.minSizeBefore | ||
| )})`, | ||
| ] | ||
| : [`${title("Minified Size: ")} ${value(info.minSize)}`] | ||
| : []), | ||
| ...(info.gzipSize | ||
| ? info.gzipSizeBefore | ||
| ? [ | ||
| `${title("Gzipped Size: ")} ${value(info.gzipSize)} (was ${value( | ||
| info.gzipSizeBefore | ||
| )})`, | ||
| ] | ||
| : [`${title("Gzipped Size: ")} ${value(info.gzipSize)}`] | ||
| : []), | ||
| ...(info.brotliSize | ||
| ? info.brotliSizeBefore | ||
| ? [ | ||
| `${title("Brotli size: ")}${value(info.brotliSize)} (was ${value( | ||
| info.brotliSizeBefore | ||
| )})`, | ||
| ] | ||
| : [`${title("Brotli size: ")}${value(info.brotliSize)}`] | ||
| : []), | ||
| ]; | ||
| return boxen(values.join("\n"), { padding: 1 }); | ||
| } |
+131
-64
@@ -5,78 +5,137 @@ 'use strict'; | ||
| function _interopNamespace(e) { | ||
| if (e && e.__esModule) { return e; } else { | ||
| var n = {}; | ||
| if (e) { | ||
| Object.keys(e).forEach(function (k) { | ||
| var d = Object.getOwnPropertyDescriptor(e, k); | ||
| Object.defineProperty(n, k, d.get ? d : { | ||
| enumerable: true, | ||
| get: function () { | ||
| return e[k]; | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
| n['default'] = e; | ||
| return n; | ||
| } | ||
| } | ||
| var fs = require('fs'); | ||
| var util = require('util'); | ||
| var path = require('path'); | ||
| var fileSize = _interopDefault(require('filesize')); | ||
| var boxen = _interopDefault(require('boxen')); | ||
| var colors = _interopDefault(require('colors')); | ||
| var merge = _interopDefault(require('lodash.merge')); | ||
| var gzip = _interopDefault(require('gzip-size')); | ||
| var terser = _interopDefault(require('terser')); | ||
| var brotli = _interopDefault(require('brotli-size')); | ||
| var pacote = _interopDefault(require('pacote')); | ||
| function _toConsumableArray(arr) { | ||
| return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
| } | ||
| const readFile = util.promisify(fs.readFile); | ||
| const thisDirectory = path.dirname(new URL((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href))).pathname); | ||
| function filesize(options = {}, env) { | ||
| let { | ||
| render, | ||
| format = {}, | ||
| theme = "dark", | ||
| showBeforeSizes = "none", | ||
| showGzippedSize = true, | ||
| showBrotliSize = false, | ||
| showMinifiedSize = true | ||
| } = options; | ||
| function _arrayWithoutHoles(arr) { | ||
| if (Array.isArray(arr)) { | ||
| for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
| const getLoggingData = async function (outputOptions, bundle) { | ||
| const { | ||
| code, | ||
| fileName | ||
| } = bundle; | ||
| const info = {}; | ||
| let codeBefore; | ||
| return arr2; | ||
| } | ||
| } | ||
| if (showBeforeSizes !== "none") { | ||
| let file = outputOptions.file || outputOptions.dest; | ||
| function _iterableToArray(iter) { | ||
| if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
| } | ||
| if (showBeforeSizes !== "build") { | ||
| const { | ||
| name | ||
| } = await new Promise(function (resolve) { resolve(_interopNamespace(require(path.join(process.cwd(), "./package.json")))); }); | ||
| function _nonIterableSpread() { | ||
| throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
| } | ||
| try { | ||
| const output = path.join(thisDirectory, "../.cache"); | ||
| var brotli = require("brotli-size"); | ||
| if (!fs.existsSync(output)) { | ||
| await pacote.extract(`${name}@latest`, output); | ||
| } | ||
| function render(opt, outputOptions, info) { | ||
| var primaryColor = opt.theme === "dark" ? "green" : "black"; | ||
| var secondaryColor = opt.theme === "dark" ? "yellow" : "blue"; | ||
| var title = colors[primaryColor].bold; | ||
| var value = colors[secondaryColor]; | ||
| var values = [].concat(_toConsumableArray(outputOptions.file ? ["".concat(title("Destination: ")).concat(value(outputOptions.file))] : info.fileName ? ["".concat(title("Bundle Name: "), " ").concat(value(info.fileName))] : []), ["".concat(title("Bundle Size: "), " ").concat(value(info.bundleSize))], _toConsumableArray(info.minSize ? ["".concat(title("Minified Size: "), " ").concat(value(info.minSize))] : []), _toConsumableArray(info.gzipSize ? ["".concat(title("Gzipped Size: "), " ").concat(value(info.gzipSize))] : []), _toConsumableArray(info.brotliSize ? ["".concat(title("Brotli size: ")).concat(value(info.brotliSize))] : [])); | ||
| return boxen(values.join("\n"), { | ||
| padding: 1 | ||
| }); | ||
| } | ||
| file = path.join(output, file); | ||
| } catch (err) { | ||
| // Package might not exist | ||
| file = null; | ||
| } | ||
| } | ||
| function filesize() { | ||
| var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
| var env = arguments.length > 1 ? arguments[1] : undefined; | ||
| var defaultOptions = { | ||
| format: {}, | ||
| theme: "dark", | ||
| render: render, | ||
| showGzippedSize: true, | ||
| showBrotliSize: false, | ||
| showMinifiedSize: true | ||
| }; | ||
| var opts = merge({}, defaultOptions, options); | ||
| if (file) { | ||
| try { | ||
| codeBefore = await readFile(file, "utf8"); | ||
| } catch (err) {// File might not exist | ||
| } | ||
| } | ||
| } | ||
| if (options.render) { | ||
| opts.render = options.render; | ||
| } | ||
| var getData = function getData(outputOptions, bundle) { | ||
| var code = bundle.code, | ||
| fileName = bundle.fileName; | ||
| var info = {}; | ||
| info.fileName = fileName; | ||
| info.bundleSize = fileSize(Buffer.byteLength(code), opts.format); | ||
| info.brotliSize = opts.showBrotliSize ? fileSize(brotli.sync(code), opts.format) : ""; | ||
| info.bundleSize = fileSize(Buffer.byteLength(code), format); | ||
| info.brotliSize = showBrotliSize ? fileSize((await brotli(code)), format) : ""; | ||
| if (opts.showMinifiedSize || opts.showGzippedSize) { | ||
| var minifiedCode = terser.minify(code).code; | ||
| info.minSize = opts.showMinifiedSize ? fileSize(minifiedCode.length, opts.format) : ""; | ||
| info.gzipSize = opts.showGzippedSize ? fileSize(gzip.sync(minifiedCode), opts.format) : ""; | ||
| if (showMinifiedSize || showGzippedSize) { | ||
| const minifiedCode = terser.minify(code).code; | ||
| info.minSize = showMinifiedSize ? fileSize(minifiedCode.length, format) : ""; | ||
| info.gzipSize = showGzippedSize ? fileSize(gzip.sync(minifiedCode), format) : ""; | ||
| } | ||
| return opts.render(opts, outputOptions, info); | ||
| if (codeBefore) { | ||
| info.bundleSizeBefore = fileSize(Buffer.byteLength(codeBefore), format); | ||
| info.brotliSizeBefore = showBrotliSize ? fileSize((await brotli(codeBefore)), format) : ""; | ||
| if (showMinifiedSize || showGzippedSize) { | ||
| const minifiedCode = terser.minify(codeBefore).code; | ||
| info.minSizeBefore = showMinifiedSize ? fileSize(minifiedCode.length, format) : ""; | ||
| info.gzipSizeBefore = showGzippedSize ? fileSize(gzip.sync(minifiedCode), format) : ""; | ||
| } | ||
| } | ||
| const opts = { | ||
| format, | ||
| theme, | ||
| render, | ||
| showBeforeSizes, | ||
| showGzippedSize, | ||
| showBrotliSize, | ||
| showMinifiedSize | ||
| }; | ||
| if (render) { | ||
| console.warn("`render` is now deprecated. Please use `reporter` instead."); | ||
| return opts.render(opts, outputOptions, info); | ||
| } | ||
| const reporters = options.reporter ? Array.isArray(options.reporter) ? options.reporter : [options.reporter] : ["boxen"]; | ||
| return (await Promise.all(reporters.map(async reporter => { | ||
| if (typeof reporter === "string") { | ||
| let p; | ||
| if (reporter === "boxen") { | ||
| p = new Promise(function (resolve) { resolve(_interopNamespace(require(path.dirname(new URL((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href))).pathname) + "/reporters/boxen.js"))); }); | ||
| } else { | ||
| p = new Promise(function (resolve) { resolve(_interopNamespace(require(path.resolve(process.cwd(), reporter)))); }); | ||
| } | ||
| reporter = (await p).default; | ||
| } | ||
| return reporter(opts, outputOptions, info); | ||
| }))).join(""); | ||
| }; | ||
| if (env === "test") { | ||
| return getData; | ||
| return getLoggingData; | ||
| } | ||
@@ -86,7 +145,8 @@ | ||
| name: "filesize", | ||
| generateBundle: function generateBundle(outputOptions, bundle, isWrite) { | ||
| Object.keys(bundle).map(function (fileName) { | ||
| return bundle[fileName]; | ||
| }).filter(function (currentBundle) { | ||
| if (currentBundle.hasOwnProperty("type")) { | ||
| async generateBundle(outputOptions, bundle | ||
| /* , isWrite */ | ||
| ) { | ||
| const dataStrs = await Promise.all(Object.keys(bundle).map(fileName => bundle[fileName]).filter(currentBundle => { | ||
| if ({}.hasOwnProperty.call(currentBundle, "type")) { | ||
| return currentBundle.type !== "asset"; | ||
@@ -96,6 +156,12 @@ } | ||
| return !currentBundle.isAsset; | ||
| }).forEach(function (currentBundle) { | ||
| console.log(getData(outputOptions, currentBundle)); | ||
| }).map(currentBundle => { | ||
| return getLoggingData(outputOptions, currentBundle); | ||
| })); | ||
| dataStrs.forEach(str => { | ||
| if (str) { | ||
| console.log(str); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
@@ -105,1 +171,2 @@ } | ||
| module.exports = filesize; | ||
| //# sourceMappingURL=index.js.map |
+32
-22
| { | ||
| "name": "rollup-plugin-filesize", | ||
| "version": "7.0.0", | ||
| "version": "8.0.0-0", | ||
| "description": "A rollup plugin to show filesize in the cli", | ||
| "main": "dist/index.js", | ||
| "jsnext:main": "src/index.js", | ||
| "module": "src/index.js", | ||
| "files": [ | ||
@@ -13,7 +13,11 @@ "src", | ||
| "scripts": { | ||
| "test": "ava test/index.test.js", | ||
| "lint": "eslint .", | ||
| "test": "nyc ava test/index.test.js", | ||
| "pretest": "rollup -c", | ||
| "prepublish": "npm run test", | ||
| "prebuild": "rm -rf dist/*" | ||
| "prebuild": "rimraf dist/*" | ||
| }, | ||
| "engines": { | ||
| "node": ">=8.0.0" | ||
| }, | ||
| "repository": { | ||
@@ -27,2 +31,3 @@ "type": "git", | ||
| "author": "Ritesh Kumar", | ||
| "contributors": [], | ||
| "license": "MIT", | ||
@@ -34,30 +39,35 @@ "bugs": { | ||
| "dependencies": { | ||
| "boxen": "^4.1.0", | ||
| "boxen": "^4.2.0", | ||
| "brotli-size": "4.0.0", | ||
| "colors": "^1.3.3", | ||
| "filesize": "^4.1.2", | ||
| "colors": "^1.4.0", | ||
| "filesize": "^6.1.0", | ||
| "gzip-size": "^5.1.1", | ||
| "lodash.merge": "^4.6.2", | ||
| "terser": "^4.1.3" | ||
| "pacote": "^11.1.4", | ||
| "terser": "^4.6.11" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/core": "^7.5.5", | ||
| "@babel/preset-env": "^7.5.5", | ||
| "@babel/register": "^7.5.5", | ||
| "ava": "^2.2.0", | ||
| "@babel/core": "^7.9.0", | ||
| "@babel/plugin-syntax-import-meta": "^7.8.3", | ||
| "@babel/preset-env": "^7.9.5", | ||
| "@babel/register": "^7.9.0", | ||
| "@rollup/plugin-json": "^4.0.3", | ||
| "ava": "^3.7.1", | ||
| "babel-eslint": "^10.1.0", | ||
| "babel-register": "^6.26.0", | ||
| "prettier": "^1.18.2", | ||
| "rollup": "^1.19.4", | ||
| "rollup-plugin-babel": "^4.3.3" | ||
| "eslint": "^6.8.0", | ||
| "eslint-config-prettier": "^6.10.1", | ||
| "eslint-plugin-prettier": "^3.1.3", | ||
| "esm": "^3.2.25", | ||
| "nyc": "^15.0.1", | ||
| "prettier": "^2.0.4", | ||
| "rimraf": "^3.0.2", | ||
| "rollup": "^2.6.1", | ||
| "rollup-plugin-babel": "^4.4.0" | ||
| }, | ||
| "ava": { | ||
| "require": [ | ||
| "@babel/register" | ||
| "esm", | ||
| "./test/bootstrap/register.js" | ||
| ] | ||
| }, | ||
| "babel": { | ||
| "presets": [ | ||
| "@babel/preset-env" | ||
| ] | ||
| } | ||
| } |
+47
-12
@@ -30,2 +30,3 @@ # rollup-plugin-filesize | ||
| #### showMinifiedSize | ||
| type: `boolean` | ||
@@ -37,2 +38,3 @@ default: true | ||
| #### showGzippedSize | ||
| type: `boolean` | ||
@@ -44,2 +46,3 @@ default: true | ||
| #### showBrotliSize | ||
| type: `boolean` | ||
@@ -50,3 +53,26 @@ default: false | ||
| #### showBeforeSizes | ||
| **Note: this feature is experimental and may be changed in a future release.** | ||
| type: `"release", ``"build"`, or `"none"` | ||
| default: `"none"` | ||
| Indicates how, if any, comparisons will be shown between the | ||
| `output.file` file size as it was and as it is now being written. | ||
| If set to `"release"`, will compare the file size at present to that of | ||
| the last npm release. | ||
| If set to `"build"`, the size of the file that is now being built will | ||
| be compared to the immediately previous build. This means that if you run | ||
| Rollup multiple times with this option, the info on the previous package | ||
| size will be lost (since Rollup will have overwritten your copy), so with | ||
| this option, you will need to consult your terminal history to see what the | ||
| file size was prior to your changes. This option may be useful if you wish | ||
| to compare size changes incrementally as you are developing rather than | ||
| comparing to your last release. | ||
| #### format | ||
| type : `object` | ||
@@ -56,18 +82,30 @@ | ||
| See the options [here](https://github.com/avoidwork/filesize.js) | ||
| See the options [here](https://github.com/avoidwork/filesize.js#optional-settings) | ||
| #### render | ||
| type : `function` | ||
| #### reporter | ||
| return the command that you want to log. Eg: | ||
| (Note that this replaces the deprecated optional `render` function option.) | ||
| type : A reporter string (currently "boxen" only), a function, or an array thereof. | ||
| Defaults to "boxen". | ||
| After rendering occurs, you may wish to pass on the collected file data, | ||
| e.g., to build a badge for filesizes (as does [filesize-badger](https://github.com/brettz9/filesize-badger)). | ||
| You can use `reporter` to do so: | ||
| ```js | ||
| filesize({ | ||
| render : function (options, bundle, { minSize, gzipSize, brotliSize, bundleSize }){ | ||
| return minSize; | ||
| } | ||
| }) | ||
| reporter: [ | ||
| function (options, bundle, { minSize, gzipSize, brotliSize, bundleSize }) { | ||
| // If a promise is returned, it will be awaited before rendering. | ||
| return promise; | ||
| }, | ||
| ], | ||
| }); | ||
| ``` | ||
| #### theme | ||
| type: `string` | ||
@@ -81,7 +119,4 @@ | ||
| ## License | ||
| ## License | ||
| MIT | ||
+134
-62
@@ -0,72 +1,137 @@ | ||
| import { readFile as origReadFile, existsSync } from "fs"; | ||
| import { promisify } from "util"; | ||
| import { dirname, resolve as pathResolve, join } from "path"; | ||
| import fileSize from "filesize"; | ||
| import boxen from "boxen"; | ||
| import colors from "colors"; | ||
| import merge from "lodash.merge"; | ||
| import gzip from "gzip-size"; | ||
| import terser from "terser"; | ||
| import brotli from "brotli-size"; | ||
| import pacote from "pacote"; | ||
| const brotli = require("brotli-size"); | ||
| const readFile = promisify(origReadFile); | ||
| function render(opt, outputOptions, info) { | ||
| const primaryColor = opt.theme === "dark" ? "green" : "black"; | ||
| const secondaryColor = opt.theme === "dark" ? "yellow" : "blue"; | ||
| const thisDirectory = dirname(new URL(import.meta.url).pathname); | ||
| const title = colors[primaryColor].bold; | ||
| const value = colors[secondaryColor]; | ||
| export default function filesize(options = {}, env) { | ||
| let { | ||
| render, | ||
| format = {}, | ||
| theme = "dark", | ||
| showBeforeSizes = "none", | ||
| showGzippedSize = true, | ||
| showBrotliSize = false, | ||
| showMinifiedSize = true, | ||
| } = options; | ||
| const values = [ | ||
| ...(outputOptions.file ? | ||
| [`${title("Destination: ")}${value(outputOptions.file)}`] : | ||
| (info.fileName ? [`${title("Bundle Name: ")} ${value(info.fileName)}`] : [])), | ||
| ...[`${title("Bundle Size: ")} ${value(info.bundleSize)}`], | ||
| ...(info.minSize ? [`${title("Minified Size: ")} ${value(info.minSize)}`] : []), | ||
| ...(info.gzipSize ? [`${title("Gzipped Size: ")} ${value(info.gzipSize)}`] : []), | ||
| ...(info.brotliSize ? [`${title("Brotli size: ")}${value(info.brotliSize)}`] : []) | ||
| ]; | ||
| const getLoggingData = async function (outputOptions, bundle) { | ||
| const { code, fileName } = bundle; | ||
| const info = {}; | ||
| return boxen(values.join("\n"), { padding: 1 }); | ||
| } | ||
| let codeBefore; | ||
| if (showBeforeSizes !== "none") { | ||
| let file = outputOptions.file || outputOptions.dest; | ||
| if (showBeforeSizes !== "build") { | ||
| const { name } = await import(join(process.cwd(), "./package.json")); | ||
| try { | ||
| const output = join(thisDirectory, "../.cache"); | ||
| if (!existsSync(output)) { | ||
| await pacote.extract(`${name}@latest`, output); | ||
| } | ||
| file = join(output, file); | ||
| } catch (err) { | ||
| // Package might not exist | ||
| file = null; | ||
| } | ||
| } | ||
| export default function filesize(options = {}, env) { | ||
| let defaultOptions = { | ||
| format: {}, | ||
| theme: "dark", | ||
| render: render, | ||
| showGzippedSize: true, | ||
| showBrotliSize: false, | ||
| showMinifiedSize: true | ||
| }; | ||
| if (file) { | ||
| try { | ||
| codeBefore = await readFile(file, "utf8"); | ||
| } catch (err) { | ||
| // File might not exist | ||
| } | ||
| } | ||
| } | ||
| let opts = merge({}, defaultOptions, options); | ||
| if (options.render) { | ||
| opts.render = options.render; | ||
| } | ||
| info.fileName = fileName; | ||
| const getData = function(outputOptions, bundle) { | ||
| const { code, fileName } = bundle; | ||
| const info = {}; | ||
| info.bundleSize = fileSize(Buffer.byteLength(code), format); | ||
| info.fileName = fileName; | ||
| info.bundleSize = fileSize(Buffer.byteLength(code), opts.format); | ||
| info.brotliSize = opts.showBrotliSize | ||
| ? fileSize(brotli.sync(code), opts.format) | ||
| info.brotliSize = showBrotliSize | ||
| ? fileSize(await brotli(code), format) | ||
| : ""; | ||
| if (opts.showMinifiedSize || opts.showGzippedSize) { | ||
| if (showMinifiedSize || showGzippedSize) { | ||
| const minifiedCode = terser.minify(code).code; | ||
| info.minSize = opts.showMinifiedSize | ||
| ? fileSize(minifiedCode.length, opts.format) | ||
| info.minSize = showMinifiedSize | ||
| ? fileSize(minifiedCode.length, format) | ||
| : ""; | ||
| info.gzipSize = opts.showGzippedSize | ||
| ? fileSize(gzip.sync(minifiedCode), opts.format) | ||
| info.gzipSize = showGzippedSize | ||
| ? fileSize(gzip.sync(minifiedCode), format) | ||
| : ""; | ||
| } | ||
| return opts.render(opts, outputOptions, info); | ||
| if (codeBefore) { | ||
| info.bundleSizeBefore = fileSize(Buffer.byteLength(codeBefore), format); | ||
| info.brotliSizeBefore = showBrotliSize | ||
| ? fileSize(await brotli(codeBefore), format) | ||
| : ""; | ||
| if (showMinifiedSize || showGzippedSize) { | ||
| const minifiedCode = terser.minify(codeBefore).code; | ||
| info.minSizeBefore = showMinifiedSize | ||
| ? fileSize(minifiedCode.length, format) | ||
| : ""; | ||
| info.gzipSizeBefore = showGzippedSize | ||
| ? fileSize(gzip.sync(minifiedCode), format) | ||
| : ""; | ||
| } | ||
| } | ||
| const opts = { | ||
| format, | ||
| theme, | ||
| render, | ||
| showBeforeSizes, | ||
| showGzippedSize, | ||
| showBrotliSize, | ||
| showMinifiedSize, | ||
| }; | ||
| if (render) { | ||
| console.warn( | ||
| "`render` is now deprecated. Please use `reporter` instead." | ||
| ); | ||
| return opts.render(opts, outputOptions, info); | ||
| } | ||
| const reporters = options.reporter | ||
| ? Array.isArray(options.reporter) | ||
| ? options.reporter | ||
| : [options.reporter] | ||
| : ["boxen"]; | ||
| return ( | ||
| await Promise.all( | ||
| reporters.map(async (reporter) => { | ||
| if (typeof reporter === "string") { | ||
| let p; | ||
| if (reporter === "boxen") { | ||
| p = import( | ||
| dirname(new URL(import.meta.url).pathname) + | ||
| "/reporters/boxen.js" | ||
| ); | ||
| } else { | ||
| p = import(pathResolve(process.cwd(), reporter)); | ||
| } | ||
| reporter = (await p).default; | ||
| } | ||
| return reporter(opts, outputOptions, info); | ||
| }) | ||
| ) | ||
| ).join(""); | ||
| }; | ||
| if (env === "test") { | ||
| return getData; | ||
| return getLoggingData; | ||
| } | ||
@@ -76,16 +141,23 @@ | ||
| name: "filesize", | ||
| generateBundle(outputOptions, bundle, isWrite) { | ||
| Object.keys(bundle) | ||
| .map(fileName => bundle[fileName]) | ||
| .filter(currentBundle => { | ||
| if (currentBundle.hasOwnProperty("type")) { | ||
| return currentBundle.type !== "asset"; | ||
| } | ||
| return !currentBundle.isAsset; | ||
| }) | ||
| .forEach((currentBundle) => { | ||
| console.log(getData(outputOptions, currentBundle)) | ||
| }); | ||
| } | ||
| async generateBundle(outputOptions, bundle /* , isWrite */) { | ||
| const dataStrs = await Promise.all( | ||
| Object.keys(bundle) | ||
| .map((fileName) => bundle[fileName]) | ||
| .filter((currentBundle) => { | ||
| if ({}.hasOwnProperty.call(currentBundle, "type")) { | ||
| return currentBundle.type !== "asset"; | ||
| } | ||
| return !currentBundle.isAsset; | ||
| }) | ||
| .map((currentBundle) => { | ||
| return getLoggingData(outputOptions, currentBundle); | ||
| }) | ||
| ); | ||
| dataStrs.forEach((str) => { | ||
| if (str) { | ||
| console.log(str); | ||
| } | ||
| }); | ||
| }, | ||
| }; | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
30497
251.51%8
100%358
123.75%117
42.68%17
112.5%1
Infinity%5
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated
Updated