Skip to content

feat(cdn): add JSPM-locked import map and loader. - #110

Merged
knightedcodemonkey merged 5 commits into
mainfrom
bananas
Nov 1, 2026
Merged

knightedcodemonkey merged 5 commits into
mainfrom
bananas

Conversation

@knightedcodemonkey

Copy link
Copy Markdown
Owner

Generate release-specific maps from a tracked dependency lock.
Add stable loader and host-owned import-map APIs.
Validate candidate graphs in Chromium.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Import-map validation misses more-specific host scopes and URL remappings, allowing conflicting React mappings or replacement entry modules to bypass the locked graph.

4 open issues
What changed in this PR

Adds a JSPM-locked browser bootstrap for @knighted/jsx, complementing the legacy CDN URL helpers with release-specific import maps and loader APIs.

Changes:

  • Adds tracked dependency locking, candidate map generation, and packaging validation.
  • Introduces loadStableCdn and a document-independent getStableCdnImportMap API.
  • Adds unit and Chromium coverage, documents bootstrap usage, and advances the alpha version.
File Description
test/​cdn-stable.test.ts Tests map validation, loader options, and host conflicts.
test/​cdn-importmap.test.ts Tests artifact validation and version-only lock reuse.
src/​cdn-stable.ts Implements import-map retrieval, installation, and runtime loading.
scripts/​generate-cdn-importmap.mjs Generates and validates published and candidate CDN graphs.
README.md Documents the new bootstrap APIs and legacy helper limits.
playwright/​cdn-importmap.spec.ts Exercises browser loading, React identity, and locked requests.
package.json Adds exports, generation scripts, packaging checks, and the alpha bump.
package-lock.json Records the version bump and JSPM tooling dependencies.
docs/​cdn-stability-plan.md Records implementation progress and remaining release gates.
cdn-importmap-lock.json Stores the dependency graph and reusable import-map template.

Review effort: Balanced

Comment thread src/cdn-stable.ts Resolved
Comment thread src/cdn-stable.ts Resolved
Comment on lines +54 to +55
manifest: JSON.parse(
fs.readFileSync(manifestPath, 'utf8'),
Comment thread test/cdn-stable.test.ts Resolved
Copilot AI balanced review requested due to automatic review settings November 1, 2026 18:37
@codecov

codecov Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.80952% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.50%. Comparing base (f8ac733) to head (30160ab).

Files with missing lines Patch % Lines
src/cdn-stable.ts 98.80% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #110      +/-   ##
==========================================
+ Coverage   88.82%   89.50%   +0.68%     
==========================================
  Files          28       28              
  Lines        2272     2440     +168     
  Branches      648      687      +39     
==========================================
+ Hits         2018     2184     +166     
- Misses         74       75       +1     
- Partials      180      181       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved import-map validation gaps allow host mappings to override locked entries or create different React instances, undermining the loader’s locked-graph and shared-instance guarantees.

1 open issue
4 previously missed issues

In code that hasn't changed since last review

Medium severity Normalize URL-like import-map keys before conflict checks

src/​cdn-stable.ts:348

A host key such as //ga.jspm.io/npm:@knighted/jsx@2.0.0-alpha.1/dist/index.js is normalized by the browser to the locked absolute URL, but the conflict lookup misses it. The loader can therefore import the host's replacement instead of the locked entry. Normalize URL-like keys in both global and scoped mappings before checking conflicts, while preserving bare specifiers.

Medium severity Check peer resolution against the application's importing module

src/​cdn-stable.ts:412

With a page at /index.html and a host /app/ scope mapping react elsewhere, /app/main.js can load successfully but receive a different React instance from the locked helpers. Checking only document.baseURI misses this visible conflict and breaks the documented shared-instance behavior. Validate peer resolution for the application's importing module through an explicit referrer URL, or conservatively check visible host scopes.

Medium severity Allow isolated package scopes to override inherited host mappings

src/​cdn-stable.ts:429

A host's global magic-string mapping to another version makes the loader fail, although the generated JSX package scope could isolate its locked version without changing the host mapping. Distinguish inherited fallbacks from conflicting mappings at the same or more-specific scope. Update createMissingImportMap as well so a differing inherited target does not suppress the required scoped mapping.

Medium severity Revalidate host import maps after cached installation

src/​cdn-stable.ts:478

A successful installation bypasses conflict checking on every later call. After loading core, the host can add a more-specific JSX React scope pointing react elsewhere; a subsequent React-entry load returns this cached promise and loads against that conflicting scope, producing a different React instance. Keep installation idempotent, but revalidate visible host maps after awaiting the cached installation.

3 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 1, 2026 19:05
@knightedcodemonkey
knightedcodemonkey merged commit f422494 into main Nov 1, 2026
10 checks passed
@knightedcodemonkey
knightedcodemonkey deleted the bananas branch November 1, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Unresolved import-map resolution and validation defects can load unintended dependency versions, omit required global imports, and reject compatible host mappings.

1 open issue
6 previously missed issues

In code that hasn't changed since last review

Medium severity Normalize URL-like import-map keys before conflict checks

src/​cdn-stable.ts:356

Browser import maps normalize URL-like keys before matching, but this lookup compares the original JSON keys verbatim. For example, a host key ending in /dist/./index.js is equivalent to the locked /dist/index.js URL in the browser, yet the conflict check misses it and allows the entry to load from a replacement URL. Normalize URL-like keys against the map's base URL before using them for conflict detection and missing-mapping calculation.

Medium severity Merge host maps using browser first-mapping-wins semantics

src/​cdn-stable.ts:396

If one host script globally maps oxc-parser to another version and a second supplies the canonical parser in the JSX package scope, the browser uses the scoped mapping, but this loop rejects the first script's global fallback. This prevents compatible dependency versions from coexisting when mappings are split across scripts. Merge normalized host maps using the browser's first-mapping-wins rules, then use that effective map for validation and missing-mapping calculation.

Medium severity Validate entry remappings against the helper's actual referrer

src/​cdn-stable.ts:413

With the documented jsDelivr bootstrap, a host scope covering cdn-stable.js can remap the absolute core entry URL without matching the document URL or any generated JSPM scope. The checks then pass, but import(url) loads the replacement because its referrer is import.meta.url, not document.baseURI. Check entry URL remappings against the helper's actual referrer before installing the map.

Medium severity Allow unrelated global versions when scoped mappings preserve the locked graph

src/​cdn-stable.ts:429

A host application that globally maps magic-string to 0.30.20 is rejected here, even though the generated JSX scope could safely resolve its own imports to 0.30.21 while preserving the application's version. The check compares against the host's global fallback before adding the generated scope, and createMissingImportMap also treats that fallback as an existing scoped mapping. Determine conflicts after composing the missing scoped mappings, rejecting mappings that would still override the locked graph rather than unrelated global dependency versions.

Medium severity Don't treat document-scoped imports as global mappings

src/​cdn-stable.ts:450

A mapping inside a document-specific scope does not supply a global import. For example, a host map with react only in the scope https://app.example/index.html causes this check to omit imports.react, so an external https://app.example/app.js module cannot import react after setup. Determine missing top-level mappings from the host maps' imports tables only, rather than their effective resolution at the document URL.

Medium severity Revalidate host maps before importing additional entries

src/​cdn-stable.ts:479

Caching installation also skips conflict validation on every later load. After loading only core, the host can append a more-specific JSX React scope pointing to a different React URL; requesting react afterward bypasses the checks and loads reactJsx with a different React instance from the installed ReactDOM graph. Keep map insertion idempotent, but revalidate the current host maps before importing additional entries.

Review effort: Balanced

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.

2 participants