@modular-scripts/workspace-resolver
v2.0.0
Published
This package encapsulates two functions:
Downloads
341
Readme
@modular-scripts/workspace-resolver
This package encapsulates two functions:
resolveWorkspace
- Searches the filesystem (at a given modular root) for workspace packages, returning a flat map of all packages found, with an additionaltype
field containing the modular type (if present). An optional 2nd argument oftarget
can be passed, which sets the working directory that workspaces should be resolved from. This can be useful when the modular root needs to be different to the current working directory, such as when modularconvert
orport
happens.analyzeWorkspaceDependencies
- Analyzespackage.json
files for a set of workspace packages, returning a flat object for each package, listing out workspace inter-dependencies plus and mismatched dependencies. The dependencies are analyzed according to dependencies defined inpackage.json
files. The resulting output intends to match the yarn v1 (classic) output foryarn workspaces info
(1)
In most cases, the output of resolveWorkspace
can be passed directly to
analyzeWorkspaceDependencies
.
(1) This package exists as a drop-in replacement for yarn workspaces info
because the yarn command is not consistent across other versions of yarn.
Example
const [workspacePackages] = resolveWorkspace('path/to/modular/project/root')
/*
Map {
"example-package": {
path: 'packages/example-package',
name: 'example-package',
workspace: false,
version: '1.0.0',
modular: {
type: 'package'
},
type: 'package',
children: [],
parent: null,
dependencies: {
'lodash': '10.0.0'
}
},
...
}
*/
const analyzed = analyzeWorkspaceDependencies(workspacePackages);
/*
{
"example-package": {
"location": "packages/example-package",
"workspaceDependencies": ['another-package'],
"mismatchedWorkspaceDependencies": []
},
"another-package": {
"location": "packages/another-package",
"workspaceDependencies": [],
"mismatchedWorkspaceDependencies": ['mismatched-dep-one']
},
...
*/