Skip to content

Commit

Permalink
cli: implement --failAfterWarnings flag
Browse files Browse the repository at this point in the history
closes #3021
  • Loading branch information
tjenkinson committed Aug 10, 2020
1 parent 8333387 commit 6fdc3ef
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 37 deletions.
72 changes: 36 additions & 36 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ MIT, ISC
## acorn
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Repository: https://github.com/acornjs/acorn.git
Repository: git+https://github.com/acornjs/acorn.git

> Copyright (C) 2012-2018 by various contributors (see AUTHORS)
>
Expand All @@ -58,7 +58,7 @@ Repository: https://github.com/acornjs/acorn.git
## acorn-class-fields
License: MIT
By: Adrian Heine
Repository: https://github.com/acornjs/acorn-class-fields
Repository: git+https://github.com/acornjs/acorn-class-fields.git

> Copyright (C) 2017-2018 by Adrian Heine
>
Expand All @@ -85,7 +85,7 @@ Repository: https://github.com/acornjs/acorn-class-fields
## acorn-numeric-separator
License: MIT
By: Adrian Heine
Repository: https://github.com/acornjs/acorn-numeric-separator
Repository: git+https://github.com/acornjs/acorn-numeric-separator.git

> Copyright (C) 2017-2018 by Adrian Heine
>
Expand All @@ -112,7 +112,7 @@ Repository: https://github.com/acornjs/acorn-numeric-separator
## acorn-private-class-elements
License: MIT
By: Adrian Heine
Repository: https://github.com/acornjs/acorn-private-class-elements
Repository: git+https://github.com/acornjs/acorn-private-class-elements.git

> Copyright (C) 2017-2018 by Adrian Heine
>
Expand All @@ -139,7 +139,7 @@ Repository: https://github.com/acornjs/acorn-private-class-elements
## acorn-static-class-features
License: MIT
By: Adrian Heine
Repository: https://github.com/acornjs/acorn-static-class-features
Repository: git+https://github.com/acornjs/acorn-static-class-features.git

> Copyright (C) 2017-2018 by Adrian Heine
>
Expand All @@ -166,7 +166,7 @@ Repository: https://github.com/acornjs/acorn-static-class-features
## acorn-walk
License: MIT
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
Repository: https://github.com/acornjs/acorn.git
Repository: git+https://github.com/acornjs/acorn.git

> Copyright (C) 2012-2018 by various contributors (see AUTHORS)
>
Expand All @@ -193,7 +193,7 @@ Repository: https://github.com/acornjs/acorn.git
## anymatch
License: ISC
By: Elan Shanker
Repository: https://github.com/micromatch/anymatch
Repository: git+https://github.com/micromatch/anymatch.git

> The ISC License
>
Expand All @@ -216,14 +216,14 @@ Repository: https://github.com/micromatch/anymatch
## binary-extensions
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/binary-extensions
Repository: git+https://github.com/sindresorhus/binary-extensions.git

---------------------------------------

## braces
License: MIT
By: Jon Schlinkert, Brian Woodward, Elan Shanker, Eugene Sharygin, hemanth.hm
Repository: micromatch/braces
Repository: git+https://github.com/micromatch/braces.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -252,7 +252,7 @@ Repository: micromatch/braces
## camelcase
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/camelcase
Repository: git+https://github.com/sindresorhus/camelcase.git

---------------------------------------

Expand Down Expand Up @@ -288,7 +288,7 @@ Repository: git+https://github.com/paulmillr/chokidar.git
## colorette
License: MIT
By: Jorge Bucaran
Repository: jorgebucaran/colorette
Repository: git+https://github.com/jorgebucaran/colorette.git

> Copyright © Jorge Bucaran <<https://jorgebucaran.com>>
>
Expand All @@ -303,21 +303,21 @@ Repository: jorgebucaran/colorette
## date-time
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/date-time
Repository: git+https://github.com/sindresorhus/date-time.git

---------------------------------------

## decamelize
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/decamelize
Repository: git+https://github.com/sindresorhus/decamelize.git

---------------------------------------

