[javascript] Create @seleniumhq/atoms npm package from TypeScript atoms - #17459
Open
AutomatedTester wants to merge 2 commits into
Open
AutomatedTester wants to merge 2 commits into
AutomatedTester wants to merge 2 commits into
Conversation
Refactors the three TypeScript atoms (get-attribute, find-elements,
is-displayed) from IIFE closures to proper ES modules with export
default, then produces two compilation targets from the same sources:
- IIFE path (language bindings): ts_project --module commonjs →
cjs-to-iife.js → browser-injectable (function(){…return fn;})()
so py/rb/java/dotnet consumers are unchanged.
- npm path: ts_project --module esnext + declaration → dist/ published
as @seleniumhq/atoms with full TypeScript type declarations.
Key changes:
* Remove outer IIFE from all three atom .ts files; add export default.
* Add cjs-to-iife.js replacing strip-trailing-semicolon.js in the
IIFE pipeline. Strips CJS boilerplate and wraps the body in an IIFE
that returns the exported default function.
* Update wrap-as-global scripts to parse CJS-compiled input instead of
asserting (function () at the start.
* Switch BUILD.bazel from js_run_binary+tsc(--module none --outFile)
to ts_project for each atom, plus a new npm_package target.
* Add tsconfig.json (esnext, declaration) and tsconfig-cjs.json for
the two compilation paths.
* Add index.ts as the package entry point.
* Promote javascript/atoms/package.json to @seleniumhq/atoms v4.45.x.
* Add get_attribute_typescript and find-elements-typescript CJS module
targets to selenium-webdriver/lib/atoms/BUILD.bazel.
All 25 Python unit tests pass; //javascript/atoms:closure-test passes.
…roject targets When multiple ts_project targets share a single tsconfig with no files/include restriction, tsc compiles all .ts files for each target. On Windows, Bazel marks outputs read-only after the first action completes; parallel actions then fail with TS5033 EPERM trying to overwrite the same files. Give each per-atom ts_project its own tsconfig that lists only the one .ts file it is responsible for, eliminating the cross-target output collision.
AutomatedTester
force-pushed
the
priceless-cannon-76a1b6
branch
from
October 5, 2026 12:34
0c73842 to
8146e8d
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Related Issues
Builds on the Closure → TypeScript atom migrations (#17458 and siblings), which are already on trunk.
💥 What does this PR do?
Turns the three TypeScript atoms (
get-attribute,find-elements,is-displayed) into real ES modules and compiles them down two independent paths from the same sources:ts_projectwith--module commonjs, then a newcjs-to-iife.jspost-processor emits browser-injectable(function(){ … return fn; })(). Python, Ruby, Java and .NET consumers see byte-compatible output and are unchanged.ts_projectwith--module esnext,declaration,declarationMapandsourceMapintodist/, packaged as@seleniumhq/atomswith full.d.tstype declarations.Both paths type-check the same
.tssources, so the published package and the injected atoms can't drift apart.🔧 Implementation Notes
Atom sources
get-attribute.ts,find-elements.tsandis-displayed.ts; each now ends inexport default <fn>.index.tsas the package entry point, re-exporting the three atoms asgetAttribute,findElementsandisDisplayed.Build wiring (
javascript/atoms/BUILD.bazel)js_run_binary+tsc --module none --outFileinvocations withts_projecttargets.strip_trailing_semicolonbinary withcjs_to_iife, which strips the CommonJS boilerplatetscemits and wraps the remaining body in an IIFE returning the default export.wrap-*-as-global.jsscripts to parse CJS-compiled input rather than asserting the file starts with(function () {.atoms-npm-compiled(ts_project→dist/) andselenium-atoms-package(npm_package,publishable = True, taggedrelease-artifact).One tsconfig per
ts_projecttargetEach atom gets its own
tsconfig-<atom>.jsonwith a single-entryfileslist, rather than sharing onetsconfig-cjs.jsonacross all three. A shared tsconfig makes severalts_projecttargets declare the same file as an input, which Bazel materialises concurrently into the same sandbox path — on Windows that races and fails withEPERM. Per-target configs give each action a disjoint input set. (tsconfig.jsonat the package root stays shared, because onlyatoms-npm-compileduses it.)Package metadata
javascript/atoms/package.jsonis promoted to@seleniumhq/atomswithexportsentries for the package root and each individual atom.✅ Verification
bazel build //javascript/atoms:selenium-atoms-package //javascript/atoms:atoms-npm-compiledplus the three*-typescript-compiledtargets — clean.bazel build //javascript/selenium-webdriver/lib/atoms:all //rb/lib/selenium/webdriver/atoms:all— clean; the generated IIFE output still ends inreturn get; })();, so the injection path is unchanged for bindings.💡 Additional Considerations
package.jsoncurrently declares"main": "./dist/index.cjs"and a"require"condition on every export, but the npm path only emits ESM.js+.d.ts— no.cjsis produced. Either the CJS conditions should be dropped (ESM-only package) or a secondts_projectshould emit the.cjsoutputs before this is published. Flagging for a decision before release.🤖 AI assistance
🔄 Types of changes