Skip to content

Move module browser scripts and Tinybird into their crates - #1423

Draft
jwrosewell wants to merge 6 commits into
feature/54-asset-routesfrom
feature/55-scripts-in-crates
Draft

jwrosewell wants to merge 6 commits into
feature/54-asset-routesfrom
feature/55-scripts-in-crates

Conversation

@jwrosewell

@jwrosewell jwrosewell commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Changes

Area Change
crates/trusted-server-js/lib 10 files, 277 lines added, 37 removed
crates/ad-tag/google 31 files, 145 lines added, 152 removed
crates/trusted-server-js/build 1 file, 144 lines added, 27 removed
docs/superpowers 1 file, 119 lines added, 0 removed
crates/trusted-server-js/build.rs 1 file, 46 lines added, 5 removed
crates/trusted-server-js/README.md 1 file, 18 lines added, 4 removed
crates/cmp/sourcepoint 5 files, 16 lines added, 16 removed
docs/guide 6 files, 16 lines added, 11 removed
crates/.prettierrc.json 1 file, 13 lines added, 0 removed
crates/eslint.config.js 1 file, 11 lines added, 0 removed
crates/tsconfig.json 1 file, 10 lines added, 0 removed
crates/analytics/tinybird 20 files, 5 lines added, 2 removed
crates/audience/permutive 4 files, 5 lines added, 5 removed
crates/tag/google-tag-manager 3 files, 5 lines added, 5 removed
crates/testing/testlight 1 file, 4 lines added, 4 removed
crates/bot-protection/datadome 3 files, 3 lines added, 3 removed
crates/cmp/didomi 2 files, 3 lines added, 3 removed
crates/identity/lockr 3 files, 3 lines added, 7 removed
AGENTS.md 1 file, 2 lines added, 2 removed
CHANGELOG.md 1 file, 2 lines added, 0 removed
crates/cmp/osano 2 files, 2 lines added, 2 removed
.github/workflows 1 file, 1 line added, 1 removed
crates/trusted-server-core/src 1 file, 1 line added, 1 removed

Closes

Part of #777

Spec

Spec: module-scripts-in-crates

Test plan

CI on this pull request at 5be1147 passed all 27 checks.

  • cargo test-fastly && cargo test-axum
  • cargo clippy-fastly && cargo clippy-axum
  • cargo fmt --all -- --check
  • JS tests: cd crates/trusted-server-js/lib && npx vitest run
  • JS format: cd crates/trusted-server-js/lib && npm run format
  • Docs format: cd docs && npm run format
  • WASM build: cargo build --package trusted-server-adapter-fastly --release --target wasm32-wasip1
  • Manual testing via fastly compute serve
  • Other: the full workflow set of this repository, run on this pull request at 5be1147

Checklist

  • Changes follow AGENTS.md conventions
  • No unwrap() in production code (clippy denies unwrap_used in CI)
  • Uses log macros as AGENTS.md asks (not println!)
  • New code has tests
  • No secrets or credentials committed

Stacks on the asset routes served on every adapter (#1412).

What this pull request does

The design is module-scripts-in-crates. Each vendor module's Rust lives in its own crate, but its browser script, the script's tests and some of their test data lived in the shared trusted-server-js crate, under lib/src/integrations/<module>/ and lib/test/integrations/<module>/. This change moves ten modules' scripts and tests into the nine crates that supply them, as js/src/<module>/ and js/test/<module>/, and moves the Tinybird project from tinybird/ into crates/analytics/tinybird/project/.

Module Crate
datadome crates/bot-protection/datadome
didomi crates/cmp/didomi
google_tag_manager crates/tag/google-tag-manager
gpt crates/ad-tag/google
gpt_diagnostics crates/ad-tag/google
lockr crates/identity/lockr
osano crates/cmp/osano
permutive crates/audience/permutive
sourcepoint crates/cmp/sourcepoint
testlight crates/testing/testlight
  • moduleSourceDirs() in lib/build-module-options.mjs and expected_module_ids in build/bundle_set.rs apply one rule, lib/src/integrations/<name> or crates/<type>/<crate>/js/src/<name>, refuse a name found twice or the name core, and pass over a broken link or a file, with tests on both sides. build.rs watches each crate's js/src folder that exists.
  • A script in a crate imports the shared browser code as @tsjs/core/... and @tsjs/shared/..., another module's code as @tsjs/module/<name>/..., and shared test data as @tsjs/test/.... It cannot import an npm package, because packages resolve only from lib's node_modules.
  • Vitest, TypeScript, ESLint and Prettier cover the crates' js/src and js/test folders, and the CI commands are unchanged. crates/ holds a tsconfig.json, an ESLint config and a Prettier config that apply lib's settings there.
  • Bundles keep their tsjs-<name>.js names, so the Rust API, the served URLs and every content hash are unchanged. The only change a reader receives is three comment lines in crates/ad-tag/google/src/gpt_bootstrap.js, which the GPT module inlines into pages and which named the GPT script's old path.
  • The APS renderer stays in the shared crate, because the browser core imports it. Prebid stays, because its shim imports an npm package and the ts prebid client command runs its bundle build from the shared crate. The vendor names in the browser core stay. Each is a later change, and the design says why.

How it was verified

Locally on Windows at 0e0d3aa, against row 54 at 1dde36e:

  • Each of the 14 bundles build-all.mjs writes has the same SHA-256 as on row 54.
  • npm run lint and npm run format pass, and a planted unused variable in a crate's script makes npm run lint fail.
  • npx vitest run passes 1254 tests, including the discovery tests and the checks of the editor settings and the @tsjs/module list. The two build-prebid-external tests that create symlinks fail on Windows, as they do on row 54. The type gate covers the moved GPT diagnostics contract test, which a planted false assertion makes fail.
  • tsc --noEmit -p tsconfig.json in lib reports no error it does not report on row 54.
  • cargo test and cargo clippy -- -D warnings pass for trusted-server-js at 0e0d3aa, and for trusted-server-ad-tag-google, whose recorded page-change fixture changed, at 338b648, after which nothing in that crate changes. cargo fmt --all -- --check passes.
  • The design had two review rounds in fresh sessions, recorded in its review log.

A vendor module's Rust lives in crates/<type>/<vendor>/, while its
browser script, the script's tests and some test data live in the
shared trusted-server-js crate. The design moves ten modules' scripts
and tests into the nine crates that supply them, makes the build, the
tests, the lint and format checks and editors find them there, and
moves the Tinybird project into the Tinybird crate.

It records what stays in the shared crate and why, being the APS
renderer, which the browser core imports, Prebid, whose shim imports an
npm package and whose bundle build the CLI runs from the shared crate,
and the vendor names still in the browser core. Its review log records
round 1.
Ten modules' browser scripts and their tests move from the shared
trusted-server-js crate into the nine crates that supply the modules,
as js/src/<module>/ and js/test/<module>/: datadome, didomi,
google_tag_manager, gpt and gpt_diagnostics, lockr, osano, permutive,
sourcepoint and testlight. The GPT tests' helper that locates
gpt_bootstrap.js moves with them.

moduleSourceDirs() in build-module-options.mjs and expected_module_ids
in build/bundle_set.rs apply one rule, lib/src/integrations/<name> or
crates/<type>/<crate>/js/src/<name>, refuse a name found in two places
or the name core, and pass over a broken link, with tests on both
sides. build.rs watches build-module-options.mjs and each crate's
js/src folder that exists. Bundles keep their tsjs-<name>.js names, so
the Rust API, served URLs and content hashes are unchanged, and all 14
built bundles are byte for byte the same as before.

Scripts reach the shared browser code as @tsjs/core/... and
@tsjs/shared/..., another module's code as @tsjs/module/<name>/...,
and shared test data as @tsjs/test/.... tsconfig.json lists each
crate's js/src folder for @tsjs/module, and a test checks the list.
Vitest, ESLint and Prettier cover the crates' js/src and js/test
folders, and crates/ holds a tsconfig.json, an ESLint config and a
Prettier config so that editors and the npm scripts apply the shared
settings there. The type gate covers the moved GPT diagnostics contract
test.

Comments and guides that named the old paths name the new ones. Three
are comment lines in gpt_bootstrap.js, which the GPT module inlines
into each page it changes, so readers receive those three lines with
the new path, and the recorded page-change fixture changes with them.
The tsjs guide now counts 13 source modules and 14 bundles, adding
ec_client_fixed.

The APS renderer stays in the shared crate because the browser core
imports it, and Prebid stays because its shim imports an npm package
and the ts prebid client command runs its bundle build from the shared
crate.
The Tinybird project the analytics module sends to, its datasources,
pipes, fixtures and tests, moves from tinybird/ at the repository root
to crates/analytics/tinybird/project/, beside the module's Rust.

Its README's links to the telemetry and configuration guides follow
the move, the crate's README points at the project, the telemetry and
configuration guides' links follow it, the Markdown format list in
format.yml and AGENTS.md drops tinybird/**/*.md, which crates/**/*.md
covers, and the changelog gives the new folder, because an operator
runs tb from it.
Rust discovery passes over a module root that is a file, as the
JavaScript side does. crates/tsconfig.json takes in the shared core's
global.d.ts, so an editor checks a crate script as lib's TypeScript run
does, and build.rs watches it, because Vite reads it when it compiles a
crate script. The format check covers .mjs files and the configuration
files in crates/, which crates/.prettierrc.json formats with lib's
options. The design and the README say how ESLint finds the crates
config, how modules kept in lib import each other, and that a Tinybird
change starts the documentation proposal workflow, and the design's
review log records round 2.
The module scripts design names #1423, the
draft pull request that carries it, in its status and related pull
requests, as the stack's other designs do.
jwrosewell added a commit to jwrosewell/trusted-server that referenced this pull request Oct 20, 2026
The design of row 55, IABTechLab#1423, joins the specs
pull request that carries every design of the stack, with the same
text as on that row's branch.
The crate's tests run as WebAssembly under Viceroy in CI, where
std::env::temp_dir panics, so the three discovery tests that built
folders in a scratch tree aborted the cargo test job. The folder walk
now hands what it found to module_ids, which applies the naming rules
and is tested with in-memory folders. The JavaScript tests still walk
a scratch tree. The design says why.
jwrosewell added a commit to jwrosewell/trusted-server that referenced this pull request Oct 20, 2026
The design now says why the Rust discovery tests run without a file
system, the same text as on the branch of IABTechLab#1423.
@jwrosewell
jwrosewell added this pull request to stack #1422 October 20, 2026 07:11

This branch has not been deployed

No deployments
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.

1 participant