@gasket/plugin-metadata
Advanced tools
Comparing version 7.0.6 to 7.0.9
@@ -52,2 +52,3 @@ const path = require('path'); | ||
// eslint-disable-next-line max-statements | ||
await gasket.execApply('metadata', async (plugin, handler) => { | ||
@@ -66,3 +67,10 @@ const isPreset = isGasketPreset.test(plugin.name); | ||
} else { | ||
pluginData.metadata.path = path.dirname(path.join(require.resolve(pluginData.name), '..')); | ||
let resolvedPath; | ||
try { | ||
resolvedPath = require.resolve(pluginData.name, { paths: [gasket.config.root] }); | ||
} catch (error) { | ||
gasket.logger.error(`Error resolving plugin ${pluginData.name}: ${error.message}`); | ||
return; | ||
} | ||
pluginData.metadata.path = path.dirname(path.join(resolvedPath, '..')); | ||
const { dependencies, devDependencies } = require(path.join(pluginData.metadata.path, 'package.json')); | ||
@@ -78,2 +86,3 @@ | ||
const isModule = isGasketModule.test(name); | ||
// eslint-disable-next-line no-continue | ||
if (!isModule) continue; | ||
@@ -80,0 +89,0 @@ |
{ | ||
"name": "@gasket/plugin-metadata", | ||
"version": "7.0.6", | ||
"version": "7.0.9", | ||
"description": "Adds metadata to gasket lifecycles", | ||
@@ -39,3 +39,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@gasket/core": "^7.0.6" | ||
"@gasket/core": "^7.0.9", | ||
"@gasket/plugin-logger": "^7.0.9" | ||
}, | ||
@@ -67,3 +68,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "90fec87372fb74755e92668a9158fc3c820dd37f" | ||
"gitHead": "ff3acd042a9a22cd43ac29c6b064bd2f49304b9e" | ||
} |
# @gasket/plugin-metadata | ||
Metadata is the information about the register plugins and presets, available to | ||
Metadata is the information about the registered plugins and presets, available to | ||
plugin lifecycle hooks. This data can be used in various was for plugins, most | ||
@@ -9,3 +9,3 @@ notably the [@gasket/plugin-docs] which uses it to collate docs for an app. | ||
This is a default plugin in the Gasket CLI and is always available for use. | ||
This is a default plugin in newly create Gasket apps. | ||
@@ -59,4 +59,8 @@ ## Actions | ||
modules: [ | ||
'left-pad', | ||
{ name: 'right-pad', extra: 'data', link: 'DOC.md' } | ||
{ | ||
name: 'module-name', | ||
version: '7.0.0', | ||
description: 'module-name despcrition', | ||
link: 'README.md' | ||
} | ||
] | ||
@@ -116,4 +120,4 @@ } | ||
Plugins and apps can read from the [metadata object] by accessing | ||
`gasket.metadata` in most lifecycles. | ||
Plugins and apps can read from the [metadata object] by using | ||
the `getMetadata` Gasket action. | ||
@@ -123,3 +127,3 @@ #### Access example | ||
Back to our example plugin, let's see how we can access details about an | ||
installed module, and put is some conditional logic. | ||
installed module, and put is some conditional logic. | ||
@@ -133,27 +137,6 @@ ```js | ||
hooks: { | ||
// Because metadata is collected during the init lifecycle, we must | ||
// adjust our init hook to occur after in order to read the metadata | ||
init: { | ||
timing: { | ||
after: ['@gasket/metadata'] | ||
}, | ||
handler: function initHook(gasket) { | ||
const { metadata } = gasket; | ||
// Find the ModuleData for a package | ||
const moduleData = metadata.modules.find(mod => mod.name === 'some-package'); | ||
// If it is installed, and meets requires | ||
if(moduleData && semver.satisfies(moduleData.version, '13.x')) { | ||
// Do something special | ||
} else { | ||
// Skip and issue warning about upgrading | ||
} | ||
// Find the PluginData for a plugin | ||
const pluginData = metadata.plugins.find(mod => mod.name === 'gasket-plugin-feature'); | ||
if(pluginData) { | ||
// Fallback for when a certain plugin is not installed | ||
} | ||
} | ||
// We need access to metadata during build | ||
async build(gasket) { | ||
const metadata = await gasket.actions.getMetadata() | ||
// ... use metadata | ||
} | ||
@@ -164,22 +147,2 @@ } | ||
## How it works | ||
Metadata begins with the info objects from the `Loader` of [@gasket/resolve] and | ||
builds data objects for [plugins][PluginData], and [presets][PresetData], and | ||
supporting [modules][ModuleData]. Any functions preset will be **redacted**, as | ||
metadata is not intended to be executed, but rather to is made available to read | ||
and inform plugins. This data can be added to, by hooking the [metadata] | ||
lifecycle in a plugin. | ||
Metadata provides insights to a plugin's shape and package information. | ||
Additional [detail info][DetailData] of plugins can added in the [metadata] | ||
lifecycle, such as what commands, lifecycles, or structures, a plugin provides. | ||
The [metadata object] be accessed in lifecycle hooks from `gasket.metadata`. | ||
Additionally, [ModuleData] for all the top-level app's dependencies are loaded | ||
by default, and is available from `gasket.metadata.app.modules`. Plugins can | ||
choose to bring in metadata for more modules, or augment what has already been | ||
loaded for the app. These, along with the app's modules, will be flattened and | ||
available from `gasket.metadata.modules`. | ||
## License | ||
@@ -186,0 +149,0 @@ |
331
17279
2
163
+ Added@gasket/plugin-logger@^7.0.9
+ Added@gasket/plugin-logger@7.2.0(transitive)
Updated@gasket/core@^7.0.9