Skip to content

chore: add element selector package#1777

Open
jxiwang wants to merge 4 commits into
mainfrom
jessewang/sr-4560-eng-001-set-up-amplitudeelement-selector-package
Open

chore: add element selector package#1777
jxiwang wants to merge 4 commits into
mainfrom
jessewang/sr-4560-eng-001-set-up-amplitudeelement-selector-package

Conversation

@jxiwang
Copy link
Copy Markdown
Collaborator

@jxiwang jxiwang commented May 27, 2026

Summary

Scaffolds the new @amplitude/element-selector package so our selector algorithm has a home shared by autocapture, zoning UI, and the Chrome extension — no algorithm code yet, just the package shell.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

Note

Low Risk
Adds an isolated new package with placeholder exports and no integration into autocapture or other consumers yet.

Overview
Introduces @amplitude/element-selector as a new workspace package intended to host a shared DOM element-selector algorithm for autocapture, dashboard zoning UI, and the Chrome extension. This PR adds only the package shell—no selector logic yet.

The scaffold includes standard monorepo wiring: dual CJS/ESM builds via tsconfig.es5.json / tsconfig.esm.json, Jest with jsdom (coverage thresholds deferred), lint/build scripts aligned with sibling packages, and a minimal src/index.ts entry that exports PACKAGE_NAME / PACKAGE_VERSION plus a smoke test. pnpm-lock.yaml registers the package with a tslib dependency.

Reviewed by Cursor Bugbot for commit b5fb5b7. Bugbot is set up for automated code reviews on this repo. Configure here.

@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 27, 2026

SR-4560

@jxiwang jxiwang force-pushed the jessewang/sr-4560-eng-001-set-up-amplitudeelement-selector-package branch from 75bfd6a to b07c1d8 Compare May 27, 2026 20:20
@jxiwang jxiwang changed the title Jessewang/sr 4560 eng 001 set up amplitudeelement selector package chore: add element selector package May 27, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 27, 2026

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 58.31 KB (0%)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 131.96 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 208.94 KB (0%)

@jxiwang jxiwang marked this pull request as ready for review May 27, 2026 21:23
@jxiwang jxiwang force-pushed the jessewang/sr-4560-eng-001-set-up-amplitudeelement-selector-package branch from 660ad25 to b6a7080 Compare May 27, 2026 22:49
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Autofix Details

Bugbot Autofix prepared fixes for both issues found in the latest run.

  • ✅ Fixed: Radix regex requires colon, won't match non-colon ids
    • Changed regex from /^radix-:/ to /^radix-/ to match both colon-prefixed and non-colon Radix UI IDs.
  • ✅ Fixed: CSS modules regex too restrictive for short class names
    • Changed middle segment quantifier from {5,} to + to allow short class names like 'root' while keeping 5+ char hash requirement.

Create PR

Or push these changes by commenting:

@cursor push 7b6033e2db
Preview (7b6033e2db)
diff --git a/packages/element-selector/src/patterns/autogenerated-ids.ts b/packages/element-selector/src/patterns/autogenerated-ids.ts
--- a/packages/element-selector/src/patterns/autogenerated-ids.ts
+++ b/packages/element-selector/src/patterns/autogenerated-ids.ts
@@ -18,7 +18,7 @@
   // React useId() — ":r0:", ":r1:", ":rk:". Stable for one render; new id on next mount.
   /^:r[0-9a-z]+:$/,
   // Radix UI primitives — "radix-:r3:", "radix-A1B2C3". Prefix match.
-  /^radix-:/,
+  /^radix-/,
   // Headless UI (Tailwind Labs) — "headlessui-menu-button-:r5:". Prefix match.
   /^headlessui-/,
   // MUI internal id prefix — "mui-12345". Don't confuse with Mui-* CSS class state markers.

diff --git a/packages/element-selector/src/patterns/unstable-classes.ts b/packages/element-selector/src/patterns/unstable-classes.ts
--- a/packages/element-selector/src/patterns/unstable-classes.ts
+++ b/packages/element-selector/src/patterns/unstable-classes.ts
@@ -47,7 +47,7 @@
   // Emotion: css-1abcd23, css-9xyzkw0.
   /^css-[a-z0-9]{6,}$/,
   // CSS modules: Button_root__abc123, Card_container__xyz789.
-  /^[a-zA-Z]+_[a-zA-Z0-9]{5,}__[a-zA-Z0-9]{5,}$/,
+  /^[a-zA-Z]+_[a-zA-Z0-9]+__[a-zA-Z0-9]{5,}$/,
   // styled-components: sc-bdVaJa, sc-1jjuPXC0.
   /^sc-[a-zA-Z0-9]{6,}$/,
   // styled-jsx (Next.js): jsx-1234567.

You can send follow-ups to the cloud agent here.

Comment thread packages/element-selector/src/patterns/autogenerated-ids.ts Outdated
Comment thread packages/element-selector/src/patterns/unstable-classes.ts Outdated
@jxiwang jxiwang force-pushed the jessewang/sr-4560-eng-001-set-up-amplitudeelement-selector-package branch from b6a7080 to b5fb5b7 Compare May 27, 2026 23:01
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Hardcoded version lacks auto-sync with package.json
    • Added version-file script and version lifecycle hook to auto-generate src/version.ts from package.json, following the pattern used by other packages in the monorepo.

Create PR

Or push these changes by commenting:

@cursor push 566766beb7
Preview (566766beb7)
diff --git a/packages/element-selector/package.json b/packages/element-selector/package.json
--- a/packages/element-selector/package.json
+++ b/packages/element-selector/package.json
@@ -31,7 +31,9 @@
     "lint:eslint": "eslint '{src,test}/**/*.ts'",
     "lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
     "test": "jest",
-    "typecheck": "tsc -p ./tsconfig.json"
+    "typecheck": "tsc -p ./tsconfig.json",
+    "version": "pnpm version-file && pnpm build",
+    "version-file": "node -p \"'export const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts"
   },
   "bugs": {
     "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"

diff --git a/packages/element-selector/src/index.ts b/packages/element-selector/src/index.ts
--- a/packages/element-selector/src/index.ts
+++ b/packages/element-selector/src/index.ts
@@ -10,4 +10,4 @@
  */
 
 export const PACKAGE_NAME = '@amplitude/element-selector';
-export const PACKAGE_VERSION = '0.1.0';
+export { VERSION as PACKAGE_VERSION } from './version';

diff --git a/packages/element-selector/src/version.ts b/packages/element-selector/src/version.ts
new file mode 100644
--- /dev/null
+++ b/packages/element-selector/src/version.ts
@@ -1,0 +1 @@
+export const VERSION = '0.1.0';

You can send follow-ups to the cloud agent here.

Reviewed by Cursor Bugbot for commit b5fb5b7. Configure here.

*/

export const PACKAGE_NAME = '@amplitude/element-selector';
export const PACKAGE_VERSION = '0.1.0';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded version lacks auto-sync with package.json

Low Severity

PACKAGE_VERSION is hardcoded to '0.1.0' in src/index.ts, but other packages in this monorepo that export a version constant (e.g., analytics-browser, plugin-autocapture-browser) use a version-file script plus a version lifecycle hook to auto-generate it from package.json. Without that mechanism, the exported constant will silently drift from the actual package version when it gets bumped — especially once the "private": true flag is removed for publishing.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit b5fb5b7. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants