Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register caches before plugins #39

Merged
merged 3 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ Here's the complete rundown of how files and directories are mapped to API calls
- **`path.js`** - export `relativeTo`.
- **`path/index.js`** - export `relativeTo`.

#### Plugin registrations
> [`await server.register(plugins, [options])`](https://github.com/hapijs/hapi/blob/master/API.md#server.register())

- **`plugins.js`** - export an array of objects `{ plugins, options }`.
- **`plugins/index.js`** - export an array of objects.
- **`plugins/plugin-name.js`** - export an object. If a plugin isn't specified in `plugins` it will be `require()`d using the filename.

#### Provisioning caches
> [`await server.cache.provision(options)`](https://github.com/hapijs/hapi/blob/master/API.md#server.cache.provision())

- **`caches.js`** - export an array of `options`.
- **`caches/index.js`** - export an array of `options`.
- **`caches/some-cache-name.js`** - export `options`. The cache's `options.name` will be assigned `'cache-name'` from the filename if a name isn't already specified.

#### Plugin registrations
> [`await server.register(plugins, [options])`](https://github.com/hapijs/hapi/blob/master/API.md#server.register())

- **`plugins.js`** - export an array of objects `{ plugins, options }`.
- **`plugins/index.js`** - export an array of objects.
- **`plugins/plugin-name.js`** - export an object. If a plugin isn't specified in `plugins` it will be `require()`d using the filename.

#### View manager (for [vision](https://github.com/hapijs/vision))
> [`server.views(options)`](https://github.com/hapijs/vision/blob/master/API.md#serverviewsoptions)

Expand Down
23 changes: 12 additions & 11 deletions lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ internals.manifest = [
list: false,
after: ['services']
},
{
place: 'caches',
method: 'cache.provision',
async: true,
list: true,
useFilename: internals.passthruOn('name'),
example: {
engine: null,
name: ''
}
},
{
place: 'plugins',
method: 'register',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the after property is to express exactly this sort of rule: "plugin registrations come after cache provisions." Can you also add after: ['caches'] to this plugin registrations item? It's described in a bit more detail here, but I am happy to elaborate!

Expand All @@ -142,6 +153,7 @@ internals.manifest = [

return value;
},
after: ['caches'],
example: {
plugins: { $value: [], $comment: 'May be an array or a single plugin' },
options: { $value: {}, $comment: 'Optional' }
Expand All @@ -159,17 +171,6 @@ internals.manifest = [
after: { $value: async (server) => {}, $comment: 'Optional' }
}
},
{
place: 'caches',
method: 'cache.provision',
async: true,
list: true,
useFilename: internals.passthruOn('name'),
example: {
engine: null,
name: ''
}
},
{
place: 'methods',
method: 'method',
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ describe('HauteCouture', () => {

expect(summary).to.equal([
'path() at path',
'register() at plugins',
'cache.provision() at caches',
'register() at plugins',
'views() at view-manager',
'decorate() at decorations',
'expose() at expose',
Expand Down Expand Up @@ -479,8 +479,8 @@ describe('HauteCouture', () => {

expect(summary).to.equal([
'path() at path',
'register() at plugins',
'cache.provision() at caches',
'register() at plugins',
'views() at view-manager',
'decorate() at decorations',
'expose() at expose',
Expand Down