@posthog/rollup-plugin 1.1.12 → 1.1.14
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/index.d.ts.map +1 -1
- package/dist/index.js +42 -31
- package/package.json +4 -4
- package/src/index.ts +58 -34
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2C,MAAM,QAAQ,CAAA;AAC7E,OAAO,EAAiC,QAAQ,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAA2C,MAAM,QAAQ,CAAA;AAC7E,OAAO,EAAiC,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAI/E,MAAM,WAAW,0BAA0B;IACvC,cAAc,EAAE,MAAM,CAAA;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,UAAU,CAAC,EAAE;QACT,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,iBAAiB,CAAC,EAAE,OAAO,CAAA;QAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;KACrB,CAAA;CACJ;AAiBD,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,WAAW,EAAE,0BAA0B,GA4E1E,MAAM,CACd"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolveBinaryPath, spawnLocal } from "@posthog/core/process";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import promises from "fs/promises";
|
|
3
4
|
function posthogRollupPlugin(userOptions) {
|
|
4
5
|
const posthogOptions = resolveOptions(userOptions);
|
|
5
6
|
return {
|
|
@@ -13,39 +14,49 @@ function posthogRollupPlugin(userOptions) {
|
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
writeBundle: {
|
|
18
|
+
sequential: true,
|
|
19
|
+
async handler (options, bundle) {
|
|
20
|
+
if (!posthogOptions.sourcemaps.enabled) return;
|
|
21
|
+
const args = [
|
|
22
|
+
'sourcemap',
|
|
23
|
+
'process'
|
|
24
|
+
];
|
|
25
|
+
const cliPath = posthogOptions.cliBinaryPath;
|
|
26
|
+
const chunks = {};
|
|
27
|
+
const basePaths = [];
|
|
28
|
+
if (options.dir) basePaths.push(options.dir);
|
|
29
|
+
if (options.file) basePaths.push(path.dirname(options.file));
|
|
30
|
+
for(const fileName in bundle){
|
|
31
|
+
const chunk = bundle[fileName];
|
|
32
|
+
if ('chunk' === chunk.type) {
|
|
33
|
+
const chunkPath = path.resolve(...basePaths, fileName);
|
|
34
|
+
chunks[chunkPath] = chunk;
|
|
35
|
+
args.push('--file', chunkPath);
|
|
36
|
+
}
|
|
28
37
|
}
|
|
38
|
+
if (posthogOptions.sourcemaps.project) args.push('--project', posthogOptions.sourcemaps.project);
|
|
39
|
+
if (posthogOptions.sourcemaps.version) args.push('--version', posthogOptions.sourcemaps.version);
|
|
40
|
+
if (posthogOptions.sourcemaps.deleteAfterUpload) args.push('--delete-after');
|
|
41
|
+
if (posthogOptions.sourcemaps.batchSize) args.push('--batch-size', posthogOptions.sourcemaps.batchSize.toString());
|
|
42
|
+
await spawnLocal(cliPath, args, {
|
|
43
|
+
env: {
|
|
44
|
+
...process.env,
|
|
45
|
+
RUST_LOG: `posthog_cli=${posthogOptions.logLevel}`,
|
|
46
|
+
POSTHOG_CLI_HOST: posthogOptions.host,
|
|
47
|
+
POSTHOG_CLI_TOKEN: posthogOptions.personalApiKey,
|
|
48
|
+
POSTHOG_CLI_ENV_ID: posthogOptions.envId
|
|
49
|
+
},
|
|
50
|
+
stdio: 'inherit',
|
|
51
|
+
cwd: process.cwd()
|
|
52
|
+
});
|
|
53
|
+
await Promise.all(Object.entries(chunks).map((param)=>{
|
|
54
|
+
let [chunkPath, chunk] = param;
|
|
55
|
+
return promises.readFile(chunkPath, 'utf8').then((content)=>{
|
|
56
|
+
chunk.code = content;
|
|
57
|
+
});
|
|
58
|
+
}));
|
|
29
59
|
}
|
|
30
|
-
else if (options.file) {
|
|
31
|
-
const filePath = path.resolve(options.file);
|
|
32
|
-
args.push('--file', filePath);
|
|
33
|
-
}
|
|
34
|
-
if (posthogOptions.sourcemaps.project) args.push('--project', posthogOptions.sourcemaps.project);
|
|
35
|
-
if (posthogOptions.sourcemaps.version) args.push('--version', posthogOptions.sourcemaps.version);
|
|
36
|
-
if (posthogOptions.sourcemaps.deleteAfterUpload) args.push('--delete-after');
|
|
37
|
-
if (posthogOptions.sourcemaps.batchSize) args.push('--batch-size', posthogOptions.sourcemaps.batchSize.toString());
|
|
38
|
-
await spawnLocal(cliPath, args, {
|
|
39
|
-
env: {
|
|
40
|
-
...process.env,
|
|
41
|
-
RUST_LOG: `posthog_cli=${posthogOptions.logLevel}`,
|
|
42
|
-
POSTHOG_CLI_HOST: posthogOptions.host,
|
|
43
|
-
POSTHOG_CLI_TOKEN: posthogOptions.personalApiKey,
|
|
44
|
-
POSTHOG_CLI_ENV_ID: posthogOptions.envId
|
|
45
|
-
},
|
|
46
|
-
stdio: 'inherit',
|
|
47
|
-
cwd: process.cwd()
|
|
48
|
-
});
|
|
49
60
|
}
|
|
50
61
|
};
|
|
51
62
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/rollup-plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.14",
|
|
4
4
|
"description": "PostHog Rollup plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,16 +16,16 @@
|
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@posthog/cli": "~0.5.20",
|
|
19
|
-
"@posthog/core": "1.
|
|
19
|
+
"@posthog/core": "1.14.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"rollup": ">= 4.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@rslib/core": "0.10.6",
|
|
26
|
-
"rollup": "~4.53.2",
|
|
27
|
-
"jest": "29.7.0",
|
|
28
26
|
"@types/jest": "^29.5.14",
|
|
27
|
+
"jest": "29.7.0",
|
|
28
|
+
"rollup": "~4.53.2",
|
|
29
29
|
"@posthog-tooling/tsconfig-base": "1.1.1"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Plugin, OutputOptions, OutputAsset, OutputChunk } from 'rollup'
|
|
2
2
|
import { spawnLocal, resolveBinaryPath, LogLevel } from '@posthog/core/process'
|
|
3
3
|
import path from 'node:path'
|
|
4
|
+
import fs from 'node:fs/promises'
|
|
4
5
|
|
|
5
6
|
export interface PostHogRollupPluginOptions {
|
|
6
7
|
personalApiKey: string
|
|
@@ -36,54 +37,77 @@ export default function posthogRollupPlugin(userOptions: PostHogRollupPluginOpti
|
|
|
36
37
|
const posthogOptions = resolveOptions(userOptions)
|
|
37
38
|
return {
|
|
38
39
|
name: 'posthog-rollup-plugin',
|
|
40
|
+
|
|
39
41
|
outputOptions: {
|
|
40
42
|
order: 'post',
|
|
41
|
-
handler(options) {
|
|
43
|
+
handler(options: OutputOptions) {
|
|
42
44
|
return {
|
|
43
45
|
...options,
|
|
44
46
|
sourcemap: posthogOptions.sourcemaps.deleteAfterUpload ? 'hidden' : true,
|
|
45
47
|
}
|
|
46
48
|
},
|
|
47
49
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
|
|
51
|
+
writeBundle: {
|
|
52
|
+
// Write bundle is executed in parallel, make it sequential to ensure correct order
|
|
53
|
+
sequential: true,
|
|
54
|
+
async handler(options: OutputOptions, bundle: { [fileName: string]: OutputAsset | OutputChunk }) {
|
|
55
|
+
if (!posthogOptions.sourcemaps.enabled) return
|
|
56
|
+
const args = ['sourcemap', 'process']
|
|
57
|
+
const cliPath = posthogOptions.cliBinaryPath
|
|
58
|
+
const chunks: { [fileName: string]: OutputChunk } = {}
|
|
59
|
+
const basePaths = []
|
|
60
|
+
|
|
61
|
+
if (options.dir) {
|
|
62
|
+
basePaths.push(options.dir)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.file) {
|
|
66
|
+
basePaths.push(path.dirname(options.file))
|
|
67
|
+
}
|
|
68
|
+
|
|
53
69
|
for (const fileName in bundle) {
|
|
54
70
|
const chunk = bundle[fileName]
|
|
55
71
|
if (chunk.type === 'chunk') {
|
|
56
|
-
const chunkPath = path.resolve(
|
|
72
|
+
const chunkPath = path.resolve(...basePaths, fileName)
|
|
73
|
+
chunks[chunkPath] = chunk
|
|
57
74
|
args.push('--file', chunkPath)
|
|
58
75
|
}
|
|
59
76
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
|
|
78
|
+
if (posthogOptions.sourcemaps.project) {
|
|
79
|
+
args.push('--project', posthogOptions.sourcemaps.project)
|
|
80
|
+
}
|
|
81
|
+
if (posthogOptions.sourcemaps.version) {
|
|
82
|
+
args.push('--version', posthogOptions.sourcemaps.version)
|
|
83
|
+
}
|
|
84
|
+
if (posthogOptions.sourcemaps.deleteAfterUpload) {
|
|
85
|
+
args.push('--delete-after')
|
|
86
|
+
}
|
|
87
|
+
if (posthogOptions.sourcemaps.batchSize) {
|
|
88
|
+
args.push('--batch-size', posthogOptions.sourcemaps.batchSize.toString())
|
|
89
|
+
}
|
|
90
|
+
await spawnLocal(cliPath, args, {
|
|
91
|
+
env: {
|
|
92
|
+
...process.env,
|
|
93
|
+
RUST_LOG: `posthog_cli=${posthogOptions.logLevel}`,
|
|
94
|
+
POSTHOG_CLI_HOST: posthogOptions.host,
|
|
95
|
+
POSTHOG_CLI_TOKEN: posthogOptions.personalApiKey,
|
|
96
|
+
POSTHOG_CLI_ENV_ID: posthogOptions.envId,
|
|
97
|
+
},
|
|
98
|
+
stdio: 'inherit',
|
|
99
|
+
cwd: process.cwd(),
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// we need to update code for others plugins to work
|
|
103
|
+
await Promise.all(
|
|
104
|
+
Object.entries(chunks).map(([chunkPath, chunk]) =>
|
|
105
|
+
fs.readFile(chunkPath, 'utf8').then((content) => {
|
|
106
|
+
chunk.code = content
|
|
107
|
+
})
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
},
|
|
87
111
|
},
|
|
88
112
|
} as Plugin
|
|
89
113
|
}
|