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

Boolean options passed to composeWith are set to false. #1033

Closed
agaray913 opened this issue Aug 11, 2017 · 1 comment
Closed

Boolean options passed to composeWith are set to false. #1033

agaray913 opened this issue Aug 11, 2017 · 1 comment
Labels

Comments

@agaray913
Copy link

agaray913 commented Aug 11, 2017

Issue:
When a parent generator passes a boolean option with a value of undefined to the composeWith function the sub-generators this.option method (in the sub-generator's constructor) converts the boolean option to false.

Versions:
"yeoman-generator": "1.1.0" and "1.1.1"

Simple example:

// In my-generator/generators/app/index.js
module.exports = class extends Generator {
  constructor(args, opts) {
    super(args, opts);
    this.option('opt1', {
      type: Boolean,
      description: 'opt1 :',
    });
  }
  initializing() {
    console.log('app opt1: ' + this.options['opt1']);
    this.composeWith(require.resolve('../gen1'), this.options);
  }
};

//sub-generator
module.exports = class extends Generator {
  constructor(args, opts) {
    super(args, opts);
    console.log('gen1 opt1: ' + this.options['opt1']);
    //A side affect of this function reassigns the value of op1 from undefined to false.
    this.option('opt1', {
      type: Boolean,
      description: 'opt1 :',
    });
    console.log('gen1 opt1: ' + this.options['opt1']);
  }

  prompting() {
    console.log('prompting - gen1');
  }

  writing() {
    console.log('writing - gen1');
  }
};

Output:

app opt1: undefined
gen1 opt1: undefined
gen1 opt1: false
prompting - gen1
writing - gen1

I traced the to problem back to the parseOptions function in yeoman-generator/lib/index.js. It looks like after the call to minimist the boolean options with value EMPTY are not converted to undefined.

Thanks,
Adrain

@github-actions
Copy link
Contributor

github-actions bot commented Jan 1, 2020

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 5 days

@github-actions github-actions bot added the stale label Jan 1, 2020
@github-actions github-actions bot closed this as completed Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant