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

Elevate @types/json-schema to dependency #227

Closed
ASDFGerte opened this issue Apr 17, 2021 · 3 comments
Closed

Elevate @types/json-schema to dependency #227

ASDFGerte opened this issue Apr 17, 2021 · 3 comments

Comments

@ASDFGerte
Copy link
Contributor

This is closely related to #175.

The issue is, that the type declarations for this project depend on @types/json-schema (they import), but the package is only listed as dev-dependency. The consumer of @apidevtools/json-schema-ref-parser reads its type declarations, which need @types/json-schema, and it therefore should be a normal dependency.

In NPM, this may slip through the cracks (maybe need to manually install @types/json-schema as dev-dependency, in the consuming project. Afterwards, there simply are no checks for being listed as dependency, when importing - it just looks into node_modules). However, on yarn 2, with strict pnp, this simply doesn't work. Typescript won't resolve the imported types, turning them all to any, which will make all types that depend on the import useless.

A work-around is to have yarn inject the missing dependency:

packageExtensions:
  "@apidevtools/json-schema-ref-parser@*":
    dependencies:
      "@types/json-schema": "*"

An alternative solution i can think of, should having types as dependency really be a problem, would be having a separate package @types/json-schema-ref-parser, which consumers manually add as dev-dependency in their own project.

@P0lip
Copy link
Member

P0lip commented Apr 19, 2021

Hey @ASDFGerte.
I'm in total alignment with you.
Would you mind shipping a PR adding @types/json-schema to dependencies?

@ASDFGerte
Copy link
Contributor Author

Possible, but i am not too sure about your conventions, and apart from changes to the lock file, it's basically just the following in package.json:

@@ -61,7 +61,6 @@
     "@jsdevtools/karma-config": "^3.1.7",
     "@semantic-release/changelog": "^5.0.1",
     "@semantic-release/git": "^9.0.0",
-    "@types/json-schema": "^7.0.6",
     "@types/node": "^14.14.21",
     "chai": "^4.2.0",
     "chai-subset": "^1.6.0",
@@ -76,6 +75,7 @@
   },
   "dependencies": {
     "@jsdevtools/ono": "^7.1.3",
+    "@types/json-schema": "^7.0.6",
     "call-me-maybe": "^1.0.1",
     "js-yaml": "^3.13.1"
   },

I typically use yarn, and am on NPM 7 otherwise, which would e.g. bump your package-lock.json version to 2. If things like that are acceptable, sure, i can make a PR.

@P0lip
Copy link
Member

P0lip commented Apr 20, 2021

Possible, but i am not too sure about your conventions, and apart from changes to the lock file, it's basically just the following in package.json:

Yup, the diff looks good.
I'm also alright with bumping lockfile to a newer version.
Same as you, I also use yarn and npm v7.

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