@techor/npm
v3.0.23
Published
Get, query, and read such as package workspaces via NPM/PNPM.
Downloads
158
Maintainers
Readme
queryWorkspaces()
- By default, read
.workspaces
of package.json in the current working directory - By default, workspaces in node_modules are excluded
Your monorepo usually looks like this:
.
├── package.json
└── packages
+ ├─── a
│ └─── package.json
+ ├─── b
│ ├─── node_modules
│ │ └─── fake-module
│ │ └─── package.json
+ │ ├─── bb
│ │ └─── package.json
│ └─── package.json
└─── c
./package.json
{
"workspaces": ["packages/**"]
}
Usage
queryWorkspaces(patterns?, options?): string[]
import queryWorkspaces from '@techor/npm'
const workspaces = queryWorkspaces()
// ['packages/a', 'packages/b', 'packages/b/bb']
const workspaces = queryWorkspaces(['packages/*'])
// ['packages/a', 'packages/b']
Options
Inherited from fast-glob options
{
cwd: process.cwd(),
ignore: ['**/node_modules/**']
}
readWorkspacePackages()
- By default, read workspace packages by package.json
.workspaces
in the current working directory - By default, workspace packages in node_modules are excluded
Your monorepo usually looks like this:
.
├── package.json
└── packages
├─── a
│ └─── package.json
├─── b
│ ├─── node_modules
│ │ └─── fake-module
│ │ └─── package.json
│ ├─── bb
│ │ └─── package.json
│ └─── package.json
├─── c
└─── d
└─── package.json
./package.json
{
"workspaces": ["packages/**"]
}
./packages/d/package.json
{
"name": "d",
"private": true
}
Usage
readWorkspacePackages(patterns?, options?): any[]
import readWorkspacePackages from '@techor/read-workspace-packages'
const packages = readWorkspacePackages()
// [{ name: 'a' }, { name: 'b' }, { name: 'd', private: true }, { name: 'bb' }]
const packages = readWorkspacePackages(['packages/*'])
// [{ name: 'a' }, { name: 'b' }, { name: 'd', private: true }]
const publicPackages = readWorkspacePackages()
.fiter((eachWorkspacePackage) => !eachWorkspacePackage.private)
// [{ name: 'a' }, { name: 'b' }, { name: 'bb' }]
Options
Inherited from fast-glob options
{
cwd: process.cwd(),
ignore: ['**/node_modules/**']
}