Skip to content

Commit

Permalink
Merge pull request #2 from codex-team/sourcemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
neSpecc authored Sep 29, 2024
2 parents 0c9fa4f + 6504fc2 commit 0bb9b91
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 12 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- 😋 Effortless installation
- 🦅 Track errors seamlessly across your Nuxt app
- 💼 Composable for manually sending errors and logs
- 💌 Sends release info with source maps

## Quick Setup

Expand All @@ -29,7 +30,7 @@ export default defineNuxtConfig({
'@hawk.so/nuxt'
],
hawk: {
tokenClient: process.env.HAWK_TOKEN_CLIENT,
token: process.env.HAWK_TOKEN,
},
})
```
Expand Down
13 changes: 11 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hawk.so/nuxt",
"version": "0.0.2",
"version": "0.0.3",
"description": "Hawk error tracker integration to Nuxt app",
"repository": "https://github.com/codex-team/hawk.nuxt",
"license": "MIT",
Expand Down Expand Up @@ -30,6 +30,7 @@
},
"dependencies": {
"@hawk.so/javascript": "^3.0.2",
"@hawk.so/vite-plugin": "^1.0.3",
"@nuxt/kit": "^3.13.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions playground/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Hawk error tracker Integration Token for client-side errors
HAWK_TOKEN_CLIENT=
# Hawk error tracker Integration Token
HAWK_TOKEN=
2 changes: 1 addition & 1 deletion playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default defineNuxtConfig({
modules: ['../src/module'],
hawk: {
tokenClient: process.env.HAWK_TOKEN_CLIENT,
token: process.env.HAWK_TOKEN,
},
devtools: { enabled: true },
})
17 changes: 15 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { defineNuxtModule, addPlugin, createResolver, updateRuntimeConfig, useRuntimeConfig, addImportsDir } from '@nuxt/kit'
import hawkVitePlugin from '@hawk.so/vite-plugin'
import type { HawkModuleConfig } from './types'

export default defineNuxtModule<HawkModuleConfig>({
meta: {
name: '@hawk.so/nuxt',
configKey: 'hawk',
},
// Default configuration options of the Nuxt module
defaults: {},
setup(config, _nuxt) {
setup(config, nuxt) {
const resolver = createResolver(import.meta.url)
const runtimeConfig = useRuntimeConfig()

Expand All @@ -32,5 +32,18 @@ export default defineNuxtModule<HawkModuleConfig>({
})

addImportsDir(resolver.resolve('./runtime/composables'))

/**
* Add @hawk.so/vite-plugin for source maps sending
*/
nuxt.hook('vite:extendConfig', (viteConfig) => {
viteConfig.plugins = viteConfig.plugins || []

viteConfig.plugins.push(
hawkVitePlugin({
token: config.token,
}),
)
})
},
})
27 changes: 26 additions & 1 deletion src/runtime/plugin.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,38 @@ import HawkCatcher from '@hawk.so/javascript'
import type { HawkModuleConfig } from '../types'
import { defineNuxtPlugin, useRuntimeConfig } from '#app'

/**
* Returns the global object depending on the environment
*/
function getGlobal(): typeof globalThis {
return typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: typeof self !== 'undefined'
? self
: {} as typeof globalThis
}

/**
* Returns the release ID from the global context
* This variable is injected by the @hawk.so/vite-plugin
*/
function getReleaseId(): string | undefined {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const global = getGlobal() as any

return global.HAWK_RELEASE
}

export default defineNuxtPlugin((nuxtApp) => {
const runtimeConfig = useRuntimeConfig()
const hawkConfig = runtimeConfig.public.hawk as HawkModuleConfig

const hawkInstance = new HawkCatcher({
token: hawkConfig.tokenClient,
token: hawkConfig.token,
vue: nuxtApp.vueApp,
release: getReleaseId(),
})

/**
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
export interface HawkModuleConfig {
/**
* Hawk Integration token for client-side errors
* Hawk Integration token
*/
tokenClient: string
token: string
}

0 comments on commit 0bb9b91

Please sign in to comment.