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

Allow YAML or JS format for configuration file #118

Closed
matbour opened this issue Nov 24, 2022 · 5 comments · Fixed by #178
Closed

Allow YAML or JS format for configuration file #118

matbour opened this issue Nov 24, 2022 · 5 comments · Fixed by #178

Comments

@matbour
Copy link

matbour commented Nov 24, 2022

My application is using the @uniswap/widgets package which for some reason does not install the necessary packages by himself and I add to install some dependencies manually.

This is my current configuration:

{
  "entry": [
    "src/pages/**/*.page.{ts,tsx}",
    "src/worker/index.ts",
    "next.config.js",
    "cypress/e2e/*.cy.ts",
    "cypress/support/e2e.ts"
  ],
  "ignorePatterns": ["**/node_modules/**", "public/**"],
  "ignoreUnimported": ["src/icons/IconTemplate.js"],

  "__note": "@ethersproject/abi jotai-immer are required by @uniswap/widgets",
  "ignoreUnused": ["next", "react", "react-dom", "@ethersproject/abi", "jotai-immer"],
  "ignoreUnresolved": ["tslib", "cross-fetch", "extract-files", "form-data"]
}

As you can see, there is a pseudo-comment explaining why I am ignoring @ethersproject/abi and jotai-immer packages.

I would like to be able to write the configuration file as a YAML file which will allow comments:

entry:
- src/pages/**/*.page.{ts,tsx}
- src/worker/index.ts
- next.config.js
- cypress/e2e/*.cy.ts
- cypress/support/e2e.ts
ignorePatterns:
- "**/node_modules/**"
- public/**
ignoreUnimported:
- src/icons/IconTemplate.js

ignoreUnused:
- next
- react
- react-dom
# Required by @uniswap/widgets
- "@ethersproject/abi"
- jotai-immer

ignoreUnresolved:
- tslib
- cross-fetch
- extract-files
- form-data

Happy to open a PR if interested.

@matbour matbour changed the title Allow YAML or JS format for configuration file. Allow YAML or JS format for configuration file Nov 24, 2022
@smeijer
Copy link
Owner

smeijer commented Nov 24, 2022

I'd be happy to accept a pull that adds https://www.npmjs.com/package/cosmiconfig. That way we'd support pretty much all config preferences in one run.

@smeijer smeijer added good first issue Good for newcomers feature labels Mar 2, 2023
@dwjohnston
Copy link

I would absolutely find this helpful. It's nice to be able to comment why you are ignoring a thing.

@smeijer
Copy link
Owner

smeijer commented Jun 29, 2023

Still happy to accept a pull-request that adds cosmiconfig to read the config file.

@ryanwilsonperkin
Copy link
Collaborator

@smeijer I've taken a shot at cosmiconfig functionality here #178 in order to solve this issue, as we'd like to be able to use a .js config file

smeijer added a commit that referenced this issue Sep 22, 2023
Fixes #118 

Introduces `cosmiconfig` as requested in #118 in order to support
loading the config from alternative file formats like:
```
.unimportedrc.js
.unimportedrc.yml
package.json > "unimported" key
```

I'm using `cosmiconfigSync` utilities instead of the async version,
despite them being available since the `getConfig` is an async method.
When we use the async equivalent, we hit a segfault in Node as a result
of `cosmiconfig` trying to call a dynamic import on the file within a
Jest context that doesn't allow it to. Patched in a recent version of
Node, and once the test infra can require the latest version it should
be fine to switch to the async version.

See nodejs/node#35889 and
jestjs/jest#11438

I haven't made any efforts to change the `update` function to write
updates to the loaded files, as this would be difficult/impossible to
update something like a .js or .yml (if using features like anchors) in
a meaningful way.

A few notes on the other changes included:
1. `cosmiconfig` pulls in a newer version of TypeScript which was
incompatible with the version of `@types/node` we used, updated it
2. One of the tests produced invalid JSON to a config file, which failed
silently before and passed the test, but now fails loudly when
`cosmiconfig` tries to read and parse the JSON. Updated it to be valid
to fulfill the spirit of the test.

---------

Co-authored-by: Stephan Meijer <[email protected]>
@smeijer
Copy link
Owner

smeijer commented Sep 22, 2023

🎉 This issue has been resolved in version 1.30.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

4 participants