From f88ff3ae8dde4d4c07be5025631fc4628914f462 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 24 Jun 2026 13:09:37 +0000 Subject: [PATCH 1/4] Fix #2383: @posthog/nextjs-config keeps `scss` files sourcemap when delete-after enabled --- packages/webpack-plugin/package.json | 2 +- packages/webpack-plugin/src/index.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/webpack-plugin/package.json b/packages/webpack-plugin/package.json index 8652e2b015..5c047e1e16 100644 --- a/packages/webpack-plugin/package.json +++ b/packages/webpack-plugin/package.json @@ -42,7 +42,7 @@ "lint": "eslint src", "lint:fix": "eslint src --fix", "build": "rslib build", - "test:unit": "jest --passWithNoTests", + "test:unit": "rslib build && jest --passWithNoTests", "dev": "rslib build --watch", "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz" }, diff --git a/packages/webpack-plugin/src/index.ts b/packages/webpack-plugin/src/index.ts index 6e7196e848..2ee6feb509 100644 --- a/packages/webpack-plugin/src/index.ts +++ b/packages/webpack-plugin/src/index.ts @@ -58,14 +58,20 @@ export class PosthogWebpackPlugin { return } - const filePaths: string[] = [] + const filePaths = new Set() chunkArray.forEach((chunk) => chunk.files.forEach((file) => { const chunkPath = path.resolve(outputDirectory, file) - filePaths.push(chunkPath) + filePaths.add(chunkPath) }) ) - await runSourcemapCli(config, { filePaths }) + compilation.getAssets().forEach((asset) => { + if (asset.name.endsWith('.css') && compilation.getAsset(`${asset.name}.map`)) { + filePaths.add(path.resolve(outputDirectory, asset.name)) + } + }) + + await runSourcemapCli(config, { filePaths: Array.from(filePaths) }) } } From bd6ec0921b585264f35eb69b51642ab04039725c Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 24 Jun 2026 16:04:11 +0200 Subject: [PATCH 2/4] test: cover css sourcemap asset processing --- .changeset/soft-css-sourcemaps.md | 5 ++ packages/webpack-plugin/test/index.spec.js | 63 ++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .changeset/soft-css-sourcemaps.md create mode 100644 packages/webpack-plugin/test/index.spec.js diff --git a/.changeset/soft-css-sourcemaps.md b/.changeset/soft-css-sourcemaps.md new file mode 100644 index 0000000000..c93d31fe0a --- /dev/null +++ b/.changeset/soft-css-sourcemaps.md @@ -0,0 +1,5 @@ +--- +"@posthog/webpack-plugin": patch +--- + +Include emitted CSS assets with adjacent source maps when processing webpack sourcemaps. diff --git a/packages/webpack-plugin/test/index.spec.js b/packages/webpack-plugin/test/index.spec.js new file mode 100644 index 0000000000..648e65199b --- /dev/null +++ b/packages/webpack-plugin/test/index.spec.js @@ -0,0 +1,63 @@ +const path = require('path') +const { runSourcemapCli } = require('@posthog/plugin-utils') + +jest.mock('@posthog/plugin-utils', () => ({ + runSourcemapCli: jest.fn().mockResolvedValue(undefined), +})) + +const { PosthogWebpackPlugin } = require('../dist/index.js') + +const config = { + personalApiKey: 'phx_test', + projectId: '1', + host: 'https://us.i.posthog.com', + logLevel: 'info', + cliBinaryPath: 'posthog-cli', + sourcemaps: { + enabled: true, + deleteAfterUpload: true, + }, +} + +function createCompilation(outputDirectory, chunks, assets) { + return { + outputOptions: { path: outputDirectory }, + chunks: new Set(chunks), + getAssets: () => assets, + getAsset: (name) => assets.find((asset) => asset.name === name), + } +} + +describe('PosthogWebpackPlugin', () => { + beforeEach(() => { + runSourcemapCli.mockClear() + }) + + it('passes emitted CSS assets with adjacent source maps to the sourcemap CLI', async () => { + const outputDirectory = path.resolve('/tmp/posthog-webpack-plugin') + const plugin = new PosthogWebpackPlugin(config, true) + const compilation = createCompilation( + outputDirectory, + [ + { + files: new Set(['static/chunks/app.js', 'static/chunks/app.js.map']), + }, + ], + [ + { name: 'static/css/app.css' }, + { name: 'static/css/app.css.map' }, + { name: 'static/css/no-map.css' }, + ] + ) + + await plugin.processSourceMaps(compilation, config) + + expect(runSourcemapCli).toHaveBeenCalledWith(config, { + filePaths: [ + path.resolve(outputDirectory, 'static/chunks/app.js'), + path.resolve(outputDirectory, 'static/chunks/app.js.map'), + path.resolve(outputDirectory, 'static/css/app.css'), + ], + }) + }) +}) From 8537e55319c6c6f8586c5f12323d336407f0bd37 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 24 Jun 2026 16:09:11 +0200 Subject: [PATCH 3/4] test: run webpack plugin tests from source --- packages/webpack-plugin/jest.config.mjs | 12 +++++ packages/webpack-plugin/package.json | 4 +- .../test/{index.spec.js => index.spec.ts} | 24 +++++---- packages/webpack-plugin/tsconfig.json | 3 +- pnpm-lock.yaml | 52 ++++++++++++++++++- 5 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 packages/webpack-plugin/jest.config.mjs rename packages/webpack-plugin/test/{index.spec.js => index.spec.ts} (66%) diff --git a/packages/webpack-plugin/jest.config.mjs b/packages/webpack-plugin/jest.config.mjs new file mode 100644 index 0000000000..42891d5457 --- /dev/null +++ b/packages/webpack-plugin/jest.config.mjs @@ -0,0 +1,12 @@ +import { createDefaultPreset } from 'ts-jest' + +const tsJestTransformCfg = createDefaultPreset().transform + +/** @type {import('jest').Config} **/ +export default { + testEnvironment: 'node', + testPathIgnorePatterns: ['/node_modules/', '/dist/'], + transform: { + ...tsJestTransformCfg, + }, +} diff --git a/packages/webpack-plugin/package.json b/packages/webpack-plugin/package.json index 5c047e1e16..d86f11ea3d 100644 --- a/packages/webpack-plugin/package.json +++ b/packages/webpack-plugin/package.json @@ -34,7 +34,9 @@ "devDependencies": { "@posthog-tooling/tsconfig-base": "workspace:*", "@rslib/core": "catalog:", + "@types/jest": "catalog:", "jest": "catalog:", + "ts-jest": "catalog:", "webpack": "^5" }, "scripts": { @@ -42,7 +44,7 @@ "lint": "eslint src", "lint:fix": "eslint src --fix", "build": "rslib build", - "test:unit": "rslib build && jest --passWithNoTests", + "test:unit": "jest --passWithNoTests", "dev": "rslib build --watch", "package": "pnpm pack --out $PACKAGE_DEST/%s.tgz" }, diff --git a/packages/webpack-plugin/test/index.spec.js b/packages/webpack-plugin/test/index.spec.ts similarity index 66% rename from packages/webpack-plugin/test/index.spec.js rename to packages/webpack-plugin/test/index.spec.ts index 648e65199b..8c475343d1 100644 --- a/packages/webpack-plugin/test/index.spec.js +++ b/packages/webpack-plugin/test/index.spec.ts @@ -1,13 +1,16 @@ -const path = require('path') -const { runSourcemapCli } = require('@posthog/plugin-utils') +import path from 'path' +import type webpack from 'webpack' +import { runSourcemapCli } from '@posthog/plugin-utils' +import { PosthogWebpackPlugin } from '../src/index' +import type { ResolvedPluginConfig } from '../src/config' jest.mock('@posthog/plugin-utils', () => ({ runSourcemapCli: jest.fn().mockResolvedValue(undefined), })) -const { PosthogWebpackPlugin } = require('../dist/index.js') +const runSourcemapCliMock = runSourcemapCli as jest.MockedFunction -const config = { +const config: ResolvedPluginConfig = { personalApiKey: 'phx_test', projectId: '1', host: 'https://us.i.posthog.com', @@ -19,18 +22,21 @@ const config = { }, } -function createCompilation(outputDirectory, chunks, assets) { +type TestAsset = { name: string } +type TestChunk = { files: Set } + +function createCompilation(outputDirectory: string, chunks: TestChunk[], assets: TestAsset[]): webpack.Compilation { return { outputOptions: { path: outputDirectory }, chunks: new Set(chunks), getAssets: () => assets, - getAsset: (name) => assets.find((asset) => asset.name === name), - } + getAsset: (name: string) => assets.find((asset) => asset.name === name), + } as unknown as webpack.Compilation } describe('PosthogWebpackPlugin', () => { beforeEach(() => { - runSourcemapCli.mockClear() + runSourcemapCliMock.mockClear() }) it('passes emitted CSS assets with adjacent source maps to the sourcemap CLI', async () => { @@ -52,7 +58,7 @@ describe('PosthogWebpackPlugin', () => { await plugin.processSourceMaps(compilation, config) - expect(runSourcemapCli).toHaveBeenCalledWith(config, { + expect(runSourcemapCliMock).toHaveBeenCalledWith(config, { filePaths: [ path.resolve(outputDirectory, 'static/chunks/app.js'), path.resolve(outputDirectory, 'static/chunks/app.js.map'), diff --git a/packages/webpack-plugin/tsconfig.json b/packages/webpack-plugin/tsconfig.json index 783027a2dc..8283f67fd8 100644 --- a/packages/webpack-plugin/tsconfig.json +++ b/packages/webpack-plugin/tsconfig.json @@ -9,5 +9,6 @@ "declarationMap": true, "moduleResolution": "bundler", "module": "ES6" - } + }, + "include": ["src/**/*.ts"] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 17b3005307..5b36b70795 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1598,10 +1598,16 @@ importers: version: link:../../tooling/tsconfig-base '@rslib/core': specifier: 'catalog:' - version: 0.10.6(@microsoft/api-extractor@7.55.1(@types/node@24.10.13))(typescript@5.9.3) + version: 0.10.6(@microsoft/api-extractor@7.55.1(@types/node@22.19.1))(typescript@5.8.2) + '@types/jest': + specifier: 'catalog:' + version: 29.5.14 jest: specifier: 'catalog:' - version: 29.7.0(@types/node@24.10.13)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@24.10.13)(typescript@5.9.3)) + version: 29.7.0(@types/node@22.19.1)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.19.1)(typescript@5.8.2)) + ts-jest: + specifier: 'catalog:' + version: 29.4.11(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.5))(esbuild@0.25.10)(jest-util@29.7.0)(jest@29.7.0(@types/node@22.19.1)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.19.1)(typescript@5.8.2)))(typescript@5.8.2) webpack: specifier: ^5 version: 5.102.1(esbuild@0.25.10) @@ -21487,6 +21493,15 @@ snapshots: '@microsoft/api-extractor': 7.55.1(@types/node@22.16.5) typescript: 5.8.2 + '@rslib/core@0.10.6(@microsoft/api-extractor@7.55.1(@types/node@22.19.1))(typescript@5.8.2)': + dependencies: + '@rsbuild/core': 1.4.8 + rsbuild-plugin-dts: 0.10.6(@microsoft/api-extractor@7.55.1(@types/node@22.19.1))(@rsbuild/core@1.4.8)(typescript@5.8.2) + tinyglobby: 0.2.17 + optionalDependencies: + '@microsoft/api-extractor': 7.55.1(@types/node@22.19.1) + typescript: 5.8.2 + '@rslib/core@0.10.6(@microsoft/api-extractor@7.55.1(@types/node@24.10.13))(typescript@5.8.2)': dependencies: '@rsbuild/core': 1.4.8 @@ -33298,6 +33313,18 @@ snapshots: '@microsoft/api-extractor': 7.55.1(@types/node@22.16.5) typescript: 5.8.2 + rsbuild-plugin-dts@0.10.6(@microsoft/api-extractor@7.55.1(@types/node@22.19.1))(@rsbuild/core@1.4.8)(typescript@5.8.2): + dependencies: + '@ast-grep/napi': 0.37.0 + '@rsbuild/core': 1.4.8 + magic-string: 0.30.21 + picocolors: 1.1.1 + tinyglobby: 0.2.17 + tsconfig-paths: 4.2.0 + optionalDependencies: + '@microsoft/api-extractor': 7.55.1(@types/node@22.19.1) + typescript: 5.8.2 + rsbuild-plugin-dts@0.10.6(@microsoft/api-extractor@7.55.1(@types/node@24.10.13))(@rsbuild/core@1.4.8)(typescript@5.8.2): dependencies: '@ast-grep/napi': 0.37.0 @@ -34719,6 +34746,27 @@ snapshots: esbuild: 0.25.10 jest-util: 29.7.0 + ts-jest@29.4.11(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.5))(esbuild@0.25.10)(jest-util@29.7.0)(jest@29.7.0(@types/node@22.19.1)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.19.1)(typescript@5.8.2)))(typescript@5.8.2): + dependencies: + bs-logger: 0.2.6 + fast-json-stable-stringify: 2.1.0 + handlebars: 4.7.9 + jest: 29.7.0(@types/node@22.19.1)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@22.19.1)(typescript@5.8.2)) + json5: 2.2.3 + lodash.memoize: 4.1.2 + make-error: 1.3.6 + semver: 7.8.2 + type-fest: 4.41.0 + typescript: 5.8.2 + yargs-parser: 21.1.1 + optionalDependencies: + '@babel/core': 7.28.5 + '@jest/transform': 29.7.0 + '@jest/types': 29.6.3 + babel-jest: 29.7.0(@babel/core@7.28.5) + esbuild: 0.25.10 + jest-util: 29.7.0 + ts-jest@29.4.11(@babel/core@7.28.5)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.28.5))(esbuild@0.25.10)(jest-util@29.7.0)(jest@29.7.0(@types/node@24.10.13)(node-notifier@8.0.2)(ts-node@10.9.2(@types/node@24.10.13)(typescript@5.8.2)))(typescript@5.8.2): dependencies: bs-logger: 0.2.6 From b8478a558da63b55858aacc85d2d0851f52ab498 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 24 Jun 2026 16:13:55 +0200 Subject: [PATCH 4/4] fix: include css sourcemap paths in webpack plugin --- packages/webpack-plugin/src/index.ts | 8 ++++++-- packages/webpack-plugin/test/index.spec.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/webpack-plugin/src/index.ts b/packages/webpack-plugin/src/index.ts index 2ee6feb509..6812c12d42 100644 --- a/packages/webpack-plugin/src/index.ts +++ b/packages/webpack-plugin/src/index.ts @@ -67,8 +67,12 @@ export class PosthogWebpackPlugin { ) compilation.getAssets().forEach((asset) => { - if (asset.name.endsWith('.css') && compilation.getAsset(`${asset.name}.map`)) { - filePaths.add(path.resolve(outputDirectory, asset.name)) + if (asset.name.endsWith('.css')) { + const mapAssetName = `${asset.name}.map` + if (compilation.getAsset(mapAssetName)) { + filePaths.add(path.resolve(outputDirectory, asset.name)) + filePaths.add(path.resolve(outputDirectory, mapAssetName)) + } } }) diff --git a/packages/webpack-plugin/test/index.spec.ts b/packages/webpack-plugin/test/index.spec.ts index 8c475343d1..4a8901a26f 100644 --- a/packages/webpack-plugin/test/index.spec.ts +++ b/packages/webpack-plugin/test/index.spec.ts @@ -63,6 +63,7 @@ describe('PosthogWebpackPlugin', () => { path.resolve(outputDirectory, 'static/chunks/app.js'), path.resolve(outputDirectory, 'static/chunks/app.js.map'), path.resolve(outputDirectory, 'static/css/app.css'), + path.resolve(outputDirectory, 'static/css/app.css.map'), ], }) })