chore: add element selector package#1777
Conversation
75bfd6a to
b07c1d8
Compare
size-limit report 📦
|
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
660ad25 to
b6a7080
Compare
There was a problem hiding this comment.
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.
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.
b6a7080 to
b5fb5b7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
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.
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'; |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit b5fb5b7. Configure here.



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
Note
Low Risk
Adds an isolated new package with placeholder exports and no integration into autocapture or other consumers yet.
Overview
Introduces
@amplitude/element-selectoras 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 withjsdom(coverage thresholds deferred), lint/build scripts aligned with sibling packages, and a minimalsrc/index.tsentry that exportsPACKAGE_NAME/PACKAGE_VERSIONplus a smoke test.pnpm-lock.yamlregisters the package with atslibdependency.Reviewed by Cursor Bugbot for commit b5fb5b7. Bugbot is set up for automated code reviews on this repo. Configure here.