spot icon indicating copy to clipboard operation
spot copied to clipboard

Spot doesn't work in a monorepo

Open ipekt opened this issue 1 year ago • 4 comments

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

ipekt avatar Feb 27 '23 21:02 ipekt

I am also running in to this issue.

Darkle avatar May 06 '23 04:05 Darkle

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 avatar May 12 '23 15:05 dhmw

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

dhmw avatar May 16 '23 10:05 dhmw

PR to update dependencies just enough to make it work https://github.com/airtasker/spot/pull/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

dhmw avatar May 16 '23 12:05 dhmw