feat: cdn contract and stable subpath export. - #106
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #106 +/- ##
==========================================
+ Coverage 88.90% 89.14% +0.24%
==========================================
Files 26 27 +1
Lines 2199 2248 +49
Branches 623 637 +14
==========================================
+ Hits 1955 2004 +49
Misses 71 71
Partials 173 173 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a generated CDN “contract” JSON and a stable helper subpath so consumers can programmatically build provider-specific (esm.sh / jsDelivr) URLs for the package’s stable entrypoints (core, react, transform).
Changes:
- Introduces
src/cdn-stable.tswithgetStableCdnUrls/buildStableCdnUrlsand contract loading logic. - Adds a generator script to produce
cdn-contract.json, and wires it intoprepackplus package exports. - Updates docs and the jsDelivr demo to use the new stable URL helper.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/cdn-stable.test.ts | Adds unit tests for URL building, contract loading, and error cases. |
| src/cdn-stable.ts | Implements contract validation, provider URL generation, and contract loading helper. |
| scripts/generate-cdn-contract.mjs | Generates cdn-contract.json from package.json dependency versions (with --check mode). |
| README.md | Documents stable CDN usage and the published cdn-contract.json subpath. |
| package.json | Exports ./cdn-stable and ./cdn-contract.json, adds generation/check scripts, updates prepack, bumps version. |
| package-lock.json | Updates lockfile package version. |
| examples/esm-demo.html | Switches demo imports to use getStableCdnUrls and stable entry URLs. |
| .gitignore | Ignores generated cdn-contract.json in the repo workspace. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/cdn-stable.ts:100
assertContractvalidates entry presence, but it doesn't validate contract-level fields or enforce a safesubpathshape. A malformed/remote contract can currently produce URLs likeundefined@undefined///reactordeps=name@instead of failing fast. Consider validatingpackageName,packageVersion,entriesand ensuring each entrysubpathis either.or starts with./, plus verifying all dependency versions are non-empty strings.
const assertContract = (contract: CdnContract) => {
if (!contract || typeof contract !== 'object') {
throw new Error('[cdn-stable] A valid contract object is required.')
}
src/cdn-stable.ts:109
- When
cdn-contract.jsonis missing (which is likely in a clean repo checkout since it’s generated at prepack time), thefile:branch throws the rawENOENT/SyntaxErrorwithout context. Wrapping this with a more actionable error (and preserving the original ascause) will make failures easier to diagnose.
if (contractUrl.protocol === 'file:') {
const fs = await import('node:fs/promises')
const content = await fs.readFile(contractUrl, 'utf8')
return JSON.parse(content) as CdnContract
}
No description provided.