Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Stats): recursively get warnings or errors of a stats and its children #11438

Closed
wants to merge 2 commits into from

Conversation

harrisoff
Copy link

What kind of change does this PR introduce?

a feature

Did you add tests for your changes?

yes

Does this PR introduce a breaking change?

no

What needs to be documented once your changes are merged?

add getWarnings() and getErrors() methods to Stats object API

@jsf-clabot
Copy link

jsf-clabot commented Sep 8, 2020

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is use case?

@harrisoff
Copy link
Author

harrisoff commented Sep 8, 2020

https://github.com/harrisoff/move-assets-webpack-plugin/blob/master/test/index.test.js#L210

I copied function webpack() from clean-webpack-plugin as part of my test codes.

function webpack(options: Configuration = {}) {
    const webpackActual = require('webpack');

    // https://webpack.js.org/concepts/mode/
    if (
        options.mode === undefined &&
        options.mode !== null &&
        webpackMajor !== null &&
        webpackMajor >= 4
    ) {
        // eslint-disable-next-line no-param-reassign
        options.mode = 'development';
    }

    if (options.mode === null) {
        // eslint-disable-next-line no-param-reassign
        delete options.mode;
    }

    const compiler = webpackActual(options);

    const runAsync = () =>
        new Promise((resolve, reject) => {
            compiler.run((error: Error, stats: Stats) => {
                if (error || stats.hasErrors()) {
                    reject(error);

                    return;
                }

                resolve(stats);
            });
        });

    return { ...compiler, run: runAsync };
}

And in my test codes, I used copy-webpack-plugin:

try {
  const options = {
    plugins: [
      new CopyPlugin({
        patterns: [
          {
            from: fePublicPath,
            to: feDistPath,
            globOptions: {
              ignore: [
                'index.html',
                {
                  glob: 'index.html',
                  matchBase: false,
                },
              ],
            },
          },
        ],
      }),
    ]
  }
  const stats = await webpack(config).run()
} catch (error) {
  console.error(error)
}

globOptions.ignore should be an array of strings, but I set an object by mistake.

stats.hasErrors() is true so runAsync() throws an error, however outside the webpack() function I could only get a null.

stats.hasErrors() returns true not only when this stats encountered errors, but also its children. So I think maybe there should be a method to return them.

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

@webpack-bot
Copy link
Contributor

@ The most important CI builds failed. This way your PR can't be merged.

Please take a look at the CI results from azure (2 errors / 1 warnings) and appveyor (failure) and fix these issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants