@posthog/webpack-plugin 1.1.4 → 1.2.0

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.
@@ -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,EAAE,WAAW,EAAS,MAAM,SAAS,CAAA;AAI5C,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,GAAG,GAAG,IAAI;IAmBpB,iBAAiB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CA+CjG"}
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,EAAE,WAAW,EAA2C,MAAM,SAAS,CAAA;AAI9E,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,GAAG,GAAG,IAAI;IA0BpB,iBAAiB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CA2CjG"}
package/dist/index.js CHANGED
@@ -11,6 +11,9 @@ var __webpack_modules__ = {
11
11
  },
12
12
  path: function(module) {
13
13
  module.exports = require("path");
14
+ },
15
+ webpack: function(module) {
16
+ module.exports = require("webpack");
14
17
  }
15
18
  };
16
19
  var __webpack_module_cache__ = {};
@@ -61,9 +64,10 @@ var __webpack_exports__ = {};
61
64
  });
62
65
  var _posthog_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("@posthog/core");
63
66
  var _config__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./config");
64
- var _posthog_core_process__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("@posthog/core/process");
65
- var path__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("path");
66
- var path__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/ __webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_3__);
67
+ var webpack__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("webpack");
68
+ var _posthog_core_process__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("@posthog/core/process");
69
+ var path__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("path");
70
+ var path__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/ __webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_4__);
67
71
  var __WEBPACK_REEXPORT_OBJECT__ = {};
