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

Add useful error on empty presets #202

Merged
merged 2 commits into from
Aug 9, 2023
Merged

Add useful error on empty presets #202

merged 2 commits into from
Aug 9, 2023

Conversation

wooorm
Copy link
Member

@wooorm wooorm commented Oct 12, 2022

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

Empty presets are most likely a mistake by the user. At best, they do nothing.
This improves the situation for humans that make mistakes, by throwing a useful error.

Closes GH-200.

Empty presets are most likely a mistake by the user.
At best, they do nothing.
This improves the situation for humans that make mistakes,
by throwing a useful error.

Closes GH-200.
@github-actions github-actions bot added the 👋 phase/new Post is being triaged automatically label Oct 12, 2022
@wooorm wooorm added 🦋 type/enhancement This is great to have 🧑 semver/major This is a change 👍 phase/yes Post is accepted and can be worked on and removed 👋 phase/new Post is being triaged automatically labels Oct 12, 2022
@github-actions github-actions bot added 🤞 phase/open Post is being triaged manually and removed 👍 phase/yes Post is accepted and can be worked on 🤞 phase/open Post is being triaged manually labels Oct 12, 2022
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@wooorm wooorm added the 👍 phase/yes Post is accepted and can be worked on label Oct 12, 2022
'Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither'
)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update the types to reflect this?

interface PresetWithPlugins {
  plugins: PluggableList
  settings?: Record<string, unknown>
}

interface PresetWithSettings {
  plugins?: PluggableList
  settings: Record<string, unknown>
}

export type Preset = PresetWithPlugins | PresetWithSettings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d say that makes errors harder to read, when something is wrong, TS will try to match both, and show both.
For a small gain?

@remcohaszing
Copy link
Member

remcohaszing commented Oct 13, 2022

Since this is semver major, this would also be a good time to consider other breaking changes. The first thing that comes to mind if officially dropping support for Node.js 12.

