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

fix multi target #140

Merged
merged 2 commits into from
Jun 13, 2017
Merged

fix multi target #140

merged 2 commits into from
Jun 13, 2017

Conversation

ljqx
Copy link
Contributor

@ljqx ljqx commented May 26, 2017

Q A
Bug fix? yes
Breaking change? no
New feature? no
Deprecations? no
Tests added? no
Docs updated? no
Fixed tickets none
License MIT

This is a bug when running grunt webpack with multi targets. If we define multi targets for this plugin, then only 1 or 2 of them will run when user calls grunt webpack, and the tasks are picked randomly.

This is because this task is defined as a grunt basic task, but actually it is designed to be used as a grunt multi tasks. And when we call grunt webpack it should handle all targets, but now the code use a global done for all targets, any of them finished will cause this task done.

The test fail because of Grunt bug, I'll work on that fix first.

An example which repro the bug:

/* eslint no-process-env: 1, camelcase: 1 */
const path            = require('path');
const _               = require('underscore');
const webpack         = require('webpack');

module.exports = function (grunt) {
  function webpackConfig(dependency) {
    return {
      entry: require.resolve(dependency),
      output: {
        filename: `${dependency}.js`,
        path: path.join(__dirname, 'dist'),
        libraryTarget: 'amd',
      },
      module: {
        rules: [{
          test: () => true,
          use: 'imports-loader?define=>false',
        }],
      },
      externals: [
        ..._.keys(require(`${dependency}/package.json`).dependencies),
        'bluebird',
      ],
      devtool: 'inline-source-map',
      plugins: [
        new webpack.ProvidePlugin({
          Promise: 'bluebird',
        }),
      ],
    };
  }

  grunt.initConfig({
    webpack: {
      cldrjs: webpackConfig('cldrjs'),
      globalize: webpackConfig('globalize'),
      html2canvas: webpackConfig('html2canvas'),
    },
  });

  grunt.loadNpmTasks('grunt-webpack');

  grunt.registerTask('default', [
    'webpack',
  ]);
};

@jsf-clabot
Copy link

jsf-clabot commented May 26, 2017

CLA assistant check
All committers have signed the CLA.

@danez
Copy link
Collaborator

danez commented May 31, 2017

It is on purpose defined as Basic task as we use custom configurations which grunt cannot handle when using multitask. (#122)
But we need to fix that it is not running all targets

@codecov
Copy link

codecov bot commented Jun 1, 2017

Codecov Report

Merging #140 into master will increase coverage by 0.97%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #140      +/-   ##
==========================================
+ Coverage   67.67%   68.65%   +0.97%     
==========================================
  Files           8        8              
  Lines         198      201       +3     
  Branches       50       51       +1     
==========================================
+ Hits          134      138       +4     
  Misses         52       52              
+ Partials       12       11       -1
Impacted Files Coverage Δ
tasks/webpack.js 78.04% <100%> (+4.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6f7ed27...69a4e38. Read the comment docs.

@ljqx
Copy link
Contributor Author

ljqx commented Jun 1, 2017

@danez I've changed back to a basic task, thanks for the notice

@ljqx
Copy link
Contributor Author

ljqx commented Jun 5, 2017

@danez , weird that I've already signed the CLA agreement but it shows not here. Did I do something wrong? And why you prefer not add peerDependency grunt? it seems cleaner to me to know which versions of grunt this plugin supports..

@ljqx
Copy link
Contributor Author

ljqx commented Jun 5, 2017

ok, it's the email address, I'll fix it.

Update package.json
@ljqx
Copy link
Contributor Author

ljqx commented Jun 5, 2017

squashed to force update :) the license check passes now

tasks/webpack.js Outdated
@@ -64,7 +66,13 @@ module.exports = (grunt) => {
}
}

if (!opts.keepalive) done();
if (!opts.keepalive) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will have weird effects if different targets have different keepalive set. Can we instead maybe check every target and if at least one target has keepalive===true then do it?
So basically outside the forEach have

let keepalive = false;

and then for every target:

keepalive = keepalive || opts.keepalive;

Als the counter decrease has to be outside this if, as otherwise we can potentially never reach 0 right now if on target has keepalive true.

so maybe just simplify to

if (--runningTargetCount === 0 && !keepalive) done();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks

@danez
Copy link
Collaborator

danez commented Jun 10, 2017

Looks good besides the comment I made.

Would you be willing doing the same thing then also for webpack-dev-server? If not it's okay, I can easily duplicate.

@ljqx
Copy link
Contributor Author

ljqx commented Jun 12, 2017

@danez , OK, I'll do this in another PR.

@danez
Copy link
Collaborator

danez commented Jun 13, 2017

Thank you

@danez danez merged commit ddafd49 into webpack-contrib:master Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants