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

Example in project README does not work #26

Closed
4 tasks done
cgwrench opened this issue Jan 27, 2024 · 8 comments · Fixed by #27
Closed
4 tasks done

Example in project README does not work #26

cgwrench opened this issue Jan 27, 2024 · 8 comments · Fixed by #27
Labels
💪 phase/solved Post is done

Comments

@cgwrench
Copy link
Contributor

Initial checklist

Affected packages and versions

6.0.0

Link to runnable example

No response

Steps to reproduce

I attempted to run the example in the project README using the following steps:

  1. Create a new Node project:

    npm init es6 -y
  2. Install dependencies:

    npm install --save-exact dictionary-en retext retext-spell vfile-reporter
  3. Copy example:

    echo "import dictionaryEn from 'dictionary-en'
    import {retext} from 'retext'
    import retextSpell from 'retext-spell'
    import {reporter} from 'vfile-reporter'
    
    const file = await retext()
      .use(retextSpell, {dictionary: dictionaryEn})
      .process('Some useles documeant.')
    
    console.error(reporter(file))" > index.js
  4. Run example:

    node index.js

This throw an error:

file:///some/path/retext-spell-repro/node_modules/retext-spell/lib/index.js:106
    throw new TypeError('Missing `dictionary` in options')
          ^

TypeError: Missing `dictionary` in options
    at Function.retextSpell (file:///some/path/retext-spell-repro/node_modules/retext-spell/lib/index.js:106:11)
    at Function.freeze (file:///some/path/retext-spell-repro/node_modules/unified/lib/index.js:636:36)
    at Function.process (file:///some/path/retext-spell-repro/node_modules/unified/lib/index.js:716:10)
    at file:///some/path/retext-spell-repro/index.js:8:4

Node.js v21.5.0

Expected behavior

I would expect the code to run, with the example output given in the project README produced.

Affected runtime and version

[email protected]

Affected package manager and version

[email protected]

Affected OS and version

Arch Linux

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 27, 2024
@ChristianMurphy
Copy link
Member

Welcome @cgwrench! 👋
Sorry you ran into a spot of trouble.

Have you read https://github.com/orgs/retextjs/discussions/96#discussioncomment-7995777 ?
I think it is related to what you are seeing.

@cgwrench
Copy link
Contributor Author

Thanks @ChristianMurphy for such a quick response. That's exactly the same issue I'm seeing, and changing the loading of the dictionary to follow what's suggested in that discussion has fixed my issue.

Does the README in this repro need to be updated?

@ChristianMurphy
Copy link
Member

I'd lean yes, the documentation should be updated.
PRs are welcome!
@wooorm feel free to chime in if you feel otherwise.

@wooorm
Copy link
Member

wooorm commented Jan 28, 2024

Well we could change docs of course. Or we can add support for the new, simpler, API? I think I’d prefer that: to support the old and the new interface?

Indeed, want to work on a PR?

@cgwrench
Copy link
Contributor Author

Thanks @ChristianMurphy and @wooorm.

I'd love to try and contribute a fix. However, when looking into what might need to change, I found that there are tests that cover the various ways you can register a dictionary1. So I was at a bit of a loss trying to explain why I was seeing the issue I first reported in this issue. I've tracked in down to the version of dictionary-en. With the repro steps I outlined, I ended up with version 4.0.0 of dictionary-en, downgrading to version 3.0.0 meant that everything worked as expected.

I'm not sure what the correct change to make is so that retext-spell can handle both versions. Do either of you have an insights you cna share on what the best approach might be?

Footnotes

  1. See https://github.com/retextjs/retext-spell/blob/main/test.js#L23-L27, https://github.com/retextjs/retext-spell/blob/main/test.js#L46, and https://github.com/retextjs/retext-spell/blob/main/test.js#L177 for example.

@ChristianMurphy
Copy link
Member

@cgwrench one approach would be to check the typeof what is passed in.
If it is a fuction use the existing/old logic, if it is object use the new logic.

@cgwrench
Copy link
Contributor Author

cgwrench commented Feb 2, 2024

Thanks @ChristianMurphy. I've had a go at implementing this in #27. Let me know if you've got any feedback, or if there are any changes you'd like to see to how I've done this.

@wooorm wooorm closed this as completed in #27 Feb 5, 2024
wooorm pushed a commit that referenced this issue Feb 5, 2024
Closes GH-26.
Closes GH-27.

Reviewed-by: Titus Wormer <[email protected]>
@wooorm wooorm added the 💪 phase/solved Post is done label Feb 5, 2024
@wooorm
Copy link
Member

wooorm commented Feb 5, 2024

nice, thanks!

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

Successfully merging a pull request may close this issue.

3 participants