@posthog/nextjs-config 1.0.1 → 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 ADDED
@@ -0,0 +1,245 @@
1
+ Copyright 2020 Posthog / Hiberly, Inc.
2
+
3
+ Copyright 2015 Mixpanel, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this work except in compliance with the License.
7
+ You may obtain a copy of the License below, or at:
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ Apache License
18
+ Version 2.0, January 2004
19
+ http://www.apache.org/licenses/
20
+
21
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
22
+
23
+ 1. Definitions.
24
+
25
+ "License" shall mean the terms and conditions for use, reproduction,
26
+ and distribution as defined by Sections 1 through 9 of this document.
27
+
28
+ "Licensor" shall mean the copyright owner or entity authorized by
29
+ the copyright owner that is granting the License.
30
+
31
+ "Legal Entity" shall mean the union of the acting entity and all
32
+ other entities that control, are controlled by, or are under common
33
+ control with that entity. For the purposes of this definition,
34
+ "control" means (i) the power, direct or indirect, to cause the
35
+ direction or management of such entity, whether by contract or
36
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
37
+ outstanding shares, or (iii) beneficial ownership of such entity.
38
+
39
+ "You" (or "Your") shall mean an individual or Legal Entity
40
+ exercising permissions granted by this License.
41
+
42
+ "Source" form shall mean the preferred form for making modifications,
43
+ including but not limited to software source code, documentation
44
+ source, and configuration files.
45
+
46
+ "Object" form shall mean any form resulting from mechanical
47
+ transformation or translation of a Source form, including but
48
+ not limited to compiled object code, generated documentation,
49
+ and conversions to other media types.
50
+
51
+ "Work" shall mean the work of authorship, whether in Source or
52
+ Object form, made available under the License, as indicated by a
53
+ copyright notice that is included in or attached to the work
54
+ (an example is provided in the Appendix below).
55
+
56
+ "Derivative Works" shall mean any work, whether in Source or Object
57
+ form, that is based on (or derived from) the Work and for which the
58
+ editorial revisions, annotations, elaborations, or other modifications
59
+ represent, as a whole, an original work of authorship. For the purposes
60
+ of this License, Derivative Works shall not include works that remain
61
+ separable from, or merely link (or bind by name) to the interfaces of,
62
+ the Work and Derivative Works thereof.
63
+
64
+ "Contribution" shall mean any work of authorship, including
65
+ the original version of the Work and any modifications or additions
66
+ to that Work or Derivative Works thereof, that is intentionally
67
+ submitted to Licensor for inclusion in the Work by the copyright owner
68
+ or by an individual or Legal Entity authorized to submit on behalf of
69
+ the copyright owner. For the purposes of this definition, "submitted"
70
+ means any form of electronic, verbal, or written communication sent
71
+ to the Licensor or its representatives, including but not limited to
72
+ communication on electronic mailing lists, source code control systems,
73
+ and issue tracking systems that are managed by, or on behalf of, the
74
+ Licensor for the purpose of discussing and improving the Work, but
75
+ excluding communication that is conspicuously marked or otherwise
76
+ designated in writing by the copyright owner as "Not a Contribution."
77
+
78
+ "Contributor" shall mean Licensor and any individual or Legal Entity
79
+ on behalf of whom a Contribution has been received by Licensor and
80
+ subsequently incorporated within the Work.
81
+
82
+ 2. Grant of Copyright License. Subject to the terms and conditions of
83
+ this License, each Contributor hereby grants to You a perpetual,
84
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
85
+ copyright license to reproduce, prepare Derivative Works of,
86
+ publicly display, publicly perform, sublicense, and distribute the
87
+ Work and such Derivative Works in Source or Object form.
88
+
89
+ 3. Grant of Patent License. Subject to the terms and conditions of
90
+ this License, each Contributor hereby grants to You a perpetual,
91
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
92
+ (except as stated in this section) patent license to make, have made,
93
+ use, offer to sell, sell, import, and otherwise transfer the Work,
94
+ where such license applies only to those patent claims licensable
95
+ by such Contributor that are necessarily infringed by their
96
+ Contribution(s) alone or by combination of their Contribution(s)
97
+ with the Work to which such Contribution(s) was submitted. If You
98
+ institute patent litigation against any entity (including a
99
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
100
+ or a Contribution incorporated within the Work constitutes direct
101
+ or contributory patent infringement, then any patent licenses
102
+ granted to You under this License for that Work shall terminate
103
+ as of the date such litigation is filed.
104
+
105
+ 4. Redistribution. You may reproduce and distribute copies of the
106
+ Work or Derivative Works thereof in any medium, with or without
107
+ modifications, and in Source or Object form, provided that You
108
+ meet the following conditions:
109
+
110
+ (a) You must give any other recipients of the Work or
111
+ Derivative Works a copy of this License; and
112
+
113
+ (b) You must cause any modified files to carry prominent notices
114
+ stating that You changed the files; and
115
+
116
+ (c) You must retain, in the Source form of any Derivative Works
117
+ that You distribute, all copyright, patent, trademark, and
118
+ attribution notices from the Source form of the Work,
119
+ excluding those notices that do not pertain to any part of
120
+ the Derivative Works; and
121
+
122
+ (d) If the Work includes a "NOTICE" text file as part of its
123
+ distribution, then any Derivative Works that You distribute must
124
+ include a readable copy of the attribution notices contained
125
+ within such NOTICE file, excluding those notices that do not
126
+ pertain to any part of the Derivative Works, in at least one
127
+ of the following places: within a NOTICE text file distributed
128
+ as part of the Derivative Works; within the Source form or
129
+ documentation, if provided along with the Derivative Works; or,
130
+ within a display generated by the Derivative Works, if and
131
+ wherever such third-party notices normally appear. The contents
132
+ of the NOTICE file are for informational purposes only and
133
+ do not modify the License. You may add Your own attribution
134
+ notices within Derivative Works that You distribute, alongside
135
+ or as an addendum to the NOTICE text from the Work, provided
136
+ that such additional attribution notices cannot be construed
137
+ as modifying the License.
138
+
139
+ You may add Your own copyright statement to Your modifications and
140
+ may provide additional or different license terms and conditions
141
+ for use, reproduction, or distribution of Your modifications, or
142
+ for any such Derivative Works as a whole, provided Your use,
143
+ reproduction, and distribution of the Work otherwise complies with
144
+ the conditions stated in this License.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Additional Liability. While redistributing
182
+ the Work or Derivative Works thereof, You may choose to offer,
183
+ and charge a fee for, acceptance of support, warranty, indemnity,
184
+ or other liability obligations and/or rights consistent with this
185
+ License. However, in accepting such obligations, You may act only
186
+ on Your own behalf and on Your sole responsibility, not on behalf
187
+ of any other Contributor, and only if You agree to indemnify,
188
+ defend, and hold each Contributor harmless for any liability
189
+ incurred by, or claims asserted against, such Contributor by reason
190
+ of your accepting any such warranty or additional liability.
191
+
192
+ END OF TERMS AND CONDITIONS
193
+
194
+ APPENDIX: How to apply the Apache License to your work.
195
+
196
+ To apply the Apache License to your work, attach the following
197
+ boilerplate notice, with the fields enclosed by brackets "[]"
198
+ replaced with your own identifying information. (Don't include
199
+ the brackets!) The text should be enclosed in the appropriate
200
+ comment syntax for the file format. We also recommend that a
201
+ file or class name and description of purpose be included on the
202
+ same "printed page" as the copyright notice for easier
203
+ identification within third-party archives.
204
+
205
+ Copyright [yyyy] [name of copyright owner]
206
+
207
+ Licensed under the Apache License, Version 2.0 (the "License");
208
+ you may not use this file except in compliance with the License.
209
+ You may obtain a copy of the License at
210
+
211
+ http://www.apache.org/licenses/LICENSE-2.0
212
+
213
+ Unless required by applicable law or agreed to in writing, software
214
+ distributed under the License is distributed on an "AS IS" BASIS,
215
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
216
+ See the License for the specific language governing permissions and
217
+ limitations under the License.
218
+
219
+
220
+ ---
221
+
222
+ Some files in this codebase contain code from getsentry/sentry-javascript by Software, Inc. dba Sentry.
223
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
224
+
225
+ MIT License
226
+
227
+ Copyright (c) 2012 Functional Software, Inc. dba Sentry
228
+
229
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
230
+ this software and associated documentation files (the "Software"), to deal in
231
+ the Software without restriction, including without limitation the rights to
232
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
233
+ of the Software, and to permit persons to whom the Software is furnished to do
234
+ so, subject to the following conditions:
235
+
236
+ The above copyright notice and this permission notice shall be included in all
237
+ copies or substantial portions of the Software.
238
+
239
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
240
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
241
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ import { NextConfig } from 'next';
2
+
3
+ type NextFuncConfig = (phase: string, { defaultConfig }: {
4
+ defaultConfig: NextConfig;
5
+ }) => NextConfig;
6
+ type NextAsyncConfig = (phase: string, { defaultConfig }: {
7
+ defaultConfig: NextConfig;
8
+ }) => Promise<NextConfig>;
9
+ type UserProvidedConfig = NextConfig | NextFuncConfig | NextAsyncConfig;
10
+ type PostHogNextConfig = {
11
+ personalApiKey: string;
12
+ envId: string;
13
+ host?: string;
14
+ verbose?: boolean;
15
+ sourcemaps?: {
16
+ enabled?: boolean;
17
+ project?: string;
18
+ version?: string;
19
+ deleteAfterUpload?: boolean;
20
+ };
21
+ };
22
+ type PostHogNextConfigComplete = {
23
+ personalApiKey: string;
24
+ envId: string;
25
+ host: string;
26
+ verbose: boolean;
27
+ sourcemaps: {
28
+ enabled: boolean;
29
+ project?: string;
30
+ version?: string;
31
+ deleteAfterUpload: boolean;
32
+ };
33
+ };
34
+ declare function withPostHogConfig(userNextConfig: UserProvidedConfig, posthogConfig: PostHogNextConfig): NextConfig;
35
+
36
+ export { type PostHogNextConfig, type PostHogNextConfigComplete, withPostHogConfig };
@@ -33,4 +33,4 @@ type PostHogNextConfigComplete = {
33
33
  };
34
34
  declare function withPostHogConfig(userNextConfig: UserProvidedConfig, posthogConfig: PostHogNextConfig): NextConfig;
35
35
 
36
- export { PostHogNextConfig, PostHogNextConfigComplete, withPostHogConfig };
36
+ export { type PostHogNextConfig, type PostHogNextConfigComplete, withPostHogConfig };
package/dist/index.js ADDED
@@ -0,0 +1,295 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __objRest = (source, exclude) => {
26
+ var target = {};
27
+ for (var prop in source)
28
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
29
+ target[prop] = source[prop];
30
+ if (source != null && __getOwnPropSymbols)
31
+ for (var prop of __getOwnPropSymbols(source)) {
32
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
33
+ target[prop] = source[prop];
34
+ }
35
+ return target;
36
+ };
37
+ var __export = (target, all) => {
38
+ for (var name in all)
39
+ __defProp(target, name, { get: all[name], enumerable: true });
40
+ };
41
+ var __copyProps = (to, from, except, desc) => {
42
+ if (from && typeof from === "object" || typeof from === "function") {
43
+ for (let key of __getOwnPropNames(from))
44
+ if (!__hasOwnProp.call(to, key) && key !== except)
45
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
46
+ }
47
+ return to;
48
+ };
49
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
50
+ // If the importer is in node compatibility mode or this is not an ESM
51
+ // file that has been converted to a CommonJS file using a Babel-
52
+ // compatible transform (i.e. "__esModule" has not been set), then set
53
+ // "default" to the CommonJS "module.exports" for node compatibility.
54
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
55
+ mod
56
+ ));
57
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
+ var __async = (__this, __arguments, generator) => {
59
+ return new Promise((resolve, reject) => {
60
+ var fulfilled = (value) => {
61
+ try {
62
+ step(generator.next(value));
63
+ } catch (e) {
64
+ reject(e);
65
+ }
66
+ };
67
+ var rejected = (value) => {
68
+ try {
69
+ step(generator.throw(value));
70
+ } catch (e) {
71
+ reject(e);
72
+ }
73
+ };
74
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
75
+ step((generator = generator.apply(__this, __arguments)).next());
76
+ });
77
+ };
78
+
79
+ // src/index.ts
80
+ var index_exports = {};
81
+ __export(index_exports, {
82
+ withPostHogConfig: () => withPostHogConfig
83
+ });
84
+ module.exports = __toCommonJS(index_exports);
85
+
86
+ // src/webpack-plugin.ts
87
+ var import_child_process = require("child_process");
88
+ var import_path2 = __toESM(require("path"));
89
+
90
+ // src/utils.ts
91
+ var import_path = __toESM(require("path"));
92
+ var import_fs = __toESM(require("fs"));
93
+ function resolveBinaryPath(envPath, cwd, binName) {
94
+ const envLocations = envPath.split(import_path.default.delimiter);
95
+ const localLocations = buildLocalBinaryPaths(cwd);
96
+ const directories = [.../* @__PURE__ */ new Set([...envLocations, ...localLocations])];
97
+ for (const directory of directories) {
98
+ const binaryPath = import_path.default.join(directory, binName);
99
+ if (import_fs.default.existsSync(binaryPath)) {
100
+ return binaryPath;
101
+ }
102
+ }
103
+ throw new Error(`Binary ${binName} not found`);
104
+ }
105
+ var buildLocalBinaryPaths = (cwd) => {
106
+ const localPaths = getLocalPaths(import_path.default.resolve(cwd)).map(
107
+ (localPath) => import_path.default.join(localPath, "node_modules/.bin")
108
+ );
109
+ return localPaths;
110
+ };
111
+ var getLocalPaths = (startPath) => {
112
+ const paths = [];
113
+ let currentPath = startPath;
114
+ while (true) {
115
+ paths.push(currentPath);
116
+ const parentPath = import_path.default.resolve(currentPath, "..");
117
+ if (parentPath === currentPath) {
118
+ break;
119
+ }
120
+ currentPath = parentPath;
121
+ }
122
+ return paths;
123
+ };
124
+
125
+ // src/webpack-plugin.ts
126
+ var SourcemapWebpackPlugin = class {
127
+ constructor(posthogOptions, isServer, nextRuntime, distDir) {
128
+ this.posthogOptions = posthogOptions;
129
+ this.isServer = isServer;
130
+ this.nextRuntime = nextRuntime;
131
+ const resolvedDistDir = import_path2.default.resolve(distDir != null ? distDir : ".next");
132
+ if (!this.posthogOptions.personalApiKey) {
133
+ throw new Error(
134
+ `Personal API key not provided. If you are using turbo, make sure to add env variables to your turbo config`
135
+ );
136
+ }
137
+ if (!this.posthogOptions.envId) {
138
+ throw new Error(
139
+ `Environment ID not provided. If you are using turbo, make sure to add env variables to your turbo config`
140
+ );
141
+ }
142
+ this.directory = this.isServer ? import_path2.default.join(resolvedDistDir, "server") : import_path2.default.join(resolvedDistDir, "static/chunks");
143
+ }
144
+ apply(compiler) {
145
+ if (this.nextRuntime === "edge") {
146
+ return;
147
+ }
148
+ const onDone = (_, callback) => __async(this, null, function* () {
149
+ callback = callback || (() => {
150
+ });
151
+ try {
152
+ yield this.runInject();
153
+ yield this.runUpload();
154
+ } catch (error) {
155
+ const errorMessage = error instanceof Error ? error.message : error;
156
+ return console.error("Error running PostHog sourcemap plugin:", errorMessage);
157
+ }
158
+ return callback();
159
+ });
160
+ if (compiler.hooks) {
161
+ compiler.hooks.done.tapAsync("SourcemapWebpackPlugin", onDone);
162
+ } else {
163
+ compiler.plugin("done", onDone);
164
+ }
165
+ }
166
+ runInject() {
167
+ return __async(this, null, function* () {
168
+ const cliOptions = [];
169
+ cliOptions.push("sourcemap", "inject", "--directory", this.directory);
170
+ yield callPosthogCli(cliOptions, process.env, this.posthogOptions.verbose);
171
+ });
172
+ }
173
+ runUpload() {
174
+ return __async(this, null, function* () {
175
+ const cliOptions = [];
176
+ if (this.posthogOptions.host) {
177
+ cliOptions.push("--host", this.posthogOptions.host);
178
+ }
179
+ cliOptions.push("sourcemap", "upload");
180
+ cliOptions.push("--directory", this.directory);
181
+ if (this.posthogOptions.sourcemaps.project) {
182
+ cliOptions.push("--project", this.posthogOptions.sourcemaps.project);
183
+ }
184
+ if (this.posthogOptions.sourcemaps.version) {
185
+ cliOptions.push("--version", this.posthogOptions.sourcemaps.version);
186
+ }
187
+ if (this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer) {
188
+ cliOptions.push("--delete-after");
189
+ }
190
+ const envVars = __spreadProps(__spreadValues({}, process.env), {
191
+ POSTHOG_CLI_TOKEN: this.posthogOptions.personalApiKey,
192
+ POSTHOG_CLI_ENV_ID: this.posthogOptions.envId
193
+ });
194
+ yield callPosthogCli(cliOptions, envVars, this.posthogOptions.verbose);
195
+ });
196
+ }
197
+ };
198
+ function callPosthogCli(args, env, verbose) {
199
+ return __async(this, null, function* () {
200
+ var _a;
201
+ let binaryLocation;
202
+ try {
203
+ binaryLocation = resolveBinaryPath((_a = process.env.PATH) != null ? _a : "", __dirname, "posthog-cli");
204
+ } catch (e) {
205
+ throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`);
206
+ }
207
+ if (verbose) {
208
+ console.log("running posthog-cli from ", binaryLocation);
209
+ }
210
+ const child = (0, import_child_process.spawn)(binaryLocation, [...args], {
211
+ stdio: verbose ? "inherit" : "ignore",
212
+ env,
213
+ cwd: process.cwd()
214
+ });
215
+ yield new Promise((resolve, reject) => {
216
+ child.on("close", (code) => {
217
+ if (code === 0) {
218
+ resolve();
219
+ } else {
220
+ reject(new Error(`Command failed with code ${code}`));
221
+ }
222
+ });
223
+ child.on("error", (error) => {
224
+ reject(error);
225
+ });
226
+ });
227
+ });
228
+ }
229
+
230
+ // src/config.ts
231
+ function withPostHogConfig(userNextConfig, posthogConfig) {
232
+ const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
233
+ return (_0, _1) => __async(null, [_0, _1], function* (phase, { defaultConfig }) {
234
+ const _a = yield resolveUserConfig(userNextConfig, phase, defaultConfig), {
235
+ webpack: userWebPackConfig,
236
+ distDir
237
+ } = _a, userConfig = __objRest(_a, [
238
+ "webpack",
239
+ "distDir"
240
+ ]);
241
+ const defaultWebpackConfig = userWebPackConfig || ((config) => config);
242
+ const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
243
+ return __spreadProps(__spreadValues({}, userConfig), {
244
+ distDir,
245
+ productionBrowserSourceMaps: sourceMapEnabled,
246
+ webpack: (config, options) => {
247
+ const webpackConfig = defaultWebpackConfig(config, options);
248
+ if (webpackConfig && options.isServer && sourceMapEnabled) {
249
+ webpackConfig.devtool = "source-map";
250
+ }
251
+ if (sourceMapEnabled) {
252
+ webpackConfig.plugins = webpackConfig.plugins || [];
253
+ webpackConfig.plugins.push(
254
+ new SourcemapWebpackPlugin(posthogNextConfigComplete, options.isServer, options.nextRuntime, distDir)
255
+ );
256
+ }
257
+ return webpackConfig;
258
+ }
259
+ });
260
+ });
261
+ }
262
+ function resolveUserConfig(userNextConfig, phase, defaultConfig) {
263
+ if (typeof userNextConfig === "function") {
264
+ const maybePromise = userNextConfig(phase, { defaultConfig });
265
+ if (maybePromise instanceof Promise) {
266
+ return maybePromise;
267
+ } else {
268
+ return Promise.resolve(maybePromise);
269
+ }
270
+ } else if (typeof userNextConfig === "object") {
271
+ return Promise.resolve(userNextConfig);
272
+ } else {
273
+ throw new Error("Invalid user config");
274
+ }
275
+ }
276
+ function resolvePostHogConfig(posthogProvidedConfig) {
277
+ var _a, _b;
278
+ const { personalApiKey, envId, host, verbose, sourcemaps = {} } = posthogProvidedConfig;
279
+ return {
280
+ personalApiKey,
281
+ envId,
282
+ host: host != null ? host : "https://us.posthog.com",
283
+ verbose: verbose != null ? verbose : true,
284
+ sourcemaps: {
285
+ enabled: (_a = sourcemaps.enabled) != null ? _a : process.env.NODE_ENV == "production",
286
+ project: sourcemaps.project,
287
+ version: sourcemaps.version,
288
+ deleteAfterUpload: (_b = sourcemaps.deleteAfterUpload) != null ? _b : true
289
+ }
290
+ };
291
+ }
292
+ // Annotate the CommonJS export names for ESM import in node:
293
+ 0 && (module.exports = {
294
+ withPostHogConfig
295
+ });
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.1",
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-lite.git",
14
- "directory": "posthog-nextjs-config"
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.4"
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
- "lib/"
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,172 +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
-
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
11
-
12
- class SourcemapWebpackPlugin {
13
- constructor(posthogOptions, isServer, nextRuntime) {
14
- this.posthogOptions = posthogOptions;
15
- this.isServer = isServer;
16
- this.nextRuntime = nextRuntime;
17
- this.directory = this.isServer ? `./.next/server` : `./.next/static/chunks`;
18
- }
19
- apply(compiler) {
20
- if (this.nextRuntime === 'edge') {
21
- // TODO: edge and nodejs runtime output files in the same location
22
- // to support edge runtime we need a way to pass a list of files to the cli
23
- return;
24
- }
25
- const onDone = async (_, callback) => {
26
- callback = callback || (() => {});
27
- try {
28
- await this.runInject();
29
- await this.runUpload();
30
- } catch (error) {
31
- const errorMessage = error instanceof Error ? error.message : error;
32
- return console.error('Error running PostHog sourcemap plugin:', errorMessage);
33
- }
34
- return callback();
35
- };
36
- if (compiler.hooks) {
37
- compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone);
38
- } else {
39
- compiler.plugin('done', onDone);
40
- }
41
- }
42
- async runInject() {
43
- const cliOptions = [];
44
- cliOptions.push('sourcemap', 'inject', '--directory', this.directory);
45
- await callPosthogCli(cliOptions, process.env, this.posthogOptions.verbose);
46
- }
47
- async runUpload() {
48
- const cliOptions = [];
49
- if (this.posthogOptions.host) {
50
- cliOptions.push('--host', this.posthogOptions.host);
51
- }
52
- cliOptions.push('sourcemap', 'upload');
53
- cliOptions.push('--directory', this.directory);
54
- if (this.posthogOptions.sourcemaps.project) {
55
- cliOptions.push('--project', this.posthogOptions.sourcemaps.project);
56
- }
57
- if (this.posthogOptions.sourcemaps.version) {
58
- cliOptions.push('--version', this.posthogOptions.sourcemaps.version);
59
- }
60
- if (this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer) {
61
- cliOptions.push('--delete-after');
62
- }
63
- // Add env variables
64
- const envVars = {
65
- ...process.env,
66
- POSTHOG_CLI_TOKEN: this.posthogOptions.personalApiKey,
67
- POSTHOG_CLI_ENV_ID: this.posthogOptions.envId
68
- };
69
- await callPosthogCli(cliOptions, envVars, this.posthogOptions.verbose);
70
- }
71
- }
72
- async function callPosthogCli(args, env, verbose) {
73
- const cwd = path__default["default"].resolve('.');
74
- const child = child_process.spawn('posthog-cli', [...args], {
75
- stdio: verbose ? 'inherit' : 'ignore',
76
- env: addLocalPath(env ?? process.env, cwd)
77
- });
78
- await new Promise((resolve, reject) => {
79
- child.on('close', code => {
80
- if (code === 0) {
81
- resolve();
82
- } else {
83
- reject(new Error(`Command failed with code ${code}`));
84
- }
85
- });
86
- child.on('error', error => {
87
- reject(error);
88
- });
89
- });
90
- }
91
- const addLocalPath = ({
92
- Path = '',
93
- PATH = Path,
94
- ...env
95
- }, cwd) => {
96
- const pathParts = PATH.split(path__default["default"].delimiter);
97
- const localPaths = getLocalPaths([], path__default["default"].resolve(cwd)).map(localPath => path__default["default"].join(localPath, 'node_modules/.bin')).filter(localPath => !pathParts.includes(localPath));
98
- return {
99
- ...env,
100
- PATH: [...localPaths, PATH].filter(Boolean).join(path__default["default"].delimiter)
101
- };
102
- };
103
- const getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path__default["default"].resolve(localPath, '..'));
104
-
105
- function withPostHogConfig(userNextConfig, posthogConfig) {
106
- const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
107
- return async (phase, {
108
- defaultConfig
109
- }) => {
110
- const {
111
- webpack: userWebPackConfig,
112
- ...userConfig
113
- } = await resolveUserConfig(userNextConfig, phase, defaultConfig);
114
- const defaultWebpackConfig = userWebPackConfig || (config => config);
115
- const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
116
- return {
117
- ...userConfig,
118
- productionBrowserSourceMaps: sourceMapEnabled,
119
- webpack: (config, options) => {
120
- const webpackConfig = defaultWebpackConfig(config, options);
121
- if (webpackConfig && options.isServer && sourceMapEnabled) {
122
- webpackConfig.devtool = 'source-map';
123
- }
124
- if (sourceMapEnabled) {
125
- webpackConfig.plugins = webpackConfig.plugins || [];
126
- webpackConfig.plugins.push(new SourcemapWebpackPlugin(posthogNextConfigComplete, options.isServer, options.nextRuntime));
127
- }
128
- return webpackConfig;
129
- }
130
- };
131
- };
132
- }
133
- function resolveUserConfig(userNextConfig, phase, defaultConfig) {
134
- if (typeof userNextConfig === 'function') {
135
- const maybePromise = userNextConfig(phase, {
136
- defaultConfig
137
- });
138
- if (maybePromise instanceof Promise) {
139
- return maybePromise;
140
- } else {
141
- return Promise.resolve(maybePromise);
142
- }
143
- } else if (typeof userNextConfig === 'object') {
144
- return Promise.resolve(userNextConfig);
145
- } else {
146
- throw new Error('Invalid user config');
147
- }
148
- }
149
- function resolvePostHogConfig(posthogProvidedConfig) {
150
- const {
151
- personalApiKey,
152
- envId,
153
- host,
154
- verbose,
155
- sourcemaps = {}
156
- } = posthogProvidedConfig;
157
- return {
158
- personalApiKey,
159
- envId,
160
- host: host ?? 'https://us.posthog.com',
161
- verbose: verbose ?? true,
162
- sourcemaps: {
163
- enabled: sourcemaps.enabled ?? process.env.NODE_ENV == 'production',
164
- project: sourcemaps.project,
165
- version: sourcemaps.version,
166
- deleteAfterUpload: sourcemaps.deleteAfterUpload ?? true
167
- }
168
- };
169
- }
170
-
171
- exports.withPostHogConfig = withPostHogConfig;
172
- //# sourceMappingURL=index.cjs.map
package/lib/index.cjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/webpack-plugin.ts","../src/config.ts"],"sourcesContent":["import { PostHogNextConfigComplete } from './config'\nimport { spawn } from 'child_process'\nimport path from 'path'\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 ) {\n this.directory = this.isServer ? `./.next/server` : `./.next/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 const cwd = path.resolve('.')\n const child = spawn('posthog-cli', [...args], {\n stdio: verbose ? 'inherit' : 'ignore',\n env: addLocalPath(env ?? process.env, 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\nconst addLocalPath = ({ Path = '', PATH = Path, ...env }: NodeJS.ProcessEnv, cwd: string): NodeJS.ProcessEnv => {\n const pathParts = PATH.split(path.delimiter)\n const localPaths = getLocalPaths([], path.resolve(cwd))\n .map((localPath: string) => path.join(localPath, 'node_modules/.bin'))\n .filter((localPath: string) => !pathParts.includes(localPath))\n return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(path.delimiter) }\n}\n\nconst getLocalPaths = (localPaths: string[], localPath: string): string[] =>\n localPaths.at(-1) === localPath\n ? localPaths\n : getLocalPaths([...localPaths, localPath], path.resolve(localPath, '..'))\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 { webpack: userWebPackConfig, ...userConfig } = await resolveUserConfig(userNextConfig, phase, defaultConfig)\n const defaultWebpackConfig = userWebPackConfig || ((config: any) => config)\n const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled\n return {\n ...userConfig,\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)\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":["SourcemapWebpackPlugin","constructor","posthogOptions","isServer","nextRuntime","directory","apply","compiler","onDone","_","callback","runInject","runUpload","error","errorMessage","Error","message","console","hooks","done","tapAsync","plugin","cliOptions","push","callPosthogCli","process","env","verbose","host","sourcemaps","project","version","deleteAfterUpload","envVars","POSTHOG_CLI_TOKEN","personalApiKey","POSTHOG_CLI_ENV_ID","envId","args","cwd","path","resolve","child","spawn","stdio","addLocalPath","Promise","reject","on","code","Path","PATH","pathParts","split","delimiter","localPaths","getLocalPaths","map","localPath","join","filter","includes","Boolean","at","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":";;;;;;;;;;;MAMaA,sBAAsB,CAAA;AAGjCC,EAAAA,WAAAA,CACUC,cAAyC,EACzCC,QAAiB,EACjBC,WAAwB,EAAA;IAFxB,IAAc,CAAAF,cAAA,GAAdA,cAAc,CAAA;IACd,IAAQ,CAAAC,QAAA,GAARA,QAAQ,CAAA;IACR,IAAW,CAAAC,WAAA,GAAXA,WAAW,CAAA;IAEnB,IAAI,CAACC,SAAS,GAAG,IAAI,CAACF,QAAQ,GAAG,CAAgB,cAAA,CAAA,GAAG,CAAuB,qBAAA,CAAA,CAAA;AAC7E,GAAA;EAEAG,KAAKA,CAACC,QAAa,EAAA;AACjB,IAAA,IAAI,IAAI,CAACH,WAAW,KAAK,MAAM,EAAE;AAC/B;AACA;AACA,MAAA,OAAA;AACD,KAAA;AAED,IAAA,MAAMI,MAAM,GAAG,OAAOC,CAAM,EAAEC,QAAa,KAAmB;AAC5DA,MAAAA,QAAQ,GAAGA,QAAQ,KAAK,MAAK,EAAG,CAAC,CAAA;MACjC,IAAI;AACF,QAAA,MAAM,IAAI,CAACC,SAAS,EAAE,CAAA;AACtB,QAAA,MAAM,IAAI,CAACC,SAAS,EAAE,CAAA;OACvB,CAAC,OAAOC,KAAK,EAAE;QACd,MAAMC,YAAY,GAAGD,KAAK,YAAYE,KAAK,GAAGF,KAAK,CAACG,OAAO,GAAGH,KAAK,CAAA;AACnE,QAAA,OAAOI,OAAO,CAACJ,KAAK,CAAC,yCAAyC,EAAEC,YAAY,CAAC,CAAA;AAC9E,OAAA;MACD,OAAOJ,QAAQ,EAAE,CAAA;KAClB,CAAA;IAED,IAAIH,QAAQ,CAACW,KAAK,E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AI,OAAOL,cAAc,KAAK,UAAU,EAAE;AACxC,IAAA,MAAMmB,YAAY,GAAGnB,cAAc,CAACI,KAAK,EAAE;AAAEC,MAAAA,aAAAA;AAAe,KAAA,CAAC,CAAA;IAC7D,IAAIc,YAAY,YAAYtC,OAAO,EAAE;AACnC,MAAA,OAAOsC,YAAY,CAAA;AACpB,KAAA,MAAM;AACL,MAAA,OAAOtC,OAAO,CAACL,OAAO,CAAC2C,YAAY,CAAC,CAAA;AACrC,KAAA;AACF,GAAA,MAAM,IAAI,OAAOnB,cAAc,KAAK,QAAQ,EAAE;AAC7C,IAAA,OAAOnB,OAAO,CAACL,OAAO,CAACwB,cAAc,CAAC,CAAA;AACvC,GAAA,MAAM;AACL,IAAA,MAAM,IAAIlD,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACvC,GAAA;AACH,CAAA;AAEA,SAASqD,oBAAoBA,CAACiB,qBAAwC,EAAA;EACpE,MAAM;IAAElD,cAAc;IAAEE,KAAK;IAAET,IAAI;IAAED,OAAO;AAAEE,IAAAA,UAAU,GAAG,EAAA;AAAI,GAAA,GAAGwD,qBAAqB,CAAA;EACvF,OAAO;IACLlD,cAAc;IACdE,KAAK;IACLT,IAAI,EAAEA,IAAI,IAAI,wBAAwB;IACtCD,OAAO,EAAEA,OAAO,IAAI,IAAI;AACxBE,IAAAA,UAAU,EAAE;MACViD,OAAO,EAAEjD,UAAU,CAACiD,OAAO,IAAIrD,OAAO,CAACC,GAAG,CAAC4D,QAAQ,IAAI,YAAY;MACnExD,OAAO,EAAED,UAAU,CAACC,OAAO;MAC3BC,OAAO,EAAEF,UAAU,CAACE,OAAO;AAC3BC,MAAAA,iBAAiB,EAAEH,UAAU,CAACG,iBAAiB,IAAI,IAAA;AACpD,KAAA;GACF,CAAA;AACH;;;;"}
package/lib/index.mjs DELETED
@@ -1,164 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import path from 'path';
3
-
4
- class SourcemapWebpackPlugin {
5
- constructor(posthogOptions, isServer, nextRuntime) {
6
- this.posthogOptions = posthogOptions;
7
- this.isServer = isServer;
8
- this.nextRuntime = nextRuntime;
9
- this.directory = this.isServer ? `./.next/server` : `./.next/static/chunks`;
10
- }
11
- apply(compiler) {
12
- if (this.nextRuntime === 'edge') {
13
- // TODO: edge and nodejs runtime output files in the same location
14
- // to support edge runtime we need a way to pass a list of files to the cli
15
- return;
16
- }
17
- const onDone = async (_, callback) => {
18
- callback = callback || (() => {});
19
- try {
20
- await this.runInject();
21
- await this.runUpload();
22
- } catch (error) {
23
- const errorMessage = error instanceof Error ? error.message : error;
24
- return console.error('Error running PostHog sourcemap plugin:', errorMessage);
25
- }
26
- return callback();
27
- };
28
- if (compiler.hooks) {
29
- compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone);
30
- } else {
31
- compiler.plugin('done', onDone);
32
- }
33
- }
34
- async runInject() {
35
- const cliOptions = [];
36
- cliOptions.push('sourcemap', 'inject', '--directory', this.directory);
37
- await callPosthogCli(cliOptions, process.env, this.posthogOptions.verbose);
38
- }
39
- async runUpload() {
40
- const cliOptions = [];
41
- if (this.posthogOptions.host) {
42
- cliOptions.push('--host', this.posthogOptions.host);
43
- }
44
- cliOptions.push('sourcemap', 'upload');
45
- cliOptions.push('--directory', this.directory);
46
- if (this.posthogOptions.sourcemaps.project) {
47
- cliOptions.push('--project', this.posthogOptions.sourcemaps.project);
48
- }
49
- if (this.posthogOptions.sourcemaps.version) {
50
- cliOptions.push('--version', this.posthogOptions.sourcemaps.version);
51
- }
52
- if (this.posthogOptions.sourcemaps.deleteAfterUpload && !this.isServer) {
53
- cliOptions.push('--delete-after');
54
- }
55
- // Add env variables
56
- const envVars = {
57
- ...process.env,
58
- POSTHOG_CLI_TOKEN: this.posthogOptions.personalApiKey,
59
- POSTHOG_CLI_ENV_ID: this.posthogOptions.envId
60
- };
61
- await callPosthogCli(cliOptions, envVars, this.posthogOptions.verbose);
62
- }
63
- }
64
- async function callPosthogCli(args, env, verbose) {
65
- const cwd = path.resolve('.');
66
- const child = spawn('posthog-cli', [...args], {
67
- stdio: verbose ? 'inherit' : 'ignore',
68
- env: addLocalPath(env ?? process.env, cwd)
69
- });
70
- await new Promise((resolve, reject) => {
71
- child.on('close', code => {
72
- if (code === 0) {
73
- resolve();
74
- } else {
75
- reject(new Error(`Command failed with code ${code}`));
76
- }
77
- });
78
- child.on('error', error => {
79
- reject(error);
80
- });
81
- });
82
- }
83
- const addLocalPath = ({
84
- Path = '',
85
- PATH = Path,
86
- ...env
87
- }, cwd) => {
88
- const pathParts = PATH.split(path.delimiter);
89
- const localPaths = getLocalPaths([], path.resolve(cwd)).map(localPath => path.join(localPath, 'node_modules/.bin')).filter(localPath => !pathParts.includes(localPath));
90
- return {
91
- ...env,
92
- PATH: [...localPaths, PATH].filter(Boolean).join(path.delimiter)
93
- };
94
- };
95
- const getLocalPaths = (localPaths, localPath) => localPaths.at(-1) === localPath ? localPaths : getLocalPaths([...localPaths, localPath], path.resolve(localPath, '..'));
96
-
97
- function withPostHogConfig(userNextConfig, posthogConfig) {
98
- const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
99
- return async (phase, {
100
- defaultConfig
101
- }) => {
102
- const {
103
- webpack: userWebPackConfig,
104
- ...userConfig
105
- } = await resolveUserConfig(userNextConfig, phase, defaultConfig);
106
- const defaultWebpackConfig = userWebPackConfig || (config => config);
107
- const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
108
- return {
109
- ...userConfig,
110
- productionBrowserSourceMaps: sourceMapEnabled,
111
- webpack: (config, options) => {
112
- const webpackConfig = defaultWebpackConfig(config, options);
113
- if (webpackConfig && options.isServer && sourceMapEnabled) {
114
- webpackConfig.devtool = 'source-map';
115
- }
116
- if (sourceMapEnabled) {
117
- webpackConfig.plugins = webpackConfig.plugins || [];
118
- webpackConfig.plugins.push(new SourcemapWebpackPlugin(posthogNextConfigComplete, options.isServer, options.nextRuntime));
119
- }
120
- return webpackConfig;
121
- }
122
- };
123
- };
124
- }
125
- function resolveUserConfig(userNextConfig, phase, defaultConfig) {
126
- if (typeof userNextConfig === 'function') {
127
- const maybePromise = userNextConfig(phase, {
128
- defaultConfig
129
- });
130
- if (maybePromise instanceof Promise) {
131
- return maybePromise;
132
- } else {
133
- return Promise.resolve(maybePromise);
134
- }
135
- } else if (typeof userNextConfig === 'object') {
136
- return Promise.resolve(userNextConfig);
137
- } else {
138
- throw new Error('Invalid user config');
139
- }
140
- }
141
- function resolvePostHogConfig(posthogProvidedConfig) {
142
- const {
143
- personalApiKey,
144
- envId,
145
- host,
146
- verbose,
147
- sourcemaps = {}
148
- } = posthogProvidedConfig;
149
- return {
150
- personalApiKey,
151
- envId,
152
- host: host ?? 'https://us.posthog.com',
153
- verbose: verbose ?? true,
154
- sourcemaps: {
155
- enabled: sourcemaps.enabled ?? process.env.NODE_ENV == 'production',
156
- project: sourcemaps.project,
157
- version: sourcemaps.version,
158
- deleteAfterUpload: sourcemaps.deleteAfterUpload ?? true
159
- }
160
- };
161
- }
162
-
163
- export { withPostHogConfig };
164
- //# sourceMappingURL=index.mjs.map
package/lib/index.mjs.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/webpack-plugin.ts","../src/config.ts"],"sourcesContent":["import { PostHogNextConfigComplete } from './config'\nimport { spawn } from 'child_process'\nimport path from 'path'\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 ) {\n this.directory = this.isServer ? `./.next/server` : `./.next/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 const cwd = path.resolve('.')\n const child = spawn('posthog-cli', [...args], {\n stdio: verbose ? 'inherit' : 'ignore',\n env: addLocalPath(env ?? process.env, 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\nconst addLocalPath = ({ Path = '', PATH = Path, ...env }: NodeJS.ProcessEnv, cwd: string): NodeJS.ProcessEnv => {\n const pathParts = PATH.split(path.delimiter)\n const localPaths = getLocalPaths([], path.resolve(cwd))\n .map((localPath: string) => path.join(localPath, 'node_modules/.bin'))\n .filter((localPath: string) => !pathParts.includes(localPath))\n return { ...env, PATH: [...localPaths, PATH].filter(Boolean).join(path.delimiter) }\n}\n\nconst getLocalPaths = (localPaths: string[], localPath: string): string[] =>\n localPaths.at(-1) === localPath\n ? localPaths\n : getLocalPaths([...localPaths, localPath], path.resolve(localPath, '..'))\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 { webpack: userWebPackConfig, ...userConfig } = await resolveUserConfig(userNextConfig, phase, defaultConfig)\n const defaultWebpackConfig = userWebPackConfig || ((config: any) => config)\n const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled\n return {\n ...userConfig,\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)\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":["SourcemapWebpackPlugin","constructor","posthogOptions","isServer","nextRuntime","directory","apply","compiler","onDone","_","callback","runInject","runUpload","error","errorMessage","Error","message","console","hooks","done","tapAsync","plugin","cliOptions","push","callPosthogCli","process","env","verbose","host","sourcemaps","project","version","deleteAfterUpload","envVars","POSTHOG_CLI_TOKEN","personalApiKey","POSTHOG_CLI_ENV_ID","envId","args","cwd","path","resolve","child","spawn","stdio","addLocalPath","Promise","reject","on","code","Path","PATH","pathParts","split","delimiter","localPaths","getLocalPaths","map","localPath","join","filter","includes","Boolean","at","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":";;;MAMaA,sBAAsB,CAAA;AAGjCC,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