Prevent yarn from creating node_modules in monorepo root - yarnpkg

I'm using yarn with monorepos that contain several packages. For examples packages foo and bar might be located in repo/foo and repo/bar within the monorepo root repo. The problem is that I sometimes accidentally run yarn without parameters in the repository root instead of the packages directories. This creates a repo/node_modules directory and a repo/yarn.lock file. Can I somehow prevent yarn from creating node_modules and yarn.lock in the repository root directory?

Related

How to resolve workspace node_modules

I have a mono-repo that contains the main code, and some custom packages as workspaces.
so my directory structure is like this
- mainRepo
-- directories of main project
-- /node_modules
-- /packages
--- my-foo-package
---- /node_modules
so since the workspace (my-foo-package in this case) has its own node_modules, every dependency that it has is going to be there
but main repo also needs the workspace dependencies too, to be able to import codes from workspace package
but after i added the workspace package, linked it and added it to main repo dependencies and ran yarn install i still cannot see the dependencies of workspace package in roo node_modules
is there any step missing?

import dependency from child_folder/node_modules doesn't work

By default node_modules folder is under the root directory of my Laravel project and it's working fine. I can compile the scripts with npm run dev and there is no error.
However according to the project folder structure, I move node_modules folder into a child folder called backend.
Here, I also moved the files like webpack.mix.js, package.json into backend folder and run npm install again inside it. But I keep my resources and public folders as original and link them with relative path via backend folder.
The folder structure looks like this
Now, if I run npm run dev inside backend folder, it complains many errors like can't resolve '#babel/runtime/regenerator'.
But if I make a symbolic node_modules inside root folder which is linked to backend/node_modules, it works fine and I can compile the scripts without error.
My question is - How can I compile the scripts from child folder without making a symbolic like this?
Probably it doesn't know where node_modules folder is located.
As laravel-mix is based on webpack. I add the modules path inside webpack config as below to make all import knows where the node_modules folder is located.
mix.webpackConfig({
resolve: {
modules : [
path.resolve("./node_modules")
]
}
});
There is no more can't resolve error.

my laravel seeds folders ignored by git how to resolve and avoid

i have modules folders in my Laravel Project.
and my sub packages/projects in there
my Laravel parent project use them to working
modules folder gitignored by his main project.
those projects in modules folders connect to its own git repos.
those projects have seeds and factories folder need when i run composer install in the parent.
but seeds and factories are empty and not sync with git and when other developers fetch/clone the repos the parent project need them.
how can i add files as Laravel documentation there to avoide this action.
is it true to create a text file there?
Git doesn't commit empty folders. Usual solution is to add .gitkeep as empty text file.

How to remove yarn workspaces correctly?

I configured 2 workspaces in package.json e.g example and gatsby-theme but later I found I was actually developing a gatsby-starter so I removed the example workspace that depended on the latter workspace from package.json.
I wonder if I moved all files from gatsby-theme/ to the project root directory and overwrote the package.json and other files with gatsby-theme's, does it become a project that could be managed with both npm and yarn?

How to `yarn run start` providing custom modules location

Here is my problem, I constructed a dockerfile launching yarn install from a folder where a package.json and yarn.lock are present (they have been taken from the project I have to setup yarn dependencies for, this project is inside a deconnected server).
Then, I run bash into container image and uploaded the created folder node_modules, and put it into the deconnected server, where project is present, at root folder project.
But then, when I launched yarn start from root folder, it says that it cannot find rescripts despite of the fact that folder #rescripts is present into node_modules.
I tried NODE_PATH=./node_modules yarn start without any success.
Thanks a lot for your help.
Regards
I think i get what i want with :
https://yarnpkg.com/blog/2016/11/24/offline-mirror/
I create a cache folder with all tar.gz dependencies downloaded.
But if i remove node_modules and yarn.lock, and run yarn install --offline --cache-folder npm-packages-offline-cache/, I got error saying it could not find proper dependance in cache folder. It's like it cannot recognize any tar.gz inside. Any help will be welcome.
Regars

Resources