BuildBus
@magento/pwa-buildpack
- @magento/pwa-buildpack
- ~BuildBus
- instance
- .getTargetsOf(depName) ⇒
Object.<string, Target>
- .init() ⇒
BuildBus
- .runPhase(phase)
- .getTargetsOf(depName) ⇒
- static
- .clear(context)
- .clearAll()
- .for(context) ⇒
BuildBus
- instance
- ~BuildBus
@magento/pwa-buildpack~BuildBus
Manages dependency participation in project builds and tasks. It executes their declare and intercept files so they can interact with each other.
Kind: inner class of @magento/pwa-buildpack
- ~BuildBus
- instance
- .getTargetsOf(depName) ⇒
Object.<string, Target>
- .init() ⇒
BuildBus
- .runPhase(phase)
- .getTargetsOf(depName) ⇒
- static
- .clear(context)
- .clearAll()
- .for(context) ⇒
BuildBus
- instance
buildBus.getTargetsOf(depName) ⇒ Object.<string, Target>
Get TargetProvider for the given named dependency. Use this to
retrieve and run targets in top-level code, when you have a reference to
the BuildBus. Declare and intercept functions should not, and cannot,
use this method. Instead, they retrieve external targets through their
targets.of()
methods.
Kind: instance method of BuildBus
Returns: Object.<string, Target>
- TargetProvider for the dependency.
Param | Type | Description |
---|---|---|
depName | string |
Dependency whose targets to retrieve. |
buildBus.init() ⇒ BuildBus
Run the two defined phases, declare
and intercept
, in order.
This binds all targets which the BuildBus can find by analyzing
dependencies in the project package file.
Kind: instance method of BuildBus
Chainable
Returns: BuildBus
- Returns this instance (chainable).
buildBus.runPhase(phase)
Run the specified phase. The BuildBus finds all dependencies which say
in their package.json
that they need to run code in this phase.
Kind: instance method of BuildBus
Param | Type | Description |
---|---|---|
phase | string |
‘declare’ or ‘intercept’ |
Example
<caption>Find all dependencies whith have `pwa-studio: { targets: { declare: './path/to/js' }} defined, and run those functions.
bus.runPhase('declare')
BuildBus.clear(context)
Remove the cached BuildBus for the given context.
Kind: static method of BuildBus
Param | Type | Description |
---|---|---|
context | string |
Root directory whose BuildBus to delete. |
BuildBus.clearAll()
Remove all cached BuildBus objects.
Kind: static method of BuildBus
BuildBus.for(context) ⇒ BuildBus
Get or create the BuildBus for the given context. This factory is the supported way to construct BuildBus instances. It caches the instances and connects them to the logging infrastructure.
Only one BuildBus is active for a project root directory (context) at any given time. This way, Buildpack code can retrieve the BuildBus for a context even if the bus instance hasn’t been sent as a parameter.
Kind: static method of BuildBus
Param | Type | Description |
---|---|---|
context | string |
Root directory of the BuildBus to get or create. |
Example (Get or create the BuildBus for the package.json file in `./project-dir`, then bind targets, then call a target.)
const bus = BuildBus.for('./project-dir);
bus.init();
bus.getTargetsOf('my-extension').myTarget.call();
For implementation details View Source.