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

proposal: config module #4382

Closed
deer opened this issue Feb 24, 2024 · 6 comments
Closed

proposal: config module #4382

deer opened this issue Feb 24, 2024 · 6 comments

Comments

@deer
Copy link

deer commented Feb 24, 2024

@iuioiua, this is the followup to denoland/fresh#2266 (comment).

I propose we introduce a type for the deno.json schema. I have a generator like this:

import configSchema from "https://raw.githubusercontent.com/denoland/deno/v1.41.0/cli/schemas/config-file.v1.json" with {
  type: "json",
};
import { compile, JSONSchema } from "npm:json-schema-to-typescript@13.1.2";

const result = await compile(configSchema as JSONSchema, "DenoConfig");
await Deno.writeTextFileSync("./config/configType.ts", result);

Maybe this type already exists, but I couldn't find it.

Additionally, there should be a suite of utilities for interacting with this configuration file. I propose two functions to start with:

  1. readConfig -- This should read a path and parse the config file, handling a few things:
    a. Look for both deno.json and deno.jsonc files.
    b. Possibly look in parent directories, mimicking whatever the cli does in order to find the governing file.
  2. importMap -- Return the relevant imports as Record<string, string>. This should handle both inline imports and also importMap.
@deer
Copy link
Author

deer commented Feb 24, 2024

I should also mention that I have this implemented with 100% test coverage. (I'm aware that coverage isn't the end-all be-all, but it's better than having 0% coverage.) Let me know if I should open a PR for this.

@iuioiua
Copy link
Contributor

iuioiua commented Mar 20, 2024

What if we add a Config (or similar) interface to a std/deno module and keep it in sync with the runtime. We can then leave it up to the developers to read the file and use the interface as necessary. This would make use of deno.json available to all runtimes.

@boywithkeyboard
Copy link

@iuioiua I agree with you here, but wouldn't it make more sense to add such a type to the global Deno namespace?

@iuioiua
Copy link
Contributor

iuioiua commented Mar 28, 2024

That would mean only Deno programs have access to it. Having it in the Standard Library allows its use in other runtimes.

@boywithkeyboard
Copy link

@iuioiua this seems like outsourcing to me. Correct me if I'm wrong, but I don't think the type definition is relevant outside of Deno, at least not that I can think of a valid use case for it.

2 more reasons to keep it in the same codebase as the runtime itself:

  • the runtime parses it & already provides auto-completion/a json schema for it
  • that way it's kept in sync with the runtime and you don't suddenly end up with a type declaration that is different from what the runtime can understand/parse

@iuioiua
Copy link
Contributor

iuioiua commented Jul 18, 2024

On second thought, yes, maybe having this in the runtime is better. Closing in favor of denoland/deno#24628.

@iuioiua iuioiua closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants