Skip to content

chore: migrate toolchain to TypeScript 5.5, Vite, Vitest, and ESLint v9#84

Merged
alexs-mparticle merged 8 commits intodevelopmentfrom
feat/typescript-vite-vitest-migration
Apr 8, 2026
Merged

chore: migrate toolchain to TypeScript 5.5, Vite, Vitest, and ESLint v9#84
alexs-mparticle merged 8 commits intodevelopmentfrom
feat/typescript-vite-vitest-migration

Conversation

@mattbodle
Copy link
Copy Markdown
Collaborator

@mattbodle mattbodle commented Apr 2, 2026

Summary

  • Migrates source from src/Rokt-Kit.js (ES5) to src/Rokt-Kit.ts (TypeScript 5.5, strict mode, class-based)
  • Replaces Rollup v1 with Vite (library mode, explicit target: 'es2020') producing IIFE + CJS bundles + .d.ts type declarations
  • Replaces the legacy manual Mocha HTML runner (test/index.html) with Vitest + jsdom (158 tests, headless — no automated real-browser testing existed before)
  • Replaces ESLint v7 .eslintrc with ESLint v9 flat config (eslint.config.mjs)
  • Updates Prettier to 120-char width, single quotes, trailing commas
  • Bumps .nvmrc to Node 24
  • Adds npm run build:watch for local development (Vite watch mode)

Browser baseline: The emitted IIFE targets ES2020 (const, let, class, ??, ?.). This is the first explicit browser target — no baseline existed before. Real-browser smoke testing can be added in a follow-up if needed.

Test plan

  • npm run lint — zero errors
  • npm run build — produces dist/Rokt-Kit.iife.js, dist/Rokt-Kit.common.js, dist/Rokt-Kit.d.ts
  • npm run build:watch — watches for changes and rebuilds
  • npm run test — 158/158 tests pass in Vitest/jsdom

🤖 Generated with Claude Code

Replaces the 2019-era ES5/Rollup/Karma/Mocha/Chai stack with a modern
toolchain aligned with the internal sdk-web repo:

- Source: src/Rokt-Kit.js → src/Rokt-Kit.ts (class-based, strict mode)
- Build: Rollup v1 → Vite (IIFE + CJS + .d.ts via vite-plugin-dts)
- Tests: Karma + Mocha/Chai → Vitest + jsdom (158 tests passing)
- Lint: ESLint v7 (.eslintrc) → ESLint v9 flat config (eslint.config.mjs)
- Prettier: updated to 120-char width, single quotes, trailing commas
- Node: .nvmrc bumped to 24

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mattbodle
Copy link
Copy Markdown
Collaborator Author

Background: this PR replaces both the build tool and the test runner for a browser SDK. The description lists the mechanical changes, but it does not say whether browser support changes or what replaces the old real-browser verification.

Please add that context explicitly. Missing in this PR description: the supported browser baseline after the Vite build, whether dropping Chrome and Firefox coverage is intentional, and whether a browser-level smoke test is coming in a follow-up PR.

-Codex

import { resolve } from 'path';

export default defineConfig({
build: {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Background: this build now ships a materially different browser target from the current release. The emitted dist/Rokt-Kit.iife.js contains const, let, class, arrow functions and ??, while the previous bundle was ES5-style. For a kit that is injected into merchant pages, that is a breaking runtime change unless we have explicitly raised the browser baseline.

Please set an explicit supported build target and verify the published IIFE against it before merging.

-Codex

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done — added target: 'es2020' to vite.config.ts. The IIFE now has an explicit browser baseline. Added a note to the PR description clarifying this is the first explicit target (no baseline existed before).

"build": "vite build",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
"lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.ts\" --fix",
"test": "vitest run",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Background: after this change the executed suite is test/src/**/*.spec.ts, but the old Karma harness still stays in-tree: test/src/tests.js, test/index.html, test/config.js and test/lib/mockhttprequest.js. That leaves a second, dead test path in the repo and adds maintenance cost to a migration PR that is supposed to simplify the toolchain.

Delete the legacy harness in the same PR, or call out clearly why it needs to stay.

-Codex

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done — deleted test/src/tests.js, test/index.html, test/config.js, and test/lib/mockhttprequest.js in commit 7d03487.

src/Rokt-Kit.ts Outdated

const selection = this.launcher!.selectPlacements(selectPlacementsOptions);

// After selection resolves, sync the Rokt session ID back to mParticle
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Background: this works, but the same side-effect is repeated in four branches, which makes the success and failure flow harder to scan than it needs to be. Normalising the result to one promise and logging once in a terminal branch would read more cleanly.

For example:

const logSelection = () => this.logSelectPlacementsEvent(selectPlacementsAttributes);

void Promise.resolve(selection)
  .then((sel) => sel?.context?.sessionId?.then((sessionId) => this.setRoktSessionId(sessionId)))
  .catch(() => undefined)
  .finally(logSelection);

That keeps the monadic flow in one place and makes the side-effects explicit.

-Codex

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done — adopted the single Promise.resolve() chain with .finally() for the log, as suggested. Fixed in 7d03487.

- Set explicit build target (es2020) in vite.config.ts
- Refactor selectPlacements to use a single functional promise chain
- Delete legacy Mocha HTML test harness (tests.js, index.html, config.js, mockhttprequest.js)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mattbodle
Copy link
Copy Markdown
Collaborator Author

Re: @mattbodle's comment: The old test harness was a manual Mocha HTML page (test/index.html) — no automated browser testing existed before, so no Chrome/Firefox coverage is being dropped. The PR description has been updated to reflect this and to call out that es2020 is the first explicit browser target.

getUserIdentities?: () => { userIdentities: Record<string, string> };
}

interface KitFilters {
Copy link
Copy Markdown
Collaborator

@alexs-mparticle alexs-mparticle Apr 3, 2026

Choose a reason for hiding this comment

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

Nit: Can this be imported from the core SDK type definitions?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't see how they are exported from the core SDK - are they published separately somewhere?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

@rmi22186 rmi22186 Apr 8, 2026

Choose a reason for hiding this comment

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

we are going to create all of these into the core sdk, then pull the types from the core sdk. so for now i'd ignore. we'll pull these in in the future

filteredUser?: FilteredUser | null;
}

interface RoktManager {
Copy link
Copy Markdown
Collaborator

@alexs-mparticle alexs-mparticle Apr 3, 2026

Choose a reason for hiding this comment

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

Nit: Can this be imported from the core SDK type definitions?

mattbodle and others added 4 commits April 7, 2026 07:50
…vitest-migration

# Conflicts:
#	src/Rokt-Kit.js
#	test/src/tests.js
- Rename KitSettings → RoktKitSettings
- Replace mergeObjects() with spread operators throughout
- Remove non-null assertions on window.Rokt.__event_stream__ calls
- Make EventDataType and EventCategory required in MParticleEvent; remove ?? 0 fallbacks
- Add MESSAGE_TYPE_PROFILE constant to replace magic number 14
- Add ESM build output (vite.config.ts formats + package.json module/exports/files)
- Remove test:ui script (vitest --ui is optional dev tooling, not needed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Port of efb8905 from main into TypeScript. Adds ErrorReportingService,
LoggingService, ReportingTransport, and RateLimiter classes with full
test coverage (42 new tests).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Resolves modify/delete conflicts by keeping src/Rokt-Kit.js and
test/src/tests.js deleted — replaced by their TypeScript equivalents
in this branch.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
getUserIdentities?: () => { userIdentities: Record<string, string> };
}

interface KitFilters {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

@alexs-mparticle alexs-mparticle left a comment

Choose a reason for hiding this comment

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

LGTM. Once @rmi22186's comments are approved, I think we can merge this.

@rmi22186 rmi22186 changed the base branch from main to development April 8, 2026 15:06
@alexs-mparticle alexs-mparticle merged commit fcecf32 into development Apr 8, 2026
5 checks passed
github-actions bot pushed a commit that referenced this pull request Apr 8, 2026
# [1.23.0](v1.22.0...v1.23.0) (2026-04-08)

### Features

* migrate toolchain to TypeScript 5.5, Vite, Vitest, and ESLint v9 ([#84](#84)) ([58f6b41](58f6b41))
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.

3 participants