# Introduce `@date-fns/cdn`, deprecate CDN served from `date-fns`

This PR addresses part of the problem with the date-fns package becoming way too large:

| | |
| --- | --- |
| Status | MERGED |
| Source | github:date-fns/date-fns#4198 |
| Original | https://github.com/date-fns/date-fns/pull/4198 |
| Workspace | Showcase |
| Tags | github, code, toml, javascript, docs, sh |

## What it does

**The change is spread across 30 files in 5 areas, with no single file dominating.**

30 files changed across 5 areas of date-fns/date-fns, 591 added and 194 removed.

This PR addresses part of the problem with the date-fns package becoming way too large:

**Diagram: Where the change landed. Node size is not to scale; the line counts are exact.**

- date-fns (30 files, 785 lines) [accent]
- Build & CI (4 files, 346 lines) [bad]
- Source (11 files, 237 lines) [accent]
- Config (11 files, 123 lines) [bad]
- Docs (2 files, 61 lines) [neutral]
- Tests (2 files, 18 lines) [good]
- cdn.ts (+157 −72) [neutral]
- date-fns -> Build & CI
- date-fns -> Source
- date-fns -> Config
- date-fns -> Docs
- date-fns -> Tests
- Build & CI -> cdn.ts : heaviest

- **Heaviest file.** pkgs/core/scripts/build/cdn.ts, +157 −72, which is 29% of the change.
- **Tests moved with it.** 2 test files changed alongside 11 source files.
- **Configuration touched.** mise.toml, pnpm-lock.yaml, package.json. Config changes are small in the diff and large in effect.
- **Spread.** 30 files, 785 changed lines in total.

## How it works

**The largest single edit is in legacyStrict.js.**

Quoted verbatim from the diff. This is the biggest hunk by changed lines, which is where a reviewer's attention usually belongs first.

**Diagram: Source files matched to test files by filename. A name-based match, so treat it as a prompt to look rather than as proof.**

- NO TEST CHANGED (11)
  - legacyStrict.js (+47 −0) [bad]
  - cdnPolyfill.js (+38 −0) [bad]
  - legacy.js (+36 −0) [bad]
  - dom.js (+25 −9) [bad]
  - locales.js (+15 −11) [bad]
- TEST CHANGED TOO (0)
  - no source file paired [bad]

```javascript
@@ -0,0 +1,47 @@
+import { testScript } from "./dom.js";
+
+testScript({
+  scripts: [
+    { src: "http://127.0.0.1:9182/jquery.js" },
+    "cdn.min.js",
+    "fp/cdn.min.js",
+    { src: "http://127.0.0.1:9182/jquery.js" },
+    "locale/cdn.min.js",
+    "locale/es/cdn.min.js",
+    { src: "http://127.0.0.1:9182/jquery.js" },
+  ],
+
+  beforeParse: (window) => {
+    // Simulate a strict environment where document.write is not allowed
+    window.document.write = () => {
+      throw new Error("Nope");
+    };
+  },
+
+  run: (dom) => {
```

_pkgs/core/examples/cdn/legacyStrict.js, +47 −0. The largest hunk in the largest file._

## File map

**Every file this change touches, heaviest first.**

Role is inferred from the path and risk from the path and the line count. Neither was read from the code.