Signed-off-by: Titus <tituswormer@gmail.com>
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4a94722) 100.00% compared to head (77f3d97) 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #202   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          596       602    +6     
=========================================
+ Hits           596       602    +6     
Files Changed Coverage Δ
lib/index.js 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wooorm wooorm merged commit b35afe0 into main Aug 9, 2023
@wooorm wooorm deleted the throw-on-useless-presets branch August 9, 2023 13:30
@wooorm wooorm added the 💪 phase/solved Post is done label Aug 9, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 👍 phase/yes Post is accepted and can be worked on label Aug 9, 2023
kodiakhq bot referenced this pull request in X-oss-byte/Nextjs Oct 16, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [unified](https://unifiedjs.com) ([source](https://togithub.com/unifiedjs/unified)) | [`8.4.2` -> `11.0.3`](https://renovatebot.com/diffs/npm/unified/8.4.2/11.0.3) | [![age](https://developer.mend.io/api/mc/badges/age/npm/unified/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/unified/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/unified/8.4.2/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/unified/8.4.2/11.0.3?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>unifiedjs/unified (unified)</summary>

### [`v11.0.3`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.3)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.2...11.0.3)

##### Fix

-   [`8dee2ab`](https://togithub.com/unifiedjs/unified/commit/8dee2ab) Fix support for functions in data

**Full Changelog**: unifiedjs/unified@11.0.2...11.0.3

### [`v11.0.2`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.2)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.1...11.0.2)

-   [`cea788b`](https://togithub.com/unifiedjs/unified/commit/cea788b) Fix type of settings if nothing is registered yet

**Full Changelog**: unifiedjs/unified@11.0.1...11.0.2

### [`v11.0.1`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/11.0.0...11.0.1)

-   [`d1a915d`](https://togithub.com/unifiedjs/unified/commit/d1a915d) Fix incorrect type of `settings` in presets

**Full Changelog**: unifiedjs/unified@11.0.0...11.0.1

### [`v11.0.0`](https://togithub.com/unifiedjs/unified/releases/tag/11.0.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.1.2...11.0.0)

##### Change

-   [`baf80b2`](https://togithub.com/unifiedjs/unified/commit/baf80b2) Change to require Node.js 16
    **migrate**: update too
-   [`dd9834a`](https://togithub.com/unifiedjs/unified/commit/dd9834a) Update `@types/unist`
    **migrate**: update too
-   [`620ccf9`](https://togithub.com/unifiedjs/unified/commit/620ccf9) Update [`vfile`](https://togithub.com/vfile/vfile/releases/tag/6.0.0)
    **migrate**: update too

##### Change (unlikey to affect you)

-   [`a44db46`](https://togithub.com/unifiedjs/unified/commit/a44db46) Add `Data`, `Settings` types to augment shared data
    **migrate**: if you deal with data, type it, see commit for info
-   [`fb49556`](https://togithub.com/unifiedjs/unified/commit/fb49556) Change to replace `Buffer` with `Uint8Array`
    **migrate**: you’re probably fine unless you use weird encodings, see commit for details if so
-   [`f3e71a8`](https://togithub.com/unifiedjs/unified/commit/f3e71a8) Remove `Attacher` type
    **migrate**: use `Plugin` instead
-   [`cc53bb6`](https://togithub.com/unifiedjs/unified/commit/cc53bb6) Remove `FrozenProcessor` type
    **migrate**: use `Processor` instead
-   [`1aa3494`](https://togithub.com/unifiedjs/unified/commit/1aa3494) Change to yield `undefined`, not `null`
    **migrate**: expect `undefined`
-   [`932c140`](https://togithub.com/unifiedjs/unified/commit/932c140) Change to use `exports`
    **migrate**: don’t use private APIs
-   [`8e57478`](https://togithub.com/unifiedjs/unified/commit/8e57478) Remove support for classes as compilers, parsers
    **migrate**: if you love classes, see commit message
-   [`4676814`](https://togithub.com/unifiedjs/unified/commit/4676814) Remove support for compilers returning nullish
    **migrate**: nobody did that
-   [`807ffb9`](https://togithub.com/unifiedjs/unified/commit/807ffb9) Add improved types
    **migrate**: it’s probably just better if anything changed at all
-   [`b35afe0`](https://togithub.com/unifiedjs/unified/commit/b35afe0) Add useful error on empty presets
    by [@&#8203;wooorm](https://togithub.com/wooorm) in [https://github.com/unifiedjs/unified/pull/202](https://togithub.com/unifiedjs/unified/pull/202)
-   [`6f068a0`](https://togithub.com/unifiedjs/unified/commit/6f068a0) Fix to deep clone preset settings
-   [`56ee288`](https://togithub.com/unifiedjs/unified/commit/56ee288) Fix non-first parameter merging when reconfiguring plugins

##### Misc

-   [`e58b095`](https://togithub.com/unifiedjs/unified/commit/e58b095) [`ad06700`](https://togithub.com/unifiedjs/unified/commit/ad06700) [`40f0329`](https://togithub.com/unifiedjs/unified/commit/40f0329) Refactor code-style
-   [`ffc146c`](https://togithub.com/unifiedjs/unified/commit/ffc146c) Update `typescript`
    by [@&#8203;ChristianMurphy](https://togithub.com/ChristianMurphy) in [https://github.com/unifiedjs/unified/pull/216](https://togithub.com/unifiedjs/unified/pull/216)
-   [`7148746`](https://togithub.com/unifiedjs/unified/commit/7148746) [`144eec0`](https://togithub.com/unifiedjs/unified/commit/144eec0) [`2d95451`](https://togithub.com/unifiedjs/unified/commit/2d95451) Add improved docs
-   [`afb704a`](https://togithub.com/unifiedjs/unified/commit/afb704a) Fix some typos
    by [@&#8203;ChristianMurphy](https://togithub.com/ChristianMurphy) in [https://github.com/unifiedjs/unified/pull/225](https://togithub.com/unifiedjs/unified/pull/225)
-   [`2aa15ea`](https://togithub.com/unifiedjs/unified/commit/2aa15ea) Refactor types
-   [`a06537c`](https://togithub.com/unifiedjs/unified/commit/a06537c) Add sponsor

**Full Changelog**: unifiedjs/unified@10.1.2...11.0.0

### [`v10.1.2`](https://togithub.com/unifiedjs/unified/releases/tag/10.1.2)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.1.1...10.1.2)

-   [`dc85d21`](https://togithub.com/unifiedjs/unified/commit/dc85d21) Fix typo
    by [@&#8203;jablko](https://togithub.com/jablko) in [https://github.com/unifiedjs/unified/pull/185](https://togithub.com/unifiedjs/unified/pull/185)

**Full Changelog**: unifiedjs/unified@10.1.1...10.1.2

### [`v10.1.1`](https://togithub.com/unifiedjs/unified/releases/tag/10.1.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.1.0...10.1.1)

-   [`6b060c2`](https://togithub.com/unifiedjs/unified/commit/6b060c2) Fix type of `run` signature
    by [@&#8203;alvinleung1996](https://togithub.com/alvinleung1996) in [https://github.com/unifiedjs/unified/pull/174](https://togithub.com/unifiedjs/unified/pull/174)

**Full Changelog**: unifiedjs/unified@10.1.0...10.1.1

### [`v10.1.0`](https://togithub.com/unifiedjs/unified/releases/tag/10.1.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.0.1...10.1.0)

-   [`134ecad`](https://togithub.com/unifiedjs/unified/commit/134ecad) Add plugin input/output type parameters

### [`v10.0.1`](https://togithub.com/unifiedjs/unified/releases/tag/10.0.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/10.0.0...10.0.1)

-   [`591b0c0`](https://togithub.com/unifiedjs/unified/commit/591b0c0) Fix types to support `void` async transformers

### [`v10.0.0`](https://togithub.com/unifiedjs/unified/releases/tag/10.0.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.2.2...10.0.0)

##### Breaking

-   [`dc46bc5`](https://togithub.com/unifiedjs/unified/commit/dc46bc5) Use ESM and update `vfile`
    -   Change:

        ```js
        // from cjs import
        var unified = require('unified')

        // to esm import
        import {unified} from 'unified'
        ```

        Learn [more about ESM in this guide](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
    -   **Breaking**: this updates `vfile`, which importantly renames ~~`vfile.contents`~~ to `vfile.value`. See [`vfile@5`](https://togithub.com/vfile/vfile/releases/tag/5.0.0)
    -   Inconsequential: this updates `trough`, which removes support for Promise-like objects returned from plugins, in favor of only support actual promises. To update, instead of returning an object with a `then` function, return and *actual* promise

##### Types

-   [`b3e2464`](https://togithub.com/unifiedjs/unified/commit/b3e2464) Rewrite types
    -   Removed the type parameter `P` for processor settings
    -   Use `any[]` instead of `[Record<string, unknown>?]` for the default plugin type parameters
-   [`45eb72e`](https://togithub.com/unifiedjs/unified/commit/45eb72e) Update types for ESM
-   [`2c7ba99`](https://togithub.com/unifiedjs/unified/commit/2c7ba99) [`8eda349`](https://togithub.com/unifiedjs/unified/commit/8eda349) Add explicit dependency on `@types/unist`
-   [`0e8f611`](https://togithub.com/unifiedjs/unified/commit/0e8f611) Remove typescript@3 legacy support
-   [`350ed9d`](https://togithub.com/unifiedjs/unified/commit/350ed9d) Fix `next` in types of transformer signature
-   [`b22bf8e`](https://togithub.com/unifiedjs/unified/commit/b22bf8e) Add support for buffer, other return values
-   [`4bfd6c8`](https://togithub.com/unifiedjs/unified/commit/4bfd6c8) [`b8fe5ec`](https://togithub.com/unifiedjs/unified/commit/b8fe5ec) [`6ef3933`](https://togithub.com/unifiedjs/unified/commit/6ef3933) Add support for boolean plugin options

##### Project

-   [`88374fc`](https://togithub.com/unifiedjs/unified/commit/88374fc) Add `esast` to list of syntax trees
-   [`a6ff3c1`](https://togithub.com/unifiedjs/unified/commit/a6ff3c1) Fix links
-   [`ee6ee47`](https://togithub.com/unifiedjs/unified/commit/ee6ee47) Update examples in `readme.md`
-   [`32abf7c`](https://togithub.com/unifiedjs/unified/commit/32abf7c) [`60de570`](https://togithub.com/unifiedjs/unified/commit/60de570) [`115898a`](https://togithub.com/unifiedjs/unified/commit/115898a) Refactor code style

### [`v9.2.2`](https://togithub.com/unifiedjs/unified/releases/tag/9.2.2)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.2.1...9.2.2)

-   [`bc50a01`](https://togithub.com/unifiedjs/unified/commit/bc50a01) Fix to set `vfile.value` if a vfile@5 is given

### [`v9.2.1`](https://togithub.com/unifiedjs/unified/releases/tag/9.2.1)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.2.0...9.2.1)

-   [`fe51be2`](https://togithub.com/unifiedjs/unified/commit/fe51be2) Fix mutating options
-   [`8f135d0`](https://togithub.com/unifiedjs/unified/commit/8f135d0) Refactor to improve bundle size
-   [`ad12369`](https://togithub.com/unifiedjs/unified/commit/ad12369) Remove outdated description of compile results

### [`v9.2.0`](https://togithub.com/unifiedjs/unified/releases/tag/9.2.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.1.0...9.2.0)

-   [`7fc4271`](https://togithub.com/unifiedjs/unified/commit/7fc4271) Add variadic tuple types for plugin tuple

### [`v9.1.0`](https://togithub.com/unifiedjs/unified/releases/tag/9.1.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/9.0.0...9.1.0)

-   [`56fdba4`](https://togithub.com/unifiedjs/unified/commit/56fdba4) Add `FrozenProcessor` interface to types

### [`v9.0.0`](https://togithub.com/unifiedjs/unified/releases/tag/9.0.0)

[Compare Source](https://togithub.com/unifiedjs/unified/compare/8.4.2...9.0.0)

-   [`c3ba172`](https://togithub.com/unifiedjs/unified/commit/c3ba172) Set `file.result` when processing to non-text
    (**breaking**, if you’re using `.process` or `.processSync` with a compiler that returns an object, then those results were available at ~~`file.contents`~~ and are now at `file.result`)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/X-oss-byte/Nextjs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 🧑 semver/major This is a change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

Throw on preset w/ neither settings nor plugins
5 participants