A package should register itself using a Bedrock event handler.
bedrock.events.on('bedrock.init', () => {
brPackageManager.register({
alias: 'mockPackage',
meta: {
optional: 'meta values',
},
packageName: '@bedrock/package-manager-mock-package',
type: 'bedrock-mock-plugin',
});
});
Use a registered package in an API.
exports.getReports = async ({query = {}, storageApi}) => {
// storageApi === 'mockPackage' would match the registration shown above
const pkg = brPackageManager.get({
alias: storageApi, type: 'bedrock-mock-plugin'
});
const storage = await import(pkg.packageName);
return storage.find(query);
};
- PackageInfo :
Object
Package information.
- bedrock-package-manager
- .get(options) ⇒
PackageInfo
- .findType(options) ⇒
Array.<PackageInfo>
- .register(options) ⇒
undefined
- .get(options) ⇒
bedrock-package-manager.get(options) ⇒ PackageInfo
Get package information. One of alias
or packageName
is required.
Kind: static method of bedrock-package-manager
Returns: PackageInfo
- The package information.
Throws:
BedrockError
Will throw aNotFoundError
if the package is not found.
Param | Type | Description |
---|---|---|
options | Object |
The options to use. |
options.type | string |
The package type. |
[options.alias] | string |
The package alias. |
[options.packageName] | string |
The package name. |
bedrock-package-manager.findType(options) ⇒ Array.<PackageInfo>
Find packages by type.
Kind: static method of bedrock-package-manager
Returns: Array.<PackageInfo>
- The package information.
Param | Type | Description |
---|---|---|
options | Object |
The options to use. |
options.type | string |
The package type to find. |
Register a package.
Kind: static method of bedrock-package-manager
Throws:
BedrockError
Will throw aDuplicateError
if the package is already registered.
Param | Type | Default | Description |
---|---|---|---|
options | Object |
The options to use. | |
options.packageName | string |
The NPM package name. | |
options.type | string |
The package type. | |
[options.meta] | Object |
{} |
Domain specific meta data. |
[options.alias] | string |
The package alias. A short name for the package (e.g. 'mongodb', 'redis'). |
Package information.
Kind: global typedef Properties
Name | Type | Description |
---|---|---|
alias | string |
The package alias. A short name for the package (e.g. 'mongodb', 'redis'). |
packageName | string |
The NPM package name. |
type | string |
The package type. |
meta | Object |
Domain specific meta data. |