Skip to content

Commit f2c2b76

Browse files
authored
Add page-tools library (#1271)
1 parent bc32a3d commit f2c2b76

File tree

29 files changed

+1355
-13
lines changed

29 files changed

+1355
-13
lines changed

.buildkite/pipeline.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,24 @@ steps:
114114
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
115115
paths: ['.yarn/cache/']
116116

117-
- label: '[Generic Utils] Lint + Test'
117+
- label: '[Misc Utils] Lint + Test'
118118
agents:
119119
queue: v1
120120
commands:
121121
- npm config set "//registry.npmjs.org/:_authToken" $${NPM_TOKEN}
122122
- echo "--- Install dependencies"
123123
- PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 HUSKY=0 yarn install --immutable
124-
- echo "+++ Run QA"
124+
- echo "+++ Run QA for generic-utils"
125125
- yarn turbo run --filter=@segment/analytics-generic-utils lint
126126
- yarn turbo run --filter=@segment/analytics-generic-utils test
127+
- echo "+++ Run QA for page-tools"
128+
- yarn turbo run --filter=@segment/analytics-page-tools lint
129+
- yarn turbo run --filter=@segment/analytics-page-tools test
127130
plugins:
128131
- ssh://[email protected]/segmentio/cache-buildkite-plugin#v2.0.0:
129132
key: "v1.1-cache-dev-{{ checksum 'yarn.lock' }}"
130133
paths: ['.yarn/cache/']
134+
131135

132136
- label: '[Consent] Lint + Test'
133137
agents:

.changeset/bright-readers-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': minor
3+
---
4+
5+
Refactor to use page-tools package

.changeset/wet-waves-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-page-tools': major
3+
---
4+
5+
Release package

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@changesets/cli": "^2.23.2",
4040
"@microsoft/api-extractor": "^7.47.9",
4141
"@npmcli/promise-spawn": "^7.0.0",
42+
"@swc/core": "^1.11.18",
4243
"@types/express": "4",
4344
"@types/jest": "^29.5.11",
4445
"@types/lodash": "^4",
@@ -62,6 +63,7 @@
6263
"prettier": "^2.6.2",
6364
"ts-jest": "^29.1.1",
6465
"ts-node": "^10.8.0",
66+
"tsup": "^8.4.0",
6567
"turbo": "^2.3.4",
6668
"typescript": "^4.7.0",
6769
"webpack": "^5.94.0",

packages/browser/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
umd.old

packages/browser/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@lukeed/uuid": "^2.0.0",
5353
"@segment/analytics-core": "1.8.1",
5454
"@segment/analytics-generic-utils": "1.2.0",
55+
"@segment/analytics-page-tools": "0.0.1",
5556
"@segment/analytics.js-video-plugins": "^0.2.1",
5657
"@segment/facade": "^3.4.9",
5758
"dset": "^3.1.4",
@@ -79,6 +80,7 @@
7980
"aws-sdk": "^2.814.0",
8081
"circular-dependency-plugin": "^5.2.2",
8182
"compression-webpack-plugin": "^8.0.1",
83+
"ecma-version-validator-webpack-plugin": "^1.2.1",
8284
"execa": "^4.1.0",
8385
"flat": "^5.0.2",
8486
"fs-extra": "^9.0.1",

packages/browser/scripts/umd-diff.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
# This script is for detecting how the webpack build has changed.
4+
5+
# 1. yarn umd && cp dist/umd dist/umd.old
6+
# 2. make changes to your webpack config
7+
# 3. `bash scripts/umd-diff.sh` to see changes
8+
9+
# Ensure the script stops on errors
10+
set -e
11+
12+
# Define directories
13+
DIST_DIR="./dist/umd"
14+
TMP_DIR="./dist/umd.old"
15+
16+
# Run the UMD build
17+
echo "Running 'yarn umd' to compile into $DIST_DIR..."
18+
yarn umd
19+
20+
# Check if the temporary directory exists
21+
if [ ! -d "$TMP_DIR" ]; then
22+
echo "Temporary directory $TMP_DIR does not exist. Exiting."
23+
exit 1
24+
fi
25+
26+
# Compare the directories
27+
echo "Comparing $DIST_DIR with $TMP_DIR..."
28+
if command -v colordiff &> /dev/null; then
29+
# Use colordiff if available for a prettier diff
30+
diff -r "$DIST_DIR" "$TMP_DIR" | grep -E "^(Only in|diff|@@)" | colordiff
31+
fi
32+
33+
rm
34+
# Print completion message
35+
echo "Comparison complete."

packages/browser/src/core/buffer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { version } from '../../generated/version'
66
import { getGlobalAnalytics } from '../../lib/global-analytics-helper'
77
import {
88
isBufferedPageContext,
9-
BufferedPageContext,
109
getDefaultBufferedPageContext,
1110
createPageContext,
11+
BufferedPageContext,
1212
PageContext,
1313
} from '../page'
1414
import { getVersionType } from '../../lib/version-type'

packages/browser/src/core/page/add-page-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pick } from '../../lib/pick'
22
import { EventProperties, SegmentEvent } from '../events'
3-
import { getDefaultPageContext } from './get-page-context'
3+
import { getDefaultPageContext } from '@segment/analytics-page-tools'
44

55
/**
66
* Augments a segment event with information about the current page.
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
export * from './get-page-context'
1+
export {
2+
BufferedPageContextDiscriminant,
3+
createBufferedPageContext,
4+
createPageContext,
5+
getDefaultBufferedPageContext,
6+
getDefaultPageContext,
7+
isBufferedPageContext,
8+
type PageContext,
9+
type BufferedPageContext,
10+
} from '@segment/analytics-page-tools'
11+
212
export * from './add-page-context'

0 commit comments

Comments
 (0)