Skip to content
This repository was archived by the owner on Mar 10, 2024. It is now read-only.

-u option repetitively adding the same entry into ignoreUnresolved #190

Closed
foucdeg opened this issue Oct 28, 2023 · 6 comments · Fixed by #191
Closed

-u option repetitively adding the same entry into ignoreUnresolved #190

foucdeg opened this issue Oct 28, 2023 · 6 comments · Fixed by #191
Labels

Comments

@foucdeg
Copy link
Contributor

foucdeg commented Oct 28, 2023

In the file app/scripts/i18n.tsx I have the following code:

// In staging and prod, the SSR code loaded from the dist directory (output dir of Babel, see build-ssr)
// so the path to the locale files is not the same as in dev.
try {
  esTranslations = require("../../../app/assets/locales/es/translation.json")
} catch (e) {
  esTranslations = require("../assets/locales/es/translation.json")
}

unimported correctly flags the first import as unresolved. (In this environment the target file is located at the 2nd path)

Running npx unimported -u adds the following entry to ignoreUnresolved:

  "ignoreUnresolved": [
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]],
  ]

but it adds it repetitively; each time I run the command, the entry is added again.

After running the command three times, ignoreUnresolved looks like this:

  "ignoreUnresolved": [
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]],
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]],
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]]
  ]

No matter how many times this entry is present in ignoreUnresolved , npx unimported returns a non-zero status and complains about this unresolved import.

I've tried to ignore this error by adding into ignorePatterns :

    "../../../app/assets/locales/es/**",
    "app/assets/locales/es/**",
    "app/scripts/i18n.tsx",

but neither of these fixed the issue.

Current workaround is using npx unimported --show-unused-files --show-unused-deps.

@foucdeg foucdeg changed the title -u option repetitively adding the same entry into ignoreUnimported -u option repetitively adding the same entry into ignoreUnresolved Oct 29, 2023
@foucdeg
Copy link
Contributor Author

foucdeg commented Oct 29, 2023

This seems to be reproductible for any import syntax; after adding another entrypoint that includes

import Layout from "@theme/Layout" // <- unresolved

this entry also gets added to the config file when using -u despite being already present. After three runs of npx unimported -u I get:

  "ignoreUnresolved": [
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]],
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]],
    ["../../../app/assets/locales/es/translation.json", ["app/scripts/i18n.tsx"]],
    ["@theme/Layout", ["docusaurus/src/pages/index.tsx"]],
    ["@theme/Layout", ["docusaurus/src/pages/index.tsx"]],
    ["@theme/Layout", ["docusaurus/src/pages/index.tsx"]]
  ],

and a non-zero exit status every time for npx unimported.

@foucdeg
Copy link
Contributor Author

foucdeg commented Oct 29, 2023

It seems that the issue is when building the index of unresolvedImports:

https://github.com/smeijer/unimported/blob/main/src/process.ts#L32

Since each entry is not a simple string, this index doesn't have the shape it should.

@foucdeg
Copy link
Contributor Author

foucdeg commented Oct 29, 2023

Opened #191 with a fix.

@foucdeg
Copy link
Contributor Author

foucdeg commented Nov 18, 2023

Hi @smeijer I see you've responded to more recent issues recently, have you read this one and the PR?

@smeijer
Copy link
Owner

smeijer commented Nov 18, 2023

🎉 This issue has been resolved in version 1.31.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@smeijer
Copy link
Owner

smeijer commented Nov 18, 2023

Sorry about the delay @foucdeg , just slipped my mind. Also, appreciate the extensive explanation. Definitely simplified the review :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants