Skip to content

Commit

Permalink
Merge branch 'main' into feat/safer-string-truncation
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Oct 17, 2024
2 parents 1a5d456 + ded55cf commit 6313e1d
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 198 deletions.
110 changes: 10 additions & 100 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,103 +1,13 @@
{
"presets": [
[
"@babel/preset-env",
{
"debug": true,
"corejs": "3.38",
"useBuiltIns": "usage",
"include": [
"es.array.from"
],
"exclude": [
"es.array.at",
"es.array.concat",
"es.array.find",
"es.array.find-index",
"es.array.fill",
"es.array.filter",
"es.array.flat-map",
"es.array.includes",
"es.array.iterator",
"es.array.join",
"es.array.map",
"es.array.slice",
"es.array.splice",
"es.array.sort",
"es.array.unscopables.flat-map",
"es.array-buffer.constructor",
"es.error.cause",
"es.function.name",
"es.global-this",
"es.json.stringify",
"es.math.trunc",
"es.math.sign",
"es.map",
"es.number.constructor",
"es.number.is-integer",
"es.number.is-nan",
"es.number.to-fixed",
"es.object.assign",
"es.object.entries",
"es.object.get-own-property-descriptor",
"es.object.get-own-property-names",
"es.object.keys",
"es.object.to-string",
"es.object.values",
"es.promise",
"es.promise.finally",
"es.reflect.get",
"es.reflect.to-string-tag",
"es.regexp.*",
"es.set",
"es.string.ends-with",
"es.string.includes",
"es.string.iterator",
"es.string.link",
"es.string.match",
"es.string.match-all",
"es.string.repeat",
"es.string.replace",
"es.string.search",
"es.string.starts-with",
"es.string.split",
"es.string.sub",
"es.string.trim",
"es.symbol",
"es.symbol.description",
"es.typed-array.*",
"es.weak-map",
"es.weak-set",
"esnext.global-this",
"esnext.string.match-all",
"esnext.typed-array.*",
"web.atob",
"web.dom-collections.for-each",
"web.dom-collections.iterator",
"web.dom-exception.constructor",
"web.dom-exception.stack",
"web.dom-exception.to-string-tag",
"web.url",
"web.url-search-params",
"web.url.to-json"
],
"targets": ">0.5%, last 2 versions, Firefox ESR, not dead, IE 11"
}
],
[
"@babel/typescript",
{
"jsxPragma": "h"
}
"presets": ["@babel/env", ["@babel/typescript", { "jsxPragma": "h" }]],
"plugins": [
"@babel/plugin-transform-nullish-coalescing-operator",
[
"@babel/transform-react-jsx",
{
"runtime": "automatic",
"importSource": "preact"
}
]
]
],
"plugins": [
[
"@babel/transform-react-jsx",
{
"runtime": "automatic",
"importSource": "preact"
}
]
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Server-side rendering and ES5
name: ES5 support check

on:
- pull_request
Expand All @@ -19,8 +19,5 @@ jobs:

- run: pnpm install && pnpm build

- name: Run es-check to check if our bundle is ES5 compatible
run: npx es-check@6.1.1 es5 dist/{array,main}.js

- name: Require module via node
run: cd dist; node -e "require('./main')"
- name: Run es-check to check if our ie11 bundle is ES5 compatible
run: npx es-check@7.2.1 es5 dist/array.full.es5.js
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.172.0 - 2024-10-17

- chore: build an es5 bundle and move main to es6 (#1480)

## 1.171.0 - 2024-10-17

- feat: start session recording on url trigger (#1451)
- chore: babel targets in rollup config (#1479)

## 1.170.1 - 2024-10-16

- feat: add stack to stacktraceless "exceptions" (#1472)
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthog-js",
"version": "1.170.1",
"version": "1.172.0",
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
"repository": "https://github.com/PostHog/posthog-js",
"author": "hey@posthog.com",
Expand Down Expand Up @@ -46,6 +46,7 @@
"devDependencies": {
"@babel/core": "7.18.9",
"@babel/plugin-syntax-decorators": "^7.23.3",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.25.8",
"@babel/plugin-transform-react-jsx": "^7.23.4",
"@babel/preset-env": "7.18.9",
"@babel/preset-typescript": "^7.18.6",
Expand All @@ -54,9 +55,9 @@
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@rollup/plugin-typescript": "^12.1.1",
"@rrweb/types": "2.0.0-alpha.13",
"@sentry/types": "8.7.0",
"@testing-library/dom": "^9.3.0",
Expand Down Expand Up @@ -100,8 +101,7 @@
"preact-render-to-string": "^6.3.1",
"prettier": "^2.7.1",
"rollup": "^4.24.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-ts": "^3.4.5",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-visualizer": "^5.12.0",
"rrweb": "2.0.0-alpha.13",
"rrweb-snapshot": "2.0.0-alpha.13",
Expand All @@ -122,7 +122,7 @@
]
},
"browserslist": [
">0.5%, last 2 versions, Firefox ESR, not dead, IE 11"
">0.5%, last 2 versions, Firefox ESR, not dead"
],
"pnpm": {
"patchedDependencies": {
Expand Down
99 changes: 17 additions & 82 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,37 @@ import typescript from '@rollup/plugin-typescript'
import { dts } from 'rollup-plugin-dts'
import terser from '@rollup/plugin-terser'
import { visualizer } from 'rollup-plugin-visualizer'
import commonjs from '@rollup/plugin-commonjs'
import fs from 'fs'
import path from 'path'
import commonjs from '@rollup/plugin-commonjs'

const plugins = [
const plugins = (es5) => [
json(),
resolve({ browser: true }),
typescript({ sourceMap: true, outDir: './dist' }),
commonjs(),
typescript({ sourceMap: true }),
babel({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelHelpers: 'bundled',
plugins: ['@babel/plugin-transform-nullish-coalescing-operator'],
presets: [
[
'@babel/preset-env',
{
debug: true,
corejs: '3.38',
useBuiltIns: 'usage',
include: ['es.array.from'],
exclude: [
'es.array.at',
'es.array.concat',
'es.array.find',
'es.array.find-index',
'es.array.fill',
'es.array.filter',
'es.array.flat-map',
'es.array.includes',
'es.array.iterator',
'es.array.join',
'es.array.map',
'es.array.slice',
'es.array.splice',
'es.array.sort',
'es.array.unscopables.flat-map',
'es.array-buffer.constructor',
'es.error.cause',
'es.function.name',
'es.global-this',
'es.json.stringify',
'es.math.trunc',
'es.math.sign',
'es.map',
'es.number.constructor',
'es.number.is-integer',
'es.number.is-nan',
'es.number.to-fixed',
'es.object.assign',
'es.object.entries',
'es.object.get-own-property-descriptor',
'es.object.get-own-property-names',
'es.object.keys',
'es.object.to-string',
'es.object.values',
'es.promise',
'es.promise.finally',
'es.reflect.get',
'es.reflect.to-string-tag',
'es.regexp.*',
'es.set',
'es.string.ends-with',
'es.string.includes',
'es.string.iterator',
'es.string.link',
'es.string.match',
'es.string.match-all',
'es.string.repeat',
'es.string.replace',
'es.string.search',
'es.string.starts-with',
'es.string.split',
'es.string.sub',
'es.string.trim',
'es.symbol',
'es.symbol.description',
'es.typed-array.*',
'es.weak-map',
'es.weak-set',
'esnext.global-this',
'esnext.string.match-all',
'esnext.typed-array.*',
'web.atob',
'web.dom-collections.for-each',
'web.dom-collections.iterator',
'web.dom-exception.constructor',
'web.dom-exception.stack',
'web.dom-exception.to-string-tag',
'web.url',
'web.url-search-params',
'web.url.to-json',
],
targets: '>0.5%, last 2 versions, Firefox ESR, not dead, IE 11',
targets: es5
? '>0.5%, last 2 versions, Firefox ESR, not dead, IE 11'
: '>0.5%, last 2 versions, Firefox ESR, not dead',
},
],
],
}),
terser({ toplevel: true }),
terser({
toplevel: true,
compress: {
// 5 is the default if unspecified
ecma: es5 ? 5 : 6,
},
}),
]

const entrypoints = fs.readdirSync('./src/entrypoints')
Expand All @@ -122,6 +55,8 @@ const entrypointTargets = entrypoints.map((file) => {

const fileName = fileParts.join('.')

const pluginsForThisFile = plugins(fileName.includes('es5'))

// we're allowed to console log in this file :)
// eslint-disable-next-line no-console
console.log(`Building ${fileName} in ${format} format`)
Expand All @@ -145,7 +80,7 @@ const entrypointTargets = entrypoints.map((file) => {
...(format === 'cjs' ? { exports: 'auto' } : {}),
},
],
plugins: [...plugins, visualizer({ filename: `bundle-stats-${fileName}.html` })],
plugins: [...pluginsForThisFile, visualizer({ filename: `bundle-stats-${fileName}.html` })],
}
})

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const SESSION_RECORDING_SAMPLE_RATE = '$replay_sample_rate'
export const SESSION_RECORDING_MINIMUM_DURATION = '$replay_minimum_duration'
export const SESSION_ID = '$sesid'
export const SESSION_RECORDING_IS_SAMPLED = '$session_is_sampled'
export const SESSION_RECORDING_URL_TRIGGER_ACTIVATED_SESSION = '$session_recording_url_trigger_activated_session'
export const SESSION_RECORDING_URL_TRIGGER_STATUS = '$session_recording_url_trigger_status'
export const ENABLED_FEATURE_FLAGS = '$enabled_feature_flags'
export const PERSISTENCE_EARLY_ACCESS_FEATURES = '$early_access_features'
export const STORED_PERSON_PROPERTIES_KEY = '$stored_person_properties'
Expand Down
11 changes: 11 additions & 0 deletions src/entrypoints/array.full.es5.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// a straight copy of the array.full.ts entrypoint,
// but will have different config when passed through rollup
// to allow es5/IE11 support

// it doesn't include recorder which doesn't support IE11,
// and it doesn't include web-vitals which doesn't support IE11

import './surveys'
import './exception-autocapture'
import './tracing-headers'
import './array.no-external'
Loading

0 comments on commit 6313e1d

Please sign in to comment.