feat(devex): minimal pnpm workspaces (#28269)

This commit is contained in:
Marius Andra
2025-02-05 12:32:11 +01:00
committed by GitHub
parent a0a3032e2e
commit b83fcf0b7e
26 changed files with 25355 additions and 30187 deletions

View File

@@ -4,7 +4,7 @@
!.storybook
!babel.config.js
!bin
!common/hogvm/python
!common/hogvm
!common/plugin_transpiler/*.*
!common/plugin_transpiler/src
!dags
@@ -28,6 +28,7 @@
!plugin-server/tsconfig.eslint.json
!plugin-server/tsconfig.json
!pnpm-lock.yaml
!pnpm-workspace.yaml
!posthog
!posthog.json
!products

View File

@@ -90,7 +90,7 @@ runs:
shell: bash
run: |
cd common/plugin_transpiler
pnpm install
pnpm --filter=@posthog/plugin-transpiler install --frozen-lockfile
pnpm run build
- name: Install Python dependencies

View File

@@ -143,7 +143,7 @@ jobs:
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.shouldTriggerCypress == 'true'
run: pnpm install --frozen-lockfile
run: pnpm --filter=@posthog/frontend install --frozen-lockfile
- name: Stop/Start stack with Docker Compose
# these are required checks so, we can't skip entire sections

View File

@@ -84,7 +84,7 @@ jobs:
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.frontend == 'true'
run: pnpm install --frozen-lockfile
run: pnpm --filter=@posthog/frontend install --frozen-lockfile
- name: Check formatting with prettier
if: needs.changes.outputs.frontend == 'true'
@@ -153,7 +153,7 @@ jobs:
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.frontend == 'true'
run: pnpm install --frozen-lockfile
run: pnpm --filter=@posthog/frontend install --frozen-lockfile
- name: Test with Jest
# set maxWorkers or Jest only uses 1 CPU in GitHub Actions

View File

@@ -125,15 +125,14 @@ jobs:
- name: Run HogVM TypeScript tests
run: |
cd common/hogvm/typescript
pnpm install --frozen-lockfile
pnpm run test
pnpm --filter=@posthog/hogvm install --frozen-lockfile
pnpm --filter=@posthog/hogvm test
- name: Run Hog tests
run: |
cd common/hogvm/typescript
pnpm run build
cd ../
pnpm --filter=@posthog/hogvm install --frozen-lockfile
pnpm --filter=@posthog/hogvm build
cd common/hogvm
./test.sh && git diff --exit-code
check-package-version:
@@ -191,7 +190,7 @@ jobs:
node-version: 18
registry-url: https://registry.npmjs.org
- name: Install package.json dependencies
run: cd common/hogvm/typescript && pnpm install
run: pnpm --filter=@posthog/hogvm install --frozen-lockfile
- name: Publish the package in the npm registry
run: cd common/hogvm/typescript && npm publish --access public
env:
@@ -270,13 +269,13 @@ jobs:
mv package.json package.old.json
jq --indent 4 '.dependencies."@posthog/hogvm" = "^'$VERSION'"' package.old.json > package.json
rm package.old.json
retry_pnpm_install
# Update plugin-server/package.json
cd plugin-server
mv package.json package.old.json
jq --indent 4 '.dependencies."@posthog/hogvm" = "^'$VERSION'"' package.old.json > package.json
rm package.old.json
retry_pnpm_install
- name: Commit updated package.json files

View File

@@ -70,7 +70,11 @@ jobs:
cache: pnpm
- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile
run: |
npm install -g husky@7 # until we make <root>/package.json a build package
pnpm --filter=@posthog/cyclotron install --frozen-lockfile
pnpm --filter=@posthog/cyclotron build
pnpm --filter=@posthog/plugin-server install --frozen-lockfile
- name: Check formatting with prettier
run: pnpm prettier:check
@@ -161,11 +165,15 @@ jobs:
with:
node-version: 18.12.1
cache: pnpm
cache-dependency-path: plugin-server/pnpm-lock.yaml
cache-dependency-path: pnpm-lock.yaml
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.plugin-server == 'true'
run: cd plugin-server && pnpm i
run: |
cd plugin-server
npm install -g husky@7 # until we make <root>/package.json a build package
pnpm --filter=@posthog/plugin-server... install --frozen-lockfile
pnpm --filter=@posthog/cyclotron build
- name: Wait for Clickhouse, Redis & Kafka
if: needs.changes.outputs.plugin-server == 'true'
@@ -253,13 +261,15 @@ jobs:
with:
node-version: 18.12.1
cache: pnpm
cache-dependency-path: plugin-server/pnpm-lock.yaml
cache-dependency-path: pnpm-lock.yaml
- name: Install package.json dependencies with pnpm
if: needs.changes.outputs.plugin-server == 'true'
run: |
cd plugin-server
pnpm install --frozen-lockfile
npm install -g husky@7 # until we make <root>/package.json a build package
pnpm --filter=@posthog/plugin-server... install --frozen-lockfile
pnpm --filter=@posthog/cyclotron build
pnpm build
- name: Wait for Clickhouse, Redis & Kafka

View File

@@ -38,7 +38,7 @@ jobs:
cache: pnpm
- name: Install dependencies and Chromatic
run: pnpm i -D chromatic
run: pnpm i -w -D chromatic
- name: Publish to Chromatic
uses: chromaui/action@v11
@@ -115,10 +115,10 @@ jobs:
cache: pnpm
- name: Install package.json dependencies with pnpm
run: pnpm install --frozen-lockfile
run: pnpm --filter=@posthog/frontend install --frozen-lockfile
- name: Install CI utilities with pnpm
run: pnpm install http-server wait-on
run: pnpm install http-server wait-on -g
- name: Build Storybook
run: pnpm build-storybook --test --quiet # Silence since progress logging results in a massive wall of spam

1
.gitignore vendored
View File

@@ -15,6 +15,7 @@ __pycache__/
.eslintcache
.idea
.mypy_cache
.parcel-cache
# pyenv local config
.python-version
.temp-deepeval-cache.json

View File

@@ -25,12 +25,11 @@ FROM node:18.19.1-bookworm-slim AS frontend-build
WORKDIR /code
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
COPY package.json pnpm-lock.yaml ./
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY patches/ patches/
RUN corepack enable && pnpm --version && \
mkdir /tmp/pnpm-store && \
pnpm install --frozen-lockfile --store-dir /tmp/pnpm-store --prod && \
rm -rf /tmp/pnpm-store
RUN --mount=type=cache,id=pnpm,target=/tmp/pnpm-store \
corepack enable && pnpm --version && \
pnpm --filter=@posthog/frontend install --frozen-lockfile --store-dir /tmp/pnpm-store --prod
COPY frontend/ frontend/
COPY products/ products/
@@ -43,15 +42,8 @@ RUN pnpm build
# ---------------------------------------------------------
#
FROM ghcr.io/posthog/rust-node-container:bookworm_rust_1.80.1-node_18.19.1 AS plugin-server-build
WORKDIR /code
COPY ./rust ./rust
COPY ./common/plugin_transpiler/ ./common/plugin_transpiler/
WORKDIR /code/plugin-server
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
# Compile and install Node.js dependencies.
COPY ./plugin-server/package.json ./plugin-server/pnpm-lock.yaml ./plugin-server/tsconfig.json ./
COPY ./plugin-server/patches/ ./patches/
# Compile and install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
"make" \
@@ -61,14 +53,26 @@ RUN apt-get update && \
"libssl-dev" \
"zlib1g-dev" \
&& \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/lib/apt/lists/*
WORKDIR /code
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY ./patches ./patches
COPY ./rust ./rust
COPY ./common/plugin_transpiler/ ./common/plugin_transpiler/
COPY ./common/hogvm/typescript/ ./common/hogvm/typescript/
COPY ./plugin-server/package.json ./plugin-server/tsconfig.json ./plugin-server/
SHELL ["/bin/bash", "-e", "-o", "pipefail", "-c"]
# Compile and install Node.js dependencies.
# NOTE: we don't actually use the plugin-transpiler with the plugin-server, it's just here for the build.
RUN --mount=type=cache,id=pnpm,target=/tmp/pnpm-store \
corepack enable && \
mkdir /tmp/pnpm-store && \
pnpm install --frozen-lockfile --store-dir /tmp/pnpm-store && \
cd ../common/plugin_transpiler && \
pnpm install --frozen-lockfile --store-dir /tmp/pnpm-store && \
pnpm build && \
rm -rf /tmp/pnpm-store
pnpm --filter=@posthog/plugin-server install --frozen-lockfile --store-dir /tmp/pnpm-store && \
pnpm --filter=@posthog/plugin-transpiler install --frozen-lockfile --store-dir /tmp/pnpm-store && \
pnpm --filter=@posthog/plugin-transpiler build
WORKDIR /code/plugin-server
# Build the plugin server.
#
@@ -76,7 +80,14 @@ RUN apt-get update && \
# the cache hit ratio of the layers above.
COPY ./plugin-server/src/ ./src/
COPY ./plugin-server/tests/ ./tests/
RUN pnpm build
RUN pnpm run build:cyclotron && pnpm build
# As the plugin-server is now built, lets keep
# only prod dependencies in the node_module folder
# as we will copy it to the last image.
RUN --mount=type=cache,id=pnpm,target=/tmp/pnpm-store \
corepack enable && \
pnpm --filter=@posthog/plugin-server install --frozen-lockfile --store-dir /tmp/pnpm-store --prod
#
# ---------------------------------------------------------
@@ -184,8 +195,12 @@ ARG COMMIT_HASH
RUN echo $COMMIT_HASH > /code/commit.txt
# Add in the compiled plugin-server & its runtime dependencies from the plugin-server-build stage.
COPY --from=plugin-server-build --chown=posthog:posthog /code/rust/cyclotron-node/dist /code/rust/cyclotron-node/dist
COPY --from=plugin-server-build --chown=posthog:posthog /code/rust/cyclotron-node/package.json /code/rust/cyclotron-node/package.json
COPY --from=plugin-server-build --chown=posthog:posthog /code/rust/cyclotron-node/index.node /code/rust/cyclotron-node/index.node
COPY --from=plugin-server-build --chown=posthog:posthog /code/common/plugin_transpiler/dist /code/common/plugin_transpiler/dist
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/dist /code/plugin-server/dist
COPY --from=plugin-server-build --chown=posthog:posthog /code/node_modules /code/node_modules
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/node_modules /code/plugin-server/node_modules
COPY --from=plugin-server-build --chown=posthog:posthog /code/plugin-server/package.json /code/plugin-server/package.json

View File

@@ -4,7 +4,7 @@ set -e
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
# NOTE when running in docker, rust might not exist so we need to check for it
if [ -d "$SCRIPT_DIR/../rust" ]; then
if [ -d "$SCRIPT_DIR/../rust/bin" ]; then
bash $SCRIPT_DIR/../rust/bin/migrate-cyclotron
fi

View File

@@ -38,7 +38,7 @@ cd plugin-server
if [[ -n $DEBUG ]]; then
echo "🧐 Verifying installed packages..."
pnpm i --frozen-lockfile
pnpm --filter=@posthog/plugin-server i --frozen-lockfile
fi
if [ $? -ne 0 ]; then

View File

@@ -0,0 +1,9 @@
{
"extends": "@parcel/config-default",
"transformers": {
"*.{js,mjs,jsx,cjs,ts,tsx}": [
"@parcel/transformer-js",
"@parcel/transformer-react-refresh-wrap"
]
}
}

View File

@@ -6,7 +6,6 @@
"source": "src/index.ts",
"main": "dist/index.js",
"module": "dist/module.js",
"packageManager": "pnpm@8.3.1",
"scripts": {
"test": "jest --runInBand --forceExit",
"clean": "rm -rf dist .parcel-cache",
@@ -24,16 +23,19 @@
"repository": "https://github.com/PostHog/posthog-plugin-server",
"license": "MIT",
"devDependencies": {
"@parcel/packager-ts": "2.12.0",
"@parcel/transformer-typescript-types": "2.12.0",
"@parcel/packager-ts": "2.13.3",
"@parcel/transformer-typescript-types": "2.13.3",
"@parcel/config-default": "2.13.3",
"@parcel/transformer-js": "2.13.3",
"@parcel/transformer-react-refresh-wrap": "2.13.3",
"@swc-node/register": "^1.9.1",
"@swc/core": "^1.5.7",
"@swc/jest": "^0.2.36",
"@types/luxon": "^3.4.2",
"@types/node": "^20.14.2",
"@types/node": "^18.11.9",
"crypto-browserify": "^3.12.0",
"jest": "^28.1.1",
"parcel": "^2.12.0",
"parcel": "^2.13.3",
"prettier": "^3.2.5",
"re2": "^1.21.3",
"typescript": "^5.4.5"

File diff suppressed because it is too large Load Diff

View File

@@ -158,7 +158,7 @@ export class HogQLPrinter {
this.indentLevel += 1
let result: string
const nodeType = node.get('__hx_ast') as string
const nodeType = node?.get('__hx_ast') as string | undefined
if (!nodeType) {
throw new Error('Node type is missing or undefined.')

View File

@@ -1,5 +1,5 @@
{
"name": "plugin_transpiler",
"name": "@posthog/plugin-transpiler",
"version": "1.0.0",
"description": "Transpiles site apps TSX to browser JS via stdin/stdout",
"main": "transpile.mjs",

View File

@@ -1,367 +0,0 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
devDependencies:
'@babel/standalone':
specifier: ^7.23.2
version: 7.26.7
'@types/babel__standalone':
specifier: ^7.1.6
version: 7.1.9
'@types/node':
specifier: ^18.11.9
version: 18.19.75
esbuild:
specifier: ^0.19.5
version: 0.19.12
typescript:
specifier: ^5.2.2
version: 5.7.3
packages:
'@babel/helper-string-parser@7.25.9':
resolution: {integrity: sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==}
engines: {node: '>=6.9.0'}
'@babel/helper-validator-identifier@7.25.9':
resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==}
engines: {node: '>=6.9.0'}
'@babel/parser@7.26.7':
resolution: {integrity: sha512-kEvgGGgEjRUutvdVvZhbn/BxVt+5VSpwXz1j3WYXQbXDo8KzFOPNG2GQbdAiNq8g6wn1yKk7C/qrke03a84V+w==}
engines: {node: '>=6.0.0'}
hasBin: true
'@babel/standalone@7.26.7':
resolution: {integrity: sha512-Fvdo9Dd20GDUAREzYMIR2EFMKAJ+ccxstgQdb39XV/yvygHL4UPcqgTkiChPyltAe/b+zgq+vUPXeukEZ6aUeA==}
engines: {node: '>=6.9.0'}
'@babel/types@7.26.7':
resolution: {integrity: sha512-t8kDRGrKXyp6+tjUh7hw2RLyclsW4TRoRvRHtSyAX9Bb5ldlFh+90YAYY6awRXrlB4G5G2izNeGySpATlFzmOg==}
engines: {node: '>=6.9.0'}
'@esbuild/aix-ppc64@0.19.12':
resolution: {integrity: sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==}
engines: {node: '>=12'}
cpu: [ppc64]
os: [aix]
'@esbuild/android-arm64@0.19.12':
resolution: {integrity: sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==}
engines: {node: '>=12'}
cpu: [arm64]
os: [android]
'@esbuild/android-arm@0.19.12':
resolution: {integrity: sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==}
engines: {node: '>=12'}
cpu: [arm]
os: [android]
'@esbuild/android-x64@0.19.12':
resolution: {integrity: sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==}
engines: {node: '>=12'}
cpu: [x64]
os: [android]
'@esbuild/darwin-arm64@0.19.12':
resolution: {integrity: sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==}
engines: {node: '>=12'}
cpu: [arm64]
os: [darwin]
'@esbuild/darwin-x64@0.19.12':
resolution: {integrity: sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==}
engines: {node: '>=12'}
cpu: [x64]
os: [darwin]
'@esbuild/freebsd-arm64@0.19.12':
resolution: {integrity: sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==}
engines: {node: '>=12'}
cpu: [arm64]
os: [freebsd]
'@esbuild/freebsd-x64@0.19.12':
resolution: {integrity: sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==}
engines: {node: '>=12'}
cpu: [x64]
os: [freebsd]
'@esbuild/linux-arm64@0.19.12':
resolution: {integrity: sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==}
engines: {node: '>=12'}
cpu: [arm64]
os: [linux]
'@esbuild/linux-arm@0.19.12':
resolution: {integrity: sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==}
engines: {node: '>=12'}
cpu: [arm]
os: [linux]
'@esbuild/linux-ia32@0.19.12':
resolution: {integrity: sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==}
engines: {node: '>=12'}
cpu: [ia32]
os: [linux]
'@esbuild/linux-loong64@0.19.12':
resolution: {integrity: sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==}
engines: {node: '>=12'}
cpu: [loong64]
os: [linux]
'@esbuild/linux-mips64el@0.19.12':
resolution: {integrity: sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==}
engines: {node: '>=12'}
cpu: [mips64el]
os: [linux]
'@esbuild/linux-ppc64@0.19.12':
resolution: {integrity: sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==}
engines: {node: '>=12'}
cpu: [ppc64]
os: [linux]
'@esbuild/linux-riscv64@0.19.12':
resolution: {integrity: sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==}
engines: {node: '>=12'}
cpu: [riscv64]
os: [linux]
'@esbuild/linux-s390x@0.19.12':
resolution: {integrity: sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==}
engines: {node: '>=12'}
cpu: [s390x]
os: [linux]
'@esbuild/linux-x64@0.19.12':
resolution: {integrity: sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==}
engines: {node: '>=12'}
cpu: [x64]
os: [linux]
'@esbuild/netbsd-x64@0.19.12':
resolution: {integrity: sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==}
engines: {node: '>=12'}
cpu: [x64]
os: [netbsd]
'@esbuild/openbsd-x64@0.19.12':
resolution: {integrity: sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==}
engines: {node: '>=12'}
cpu: [x64]
os: [openbsd]
'@esbuild/sunos-x64@0.19.12':
resolution: {integrity: sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==}
engines: {node: '>=12'}
cpu: [x64]
os: [sunos]
'@esbuild/win32-arm64@0.19.12':
resolution: {integrity: sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==}
engines: {node: '>=12'}
cpu: [arm64]
os: [win32]
'@esbuild/win32-ia32@0.19.12':
resolution: {integrity: sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==}
engines: {node: '>=12'}
cpu: [ia32]
os: [win32]
'@esbuild/win32-x64@0.19.12':
resolution: {integrity: sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==}
engines: {node: '>=12'}
cpu: [x64]
os: [win32]
'@types/babel__core@7.20.5':
resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==}
'@types/babel__generator@7.6.8':
resolution: {integrity: sha512-ASsj+tpEDsEiFr1arWrlN6V3mdfjRMZt6LtK/Vp/kreFLnr5QH5+DhvD5nINYZXzwJvXeGq+05iUXcAzVrqWtw==}
'@types/babel__standalone@7.1.9':
resolution: {integrity: sha512-IcCNPLqpevUD7UpV8QB0uwQPOyoOKACFf0YtYWRHcmxcakaje4Q7dbG2+jMqxw/I8Zk0NHvEps66WwS7z/UaaA==}
'@types/babel__template@7.4.4':
resolution: {integrity: sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==}
'@types/babel__traverse@7.20.6':
resolution: {integrity: sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==}
'@types/node@18.19.75':
resolution: {integrity: sha512-UIksWtThob6ZVSyxcOqCLOUNg/dyO1Qvx4McgeuhrEtHTLFTf7BBhEazaE4K806FGTPtzd/2sE90qn4fVr7cyw==}
esbuild@0.19.12:
resolution: {integrity: sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==}
engines: {node: '>=12'}
hasBin: true
typescript@5.7.3:
resolution: {integrity: sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==}
engines: {node: '>=14.17'}
hasBin: true
undici-types@5.26.5:
resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==}
snapshots:
'@babel/helper-string-parser@7.25.9': {}
'@babel/helper-validator-identifier@7.25.9': {}
'@babel/parser@7.26.7':
dependencies:
'@babel/types': 7.26.7
'@babel/standalone@7.26.7': {}
'@babel/types@7.26.7':
dependencies:
'@babel/helper-string-parser': 7.25.9
'@babel/helper-validator-identifier': 7.25.9
'@esbuild/aix-ppc64@0.19.12':
optional: true
'@esbuild/android-arm64@0.19.12':
optional: true
'@esbuild/android-arm@0.19.12':
optional: true
'@esbuild/android-x64@0.19.12':
optional: true
'@esbuild/darwin-arm64@0.19.12':
optional: true
'@esbuild/darwin-x64@0.19.12':
optional: true
'@esbuild/freebsd-arm64@0.19.12':
optional: true
'@esbuild/freebsd-x64@0.19.12':
optional: true
'@esbuild/linux-arm64@0.19.12':
optional: true
'@esbuild/linux-arm@0.19.12':
optional: true
'@esbuild/linux-ia32@0.19.12':
optional: true
'@esbuild/linux-loong64@0.19.12':
optional: true
'@esbuild/linux-mips64el@0.19.12':
optional: true
'@esbuild/linux-ppc64@0.19.12':
optional: true
'@esbuild/linux-riscv64@0.19.12':
optional: true
'@esbuild/linux-s390x@0.19.12':
optional: true
'@esbuild/linux-x64@0.19.12':
optional: true
'@esbuild/netbsd-x64@0.19.12':
optional: true
'@esbuild/openbsd-x64@0.19.12':
optional: true
'@esbuild/sunos-x64@0.19.12':
optional: true
'@esbuild/win32-arm64@0.19.12':
optional: true
'@esbuild/win32-ia32@0.19.12':
optional: true
'@esbuild/win32-x64@0.19.12':
optional: true
'@types/babel__core@7.20.5':
dependencies:
'@babel/parser': 7.26.7
'@babel/types': 7.26.7
'@types/babel__generator': 7.6.8
'@types/babel__template': 7.4.4
'@types/babel__traverse': 7.20.6
'@types/babel__generator@7.6.8':
dependencies:
'@babel/types': 7.26.7
'@types/babel__standalone@7.1.9':
dependencies:
'@babel/parser': 7.26.7
'@babel/types': 7.26.7
'@types/babel__core': 7.20.5
'@types/babel__generator': 7.6.8
'@types/babel__template': 7.4.4
'@types/babel__traverse': 7.20.6
'@types/babel__template@7.4.4':
dependencies:
'@babel/parser': 7.26.7
'@babel/types': 7.26.7
'@types/babel__traverse@7.20.6':
dependencies:
'@babel/types': 7.26.7
'@types/node@18.19.75':
dependencies:
undici-types: 5.26.5
esbuild@0.19.12:
optionalDependencies:
'@esbuild/aix-ppc64': 0.19.12
'@esbuild/android-arm': 0.19.12
'@esbuild/android-arm64': 0.19.12
'@esbuild/android-x64': 0.19.12
'@esbuild/darwin-arm64': 0.19.12
'@esbuild/darwin-x64': 0.19.12
'@esbuild/freebsd-arm64': 0.19.12
'@esbuild/freebsd-x64': 0.19.12
'@esbuild/linux-arm': 0.19.12
'@esbuild/linux-arm64': 0.19.12
'@esbuild/linux-ia32': 0.19.12
'@esbuild/linux-loong64': 0.19.12
'@esbuild/linux-mips64el': 0.19.12
'@esbuild/linux-ppc64': 0.19.12
'@esbuild/linux-riscv64': 0.19.12
'@esbuild/linux-s390x': 0.19.12
'@esbuild/linux-x64': 0.19.12
'@esbuild/netbsd-x64': 0.19.12
'@esbuild/openbsd-x64': 0.19.12
'@esbuild/sunos-x64': 0.19.12
'@esbuild/win32-arm64': 0.19.12
'@esbuild/win32-ia32': 0.19.12
'@esbuild/win32-x64': 0.19.12
typescript@5.7.3: {}
undici-types@5.26.5: {}

View File

@@ -1,5 +1,5 @@
{
"name": "posthog",
"name": "@posthog/frontend",
"description": "",
"version": "0.0.0",
"repository": {
@@ -15,7 +15,7 @@
"engines": {
"node": ">=18 <19"
},
"packageManager": "pnpm@8.10.5",
"packageManager": "pnpm@9.15.4",
"scripts": {
"copy-scripts": "mkdir -p frontend/dist/ && ./bin/copy-posthog-js",
"test": "pnpm test:unit && pnpm test:visual",
@@ -79,10 +79,11 @@
"@posthog/hogvm": "^1.0.67",
"@posthog/icons": "0.10.0",
"@posthog/plugin-scaffold": "^1.4.4",
"@radix-ui/react-accordion": "^1.2.2",
"@react-hook/size": "^2.1.2",
"@posthog/rrweb": "0.0.8",
"@posthog/rrweb-plugin-console-record": "0.0.8",
"@posthog/rrweb-types": "0.0.8",
"@radix-ui/react-accordion": "^1.2.2",
"@react-hook/size": "^2.1.2",
"@sentry/react": "7.112.1",
"@stripe/react-stripe-js": "^2.8.0",
"@stripe/stripe-js": "^4.5.0",
@@ -190,7 +191,6 @@
"react-transition-group": "^4.4.5",
"react-virtualized": "^9.22.5",
"resize-observer-polyfill": "^1.5.1",
"@posthog/rrweb": "0.0.8",
"sass": "^1.26.2",
"tailwind-merge": "^2.2.2",
"tailwindcss": "3.4.1",
@@ -211,6 +211,8 @@
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.5",
"@cypress/webpack-preprocessor": "^6.0.2",
"@parcel/packager-ts": "2.13.3",
"@parcel/transformer-typescript-types": "2.13.3",
"@playwright/test": "1.45.0",
"@sentry/types": "7.112.1",
"@storybook/addon-a11y": "^7.6.4",
@@ -339,6 +341,7 @@
"typescript": "~4.9.5"
},
"patchedDependencies": {
"node-rdkafka@2.17.0": "patches/node-rdkafka@2.17.0.patch",
"heatmap.js@2.0.5": "patches/heatmap.js@2.0.5.patch",
"dayjs@1.11.11": "patches/dayjs@1.11.11.patch"
}

View File

@@ -1,812 +0,0 @@
diff --git a/es/rrweb/packages/rrweb/src/replay/index.js b/es/rrweb/packages/rrweb/src/replay/index.js
index 0d49411b1f6d31103bed898c0e81d1d74ab51234..0b2160ef08aa3ae5310f63c295abc0a560332b22 100644
--- a/es/rrweb/packages/rrweb/src/replay/index.js
+++ b/es/rrweb/packages/rrweb/src/replay/index.js
@@ -203,6 +203,10 @@ class Replayer {
mouseTail: defaultMouseTailConfig,
useVirtualDom: true,
logger: console,
+ onError: (e) => {
+ // maintain the existing behaviour of throwing if no handler is provided
+ throw e;
+ },
};
this.config = Object.assign({}, defaultConfig, config);
this.handleResize = this.handleResize.bind(this);
@@ -755,255 +759,259 @@ class Replayer {
applyIncremental(e, isSync) {
var _a, _b, _c;
const { data: d } = e;
- switch (d.source) {
- case IncrementalSource.Mutation: {
- try {
- this.applyMutation(d, isSync);
- }
- catch (error) {
- this.warn(`Exception in mutation ${error.message || error}`, d);
- }
- break;
- }
- case IncrementalSource.Drag:
- case IncrementalSource.TouchMove:
- case IncrementalSource.MouseMove:
- if (isSync) {
- const lastPosition = d.positions[d.positions.length - 1];
- this.mousePos = {
- x: lastPosition.x,
- y: lastPosition.y,
- id: lastPosition.id,
- debugData: d,
- };
+ try {
+ switch (d.source) {
+ case IncrementalSource.Mutation: {
+ try {
+ this.applyMutation(d, isSync);
+ }
+ catch (error) {
+ this.warn(`Exception in mutation ${error.message || error}`, d);
+ }
+ break;
}
- else {
- d.positions.forEach((p) => {
- const action = {
- doAction: () => {
- this.moveAndHover(p.x, p.y, p.id, isSync, d);
- },
- delay: p.timeOffset +
- e.timestamp -
- this.service.state.context.baselineTime,
+ case IncrementalSource.Drag:
+ case IncrementalSource.TouchMove:
+ case IncrementalSource.MouseMove:
+ if (isSync) {
+ const lastPosition = d.positions[d.positions.length - 1];
+ this.mousePos = {
+ x: lastPosition.x,
+ y: lastPosition.y,
+ id: lastPosition.id,
+ debugData: d,
};
- this.timer.addAction(action);
- });
- this.timer.addAction({
- doAction() {
- },
- delay: e.delay - ((_a = d.positions[0]) === null || _a === void 0 ? void 0 : _a.timeOffset),
- });
- }
- break;
- case IncrementalSource.MouseInteraction: {
- if (d.id === -1) {
+ }
+ else {
+ d.positions.forEach((p) => {
+ const action = {
+ doAction: () => {
+ this.moveAndHover(p.x, p.y, p.id, isSync, d);
+ },
+ delay: p.timeOffset +
+ e.timestamp -
+ this.service.state.context.baselineTime,
+ };
+ this.timer.addAction(action);
+ });
+ this.timer.addAction({
+ doAction() {
+ },
+ delay: e.delay - ((_a = d.positions[0]) === null || _a === void 0 ? void 0 : _a.timeOffset),
+ });
+ }
break;
- }
- const event = new Event(toLowerCase(MouseInteractions[d.type]));
- const target = this.mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
- }
- this.emitter.emit(ReplayerEvents.MouseInteraction, {
- type: d.type,
- target,
- });
- const { triggerFocus } = this.config;
- switch (d.type) {
- case MouseInteractions.Blur:
- if ('blur' in target) {
- target.blur();
- }
- break;
- case MouseInteractions.Focus:
- if (triggerFocus && target.focus) {
- target.focus({
- preventScroll: true,
- });
- }
+ case IncrementalSource.MouseInteraction: {
+ if (d.id === -1) {
break;
- case MouseInteractions.Click:
- case MouseInteractions.TouchStart:
- case MouseInteractions.TouchEnd:
- case MouseInteractions.MouseDown:
- case MouseInteractions.MouseUp:
- if (isSync) {
- if (d.type === MouseInteractions.TouchStart) {
- this.touchActive = true;
- }
- else if (d.type === MouseInteractions.TouchEnd) {
- this.touchActive = false;
- }
- if (d.type === MouseInteractions.MouseDown) {
- this.lastMouseDownEvent = [target, event];
- }
- else if (d.type === MouseInteractions.MouseUp) {
- this.lastMouseDownEvent = null;
+ }
+ const event = new Event(toLowerCase(MouseInteractions[d.type]));
+ const target = this.mirror.getNode(d.id);
+ if (!target) {
+ return this.debugNodeNotFound(d, d.id);
+ }
+ this.emitter.emit(ReplayerEvents.MouseInteraction, {
+ type: d.type,
+ target,
+ });
+ const { triggerFocus } = this.config;
+ switch (d.type) {
+ case MouseInteractions.Blur:
+ if ('blur' in target) {
+ target.blur();
}
- this.mousePos = {
- x: d.x || 0,
- y: d.y || 0,
- id: d.id,
- debugData: d,
- };
- }
- else {
- if (d.type === MouseInteractions.TouchStart) {
- this.tailPositions.length = 0;
+ break;
+ case MouseInteractions.Focus:
+ if (triggerFocus && target.focus) {
+ target.focus({
+ preventScroll: true,
+ });
}
- this.moveAndHover(d.x || 0, d.y || 0, d.id, isSync, d);
- if (d.type === MouseInteractions.Click) {
- this.mouse.classList.remove('active');
- void this.mouse.offsetWidth;
- this.mouse.classList.add('active');
+ break;
+ case MouseInteractions.Click:
+ case MouseInteractions.TouchStart:
+ case MouseInteractions.TouchEnd:
+ case MouseInteractions.MouseDown:
+ case MouseInteractions.MouseUp:
+ if (isSync) {
+ if (d.type === MouseInteractions.TouchStart) {
+ this.touchActive = true;
+ }
+ else if (d.type === MouseInteractions.TouchEnd) {
+ this.touchActive = false;
+ }
+ if (d.type === MouseInteractions.MouseDown) {
+ this.lastMouseDownEvent = [target, event];
+ }
+ else if (d.type === MouseInteractions.MouseUp) {
+ this.lastMouseDownEvent = null;
+ }
+ this.mousePos = {
+ x: d.x || 0,
+ y: d.y || 0,
+ id: d.id,
+ debugData: d,
+ };
}
- else if (d.type === MouseInteractions.TouchStart) {
- void this.mouse.offsetWidth;
- this.mouse.classList.add('touch-active');
+ else {
+ if (d.type === MouseInteractions.TouchStart) {
+ this.tailPositions.length = 0;
+ }
+ this.moveAndHover(d.x || 0, d.y || 0, d.id, isSync, d);
+ if (d.type === MouseInteractions.Click) {
+ this.mouse.classList.remove('active');
+ void this.mouse.offsetWidth;
+ this.mouse.classList.add('active');
+ }
+ else if (d.type === MouseInteractions.TouchStart) {
+ void this.mouse.offsetWidth;
+ this.mouse.classList.add('touch-active');
+ }
+ else if (d.type === MouseInteractions.TouchEnd) {
+ this.mouse.classList.remove('touch-active');
+ }
+ else {
+ target.dispatchEvent(event);
+ }
}
- else if (d.type === MouseInteractions.TouchEnd) {
- this.mouse.classList.remove('touch-active');
+ break;
+ case MouseInteractions.TouchCancel:
+ if (isSync) {
+ this.touchActive = false;
}
else {
- target.dispatchEvent(event);
+ this.mouse.classList.remove('touch-active');
}
- }
+ break;
+ default:
+ target.dispatchEvent(event);
+ }
+ break;
+ }
+ case IncrementalSource.Scroll: {
+ if (d.id === -1) {
break;
- case MouseInteractions.TouchCancel:
- if (isSync) {
- this.touchActive = false;
- }
- else {
- this.mouse.classList.remove('touch-active');
+ }
+ if (this.usingVirtualDom) {
+ const target = this.virtualDom.mirror.getNode(d.id);
+ if (!target) {
+ return this.debugNodeNotFound(d, d.id);
}
+ target.scrollData = d;
break;
- default:
- target.dispatchEvent(event);
- }
- break;
- }
- case IncrementalSource.Scroll: {
- if (d.id === -1) {
- break;
- }
- if (this.usingVirtualDom) {
- const target = this.virtualDom.mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
}
- target.scrollData = d;
+ this.applyScroll(d, isSync);
break;
}
- this.applyScroll(d, isSync);
- break;
- }
- case IncrementalSource.ViewportResize:
- this.emitter.emit(ReplayerEvents.Resize, {
- width: d.width,
- height: d.height,
- });
- break;
- case IncrementalSource.Input: {
- if (d.id === -1) {
+ case IncrementalSource.ViewportResize:
+ this.emitter.emit(ReplayerEvents.Resize, {
+ width: d.width,
+ height: d.height,
+ });
break;
- }
- if (this.usingVirtualDom) {
- const target = this.virtualDom.mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
+ case IncrementalSource.Input: {
+ if (d.id === -1) {
+ break;
}
- target.inputData = d;
+ if (this.usingVirtualDom) {
+ const target = this.virtualDom.mirror.getNode(d.id);
+ if (!target) {
+ return this.debugNodeNotFound(d, d.id);
+ }
+ target.inputData = d;
+ break;
+ }
+ this.applyInput(d);
break;
}
- this.applyInput(d);
- break;
- }
- case IncrementalSource.MediaInteraction: {
- const target = this.usingVirtualDom
- ? this.virtualDom.mirror.getNode(d.id)
- : this.mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
- }
- const mediaEl = target;
- const { events } = this.service.state.context;
- this.mediaManager.mediaMutation({
- target: mediaEl,
- timeOffset: e.timestamp - events[0].timestamp,
- mutation: d,
- });
- break;
- }
- case IncrementalSource.StyleSheetRule:
- case IncrementalSource.StyleDeclaration: {
- if (this.usingVirtualDom) {
- if (d.styleId)
- this.constructedStyleMutations.push(d);
- else if (d.id)
- (_b = this.virtualDom.mirror.getNode(d.id)) === null || _b === void 0 ? void 0 : _b.rules.push(d);
- }
- else
- this.applyStyleSheetMutation(d);
- break;
- }
- case IncrementalSource.CanvasMutation: {
- if (!this.config.UNSAFE_replayCanvas) {
- return;
- }
- if (this.usingVirtualDom) {
- const target = this.virtualDom.mirror.getNode(d.id);
+ case IncrementalSource.MediaInteraction: {
+ const target = this.usingVirtualDom
+ ? this.virtualDom.mirror.getNode(d.id)
+ : this.mirror.getNode(d.id);
if (!target) {
return this.debugNodeNotFound(d, d.id);
}
- target.canvasMutations.push({
- event: e,
+ const mediaEl = target;
+ const { events } = this.service.state.context;
+ this.mediaManager.mediaMutation({
+ target: mediaEl,
+ timeOffset: e.timestamp - events[0].timestamp,
mutation: d,
});
+ break;
}
- else {
- const target = this.mirror.getNode(d.id);
- if (!target) {
- return this.debugNodeNotFound(d, d.id);
+ case IncrementalSource.StyleSheetRule:
+ case IncrementalSource.StyleDeclaration: {
+ if (this.usingVirtualDom) {
+ if (d.styleId)
+ this.constructedStyleMutations.push(d);
+ else if (d.id)
+ (_b = this.virtualDom.mirror.getNode(d.id)) === null || _b === void 0 ? void 0 : _b.rules.push(d);
}
- void canvasMutation({
- event: e,
- mutation: d,
- target: target,
- imageMap: this.imageMap,
- canvasEventMap: this.canvasEventMap,
- errorHandler: this.warnCanvasMutationFailed.bind(this),
- });
+ else
+ this.applyStyleSheetMutation(d);
+ break;
}
- break;
- }
- case IncrementalSource.Font: {
- try {
- const fontFace = new FontFace(d.family, d.buffer
- ? new Uint8Array(JSON.parse(d.fontSource))
- : d.fontSource, d.descriptors);
- (_c = this.iframe.contentDocument) === null || _c === void 0 ? void 0 : _c.fonts.add(fontFace);
+ case IncrementalSource.CanvasMutation: {
+ if (!this.config.UNSAFE_replayCanvas) {
+ return;
+ }
+ if (this.usingVirtualDom) {
+ const target = this.virtualDom.mirror.getNode(d.id);
+ if (!target) {
+ return this.debugNodeNotFound(d, d.id);
+ }
+ target.canvasMutations.push({
+ event: e,
+ mutation: d,
+ });
+ }
+ else {
+ const target = this.mirror.getNode(d.id);
+ if (!target) {
+ return this.debugNodeNotFound(d, d.id);
+ }
+ void canvasMutation({
+ event: e,
+ mutation: d,
+ target: target,
+ imageMap: this.imageMap,
+ canvasEventMap: this.canvasEventMap,
+ errorHandler: this.warnCanvasMutationFailed.bind(this),
+ });
+ }
+ break;
}
- catch (error) {
- this.warn(error);
+ case IncrementalSource.Font: {
+ try {
+ const fontFace = new FontFace(d.family, d.buffer
+ ? new Uint8Array(JSON.parse(d.fontSource))
+ : d.fontSource, d.descriptors);
+ (_c = this.iframe.contentDocument) === null || _c === void 0 ? void 0 : _c.fonts.add(fontFace);
+ }
+ catch (error) {
+ this.warn(error);
+ }
+ break;
}
- break;
- }
- case IncrementalSource.Selection: {
- if (isSync) {
- this.lastSelectionData = d;
+ case IncrementalSource.Selection: {
+ if (isSync) {
+ this.lastSelectionData = d;
+ break;
+ }
+ this.applySelection(d);
+ break;
+ }
+ case IncrementalSource.AdoptedStyleSheet: {
+ if (this.usingVirtualDom)
+ this.adoptedStyleSheets.push(d);
+ else
+ this.applyAdoptedStyleSheet(d);
break;
}
- this.applySelection(d);
- break;
- }
- case IncrementalSource.AdoptedStyleSheet: {
- if (this.usingVirtualDom)
- this.adoptedStyleSheets.push(d);
- else
- this.applyAdoptedStyleSheet(d);
- break;
}
+ } catch (error) {
+ this.config.onError(error);
}
}
applyMutation(d, isSync) {
diff --git a/es/rrweb/packages/rrweb/src/replay/media/index.js b/es/rrweb/packages/rrweb/src/replay/media/index.js
index 22fee601e786c1d8dfb5c01d2e359c8bcbac7c42..6d80d33030c601fa74f1b95573cb1590c3a0116b 100644
--- a/es/rrweb/packages/rrweb/src/replay/media/index.js
+++ b/es/rrweb/packages/rrweb/src/replay/media/index.js
@@ -21,7 +21,7 @@ class MediaManager {
this.mediaMap.forEach((mediaState, target) => {
this.syncTargetWithState(target);
if (options.pause) {
- target.pause();
+ target?.pause();
}
});
}
@@ -49,7 +49,7 @@ class MediaManager {
target.currentTime = seekToTime;
}
else {
- target.pause();
+ target?.pause();
target.currentTime = mediaState.currentTimeAtLastInteraction;
}
}
@@ -117,7 +117,7 @@ class MediaManager {
void target.play();
}
else {
- target.pause();
+ target?.pause();
}
}
catch (error) {
@@ -141,7 +141,7 @@ class MediaManager {
isPlaying = target.getAttribute('autoplay') !== null;
}
if (isPlaying && playerIsPaused)
- target.pause();
+ target?.pause();
let playbackRate = 1;
if (typeof mediaAttributes.rr_mediaPlaybackRate === 'number') {
playbackRate = mediaAttributes.rr_mediaPlaybackRate;
@@ -180,6 +180,8 @@ class MediaManager {
this.syncTargetWithState(target);
}
mediaMutation({ target, timeOffset, mutation, }) {
+ if (!['AUDIO', 'VIDEO'].includes(target.nodeName))
+ return;
this.mediaMap.set(target, this.getMediaStateFromMutation({
target,
timeOffset,
diff --git a/es/rrweb/packages/rrweb-snapshot/es/css.js b/es/rrweb/packages/rrweb-snapshot/es/css.js
new file mode 100644
index 0000000000000000000000000000000000000000..0a6c5930c017852afd3d7f0170f6eca821619dd3
--- /dev/null
+++ b/es/rrweb/packages/rrweb-snapshot/es/css.js
@@ -0,0 +1,87 @@
+import postcss from '../../../../../../../../../postcss/lib/postcss.js'
+
+const MEDIA_SELECTOR = /(max|min)-device-(width|height)/
+const MEDIA_SELECTOR_GLOBAL = new RegExp(MEDIA_SELECTOR.source, 'g')
+
+export const mutate = (cssText) => {
+ const ast = postcss([mediaSelectorPlugin, pseudoClassPlugin]).process(cssText)
+ return ast.css
+}
+
+const mediaSelectorPlugin = {
+ postcssPlugin: 'postcss-custom-selectors',
+ prepare() {
+ return {
+ postcssPlugin: 'postcss-custom-selectors',
+ AtRule: function (atrule) {
+ if (atrule.params.match(MEDIA_SELECTOR_GLOBAL)) {
+ atrule.params = atrule.params.replace(MEDIA_SELECTOR_GLOBAL, '$1-$2')
+ }
+ },
+ }
+ },
+}
+
+// Adapted from https://github.com/giuseppeg/postcss-pseudo-classes/blob/master/index.js
+const pseudoClassPlugin = {
+ postcssPlugin: 'postcss-hover-classes',
+ prepare: function () {
+ const fixed = []
+ return {
+ Rule: function (rule) {
+ if (fixed.indexOf(rule) !== -1) {
+ return
+ }
+ fixed.push(rule)
+
+ rule.selectors.forEach(function (selector) {
+ if (!selector.includes(':')) {
+ return
+ }
+
+ const selectorParts = selector.replace(/\n/g, ' ').split(' ')
+ const pseudoedSelectorParts = []
+
+ selectorParts.forEach(function (selectorPart) {
+ const pseudos = selectorPart.match(/::?([^:]+)/g)
+
+ if (!pseudos) {
+ pseudoedSelectorParts.push(selectorPart)
+ return
+ }
+
+ const baseSelector = selectorPart.substr(0, selectorPart.length - pseudos.join('').length)
+
+ const classPseudos = pseudos.map(function (pseudo) {
+ const pseudoToCheck = pseudo.replace(/\(.*/g, '')
+ if (pseudoToCheck !== ':hover') {
+ return pseudo
+ }
+
+ // Ignore pseudo-elements!
+ if (pseudo.match(/^::/)) {
+ return pseudo
+ }
+
+ // Kill the colon
+ pseudo = pseudo.substr(1)
+
+ // Replace left and right parens
+ pseudo = pseudo.replace(/\(/g, '\\(')
+ pseudo = pseudo.replace(/\)/g, '\\)')
+
+ return '.' + '\\:' + pseudo
+ })
+
+ pseudoedSelectorParts.push(baseSelector + classPseudos.join(''))
+ })
+
+ const newSelector = pseudoedSelectorParts.join(' ')
+ if (newSelector && newSelector !== selector) {
+ rule.selector += ',\n' + newSelector
+ }
+ })
+ },
+ }
+ },
+}
diff --git a/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js b/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js
index 38a23aaae8d683fa584329eced277dd8de55d1ff..8aeee467a3bab9baeefb1a97f2b131bedbd0fa3c 100644
--- a/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js
+++ b/es/rrweb/packages/rrweb-snapshot/es/rrweb-snapshot.js
@@ -1,3 +1,5 @@
+import {mutate} from './css.js';
+
var NodeType;
(function (NodeType) {
NodeType[NodeType["Document"] = 0] = "Document";
@@ -1255,54 +1257,19 @@ function parse(css, options = {}) {
});
}
function selector() {
- whitespace();
- while (css[0] == '}') {
- error('extra closing bracket');
- css = css.slice(1);
- whitespace();
- }
- const m = match(/^(("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^{])+)/);
+ const m = match(/^([^{]+)/);
if (!m) {
return;
}
- const cleanedInput = m[0]
- .trim()
+ return trim(m[0])
.replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
.replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, (m) => {
- return m.replace(/,/g, '\u200C');
- });
- return customSplit(cleanedInput).map((s) => s.replace(/\u200C/g, ',').trim());
- }
- function customSplit(input) {
- const result = [];
- let currentSegment = '';
- let depthParentheses = 0;
- let depthBrackets = 0;
- for (const char of input) {
- if (char === '(') {
- depthParentheses++;
- }
- else if (char === ')') {
- depthParentheses--;
- }
- else if (char === '[') {
- depthBrackets++;
- }
- else if (char === ']') {
- depthBrackets--;
- }
- if (char === ',' && depthParentheses === 0 && depthBrackets === 0) {
- result.push(currentSegment);
- currentSegment = '';
- }
- else {
- currentSegment += char;
- }
- }
- if (currentSegment) {
- result.push(currentSegment);
- }
- return result;
+ return m.replace(/,/g, '\u200C');
+ })
+ .split(/\s*(?![^(]*\)),\s*/)
+ .map((s) => {
+ return s.replace(/\u200C/g, ',');
+ });
}
function declaration() {
const pos = position();
@@ -1662,56 +1629,60 @@ function adaptCssForReplay(cssText, cache) {
const cachedStyle = cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.get(cssText);
if (cachedStyle)
return cachedStyle;
- const ast = parse(cssText, {
- silent: true,
- });
- if (!ast.stylesheet) {
- return cssText;
- }
- const selectors = [];
- const medias = [];
- function getSelectors(rule) {
- if ('selectors' in rule && rule.selectors) {
- rule.selectors.forEach((selector) => {
- if (HOVER_SELECTOR.test(selector)) {
- selectors.push(selector);
- }
- });
+ let result = cssText;
+ try {
+ result = mutate(cssText)
+ } catch (error) {
+ const ast = parse(cssText, {
+ silent: true,
+ });
+ if (!ast.stylesheet) {
+ return cssText;
+ }
+ const selectors = [];
+ const medias = [];
+ function getSelectors(rule) {
+ if ('selectors' in rule && rule.selectors) {
+ rule.selectors.forEach((selector) => {
+ if (HOVER_SELECTOR.test(selector)) {
+ selectors.push(selector);
+ }
+ });
+ }
+ if ('media' in rule && rule.media && MEDIA_SELECTOR.test(rule.media)) {
+ medias.push(rule.media);
+ }
+ if ('rules' in rule && rule.rules) {
+ rule.rules.forEach(getSelectors);
+ }
}
- if ('media' in rule && rule.media && MEDIA_SELECTOR.test(rule.media)) {
- medias.push(rule.media);
+ getSelectors(ast.stylesheet);
+ if (selectors.length > 0) {
+ const selectorMatcher = new RegExp(selectors
+ .filter((selector, index) => selectors.indexOf(selector) === index)
+ .sort((a, b) => b.length - a.length)
+ .map((selector) => {
+ return escapeRegExp(selector);
+ })
+ .join('|'), 'g');
+ result = result.replace(selectorMatcher, (selector) => {
+ const newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
+ return `${selector}, ${newSelector}`;
+ });
}
- if ('rules' in rule && rule.rules) {
- rule.rules.forEach(getSelectors);
+ if (medias.length > 0) {
+ const mediaMatcher = new RegExp(medias
+ .filter((media, index) => medias.indexOf(media) === index)
+ .sort((a, b) => b.length - a.length)
+ .map((media) => {
+ return escapeRegExp(media);
+ })
+ .join('|'), 'g');
+ result = result.replace(mediaMatcher, (media) => {
+ return media.replace(MEDIA_SELECTOR_GLOBAL, '$1-$2');
+ });
}
}
- getSelectors(ast.stylesheet);
- let result = cssText;
- if (selectors.length > 0) {
- const selectorMatcher = new RegExp(selectors
- .filter((selector, index) => selectors.indexOf(selector) === index)
- .sort((a, b) => b.length - a.length)
- .map((selector) => {
- return escapeRegExp(selector);
- })
- .join('|'), 'g');
- result = result.replace(selectorMatcher, (selector) => {
- const newSelector = selector.replace(HOVER_SELECTOR_GLOBAL, '$1.\\:hover');
- return `${selector}, ${newSelector}`;
- });
- }
- if (medias.length > 0) {
- const mediaMatcher = new RegExp(medias
- .filter((media, index) => medias.indexOf(media) === index)
- .sort((a, b) => b.length - a.length)
- .map((media) => {
- return escapeRegExp(media);
- })
- .join('|'), 'g');
- result = result.replace(mediaMatcher, (media) => {
- return media.replace(MEDIA_SELECTOR_GLOBAL, '$1-$2');
- });
- }
cache === null || cache === void 0 ? void 0 : cache.stylesWithHoverClass.set(cssText, result);
return result;
}

View File

@@ -4,7 +4,6 @@
"description": "PostHog Plugin Server",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"packageManager": "pnpm@8.6.0",
"scripts": {
"test": "jest --runInBand --forceExit",
"functional_tests": "jest --config ./jest.config.functional.js",
@@ -13,7 +12,7 @@
"start:dev": "NODE_ENV=dev BASE_DIR=.. nodemon --watch src/ --exec node -r @swc-node/register src/index.ts",
"start:devNoWatch": "NODE_ENV=dev BASE_DIR=.. node -r @swc-node/register src/index.ts",
"build": "pnpm clean && pnpm typescript:compile && pnpm typescript:compile-cleanup",
"clean": "rm -rf dist/* && rm -rf ../rust/cyclotron-node/index.node",
"clean": "rm -rf dist/*",
"typescript:compile": "tsc -b",
"typescript:compile-cleanup": "[ -d dist/src ] && mv dist/src/* dist/ || true",
"typescript:check": "tsc --noEmit -p .",
@@ -45,11 +44,11 @@
"dependencies": {
"@aws-sdk/client-s3": "^3.709.0",
"@aws-sdk/lib-storage": "^3.709.0",
"@babel/core": "^7.18.10",
"@babel/plugin-transform-react-jsx": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@babel/core": "^7.22.10",
"@babel/plugin-transform-react-jsx": "^7.22.5",
"@babel/preset-env": "^7.22.10",
"@babel/preset-typescript": "^7.18.6",
"@babel/standalone": "^7.18.12",
"@babel/standalone": "^7.23.2",
"@google-cloud/pubsub": "3.0.1",
"@google-cloud/storage": "^5.8.5",
"@maxmind/geoip2-node": "^3.4.0",
@@ -58,10 +57,10 @@
"@posthog/hogvm": "^1.0.67",
"@posthog/plugin-scaffold": "1.4.4",
"@posthog/siphash": "1.1.1",
"@sentry/node": "^7.49.0",
"@sentry/profiling-node": "^0.3.0",
"@sentry/tracing": "^7.17.4",
"@sentry/utils": "^7.17.4",
"@sentry/node": "7.112.1",
"@sentry/profiling-node": "7.112.1",
"@sentry/tracing": "7.112.1",
"@sentry/utils": "7.112.1",
"@types/lru-cache": "^5.1.0",
"@types/node": "^18.11.9",
"@types/tail": "^2.2.1",
@@ -76,6 +75,7 @@
"fernet-nodejs": "^1.0.6",
"generic-pool": "^3.7.1",
"graphile-worker": "0.13.0",
"husky": "^7.0.4",
"ioredis": "^4.27.6",
"ipaddr.js": "^2.1.0",
"js-big-decimal": "^2.2.0",
@@ -106,12 +106,12 @@
},
"devDependencies": {
"0x": "^5.5.0",
"@babel/cli": "^7.18.10",
"@babel/cli": "^7.22.5",
"@babel/types": "^7.20.2",
"@sentry/types": "^7.17.4",
"@swc-node/register": "^1.5.1",
"@swc/core": "^1.2.186",
"@swc/jest": "^0.2.21",
"@sentry/types": "7.112.1",
"@swc-node/register": "^1.10.9",
"@swc/core": "^1.10.14",
"@swc/jest": "^0.2.37",
"@types/adm-zip": "^0.4.34",
"@types/babel__core": "^7.1.19",
"@types/babel__standalone": "^7.1.4",
@@ -151,11 +151,6 @@
"supertest": "^7.0.0",
"ts-node": "^10.9.1"
},
"pnpm": {
"patchedDependencies": {
"node-rdkafka@2.17.0": "patches/node-rdkafka@2.17.0.patch"
}
},
"cyclotron": {
"//This is a short term workaround to ensure that cyclotron changes trigger a rebuild": true,
"version": "0.1.7"

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,6 @@ const fs = require('fs')
import * as Sentry from '@sentry/node'
import { ProfilingIntegration } from '@sentry/profiling-node'
import * as Tracing from '@sentry/tracing'
import { Span, SpanContext, TransactionContext } from '@sentry/types'
import { timestampWithMs } from '@sentry/utils'
import { AsyncLocalStorage } from 'node:async_hooks'
@@ -12,7 +11,7 @@ import { PluginsServerConfig } from './types'
// Must require as `tsc` strips unused `import` statements and just requiring this seems to init some globals
require('@sentry/tracing')
const asyncLocalStorage = new AsyncLocalStorage<Tracing.Span>()
const asyncLocalStorage = new AsyncLocalStorage<Span>()
// Code that runs on app start, in both the main and worker threads
export function initSentry(config: PluginsServerConfig): void {
@@ -50,7 +49,7 @@ export function initSentry(config: PluginsServerConfig): void {
}
}
export function getSpan(): Tracing.Span | undefined {
export function getSpan(): Span | undefined {
return asyncLocalStorage.getStore()
}

37828
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

6
pnpm-workspace.yaml Normal file
View File

@@ -0,0 +1,6 @@
packages:
- '.'
- plugin-server
- common/plugin_transpiler
- common/hogvm/typescript
- rust/cyclotron-node

View File

@@ -7,12 +7,12 @@
"scripts": {
"test": "cargo test",
"build": "pnpm run build:cargo --release && pnpm run build:move-lib && pnpm run build:typescript",
"build:move-lib": "cp ../target/release/libcyclotron_node.dylib index.node || cp ../target/release/libcyclotron_node.so index.node",
"build:move-lib": "cp ../target/release/libcyclotron_node.dylib index.node 2>/dev/null || cp ../target/release/libcyclotron_node.so index.node || (echo \"No valid library file found.\" && exit 1)",
"build:cargo": "cargo build --message-format=json > cargo.log",
"build:cargo:debug": "pnpm run build:cargo",
"build:cross": "cross build --message-format=json > cross.log",
"build:typescript": "tsc",
"package": "NODE_ENV=development pnpm i --dev && pnpm run build"
"package": "NODE_ENV=development pnpm --filter=@posthog/cyclotron i --dev && pnpm run build"
},
"author": "",
"license": "MIT",