
@vltpkg/workspaces
Utilities for working with vlt workspaces.
Usage · Run Order
Usage
import { Monorepo, Workspace } from '@vltpkg/workspaces'
const m = await Monorepo.load()
const appWS = m.get('@acme/app')
console.log(appWS.path)
console.log(appWS.groups)
console.log(await appWS.manifest())
console.log(appWS.inGroup('frontend'))
console.log(appWS.inGroup('datalayer'))
assert.equal(m.get('packages/apps/app'), appWS)
for (const workspace of m) {
}
m.run(async (ws, signal, depResults) => {
await doSomethingAsync(ws, signal)
})
console.log(m.group('app'))
m.group('app').run(async ([name, ws]) => {
console.log(name, ws)
})
const apps = new Monorepo()
apps.load({ groups: 'apps' })
const { manifest } = app.get('packages/my-app')
for (const name of m.names()) {
}
for (const path of m.paths()) {
}
Configuration is stored in the project root at vlt.json. The type of
the object in the file must be:
type VltProject = {
workspaces:
| string
| string[]
| { [group: string]: string | string[] }
}
If it's an object, each key is a group name, and each value is a path,
glob, or array of paths and globs, which specify the location of the
workspace projects. Glob matches are only considered if they are a
directory containing a package.json file.
A string or string[] in the file is interpreted as
{"packages": <value>}. Ie, the default group is packages.
Workspaces are allowed to be in multiple groups, so something like
this is fine:
{
"apps": "apps/*",
"frontend": ["utils/frontend", "apps/website"],
"utils": ["utils/**"]
}
If the glob patterns result in a situation where one workspace folder
is contained within another workspace folder, an error will be raised.
Run Order
The monorepo.run method can run an async function for each workspace
in the project, visiting each exactly once.
When workspaces depend on one another, it will walk dependencies
before dependents, unless there is a cycle, as that would be
impossible, and vlt does not prevent workspace dependency cycles.