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

Running with a project that uses yarn creates a package-lock.json file #560

Open
gugahoi opened this issue Nov 21, 2022 · 7 comments
Open
Labels
area:api Issues related to the `api` CLI, which builds the SDKs enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@gugahoi
Copy link

gugahoi commented Nov 21, 2022

It seems like this script does not respect projects that use yarn and instead will always create a package-lock file. Here is the outcome from running it on my project:

➜ npx api install @basiq/v3.0#73eilabzsv3b
✔ What language would you like to generate an SDK for? › TypeScript
✔ Fetching your API
✔ Generating your SDK
✔ Saving your SDK into your codebase
⚠ This generator requires some packages to be installed alongside it:
  › api: Required for the `api/dist/core` library that the codegen''d SDK uses for making requests. https://npm.im/api
  › json-schema-to-ts: Required for TypeScript type handling. https://npm.im/json-schema-to-ts
  › oas: Used within `api/dist/core` and is also loaded for TypeScript types. https://npm.im/oas
✔ OK to proceed with package installation? … yes
✔ Installing required packages
🚀 All done!


➜ git status                            
On branch basiq-connect
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   yarn.lock

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	.api/
	package-lock.json

no changes added to commit (use "git add" and/or "git commit -a")

I am not sure why the package-lock.json file is there at all - I don't think it will do anything since I am using yarn.

Furthermore I also am not sure how I would go about importing the downloaded SDK. I can see the files under ./.api but there is nothing in the documentation instructing me on how to consume them. Do I need to add a local file entry to package.json?

➜ tree -L 3 .api 
.api
├── api.json
└── apis
    └── basiq
        ├── index.ts
        ├── node_modules
        ├── openapi.json
        ├── package-lock.json
        ├── package.json
        ├── schemas.ts
        └── types.ts
@erunion erunion self-assigned this Nov 23, 2022
@erunion erunion added area:api Issues related to the `api` CLI, which builds the SDKs enhancement New feature or request good first issue Good for newcomers labels Nov 23, 2022
@erunion
Copy link
Member

erunion commented Nov 25, 2022

api currently doesn't support Yarn but it's on our immediate roadmap.

Furthermore I also am not sure how I would go about importing the downloaded SDK. I can see the files under ./.api but there is nothing in the documentation instructing me on how to consume them. Do I need to add a local file entry to package.json?

There was actually a bug that was preventing the installed API in .api/.apis/ from being hooked up into your package.json. If you re-install that API @api/basiq will be added to your package.json so you can import it.

@gugahoi
Copy link
Author

gugahoi commented Nov 28, 2022

Thanks for fixing the consumption part, however I am still having some problems and I am not sure if they are due to the API spec that I am trying to consume or something missing from this package. Following is the terminal output:

➜ npx api install @basiq/v3.0#73eilabzsv3b
Need to install the following packages:
  api
Ok to proceed? (y) 
✔ What language would you like to generate an SDK for? › TypeScript
✔ Fetching your API
✔ Generating your SDK
✔ Saving your SDK into your codebase
⚠ This generator requires some packages to be installed alongside it:
  › api: Required for the `api/dist/core` library that the codegen'd SDK uses for making requests. https://npm.im/api
  › json-schema-to-ts: Required for TypeScript type handling. https://npm.im/json-schema-to-ts
  › oas: Used within `api/dist/core` and is also loaded for TypeScript types. https://npm.im/oas
✔ OK to proceed with package installation? … yes
✔ Installing required packages
🚀 All done!

flux/packages/api-service …
✘130 ➜ yarn    
yarn install v1.22.18
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
error Can't add "@api/basiq": invalid package version "".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

flux/packages/api-service …
✘1 ➜ rm package-lock.json 

flux/packages/api-service …
➜ yarn
yarn install v1.22.18
[1/4] 🔍  Resolving packages...
error Can't add "@api/basiq": invalid package version "".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

As you can see, yarn complains about the installed api sdk due to a missing version. I can manually rectify this locally but I don't think this is the correct way to approach this. Is the problem on my end? On the API spec I am consuming? Or is this still a bug?

@erunion
Copy link
Member

erunion commented Nov 28, 2022

Seems this is happening because we aren't setting a version property in the package.json we create for the installed API in the .apis/ directory. I'll get a fix going for this.

@erunion
Copy link
Member

erunion commented Nov 28, 2022

@gugahoi That issue should now be resolved in v5.0.3.

I'll see if I can carve out some time this week to prioritize Yarn support.

@haltcase
Copy link

haltcase commented Dec 2, 2022

@erunion similarly, it would be nice to have support for pnpm, but it could be more complicated. What ended up working for me as a workaround was to:

  1. Execute pnpm dlx api install @render-api/v1.0#f084kp1glacw8qb7 and say yes to package installation
  2. Cancel once the .api/apis/render-api/package.json file is updated with dependencies ( this wasn't perfect — I had to manually add openapi-types as it was missing, might have been timing but I'm not sure yet )
  3. Create pnpm-workspace.yaml (pnpm doesn't handle dependency installation well for locally linked packages)
    packages:
      - ".api/apis/*"
  4. Add the api package as a workspace dependency in the root package.json
    "dependencies": {
    	"@api/render-api": "workspace:*"
    }
  5. Run pnpm install and the package should be importable now

However, I wonder if it would be worth looking into how Prisma generates its client since that works rather well across package managers in my experience. You'd have to regenerate the API package in fresh directories though (since it's dropped into node_modules).

@erunion
Copy link
Member

erunion commented Oct 18, 2023

Dug into this a bit after discovering preferred-pm and that's got a pretty big blocker for us where if we you run npx api install from inside of an NPM workspace directory like packages/client it thinks you use Yarn. I've filed the bug to zkochan/packages#180 but am unfortunately going to have to put Yarn and pnpm on hold until that's sorted out.

@erunion erunion removed this from the v7 milestone Oct 18, 2023
@erunion erunion added the help wanted Extra attention is needed label Oct 18, 2023
@erunion erunion removed their assignment Oct 19, 2023
@EugenGedroyc
Copy link
Contributor

EugenGedroyc commented Jan 25, 2024

I use ynpx and get the same problems

I've filed the bug to zkochan/packages#180

answer received

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:api Issues related to the `api` CLI, which builds the SDKs enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants