SamVerschueren / vscode-yo

Yeoman plugin for VS Code
MIT License
87 stars 15 forks source link

Error this.async is not a function #26

Closed RafaelGorski closed 8 years ago

RafaelGorski commented 8 years ago

Hi @SamVerschueren ,

First, great initiative to wrap yo inside the vscode! I got a error when I use it, I will try to explain the scenario.

When I try to use generator-generator from vscode the following error:

Error this.async is not a function

Steps: 1) yo 2) generator 3) <enter, confirming the suggestion> 4) error presented: Error this.async is not a function

Using the normal yo works fine:

yo
? 'Allo GORSKI! What would you like to do? Generator

Make sure you are in the directory you want to scaffold into.
This generator can also be run with: yo generator

? Your generator name generator-exploratory-test-cases-yo
Your generator must be inside a folder named generator-exploratory-test-cases-yo
I'll automatically create this folder.
? Description 

Versions: npm -v --> 3.3.12 node -v --> v5.3.0

SamVerschueren commented 8 years ago

Thanks for reporting. Will check it out asap.

SamVerschueren commented 8 years ago

I can reproduce, but no idea why this is causing an error. When using generator-nm, which uses this.async() as well, it works like a charm.

@SBoudrias sorry to bother :), but any idea?

SBoudrias commented 8 years ago

Anyway we can get a trace?

SamVerschueren commented 8 years ago

@SBoudrias No problem

TypeError: this.async is not a function
    at Object.module.exports.prompts.when (/Users/sam/.nvm/versions/node/v4.2.1/lib/node_modules/generator-generator/node_modules/inquirer-npm-name/lib/index.js:20:23)
    at /Users/sam/Projects/opensource/vscode-yo/out/yo/adapter.js:37:48

adapter.js:37:48 is refering to adapter.ts:48.

What is happening is that generator-generator is asking for a generator name, when the user provides a name, it checks if the name exists on npm in inquirer-npm-name and it is failing in the when clause here.

I wasn't aware it was possible to write the when clauses async. So apart from the context not being bound correctly, I probably have to rewrite the line adapter.ts:48 differently.

SBoudrias commented 8 years ago

@SamVerschueren ah yes, you're correct. Most Inquirer functions can be asynchronous. We're using run-aync to handle all of them. You might want to reuse that library too so it takes exactly the same signature.

SamVerschueren commented 8 years ago

@SBoudrias thanks! By using run-async, I am able to make it work :).

Can you elaborate which properties of this list can be async? The documentation isn't very clear about it. My best guess are these

But maybe default and message as well?

SamVerschueren commented 8 years ago

@RafaelGorski Should be fixed in v0.8.1.

SBoudrias commented 8 years ago

All of them can be async

SamVerschueren commented 8 years ago

Even the type and the name for example?

SBoudrias commented 8 years ago

default, choices (if defined as functions), validate, filter and when functions can be called asynchronously using this.async(). You just have to pass the value you'd normally return to the callback option.

RafaelGorski commented 8 years ago

@SamVerschueren @SBoudrias you rock!!!! cheers //Rafael

SamVerschueren commented 8 years ago

@SBoudrias sorry, missed that. Thanks for quoting and for your time!

@RafaelGorski you're welcome :)

SBoudrias commented 8 years ago

@SamVerschueren no worry, always happy to help.