Skip to content

Commit 441a0a5

Browse files
refactor(audience): trim redundant comments on CDN bundle files
- Drops narrative module headers from cdn.ts, cdn.test.ts, tsup.cdn.js. - Keeps one-line WHY comments only, matching tsup.config.js and pixel/tsup.config.ts density. Refs SDK-115
1 parent c58d1f8 commit 441a0a5

File tree

3 files changed

+6
-68
lines changed

3 files changed

+6
-68
lines changed

packages/audience/sdk/src/cdn.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/**
2-
* Smoke test for the CDN entry point. Verifies that importing `./cdn`
3-
* attaches { Audience, AudienceError, IdentityType, version } to
4-
* window.ImmutableAudience.
5-
*
6-
* This tests the contract of cdn.ts — not the tsup build output. The bundle
7-
* itself is exercised by running `pnpm build` and loading the built file in
8-
* a browser.
9-
*/
101
import type { ImmutableAudienceGlobal } from './cdn';
112

123
describe('cdn entry point', () => {
@@ -33,7 +24,6 @@ describe('cdn entry point', () => {
3324
expect(typeof g!.version).toBe('string');
3425
expect(g!.version.length).toBeGreaterThan(0);
3526

36-
// AudienceError should be constructable and extend Error
3727
const err = new g!.AudienceError({
3828
code: 'NETWORK_ERROR',
3929
message: 'test',

packages/audience/sdk/src/cdn.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,23 @@
1-
/**
2-
* CDN bundle entry point.
3-
*
4-
* Side-effect module: importing this file attaches Audience, AudienceError,
5-
* and IdentityType to `window.ImmutableAudience` so the SDK can be consumed
6-
* via a <script> tag.
7-
*
8-
* DO NOT import this from application code — use `import { Audience } from
9-
* '@imtbl/audience'` instead. This file exists solely as the entry point
10-
* for the CDN build (packages/audience/sdk/tsup.cdn.js).
11-
*/
12-
131
import { AudienceError, IdentityType } from '@imtbl/audience-core';
142

153
import { Audience } from './sdk';
164
import { LIBRARY_VERSION } from './config';
175

18-
/**
19-
* The shape of `window.ImmutableAudience` attached by the CDN bundle.
20-
* Type-only export — importing this module otherwise has runtime side effects,
21-
* which is why the file's `DO NOT import this` warning above only applies to
22-
* value imports. The CDN smoke test imports this type to keep its assertions
23-
* in lockstep with the real surface, eliminating the need for a duplicate
24-
* definition.
25-
*/
266
export type ImmutableAudienceGlobal = {
277
Audience: typeof Audience;
288
AudienceError: typeof AudienceError;
299
IdentityType: typeof IdentityType;
3010
version: string;
3111
};
3212

33-
// globalThis is ES2020; tsup targets es2018, so provide a runtime fallback
34-
// to `window` for browsers that predate globalThis (Safari < 12.1).
13+
// Fallback for es2018 targets that predate globalThis (Safari < 12.1).
3514
const globalObj = (
3615
typeof globalThis !== 'undefined' ? globalThis : window
3716
) as unknown as { ImmutableAudience?: ImmutableAudienceGlobal };
3817

3918
if (globalObj.ImmutableAudience) {
4019
// eslint-disable-next-line no-console
41-
console.warn(
42-
'[@imtbl/audience] CDN bundle loaded twice; keeping the first instance.',
43-
);
20+
console.warn('[@imtbl/audience] CDN bundle loaded twice; keeping the first instance.');
4421
} else {
4522
globalObj.ImmutableAudience = {
4623
Audience,

packages/audience/sdk/tsup.cdn.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,8 @@ import { defineConfig } from 'tsup';
33
import { replace } from 'esbuild-plugin-replace';
44
import pkg from './package.json' with { type: 'json' };
55

6-
/**
7-
* CDN bundle config for @imtbl/audience.
8-
*
9-
* Produces a single-file IIFE at dist/cdn/imtbl-audience.global.js that
10-
* studios load via <script>. Bundles audience-core directly (no runtime
11-
* dependency resolution), attaches globals via the src/cdn.ts side-effect
12-
* entry point, and minifies for size.
13-
*
14-
* Runs alongside the main ESM build configured in tsup.config.js — they
15-
* share the dist/ directory so `clean: false` is required to avoid wiping
16-
* the ESM output. The package.json build script runs transpile (ESM/CJS)
17-
* first, then transpile:cdn, then typegen, so the order-dependent dist/
18-
* state is well-defined.
19-
*
20-
* The esbuild replace plugin substitutes '__SDK_VERSION__' with the
21-
* actual package version at build time. Both @imtbl/audience and
22-
* @imtbl/audience-core use '__SDK_VERSION__' as a placeholder in their
23-
* source (config.ts / context.ts) so the real version gets stamped
24-
* into context.libraryVersion on every message. Without this replacement
25-
* the CDN bundle ships the literal placeholder and the backend 400s.
26-
*
27-
* Local dev builds have pkg.version === '0.0.0' because the real version
28-
* is only written by `pnpm nx release version` in the publish workflow.
29-
* We substitute '0.0.0-local' in that case so a hand-carried local build
30-
* shows up as obviously non-production in context.libraryVersion logs.
31-
*/
6+
// IIFE bundle of @imtbl/audience for <script>-tag loading. Runs after the
7+
// ESM/CJS build in tsup.config.js — `clean: false` preserves that output.
328
export default defineConfig({
339
entry: { 'imtbl-audience': 'src/cdn.ts' },
3410
format: ['iife'],
@@ -40,14 +16,9 @@ export default defineConfig({
4016
target: 'es2018',
4117
platform: 'browser',
4218
dts: false,
43-
// IIFE has no runtime module resolution, so every dep (including third-party
44-
// npm deps) must be inlined. Can't reuse BUNDLED_WORKSPACE_DEPS from the sibling
45-
// tsup.config.js — that list is workspace-only and would leave third-party deps
46-
// as externals, breaking the <script>-tag use case.
19+
// IIFE has no runtime module resolution — inline everything, including npm deps.
4720
noExternal: [/.*/],
4821
esbuildPlugins: [
49-
replace({
50-
__SDK_VERSION__: pkg.version === '0.0.0' ? '0.0.0-local' : pkg.version,
51-
}),
22+
replace({ __SDK_VERSION__: pkg.version === '0.0.0' ? '0.0.0-local' : pkg.version }),
5223
],
5324
});

0 commit comments

Comments
 (0)