## fill-range
License: MIT
By: Jon Schlinkert, Edo Rivai, Paul Miller, Rouven Weßling
Repository: jonschlinkert/fill-range
Repository: git+https://github.com/jonschlinkert/fill-range.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -346,7 +346,7 @@ Repository: jonschlinkert/fill-range
## glob-parent
License: ISC
By: Gulp Team, Elan Shanker, Blaine Bublitz
Repository: gulpjs/glob-parent
Repository: git+https://github.com/gulpjs/glob-parent.git

> The ISC License
>
Expand All @@ -369,13 +369,13 @@ Repository: gulpjs/glob-parent
## hash.js
License: MIT
By: Fedor Indutny
Repository: git@github.com:indutny/hash.js
Repository: git+ssh://git@github.com/indutny/hash.js.git

---------------------------------------

## inherits
License: ISC
Repository: git://github.com/isaacs/inherits
Repository: git://github.com/isaacs/inherits.git

> The ISC License
>
Expand All @@ -398,14 +398,14 @@ Repository: git://github.com/isaacs/inherits
## is-binary-path
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/is-binary-path
Repository: git+https://github.com/sindresorhus/is-binary-path.git

---------------------------------------

## is-extglob
License: MIT
By: Jon Schlinkert
Repository: jonschlinkert/is-extglob
Repository: git+https://github.com/jonschlinkert/is-extglob.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -434,7 +434,7 @@ Repository: jonschlinkert/is-extglob
## is-glob
License: MIT
By: Jon Schlinkert, Brian Woodward, Daniel Perez
Repository: micromatch/is-glob
Repository: git+https://github.com/micromatch/is-glob.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -463,7 +463,7 @@ Repository: micromatch/is-glob
## is-number
License: MIT
By: Jon Schlinkert, Olsten Larck, Rouven Weßling
Repository: jonschlinkert/is-number
Repository: git+https://github.com/jonschlinkert/is-number.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -499,14 +499,14 @@ Repository: git+https://github.com/Rich-Harris/is-reference.git
## locate-character
License: MIT
By: Rich Harris
Repository: Rich-Harris/locate-character
Repository: git+https://github.com/Rich-Harris/locate-character.git

---------------------------------------

## magic-string
License: MIT
By: Rich Harris
Repository: https://github.com/rich-harris/magic-string
Repository: git+https://github.com/rich-harris/magic-string.git

> Copyright 2018 Rich Harris
>
Expand All @@ -521,7 +521,7 @@ Repository: https://github.com/rich-harris/magic-string
## micromatch
License: MIT
By: Jon Schlinkert, Amila Welihinda, Bogdan Chadkin, Brian Woodward, Devon Govett, Elan Shanker, Fabrício Matté, Martin Kolárik, Olsten Larck, Paul Miller, Tom Byrer, Tyler Akins, Peter Bright
Repository: micromatch/micromatch
Repository: git+https://github.com/micromatch/micromatch.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -549,7 +549,7 @@ Repository: micromatch/micromatch

## minimalistic-assert
License: ISC
Repository: https://github.com/calvinmetcalf/minimalistic-assert.git
Repository: git+https://github.com/calvinmetcalf/minimalistic-assert.git

> Copyright 2015 Calvin Metcalf
>
Expand All @@ -570,7 +570,7 @@ Repository: https://github.com/calvinmetcalf/minimalistic-assert.git
## normalize-path
License: MIT
By: Jon Schlinkert, Blaine Bublitz
Repository: jonschlinkert/normalize-path
Repository: git+https://github.com/jonschlinkert/normalize-path.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -599,14 +599,14 @@ Repository: jonschlinkert/normalize-path
## parse-ms
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/parse-ms
Repository: git+https://github.com/sindresorhus/parse-ms.git

---------------------------------------

## picomatch
License: MIT
By: Jon Schlinkert
Repository: micromatch/picomatch
Repository: git+https://github.com/micromatch/picomatch.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -635,14 +635,14 @@ Repository: micromatch/picomatch
## pretty-bytes
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/pretty-bytes
Repository: git+https://github.com/sindresorhus/pretty-bytes.git

