Skip to content

Commit

Permalink
fix(module): handle entry errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed Jun 26, 2020
1 parent e988e4f commit f8051d0
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/module.ts
Expand Up @@ -9,11 +9,11 @@ import { ensureUserconsent } from './consent'
import log from './utils/log'
import { hash } from './utils/hash'

async function telemetryModule () {
async function _telemetryModule (nuxt) {
const toptions: TelemetryOptions = {
endpoint: destr(process.env.NUXT_TELEMETRY_ENDPOINT) || 'https://telemetry.nuxtjs.com',
debug: destr(process.env.NUXT_TELEMETRY_DEBUG),
...this.options.telemetry
...nuxt.options.telemetry
}

if (!toptions.debug) {
Expand All @@ -22,7 +22,7 @@ async function telemetryModule () {

if (
toptions.enabled === false ||
this.options.telemetry === false ||
nuxt.options.telemetry === false ||
!await ensureUserconsent(toptions)
) {
log.info('Telemetry disabled')
Expand All @@ -36,26 +36,34 @@ async function telemetryModule () {
log.info('Seed generated:', toptions.seed)
}

const t = new Telemetry(this.nuxt, toptions)
const t = new Telemetry(nuxt, toptions)

if (this.options._start) {
if (nuxt.options._start) {
// nuxt start
this.nuxt.hook('listen', () => {
nuxt.hook('listen', () => {
t.createEvent('project')
t.createEvent('session')
t.createEvent('command')
t.sendEvents()
})
}

this.nuxt.hook('build:before', () => {
nuxt.hook('build:before', () => {
t.createEvent('project')
t.createEvent('session')
t.createEvent('command')
t.createEvent('dependency')
})

profile(this.nuxt, t)
profile(nuxt, t)
}

async function telemetryModule () {
try {
await _telemetryModule(this.nuxt)
} catch (err) {
log.error(err)
}
}

function profile (nuxt: Nuxt, t: Telemetry) {
Expand Down

0 comments on commit f8051d0

Please sign in to comment.