@posthog/core 1.23.4 → 1.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/process/cli.d.ts +23 -0
- package/dist/process/cli.d.ts.map +1 -0
- package/dist/process/cli.js +80 -0
- package/dist/process/cli.mjs +40 -0
- package/dist/process/config.d.ts +42 -0
- package/dist/process/config.d.ts.map +1 -0
- package/dist/process/config.js +67 -0
- package/dist/process/config.mjs +33 -0
- package/dist/process/index.d.ts +2 -1
- package/dist/process/index.d.ts.map +1 -1
- package/dist/process/index.js +24 -0
- package/dist/process/index.mjs +2 -0
- package/dist/process/spawn-local.d.ts +1 -0
- package/dist/process/spawn-local.d.ts.map +1 -1
- package/dist/process/spawn-local.js +13 -1
- package/dist/process/spawn-local.mjs +13 -1
- package/package.json +1 -1
- package/src/process/cli.ts +74 -0
- package/src/process/config.ts +86 -0
- package/src/process/index.ts +2 -2
- package/src/process/spawn-local.ts +15 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ResolvedPluginConfig } from './config';
|
|
2
|
+
/**
|
|
3
|
+
* Build CLI arguments for `posthog-cli sourcemap process`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function buildSourcemapCliArgs(config: ResolvedPluginConfig, mode: {
|
|
6
|
+
stdin: true;
|
|
7
|
+
} | {
|
|
8
|
+
directory: string;
|
|
9
|
+
}): string[];
|
|
10
|
+
/**
|
|
11
|
+
* Build environment variables for CLI invocation.
|
|
12
|
+
* Plugin config values override any existing process.env values.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildCliEnv(config: ResolvedPluginConfig): NodeJS.ProcessEnv;
|
|
15
|
+
/**
|
|
16
|
+
* Spawn the PostHog CLI for sourcemap processing via stdin (file list).
|
|
17
|
+
*/
|
|
18
|
+
export declare function runSourcemapCli(config: ResolvedPluginConfig, options: {
|
|
19
|
+
filePaths: string[];
|
|
20
|
+
} | {
|
|
21
|
+
directory: string;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/process/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAG/C;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC5C,MAAM,EAAE,CA0BV;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,oBAAoB,GAAG,MAAM,CAAC,UAAU,CAQ3E;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GACvD,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
runSourcemapCli: ()=>runSourcemapCli,
|
|
28
|
+
buildCliEnv: ()=>buildCliEnv,
|
|
29
|
+
buildSourcemapCliArgs: ()=>buildSourcemapCliArgs
|
|
30
|
+
});
|
|
31
|
+
const external_spawn_local_js_namespaceObject = require("./spawn-local.js");
|
|
32
|
+
function buildSourcemapCliArgs(config, mode) {
|
|
33
|
+
const args = [
|
|
34
|
+
'sourcemap',
|
|
35
|
+
'process'
|
|
36
|
+
];
|
|
37
|
+
if ('stdin' in mode) args.push('--stdin');
|
|
38
|
+
else args.push('--directory', mode.directory);
|
|
39
|
+
if (config.sourcemaps.releaseName) args.push('--release-name', config.sourcemaps.releaseName);
|
|
40
|
+
if (config.sourcemaps.releaseVersion) args.push('--release-version', config.sourcemaps.releaseVersion);
|
|
41
|
+
if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
|
|
42
|
+
if (config.sourcemaps.batchSize) args.push('--batch-size', config.sourcemaps.batchSize.toString());
|
|
43
|
+
return args;
|
|
44
|
+
}
|
|
45
|
+
function buildCliEnv(config) {
|
|
46
|
+
return {
|
|
47
|
+
...process.env,
|
|
48
|
+
RUST_LOG: `posthog_cli=${config.logLevel}`,
|
|
49
|
+
POSTHOG_CLI_HOST: config.host,
|
|
50
|
+
POSTHOG_CLI_API_KEY: config.personalApiKey,
|
|
51
|
+
POSTHOG_CLI_PROJECT_ID: config.projectId
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
async function runSourcemapCli(config, options) {
|
|
55
|
+
const mode = 'filePaths' in options ? {
|
|
56
|
+
stdin: true
|
|
57
|
+
} : {
|
|
58
|
+
directory: options.directory
|
|
59
|
+
};
|
|
60
|
+
const args = buildSourcemapCliArgs(config, mode);
|
|
61
|
+
const env = buildCliEnv(config);
|
|
62
|
+
const spawnOptions = {
|
|
63
|
+
cwd: process.cwd(),
|
|
64
|
+
env,
|
|
65
|
+
stdio: 'inherit'
|
|
66
|
+
};
|
|
67
|
+
if ('filePaths' in options) spawnOptions.stdin = options.filePaths.join('\n') + '\n';
|
|
68
|
+
await (0, external_spawn_local_js_namespaceObject.spawnLocal)(config.cliBinaryPath, args, spawnOptions);
|
|
69
|
+
}
|
|
70
|
+
exports.buildCliEnv = __webpack_exports__.buildCliEnv;
|
|
71
|
+
exports.buildSourcemapCliArgs = __webpack_exports__.buildSourcemapCliArgs;
|
|
72
|
+
exports.runSourcemapCli = __webpack_exports__.runSourcemapCli;
|
|
73
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
74
|
+
"buildCliEnv",
|
|
75
|
+
"buildSourcemapCliArgs",
|
|
76
|
+
"runSourcemapCli"
|
|
77
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
78
|
+
Object.defineProperty(exports, '__esModule', {
|
|
79
|
+
value: true
|
|
80
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { spawnLocal } from "./spawn-local.mjs";
|
|
2
|
+
function buildSourcemapCliArgs(config, mode) {
|
|
3
|
+
const args = [
|
|
4
|
+
'sourcemap',
|
|
5
|
+
'process'
|
|
6
|
+
];
|
|
7
|
+
if ('stdin' in mode) args.push('--stdin');
|
|
8
|
+
else args.push('--directory', mode.directory);
|
|
9
|
+
if (config.sourcemaps.releaseName) args.push('--release-name', config.sourcemaps.releaseName);
|
|
10
|
+
if (config.sourcemaps.releaseVersion) args.push('--release-version', config.sourcemaps.releaseVersion);
|
|
11
|
+
if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
|
|
12
|
+
if (config.sourcemaps.batchSize) args.push('--batch-size', config.sourcemaps.batchSize.toString());
|
|
13
|
+
return args;
|
|
14
|
+
}
|
|
15
|
+
function buildCliEnv(config) {
|
|
16
|
+
return {
|
|
17
|
+
...process.env,
|
|
18
|
+
RUST_LOG: `posthog_cli=${config.logLevel}`,
|
|
19
|
+
POSTHOG_CLI_HOST: config.host,
|
|
20
|
+
POSTHOG_CLI_API_KEY: config.personalApiKey,
|
|
21
|
+
POSTHOG_CLI_PROJECT_ID: config.projectId
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async function runSourcemapCli(config, options) {
|
|
25
|
+
const mode = 'filePaths' in options ? {
|
|
26
|
+
stdin: true
|
|
27
|
+
} : {
|
|
28
|
+
directory: options.directory
|
|
29
|
+
};
|
|
30
|
+
const args = buildSourcemapCliArgs(config, mode);
|
|
31
|
+
const env = buildCliEnv(config);
|
|
32
|
+
const spawnOptions = {
|
|
33
|
+
cwd: process.cwd(),
|
|
34
|
+
env,
|
|
35
|
+
stdio: 'inherit'
|
|
36
|
+
};
|
|
37
|
+
if ('filePaths' in options) spawnOptions.stdin = options.filePaths.join('\n') + '\n';
|
|
38
|
+
await spawnLocal(config.cliBinaryPath, args, spawnOptions);
|
|
39
|
+
}
|
|
40
|
+
export { buildCliEnv, buildSourcemapCliArgs, runSourcemapCli };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
2
|
+
export interface PluginConfig {
|
|
3
|
+
personalApiKey: string;
|
|
4
|
+
/** @deprecated Use projectId instead */
|
|
5
|
+
envId?: string;
|
|
6
|
+
projectId?: string;
|
|
7
|
+
host?: string;
|
|
8
|
+
logLevel?: LogLevel;
|
|
9
|
+
cliBinaryPath?: string;
|
|
10
|
+
sourcemaps?: {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
/** @deprecated Use releaseName instead */
|
|
13
|
+
project?: string;
|
|
14
|
+
releaseName?: string;
|
|
15
|
+
/** @deprecated Use releaseVersion instead */
|
|
16
|
+
version?: string;
|
|
17
|
+
releaseVersion?: string;
|
|
18
|
+
deleteAfterUpload?: boolean;
|
|
19
|
+
batchSize?: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export interface ResolvedPluginConfig extends Omit<PluginConfig, 'envId' | 'projectId'> {
|
|
23
|
+
projectId?: string;
|
|
24
|
+
host: string;
|
|
25
|
+
logLevel: LogLevel;
|
|
26
|
+
cliBinaryPath: string;
|
|
27
|
+
sourcemaps: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
releaseName?: string;
|
|
30
|
+
releaseVersion?: string;
|
|
31
|
+
deleteAfterUpload: boolean;
|
|
32
|
+
batchSize?: number;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface ResolveConfigOptions {
|
|
36
|
+
/** Default value for sourcemaps.enabled when not explicitly set. Defaults to true. */
|
|
37
|
+
defaultEnabled?: boolean;
|
|
38
|
+
/** The cwd used for resolving the CLI binary path. Defaults to process.cwd(). */
|
|
39
|
+
cwd?: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function resolveConfig(options: PluginConfig, resolveOptions?: ResolveConfigOptions): ResolvedPluginConfig;
|
|
42
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/process/config.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAA;AAErE,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAA;IACtB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,UAAU,CAAC,EAAE;QACX,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,0CAA0C;QAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,6CAA6C;QAC7C,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,iBAAiB,CAAC,EAAE,OAAO,CAAA;QAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,CAAA;CACF;AAED,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,YAAY,EAAE,OAAO,GAAG,WAAW,CAAC;IACrF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,QAAQ,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE;QACV,OAAO,EAAE,OAAO,CAAA;QAChB,WAAW,CAAC,EAAE,MAAM,CAAA;QACpB,cAAc,CAAC,EAAE,MAAM,CAAA;QACvB,iBAAiB,EAAE,OAAO,CAAA;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,CAAA;CACF;AAED,MAAM,WAAW,oBAAoB;IACnC,sFAAsF;IACtF,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,EAAE,cAAc,CAAC,EAAE,oBAAoB,GAAG,oBAAoB,CAuChH"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
resolveConfig: ()=>resolveConfig
|
|
28
|
+
});
|
|
29
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
30
|
+
function resolveConfig(options, resolveOptions) {
|
|
31
|
+
const projectId = options.projectId ?? options.envId;
|
|
32
|
+
const host = options.host ?? 'https://us.i.posthog.com';
|
|
33
|
+
const logLevel = options.logLevel ?? 'info';
|
|
34
|
+
const cwd = resolveOptions?.cwd ?? process.cwd();
|
|
35
|
+
const cliBinaryPath = options.cliBinaryPath ?? (0, external_utils_js_namespaceObject.resolveBinaryPath)('posthog-cli', {
|
|
36
|
+
path: process.env.PATH ?? '',
|
|
37
|
+
cwd
|
|
38
|
+
});
|
|
39
|
+
const userSourcemaps = options.sourcemaps ?? {};
|
|
40
|
+
const defaultEnabled = resolveOptions?.defaultEnabled ?? true;
|
|
41
|
+
const enabled = userSourcemaps.enabled ?? defaultEnabled;
|
|
42
|
+
if (enabled) {
|
|
43
|
+
if (!projectId) throw new Error('projectId is required when sourcemaps are enabled (envId is deprecated)');
|
|
44
|
+
if (!options.personalApiKey) throw new Error('personalApiKey is required when sourcemaps are enabled');
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
personalApiKey: options.personalApiKey,
|
|
48
|
+
projectId,
|
|
49
|
+
host,
|
|
50
|
+
logLevel,
|
|
51
|
+
cliBinaryPath,
|
|
52
|
+
sourcemaps: {
|
|
53
|
+
enabled,
|
|
54
|
+
releaseName: userSourcemaps.releaseName ?? userSourcemaps.project,
|
|
55
|
+
releaseVersion: userSourcemaps.releaseVersion ?? userSourcemaps.version,
|
|
56
|
+
deleteAfterUpload: userSourcemaps.deleteAfterUpload ?? true,
|
|
57
|
+
batchSize: userSourcemaps.batchSize
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.resolveConfig = __webpack_exports__.resolveConfig;
|
|
62
|
+
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
63
|
+
"resolveConfig"
|
|
64
|
+
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
65
|
+
Object.defineProperty(exports, '__esModule', {
|
|
66
|
+
value: true
|
|
67
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolveBinaryPath } from "./utils.mjs";
|
|
2
|
+
function resolveConfig(options, resolveOptions) {
|
|
3
|
+
const projectId = options.projectId ?? options.envId;
|
|
4
|
+
const host = options.host ?? 'https://us.i.posthog.com';
|
|
5
|
+
const logLevel = options.logLevel ?? 'info';
|
|
6
|
+
const cwd = resolveOptions?.cwd ?? process.cwd();
|
|
7
|
+
const cliBinaryPath = options.cliBinaryPath ?? resolveBinaryPath('posthog-cli', {
|
|
8
|
+
path: process.env.PATH ?? '',
|
|
9
|
+
cwd
|
|
10
|
+
});
|
|
11
|
+
const userSourcemaps = options.sourcemaps ?? {};
|
|
12
|
+
const defaultEnabled = resolveOptions?.defaultEnabled ?? true;
|
|
13
|
+
const enabled = userSourcemaps.enabled ?? defaultEnabled;
|
|
14
|
+
if (enabled) {
|
|
15
|
+
if (!projectId) throw new Error('projectId is required when sourcemaps are enabled (envId is deprecated)');
|
|
16
|
+
if (!options.personalApiKey) throw new Error('personalApiKey is required when sourcemaps are enabled');
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
personalApiKey: options.personalApiKey,
|
|
20
|
+
projectId,
|
|
21
|
+
host,
|
|
22
|
+
logLevel,
|
|
23
|
+
cliBinaryPath,
|
|
24
|
+
sourcemaps: {
|
|
25
|
+
enabled,
|
|
26
|
+
releaseName: userSourcemaps.releaseName ?? userSourcemaps.project,
|
|
27
|
+
releaseVersion: userSourcemaps.releaseVersion ?? userSourcemaps.version,
|
|
28
|
+
deleteAfterUpload: userSourcemaps.deleteAfterUpload ?? true,
|
|
29
|
+
batchSize: userSourcemaps.batchSize
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export { resolveConfig };
|
package/dist/process/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/process/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,cAAc,UAAU,CAAA;AACxB,cAAc,OAAO,CAAA"}
|
package/dist/process/index.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_modules__ = {
|
|
3
|
+
"./cli": function(module) {
|
|
4
|
+
module.exports = require("./cli.js");
|
|
5
|
+
},
|
|
6
|
+
"./config": function(module) {
|
|
7
|
+
module.exports = require("./config.js");
|
|
8
|
+
},
|
|
3
9
|
"./spawn-local": function(module) {
|
|
4
10
|
module.exports = require("./spawn-local.js");
|
|
5
11
|
},
|
|
@@ -63,6 +69,24 @@ var __webpack_exports__ = {};
|
|
|
63
69
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
64
70
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
65
71
|
var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./utils?198b");
|
|
72
|
+
var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./config");
|
|
73
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
74
|
+
for(var __WEBPACK_IMPORT_KEY__ in _config__WEBPACK_IMPORTED_MODULE_2__)if ([
|
|
75
|
+
"resolveBinaryPath",
|
|
76
|
+
"default"
|
|
77
|
+
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
78
|
+
return _config__WEBPACK_IMPORTED_MODULE_2__[key];
|
|
79
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
80
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
81
|
+
var _cli__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("./cli");
|
|
82
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
83
|
+
for(var __WEBPACK_IMPORT_KEY__ in _cli__WEBPACK_IMPORTED_MODULE_3__)if ([
|
|
84
|
+
"resolveBinaryPath",
|
|
85
|
+
"default"
|
|
86
|
+
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
87
|
+
return _cli__WEBPACK_IMPORTED_MODULE_3__[key];
|
|
88
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
89
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
66
90
|
})();
|
|
67
91
|
exports.resolveBinaryPath = __webpack_exports__.resolveBinaryPath;
|
|
68
92
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
package/dist/process/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn-local.d.ts","sourceRoot":"","sources":["../../src/process/spawn-local.ts"],"names":[],"mappings":"AAEA,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;IACP,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IACtB,KAAK,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"spawn-local.d.ts","sourceRoot":"","sources":["../../src/process/spawn-local.ts"],"names":[],"mappings":"AAEA,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,EAAE;IACP,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;IACtB,KAAK,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GACA,OAAO,CAAC,IAAI,CAAC,CAiCf"}
|
|
@@ -28,13 +28,25 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const external_cross_spawn_namespaceObject = require("cross-spawn");
|
|
30
30
|
async function spawnLocal(executable, args, options) {
|
|
31
|
+
const stdioOption = void 0 !== options.stdin ? [
|
|
32
|
+
'pipe',
|
|
33
|
+
options.stdio,
|
|
34
|
+
options.stdio
|
|
35
|
+
] : options.stdio;
|
|
31
36
|
const child = (0, external_cross_spawn_namespaceObject.spawn)(executable, [
|
|
32
37
|
...args
|
|
33
38
|
], {
|
|
34
|
-
stdio:
|
|
39
|
+
stdio: stdioOption,
|
|
35
40
|
env: options.env,
|
|
36
41
|
cwd: options.cwd
|
|
37
42
|
});
|
|
43
|
+
if (void 0 !== options.stdin && child.stdin) {
|
|
44
|
+
child.stdin.on('error', (err)=>{
|
|
45
|
+
if ('EPIPE' !== err.code) throw err;
|
|
46
|
+
});
|
|
47
|
+
child.stdin.write(options.stdin);
|
|
48
|
+
child.stdin.end();
|
|
49
|
+
}
|
|
38
50
|
await new Promise((resolve, reject)=>{
|
|
39
51
|
child.on('close', (code)=>{
|
|
40
52
|
if (0 === code) resolve();
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import { spawn } from "cross-spawn";
|
|
2
2
|
async function spawnLocal(executable, args, options) {
|
|
3
|
+
const stdioOption = void 0 !== options.stdin ? [
|
|
4
|
+
'pipe',
|
|
5
|
+
options.stdio,
|
|
6
|
+
options.stdio
|
|
7
|
+
] : options.stdio;
|
|
3
8
|
const child = spawn(executable, [
|
|
4
9
|
...args
|
|
5
10
|
], {
|
|
6
|
-
stdio:
|
|
11
|
+
stdio: stdioOption,
|
|
7
12
|
env: options.env,
|
|
8
13
|
cwd: options.cwd
|
|
9
14
|
});
|
|
15
|
+
if (void 0 !== options.stdin && child.stdin) {
|
|
16
|
+
child.stdin.on('error', (err)=>{
|
|
17
|
+
if ('EPIPE' !== err.code) throw err;
|
|
18
|
+
});
|
|
19
|
+
child.stdin.write(options.stdin);
|
|
20
|
+
child.stdin.end();
|
|
21
|
+
}
|
|
10
22
|
await new Promise((resolve, reject)=>{
|
|
11
23
|
child.on('close', (code)=>{
|
|
12
24
|
if (0 === code) resolve();
|
package/package.json
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ResolvedPluginConfig } from './config'
|
|
2
|
+
import { spawnLocal } from './spawn-local'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Build CLI arguments for `posthog-cli sourcemap process`.
|
|
6
|
+
*/
|
|
7
|
+
export function buildSourcemapCliArgs(
|
|
8
|
+
config: ResolvedPluginConfig,
|
|
9
|
+
mode: { stdin: true } | { directory: string }
|
|
10
|
+
): string[] {
|
|
11
|
+
const args = ['sourcemap', 'process']
|
|
12
|
+
|
|
13
|
+
if ('stdin' in mode) {
|
|
14
|
+
args.push('--stdin')
|
|
15
|
+
} else {
|
|
16
|
+
args.push('--directory', mode.directory)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (config.sourcemaps.releaseName) {
|
|
20
|
+
args.push('--release-name', config.sourcemaps.releaseName)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (config.sourcemaps.releaseVersion) {
|
|
24
|
+
args.push('--release-version', config.sourcemaps.releaseVersion)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (config.sourcemaps.deleteAfterUpload) {
|
|
28
|
+
args.push('--delete-after')
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (config.sourcemaps.batchSize) {
|
|
32
|
+
args.push('--batch-size', config.sourcemaps.batchSize.toString())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return args
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Build environment variables for CLI invocation.
|
|
40
|
+
* Plugin config values override any existing process.env values.
|
|
41
|
+
*/
|
|
42
|
+
export function buildCliEnv(config: ResolvedPluginConfig): NodeJS.ProcessEnv {
|
|
43
|
+
return {
|
|
44
|
+
...process.env,
|
|
45
|
+
RUST_LOG: `posthog_cli=${config.logLevel}`,
|
|
46
|
+
POSTHOG_CLI_HOST: config.host,
|
|
47
|
+
POSTHOG_CLI_API_KEY: config.personalApiKey,
|
|
48
|
+
POSTHOG_CLI_PROJECT_ID: config.projectId,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Spawn the PostHog CLI for sourcemap processing via stdin (file list).
|
|
54
|
+
*/
|
|
55
|
+
export async function runSourcemapCli(
|
|
56
|
+
config: ResolvedPluginConfig,
|
|
57
|
+
options: { filePaths: string[] } | { directory: string }
|
|
58
|
+
): Promise<void> {
|
|
59
|
+
const mode = 'filePaths' in options ? { stdin: true as const } : { directory: options.directory }
|
|
60
|
+
const args = buildSourcemapCliArgs(config, mode)
|
|
61
|
+
const env = buildCliEnv(config)
|
|
62
|
+
|
|
63
|
+
const spawnOptions: Parameters<typeof spawnLocal>[2] = {
|
|
64
|
+
cwd: process.cwd(),
|
|
65
|
+
env,
|
|
66
|
+
stdio: 'inherit',
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if ('filePaths' in options) {
|
|
70
|
+
spawnOptions.stdin = options.filePaths.join('\n') + '\n'
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await spawnLocal(config.cliBinaryPath, args, spawnOptions)
|
|
74
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { resolveBinaryPath } from './utils'
|
|
2
|
+
|
|
3
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'
|
|
4
|
+
|
|
5
|
+
export interface PluginConfig {
|
|
6
|
+
personalApiKey: string
|
|
7
|
+
/** @deprecated Use projectId instead */
|
|
8
|
+
envId?: string
|
|
9
|
+
projectId?: string
|
|
10
|
+
host?: string
|
|
11
|
+
logLevel?: LogLevel
|
|
12
|
+
cliBinaryPath?: string
|
|
13
|
+
sourcemaps?: {
|
|
14
|
+
enabled?: boolean
|
|
15
|
+
/** @deprecated Use releaseName instead */
|
|
16
|
+
project?: string
|
|
17
|
+
releaseName?: string
|
|
18
|
+
/** @deprecated Use releaseVersion instead */
|
|
19
|
+
version?: string
|
|
20
|
+
releaseVersion?: string
|
|
21
|
+
deleteAfterUpload?: boolean
|
|
22
|
+
batchSize?: number
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ResolvedPluginConfig extends Omit<PluginConfig, 'envId' | 'projectId'> {
|
|
27
|
+
projectId?: string
|
|
28
|
+
host: string
|
|
29
|
+
logLevel: LogLevel
|
|
30
|
+
cliBinaryPath: string
|
|
31
|
+
sourcemaps: {
|
|
32
|
+
enabled: boolean
|
|
33
|
+
releaseName?: string
|
|
34
|
+
releaseVersion?: string
|
|
35
|
+
deleteAfterUpload: boolean
|
|
36
|
+
batchSize?: number
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ResolveConfigOptions {
|
|
41
|
+
/** Default value for sourcemaps.enabled when not explicitly set. Defaults to true. */
|
|
42
|
+
defaultEnabled?: boolean
|
|
43
|
+
/** The cwd used for resolving the CLI binary path. Defaults to process.cwd(). */
|
|
44
|
+
cwd?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function resolveConfig(options: PluginConfig, resolveOptions?: ResolveConfigOptions): ResolvedPluginConfig {
|
|
48
|
+
const projectId = options.projectId ?? options.envId
|
|
49
|
+
const host = options.host ?? 'https://us.i.posthog.com'
|
|
50
|
+
const logLevel = options.logLevel ?? 'info'
|
|
51
|
+
const cwd = resolveOptions?.cwd ?? process.cwd()
|
|
52
|
+
const cliBinaryPath =
|
|
53
|
+
options.cliBinaryPath ??
|
|
54
|
+
resolveBinaryPath('posthog-cli', {
|
|
55
|
+
path: process.env.PATH ?? '',
|
|
56
|
+
cwd,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const userSourcemaps = options.sourcemaps ?? {}
|
|
60
|
+
const defaultEnabled = resolveOptions?.defaultEnabled ?? true
|
|
61
|
+
const enabled = userSourcemaps.enabled ?? defaultEnabled
|
|
62
|
+
|
|
63
|
+
if (enabled) {
|
|
64
|
+
if (!projectId) {
|
|
65
|
+
throw new Error('projectId is required when sourcemaps are enabled (envId is deprecated)')
|
|
66
|
+
}
|
|
67
|
+
if (!options.personalApiKey) {
|
|
68
|
+
throw new Error('personalApiKey is required when sourcemaps are enabled')
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
personalApiKey: options.personalApiKey,
|
|
74
|
+
projectId,
|
|
75
|
+
host,
|
|
76
|
+
logLevel,
|
|
77
|
+
cliBinaryPath,
|
|
78
|
+
sourcemaps: {
|
|
79
|
+
enabled,
|
|
80
|
+
releaseName: userSourcemaps.releaseName ?? userSourcemaps.project,
|
|
81
|
+
releaseVersion: userSourcemaps.releaseVersion ?? userSourcemaps.version,
|
|
82
|
+
deleteAfterUpload: userSourcemaps.deleteAfterUpload ?? true,
|
|
83
|
+
batchSize: userSourcemaps.batchSize,
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/process/index.ts
CHANGED
|
@@ -7,14 +7,28 @@ export async function spawnLocal(
|
|
|
7
7
|
env: NodeJS.ProcessEnv
|
|
8
8
|
stdio: 'inherit' | 'ignore'
|
|
9
9
|
cwd: string
|
|
10
|
+
stdin?: string
|
|
10
11
|
}
|
|
11
12
|
): Promise<void> {
|
|
13
|
+
const stdioOption = options.stdin !== undefined ? ['pipe' as const, options.stdio, options.stdio] : options.stdio
|
|
14
|
+
|
|
12
15
|
const child = spawn(executable, [...args], {
|
|
13
|
-
stdio:
|
|
16
|
+
stdio: stdioOption,
|
|
14
17
|
env: options.env,
|
|
15
18
|
cwd: options.cwd,
|
|
16
19
|
})
|
|
17
20
|
|
|
21
|
+
if (options.stdin !== undefined && child.stdin) {
|
|
22
|
+
child.stdin.on('error', (err: any) => {
|
|
23
|
+
if (err.code !== 'EPIPE') {
|
|
24
|
+
throw err
|
|
25
|
+
}
|
|
26
|
+
// Swallow EPIPE: child may exit before consuming all stdin
|
|
27
|
+
})
|
|
28
|
+
child.stdin.write(options.stdin)
|
|
29
|
+
child.stdin.end()
|
|
30
|
+
}
|
|
31
|
+
|
|
18
32
|
await new Promise<void>((resolve, reject) => {
|
|
19
33
|
child.on('close', (code) => {
|
|
20
34
|
if (code === 0) {
|