From 54c8ece35bf710c8b8d66eabfa053cd68ab44c94 Mon Sep 17 00:00:00 2001 From: Stuart Clark Date: Tue, 19 Jul 2022 10:54:36 +1000 Subject: [PATCH] feat(#349): enable dependencies (#540) * feat(#349): enable breadcrumb dependencies * feat(#349): enable druxt-menu dependencies * feat(#349): enable druxt-router dependencies --- .changeset/itchy-roses-cross.md | 2 +- .changeset/lazy-wasps-deliver.md | 5 +++++ .changeset/pink-laws-boil.md | 5 +++++ .changeset/ten-vans-drum.md | 5 +++++ .changeset/three-emus-deny.md | 2 +- .changeset/tidy-melons-add.md | 2 +- packages/breadcrumb/src/nuxtModule.js | 21 +++++++++++++++++---- packages/menu/src/nuxtModule.js | 8 ++++---- packages/menu/test/nuxtModule.test.js | 5 +++-- packages/router/src/nuxt/index.js | 6 +++--- packages/router/test/nuxt/index.test.js | 1 + 11 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 .changeset/lazy-wasps-deliver.md create mode 100644 .changeset/pink-laws-boil.md create mode 100644 .changeset/ten-vans-drum.md diff --git a/.changeset/itchy-roses-cross.md b/.changeset/itchy-roses-cross.md index c783a853a..42d61a6f2 100644 --- a/.changeset/itchy-roses-cross.md +++ b/.changeset/itchy-roses-cross.md @@ -2,4 +2,4 @@ "druxt-site": minor --- -Added watch for 'theme' prop +Added watch for 'theme' prop. diff --git a/.changeset/lazy-wasps-deliver.md b/.changeset/lazy-wasps-deliver.md new file mode 100644 index 000000000..135312010 --- /dev/null +++ b/.changeset/lazy-wasps-deliver.md @@ -0,0 +1,5 @@ +--- +"druxt-router": minor +--- + +Enabled dependencies when only using Nuxt druxt-router module. diff --git a/.changeset/pink-laws-boil.md b/.changeset/pink-laws-boil.md new file mode 100644 index 000000000..a6a6a0259 --- /dev/null +++ b/.changeset/pink-laws-boil.md @@ -0,0 +1,5 @@ +--- +"druxt-breadcrumb": minor +--- + +Enabled dependencies when only using Nuxt druxt-breadcrumb module. diff --git a/.changeset/ten-vans-drum.md b/.changeset/ten-vans-drum.md new file mode 100644 index 000000000..ef3df024f --- /dev/null +++ b/.changeset/ten-vans-drum.md @@ -0,0 +1,5 @@ +--- +"druxt-menu": minor +--- + +Enabled dependencies when only using Nuxt druxt-menu module. diff --git a/.changeset/three-emus-deny.md b/.changeset/three-emus-deny.md index 73128d72f..811d6da60 100644 --- a/.changeset/three-emus-deny.md +++ b/.changeset/three-emus-deny.md @@ -2,4 +2,4 @@ "druxt-entity": minor --- -Added watch for 'settings' prop +Added watch for 'settings' prop. diff --git a/.changeset/tidy-melons-add.md b/.changeset/tidy-melons-add.md index 25b60eba8..9a9a2780e 100644 --- a/.changeset/tidy-melons-add.md +++ b/.changeset/tidy-melons-add.md @@ -2,4 +2,4 @@ "druxt-views": minor --- -Added watch for 'arguments' prop +Added watch for 'arguments' prop. diff --git a/packages/breadcrumb/src/nuxtModule.js b/packages/breadcrumb/src/nuxtModule.js index 79b221715..754a67bb4 100644 --- a/packages/breadcrumb/src/nuxtModule.js +++ b/packages/breadcrumb/src/nuxtModule.js @@ -21,7 +21,21 @@ import { join, resolve } from 'path' * * @param {object} moduleOptions - Nuxt.js module options object. */ -const DruxtBreadcrumbModule = function () { +const DruxtBreadcrumbModule = async function (moduleOptions = {}) { + // Set default options. + const options = { + baseUrl: moduleOptions.baseUrl, + ...(this.options || {}).druxt || {}, + breadcrumb: { + ...((this.options || {}).druxt || {}).breadcrumb, + ...moduleOptions, + } + } + + // Add dependent module. + await this.addModule(['druxt', options]) + await this.addModule(['druxt-router/nuxt', options]) + // Register components directories. this.nuxt.hook('components:dirs', dirs => { dirs.push({ path: join(__dirname, 'components') }) @@ -29,13 +43,12 @@ const DruxtBreadcrumbModule = function () { }) // Nuxt Storybook. - const { addTemplate, options } = this this.nuxt.hook('storybook:config', ({ stories }) => { - addTemplate({ + this.addTemplate({ src: resolve(__dirname, '../templates/druxt-breadcrumb.stories.js'), fileName: 'stories/druxt-breadcrumb.stories.js', }) - stories.push(resolve(options.buildDir, './stories/druxt-breadcrumb.stories.js')) + stories.push(resolve(this.options.buildDir, './stories/druxt-breadcrumb.stories.js')) }) } diff --git a/packages/menu/src/nuxtModule.js b/packages/menu/src/nuxtModule.js index 0ec90eae0..bd895a6b3 100644 --- a/packages/menu/src/nuxtModule.js +++ b/packages/menu/src/nuxtModule.js @@ -25,7 +25,7 @@ import DruxtMenuStorybook from './nuxtStorybook' * * @param {object} moduleOptions - Module options object. */ -const DruxtMenuNuxtModule = function (moduleOptions = {}) { +const DruxtMenuNuxtModule = async function (moduleOptions = {}) { // Set default options. const options = { baseUrl: moduleOptions.baseUrl, @@ -36,6 +36,9 @@ const DruxtMenuNuxtModule = function (moduleOptions = {}) { } } + // Add dependant modules. + await this.addModule(['druxt', options]) + // Register components directories. this.nuxt.hook('components:dirs', dirs => { dirs.push({ path: join(__dirname, 'components') }) @@ -49,9 +52,6 @@ const DruxtMenuNuxtModule = function (moduleOptions = {}) { options }) - // Enable Vuex Store. - this.options.store = true - // Add Vuex plugin. this.addPlugin({ src: resolve(__dirname, '../templates/store.js'), diff --git a/packages/menu/test/nuxtModule.test.js b/packages/menu/test/nuxtModule.test.js index 12e4b3d46..f8197a3c0 100644 --- a/packages/menu/test/nuxtModule.test.js +++ b/packages/menu/test/nuxtModule.test.js @@ -3,6 +3,7 @@ import { DruxtMenuNuxtModule } from '../src/nuxtModule' jest.mock('../src/nuxtStorybook') const mock = { + addModule: jest.fn(), addPlugin: jest.fn(), nuxt: { hook: jest.fn((hook, fn) => { @@ -18,7 +19,7 @@ const mock = { } } -test('Nuxt module', () => { - DruxtMenuNuxtModule.call(mock) +test('Nuxt module', async () => { + await DruxtMenuNuxtModule.call(mock) expect(mock.addPlugin).toHaveBeenCalled() }) diff --git a/packages/router/src/nuxt/index.js b/packages/router/src/nuxt/index.js index 8f0881a8c..f2cbbe2e3 100644 --- a/packages/router/src/nuxt/index.js +++ b/packages/router/src/nuxt/index.js @@ -40,6 +40,9 @@ const DruxtRouterNuxtModule = async function (moduleOptions = {}) { } } + // Add dependant modules. + await this.addModule(['druxt', options]) + // Register components directories. this.nuxt.hook('components:dirs', dirs => { dirs.push({ path: join(__dirname, '../dist/components') }) @@ -107,9 +110,6 @@ const DruxtRouterNuxtModule = async function (moduleOptions = {}) { options }) - // Enable Vuex Store. - this.options.store = true - // Add Vuex plugin. this.addPlugin({ src: resolve(__dirname, '../templates/store.js'), diff --git a/packages/router/test/nuxt/index.test.js b/packages/router/test/nuxt/index.test.js index 02924d940..58559174d 100644 --- a/packages/router/test/nuxt/index.test.js +++ b/packages/router/test/nuxt/index.test.js @@ -1,6 +1,7 @@ import DruxtRouterNuxtModule from '../../nuxt' const mock = { + addModule: jest.fn(), addPlugin: jest.fn(), addTemplate: jest.fn(), extendRoutes: jest.fn((func) => {