Commit 28d0c5c
refactor(audience): move demo to sibling sdk-sample-app package
Addresses review feedback on #2837 from @nattb8: the interactive demo
should live in its own workspace package (matching the repo convention
used by passport/sdk-sample-app, checkout/sdk-sample-app, dex/sdk-sample-app,
bridge/bridge-sample-app) rather than inside the published @imtbl/audience
package directory.
Why this matters beyond aesthetics:
- @imtbl/audience is a published npm package with a dedicated build
pipeline (#2838): local tsup.config.js, prepack/postpack scripts that
strip workspace deps from package.json, rollup-plugin-dts to inline
type re-exports. The sdk package directory should stay focused on
shipping artifacts; a demo harness is not one.
- The demo was vanilla ES2020 (no TS, no modules, loaded via a script
tag) while the sdk package is pure TypeScript. Co-locating them forced
sdk/.eslintignore + an .eslintrc.cjs override block just to keep
lint-staged from trying to parse demo/*.js with the TS parser. Both
pieces of config disappear with this move.
- The existing repo-wide root .eslintignore already has a
`**sample-app**/` glob (for passport/sdk-sample-app and friends), so
the new directory is automatically excluded from root lint with zero
local config.
Addresses the reviewer's secondary concern — "this is included in the
CDN bundle too" — at the structural level. For the record, verified
the demo was never literally bundled into dist/cdn/imtbl-audience.global.js:
src/cdn.ts imports only ./sdk, ./config, and @imtbl/audience-core, and
`files: ["dist"]` in package.json already excluded demo/ from the npm
tarball. Confirmed by packing the sdk and inspecting the tarball — it
only contains dist/browser, dist/cdn, dist/node, dist/types, plus
README.md, LICENSE.md, and package.json.
Changes:
New package — packages/audience/sdk-sample-app/
- package.json: private, @imtbl/audience as a workspace:* devDep,
engines node >= 20.11, `pnpm dev` builds @imtbl/audience then runs
the local serve script
- serve.mjs: ~90-line Node static server using only the stdlib.
Serves the sample-app's own files from ./, and routes /vendor/
to ../sdk/dist/cdn/ so the HTML can load the CDN bundle via a
same-origin URL (keeps the demo's CSP happy). Blocks serve.mjs,
package.json, and node_modules from being served, plus path
traversal attempts via decodeURIComponent + a resolve/startsWith
guard. Verified with curl: 200 for /, /demo.css, /demo.js and
/vendor/imtbl-audience.global.js(.map); 403 for /package.json,
/serve.mjs, /vendor/../../package.json, /%2e%2e/secret; 404 for
/nonexistent.html.
- index.html, demo.js, demo.css, README.md: git-renamed from
packages/audience/sdk/demo/. The only content change is in
index.html — the <script src> moved from ../dist/cdn/... to
vendor/... — plus README.md was updated with the new run
instructions and a layout diagram for the new location.
Package cleanup — packages/audience/sdk/
- Remove the `demo` script from package.json (its entry point is
gone now).
- Revert .eslintrc.cjs to main's 6-line baseline by dropping the
22-line `demo/**/*.js` overrides block that the PR had added.
- Delete .eslintignore entirely (its only line was `demo/`).
- Update README.md's two `demo/` references to point at
`../sdk-sample-app/README.md` instead.
Repo-level
- Drop the `packages/audience/sdk/demo/` line from root .eslintignore
(the existing `**sample-app**/` glob covers the new location).
- Register `packages/audience/sdk-sample-app` in pnpm-workspace.yaml.
- pnpm-lock.yaml picks up a 6-line importer entry for the new package
(just the workspace:* link to ../sdk, no external deps).
Verification:
- `pnpm --filter @imtbl/audience-core --filter @imtbl/audience run
lint typecheck test` — 113 core + 51 sdk tests pass, lint/typecheck
clean on both packages.
- `pnpm --filter @imtbl/audience run build` — ESM (browser+node),
CDN IIFE (52.04 KB), and rolled-up .d.ts all build clean.
- `pnpm --filter @imtbl/audience-sdk-sample-app run dev` — builds
the sdk, starts the local server, demo loads at http://localhost:3456/
with the CDN bundle served from /vendor/.
- `pnpm pack --pack-destination /tmp/...` in the sdk — tarball
contains only dist/{browser,cdn,node,types}, LICENSE.md, README.md,
and package.json. No demo, no vendor, no sample-app, no scripts.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 60c8827 commit 28d0c5c
13 files changed
Lines changed: 130 additions & 39 deletions
File tree
- packages/audience
- sdk-sample-app
- sdk
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 12 | + | |
17 | 13 | | |
18 | 14 | | |
19 | 15 | | |
| |||
48 | 44 | | |
49 | 45 | | |
50 | 46 | | |
51 | | - | |
| 47 | + | |
52 | 48 | | |
53 | 49 | | |
54 | 50 | | |
| |||
57 | 53 | | |
58 | 54 | | |
59 | 55 | | |
60 | | - | |
61 | | - | |
| 56 | + | |
| 57 | + | |
62 | 58 | | |
63 | 59 | | |
| 60 | + | |
| 61 | + | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
| |||
File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
0 commit comments