@posthog/nextjs-config 1.3.1 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +8 -64
- package/dist/utils.mjs +8 -56
- package/package.json +4 -3
- package/dist/utils.spec.d.ts +0 -1
- package/dist/utils.spec.js +0 -16
- package/dist/utils.spec.mjs +0 -10
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { PostHogNextConfigComplete } from './config';
|
|
2
|
-
export declare function resolveBinaryPath(envPath: string, cwd: string, binName: string): string;
|
|
3
|
-
export declare const buildLocalBinaryPaths: (cwd: string) => string[];
|
|
4
2
|
export declare function getNextJsVersion(): string;
|
|
5
3
|
export declare function hasCompilerHook(): boolean;
|
|
6
4
|
export declare function processSourceMaps(posthogOptions: PostHogNextConfigComplete, directory: string): Promise<void>;
|
package/dist/utils.js
CHANGED
|
@@ -35,50 +35,14 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
isTurbopackEnabled: ()=>isTurbopackEnabled,
|
|
37
37
|
hasCompilerHook: ()=>hasCompilerHook,
|
|
38
|
-
resolveBinaryPath: ()=>resolveBinaryPath,
|
|
39
|
-
buildLocalBinaryPaths: ()=>buildLocalBinaryPaths,
|
|
40
38
|
getNextJsVersion: ()=>getNextJsVersion,
|
|
41
39
|
processSourceMaps: ()=>processSourceMaps
|
|
42
40
|
});
|
|
43
|
-
const external_path_namespaceObject = require("path");
|
|
44
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
45
|
-
const external_fs_namespaceObject = require("fs");
|
|
46
|
-
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
47
|
-
const external_child_process_namespaceObject = require("child_process");
|
|
48
41
|
const package_json_namespaceObject = require("next/package.json");
|
|
49
42
|
var package_json_default = /*#__PURE__*/ __webpack_require__.n(package_json_namespaceObject);
|
|
50
43
|
const external_semver_namespaceObject = require("semver");
|
|
51
44
|
var external_semver_default = /*#__PURE__*/ __webpack_require__.n(external_semver_namespaceObject);
|
|
52
|
-
|
|
53
|
-
const envLocations = envPath.split(external_path_default().delimiter);
|
|
54
|
-
const localLocations = buildLocalBinaryPaths(cwd);
|
|
55
|
-
const directories = [
|
|
56
|
-
...new Set([
|
|
57
|
-
...localLocations,
|
|
58
|
-
...envLocations
|
|
59
|
-
])
|
|
60
|
-
];
|
|
61
|
-
for (const directory of directories){
|
|
62
|
-
const binaryPath = external_path_default().join(directory, binName);
|
|
63
|
-
if (external_fs_default().existsSync(binaryPath)) return binaryPath;
|
|
64
|
-
}
|
|
65
|
-
throw new Error(`Binary ${binName} not found`);
|
|
66
|
-
}
|
|
67
|
-
const buildLocalBinaryPaths = (cwd)=>{
|
|
68
|
-
const localPaths = getLocalPaths(external_path_default().resolve(cwd)).map((localPath)=>external_path_default().join(localPath, 'node_modules/.bin'));
|
|
69
|
-
return localPaths;
|
|
70
|
-
};
|
|
71
|
-
const getLocalPaths = (startPath)=>{
|
|
72
|
-
const paths = [];
|
|
73
|
-
let currentPath = startPath;
|
|
74
|
-
while(true){
|
|
75
|
-
paths.push(currentPath);
|
|
76
|
-
const parentPath = external_path_default().resolve(currentPath, '..');
|
|
77
|
-
if (parentPath === currentPath) break;
|
|
78
|
-
currentPath = parentPath;
|
|
79
|
-
}
|
|
80
|
-
return paths;
|
|
81
|
-
};
|
|
45
|
+
const process_namespaceObject = require("@posthog/core/process");
|
|
82
46
|
function getNextJsVersion() {
|
|
83
47
|
return package_json_default().version;
|
|
84
48
|
}
|
|
@@ -102,48 +66,28 @@ async function processSourceMaps(posthogOptions, directory) {
|
|
|
102
66
|
await callPosthogCli(cliOptions, envVars, posthogOptions.verbose);
|
|
103
67
|
}
|
|
104
68
|
async function callPosthogCli(args, env, verbose) {
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
var _process_env_PATH;
|
|
108
|
-
binaryLocation = resolveBinaryPath(null != (_process_env_PATH = process.env.PATH) ? _process_env_PATH : '', __dirname, 'posthog-cli');
|
|
109
|
-
} catch (e) {
|
|
110
|
-
throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`);
|
|
111
|
-
}
|
|
112
|
-
if (verbose) console.log('running posthog-cli from ', binaryLocation);
|
|
113
|
-
const child = (0, external_child_process_namespaceObject.spawn)(binaryLocation, [
|
|
114
|
-
...args
|
|
115
|
-
], {
|
|
116
|
-
shell: true,
|
|
117
|
-
stdio: verbose ? 'inherit' : 'ignore',
|
|
69
|
+
await (0, process_namespaceObject.spawnLocal)('posthog-cli', args, {
|
|
118
70
|
env,
|
|
71
|
+
stdio: verbose ? 'inherit' : 'ignore',
|
|
72
|
+
onBinaryFound: (binaryPath)=>{
|
|
73
|
+
console.log(`running posthog-cli binary from ${binaryPath}`);
|
|
74
|
+
},
|
|
75
|
+
resolveFrom: __dirname,
|
|
119
76
|
cwd: process.cwd()
|
|
120
77
|
});
|
|
121
|
-
await new Promise((resolve, reject)=>{
|
|
122
|
-
child.on('close', (code)=>{
|
|
123
|
-
if (0 === code) resolve();
|
|
124
|
-
else reject(new Error(`Command failed with code ${code}`));
|
|
125
|
-
});
|
|
126
|
-
child.on('error', (error)=>{
|
|
127
|
-
reject(error);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
78
|
}
|
|
131
79
|
function isTurbopackEnabled() {
|
|
132
80
|
return '1' === process.env.TURBOPACK;
|
|
133
81
|
}
|
|
134
|
-
exports.buildLocalBinaryPaths = __webpack_exports__.buildLocalBinaryPaths;
|
|
135
82
|
exports.getNextJsVersion = __webpack_exports__.getNextJsVersion;
|
|
136
83
|
exports.hasCompilerHook = __webpack_exports__.hasCompilerHook;
|
|
137
84
|
exports.isTurbopackEnabled = __webpack_exports__.isTurbopackEnabled;
|
|
138
85
|
exports.processSourceMaps = __webpack_exports__.processSourceMaps;
|
|
139
|
-
exports.resolveBinaryPath = __webpack_exports__.resolveBinaryPath;
|
|
140
86
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
141
|
-
"buildLocalBinaryPaths",
|
|
142
87
|
"getNextJsVersion",
|
|
143
88
|
"hasCompilerHook",
|
|
144
89
|
"isTurbopackEnabled",
|
|
145
|
-
"processSourceMaps"
|
|
146
|
-
"resolveBinaryPath"
|
|
90
|
+
"processSourceMaps"
|
|
147
91
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
148
92
|
Object.defineProperty(exports, '__esModule', {
|
|
149
93
|
value: true
|
package/dist/utils.mjs
CHANGED
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath as __webpack_fileURLToPath__ } from "node:url";
|
|
2
2
|
import { dirname as __webpack_dirname__ } from "node:path";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import { spawn } from "child_process";
|
|
6
3
|
import next_package from "next/package.json" with {
|
|
7
4
|
type: "json"
|
|
8
5
|
};
|
|
9
6
|
import semver from "semver";
|
|
7
|
+
import { spawnLocal } from "@posthog/core/process";
|
|
10
8
|
var utils_dirname = __webpack_dirname__(__webpack_fileURLToPath__(import.meta.url));
|
|
11
|
-
function resolveBinaryPath(envPath, cwd, binName) {
|
|
12
|
-
const envLocations = envPath.split(path.delimiter);
|
|
13
|
-
const localLocations = buildLocalBinaryPaths(cwd);
|
|
14
|
-
const directories = [
|
|
15
|
-
...new Set([
|
|
16
|
-
...localLocations,
|
|
17
|
-
...envLocations
|
|
18
|
-
])
|
|
19
|
-
];
|
|
20
|
-
for (const directory of directories){
|
|
21
|
-
const binaryPath = path.join(directory, binName);
|
|
22
|
-
if (fs.existsSync(binaryPath)) return binaryPath;
|
|
23
|
-
}
|
|
24
|
-
throw new Error(`Binary ${binName} not found`);
|
|
25
|
-
}
|
|
26
|
-
const buildLocalBinaryPaths = (cwd)=>{
|
|
27
|
-
const localPaths = getLocalPaths(path.resolve(cwd)).map((localPath)=>path.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.resolve(currentPath, '..');
|
|
36
|
-
if (parentPath === currentPath) break;
|
|
37
|
-
currentPath = parentPath;
|
|
38
|
-
}
|
|
39
|
-
return paths;
|
|
40
|
-
};
|
|
41
9
|
function getNextJsVersion() {
|
|
42
10
|
return next_package.version;
|
|
43
11
|
}
|
|
@@ -61,33 +29,17 @@ async function processSourceMaps(posthogOptions, directory) {
|
|
|
61
29
|
await callPosthogCli(cliOptions, envVars, posthogOptions.verbose);
|
|
62
30
|
}
|
|
63
31
|
async function callPosthogCli(args, env, verbose) {
|
|
64
|
-
|
|
65
|
-
try {
|
|
66
|
-
var _process_env_PATH;
|
|
67
|
-
binaryLocation = resolveBinaryPath(null != (_process_env_PATH = process.env.PATH) ? _process_env_PATH : '', utils_dirname, 'posthog-cli');
|
|
68
|
-
} catch (e) {
|
|
69
|
-
throw new Error(`Binary ${e} not found. Make sure postinstall script has been allowed for @posthog/cli`);
|
|
70
|
-
}
|
|
71
|
-
if (verbose) console.log('running posthog-cli from ', binaryLocation);
|
|
72
|
-
const child = spawn(binaryLocation, [
|
|
73
|
-
...args
|
|
74
|
-
], {
|
|
75
|
-
shell: true,
|
|
76
|
-
stdio: verbose ? 'inherit' : 'ignore',
|
|
32
|
+
await spawnLocal('posthog-cli', args, {
|
|
77
33
|
env,
|
|
34
|
+
stdio: verbose ? 'inherit' : 'ignore',
|
|
35
|
+
onBinaryFound: (binaryPath)=>{
|
|
36
|
+
console.log(`running posthog-cli binary from ${binaryPath}`);
|
|
37
|
+
},
|
|
38
|
+
resolveFrom: utils_dirname,
|
|
78
39
|
cwd: process.cwd()
|
|
79
40
|
});
|
|
80
|
-
await new Promise((resolve, reject)=>{
|
|
81
|
-
child.on('close', (code)=>{
|
|
82
|
-
if (0 === code) resolve();
|
|
83
|
-
else reject(new Error(`Command failed with code ${code}`));
|
|
84
|
-
});
|
|
85
|
-
child.on('error', (error)=>{
|
|
86
|
-
reject(error);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
41
|
}
|
|
90
42
|
function isTurbopackEnabled() {
|
|
91
43
|
return '1' === process.env.TURBOPACK;
|
|
92
44
|
}
|
|
93
|
-
export {
|
|
45
|
+
export { getNextJsVersion, hasCompilerHook, isTurbopackEnabled, processSourceMaps };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/nextjs-config",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "NextJS configuration helper for Posthog 🦔",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@posthog/cli": "^0.4.7",
|
|
36
|
-
"semver": "^7.7.2"
|
|
36
|
+
"semver": "^7.7.2",
|
|
37
|
+
"@posthog/core": "1.3.0"
|
|
37
38
|
},
|
|
38
39
|
"keywords": [
|
|
39
40
|
"posthog",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
"lint": "eslint src",
|
|
61
62
|
"lint:fix": "eslint src --fix",
|
|
62
63
|
"build": "rslib build",
|
|
63
|
-
"test:unit": "jest",
|
|
64
|
+
"test:unit": "jest --passWithNoTests",
|
|
64
65
|
"dev": "rslib build --watch",
|
|
65
66
|
"package": "pnpm pack --out $PACKAGE_DEST/%s.tgz"
|
|
66
67
|
}
|
package/dist/utils.spec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/utils.spec.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_exports__ = {};
|
|
3
|
-
const external_utils_js_namespaceObject = require("./utils.js");
|
|
4
|
-
describe('buildLocalBinaryPaths', ()=>{
|
|
5
|
-
it('generates possible binary locations', ()=>{
|
|
6
|
-
const cwd = '/home/user';
|
|
7
|
-
const result = (0, external_utils_js_namespaceObject.buildLocalBinaryPaths)(cwd);
|
|
8
|
-
expect(result.includes('/home/user/node_modules/.bin')).toBe(true);
|
|
9
|
-
expect(result.includes('/home/node_modules/.bin')).toBe(true);
|
|
10
|
-
expect(result.includes('/node_modules/.bin')).toBe(true);
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
14
|
-
Object.defineProperty(exports, '__esModule', {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
package/dist/utils.spec.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { buildLocalBinaryPaths } from "./utils.mjs";
|
|
2
|
-
describe('buildLocalBinaryPaths', ()=>{
|
|
3
|
-
it('generates possible binary locations', ()=>{
|
|
4
|
-
const cwd = '/home/user';
|
|
5
|
-
const result = buildLocalBinaryPaths(cwd);
|
|
6
|
-
expect(result.includes('/home/user/node_modules/.bin')).toBe(true);
|
|
7
|
-
expect(result.includes('/home/node_modules/.bin')).toBe(true);
|
|
8
|
-
expect(result.includes('/node_modules/.bin')).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
});
|