I have nested directories with different nodejs environments (package.json and node_modules/), and need to run npx under different environments. Something like this:
a/
├─ node_modules/
├─ b/
│ ├─ c/
│ │ ├─ node_modules/
│ │ ├─ package.json
├─ package.json
Recently, I created directory c/, and found that when running a command with npx under c/, it shows some warning related to a/node_modules/. Both environments have this command (package), to avoid confusion.
Thus, I would like to check why npx is unexpectedly looking at the upper levels of the directory structure.
Is there a way to output the relevant information?
For example, how do I check which (environment of) directory that npx is running commands in?
Related
Today I got email with feedback from my recruitment task. One of the notices said:
There was usage of dot notation which is deprecated (from .bfs import BFS)
The code that is quoted comes from my init.py module, and the project tree goes like this:
my-app/
├─ main.py/
├─ src/
│ ├─ __init__.py
│ ├─ bfs.py
├─ .gitignore
├─ requirements.txt
├─ README.md
etc...
Question is: Is there a better way to use init.py file? Is "dot notation" really deprecated?
Say you have the eslint-config-next package installed at the root of a monorepo, and you have a base ESLint config at the root which is extended by a child ESLint config in a sub-package:
# monorepo
├── .eslintrc.base.yml
├── apps
│ └── client
│ └── .eslintrc.yml
└── packages
└── components
└── .eslintrc.yml
Here's how the child .eslintrc.yml in packages/components config looks like:
extends:
- "../../.eslintrc.base.yml"
- "next"
But there is no node_modules directory in packages/components. Does ESLint look up the directory tree (in this case, go up two directories at the root of the monorepo) to locate the next config in the node_modules directory?
I am working on an NPM workspace node project. To deploy one of the workspace's packages, I would like to run npm install and obtain a node_modules directory as a subdirectory of that package such that the package becomes self-contained.
Consider the directory structure below:
node_modules
packages
├ cloud-app
│ ├ src
│ └ package.json
├ helpers
│ ├ src
│ └ package.json
├ business-logic
│ ├ src
└ └ package.json
package.json
Just one deduplicated node_modules is excellent for development in a monorepo. But to deploy the cloud-app package, I need the structure to look like this:
packages
├ cloud-app
│ ├ node_modules
│ ├ src
│ └ package.json
├ helpers
│ ├ src
│ └ package.json
├ business-logic
│ ├ src
└ └ package.json
package.json
Then, I could upload the cloud-app directory as usual without exposing my NPM workspace to the vendor's (incompatible) CD pipeline.
Is this possible at all? What would be the correct command or procedure here?
This seems to work. Try the workspaces argument:
cd <my_project_root>
npm i --workspaces=false
https://docs.npmjs.com/cli/v9/commands/npm-install#workspaces
While I did not find a standard way to achieve this, there is a slightly hacky way that worked for me:
Copying the node_modules directory allows the package to act as a stand-alone module. However, there is one caveat: The node_modules directory contains a symlink for each package in the workspace. Thus, a loop begins when it is copied into a package and when symlinks are followed. To prevent this, we first have to delete our package. Therefore, a deploy script could look something like this:
rm ./node_modules/cloud-app
cp -rL ./node_modules ./cloud-app/node_modules
# deploy cloud-app here
I thought of this while formulating the above question but would still be delighted to know whether there is any canonical, supported way to do this.
Something you can try is what #youzen brought on this post.
Basically, in the root folder of your repository, you can run:
npm install --prefix <path/to/prefix_folder> -g
And so, the node_modules folder will be created in the specified folder.
You could access the link mentioned above to get others solutions, hope this helps!
I have a git a repository set up with CD on Netlify. The site itself is 4 files, but I have some other files I'd like to add to the repository that I don't want deployed. Is there a way to deploy only certain files with a deployment? Or only a specific folder?
My site only requires an http server, there's not an npm, jekyll, or hugo install. It's just the deployment of 4 files.
If you put the files in a specific folder you can set the Base Directory in your Build & Deploy settings to that directory and it will ignore the other files/folders not in that directory.
According to the docs, this is a bit more involved than just setting the base repo:
For this next example, consider a monorepo project set up like this, where blog-1 is the base directory.
repository-root/
├─ package.json
└─ workspaces/
├─ blog-1/
│ ├─ package.json
│ └─ netlify.toml
├─ common/
│ └─ package.json
└─ blog-2/
├─ package.json
└─ netlify.toml
The following ignore command example adapts the default behavior so that the build proceeds only if there are changes within the blog-1 or common directories.
[build]
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF . ../common/"
I run npm install on a project and get a deprecation error for an underlying dependency.
It is not a direct dependency, it's in node_modules. How can I easily figure out which of my dependencies eventually depends on the problematic library?
A first-pass solution is to use grep, but 2 issues:
This will help me locate the package.json containing the problematic dependency, but there could be 2, 3, 4...n packages between that and my own project's package.json
grep is a bit slow
What's wrong with using npm ls? Here's sample output for a module:
➜ node-address-rfc2821 git:(master) npm ls
address-rfc2821#2.0.0 /Users/matt/git/node-address-rfc2821
├─┬ nearley#2.20.1
│ ├── commander#2.20.3
│ ├── moo#0.5.1
│ ├── railroad-diagrams#1.0.0
│ └─┬ randexp#0.4.6
│ ├── discontinuous-range#1.0.0
│ └── ret#0.1.15
└── punycode#2.1.1
The command npm ls has been around since at least 2011