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 a JSON schema #147

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ npm test
- [commander](https://ghub.io/commander): the complete solution for node.js command-line programs
- [cosmiconfig](https://ghub.io/cosmiconfig): Find and load configuration from a package.json property, rc file, or CommonJS module
- [enquirer](https://ghub.io/enquirer): Stylish, intuitive and user-friendly prompt system. Fast and lightweight enough for small projects, powerful and extensible enough for the most advanced use cases.
- [fs-extra](https://ghub.io/fs-extra): fs-extra contains methods that aren't included in the vanilla Node.js fs package. Such as recursive mkdir, copy, and remove.
- [globby](https://ghub.io/globby): User-friendly glob matching
- [minimatch](https://ghub.io/minimatch): a glob matcher in javascript
- [ora](https://ghub.io/ora): Elegant terminal spinner
Expand All @@ -45,7 +44,6 @@ npm test
## Dev Dependencies

- [@tsconfig/node18](https://ghub.io/@tsconfig/node18): A base TSConfig for working with Node 18.
- [@types/fs-extra](https://ghub.io/@types/fs-extra): TypeScript definitions for fs-extra
- [@types/jest](https://ghub.io/@types/jest): TypeScript definitions for Jest
- [@types/node](https://ghub.io/@types/node): TypeScript definitions for Node.js
- [@types/prompts](https://ghub.io/@types/prompts): TypeScript definitions for prompts
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"commander": "11.0.0",
"cosmiconfig": "8.2.0",
"enquirer": "2.3.6",
"fs-extra": "11.1.1",
"globby": "11.1.0",
"minimatch": "9.0.2",
"ora": "5.4.1",
Expand All @@ -51,7 +50,6 @@
},
"devDependencies": {
"@tsconfig/node18": "18.2.0",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.5.2",
"@types/node": "14.18.36",
"@types/prompts": "2.4.4",
Expand All @@ -66,6 +64,7 @@
"prettier": "2.8.8",
"rimraf": "5.0.1",
"ts-jest": "29.1.1",
"ts-json-schema-generator": "1.2.0",
"ts-node": "10.9.1",
"typescript": "5.1.6"
},
Expand Down Expand Up @@ -114,8 +113,9 @@
"lint": "yarn lint:ts && yarn lint:eslint",
"lint:eslint": "eslint --ext .ts .",
"lint:ts": "tsc --noEmit --project tsconfig.json",
"prepack": "yarn build",
"test": "jest src test"
"prepack": "yarn build && yarn schema",
"test": "jest src test",
"schema": "ts-json-schema-generator --path ./src/index.ts --type RcFile -o schema.json"
},
"types": "dist/index.d.ts"
}
267 changes: 267 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"$ref": "#/definitions/RcFile",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"CustomTypeConfig.Any": {
"anyOf": [
{
"$ref": "#/definitions/CustomTypeConfig.NameAndVersionProps"
},
{
"$ref": "#/definitions/CustomTypeConfig.NamedVersionString"
},
{
"$ref": "#/definitions/CustomTypeConfig.UnnamedVersionString"
},
{
"$ref": "#/definitions/CustomTypeConfig.VersionsByName"
}
]
},
"CustomTypeConfig.NameAndVersionProps": {
"additionalProperties": false,
"properties": {
"namePath": {
"type": "string"
},
"path": {
"type": "string"
},
"strategy": {
"const": "name~version",
"type": "string"
}
},
"required": [
"namePath",
"path",
"strategy"
],
"type": "object"
},
"CustomTypeConfig.NamedVersionString": {
"additionalProperties": false,
"properties": {
"path": {
"type": "string"
},
"strategy": {
"const": "name@version",
"type": "string"
}
},
"required": [
"path",
"strategy"
],
"type": "object"
},
"CustomTypeConfig.UnnamedVersionString": {
"additionalProperties": false,
"properties": {
"path": {
"type": "string"
},
"strategy": {
"const": "version",
"type": "string"
}
},
"required": [
"path",
"strategy"
],
"type": "object"
},
"CustomTypeConfig.VersionsByName": {
"additionalProperties": false,
"properties": {
"path": {
"type": "string"
},
"strategy": {
"const": "versionsByName",
"type": "string"
}
},
"required": [
"path",
"strategy"
],
"type": "object"
},
"RcFile": {
"additionalProperties": false,
"properties": {
"$schema": {
"type": "string"
},
"customTypes": {
"additionalProperties": {
"$ref": "#/definitions/CustomTypeConfig.Any"
},
"type": "object"
},
"dependencyTypes": {
"items": {
"type": "string"
},
"type": "array"
},
"filter": {
"type": "string"
},
"indent": {
"type": "string"
},
"semverGroups": {
"items": {
"$ref": "#/definitions/SemverGroupConfig.Any"
},
"type": "array"
},
"semverRange": {
"$ref": "#/definitions/SemverRange"
},
"sortAz": {
"items": {
"type": "string"
},
"type": "array"
},
"sortFirst": {
"items": {
"type": "string"
},
"type": "array"
},
"source": {
"items": {
"type": "string"
},
"type": "array"
},
"versionGroups": {
"items": {
"$ref": "#/definitions/VersionGroupConfig.Any"
},
"type": "array"
}
},
"type": "object"
},
"SemverGroupConfig.Any": {
"additionalProperties": false,
"properties": {
"dependencies": {
"items": {
"type": "string"
},
"type": "array"
},
"dependencyTypes": {
"items": {
"type": "string"
},
"type": "array"
},
"isIgnored": {
"const": true,
"type": "boolean"
},
"label": {
"type": "string"
},
"packages": {
"items": {
"type": "string"
},
"type": "array"
},
"range": {
"$ref": "#/definitions/SemverRange"
}
},
"required": [
"dependencies",
"packages"
],
"type": "object"
},
"SemverRange": {
"default": "",
"description": "Aliases for semver range formats supported by syncpack\n\nDefaults to `\"\"` to ensure that exact dependency versions are used instead of loose ranges, but this can be overridden in your config file or via the `--semver-range` command line option.\n\n| Supported Range | Example | | --------------- | --------: | | `\"<\"` | `<1.4.2` | | `\"<=\"` | `<=1.4.2` | | `\"\"` | `1.4.2` | | `\"~\"` | `~1.4.2` | | `\"^\"` | `^1.4.2` | | `\">=\"` | `>=1.4.2` | | `\">\"` | `>1.4.2` | | `\"*\"` | `*` |",
"enum": [
"",
"*",
">",
">=",
".x",
"<",
"<=",
"^",
"~"
],
"type": "string"
},
"VersionGroupConfig.Any": {
"additionalProperties": false,
"properties": {
"dependencies": {
"items": {
"type": "string"
},
"type": "array"
},
"dependencyTypes": {
"items": {
"type": "string"
},
"type": "array"
},
"isBanned": {
"const": true,
"type": "boolean"
},
"isIgnored": {
"const": true,
"type": "boolean"
},
"label": {
"type": "string"
},
"packages": {
"items": {
"type": "string"
},
"type": "array"
},
"pinVersion": {
"type": "string"
},
"policy": {
"const": "sameRange",
"type": "string"
},
"preferVersion": {
"enum": [
"highestSemver",
"lowestSemver"
],
"type": "string"
},
"snapTo": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"dependencies",
"packages"
],
"type": "object"
}
}
}
9 changes: 3 additions & 6 deletions src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Context from '@effect/data/Context';
import type { Union } from 'ts-toolbelt';

/**
* Aliases for semver range formats supported by syncpack
Expand Down Expand Up @@ -39,7 +38,7 @@ export namespace SemverGroupConfig {
range: SemverRange;
}

export type Any = Union.Strict<Ignored | WithRange>;
export type Any = GroupConfig & Partial<Ignored & WithRange>;
Copy link
Owner

Choose a reason for hiding this comment

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

What was happening when you made this change? Maybe I can help. This doesn't seem right as Ignored and WithRange are mutually exclusive but this change makes them a combination of both types added together.

This comment also apples to the same change made below.

Copy link
Author

@UnderKoen UnderKoen Jul 7, 2023

Choose a reason for hiding this comment

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

What was happening when you made this change?

ts-json-schema-generator doesn't understand the union type.

This doesn't seem right as Ignored and WithRange are mutually exclusive but this change makes them a combination of both types added together.

Maybe I don't understand the union correctly. It is a combination of the types right?
The Union.Strict makes sure when type is Ignored all other fields of Ignored are also required.

What you want would be:

Suggested change
export type Any = GroupConfig & Partial<Ignored & WithRange>;
export type Any = Ignored | WithRange;

Here it is not possible to define Ignored and WithRange

Copy link
Owner

Choose a reason for hiding this comment

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

Hopefully this makes sense, what Union.Strict<Ignored | WithRange> is describing is:

// Accept exactly one or the other of the types inside <here>
// - do not allow an Ignored with additional properties
// - do not allow a WithRange with additional properties
// - do not allow an Ignored with a WithRange on top of it
Union.Strict<
  // Accept either one or the other, but not both at the same time
  Ignored | WithRange
>

In contrast Ignored & WithRange is creating one new type, which is Ignored with all the properties of WithRange merged together on top into one object.

Maybe give it a try by going back to how it was but remove every usage of Union.Strict and see if everything still works. It may be fine, but I think possibly there may be some cases where the problems linked here may come up.

}

export namespace VersionGroupConfig {
Expand Down Expand Up @@ -71,7 +70,7 @@ export namespace VersionGroupConfig {
preferVersion?: 'highestSemver' | 'lowestSemver';
}

export type Any = Union.Strict<Banned | Ignored | Pinned | SameRange | SnappedTo | Standard>;
export type Any = GroupConfig & Partial<Banned & Ignored & Pinned & SameRange & SnappedTo & Standard>;
}

namespace CustomTypeConfig {
Expand All @@ -96,9 +95,7 @@ namespace CustomTypeConfig {
strategy: 'versionsByName';
}

export type Any = Union.Strict<
NameAndVersionProps | NamedVersionString | UnnamedVersionString | VersionsByName
>;
export type Any = NameAndVersionProps | NamedVersionString | UnnamedVersionString | VersionsByName;
Copy link
Owner

Choose a reason for hiding this comment

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

What was happening when Union.Strict was still there please?

Copy link
Author

Choose a reason for hiding this comment

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

Union.Strict was doing nothing here, because all of these types have the same fields.

}

export interface CliConfig {
Expand Down
Loading