[READ-ONLY] Mirror of https://github.com/danielroe/nuxt-timings-module.
0

Configure Feed

Select the types of activity you want to include in your feed.

chore: migrate to using `@nuxt/kit` to define module

Daniel Roe (Jun 10, 2021, 10:43 AM +0100) edcae2e6 33d8969b

+77 -46
+1 -1
package.json
··· 33 33 "test": "yarn lint && yarn build && yarn jest" 34 34 }, 35 35 "dependencies": { 36 + "@nuxt/kit": "^0.6.2", 36 37 "chalk": "4.1.1", 37 38 "consola": "2.15.3", 38 - "defu": "5.0.0", 39 39 "upath": "2.0.1" 40 40 }, 41 41 "devDependencies": {
+40
yarn.lock
··· 1361 1361 node-html-parser "^3.3.0" 1362 1362 ufo "^0.7.4" 1363 1363 1364 + "@nuxt/kit@^0.6.2": 1365 + version "0.6.2" 1366 + resolved "https://registry.yarnpkg.com/@nuxt/kit/-/kit-0.6.2.tgz#f6747c6b215a6e5cb174cc5b503b6c423e3d35bf" 1367 + integrity sha512-hiCG3Tfa2pE9QAEZBtuoXvG78JcU1BlbXGq6N2Uodpd8cIow6v9vZfKWciHe5NwlBEWZcQ9eVmYq1R4ukSNT9w== 1368 + dependencies: 1369 + consola "^2.15.3" 1370 + create-require "^1.1.1" 1371 + defu "^5.0.0" 1372 + dotenv "^10.0.0" 1373 + globby "^11.0.3" 1374 + hash-sum "^2.0.0" 1375 + jiti "^1.9.2" 1376 + rc9 "^1.2.0" 1377 + scule "^0.2.1" 1378 + std-env "^2.3.0" 1379 + ufo "^0.7.5" 1380 + unctx "^0.0.3" 1381 + untyped "^0.2.5" 1382 + upath "^2.0.1" 1383 + 1364 1384 "@nuxt/loading-screen@^2.0.3": 1365 1385 version "2.0.3" 1366 1386 resolved "https://registry.yarnpkg.com/@nuxt/loading-screen/-/loading-screen-2.0.3.tgz#1d6b1f976bb143c6592231af0bf7fa6245f6ebd2" ··· 4795 4815 integrity sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q== 4796 4816 dependencies: 4797 4817 is-obj "^2.0.0" 4818 + 4819 + dotenv@^10.0.0: 4820 + version "10.0.0" 4821 + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81" 4822 + integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== 4798 4823 4799 4824 dotenv@^8.2.0: 4800 4825 version "8.2.0" ··· 11752 11777 resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.7.4.tgz#06e971738bea098b95056755ba006a6b73a63f97" 11753 11778 integrity sha512-qFCjO4/IAaejZ6QKVBdM7FZkjhd8zQmBmE6i2bcSwBRrctPVtKXFojJa2flaqNUd7YWQoCFwd44MpOt1g94ekQ== 11754 11779 11780 + ufo@^0.7.5: 11781 + version "0.7.5" 11782 + resolved "https://registry.yarnpkg.com/ufo/-/ufo-0.7.5.tgz#5d5b2174747c0072edd30501994c8ac4ad2e77ea" 11783 + integrity sha512-FGG+EgguC1oz5dTE1JptPWCyj6Z9mYpwvZY8PTu9Vh/Aoy+Mj9cpeQ3gg4kyEMDbMrH+lTYiw7bomG58B8X7Kg== 11784 + 11755 11785 uglify-js@^3.1.4, uglify-js@^3.5.1: 11756 11786 version "3.13.4" 11757 11787 resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.13.4.tgz#592588bb9f47ae03b24916e2471218d914955574" ··· 11766 11796 has-bigints "^1.0.1" 11767 11797 has-symbols "^1.0.2" 11768 11798 which-boxed-primitive "^1.0.2" 11799 + 11800 + unctx@^0.0.3: 11801 + version "0.0.3" 11802 + resolved "https://registry.yarnpkg.com/unctx/-/unctx-0.0.3.tgz#e06f67d5bebe2babe5a57c1dc13d77255e3458c0" 11803 + integrity sha512-x+NCoXiYn93laQNnoJGZx2UZj7vv8ViFKadUCDx9S4QoPIkGRCYT0OLUDEMlg/B+Q6bnqdSkPLmiy/kjNIwVyQ== 11769 11804 11770 11805 unfetch@^4.2.0: 11771 11806 version "4.2.0" ··· 11868 11903 dependencies: 11869 11904 has-value "^0.3.1" 11870 11905 isobject "^3.0.0" 11906 + 11907 + untyped@^0.2.5: 11908 + version "0.2.5" 11909 + resolved "https://registry.yarnpkg.com/untyped/-/untyped-0.2.5.tgz#0464bb73509d8f1078eb7a70dacb67fa92cfed53" 11910 + integrity sha512-VYYchiYP9EUXISmErn1aFzhikpWhxSic8IsJzPDEZ/MyezenSDhNua0YHh9jY/54aDlv0G4yjPThEr+tXZA7SA== 11871 11911 11872 11912 upath@2.0.1, upath@^2.0.1: 11873 11913 version "2.0.1"
+3 -4
src/fetch.ts
··· 1 + import { addPlugin } from '@nuxt/kit' 1 2 import { extname } from 'upath' 2 3 3 - import type { ModuleThis } from '@nuxt/types/config/module' 4 - 5 - export function registerFetchTimings (this: ModuleThis) { 4 + export function registerFetchTimings () { 6 5 const src = require.resolve('./templates/fetch') 7 - this.addPlugin({ 6 + addPlugin({ 8 7 src, 9 8 fileName: 'timings-fetch.server' + extname(src) 10 9 })
+20 -20
src/index.ts
··· 1 - import type { Module, NuxtOptions } from '@nuxt/types' 1 + // eslint-disable-next-line 2 + import type { Module } from '@nuxt/types' 3 + import { defineNuxtModule } from '@nuxt/kit' 2 4 3 5 import { bold } from 'chalk' 4 6 import consola from 'consola' 5 - import defu from 'defu' 6 7 7 - import { name, version } from '../package.json' 8 + import { name } from '../package.json' 8 9 import { registerFetchTimings } from './fetch' 9 10 import { registerPluginTimings } from './plugins' 10 11 import { registerStoreTimings } from './store' ··· 14 15 enabled?: boolean 15 16 } 16 17 17 - const nuxtModule: Module<ModuleOptions> = function (moduleOptions) { 18 - const nuxtOptions = this.nuxt.options as NuxtOptions 19 - const providedOptions = defu(this.options[CONFIG_KEY] /* istanbul ignore next */ || {}, moduleOptions, { enabled: nuxtOptions.dev }) 18 + export default defineNuxtModule(nuxt => ({ 19 + name, 20 + configKey: CONFIG_KEY, 21 + defaults: { enabled: nuxt.options.dev }, 22 + setup (options, nuxt) { 23 + if (!options.enabled) { 24 + return 25 + } 20 26 21 - if (!providedOptions.enabled) { 22 - return 27 + consola.info(`Enabling ${bold('nuxt-timings')}.`) 28 + 29 + nuxt.options.server.timing = { total: true } as any 30 + 31 + registerPluginTimings() 32 + registerStoreTimings() 33 + registerFetchTimings() 23 34 } 24 - 25 - consola.info(`Enabling ${bold('nuxt-timings')}.`) 26 - 27 - nuxtOptions.server.timing = { total: true } 28 - 29 - registerPluginTimings.call(this) 30 - registerStoreTimings.call(this) 31 - registerFetchTimings.call(this) 32 - } 33 - ;(nuxtModule as any).meta = { name, version } 35 + })) 34 36 35 37 declare module '@nuxt/types' { 36 38 interface NuxtConfig { ··· 40 42 [CONFIG_KEY]?: ModuleOptions; 41 43 } // Nuxt 2.9 - 2.13 42 44 } 43 - 44 - export default nuxtModule 45 45 46 46 export type { ModuleOptions }
+10 -17
src/plugins.ts
··· 1 + import { addTemplate, useNuxt } from '@nuxt/kit' 1 2 import { extname, resolve } from 'upath' 2 3 3 - import type { NuxtOptions } from '@nuxt/types' 4 - import type { ModuleThis } from '@nuxt/types/config/module' 5 4 import type { NuxtOptionsPlugin } from '@nuxt/types/config/plugin' 6 5 7 6 function templateFile ( 8 - this: ModuleThis, 9 7 src: string, 10 8 fileName: string, 11 9 options: Record<string, any> 12 10 ) { 13 - const { dst } = this.addTemplate({ 14 - src, 15 - fileName, 16 - options 17 - }) 18 - return resolve(this.nuxt.options.buildDir, dst) 11 + const nuxt = useNuxt() 12 + const { dst } = addTemplate({ src, fileName, options }) 13 + return resolve(nuxt.options.buildDir, dst) 19 14 } 20 15 21 - export function registerPluginTimings (this: ModuleThis) { 22 - const nuxtOptions = this.nuxt.options as NuxtOptions 16 + export function registerPluginTimings () { 17 + const nuxt = useNuxt() 23 18 24 - nuxtOptions.plugins = nuxtOptions.plugins.reduce((plugins, plugin, index) => { 25 - const pluginName = (typeof plugin === 'string' ? plugin : plugin.src).replace(nuxtOptions.buildDir + '/', '').replace('~/plugins/', '').replace('~/', '') 19 + nuxt.options.plugins = nuxt.options.plugins.reduce((plugins, plugin, index) => { 20 + const pluginName = (typeof plugin === 'string' ? plugin : plugin.src).replace(nuxt.options.buildDir + '/', '').replace('~/plugins/', '').replace('~/', '') 26 21 27 22 const src = require.resolve('./templates/plugins') 28 - const before = templateFile.call( 29 - this, 23 + const before = templateFile( 30 24 src, 31 25 'timings-plugins-' + index + 'before.server' + extname(src), 32 26 { ··· 34 28 mode: 'start' 35 29 } 36 30 ) 37 - const after = templateFile.call( 38 - this, 31 + const after = templateFile( 39 32 src, 40 33 'timings-plugins-' + index + 'after.server' + extname(src), 41 34 {
+3 -4
src/store.ts
··· 1 + import { addPlugin } from '@nuxt/kit' 1 2 import { extname } from 'upath' 2 3 3 - import type { ModuleThis } from '@nuxt/types/config/module' 4 - 5 - export function registerStoreTimings (this: ModuleThis) { 4 + export function registerStoreTimings () { 6 5 const src = require.resolve('./templates/store') 7 - this.addPlugin({ 6 + addPlugin({ 8 7 src, 9 8 fileName: 'timings-store.server' + extname(src) 10 9 })