vtex / faststore

Digital commerce toolkit for frontend developers
https://faststore.dev
MIT License
182 stars 57 forks source link

Invert direction of dependency between @faststore/core and @faststore/cli #2377

Closed gvc closed 1 week ago

gvc commented 2 weeks ago

What's the purpose of this pull request?

This PR aims to make @faststore/core a dependency of the @faststore/cli. It just makes sense. Someone can fork @faststore/core and never need to use the CLI, but there's hardly any usefulness to the CLI without @faststore/core.

How it works?

The only thing linking Core to the CLI was the generate-graphql command on the CLI. It just called back 4 scripts on core's package.json: generate:schema, generate:codegen, format:generated and generate:copy-back. The copy-back command was only needed to improve the DX of customers customizing their GraphQL schema [ref] and it was the only part of the script that needed information available at the CLI level only.

Since it was only a DX improvement, all that was needed was, during the faststore dev execution I had to generate the new schema, copy the files to the correct node_modules dir, and then start the NextJS dev server. In order to do this I split the dev script into predev, dev, and dev-only*. From the FastStore CLI I could now call yarn predev, copy the files to the correct place, and then run yarn dev-only to start the NextJS dev server.

Someone developing on the faststore monorepo (us VTEX developers, or someone contributing to our project) will continue to run core via yarn dev. npm, yarn, and pnpm support the lifecycle scripts out of the box. I did the same thing to build for equivalence.

One thing that can be up to discussion is the existence of runCommandSync util. It was only used on generate-graphql and can be easily removed (in this PR or in a future one).

How to test it?

Add this PR @faststore/cli from codesandbox as a dependency of the starter store, remove @faststore/core as an explicit dependency, and @faststore/cli as a devDependency. Run your store and see that everything still works fine. Or go to the starter preview [PR] here and see the store running in "production".

vercel[bot] commented 2 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **faststore-site** | ⬜️ Ignored ([Inspect](https://vercel.com/faststore/faststore-site/9cjsDazKEd7LiCnTYresrGn9hU7J)) | [Visit Preview](https://faststore-site-git-invert-cli-core-dependency-faststore.vercel.app) | | Jul 17, 2024 7:56pm |
codesandbox-ci[bot] commented 2 weeks ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

gvc commented 1 week ago

@eduardoformiga

It's very uncommon to remove the core dependency because some functions from @faststore/core are used in our features as API extensions, Section Overrides etc.

but since the CLI depends on Core, it will always be there :)