From c7c07ac180c790ab3284f2739bc54a3d792218d4 Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Sun, 4 Feb 2018 13:26:25 +0200 Subject: [PATCH] Move CLI-only function to CLI file --- packages/plugin/src/analyzer.js | 10 +--------- packages/plugin/src/bin/analyzer.js | 9 ++++++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/plugin/src/analyzer.js b/packages/plugin/src/analyzer.js index 48339cfb..f9196096 100644 --- a/packages/plugin/src/analyzer.js +++ b/packages/plugin/src/analyzer.js @@ -1,4 +1,3 @@ -const fs = require('fs'); const path = require('path'); const _ = require('lodash'); @@ -11,8 +10,7 @@ const FILENAME_QUERY_REGEXP = /\?.*$/; const MULTI_MODULE_REGEXP = /^multi /; module.exports = { - getChartData, - readStatsFromFile + getChartData }; function getViewerData(bundleStats, bundleDir, opts) { @@ -105,12 +103,6 @@ function getViewerData(bundleStats, bundleDir, opts) { }, []); } -function readStatsFromFile(filename) { - return JSON.parse( - fs.readFileSync(filename, 'utf8') - ); -} - function assetHasModule(statAsset, statModule) { return _.some(statModule.chunks, moduleChunk => _.includes(statAsset.chunks, moduleChunk) diff --git a/packages/plugin/src/bin/analyzer.js b/packages/plugin/src/bin/analyzer.js index 2a927f89..7d3971e9 100755 --- a/packages/plugin/src/bin/analyzer.js +++ b/packages/plugin/src/bin/analyzer.js @@ -1,6 +1,7 @@ #! /usr/bin/env node const { resolve, dirname } = require('path'); +const fs = require('fs'); const _ = require('lodash'); const commander = require('commander'); @@ -74,7 +75,7 @@ if (!bundleDir) bundleDir = dirname(bundleStatsFile); let bundleStats; try { - bundleStats = analyzer.readStatsFromFile(bundleStatsFile); + bundleStats = readStatsFromFile(bundleStatsFile); } catch (err) { console.error(`Could't read webpack bundle stats from "${bundleStatsFile}":\n${err}`); process.exit(1); @@ -106,3 +107,9 @@ function showHelp(error) { function br(str) { return `\n${_.repeat(' ', 28)}${str}`; } + +function readStatsFromFile(filename) { + return JSON.parse( + fs.readFileSync(filename, 'utf8') + ); +}