@posthog/nuxt 0.0.27 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.d.mts +11 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +89 -71
- package/dist/runtime/nitro-plugin.js +18 -15
- package/dist/runtime/vue-plugin.d.ts +2 -2
- package/dist/runtime/vue-plugin.js +18 -9
- package/dist/types.d.mts +1 -1
- package/package.json +5 -5
package/dist/module.d.mts
CHANGED
|
@@ -12,16 +12,24 @@ interface EnabledSourcemaps {
|
|
|
12
12
|
version?: string;
|
|
13
13
|
project?: string;
|
|
14
14
|
verbose?: boolean;
|
|
15
|
+
deleteAfterUpload?: boolean;
|
|
15
16
|
}
|
|
16
17
|
interface ModuleOptions {
|
|
17
18
|
host: string;
|
|
18
19
|
publicKey: string;
|
|
19
20
|
debug?: boolean;
|
|
20
|
-
clientConfig?:
|
|
21
|
-
serverConfig?:
|
|
21
|
+
clientConfig?: PostHogClientConfig;
|
|
22
|
+
serverConfig?: PostHogServerConfig;
|
|
22
23
|
sourcemaps: DisabledSourcemaps | EnabledSourcemaps | undefined;
|
|
23
24
|
}
|
|
25
|
+
interface PostHogCommon {
|
|
26
|
+
publicKey: string;
|
|
27
|
+
host: string;
|
|
28
|
+
debug?: boolean;
|
|
29
|
+
}
|
|
30
|
+
type PostHogServerConfig = PostHogOptions;
|
|
31
|
+
type PostHogClientConfig = Partial<PostHogConfig>;
|
|
24
32
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
25
33
|
|
|
26
34
|
export { _default as default };
|
|
27
|
-
export type { ModuleOptions };
|
|
35
|
+
export type { ModuleOptions, PostHogClientConfig, PostHogCommon, PostHogServerConfig };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addPlugin, addServerPlugin } from '@nuxt/kit';
|
|
2
2
|
import { spawnLocal } from '@posthog/core/process';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { dirname } from 'node:path';
|
|
4
|
+
import path, { dirname } from 'node:path';
|
|
5
5
|
|
|
6
|
-
const VUE_OUTPUT_DIRECTORY = ".output/public";
|
|
7
|
-
const NITRO_OUTPUT_DIRECTORY = ".output/server";
|
|
8
6
|
const filename = fileURLToPath(import.meta.url);
|
|
9
7
|
const resolvedDirname = dirname(filename);
|
|
10
8
|
const module = defineNuxtModule({
|
|
@@ -25,85 +23,105 @@ const module = defineNuxtModule({
|
|
|
25
23
|
const resolver = createResolver(import.meta.url);
|
|
26
24
|
addPlugin(resolver.resolve("./runtime/vue-plugin"));
|
|
27
25
|
addServerPlugin(resolver.resolve("./runtime/nitro-plugin"));
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
26
|
+
Object.assign(nuxt.options.runtimeConfig.public, {
|
|
27
|
+
posthog: {
|
|
28
|
+
publicKey: options.publicKey,
|
|
29
|
+
host: options.host,
|
|
30
|
+
debug: options.debug
|
|
31
|
+
},
|
|
32
|
+
posthogClientConfig: options.clientConfig
|
|
33
|
+
});
|
|
34
|
+
Object.assign(nuxt.options.runtimeConfig, {
|
|
35
|
+
posthogServerConfig: options.serverConfig
|
|
36
|
+
});
|
|
36
37
|
const sourcemapsConfig = options.sourcemaps;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
POSTHOG_CLI_ENV_ID: sourcemapsConfig.envId,
|
|
40
|
-
POSTHOG_CLI_TOKEN: sourcemapsConfig.personalApiKey
|
|
41
|
-
};
|
|
42
|
-
const sharedInjectOptions = [
|
|
43
|
-
"--host",
|
|
44
|
-
options.host,
|
|
45
|
-
"sourcemap",
|
|
46
|
-
"inject",
|
|
47
|
-
"--ignore",
|
|
48
|
-
"**/node_modules/**"
|
|
49
|
-
];
|
|
50
|
-
if (options.sourcemaps.project) {
|
|
51
|
-
sharedInjectOptions.push("--project", options.sourcemaps.project);
|
|
52
|
-
}
|
|
53
|
-
if (options.sourcemaps.version) {
|
|
54
|
-
sharedInjectOptions.push("--version", options.sourcemaps.version);
|
|
38
|
+
if (!sourcemapsConfig?.enabled || nuxt.options.dev) {
|
|
39
|
+
return;
|
|
55
40
|
}
|
|
56
|
-
nuxt.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
41
|
+
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
42
|
+
nitroConfig.rollupConfig = {
|
|
43
|
+
...nitroConfig.rollupConfig || {},
|
|
44
|
+
output: {
|
|
45
|
+
...nitroConfig.rollupConfig?.output || {},
|
|
46
|
+
sourcemapExcludeSources: false
|
|
47
|
+
// Make sure to set it (otherwise server sourcemaps will not be generated)
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
nuxt.hook("build:before", () => {
|
|
52
|
+
nuxt.options.sourcemap = {
|
|
53
|
+
client: "hidden",
|
|
54
|
+
server: "hidden"
|
|
55
|
+
};
|
|
69
56
|
});
|
|
70
|
-
nuxt.
|
|
57
|
+
const outputDir = getOutputDir(nuxt.options.nitro);
|
|
58
|
+
let isBuildProcess = false;
|
|
59
|
+
nuxt.hook("nitro:build:public-assets", async () => {
|
|
60
|
+
isBuildProcess = true;
|
|
71
61
|
try {
|
|
72
|
-
await
|
|
73
|
-
env: cliEnv,
|
|
74
|
-
cwd: process.cwd(),
|
|
75
|
-
resolveFrom: resolvedDirname,
|
|
76
|
-
stdio: "inherit",
|
|
77
|
-
onBinaryFound: () => {
|
|
78
|
-
}
|
|
79
|
-
});
|
|
62
|
+
await runInject(path.join(outputDir, "public"), options.host, sourcemapsConfig);
|
|
80
63
|
} catch (error) {
|
|
81
|
-
console.error("
|
|
64
|
+
console.error("Failed to process public sourcemaps:", error);
|
|
82
65
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"sourcemap",
|
|
87
|
-
"upload",
|
|
88
|
-
"--directory",
|
|
89
|
-
".output",
|
|
90
|
-
"--ignore",
|
|
91
|
-
"**/node_modules/**"
|
|
92
|
-
];
|
|
66
|
+
});
|
|
67
|
+
nuxt.hook("close", async () => {
|
|
68
|
+
if (!isBuildProcess) return;
|
|
93
69
|
try {
|
|
94
|
-
await
|
|
95
|
-
|
|
96
|
-
cwd: process.cwd(),
|
|
97
|
-
resolveFrom: resolvedDirname,
|
|
98
|
-
stdio: "inherit",
|
|
99
|
-
onBinaryFound: () => {
|
|
100
|
-
}
|
|
101
|
-
});
|
|
70
|
+
await runInject(path.join(outputDir, "server"), options.host, sourcemapsConfig);
|
|
71
|
+
await runUpload(outputDir, options.host, sourcemapsConfig);
|
|
102
72
|
} catch (error) {
|
|
103
|
-
console.error("
|
|
73
|
+
console.error("Failed to process server sourcemaps:", error);
|
|
104
74
|
}
|
|
105
75
|
});
|
|
106
76
|
}
|
|
107
77
|
});
|
|
78
|
+
async function runInject(directory, host, sourcemapsConfig) {
|
|
79
|
+
const processOptions = ["--host", host, "sourcemap", "process", "--ignore", "**/node_modules/**"];
|
|
80
|
+
if (sourcemapsConfig.project) {
|
|
81
|
+
processOptions.push("--project", sourcemapsConfig.project);
|
|
82
|
+
}
|
|
83
|
+
if (sourcemapsConfig.version) {
|
|
84
|
+
processOptions.push("--version", sourcemapsConfig.version);
|
|
85
|
+
}
|
|
86
|
+
await spawnLocal("posthog-cli", [...processOptions, "--directory", directory], {
|
|
87
|
+
env: {
|
|
88
|
+
...process.env,
|
|
89
|
+
POSTHOG_CLI_ENV_ID: sourcemapsConfig.envId,
|
|
90
|
+
POSTHOG_CLI_TOKEN: sourcemapsConfig.personalApiKey
|
|
91
|
+
},
|
|
92
|
+
cwd: process.cwd(),
|
|
93
|
+
resolveFrom: resolvedDirname,
|
|
94
|
+
stdio: "inherit",
|
|
95
|
+
onBinaryFound: () => {
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
async function runUpload(directory, host, sourcemapsConfig) {
|
|
100
|
+
const processOptions = ["--host", host, "sourcemap", "upload", "--ignore", "**/node_modules/**"];
|
|
101
|
+
if (sourcemapsConfig.deleteAfterUpload ?? true) {
|
|
102
|
+
processOptions.push("--delete-after");
|
|
103
|
+
}
|
|
104
|
+
await spawnLocal("posthog-cli", [...processOptions, "--directory", directory], {
|
|
105
|
+
env: {
|
|
106
|
+
...process.env,
|
|
107
|
+
POSTHOG_CLI_ENV_ID: sourcemapsConfig.envId,
|
|
108
|
+
POSTHOG_CLI_TOKEN: sourcemapsConfig.personalApiKey
|
|
109
|
+
},
|
|
110
|
+
cwd: process.cwd(),
|
|
111
|
+
resolveFrom: resolvedDirname,
|
|
112
|
+
stdio: "inherit",
|
|
113
|
+
onBinaryFound: () => {
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function getOutputDir(nitroConfig) {
|
|
118
|
+
if (nitroConfig.preset && nitroConfig.preset.includes("vercel")) {
|
|
119
|
+
return ".vercel/output";
|
|
120
|
+
}
|
|
121
|
+
if (nitroConfig.output && nitroConfig.output.dir) {
|
|
122
|
+
return nitroConfig.output.dir;
|
|
123
|
+
}
|
|
124
|
+
return ".output";
|
|
125
|
+
}
|
|
108
126
|
|
|
109
127
|
export { module as default };
|
|
@@ -4,25 +4,28 @@ import { defineNitroPlugin } from "nitropack/runtime";
|
|
|
4
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
5
|
export default defineNitroPlugin((nitroApp) => {
|
|
6
6
|
const runtimeConfig = useRuntimeConfig();
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
host,
|
|
14
|
-
...restOfConfig
|
|
7
|
+
const posthogCommon = runtimeConfig.public.posthog;
|
|
8
|
+
const posthogServerConfig = runtimeConfig.posthogServerConfig;
|
|
9
|
+
const debug = posthogCommon.debug;
|
|
10
|
+
const client = new PostHog(posthogCommon.publicKey, {
|
|
11
|
+
host: posthogCommon.host,
|
|
12
|
+
...posthogServerConfig
|
|
15
13
|
});
|
|
16
14
|
if (debug) {
|
|
17
15
|
client.debug(true);
|
|
18
16
|
}
|
|
19
|
-
if (
|
|
20
|
-
nitroApp.hooks.hook("error",
|
|
21
|
-
|
|
22
|
-
$process_person_profile: false
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
if (posthogServerConfig.enableExceptionAutocapture) {
|
|
18
|
+
nitroApp.hooks.hook("error", (error, { event }) => {
|
|
19
|
+
const props = {
|
|
20
|
+
$process_person_profile: false
|
|
21
|
+
};
|
|
22
|
+
if (event?.path) {
|
|
23
|
+
props.path = event.path;
|
|
24
|
+
}
|
|
25
|
+
if (event?.method) {
|
|
26
|
+
props.method = event.method;
|
|
27
|
+
}
|
|
28
|
+
client.captureException(error, uuidv7(), props);
|
|
26
29
|
});
|
|
27
30
|
}
|
|
28
31
|
nitroApp.hooks.hook("close", async () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<{
|
|
2
2
|
posthog: () => import("posthog-js").PostHog;
|
|
3
|
-
}> & import("
|
|
3
|
+
}> & import("nuxt/app").ObjectPlugin<{
|
|
4
4
|
posthog: () => import("posthog-js").PostHog;
|
|
5
5
|
}>;
|
|
6
6
|
export default _default;
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
2
2
|
import posthog from "posthog-js";
|
|
3
|
-
export default defineNuxtPlugin(() => {
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
4
|
const runtimeConfig = useRuntimeConfig();
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const configOverride = runtimeConfig.public.posthogClientConfig;
|
|
8
|
-
const debug = runtimeConfig.public.posthogDebug;
|
|
5
|
+
const posthogCommon = runtimeConfig.public.posthog;
|
|
6
|
+
const posthogClientConfig = runtimeConfig.public.posthogClientConfig;
|
|
9
7
|
if (!window || posthog.__loaded) {
|
|
10
8
|
return;
|
|
11
9
|
}
|
|
12
|
-
posthog.init(
|
|
13
|
-
api_host: host,
|
|
14
|
-
...
|
|
10
|
+
posthog.init(posthogCommon.publicKey, {
|
|
11
|
+
api_host: posthogCommon.host,
|
|
12
|
+
...posthogClientConfig
|
|
15
13
|
});
|
|
16
|
-
if (debug) {
|
|
14
|
+
if (posthogCommon.debug) {
|
|
17
15
|
posthog.debug(true);
|
|
18
16
|
}
|
|
17
|
+
if (autocaptureEnabled(posthogClientConfig)) {
|
|
18
|
+
nuxtApp.hook("vue:error", (error, info) => {
|
|
19
|
+
posthog.captureException(error, { info });
|
|
20
|
+
});
|
|
21
|
+
}
|
|
19
22
|
return {
|
|
20
23
|
provide: {
|
|
21
24
|
posthog: () => posthog
|
|
22
25
|
}
|
|
23
26
|
};
|
|
24
27
|
});
|
|
28
|
+
function autocaptureEnabled(config) {
|
|
29
|
+
if (!config) return false;
|
|
30
|
+
if (typeof config.capture_exceptions === "boolean") return config.capture_exceptions;
|
|
31
|
+
if (typeof config.capture_exceptions === "object") return config.capture_exceptions.capture_unhandled_errors === true;
|
|
32
|
+
return false;
|
|
33
|
+
}
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/nuxt",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Nuxt module for Posthog 🦔",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"dist"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@posthog/cli": "^0.5.
|
|
23
|
+
"@posthog/cli": "^0.5.7",
|
|
24
24
|
"@nuxt/kit": ">=3.7.0",
|
|
25
|
-
"posthog-node": "5.11.
|
|
26
|
-
"@posthog/core": "1.5.
|
|
27
|
-
"posthog-js": "1.
|
|
25
|
+
"posthog-node": "5.11.1",
|
|
26
|
+
"@posthog/core": "1.5.1",
|
|
27
|
+
"posthog-js": "1.286.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^20.0.0",
|