Closed stephanschubert closed 5 years ago
If package (site in case) uses dependency, then it should declare that dependency. If you want to avoid manually installing dependencies in each individual package please take a look at lerna bootstrap
that will handle that. Another useful thing to consider is using yarn workspaces.
Gatsby doesn't really require anything, so there is no other way to determine if current working directory is actually root of gatsby project - if we would remove that check you could run gatsby build/develop
anywhere and it would probably build empty site which is definitely not great DX
I don't use lerna bootstrap
nor yarn workspaces
for different reasons. (FYI: Moving all deps into root package.json
allows me to just run npm i packages/*
to setup everything up.)
But back to topic: The current check does not ensure the current directory is actually a valid (as in buildable) Gatsby project. A lot of things can be wrong or missing in any case..?
Like @pieh mentioned, Gatsby doesn't really require anything so the current check for gatsby
as a dependency or dev dependency makes sense because it is a pretty strong indicator that the current folder is a Gatsby project if it depends on it.
If I understand correctly, you want to avoid manually installing dependencies for every individual package (for which you're using npm i packages/*
)
lerna bootstrap does the same thing:
npm install all external dependencies of each package. Symlink together all Lerna packages that are dependencies of each other. npm run prepublish in all bootstrapped packages. npm run prepare in all bootstrapped packages.
On a separate note, it is a good practice for individual packages to list their own dependencies so that they are self contained and can work in isolation.
I'm closing this issue for now but please feel free to reopen if there is anything else.
@sidharthachatterjee Yes, that's what I want(ed) to avoid. Just for the record: "my" approach is a suggestion from lerna maintainers.
Besides that moving all deps into one root package.json avoids issues with different versions. Personally I take the tradeoff of having to put the deps back when publishing.
Anyway, I can live with this check but wanted to raise the question whether it's still useful.
You can also skip using gatsby-cli
and call build/develop commands directly with some small custom wrapper:
here's entry point for build https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/commands/build.js - you can write very small js file to setup BuildArgs
(that normally are setup by cli
)
I do think that tradeoff for not checking local package.json
is not worth supporting this pretty niche use case - that's the only sanity check we can do :/
Thank you for bringing it up anyway, @stephanschubert
If there's more interest in the usecase, we'll relook at this in the future. In the mean time, happy building 🙂
@pieh Thanks for the hint, I will look into that.
Hi all, after much trial and error getting a similar setup running I noticed without declaring gatsby
in the root package.json file gatsby sites in a monorepo will not run - failing resolving modules such as gatsby/graphql
and gatsby-plugin-react-helmet
.
I have a whole issue typed up (see below) but figured I could tack on to this issue. I did not see this note in the documentation, and was wondering if it could be added somewhere?
I have a monorepo set up with
lerna
(which shouldn't matter) and moved all (dev)dependencies into the rootpackage.json
. But it is required thatgatsby
is added to the package's ownpackage.json
.I'm not running
npm i
inside the (sub-)package—I just added it.Are there any (legacy?) reasons why this check is required or could it be removed/replaced with a more flexible one?