@posthog/webpack-plugin 1.1.4 → 1.2.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/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -28
- package/dist/index.mjs +13 -28
- package/package.json +6 -3
- package/src/index.ts +19 -49
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Logger } from '@posthog/core';
|
|
2
2
|
import { PluginConfig, ResolvedPluginConfig } from './config';
|
|
3
|
-
import
|
|
3
|
+
import webpack from 'webpack';
|
|
4
4
|
export * from './config';
|
|
5
5
|
export declare class PosthogWebpackPlugin {
|
|
6
6
|
resolvedConfig: ResolvedPluginConfig;
|
|
7
7
|
logger: Logger;
|
|
8
8
|
constructor(pluginConfig: PluginConfig);
|
|
9
|
-
apply(compiler:
|
|
10
|
-
processSourceMaps(compilation: Compilation, config: ResolvedPluginConfig): Promise<void>;
|
|
9
|
+
apply(compiler: webpack.Compiler): void;
|
|
10
|
+
processSourceMaps(compilation: webpack.Compilation, config: ResolvedPluginConfig): Promise<void>;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
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,EAAE,MAAM,EAAgB,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,YAAY,EAAiB,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAgB,MAAM,eAAe,CAAA;AACpD,OAAO,EAAE,YAAY,EAAiB,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAC5E,OAAO,OAAO,MAAM,SAAS,CAAA;AAI7B,cAAc,UAAU,CAAA;AAExB,qBAAa,oBAAoB;IAC7B,cAAc,EAAE,oBAAoB,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;gBAEF,YAAY,EAAE,YAAY;IAatC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,QAAQ,GAAG,IAAI;IA0BjC,iBAAiB,CAAC,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CA2CzG"}
|
package/dist/index.js
CHANGED
|
@@ -74,18 +74,24 @@ var __webpack_exports__ = {};
|
|
|
74
74
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
75
75
|
class PosthogWebpackPlugin {
|
|
76
76
|
apply(compiler) {
|
|
77
|
+
new compiler.webpack.SourceMapDevToolPlugin({
|
|
78
|
+
filename: '[file].map',
|
|
79
|
+
noSources: false,
|
|
80
|
+
moduleFilenameTemplate: '[resource-path]',
|
|
81
|
+
append: this.resolvedConfig.sourcemaps.deleteAfterUpload ? false : void 0
|
|
82
|
+
}).apply(compiler);
|
|
77
83
|
const onDone = async (stats, callback)=>{
|
|
78
84
|
callback = callback || (()=>{});
|
|
79
85
|
try {
|
|
80
86
|
await this.processSourceMaps(stats.compilation, this.resolvedConfig);
|
|
81
87
|
} catch (error) {
|
|
82
88
|
const errorMessage = error instanceof Error ? error.message : error;
|
|
83
|
-
this.logger.error('Error running PostHog
|
|
89
|
+
this.logger.error('Error running PostHog webpack plugin:', errorMessage);
|
|
84
90
|
}
|
|
85
91
|
return callback();
|
|
86
92
|
};
|
|
87
|
-
if (compiler.hooks) compiler.hooks.done.tapAsync('
|
|
88
|
-
else
|
|
93
|
+
if (compiler.hooks) compiler.hooks.done.tapAsync('PosthogWebpackPlugin', onDone);
|
|
94
|
+
else throw new Error('PosthogWebpackPlugin is not compatible with webpack version < 5');
|
|
89
95
|
}
|
|
90
96
|
async processSourceMaps(compilation, config) {
|
|
91
97
|
const outputDirectory = compilation.outputOptions.path;
|
|
@@ -95,10 +101,10 @@ var __webpack_exports__ = {};
|
|
|
95
101
|
];
|
|
96
102
|
const chunkArray = Array.from(compilation.chunks);
|
|
97
103
|
if (0 == chunkArray.length) return;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
chunkArray.forEach((chunk)=>chunk.files.forEach((file)=>{
|
|
105
|
+
const chunkPath = path__WEBPACK_IMPORTED_MODULE_3___default().resolve(outputDirectory, file);
|
|
106
|
+
args.push('--file', chunkPath);
|
|
107
|
+
}));
|
|
102
108
|
if (config.sourcemaps.project) args.push('--project', config.sourcemaps.project);
|
|
103
109
|
if (config.sourcemaps.version) args.push('--version', config.sourcemaps.version);
|
|
104
110
|
if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
|
|
@@ -124,27 +130,6 @@ var __webpack_exports__ = {};
|
|
|
124
130
|
function assertValue(value, message) {
|
|
125
131
|
if (!value) throw new Error(message);
|
|
126
132
|
}
|
|
127
|
-
function splitFilePaths(absolutePaths) {
|
|
128
|
-
if (!absolutePaths || 0 === absolutePaths.length) return [
|
|
129
|
-
process.cwd(),
|
|
130
|
-
[]
|
|
131
|
-
];
|
|
132
|
-
let commonDir = path__WEBPACK_IMPORTED_MODULE_3___default().dirname(absolutePaths[0]);
|
|
133
|
-
const isCommonAncestor = (candidate)=>absolutePaths.every((p)=>{
|
|
134
|
-
const rel = path__WEBPACK_IMPORTED_MODULE_3___default().relative(candidate, p);
|
|
135
|
-
return '' === rel || !rel.startsWith('..') && !path__WEBPACK_IMPORTED_MODULE_3___default().isAbsolute(rel);
|
|
136
|
-
});
|
|
137
|
-
while(!isCommonAncestor(commonDir)){
|
|
138
|
-
const parent = path__WEBPACK_IMPORTED_MODULE_3___default().dirname(commonDir);
|
|
139
|
-
if (parent === commonDir) break;
|
|
140
|
-
commonDir = parent;
|
|
141
|
-
}
|
|
142
|
-
const relativePaths = absolutePaths.map((p)=>path__WEBPACK_IMPORTED_MODULE_3___default().relative(commonDir, p).replace(/\\/g, '/'));
|
|
143
|
-
return [
|
|
144
|
-
commonDir,
|
|
145
|
-
relativePaths
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
133
|
})();
|
|
149
134
|
exports.PosthogWebpackPlugin = __webpack_exports__.PosthogWebpackPlugin;
|
|
150
135
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
package/dist/index.mjs
CHANGED
|
@@ -5,18 +5,24 @@ import path from "path";
|
|
|
5
5
|
export * from "./config.mjs";
|
|
6
6
|
class PosthogWebpackPlugin {
|
|
7
7
|
apply(compiler) {
|
|
8
|
+
new compiler.webpack.SourceMapDevToolPlugin({
|
|
9
|
+
filename: '[file].map',
|
|
10
|
+
noSources: false,
|
|
11
|
+
moduleFilenameTemplate: '[resource-path]',
|
|
12
|
+
append: this.resolvedConfig.sourcemaps.deleteAfterUpload ? false : void 0
|
|
13
|
+
}).apply(compiler);
|
|
8
14
|
const onDone = async (stats, callback)=>{
|
|
9
15
|
callback = callback || (()=>{});
|
|
10
16
|
try {
|
|
11
17
|
await this.processSourceMaps(stats.compilation, this.resolvedConfig);
|
|
12
18
|
} catch (error) {
|
|
13
19
|
const errorMessage = error instanceof Error ? error.message : error;
|
|
14
|
-
this.logger.error('Error running PostHog
|
|
20
|
+
this.logger.error('Error running PostHog webpack plugin:', errorMessage);
|
|
15
21
|
}
|
|
16
22
|
return callback();
|
|
17
23
|
};
|
|
18
|
-
if (compiler.hooks) compiler.hooks.done.tapAsync('
|
|
19
|
-
else
|
|
24
|
+
if (compiler.hooks) compiler.hooks.done.tapAsync('PosthogWebpackPlugin', onDone);
|
|
25
|
+
else throw new Error('PosthogWebpackPlugin is not compatible with webpack version < 5');
|
|
20
26
|
}
|
|
21
27
|
async processSourceMaps(compilation, config) {
|
|
22
28
|
const outputDirectory = compilation.outputOptions.path;
|
|
@@ -26,10 +32,10 @@ class PosthogWebpackPlugin {
|
|
|
26
32
|
];
|
|
27
33
|
const chunkArray = Array.from(compilation.chunks);
|
|
28
34
|
if (0 == chunkArray.length) return;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
chunkArray.forEach((chunk)=>chunk.files.forEach((file)=>{
|
|
36
|
+
const chunkPath = path.resolve(outputDirectory, file);
|
|
37
|
+
args.push('--file', chunkPath);
|
|
38
|
+
}));
|
|
33
39
|
if (config.sourcemaps.project) args.push('--project', config.sourcemaps.project);
|
|
34
40
|
if (config.sourcemaps.version) args.push('--version', config.sourcemaps.version);
|
|
35
41
|
if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
|
|
@@ -55,25 +61,4 @@ class PosthogWebpackPlugin {
|
|
|
55
61
|
function assertValue(value, message) {
|
|
56
62
|
if (!value) throw new Error(message);
|
|
57
63
|
}
|
|
58
|
-
function splitFilePaths(absolutePaths) {
|
|
59
|
-
if (!absolutePaths || 0 === absolutePaths.length) return [
|
|
60
|
-
process.cwd(),
|
|
61
|
-
[]
|
|
62
|
-
];
|
|
63
|
-
let commonDir = path.dirname(absolutePaths[0]);
|
|
64
|
-
const isCommonAncestor = (candidate)=>absolutePaths.every((p)=>{
|
|
65
|
-
const rel = path.relative(candidate, p);
|
|
66
|
-
return '' === rel || !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
67
|
-
});
|
|
68
|
-
while(!isCommonAncestor(commonDir)){
|
|
69
|
-
const parent = path.dirname(commonDir);
|
|
70
|
-
if (parent === commonDir) break;
|
|
71
|
-
commonDir = parent;
|
|
72
|
-
}
|
|
73
|
-
const relativePaths = absolutePaths.map((p)=>path.relative(commonDir, p).replace(/\\/g, '/'));
|
|
74
|
-
return [
|
|
75
|
-
commonDir,
|
|
76
|
-
relativePaths
|
|
77
|
-
];
|
|
78
|
-
}
|
|
79
64
|
export { PosthogWebpackPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/webpack-plugin",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Webpack plugin for Posthog 🦔",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,17 +16,20 @@
|
|
|
16
16
|
"module": "./dist/index.mjs",
|
|
17
17
|
"types": "./dist/index.d.ts",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@posthog/cli": "~0.5.
|
|
19
|
+
"@posthog/cli": "~0.5.17",
|
|
20
20
|
"@posthog/core": "1.7.1"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
23
23
|
"dist",
|
|
24
24
|
"src"
|
|
25
25
|
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"webpack": "^5"
|
|
28
|
+
},
|
|
26
29
|
"devDependencies": {
|
|
27
30
|
"@rslib/core": "0.10.6",
|
|
28
31
|
"jest": "29.7.0",
|
|
29
|
-
"webpack": "^5
|
|
32
|
+
"webpack": "^5",
|
|
30
33
|
"@posthog-tooling/tsconfig-base": "1.1.1"
|
|
31
34
|
},
|
|
32
35
|
"exports": {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Logger, createLogger } from '@posthog/core'
|
|
2
2
|
import { PluginConfig, resolveConfig, ResolvedPluginConfig } from './config'
|
|
3
|
-
import
|
|
3
|
+
import webpack from 'webpack'
|
|
4
4
|
import { spawnLocal } from '@posthog/core/process'
|
|
5
5
|
import path from 'path'
|
|
6
6
|
|
|
@@ -23,26 +23,33 @@ export class PosthogWebpackPlugin {
|
|
|
23
23
|
)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
apply(compiler:
|
|
27
|
-
|
|
26
|
+
apply(compiler: webpack.Compiler): void {
|
|
27
|
+
new compiler.webpack.SourceMapDevToolPlugin({
|
|
28
|
+
filename: '[file].map',
|
|
29
|
+
noSources: false,
|
|
30
|
+
moduleFilenameTemplate: '[resource-path]',
|
|
31
|
+
append: this.resolvedConfig.sourcemaps.deleteAfterUpload ? false : undefined,
|
|
32
|
+
}).apply(compiler)
|
|
33
|
+
|
|
34
|
+
const onDone = async (stats: webpack.Stats, callback: any): Promise<void> => {
|
|
28
35
|
callback = callback || (() => {})
|
|
29
36
|
try {
|
|
30
37
|
await this.processSourceMaps(stats.compilation, this.resolvedConfig)
|
|
31
38
|
} catch (error) {
|
|
32
39
|
const errorMessage = error instanceof Error ? error.message : error
|
|
33
|
-
this.logger.error('Error running PostHog
|
|
40
|
+
this.logger.error('Error running PostHog webpack plugin:', errorMessage)
|
|
34
41
|
}
|
|
35
42
|
return callback()
|
|
36
43
|
}
|
|
37
44
|
|
|
38
45
|
if (compiler.hooks) {
|
|
39
|
-
compiler.hooks.done.tapAsync('
|
|
46
|
+
compiler.hooks.done.tapAsync('PosthogWebpackPlugin', onDone)
|
|
40
47
|
} else {
|
|
41
|
-
|
|
48
|
+
throw new Error('PosthogWebpackPlugin is not compatible with webpack version < 5')
|
|
42
49
|
}
|
|
43
50
|
}
|
|
44
51
|
|
|
45
|
-
async processSourceMaps(compilation: Compilation, config: ResolvedPluginConfig): Promise<void> {
|
|
52
|
+
async processSourceMaps(compilation: webpack.Compilation, config: ResolvedPluginConfig): Promise<void> {
|
|
46
53
|
const outputDirectory = compilation.outputOptions.path
|
|
47
54
|
|
|
48
55
|
// chunks are output outside of the output directory for server chunks
|
|
@@ -54,16 +61,12 @@ export class PosthogWebpackPlugin {
|
|
|
54
61
|
return
|
|
55
62
|
}
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
chunkArray.forEach((chunk) =>
|
|
65
|
+
chunk.files.forEach((file) => {
|
|
66
|
+
const chunkPath = path.resolve(outputDirectory, file)
|
|
67
|
+
args.push('--file', chunkPath)
|
|
68
|
+
})
|
|
59
69
|
)
|
|
60
|
-
const [commonDirectory, relativeFilePaths] = splitFilePaths(filePaths)
|
|
61
|
-
|
|
62
|
-
args.push('--directory', commonDirectory)
|
|
63
|
-
|
|
64
|
-
for (const chunkPath of relativeFilePaths) {
|
|
65
|
-
args.push('--include', `**/${chunkPath}`)
|
|
66
|
-
}
|
|
67
70
|
|
|
68
71
|
if (config.sourcemaps.project) {
|
|
69
72
|
args.push('--project', config.sourcemaps.project)
|
|
@@ -96,36 +99,3 @@ function assertValue(value: any, message: string): void {
|
|
|
96
99
|
throw new Error(message)
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
|
-
|
|
100
|
-
// Convert a list of absolute file path to a common absolute directory ancestor path and relative path
|
|
101
|
-
function splitFilePaths(absolutePaths: string[]): [string, string[]] {
|
|
102
|
-
if (!absolutePaths || absolutePaths.length === 0) {
|
|
103
|
-
return [process.cwd(), []]
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Start with the directory of the first path and walk up until we find a common ancestor
|
|
107
|
-
let commonDir = path.dirname(absolutePaths[0])
|
|
108
|
-
|
|
109
|
-
const isCommonAncestor = (candidate: string): boolean => {
|
|
110
|
-
return absolutePaths.every((p) => {
|
|
111
|
-
const rel = path.relative(candidate, p)
|
|
112
|
-
// If rel starts with '..' or is absolute, p is not inside candidate
|
|
113
|
-
return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel))
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// If the first candidate isn't a common ancestor, walk up the directory tree
|
|
118
|
-
while (!isCommonAncestor(commonDir)) {
|
|
119
|
-
const parent = path.dirname(commonDir)
|
|
120
|
-
if (parent === commonDir) {
|
|
121
|
-
// reached filesystem root
|
|
122
|
-
break
|
|
123
|
-
}
|
|
124
|
-
commonDir = parent
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Compute relative paths from the common directory, normalize to forward slashes for globs
|
|
128
|
-
const relativePaths = absolutePaths.map((p) => path.relative(commonDir, p).replace(/\\/g, '/'))
|
|
129
|
-
|
|
130
|
-
return [commonDir, relativePaths]
|
|
131
|
-
}
|