8000 Change Request: Make `defineConfig` support `Promise<Config>`, or another API that can do that? · Issue #205 · eslint/rewrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Change Request: Make defineConfig support Promise<Config>, or another API that can do that? #205
Open
@vikr01

Description

@vikr01

Which packages would you like to change?

  • @eslint/compat
  • @eslint/config-array
  • @eslint/config-helpers
  • @eslint/core
  • @eslint/migrate-config
  • @eslint/object-schema
  • @eslint/plugin-kit

What problem do you want to solve?

As of eslint/eslint#17301, it seems like Promise<Config> is understandable to eslint. When I export a promise config, eslint is able to read it fine.

However, when I try to use a Promise<config> within defineConfig, it fails.

import config1 from 'config1'; // Is of type Promise<Config>
import config2 from 'config2'; // Is of type Config
import config3 from 'config3'; // Is of type Config

export default defineConfig(
  config1, // causes runtime errors due to being a promise
  config2,
  config3,
);

export default defineConfig(
  config2,
  config3,
); // no issues

You could rewrite this to be a promise that unwraps the value of the other promise, but it feels like it adds overhead for people just importing another config:

import config1 from 'config1'; // Is of type Promise<Config>
import config2 from 'config2'; // Is of type Config
import config3 from 'config3'; // Is of type Config

export default (async()=>{
  const config1Unwrapped = await config1;

  return defineConfig(
    config1Unwrapped,
    config2,
    config3,
  );
});

It would be nice if we could have an async version of defineConfig:

import config1 from 'config1'; // Is of type Promise<Config>
import config2 from 'config2'; // Is of type Config
import config3 from 'config3'; // Is of type Config

export default defineConfigAsync( // returns a promise, handles promises under the hood (i.e. Promise.all)
  config1,
  config2,
  config3,
);

What do you think is the correct solution?

A new API defineConfigAsync that just uses defineConfig under the hood, but extracts all results of promises first.

Participation

  • I am willing to submit a pull request for this change.

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Status

    Triaging

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0