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

feat: add schema definition to package #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jase88
Copy link

@jase88 jase88 commented Dec 13, 2023

fixes naugtur/npm-audit-resolver#76

changes:

  • moved schemas of both versions to separate file (v0.schema.json, v1.schema.json), which is consumed internally
  • added small test which makes sure that the definition of the enum decision is in sync with the object in the code

out of scope / didn't do:

  • automatically adding schema with {"$schema": "./node_modules/npm-audit-resolver-core/auditFile/versions/v1.schema.json"}, because unsure how to properly resolve npm package folder (could be lying somewhere different, depending on package manager)

@jase88
Copy link
Author

jase88 commented Mar 15, 2024

@naugtur can you please take a look at this? :)

@naugtur
Copy link
Owner

naugtur commented Mar 19, 2024

Hi, sorry I missed this.

I need to fold this repository back into the original project. It was made separate because I was hoping to donate this part to NPM itself.

For this to be a fix, we'd need a way to ship those schemas somehow.
Do you know of any other packages that export their schemas? ow do they do that?

@jase88
Copy link
Author

jase88 commented Mar 19, 2024

No need to apologize.

I need to fold this repository back into the original project. It was made separate because I was hoping to donate this part to NPM itself.

Too bad it's not part of npm - the features are essential. You could port them back together in one repository with something like npm workspaces or you throw them directly together ;)

For this to be a fix, we'd need a way to ship those schemas somehow.
Do you know of any other packages that export their schemas? ow do they do that?

The only one I know is nx. The have a project.json file that references their schema like this:

{
  "name": "awesome-app",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "application",
   ...
}

Alternatively it could be referenced as URL

{
  "$schema": "https://unpkg.com/somepackage@someversion/schema.json",
}

@naugtur
Copy link
Owner

naugtur commented Mar 19, 2024

I was thinking about that unpkg or jsdelivr option, if I folded this into the main repo, it could be somewhat intuitive.

I wonder if setting the json files as exports in package.json would be any helpful for referencing them too. Gonna ask GPT tomorrow and see if it has any reasonable examples of this in training sets :D

@naugtur
Copy link
Owner

naugtur commented Mar 31, 2024

There doesn't seem to be a way to use anything other than a fully qualified url in "$schema"
So relative paths, not to mention resolving form a package, won't work. jsdelivr approach is the only one left.
Let's look into merging the repo back in, as it's necessary anyway.

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

Successfully merging this pull request may close these issues.

Feature request: JSON schema for audit-resolve.json
2 participants