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

[Bug]: import config not working with @cspell/dict-fr-fr in a subdirectory since v8.1.0 #5034

Closed
1 task done
esetnik opened this issue Dec 4, 2023 · 11 comments · Fixed by #5035
Closed
1 task done

Comments

@esetnik
Copy link

esetnik commented Dec 4, 2023

Kind of Issue

Runtime - command-line tools

Tool or Library

cspell

Version

v8.1.0

Supporting Library

No response

OS

ALL

OS Version

No response

Description

After v8.1.0 we receive the error Configuration Error: Failed to resolve file: "node_modules/@cspell/dict-fr-fr/cspell-ext.json"

The import path appears to be incorrect given what we are providing in the config.

Steps to Reproduce

  1. Use the below cspell.json
  2. Use a subdirectory for node_modules / yarn, e.g. frontend
  3. Tell the root cspell.json to import the french dictionaries from the subdirectory

Expected Behavior

Behavior should not change between v8.0.0 (working) and v8.1.0 (not working). There is no release note indicating that cspell no longer supports relative config imports from a subdirectory.

The path node_modules/@cspell/dict-fr-fr/cspell-ext.json is incorrect and not what is being supplied in the config. It should be ./frontend/node_modules/@cspell/dict-fr-fr/cspell-ext.json

Additional Information

Test cases should be added for this common scenario to prevent future regression

cspell.json

{
  "version": "0.2",
  "ignorePaths": [
    ".neoconf.json",
    ".vscode/settings.json",
    ".vim/coc-settings.json",
    "frontend/node_modules/**",
    "frontend/coverage/**",
    "frontend/build/**",
    "frontend/db/dist/**",
    "frontend/package.json",
    "frontend/public/locales/ar/**",
    "frontend/public/locales/zgh/**",
    "frontend/public/supportedBrowsers.js",
    "docker-compose*.yml",
    "cloudformation.yml",
    "vendor",
    "web/src/composer.json",
    "web/src/vendor",
    "web/src/shared/scripts",
    "web/src/css",
    "web/src/locales/ar/translations.yml",
    "node/src/locales/ar.json",
    "web/src/locales/zgh/translations.yml",
    "web/src/api/Validation/lang/ar/validation.php",
    ".env",
    "renovate.json",
    "web/conf/**/*",
    "*Dockerfile"
  ],
  "allowCompoundWords": true,
  "ignoreWords": [
    "culturehq",
    "yiisoft",
    "lintstagedrc",
    "rehype",
    "noto",
    "graphiql",
    "webp"
  ],
  "words": [
    "AMZN",
    "capce",
    "cedata",
    "crunz",
    "cronitor",
    "destructured",
    "droppable",
    "entityid",
    "esetnik",
    "esnext",
    "falsey",
    "Gravatar",
    "hacky",
    "Handtevy",
    "hocs",
    "iframe",
    "imgix",
    "immer",
    "junit",
    "jwplayer",
    "JWPLAYER",
    "Lngs",
    "luxon",
    "Maknz",
    "Mebibytes",
    "msodbcsql",
    "newid",
    "noopener",
    "NREMT",
    "nuka",
    "oems",
    "onstatechange",
    "onupdatefound",
    "phpcs",
    "phpcbf",
    "phuocng",
    "recertification",
    "reduxjs",
    "resizer",
    "signup",
    "testid",
    "tamazight",
    "tifinagh",
    "tsql",
    "Tuupola",
    "unmount",
    "unregister",
    "UPDLOCK",
    "wdyr",
    "xlarge"
  ],
  "import": ["./frontend/node_modules/@cspell/dict-fr-fr/cspell-ext.json"],
  "overrides": [
    {
      "filename": "**/locales/fr/**/{*.json,*.yml}",
      "language": "en,fr"
    },
    {
      "filename": "**/__test__/**",
      "language": "en,fr"
    },
    {
      "filename": "**/{*.test.ts,*.test.tsx}",
      "language": "en,fr"
    },
    {
      "filename": "**/Validation/lang/fr/validation.php",
      "language": "en,fr"
    },
    {
      "filename": "node/src/locales/fr.json",
      "language": "en,fr"
    },
    {
      "filename": "frontend/src/themes/*.json",
      "languageId": "css"
    }
  ]
}

cspell.config.yaml

No response

Example Repository

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Jason3S
Copy link
Collaborator

Jason3S commented Dec 4, 2023

@esetnik,

I'll take a look. Relative imports are expected to work.

@Jason3S
Copy link
Collaborator

Jason3S commented Dec 4, 2023

@esetnik,

I'm not able to reproduce the issue.

Just to be clear, your repository looks like this?

repo-root
|- cspell.json
|- frontend
   |- node_modules/@cspell/dict-fr-fr/cspell-ext.json

Jason3S added a commit that referenced this issue Dec 4, 2023
So far it is not possible to reproduce.
@esetnik
Copy link
Author

esetnik commented Dec 4, 2023

That's correct. And we are calling cspell from the root directory using yarn like this:

❯ yarn --cwd frontend spellcheck

yarn run v1.22.21
$ cspell -c '../.cspell.json' -r '..' --no-progress --dot --gitignore "**/*.{php,js,jsx,ts,tsx,json,yml}"
Configuration Error: Failed to resolve file: "node_modules/@cspell/dict-fr-fr/cspell-ext.json"
CSpell: Files checked: 1247, Issues found: 0 in 0 files
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

frontend/package.json

{
  "name": "frontend",
  "version": "2.34.4",
  "private": true,
  "dependencies": {},
  "scripts": {
    "spellcheck": "cspell -c '../.cspell.json' -r '..' --no-progress --dot --gitignore \"**/*.{js,jsx,ts,tsx,json,yml}\"",
  },
  "devDependencies": {
    "@cspell/dict-fr-fr": "2.2.2",
    "cspell": "8.1.0"
  }
}

Repo heirarchy:

repo-root
|- .cspell.json
|- frontend
   |- node_modules/@cspell/dict-fr-fr/cspell-ext.json
   |- package.json

@Jason3S
Copy link
Collaborator

Jason3S commented Dec 4, 2023

@esetnik,

I'm having trouble reproducing the issue.

image

I tried copying your config.

@Jason3S
Copy link
Collaborator

Jason3S commented Dec 4, 2023

@Jason3S
Copy link
Collaborator

Jason3S commented Dec 5, 2023

@esetnik,

Do you have any other *cspell* configuration files around? Since it did not find any issues -- CSpell: Files checked: 1247, Issues found: 0 in 0 files -- I'm assuming it was able to load the French dictionary.

The spell checker will search for the nearest config file when spell checking file.

Please try adding "noConfigSearch": true to .cspell.json. See: noConfigSearch.

@esetnik
Copy link
Author

esetnik commented Dec 5, 2023

@esetnik,

Do you have any other *cspell* configuration files around? Since it did not find any issues -- CSpell: Files checked: 1247, Issues found: 0 in 0 files -- I'm assuming it was able to load the French dictionary.

The spell checker will search for the nearest config file when spell checking file.

Please try adding "noConfigSearch": true to .cspell.json. See: noConfigSearch.

@Jason3S that was the issue. I didn't realize I had a second .cspell.json file in a subdirectory that had some overrides in it. It seems as though something changed with the path resolution between v8.0.0 and v8.1.0 because it was working previously.

File path: frontend/public/locales/fr/.cspell.json

Used to work before v8.1.0:

{
  "import": ["node_modules/@cspell/dict-fr-fr/cspell-ext.json"],
  "language": "en,fr"
}

Works as of v8.1.0:

{
  "import": ["@cspell/dict-fr-fr/cspell-ext.json"],
  "language": "en,fr"
}

@Jason3S
Copy link
Collaborator

Jason3S commented Dec 6, 2023

@esetnik,

That is good news.

The way the imported path was resolved changed to support ESM Module imports. If the path had been "./node_modules/@cspell/dict-fr-fr/cspell-ext.json", it should have worked. Without the ./ it assumes it is a module.

I'll see if it reasonable to bring back the old behavior.

@Jason3S Jason3S linked a pull request Dec 6, 2023 that will close this issue
Jason3S added a commit that referenced this issue Dec 6, 2023
So far it is not possible to reproduce.
@esetnik
Copy link
Author

esetnik commented Dec 6, 2023

This is great, thanks for your help @Jason3S

@Jason3S
Copy link
Collaborator

Jason3S commented Dec 6, 2023

@esetnik,

The fix is in 8.1.3. There will be a warning if the import starts with node_modules instead of ./node_modules but the file will still load.

Copy link
Contributor

github-actions bot commented Jan 6, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants