@posthog/nextjs-config 1.3.10 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -219,7 +219,7 @@ limitations under the License.
219
219
 
220
220
  ---
221
221
 
222
- Some files in this codebase contain code from getsentry/sentry-javascript by Software, Inc. dba Sentry.
222
+ Some files in this codebase contain code from getsentry/sentry-javascript or getsentry/sentry-react-native by Software, Inc. dba Sentry.
223
223
  In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
224
224
 
225
225
  MIT License
@@ -242,4 +242,58 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
242
242
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
243
243
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
244
244
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
245
- SOFTWARE.
245
+ SOFTWARE.
246
+
247
+ ---
248
+
249
+ Some files in this codebase contain code from facebook/metro by Meta Platforms, Inc. and affiliates.
250
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
251
+
252
+ MIT License
253
+
254
+ Copyright (c) Meta Platforms, Inc. and affiliates.
255
+
256
+ Permission is hereby granted, free of charge, to any person obtaining a copy
257
+ of this software and associated documentation files (the "Software"), to deal
258
+ in the Software without restriction, including without limitation the rights
259
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
260
+ copies of the Software, and to permit persons to whom the Software is
261
+ furnished to do so, subject to the following conditions:
262
+
263
+ The above copyright notice and this permission notice shall be included in all
264
+ copies or substantial portions of the Software.
265
+
266
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
267
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
268
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
269
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
270
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
271
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
272
+ SOFTWARE.
273
+
274
+ ---
275
+
276
+ Some files in this codebase contain code from expo/expo by 650 Industries, Inc. (aka Expo).
277
+ In such cases it is explicitly stated in the file header. This license only applies to the relevant code in such cases.
278
+
279
+ The MIT License (MIT)
280
+
281
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
282
+
283
+ Permission is hereby granted, free of charge, to any person obtaining a copy
284
+ of this software and associated documentation files (the "Software"), to deal
285
+ in the Software without restriction, including without limitation the rights
286
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
287
+ copies of the Software, and to permit persons to whom the Software is
288
+ furnished to do so, subject to the following conditions:
289
+
290
+ The above copyright notice and this permission notice shall be included in all
291
+ copies or substantial portions of the Software.
292
+
293
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
294
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
295
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
296
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
297
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
298
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
299
+ SOFTWARE.
package/dist/config.d.ts CHANGED
@@ -6,11 +6,13 @@ type NextAsyncConfig = (phase: string, { defaultConfig }: {
6
6
  defaultConfig: NextConfig;
7
7
  }) => Promise<NextConfig>;
8
8
  type UserProvidedConfig = NextConfig | NextFuncConfig | NextAsyncConfig;
9
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
9
10
  export type PostHogNextConfig = {
11
+ cliBinaryPath?: string;
10
12
  personalApiKey: string;
11
13
  envId: string;
12
14
  host?: string;
13
- verbose?: boolean;
15
+ logLevel?: LogLevel;
14
16
  sourcemaps?: {
15
17
  enabled?: boolean;
16
18
  project?: string;
@@ -19,10 +21,11 @@ export type PostHogNextConfig = {
19
21
  };
20
22
  };
21
23
  export type PostHogNextConfigComplete = {
24
+ cliBinaryPath: string;
22
25
  personalApiKey: string;
23
26
  envId: string;
24
27
  host: string;
25
- verbose: boolean;
28
+ logLevel: LogLevel;
26
29
  sourcemaps: {
27
30
  enabled: boolean;
28
31
  project?: string;
package/dist/config.js CHANGED
@@ -28,6 +28,7 @@ __webpack_require__.d(__webpack_exports__, {
28
28
  });
29
29
  const external_webpack_plugin_js_namespaceObject = require("./webpack-plugin.js");
30
30
  const external_utils_js_namespaceObject = require("./utils.js");
31
+ const process_namespaceObject = require("@posthog/core/process");
31
32
  function withPostHogConfig(userNextConfig, posthogConfig) {
32
33
  const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
33
34
  const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
@@ -58,13 +59,19 @@ function resolveUserConfig(userNextConfig, phase, defaultConfig) {
58
59
  throw new Error('Invalid user config');
59
60
  }
60
61
  function resolvePostHogConfig(posthogProvidedConfig) {
61
- const { personalApiKey, envId, host, verbose, sourcemaps = {} } = posthogProvidedConfig;
62
+ const { personalApiKey, envId, host, logLevel, sourcemaps = {} } = posthogProvidedConfig;
63
+ var _process_env_PATH, _posthogProvidedConfig_cliBinaryPath;
64
+ const cliBinaryPath = null != (_posthogProvidedConfig_cliBinaryPath = posthogProvidedConfig.cliBinaryPath) ? _posthogProvidedConfig_cliBinaryPath : (0, process_namespaceObject.resolveBinaryPath)('posthog-cli', {
65
+ path: null != (_process_env_PATH = process.env.PATH) ? _process_env_PATH : '',
66
+ cwd: __dirname
67
+ });
62
68
  var _sourcemaps_enabled, _sourcemaps_deleteAfterUpload;
63
69
  return {
70
+ cliBinaryPath,
64
71
  personalApiKey,
65
72
  envId,
66
- host: null != host ? host : 'https://us.posthog.com',
67
- verbose: null != verbose ? verbose : true,
73
+ host: null != host ? host : 'https://us.i.posthog.com',
74
+ logLevel: null != logLevel ? logLevel : 'info',
68
75
  sourcemaps: {
69
76
  enabled: null != (_sourcemaps_enabled = sourcemaps.enabled) ? _sourcemaps_enabled : 'production' == process.env.NODE_ENV,
70
77
  project: sourcemaps.project,
@@ -97,7 +104,7 @@ function withCompilerConfig(userCompilerConfig, posthogConfig) {
97
104
  const userCompilerHook = null == userCompilerConfig ? void 0 : userCompilerConfig.runAfterProductionCompile;
98
105
  newConfig.runAfterProductionCompile = async (config)=>{
99
106
  await (null == userCompilerHook ? void 0 : userCompilerHook(config));
100
- posthogConfig.verbose && console.debug('Processing source maps from compilation hook...');
107
+ console.debug('Processing source maps from compilation hook...');
101
108
  await (0, external_utils_js_namespaceObject.processSourceMaps)(posthogConfig, config.distDir);
102
109
  };
103
110
  return newConfig;
package/dist/config.mjs CHANGED
@@ -1,5 +1,9 @@
1
+ import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
2
+ import { dirname as __webpack_dirname__ } from "node:path";
1
3
  import { SourcemapWebpackPlugin } from "./webpack-plugin.mjs";
2
4
  import { hasCompilerHook, isTurbopackEnabled, processSourceMaps } from "./utils.mjs";
5
+ import { resolveBinaryPath } from "@posthog/core/process";
6
+ var config_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
3
7
  function withPostHogConfig(userNextConfig, posthogConfig) {
4
8
  const posthogNextConfigComplete = resolvePostHogConfig(posthogConfig);
5
9
  const sourceMapEnabled = posthogNextConfigComplete.sourcemaps.enabled;
@@ -30,13 +34,19 @@ function resolveUserConfig(userNextConfig, phase, defaultConfig) {
30
34
  throw new Error('Invalid user config');
31
35
  }
32
36
  function resolvePostHogConfig(posthogProvidedConfig) {
33
- const { personalApiKey, envId, host, verbose, sourcemaps = {} } = posthogProvidedConfig;
37
+ const { personalApiKey, envId, host, logLevel, sourcemaps = {} } = posthogProvidedConfig;
38
+ var _process_env_PATH, _posthogProvidedConfig_cliBinaryPath;
39
+ const cliBinaryPath = null != (_posthogProvidedConfig_cliBinaryPath = posthogProvidedConfig.cliBinaryPath) ? _posthogProvidedConfig_cliBinaryPath : resolveBinaryPath('posthog-cli', {
40
+ path: null != (_process_env_PATH = process.env.PATH) ? _process_env_PATH : '',
41
+ cwd: config_dirname
42
+ });
34
43
  var _sourcemaps_enabled, _sourcemaps_deleteAfterUpload;
35
44
  return {
45
+ cliBinaryPath,
36
46
  personalApiKey,
37
47
  envId,
38
- host: null != host ? host : 'https://us.posthog.com',
39
- verbose: null != verbose ? verbose : true,
48
+ host: null != host ? host : 'https://us.i.posthog.com',
49
+ logLevel: null != logLevel ? logLevel : 'info',
40
50
  sourcemaps: {
41
51
  enabled: null != (_sourcemaps_enabled = sourcemaps.enabled) ? _sourcemaps_enabled : 'production' == process.env.NODE_ENV,
42
52
  project: sourcemaps.project,
@@ -69,7 +79,7 @@ function withCompilerConfig(userCompilerConfig, posthogConfig) {
69
79
  const userCompilerHook = null == userCompilerConfig ? void 0 : userCompilerConfig.runAfterProductionCompile;
70
80
  newConfig.runAfterProductionCompile = async (config)=>{
71
81
  await (null == userCompilerHook ? void 0 : userCompilerHook(config));
72
- posthogConfig.verbose && console.debug('Processing source maps from compilation hook...');
82
+ console.debug('Processing source maps from compilation hook...');
73
83
  await processSourceMaps(posthogConfig, config.distDir);
74
84
  };
75
85
  return newConfig;
package/dist/utils.js CHANGED
@@ -52,27 +52,25 @@ function hasCompilerHook() {
52
52
  }
53
53
  async function processSourceMaps(posthogOptions, directory) {
54
54
  const cliOptions = [];
55
- if (posthogOptions.host) cliOptions.push('--host', posthogOptions.host);
56
55
  cliOptions.push('sourcemap', 'process');
57
56
  cliOptions.push('--directory', directory);
58
57
  if (posthogOptions.sourcemaps.project) cliOptions.push('--project', posthogOptions.sourcemaps.project);
59
58
  if (posthogOptions.sourcemaps.version) cliOptions.push('--version', posthogOptions.sourcemaps.version);
60
59
  if (posthogOptions.sourcemaps.deleteAfterUpload) cliOptions.push('--delete-after');
60
+ const logLevel = `posthog_cli=${posthogOptions.logLevel}`;
61
61
  const envVars = {
62
62
  ...process.env,
63
+ RUST_LOG: logLevel,
64
+ POSTHOG_CLI_HOST: posthogOptions.host,
63
65
  POSTHOG_CLI_TOKEN: posthogOptions.personalApiKey,
64
66
  POSTHOG_CLI_ENV_ID: posthogOptions.envId
65
67
  };
66
- await callPosthogCli(cliOptions, envVars, posthogOptions.verbose);
68
+ await callPosthogCli(posthogOptions.cliBinaryPath, cliOptions, envVars);
67
69
  }
68
- async function callPosthogCli(args, env, verbose) {
69
- await (0, process_namespaceObject.spawnLocal)('posthog-cli', args, {
70
+ async function callPosthogCli(binaryPath, args, env) {
71
+ await (0, process_namespaceObject.spawnLocal)(binaryPath, args, {
70
72
  env,
71
- stdio: verbose ? 'inherit' : 'ignore',
72
- onBinaryFound: (binaryPath)=>{
73
- console.log(`running posthog-cli binary from ${binaryPath}`);
74
- },
75
- resolveFrom: __dirname,
73
+ stdio: 'inherit',
76
74
  cwd: process.cwd()
77
75
  });
78
76
  }
package/dist/utils.mjs CHANGED
@@ -1,11 +1,8 @@
1
- import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
2
- import { dirname as __webpack_dirname__ } from "node:path";
3
1
  import next_package from "next/package.json" with {
4
2
  type: "json"
5
3
  };
6
4
  import semver from "semver";
7
5
  import { spawnLocal } from "@posthog/core/process";
8
- var utils_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
9
6
  function getNextJsVersion() {
10
7
  return next_package.version;
11
8
  }
@@ -15,27 +12,25 @@ function hasCompilerHook() {
15
12
  }
16
13
  async function processSourceMaps(posthogOptions, directory) {
17
14
  const cliOptions = [];
18
- if (posthogOptions.host) cliOptions.push('--host', posthogOptions.host);
19
15
  cliOptions.push('sourcemap', 'process');
20
16
  cliOptions.push('--directory', directory);
21
17
  if (posthogOptions.sourcemaps.project) cliOptions.push('--project', posthogOptions.sourcemaps.project);
22
18
  if (posthogOptions.sourcemaps.version) cliOptions.push('--version', posthogOptions.sourcemaps.version);
23
19
  if (posthogOptions.sourcemaps.deleteAfterUpload) cliOptions.push('--delete-after');
20
+ const logLevel = `posthog_cli=${posthogOptions.logLevel}`;
24
21
  const envVars = {
25
22
  ...process.env,
23
+ RUST_LOG: logLevel,
24
+ POSTHOG_CLI_HOST: posthogOptions.host,
26
25
  POSTHOG_CLI_TOKEN: posthogOptions.personalApiKey,
27
26
  POSTHOG_CLI_ENV_ID: posthogOptions.envId
28
27
  };
29
- await callPosthogCli(cliOptions, envVars, posthogOptions.verbose);
28
+ await callPosthogCli(posthogOptions.cliBinaryPath, cliOptions, envVars);
30
29
  }
31
- async function callPosthogCli(args, env, verbose) {
32
- await spawnLocal('posthog-cli', args, {
30
+ async function callPosthogCli(binaryPath, args, env) {
31
+ await spawnLocal(binaryPath, args, {
33
32
  env,
34
- stdio: verbose ? 'inherit' : 'ignore',
35
- onBinaryFound: (binaryPath)=>{
36
- console.log(`running posthog-cli binary from ${binaryPath}`);
37
- },
38
- resolveFrom: utils_dirname,
33
+ stdio: 'inherit',
39
34
  cwd: process.cwd()
40
35
  });
41
36
  }
@@ -44,7 +44,7 @@ class SourcemapWebpackPlugin {
44
44
  const onDone = async (_, callback)=>{
45
45
  callback = callback || (()=>{});
46
46
  try {
47
- this.posthogOptions.verbose && console.log('Processing source maps from webpack plugin...');
47
+ console.log('Processing source maps from webpack plugin...');
48
48
  const posthogOptions = {
49
49
  ...this.posthogOptions,
50
50
  sourcemaps: {
@@ -6,7 +6,7 @@ class SourcemapWebpackPlugin {
6
6
  const onDone = async (_, callback)=>{
7
7
  callback = callback || (()=>{});
8
8
  try {
9
- this.posthogOptions.verbose && console.log('Processing source maps from webpack plugin...');
9
+ console.log('Processing source maps from webpack plugin...');
10
10
  const posthogOptions = {
11
11
  ...this.posthogOptions,
12
12
  sourcemaps: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/nextjs-config",
3
- "version": "1.3.10",
3
+ "version": "1.4.1",
4
4
  "description": "NextJS configuration helper for Posthog 🦔",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,9 +32,9 @@
32
32
  },
33
33
  "license": "MIT",
34
34
  "dependencies": {
35
- "@posthog/cli": "^0.5.7",
35
+ "@posthog/cli": "~0.5.9",
36
36
  "semver": "^7.7.2",
37
- "@posthog/core": "1.5.1"
37
+ "@posthog/core": "1.5.3"
38
38
  },
39
39
  "keywords": [
40
40
  "posthog",
@@ -44,11 +44,12 @@
44
44
  "@rslib/core": "^0.10.5",
45
45
  "@types/node": "^22.15.23",
46
46
  "@types/semver": "^7.7.0",
47
+ "@types/jest": "^29.5.0",
47
48
  "jest": "^29.7.0",
48
49
  "next": "^15.4.1",
49
50
  "ts-jest": "29.4.0",
50
- "@posthog-tooling/tsconfig-base": "1.0.0",
51
- "@posthog-tooling/rollup-utils": "1.0.0"
51
+ "@posthog-tooling/rollup-utils": "1.0.0",
52
+ "@posthog-tooling/tsconfig-base": "1.0.0"
52
53
  },
53
54
  "peerDependencies": {
54
55
  "next": ">12.1.0"