size-limit
Advanced tools
Comparing version 4.1.1 to 4.2.0
39
calc.js
@@ -1,10 +0,25 @@ | ||
module.exports = async function calc (plugins, config) { | ||
async function exec (step) { | ||
module.exports = async function calc (plugins, config, createSpinner) { | ||
process.setMaxListeners(config.checks.reduce((a, i) => a + i.path.length, 0)) | ||
async function step (number) { | ||
for (let plugin of plugins.list) { | ||
if (plugin[step]) { | ||
process.setMaxListeners(config.checks.reduce((all, check) => { | ||
return all + check.path.length | ||
}, 0)) | ||
await Promise.all(config.checks.map(i => plugin[step](config, i))) | ||
let spinner | ||
if (plugin['wait' + number] && createSpinner) { | ||
spinner = createSpinner(plugin['wait' + number]).start() | ||
} | ||
if (plugin['step' + number] || plugin['all' + number]) { | ||
try { | ||
if (plugin['all' + number]) { | ||
await plugin['all' + number](config) | ||
} else { | ||
await Promise.all(config.checks.map(i => { | ||
return plugin['step' + number](config, i) | ||
})) | ||
} | ||
} catch (e) { | ||
if (spinner) spinner.fail() | ||
throw e | ||
} | ||
} | ||
if (spinner) spinner.succeed() | ||
} | ||
@@ -14,5 +29,11 @@ } | ||
try { | ||
for (let i = 0; i <= 100; i++) await exec(`step${ i }`) | ||
for (let i = 0; i <= 100; i++) await step(i) | ||
} finally { | ||
exec('finally') | ||
for (let plugin of plugins.list) { | ||
if (plugin.finally) { | ||
await Promise.all(config.checks.map(i => { | ||
return plugin.finally(config, i) | ||
})) | ||
} | ||
} | ||
} | ||
@@ -19,0 +40,0 @@ for (let check of config.checks) { |
@@ -68,3 +68,3 @@ let { isAbsolute, dirname, join, relative } = require('path') | ||
function makeAbsolute (file, cwd) { | ||
function toAbsolute (file, cwd) { | ||
return isAbsolute(file) ? file : join(cwd, file) | ||
@@ -78,3 +78,5 @@ } | ||
module.exports = async function getConfig (plugins, process, args, pkg) { | ||
let config = { } | ||
let config = { | ||
cwd: process.cwd() | ||
} | ||
if (args.why) { | ||
@@ -85,8 +87,6 @@ config.project = pkg.packageJson.name | ||
if (args.saveBundle) { | ||
config.saveBundle = makeAbsolute(args.saveBundle, process.cwd()) | ||
config.saveBundle = toAbsolute(args.saveBundle, process.cwd()) | ||
} | ||
let cwd | ||
if (args.files.length > 0) { | ||
cwd = process.cwd() | ||
config.checks = [{ path: args.files }] | ||
@@ -108,6 +108,6 @@ } else { | ||
config.configPath = relative(process.cwd(), result.filepath) | ||
cwd = dirname(result.filepath) | ||
config.cwd = dirname(result.filepath) | ||
config.checks = await Promise.all(result.config.map(async check => { | ||
if (check.path) { | ||
check.path = await globby(check.path, { cwd: dirname(result.filepath) }) | ||
check.path = await globby(check.path, { cwd: config.cwd }) | ||
} else if (!check.entry) { | ||
@@ -130,3 +130,3 @@ if (pkg.packageJson.main) { | ||
if (check.entry && !Array.isArray(check.entry)) check.entry = [check.entry] | ||
if (!check.name) check.name = toName(check.entry || check.path, cwd) | ||
if (!check.name) check.name = toName(check.entry || check.path, config.cwd) | ||
if (args.limit) check.limit = args.limit | ||
@@ -145,4 +145,4 @@ if (check.limit) { | ||
} | ||
if (check.path) check.path = check.path.map(i => makeAbsolute(i, cwd)) | ||
if (check.config) check.config = makeAbsolute(check.config, cwd) | ||
if (check.path) check.path = check.path.map(i => toAbsolute(i, config.cwd)) | ||
if (check.config) check.config = toAbsolute(check.config, config.cwd) | ||
} | ||
@@ -149,0 +149,0 @@ |
@@ -19,3 +19,3 @@ let { Plugins } = require('./load-plugins') | ||
await calc(pluginList, files) | ||
await calc(pluginList, files, false) | ||
@@ -22,0 +22,0 @@ return files.checks.map(i => { |
{ | ||
"name": "size-limit", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "CLI tool for Size Limit", | ||
@@ -8,2 +8,3 @@ "keywords": [ | ||
"cli", | ||
"esm", | ||
"performance", | ||
@@ -26,4 +27,5 @@ "budget", | ||
"globby": "^11.0.0", | ||
"ora": "^4.0.3", | ||
"read-pkg-up": "^7.0.1" | ||
} | ||
} |
let readPkgUp = require('read-pkg-up') | ||
let ora = require('ora') | ||
@@ -45,3 +46,3 @@ let SizeLimitError = require('./size-limit-error') | ||
await calc(plugins, config) | ||
await calc(plugins, config, ora) | ||
@@ -48,0 +49,0 @@ debug.results(process, args, config) |
@@ -54,2 +54,5 @@ const MESSAGES = { | ||
'Update your Node.js to version >= v11.7.0 to use Brotli' | ||
), | ||
cmdError: (cmd, error) => ( | ||
error ? `${ cmd } error: ${ error }` : `${ cmd } error` | ||
) | ||
@@ -56,0 +59,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22598
637
7
+ Addedora@^4.0.3
+ Addedansi-regex@5.0.1(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcli-cursor@3.1.0(transitive)
+ Addedcli-spinners@2.9.2(transitive)
+ Addedclone@1.0.4(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addeddefaults@1.0.4(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedis-interactive@1.0.0(transitive)
+ Addedlog-symbols@3.0.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addedmute-stream@0.0.8(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedora@4.1.1(transitive)
+ Addedrestore-cursor@3.1.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedwcwidth@1.0.1(transitive)