| File | Role | Change | Risk |
| --- | --- | --- | --- |
| `pkgs/core/scripts/build/cdn.ts` | application code | modified, patch unavailable (generated or vendored file) | high |
| `pkgs/core/scripts/build/package.sh` | application code | modified, patch unavailable (generated or vendored file) | low |
| `pkgs/core/mise.toml` | application code | modified, +47 −1 | low |
| `pkgs/core/examples/cdn/legacyStrict.js` | application code | added, +47 −0 | low |
| `pkgs/core/scripts/build/cdnPolyfills.ts` | application code | added, patch unavailable (generated or vendored file) | low |
| `pkgs/core/docs/cdn.md` | documentation | modified, +27 −18 | none |
| `pnpm-lock.yaml` | application code | modified, patch unavailable (generated or vendored file) | high |
| `pkgs/core/src/_lib/cdnPolyfill.js` | application code | added, +38 −0 | low |
| `pkgs/core/examples/cdn/legacy.js` | application code | added, +36 −0 | low |
| `pkgs/core/examples/cdn/dom.js` | application code | modified, +25 −9 | low |
| `pkgs/core/examples/cdn/locales.js` | application code | modified, +15 −11 | low |
| `pkgs/core/scripts/release/release.sh` | application code | modified, +17 −3 | low |
| `pkgs/core/CHANGELOG.md` | documentation | modified, +15 −1 | none |
| `pkgs/core/examples/cdn/basic.js` | application code | modified, +9 −5 | low |
| `pkgs/core/examples/cdn/fp.js` | application code | modified, +9 −5 | low |
| `pkgs/core/examples/cdn/locale.js` | application code | modified, +9 −5 | low |
| `pkgs/core/scripts/test/smoke.sh` | test coverage | modified, +13 −1 | low |
| `pkgs/core/examples/cdn/package.json` | application code | modified, +9 −4 | low |
| `pkgs/core/src/formatISO/test.ts` | test coverage | modified, +1 −4 | low |
| `pkgs/core/src/formatRFC3339/test.ts` | test coverage | modified, +1 −4 | low |
| `mise.toml` | application code | modified, +3 −1 | low |
| `pkgs/core/examples/cdn/jquery.js` | application code | added, +4 −0 | low |
| `pkgs/core/examples/node-esm/package.json` | application code | modified, +2 −2 | low |
| `pkgs/core/scripts/test/types.sh` | test coverage | modified, +4 −0 | low |

## Receipts

**Where each number above comes from.**

All of it is arithmetic over the file list and the check results, so it can be recomputed from the source.

- **Claim.** Repeated block: 2 occurrences.
  - Evidence: import { testScript } from "./dom.js";

testScript({
  - Where: pkgs/core/examples/cdn/legacyStrict.js
- **Claim.** 30 files changed, +591 −194.
  - Evidence: pkgs/core/mise.toml (+47 −1); pkgs/core/examples/cdn/legacyStrict.js (+47 −0); pkgs/core/docs/cdn.md (+27 −18)
  - Where: https://github.com/date-fns/date-fns/pull/4198
- **Claim.** cdn.ts carries 29% of the changed lines.
  - Evidence: 229 of 785 changed lines
  - Where: pkgs/core/scripts/build/cdn.ts
- **Claim.** It arrived as 5 commits.
  - Evidence: Deprecate type tests as attw hangs on date-fns package
  - Where: commit 81bae0e
- **Claim.** CI reports 0 failing of 10.
  - Evidence: tests
  - Where: CI check: tests

## Where to attack

**What the shape of this diff suggests looking at first.**

These come from structure alone: which areas were touched, what was not touched alongside them, and what CI says. None of them is a judgement about the code.

- **Configuration changed** (high)
  - pkgs/core/mise.toml, pnpm-lock.yaml, pkgs/core/examples/cdn/package.json changed. A config edit is usually a handful of lines and decides behaviour for an entire environment, so diff size is a poor guide to its blast radius.
  - Mitigation: Check what reads each of these values, and in which environments they differ.
- **4 files have no visible patch** (low)
  - cdn.ts, package.sh, cdnPolyfills.ts could not be retrieved, so nothing in this brief accounts for their contents.
  - Mitigation: Open these directly in the source.

## Merge order

**A reading order for the review, not a deployment plan.**

Ordered by how expensive each part is to get wrong, which is a structural property rather than an informed one.

1. **Review the configuration changes.** mise.toml, pnpm-lock.yaml, package.json. Smallest diff, widest effect.
2. **Then cdn.ts.** The largest single file in the change, +157 −72.
3. **Finish with the tests.** 2 test files changed. Reading them last tells you what the author believed they were changing.

## What this brief could not check

- No language model read this change. Every statement here is computed from file paths, line counts, and CI status, so it describes the shape of the diff and not what the diff means.
- 4 patch(es) were not retrieved, so any file among them is described by its stat line only.
