@posthog/nextjs-config 1.0.2 → 1.1.0
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/LICENSE +245 -0
- package/dist/index.d.mts +36 -0
- package/{lib → dist}/index.d.ts +1 -1
- package/dist/index.js +295 -0
- package/dist/index.mjs +261 -0
- package/package.json +34 -14
- package/lib/index.cjs +0 -210
- package/lib/index.cjs.map +0 -1
- package/lib/index.mjs +0 -201
- package/lib/index.mjs.map +0 -1
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// src/webpack-plugin.ts
|
|
54
|
+
import { spawn } from "child_process";
|
|
55
|
+
import path2 from "path";
|
|
56
|
+
|
|
57
|
+
// src/utils.ts
|
|
58
|
+
import path from "path";
|
|
59
|
+
import fs from "fs";
|
|
60
|
+
function resolveBinaryPath(envPath, cwd, binName) {
|
|
61
|
+
const envLocations = envPath.split(path.delimiter);
|
|
62
|
+
const localLocations = buildLocalBinaryPaths(cwd);
|
|
63
|
+
const directories = [.../* @__PURE__ */ new Set([...envLocations, ...localLocations])];
|
|
64
|
+
for (const directory of directories) {
|
|
65
|
+
const binaryPath = path.join(directory, binName);
|
|
66
|
+
if (fs.existsSync(binaryPath)) {
|
|
67
|
+
return binaryPath;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new Error(`Binary ${binName} not found`);
|
|
71
|
+
}
|
|
72
|
+
var buildLocalBinaryPaths = (cwd) => {
|
|
73
|
+
const localPaths = getLocalPaths(path.resolve(cwd)).map(
|
|
74
|
+
(localPath) => path.join(localPath, "node_modules/.bin")
|
|
75
|
+
);
|
|
76
|
+
return localPaths;
|
|
77
|
+
};
|
|
78
|
+
var getLocalPaths = (startPath) => {
|
|
79
|
+
const paths = [];
|
|
80
|
+
let currentPath = startPath;
|
|
81
|
+
while (true) {
|
|
82
|
+
paths.push(currentPath);
|
|
83
|
+
const parentPath = path.resolve(currentPath, "..");
|
|
84
|
+
if (parentPath === currentPath) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
currentPath = parentPath;
|
|
88
|
+
}
|
|
89
|
+
return paths;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// src/webpack-plugin.ts
|
|
93
|
+
var SourcemapWebpackPlugin = class {
|
|
94
|
+
constructor(posthogOptions, isServer, nextRuntime, distDir) {
|
|
95
|
+
this.posthogOptions = posthogOptions;
|
|
96
|
+
this.isServer = isServer;
|
|
97
|
+
this.nextRuntime = nextRuntime;
|
|
98
|
+
const resolvedDistDir = path2.resolve(distDir != null ? distDir : ".next");
|
|
99
|
+
if (!this.posthogOptions.personalApiKey) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Personal API key not provided. If you are using turbo, make sure to add env variables to your turbo config`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (!this.posthogOptions.envId) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Environment ID not provided. If you are using turbo, make sure to add env variables to your turbo config`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
this.directory = this.isServer ? path2.join(resolvedDistDir, "server") : path2.join(resolvedDistDir, "static/chunks");
|
|
110
|
+
}
|
|
111
|
+
apply(compiler) {
|
|
112
|
+
if (this.nextRuntime === "edge") {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const onDone = (_, callback) => __async(this, null, function* () {
|
|
116
|
+
callback = callback || (() => {
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
yield this.runInject();
|
|
120
|
+
yield this.runUpload();
|
|
121
|
+
} catch (error) {
|
|
122
|
+
const errorMessage = error instanceof Error ? error.message : error;
|
|
123
|
+
return console.error("Error running PostHog sourcemap plugin:", errorMessage);
|
|
124
|
+
}
|
|
125
|
+
return callback();
|
|
126
|
+
});
|
|
127
|
+
if (compiler.hooks) {
|
|
128
|
+
compiler.hooks.done.tapAsync("SourcemapWebpackPlugin", onDone);
|
|
129
|
+
} else {
|
|
130
|
+
compiler.plugin("done", onDone);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
runInject() {
|
|
134
|
+
return __async(this, null, function* () {
|
|
135
|
+
const cliOptions = [];
|
|
136
|
+
cliOptions.push("sourcemap", "inject", "--directory", this.directory);
|
|
137
|
+
yield callPosthogCli(cliOptions, process.env, this.posthogOptions.verbose);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
runUpload() {
|
|
141
|
+
return __async(this, null, function* () {
|
|
142
|
+
const cliOptions = [];
|
|
143
|
+
if (this.posthogOptions.host) {
|
|
144
|
+
cliOptions.push("--host", this.posthogOptions.host);
|
|
145
|
+
}
|
|
146
|
+
cliOptions.push("sourcemap", "upload");
|
|
147
|
+
cliOptions.push("--directory", this.directory);
|
|
148
|
+
if (this.posthogOptions.sourcemaps.project) {
|
|
149
|
+
cliOptions.push("--project", this.posthogOptions.sourcemaps.project);
|
|
150
|
+
}
|
|
151
|
+
if (this.posthogOptions.sourcemaps.version) {
|
|
152
|
+
cliOptions.push("--version", this.posthogOptions.sourcemaps.version);
|
|
153
|
+
}
|
|
154
|
+
if (this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer) {
|
|
155
|
+
cliOptions.push("--delete-after");
|
|
156
|
+
}
|
|
157
|
+
const envVars = __spreadProps(__spreadValues({}, process.env), {
|
|
158
|
+
POSTHOG_CLI_TOKEN: this.posthogOptions.personalApiKey,
|
|
159
|
+
POSTHOG_CLI_ENV_ID: this.posthogOptions.envId
|
|
160
|
+
});
|
|
161
|
+
yield callPosthogCli(cliOptions, envVars, this.posthogOptions.verbose);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
function callPosthogCli(args, env, verbose) {
|
|
166
|
+
return __async(this, null, function* () {
|
|
167
|
+
var _a;
|
|
168
|
+
let binaryLocation;
|
|
169
|
+
try {
|
|
170
|
+
binaryLocation = resolveBinaryPath((_a = process.env.PATH) != null ? _a : "", __dirname, "posthog-cli");
|
|
171
|
+
} catch (e) {
|
|
172
|
+
throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`);
|
|
173
|
+
}
|
|
174
|
+
if (verbose) {
|
|
175
|
+
console.log("running posthog-cli from ", binaryLocation);
|
|
176
|
+
}
|
|
177
|
+
const child = spawn(binaryLocation, [...args], {
|
|
178
|
+
stdio: verbose ? "inherit" : "ignore",
|
|
179
|
+
env,
|
|
180
|
+
cwd: process.cwd()
|
|
181
|
+
});
|
|
182
|
+
yield new Promise((resolve, reject) => {
|
|
183
|
+
child.on("close", (code) => {
|
|
184
|
+
if (code === 0) {
|
|
185
|
+
resolve();
|
|
186
|
+
} else {
|
|
187
|
+
reject(new Error(`Command failed with code ${code}`));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
child.on("error", (error) => {
|
|
191
|
+
reject(error);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/config.ts
|
|
198
|
+
function withPostHogConfig(userNextConfig, posthogConfig) {
|
|
199
|
+
const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
|
|
200
|
+
return (_0, _1) => __async(null, [_0, _1], function* (phase, { defaultConfig }) {
|
|
201
|
+
const _a = yield resolveUserConfig(userNextConfig, phase, defaultConfig), {
|
|
202
|
+
webpack: userWebPackConfig,
|
|
203
|
+
distDir
|
|
204
|
+
} = _a, userConfig = __objRest(_a, [
|
|
205
|
+
"webpack",
|
|
206
|
+
"distDir"
|
|
207
|
+
]);
|
|
208
|
+
const defaultWebpackConfig = userWebPackConfig || ((config) => config);
|
|
209
|
+
const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
|
|
210
|
+
return __spreadProps(__spreadValues({}, userConfig), {
|
|
211
|
+
distDir,
|
|
212
|
+
productionBrowserSourceMaps: sourceMapEnabled,
|
|
213
|
+
webpack: (config, options) => {
|
|
214
|
+
const webpackConfig = defaultWebpackConfig(config, options);
|
|
215
|
+
if (webpackConfig && options.isServer && sourceMapEnabled) {
|
|
216
|
+
webpackConfig.devtool = "source-map";
|
|
217
|
+
}
|
|
218
|
+
if (sourceMapEnabled) {
|
|
219
|
+
webpackConfig.plugins = webpackConfig.plugins || [];
|
|
220
|
+
webpackConfig.plugins.push(
|
|
221
|
+
new SourcemapWebpackPlugin(posthogNextConfigComplete, options.isServer, options.nextRuntime, distDir)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
return webpackConfig;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
function resolveUserConfig(userNextConfig, phase, defaultConfig) {
|
|
230
|
+
if (typeof userNextConfig === "function") {
|
|
231
|
+
const maybePromise = userNextConfig(phase, { defaultConfig });
|
|
232
|
+
if (maybePromise instanceof Promise) {
|
|
233
|
+
return maybePromise;
|
|
234
|
+
} else {
|
|
235
|
+
return Promise.resolve(maybePromise);
|
|
236
|
+
}
|
|
237
|
+
} else if (typeof userNextConfig === "object") {
|
|
238
|
+
return Promise.resolve(userNextConfig);
|
|
239
|
+
} else {
|
|
240
|
+
throw new Error("Invalid user config");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
function resolvePostHogConfig(posthogProvidedConfig) {
|
|
244
|
+
var _a, _b;
|
|
245
|
+
const { personalApiKey, envId, host, verbose, sourcemaps = {} } = posthogProvidedConfig;
|
|
246
|
+
return {
|
|
247
|
+
personalApiKey,
|
|
248
|
+
envId,
|
|
249
|
+
host: host != null ? host : "https://us.posthog.com",
|
|
250
|
+
verbose: verbose != null ? verbose : true,
|
|
251
|
+
sourcemaps: {
|
|
252
|
+
enabled: (_a = sourcemaps.enabled) != null ? _a : process.env.NODE_ENV == "production",
|
|
253
|
+
project: sourcemaps.project,
|
|
254
|
+
version: sourcemaps.version,
|
|
255
|
+
deleteAfterUpload: (_b = sourcemaps.deleteAfterUpload) != null ? _b : true
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
export {
|
|
260
|
+
withPostHogConfig
|
|
261
|
+
};
|
package/package.json
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/nextjs-config",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "NextJS configuration helper for Posthog 🦔",
|
|
5
|
-
"main": "./lib/index.cjs",
|
|
6
|
-
"module": "./lib/index.mjs",
|
|
7
|
-
"types": "./lib/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"prepublishOnly": "cd .. && yarn build"
|
|
10
|
-
},
|
|
11
5
|
"repository": {
|
|
12
6
|
"type": "git",
|
|
13
|
-
"url": "https://github.com/PostHog/posthog-js
|
|
14
|
-
"directory": "
|
|
7
|
+
"url": "https://github.com/PostHog/posthog-js.git",
|
|
8
|
+
"directory": "packages/nextjs-config"
|
|
15
9
|
},
|
|
16
10
|
"author": {
|
|
17
11
|
"name": "PostHog",
|
|
18
12
|
"email": "hey@posthog.com",
|
|
19
13
|
"url": "https://posthog.com"
|
|
20
14
|
},
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
23
|
+
},
|
|
24
|
+
"require": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
21
30
|
"engines": {
|
|
22
31
|
"node": ">=18.0.0"
|
|
23
32
|
},
|
|
24
33
|
"license": "MIT",
|
|
25
34
|
"dependencies": {
|
|
26
|
-
"@posthog/cli": "^0.3.
|
|
35
|
+
"@posthog/cli": "^0.3.6"
|
|
27
36
|
},
|
|
28
37
|
"keywords": [
|
|
29
38
|
"posthog",
|
|
@@ -31,12 +40,23 @@
|
|
|
31
40
|
],
|
|
32
41
|
"devDependencies": {
|
|
33
42
|
"@types/node": "^22.15.23",
|
|
34
|
-
"next": "^12.1.0"
|
|
43
|
+
"next": "^12.1.0",
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
|
+
"@posthog-tooling/tsconfig-base": "1.0.0",
|
|
46
|
+
"@posthog-tooling/rollup-utils": "1.0.0"
|
|
35
47
|
},
|
|
36
48
|
"peerDependencies": {
|
|
37
49
|
"next": ">12.1.0"
|
|
38
50
|
},
|
|
39
51
|
"files": [
|
|
40
|
-
"
|
|
41
|
-
]
|
|
42
|
-
|
|
52
|
+
"dist/"
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"clean": "rimraf dist",
|
|
56
|
+
"lint": "eslint src",
|
|
57
|
+
"lint:fix": "eslint src --fix",
|
|
58
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --out-dir dist",
|
|
59
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --out-dir dist --watch",
|
|
60
|
+
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/lib/index.cjs
DELETED
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var child_process = require('child_process');
|
|
6
|
-
var path = require('path');
|
|
7
|
-
var fs = require('fs');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
12
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
13
|
-
|
|
14
|
-
function resolveBinaryPath(envPath, cwd, binName) {
|
|
15
|
-
const envLocations = envPath.split(path__default["default"].delimiter);
|
|
16
|
-
const localLocations = buildLocalBinaryPaths(cwd);
|
|
17
|
-
const directories = [...new Set([...envLocations, ...localLocations])];
|
|
18
|
-
for (const directory of directories) {
|
|
19
|
-
const binaryPath = path__default["default"].join(directory, binName);
|
|
20
|
-
if (fs__default["default"].existsSync(binaryPath)) {
|
|
21
|
-
return binaryPath;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
throw new Error(`Binary ${binName} not found`);
|
|
25
|
-
}
|
|
26
|
-
const buildLocalBinaryPaths = cwd => {
|
|
27
|
-
const localPaths = getLocalPaths(path__default["default"].resolve(cwd)).map(localPath => path__default["default"].join(localPath, 'node_modules/.bin'));
|
|
28
|
-
return localPaths;
|
|
29
|
-
};
|
|
30
|
-
const getLocalPaths = startPath => {
|
|
31
|
-
const paths = [];
|
|
32
|
-
let currentPath = startPath;
|
|
33
|
-
while (true) {
|
|
34
|
-
paths.push(currentPath);
|
|
35
|
-
const parentPath = path__default["default"].resolve(currentPath, '..');
|
|
36
|
-
// If we've reached the root directory, stop
|
|
37
|
-
if (parentPath === currentPath) {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
currentPath = parentPath;
|
|
41
|
-
}
|
|
42
|
-
return paths;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
class SourcemapWebpackPlugin {
|
|
46
|
-
constructor(posthogOptions, isServer, nextRuntime, distDir) {
|
|
47
|
-
this.posthogOptions = posthogOptions;
|
|
48
|
-
this.isServer = isServer;
|
|
49
|
-
this.nextRuntime = nextRuntime;
|
|
50
|
-
const resolvedDistDir = path__default["default"].resolve(distDir ?? '.next');
|
|
51
|
-
if (!this.posthogOptions.personalApiKey) {
|
|
52
|
-
throw new Error(`Personal API key not provided. If you are using turbo, make sure to add env variables to your turbo config`);
|
|
53
|
-
}
|
|
54
|
-
if (!this.posthogOptions.envId) {
|
|
55
|
-
throw new Error(`Environment ID not provided. If you are using turbo, make sure to add env variables to your turbo config`);
|
|
56
|
-
}
|
|
57
|
-
this.directory = this.isServer ? path__default["default"].join(resolvedDistDir, 'server') : path__default["default"].join(resolvedDistDir, 'static/chunks');
|
|
58
|
-
}
|
|
59
|
-
apply(compiler) {
|
|
60
|
-
if (this.nextRuntime === 'edge') {
|
|
61
|
-
// TODO: edge and nodejs runtime output files in the same location
|
|
62
|
-
// to support edge runtime we need a way to pass a list of files to the cli
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const onDone = async (_, callback) => {
|
|
66
|
-
callback = callback || (() => {});
|
|
67
|
-
try {
|
|
68
|
-
await this.runInject();
|
|
69
|
-
await this.runUpload();
|
|
70
|
-
} catch (error) {
|
|
71
|
-
const errorMessage = error instanceof Error ? error.message : error;
|
|
72
|
-
return console.error('Error running PostHog sourcemap plugin:', errorMessage);
|
|
73
|
-
}
|
|
74
|
-
return callback();
|
|
75
|
-
};
|
|
76
|
-
if (compiler.hooks) {
|
|
77
|
-
compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone);
|
|
78
|
-
} else {
|
|
79
|
-
compiler.plugin('done', onDone);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async runInject() {
|
|
83
|
-
const cliOptions = [];
|
|
84
|
-
cliOptions.push('sourcemap', 'inject', '--directory', this.directory);
|
|
85
|
-
await callPosthogCli(cliOptions, process.env, this.posthogOptions.verbose);
|
|
86
|
-
}
|
|
87
|
-
async runUpload() {
|
|
88
|
-
const cliOptions = [];
|
|
89
|
-
if (this.posthogOptions.host) {
|
|
90
|
-
cliOptions.push('--host', this.posthogOptions.host);
|
|
91
|
-
}
|
|
92
|
-
cliOptions.push('sourcemap', 'upload');
|
|
93
|
-
cliOptions.push('--directory', this.directory);
|
|
94
|
-
if (this.posthogOptions.sourcemaps.project) {
|
|
95
|
-
cliOptions.push('--project', this.posthogOptions.sourcemaps.project);
|
|
96
|
-
}
|
|
97
|
-
if (this.posthogOptions.sourcemaps.version) {
|
|
98
|
-
cliOptions.push('--version', this.posthogOptions.sourcemaps.version);
|
|
99
|
-
}
|
|
100
|
-
if (this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer) {
|
|
101
|
-
cliOptions.push('--delete-after');
|
|
102
|
-
}
|
|
103
|
-
// Add env variables
|
|
104
|
-
const envVars = {
|
|
105
|
-
...process.env,
|
|
106
|
-
POSTHOG_CLI_TOKEN: this.posthogOptions.personalApiKey,
|
|
107
|
-
POSTHOG_CLI_ENV_ID: this.posthogOptions.envId
|
|
108
|
-
};
|
|
109
|
-
await callPosthogCli(cliOptions, envVars, this.posthogOptions.verbose);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async function callPosthogCli(args, env, verbose) {
|
|
113
|
-
let binaryLocation;
|
|
114
|
-
try {
|
|
115
|
-
binaryLocation = resolveBinaryPath(process.env.PATH ?? '', __dirname, 'posthog-cli');
|
|
116
|
-
} catch (e) {
|
|
117
|
-
throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`);
|
|
118
|
-
}
|
|
119
|
-
if (verbose) {
|
|
120
|
-
console.log('running posthog-cli from ', binaryLocation);
|
|
121
|
-
}
|
|
122
|
-
const child = child_process.spawn(binaryLocation, [...args], {
|
|
123
|
-
stdio: verbose ? 'inherit' : 'ignore',
|
|
124
|
-
env,
|
|
125
|
-
cwd: process.cwd()
|
|
126
|
-
});
|
|
127
|
-
await new Promise((resolve, reject) => {
|
|
128
|
-
child.on('close', code => {
|
|
129
|
-
if (code === 0) {
|
|
130
|
-
resolve();
|
|
131
|
-
} else {
|
|
132
|
-
reject(new Error(`Command failed with code ${code}`));
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
child.on('error', error => {
|
|
136
|
-
reject(error);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function withPostHogConfig(userNextConfig, posthogConfig) {
|
|
142
|
-
const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
|
|
143
|
-
return async (phase, {
|
|
144
|
-
defaultConfig
|
|
145
|
-
}) => {
|
|
146
|
-
const {
|
|
147
|
-
webpack: userWebPackConfig,
|
|
148
|
-
distDir,
|
|
149
|
-
...userConfig
|
|
150
|
-
} = await resolveUserConfig(userNextConfig, phase, defaultConfig);
|
|
151
|
-
const defaultWebpackConfig = userWebPackConfig || (config => config);
|
|
152
|
-
const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
|
|
153
|
-
return {
|
|
154
|
-
...userConfig,
|
|
155
|
-
distDir,
|
|
156
|
-
productionBrowserSourceMaps: sourceMapEnabled,
|
|
157
|
-
webpack: (config, options) => {
|
|
158
|
-
const webpackConfig = defaultWebpackConfig(config, options);
|
|
159
|
-
if (webpackConfig && options.isServer && sourceMapEnabled) {
|
|
160
|
-
webpackConfig.devtool = 'source-map';
|
|
161
|
-
}
|
|
162
|
-
if (sourceMapEnabled) {
|
|
163
|
-
webpackConfig.plugins = webpackConfig.plugins || [];
|
|
164
|
-
webpackConfig.plugins.push(new SourcemapWebpackPlugin(posthogNextConfigComplete, options.isServer, options.nextRuntime, distDir));
|
|
165
|
-
}
|
|
166
|
-
return webpackConfig;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
function resolveUserConfig(userNextConfig, phase, defaultConfig) {
|
|
172
|
-
if (typeof userNextConfig === 'function') {
|
|
173
|
-
const maybePromise = userNextConfig(phase, {
|
|
174
|
-
defaultConfig
|
|
175
|
-
});
|
|
176
|
-
if (maybePromise instanceof Promise) {
|
|
177
|
-
return maybePromise;
|
|
178
|
-
} else {
|
|
179
|
-
return Promise.resolve(maybePromise);
|
|
180
|
-
}
|
|
181
|
-
} else if (typeof userNextConfig === 'object') {
|
|
182
|
-
return Promise.resolve(userNextConfig);
|
|
183
|
-
} else {
|
|
184
|
-
throw new Error('Invalid user config');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function resolvePostHogConfig(posthogProvidedConfig) {
|
|
188
|
-
const {
|
|
189
|
-
personalApiKey,
|
|
190
|
-
envId,
|
|
191
|
-
host,
|
|
192
|
-
verbose,
|
|
193
|
-
sourcemaps = {}
|
|
194
|
-
} = posthogProvidedConfig;
|
|
195
|
-
return {
|
|
196
|
-
personalApiKey,
|
|
197
|
-
envId,
|
|
198
|
-
host: host ?? 'https://us.posthog.com',
|
|
199
|
-
verbose: verbose ?? true,
|
|
200
|
-
sourcemaps: {
|
|
201
|
-
enabled: sourcemaps.enabled ?? process.env.NODE_ENV == 'production',
|
|
202
|
-
project: sourcemaps.project,
|
|
203
|
-
version: sourcemaps.version,
|
|
204
|
-
deleteAfterUpload: sourcemaps.deleteAfterUpload ?? true
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
exports.withPostHogConfig = withPostHogConfig;
|
|
210
|
-
//# sourceMappingURL=index.cjs.map
|
package/lib/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/webpack-plugin.ts","../src/config.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs'\n\nexport function resolveBinaryPath(envPath: string, cwd: string, binName: string): string {\n const envLocations = envPath.split(path.delimiter)\n const localLocations = buildLocalBinaryPaths(cwd)\n const directories = [...new Set([...envLocations, ...localLocations])]\n for (const directory of directories) {\n const binaryPath = path.join(directory, binName)\n if (fs.existsSync(binaryPath)) {\n return binaryPath\n }\n }\n throw new Error(`Binary ${binName} not found`)\n}\n\nexport const buildLocalBinaryPaths = (cwd: string): string[] => {\n const localPaths = getLocalPaths(path.resolve(cwd)).map((localPath: string) =>\n path.join(localPath, 'node_modules/.bin')\n )\n return localPaths\n}\n\nconst getLocalPaths = (startPath: string): string[] => {\n const paths: string[] = []\n let currentPath = startPath\n\n while (true) {\n paths.push(currentPath)\n const parentPath = path.resolve(currentPath, '..')\n\n // If we've reached the root directory, stop\n if (parentPath === currentPath) {\n break\n }\n\n currentPath = parentPath\n }\n\n return paths\n}\n","import { PostHogNextConfigComplete } from './config'\nimport { spawn } from 'child_process'\nimport path from 'path'\nimport { resolveBinaryPath } from './utils'\n\ntype NextRuntime = 'edge' | 'nodejs' | undefined\n\nexport class SourcemapWebpackPlugin {\n directory: string\n\n constructor(\n private posthogOptions: PostHogNextConfigComplete,\n private isServer: boolean,\n private nextRuntime: NextRuntime,\n distDir?: string\n ) {\n const resolvedDistDir = path.resolve(distDir ?? '.next')\n if (!this.posthogOptions.personalApiKey) {\n throw new Error(\n `Personal API key not provided. If you are using turbo, make sure to add env variables to your turbo config`\n )\n }\n if (!this.posthogOptions.envId) {\n throw new Error(\n `Environment ID not provided. If you are using turbo, make sure to add env variables to your turbo config`\n )\n }\n this.directory = this.isServer ? path.join(resolvedDistDir, 'server') : path.join(resolvedDistDir, 'static/chunks')\n }\n\n apply(compiler: any): void {\n if (this.nextRuntime === 'edge') {\n // TODO: edge and nodejs runtime output files in the same location\n // to support edge runtime we need a way to pass a list of files to the cli\n return\n }\n\n const onDone = async (_: any, callback: any): Promise<void> => {\n callback = callback || (() => {})\n try {\n await this.runInject()\n await this.runUpload()\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : error\n return console.error('Error running PostHog sourcemap plugin:', errorMessage)\n }\n return callback()\n }\n\n if (compiler.hooks) {\n compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone)\n } else {\n compiler.plugin('done', onDone)\n }\n }\n\n async runInject(): Promise<void> {\n const cliOptions = []\n cliOptions.push('sourcemap', 'inject', '--directory', this.directory)\n await callPosthogCli(cliOptions, process.env, this.posthogOptions.verbose)\n }\n\n async runUpload(): Promise<void> {\n const cliOptions = []\n if (this.posthogOptions.host) {\n cliOptions.push('--host', this.posthogOptions.host)\n }\n cliOptions.push('sourcemap', 'upload')\n cliOptions.push('--directory', this.directory)\n if (this.posthogOptions.sourcemaps.project) {\n cliOptions.push('--project', this.posthogOptions.sourcemaps.project)\n }\n if (this.posthogOptions.sourcemaps.version) {\n cliOptions.push('--version', this.posthogOptions.sourcemaps.version)\n }\n if (this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer) {\n cliOptions.push('--delete-after')\n }\n // Add env variables\n const envVars = {\n ...process.env,\n POSTHOG_CLI_TOKEN: this.posthogOptions.personalApiKey,\n POSTHOG_CLI_ENV_ID: this.posthogOptions.envId,\n }\n await callPosthogCli(cliOptions, envVars, this.posthogOptions.verbose)\n }\n}\n\nasync function callPosthogCli(args: string[], env: NodeJS.ProcessEnv, verbose: boolean): Promise<void> {\n let binaryLocation\n try {\n binaryLocation = resolveBinaryPath(process.env.PATH ?? '', __dirname, 'posthog-cli')\n } catch (e) {\n throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`)\n }\n\n if (verbose) {\n console.log('running posthog-cli from ', binaryLocation)\n }\n\n const child = spawn(binaryLocation, [...args], {\n stdio: verbose ? 'inherit' : 'ignore',\n env,\n cwd: process.cwd(),\n })\n\n await new Promise<void>((resolve, reject) => {\n child.on('close', (code) => {\n if (code === 0) {\n resolve()\n } else {\n reject(new Error(`Command failed with code ${code}`))\n }\n })\n\n child.on('error', (error) => {\n reject(error)\n })\n })\n}\n","import type { NextConfig } from 'next'\nimport { SourcemapWebpackPlugin } from './webpack-plugin'\n\ntype NextFuncConfig = (phase: string, { defaultConfig }: { defaultConfig: NextConfig }) => NextConfig\ntype NextAsyncConfig = (phase: string, { defaultConfig }: { defaultConfig: NextConfig }) => Promise<NextConfig>\ntype UserProvidedConfig = NextConfig | NextFuncConfig | NextAsyncConfig\n\nexport type PostHogNextConfig = {\n personalApiKey: string\n envId: string\n host?: string\n verbose?: boolean\n sourcemaps?: {\n enabled?: boolean\n project?: string\n version?: string\n deleteAfterUpload?: boolean\n }\n}\n\nexport type PostHogNextConfigComplete = {\n personalApiKey: string\n envId: string\n host: string\n verbose: boolean\n sourcemaps: {\n enabled: boolean\n project?: string\n version?: string\n deleteAfterUpload: boolean\n }\n}\n\nexport function withPostHogConfig(userNextConfig: UserProvidedConfig, posthogConfig: PostHogNextConfig): NextConfig {\n const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig)\n return async (phase: string, { defaultConfig }: { defaultConfig: NextConfig }) => {\n const {\n webpack: userWebPackConfig,\n distDir,\n ...userConfig\n } = await resolveUserConfig(userNextConfig, phase, defaultConfig)\n const defaultWebpackConfig = userWebPackConfig || ((config: any) => config)\n const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled\n return {\n ...userConfig,\n distDir,\n productionBrowserSourceMaps: sourceMapEnabled,\n webpack: (config: any, options: any) => {\n const webpackConfig = defaultWebpackConfig(config, options)\n if (webpackConfig && options.isServer && sourceMapEnabled) {\n webpackConfig.devtool = 'source-map'\n }\n if (sourceMapEnabled) {\n webpackConfig.plugins = webpackConfig.plugins || []\n webpackConfig.plugins.push(\n new SourcemapWebpackPlugin(posthogNextConfigComplete, options.isServer, options.nextRuntime, distDir)\n )\n }\n return webpackConfig\n },\n }\n }\n}\n\nfunction resolveUserConfig(\n userNextConfig: UserProvidedConfig,\n phase: string,\n defaultConfig: NextConfig\n): Promise<NextConfig> {\n if (typeof userNextConfig === 'function') {\n const maybePromise = userNextConfig(phase, { defaultConfig })\n if (maybePromise instanceof Promise) {\n return maybePromise\n } else {\n return Promise.resolve(maybePromise)\n }\n } else if (typeof userNextConfig === 'object') {\n return Promise.resolve(userNextConfig)\n } else {\n throw new Error('Invalid user config')\n }\n}\n\nfunction resolvePostHogConfig(posthogProvidedConfig: PostHogNextConfig): PostHogNextConfigComplete {\n const { personalApiKey, envId, host, verbose, sourcemaps = {} } = posthogProvidedConfig\n return {\n personalApiKey,\n envId,\n host: host ?? 'https://us.posthog.com',\n verbose: verbose ?? true,\n sourcemaps: {\n enabled: sourcemaps.enabled ?? process.env.NODE_ENV == 'production',\n project: sourcemaps.project,\n version: sourcemaps.version,\n deleteAfterUpload: sourcemaps.deleteAfterUpload ?? true,\n },\n }\n}\n"],"names":["resolveBinaryPath","envPath","cwd","binName","envLocations","split","path","delimiter","localLocations","buildLocalBinaryPaths","directories","Set","directory","binaryPath","join","fs","existsSync","Error","localPaths","getLocalPaths","resolve","map","localPath","startPath","paths","currentPath","push","parentPath","SourcemapWebpackPlugin","constructor","posthogOptions","isServer","nextRuntime","distDir","resolvedDistDir","personalApiKey","envId","apply","compiler","onDone","_","callback","runInject","runUpload","error","errorMessage","message","console","hooks","done","tapAsync","plugin","cliOptions","callPosthogCli","process","env","verbose","host","sourcemaps","project","version","deleteAfterUpload","envVars","POSTHOG_CLI_TOKEN","POSTHOG_CLI_ENV_ID","args","binaryLocation","PATH","__dirname","e","log","child","spawn","stdio","Promise","reject","on","code","withPostHogConfig","userNextConfig","posthogConfig","posthogNextConfigComplete","resolvePostHogConfig","phase","defaultConfig","webpack","userWebPackConfig","userConfig","resolveUserConfig","defaultWebpackConfig","config","sourceMapEnabled","enabled","productionBrowserSourceMaps","options","webpackConfig","devtool","plugins","maybePromise","posthogProvidedConfig","NODE_ENV"],"mappings":";;;;;;;;;;;;;SAGgBA,iBAAiBA,CAACC,OAAe,EAAEC,GAAW,EAAEC,OAAe,EAAA;EAC7E,MAAMC,YAAY,GAAGH,OAAO,CAACI,KAAK,CAACC,wBAAI,CAACC,SAAS,CAAC,CAAA;AAClD,EAAA,MAAMC,cAAc,GAAGC,qBAAqB,CAACP,GAAG,CAAC,CAAA;AACjD,EAAA,MAAMQ,WAAW,GAAG,CAAC,GAAG,IAAIC,GAAG,CA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