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

Spot doesn't work in a monorepo #2059

Open
ipekt opened this issue Feb 27, 2023 · 4 comments
Open

Spot doesn't work in a monorepo #2059

ipekt opened this issue Feb 27, 2023 · 4 comments

Comments

@ipekt
Copy link

ipekt commented Feb 27, 2023

Describe the bug
Spot outputs TS errors when spot generate command is run in an monorepo. But the same code works fine when it is outside a monorepo. This may be an issue with TS looking at parent node_modules folder

To Reproduce

  1. Create a package.json with serverless in root folder:
{
  "dependencies": {
    "serverless": "^3.15.0"
  }
}
  1. Create another package.json in a nested folder: (root/spot)
{
   "dependencies": {
    "@airtasker/spot": "^1.9.0"
  }
}
  1. Add api.ts file
  2. Run spot generate --contract api.ts --language yaml --generator openapi3 --out output/
  3. Exists with errors shared below

Expected behavior
spot generate works in a monorepo setup

Screenshots
Example command line output:

...

 ';' expected.
    Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`.
    ';' expected.
    Cannot find name 'infer'.
    ';' expected.
    Cannot find name 'T'.
    Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`.
    ';' expected.
    Cannot find name 'infer'.
    ';' expected.
    Cannot find name 'U'.
    ';' expected.
    Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`.
    ';' expected.
    Cannot find name 'T'.
    Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i @types/jquery`.
    ';' expected.
    'PascalCase' only refers to a type, but is being used as a value here.
    Cannot find name 'U'.
    '(' expected.
    ';' expected.
    'PropertyKey' only refers to a type, but is being used as a value here.
    ';' expected.
    ';' expected.
    ';' expected.
    This expression is not callable.
    Unterminated template literal.

Desktop (please complete the following information):

  • NPM version: 6.14.16
  • Node version: v14.19.1
  • Spot version: 1.9.0
@Darkle
Copy link

Darkle commented May 6, 2023

I am also running in to this issue.

@dhmw
Copy link
Contributor

dhmw commented May 12, 2023

Same here.

There seems to be very few tools available for generating API specs from TS types.

This project looks very promising and I like the idea of the contract declaration to have some degree of control over what is exposed in the spec as well.

I've tried some of the others as well (ones which also integrate with serverless framework) - and they too are also all broken and/or abandoned.

It's a shame, because something like this will save a lot of time and effort in allowing 3rd parties to integrate on our APIs without having to do all the spec and client implementation work manually.

@dhmw
Copy link
Contributor

dhmw commented May 16, 2023

This appears to be mostly due to the really old version of ts-morph that spot uses; I have a local copy updated to ts-morph@18.0.0 and most of these errors go away. I'm still tracking down some other incompatibilities though.

@dhmw dhmw mentioned this issue May 16, 2023
2 tasks
@dhmw
Copy link
Contributor

dhmw commented May 16, 2023

PR to update dependencies just enough to make it work #2061

EDIT: I have been going deeper using this tool on my types, and I have to say that the definition of "work" is actually quite limited. I don't think I will be able to continue to use this tool with my project, since the types we have are quite complex and the parsing is failing in unknown ways; there's quite a bit of TS which is simply not supported/supportable here. Given that the tool likes to bail out completely rather than skip over parts it cannot handle, it makes debugging the generator and our project types almost impossible, and certainly more work than writing a spec from scratch.

❯ yarn run spot generate -c src/contracts/test.ts --out dist/spec --language yaml --generator openapi3
    Error: unknown type

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