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

initial prop doesn't seem to work #274

Open
warflash opened this issue Jan 20, 2024 · 2 comments
Open

initial prop doesn't seem to work #274

warflash opened this issue Jan 20, 2024 · 2 comments

Comments

@warflash
Copy link

Environment

node: v18.18.0
consola: 3.2.3

Reproduction

https://stackblitz.com/edit/stackblitz-starters-wxmucj?file=index.js,package.json

Describe the bug

Setting the initial prop of promps doesn't seem to work. The repro above is taken from the example code in the repo https://github.com/unjs/consola/blob/main/examples/prompt.ts

Additional context

No response

Logs

No response

@peterroe
Copy link
Contributor

peterroe commented Jan 20, 2024

I looked hard to find out why.

I find the consola/dist/chunks/prompt.mjs file produced by the repository building and the one distributed via npm are different.

In https://www.npmjs.com/package/consola?activeTab=code file:consola/dist/chunks/prompt.mjs line: 409-425

The expected product should be:

  if (opts.type === "select") {
    return await select({
      message,
      options: opts.options.map(
        (o) => typeof o === "string" ? { value: o, label: o } : o
      )
+     initialValue: opts.initial
    });
  }
  if (opts.type === "multiselect") {
    return await multiselect({
      message,
      options: opts.options.map(
        (o) => typeof o === "string" ? { value: o, label: o } : o
      ),
      required: opts.required,
+      initialValue: opts.initial
    });
  }

Maybe we should release a new version soon. :) cc @pi0

@LekoArts
Copy link

LekoArts commented Feb 9, 2024

You can install from GitHub so long, (e.g. with pnpm https://pnpm.io/cli/add#install-from-git-repository). Or use https://www.npmjs.com/package/patch-package

I created a fork and added a prepare script so that the package gets built:
https://github.com/LekoArts/consola/tree/prepare-script

Then with pnpm you can use:

pnpm add github:LekoArts/consola#prepare-script

@pi0 Can you release a new version please? Thanks a lot!

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

No branches or pull requests

3 participants