68
72
  for(var __WEBPACK_IMPORT_KEY__ in _config__WEBPACK_IMPORTED_MODULE_1__)if ([
69
73
  "default",
@@ -74,17 +78,23 @@ var __webpack_exports__ = {};
74
78
  __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
75
79
  class PosthogWebpackPlugin {
76
80
  apply(compiler) {
81
+ new webpack__WEBPACK_IMPORTED_MODULE_2__.SourceMapDevToolPlugin({
82
+ filename: '[file].map',
83
+ noSources: false,
84
+ moduleFilenameTemplate: '[resource-path]',
85
+ append: this.resolvedConfig.sourcemaps.deleteAfterUpload ? false : void 0
86
+ }).apply(compiler);
77
87
  const onDone = async (stats, callback)=>{
78
88
  callback = callback || (()=>{});
79
89
  try {
80
90
  await this.processSourceMaps(stats.compilation, this.resolvedConfig);
81
91
  } catch (error) {
82
92
  const errorMessage = error instanceof Error ? error.message : error;
83
- this.logger.error('Error running PostHog sourcemap plugin:', errorMessage);
93
+ this.logger.error('Error running PostHog webpack plugin:', errorMessage);
84
94
  }
85
95
  return callback();
86
96
  };
87
- if (compiler.hooks) compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone);
97
+ if (compiler.hooks) compiler.hooks.done.tapAsync('PosthogWebpackPlugin', onDone);
88
98
  else compiler.plugin('done', onDone);
89
99
  }
90
100
  async processSourceMaps(compilation, config) {
@@ -95,14 +105,14 @@ var __webpack_exports__ = {};
95
105
  ];
96
106
  const chunkArray = Array.from(compilation.chunks);
97
107
  if (0 == chunkArray.length) return;
98
- const filePaths = chunkArray.flatMap((chunk)=>Array.from(chunk.files).map((file)=>path__WEBPACK_IMPORTED_MODULE_3___default().resolve(outputDirectory, file)));
99
- const [commonDirectory, relativeFilePaths] = splitFilePaths(filePaths);
100
- args.push('--directory', commonDirectory);
101
- for (const chunkPath of relativeFilePaths)args.push('--include', `**/${chunkPath}`);
108
+ chunkArray.forEach((chunk)=>chunk.files.forEach((file)=>{
109
+ const chunkPath = path__WEBPACK_IMPORTED_MODULE_4___default().resolve(outputDirectory, file);
110
+ args.push('--file', chunkPath);
111
+ }));
102
112
  if (config.sourcemaps.project) args.push('--project', config.sourcemaps.project);
103
113
  if (config.sourcemaps.version) args.push('--version', config.sourcemaps.version);
104
114
  if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
105
- await (0, _posthog_core_process__WEBPACK_IMPORTED_MODULE_2__.spawnLocal)(config.cliBinaryPath, args, {
115
+ await (0, _posthog_core_process__WEBPACK_IMPORTED_MODULE_3__.spawnLocal)(config.cliBinaryPath, args, {
106
116
  cwd: process.cwd(),
107
117
  env: {
108
118
  ...process.env,
@@ -124,27 +134,6 @@ var __webpack_exports__ = {};
124
134
  function assertValue(value, message) {
125
135
  if (!value) throw new Error(message);
126
136
  }
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
137
  })();
149
138
  exports.PosthogWebpackPlugin = __webpack_exports__.PosthogWebpackPlugin;
150
139
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
package/dist/index.mjs CHANGED
@@ -1,21 +1,28 @@
1
1
  import { createLogger } from "@posthog/core";
2
2
  import { resolveConfig } from "./config.mjs";
3
+ import { SourceMapDevToolPlugin } from "webpack";
3
4
  import { spawnLocal } from "@posthog/core/process";
4
5
  import path from "path";
5
6
  export * from "./config.mjs";
6
7
  class PosthogWebpackPlugin {
7
8
  apply(compiler) {
9
+ new SourceMapDevToolPlugin({
10
+ filename: '[file].map',
11
+ noSources: false,
12
+ moduleFilenameTemplate: '[resource-path]',
13
+ append: this.resolvedConfig.sourcemaps.deleteAfterUpload ? false : void 0
14
+ }).apply(compiler);
8
15
  const onDone = async (stats, callback)=>{
9
16
  callback = callback || (()=>{});
10
17
  try {
11
18
  await this.processSourceMaps(stats.compilation, this.resolvedConfig);
12
19
  } catch (error) {
13
20
  const errorMessage = error instanceof Error ? error.message : error;
14
- this.logger.error('Error running PostHog sourcemap plugin:', errorMessage);
21
+ this.logger.error('Error running PostHog webpack plugin:', errorMessage);
15
22
  }
16
23
  return callback();
17
24
  };
18
- if (compiler.hooks) compiler.hooks.done.tapAsync('SourcemapWebpackPlugin', onDone);
25
+ if (compiler.hooks) compiler.hooks.done.tapAsync('PosthogWebpackPlugin', onDone);
19
26
  else compiler.plugin('done', onDone);
20
27
  }
21
28
  async processSourceMaps(compilation, config) {
@@ -26,10 +33,10 @@ class PosthogWebpackPlugin {
26
33
  ];
27
34
  const chunkArray = Array.from(compilation.chunks);
28
35
  if (0 == chunkArray.length) return;
29
- const filePaths = chunkArray.flatMap((chunk)=>Array.from(chunk.files).map((file)=>path.resolve(outputDirectory, file)));
30
- const [commonDirectory, relativeFilePaths] = splitFilePaths(filePaths);
31
- args.push('--directory', commonDirectory);
32
- for (const chunkPath of relativeFilePaths)args.push('--include', `**/${chunkPath}`);
36
+ chunkArray.forEach((chunk)=>chunk.files.forEach((file)=>{
37
+ const chunkPath = path.resolve(outputDirectory, file);
38
+ args.push('--file', chunkPath);
39
+ }));
33
40
  if (config.sourcemaps.project) args.push('--project', config.sourcemaps.project);
34
41
  if (config.sourcemaps.version) args.push('--version', config.sourcemaps.version);
35
42
  if (config.sourcemaps.deleteAfterUpload) args.push('--delete-after');
@@ -55,25 +62,4 @@ class PosthogWebpackPlugin {
55
62
  function assertValue(value, message) {
56
63
  if (!value) throw new Error(message);
57
64
  }
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
65
  export { PosthogWebpackPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/webpack-plugin",
3
- "version": "1.1.4",
3
+ "version": "1.2.0",
4
4
  "description": "Webpack plugin for Posthog 🦔",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "module": "./dist/index.mjs",
17
17
  "types": "./dist/index.d.ts",
18
18
  "dependencies": {
19
- "@posthog/cli": "~0.5.16",
19
+ "@posthog/cli": "~0.5.17",
20
20
  "@posthog/core": "1.7.1"
21
21
  },
22
22
  "files": [
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 { Compilation, Stats } from 'webpack'
3
+ import { Compilation, Stats, SourceMapDevToolPlugin, Compiler } from 'webpack'
4
4
  import { spawnLocal } from '@posthog/core/process'
5
5
  import path from 'path'
6
6
 
@@ -24,19 +24,26 @@ export class PosthogWebpackPlugin {
24
24
  }
25
25
 
26
26
  apply(compiler: any): void {
27
+ new SourceMapDevToolPlugin({
28
+ filename: '[file].map',
29
+ noSources: false,
30
+ moduleFilenameTemplate: '[resource-path]',
31
+ append: this.resolvedConfig.sourcemaps.deleteAfterUpload ? false : undefined,
32
+ }).apply(compiler)
33
+
27
34
  const onDone = async (stats: 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 sourcemap plugin:', errorMessage)
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('SourcemapWebpackPlugin', onDone)
46
+ compiler.hooks.done.tapAsync('PosthogWebpackPlugin', onDone)
40
47
  } else {
41
48
  compiler.plugin('done', onDone)
42
49
  }
@@ -54,16 +61,12 @@ export class PosthogWebpackPlugin {
54
61
  return
55
62
  }
56
63
 
57
- const filePaths = chunkArray.flatMap((chunk) =>
58
- Array.from(chunk.files).map((file) => path.resolve(outputDirectory, file))
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
- }