@posthog/nuxt 1.0.3 → 1.1.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 +6 -7
- package/dist/module.json +1 -1
- package/dist/module.mjs +34 -34
- package/package.json +5 -5
package/dist/module.d.mts
CHANGED
|
@@ -2,25 +2,24 @@ import * as _nuxt_schema from '@nuxt/schema';
|
|
|
2
2
|
import { PostHogConfig } from 'posthog-js';
|
|
3
3
|
import { PostHogOptions } from 'posthog-node';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
interface EnabledSourcemaps {
|
|
9
|
-
enabled: true;
|
|
5
|
+
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
6
|
+
interface SourcemapsConfig {
|
|
7
|
+
enabled: boolean;
|
|
10
8
|
personalApiKey: string;
|
|
11
9
|
envId: string;
|
|
12
10
|
version?: string;
|
|
13
11
|
project?: string;
|
|
14
|
-
|
|
12
|
+
logLevel?: LogLevel;
|
|
15
13
|
deleteAfterUpload?: boolean;
|
|
16
14
|
}
|
|
17
15
|
interface ModuleOptions {
|
|
18
16
|
host: string;
|
|
19
17
|
publicKey: string;
|
|
20
18
|
debug?: boolean;
|
|
19
|
+
cliBinaryPath?: string;
|
|
21
20
|
clientConfig?: PostHogClientConfig;
|
|
22
21
|
serverConfig?: PostHogServerConfig;
|
|
23
|
-
sourcemaps:
|
|
22
|
+
sourcemaps: SourcemapsConfig | undefined;
|
|
24
23
|
}
|
|
25
24
|
interface PostHogCommon {
|
|
26
25
|
publicKey: string;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineNuxtModule, createResolver, addPlugin, addServerPlugin } from '@nuxt/kit';
|
|
2
|
-
import { spawnLocal } from '@posthog/core/process';
|
|
2
|
+
import { resolveBinaryPath, spawnLocal } from '@posthog/core/process';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import path, { dirname } from 'node:path';
|
|
5
5
|
|
|
@@ -34,10 +34,10 @@ const module = defineNuxtModule({
|
|
|
34
34
|
Object.assign(nuxt.options.runtimeConfig, {
|
|
35
35
|
posthogServerConfig: options.serverConfig
|
|
36
36
|
});
|
|
37
|
-
|
|
38
|
-
if (!sourcemapsConfig?.enabled || nuxt.options.dev) {
|
|
37
|
+
if (!options.sourcemaps?.enabled || nuxt.options.dev) {
|
|
39
38
|
return;
|
|
40
39
|
}
|
|
40
|
+
const sourcemapsConfig = options.sourcemaps;
|
|
41
41
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
42
42
|
nitroConfig.rollupConfig = {
|
|
43
43
|
...nitroConfig.rollupConfig || {},
|
|
@@ -56,10 +56,32 @@ const module = defineNuxtModule({
|
|
|
56
56
|
});
|
|
57
57
|
const outputDir = getOutputDir(nuxt.options.nitro);
|
|
58
58
|
let isBuildProcess = false;
|
|
59
|
+
const posthogCliRunner = () => {
|
|
60
|
+
const cliBinaryPath = options.cliBinaryPath || resolveBinaryPath("posthog-cli", {
|
|
61
|
+
path: process.env.PATH ?? "",
|
|
62
|
+
cwd: resolvedDirname
|
|
63
|
+
});
|
|
64
|
+
const logLevel = sourcemapsConfig.logLevel || "info";
|
|
65
|
+
const cliEnv = {
|
|
66
|
+
...process.env,
|
|
67
|
+
RUST_LOG: `posthog_cli=${logLevel}`,
|
|
68
|
+
POSTHOG_CLI_HOST: options.host,
|
|
69
|
+
POSTHOG_CLI_ENV_ID: sourcemapsConfig.envId,
|
|
70
|
+
POSTHOG_CLI_TOKEN: sourcemapsConfig.personalApiKey
|
|
71
|
+
};
|
|
72
|
+
return (args) => {
|
|
73
|
+
return spawnLocal(cliBinaryPath, args, {
|
|
74
|
+
env: cliEnv,
|
|
75
|
+
cwd: process.cwd(),
|
|
76
|
+
stdio: "inherit"
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const cliRunner = posthogCliRunner();
|
|
59
81
|
nuxt.hook("nitro:build:public-assets", async () => {
|
|
60
82
|
isBuildProcess = true;
|
|
61
83
|
try {
|
|
62
|
-
await
|
|
84
|
+
await cliRunner(getInjectArgs(path.join(outputDir, "public"), sourcemapsConfig));
|
|
63
85
|
} catch (error) {
|
|
64
86
|
console.error("Failed to process public sourcemaps:", error);
|
|
65
87
|
}
|
|
@@ -67,52 +89,30 @@ const module = defineNuxtModule({
|
|
|
67
89
|
nuxt.hook("close", async () => {
|
|
68
90
|
if (!isBuildProcess) return;
|
|
69
91
|
try {
|
|
70
|
-
await
|
|
71
|
-
await
|
|
92
|
+
await cliRunner(getInjectArgs(path.join(outputDir, "server"), sourcemapsConfig));
|
|
93
|
+
await cliRunner(getUploadArgs(outputDir, sourcemapsConfig));
|
|
72
94
|
} catch (error) {
|
|
73
95
|
console.error("Failed to process server sourcemaps:", error);
|
|
74
96
|
}
|
|
75
97
|
});
|
|
76
98
|
}
|
|
77
99
|
});
|
|
78
|
-
|
|
79
|
-
const processOptions = ["
|
|
100
|
+
function getInjectArgs(directory, sourcemapsConfig) {
|
|
101
|
+
const processOptions = ["sourcemap", "inject", "--ignore", "**/node_modules/**", "--directory", directory];
|
|
80
102
|
if (sourcemapsConfig.project) {
|
|
81
103
|
processOptions.push("--project", sourcemapsConfig.project);
|
|
82
104
|
}
|
|
83
105
|
if (sourcemapsConfig.version) {
|
|
84
106
|
processOptions.push("--version", sourcemapsConfig.version);
|
|
85
107
|
}
|
|
86
|
-
|
|
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
|
-
});
|
|
108
|
+
return processOptions;
|
|
98
109
|
}
|
|
99
|
-
|
|
100
|
-
const processOptions = ["
|
|
110
|
+
function getUploadArgs(directory, sourcemapsConfig) {
|
|
111
|
+
const processOptions = ["sourcemap", "upload", "--ignore", "**/node_modules/**", "--directory", directory];
|
|
101
112
|
if (sourcemapsConfig.deleteAfterUpload ?? true) {
|
|
102
113
|
processOptions.push("--delete-after");
|
|
103
114
|
}
|
|
104
|
-
|
|
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
|
-
});
|
|
115
|
+
return processOptions;
|
|
116
116
|
}
|
|
117
117
|
function getOutputDir(nitroConfig) {
|
|
118
118
|
if (nitroConfig.preset && nitroConfig.preset.includes("vercel")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/nuxt",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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": "
|
|
23
|
+
"@posthog/cli": "~0.5.9",
|
|
24
24
|
"@nuxt/kit": ">=3.7.0",
|
|
25
|
-
"posthog-node": "5.11.
|
|
26
|
-
"
|
|
27
|
-
"posthog
|
|
25
|
+
"posthog-node": "5.11.2",
|
|
26
|
+
"posthog-js": "1.289.0",
|
|
27
|
+
"@posthog/core": "1.5.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^20.0.0",
|