---------------------------------------

## pretty-ms
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/pretty-ms
Repository: git+https://github.com/sindresorhus/pretty-ms.git

---------------------------------------

Expand Down Expand Up @@ -685,14 +685,14 @@ Repository: git://github.com/kamicane/require-relative.git
## rollup-pluginutils
License: MIT
By: Rich Harris
Repository: rollup/rollup-pluginutils
Repository: git+https://github.com/rollup/rollup-pluginutils.git

---------------------------------------

## signal-exit
License: ISC
By: Ben Coe
Repository: https://github.com/tapjs/signal-exit.git
Repository: git+https://github.com/tapjs/signal-exit.git

> The ISC License
>
Expand All @@ -716,7 +716,7 @@ Repository: https://github.com/tapjs/signal-exit.git
## sourcemap-codec
License: MIT
By: Rich Harris
Repository: https://github.com/Rich-Harris/sourcemap-codec
Repository: git+https://github.com/Rich-Harris/sourcemap-codec.git

> The MIT License
>
Expand Down Expand Up @@ -745,14 +745,14 @@ Repository: https://github.com/Rich-Harris/sourcemap-codec
## time-zone
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/time-zone
Repository: git+https://github.com/sindresorhus/time-zone.git

---------------------------------------

## to-regex-range
License: MIT
By: Jon Schlinkert, Rouven Weßling
Repository: micromatch/to-regex-range
Repository: git+https://github.com/micromatch/to-regex-range.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -781,7 +781,7 @@ Repository: micromatch/to-regex-range
## yargs-parser
License: ISC
By: Ben Coe
Repository: https://github.com/yargs/yargs-parser.git
Repository: git+https://github.com/yargs/yargs-parser.git

> Copyright (c) 2016, Contributors
>
Expand Down
1 change: 1 addition & 0 deletions cli/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Basic options:
--preserveSymlinks Do not follow symlinks when resolving files
--shimMissingExports Create shim variables for missing exports
--silent Don't print warnings
--failAfterWarnings Exit with an error code if there was a warning during the build
--sourcemapExcludeSources Do not include source code in source maps
--sourcemapFile <file> Specify bundle position for source maps
--no-stdin do not read "-" from stdin
Expand Down
7 changes: 7 additions & 0 deletions cli/run/batchWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,27 @@ import { stderr } from '../logging';

export interface BatchWarnings {
add: (warning: RollupWarning) => void;
readonly total: number;
readonly count: number;
flush: () => void;
}

export default function batchWarnings() {
let deferredWarnings = new Map<keyof typeof deferredHandlers, RollupWarning[]>();
let total = 0;
let count = 0;

return {
get total() {
return total;
},

get count() {
return count;
},

add: (warning: RollupWarning) => {
total += 1;
count += 1;

if (warning.code! in deferredHandlers) {
Expand Down
6 changes: 6 additions & 0 deletions cli/run/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export default async function runRollup(command: any) {
for (const inputOptions of options) {
await build(inputOptions, warnings, command.silent);
}
if (command.failAfterWarnings && warnings.total) {
throw {
code: 'FAIL_AFTER_WARNINGS',
message: 'Warnings occurred and --failAfterWarnings flag present'
};
}
} catch (err) {
warnings.flush();
handleError(err);
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/utils/options/mergeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function mergeOptions(
'environment',
'plugin',
'silent',
'failAfterWarnings',
'stdin',
'waitForBundleInput'
),
Expand Down
9 changes: 9 additions & 0 deletions test/cli/samples/fail-after-warnings/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { assertIncludes } = require('../../../utils.js');

module.exports = {
description: 'errors on warnings with --failAfterWarnings',
command: 'rollup -i main.js --failAfterWarnings',
error: () => true,
stderr: stderr =>
assertIncludes(stderr, '[!] Warnings occurred and --failAfterWarnings flag present')
};
5 changes: 5 additions & 0 deletions test/cli/samples/fail-after-warnings/_expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

require('unknown');

console.log(42);

0 comments on commit 6fdc3ef

Please sign in to comment.