Skip to content

Commit d948ec1

Browse files
committed
Preserve but deprecate CDN versions for v4, set up v5 with polyfills
1 parent ee65753 commit d948ec1

19 files changed

Lines changed: 419 additions & 89 deletions

File tree

‎pkgs/core/CHANGELOG.md‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ This change log follows the format documented in [Keep a CHANGELOG].
88
[semantic versioning]: http://semver.org/
99
[keep a changelog]: http://keepachangelog.com/
1010

11-
## v4.3.0
11+
## v5.0.0-alpha.0 - 2026-05-30
12+
13+
### Changed
14+
15+
- **BREAKING**: The CDN scripts are now available via the `@date-fns/cdn` npm package instead of `date-fns`. Users relying on the latest CDN version (e.g., `https://cdn.jsdelivr.net/npm/date-fns/cdn.min.js`) would be served a polyfill that inserts a script with the correct URL (`https://cdn.jsdelivr.net/npm/@date-fns/cdn/cdn.min.js`) into the page.
16+
17+
## v4.4.0 - 2026-05-30
18+
19+
### Changed
20+
21+
- **DEPRECATED**: The `date-fns` CDN scripts are now deprecated and will be removed in the next major release. Please switch to the new `@date-fns/cdn` package for CDN usage.
22+
23+
- Removed CDN source maps to reduce the package size. If you rely on them, please switch to the new `@date-fns/cdn` package that still includes them.
24+
25+
## v4.3.0 - 2026-05-22
1226

1327
Kudos to [@ImRodry](https://github.com/ImRodry) and [@puneetdixit200](https://github.com/puneetdixit200) for their contributions.
1428

‎pkgs/core/docs/cdn.md‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
The CDN versions of date-fns are available as the [`@date-fns/cdn`](https://www.jsdelivr.com/package/npm/@date-fns/cdn) package on jsDelivr and other CDNs. They expose the date-fns functionality via the `window.dateFns` global variable.
44

5+
> ⚠️ The legacy CDN files in the `date-fns` package are deprecated and will be removed in a future version. They remain available for compatibility, but they log a migration notice in the console. Please update your URLs from `date-fns` to `@date-fns/cdn`.
6+
57
Unlike the npm package, the CDN is transpiled to be compatible with IE11, so it supports a wide variety of legacy browsers and environments.
68

79
```html
8-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/cdn.min.js"></script>
9-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/locale/es/cdn.min.js"></script>
10-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/locale/ru/cdn.min.js"></script>
10+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
11+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/es/cdn.min.js"></script>
12+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/ru/cdn.min.js"></script>
1113
<script>
1214
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date());
1315
//=> "last Friday at 7:26 p.m."
@@ -24,6 +26,13 @@ Unlike the npm package, the CDN is transpiled to be compatible with IE11, so it
2426
</script>
2527
```
2628

29+
Legacy URLs still work for now but should be replaced:
30+
31+
```diff
32+
- https://cdn.jsdelivr.net/npm/date-fns@VERSION/cdn.min.js
33+
+ https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/cdn.min.js
34+
```
35+
2736
The CDN versions are available for the main module, all & individual locales, and the FP submodule.
2837

2938
They come in two flavors: `cdn.js` and `cdn.min.js`. The latter is minified and should be used in production. The former is useful for debugging and development.
@@ -42,7 +51,7 @@ https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/cdn.min.js
4251
You can access it via the `dateFns` global variable:
4352

4453
```html
45-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/cdn.min.js"></script>
54+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
4655
<script>
4756
dateFns.addDays(new Date(2014, 1, 11), 10);
4857
//=> Tue Feb 21 2014 00:00:00
@@ -61,7 +70,7 @@ https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/fp/cdn.min.js
6170
You can access it via the `dateFns.fp` global variable:
6271

6372
```html
64-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/fp/cdn.min.js"></script>
73+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/fp/cdn.min.js"></script>
6574
<script>
6675
dateFns.fp.addDays(10, new Date(2014, 1, 11));
6776
//=> Tue Feb 21 2014 00:00:00
@@ -80,8 +89,8 @@ https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/locale/cdn.min.js
8089
You can access them via the `dateFns.locale` global variable:
8190

8291
```html
83-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/cdn.min.js"></script>
84-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/locale/cdn.min.js"></script>
92+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
93+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/cdn.min.js"></script>
8594
<script>
8695
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date(), {
8796
locale: dateFns.locale.es,
@@ -100,8 +109,8 @@ https://cdn.jsdelivr.net/npm/@date-fns/cdn@VERSION/locale/LOCALE/cdn.min.js
100109
You can access them via the `dateFns.locale.LOCALE` global variable:
101110

102111
```html
103-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/cdn.min.js"></script>
104-
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.3.0/locale/es/cdn.min.js"></script>
112+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/cdn.min.js"></script>
113+
<script src="https://cdn.jsdelivr.net/npm/@date-fns/cdn@4.4.0/locale/es/cdn.min.js"></script>
105114
<script>
106115
dateFns.formatRelative(dateFns.subDays(new Date(), 3), new Date(), {
107116
locale: dateFns.locale.es,

‎pkgs/core/examples/cdn/basic.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { testScript } from "./dom.js";
22

3-
testScript("cdn.min.js", (dom) => {
4-
const result = dom.window.eval(
5-
`window.dateFns.addDays(new Date(1987, 1, 11), 1).getDate()`,
6-
);
7-
console.log(result === 12);
3+
testScript({
4+
script: "cdn.min.js",
5+
6+
run: (dom) => {
7+
const result = dom.window.eval(
8+
`window.dateFns.addDays(new Date(1987, 1, 11), 1).getDate()`,
9+
);
10+
console.log(result === 12);
11+
},
812
});

‎pkgs/core/examples/cdn/dom.js‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { JSDOM, ResourceLoader } from "jsdom";
21
import { readFile } from "fs/promises";
2+
import { JSDOM, ResourceLoader, VirtualConsole } from "jsdom";
33
import { resolve } from "path";
44

55
class CustomResourceLoader extends ResourceLoader {
@@ -13,23 +13,39 @@ const resources = new CustomResourceLoader({
1313
proxy: "http://127.0.0.1:9182",
1414
strictSSL: false,
1515
});
16+
const virtualConsole = new VirtualConsole();
17+
18+
virtualConsole.on("jsdomError", (error) => console.error(error));
1619

1720
const options = {
1821
runScripts: "dangerously",
1922
resources,
23+
virtualConsole,
2024
};
2125

22-
export function testScript(script, cb) {
26+
export function testScript(props) {
27+
const {
28+
script,
29+
scripts,
30+
run,
31+
beforeParse,
32+
pkg = process.env.DATE_FNS_CDN_TEST_PKG || "@date-fns/cdn",
33+
} = props;
34+
2335
const dom = new JSDOM(
2436
[]
25-
.concat(script)
26-
.map(
27-
(script) =>
28-
`<script src="http://127.0.0.1:9182/node_modules/@date-fns/cdn/${script}"></script>`,
29-
)
37+
.concat(script || scripts)
38+
.map((script) => {
39+
if (script.src) return `<script src="${script.src}"></script>`;
40+
41+
const path = typeof script === "string" ? script : script.path;
42+
const scriptPkg = typeof script === "string" ? pkg : script.pkg;
43+
44+
return `<script src="http://127.0.0.1:9182/node_modules/${scriptPkg}/${path}"></script>`;
45+
})
3046
.join("\n"),
31-
options,
47+
{ ...options, beforeParse },
3248
);
3349

34-
dom.window.addEventListener("DOMContentLoaded", () => cb(dom));
50+
dom.window.addEventListener("load", () => run(dom));
3551
}

‎pkgs/core/examples/cdn/fp.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { testScript } from "./dom.js";
22

3-
testScript("fp/cdn.min.js", (dom) => {
4-
const result = dom.window.eval(
5-
`window.dateFns.fp.startOfWeekWithOptions({ weekStartsOn: 1 }, new Date(1987, 1, 11)).getDate()`,
6-
);
7-
console.log(result === 9);
3+
testScript({
4+
script: "fp/cdn.min.js",
5+
6+
run: (dom) => {
7+
const result = dom.window.eval(
8+
`window.dateFns.fp.startOfWeekWithOptions({ weekStartsOn: 1 }, new Date(1987, 1, 11)).getDate()`,
9+
);
10+
console.log(result === 9);
11+
},
812
});

‎pkgs/core/examples/cdn/jquery.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
window.jQuery = window.$ = {
2+
version: "fixture",
3+
loaded: (window.jQuery && window.jQuery.loaded + 1) || 1,
4+
};

‎pkgs/core/examples/cdn/legacy.js‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { testScript } from "./dom.js";
2+
3+
testScript({
4+
scripts: [
5+
{ src: "http://127.0.0.1:9182/jquery.js" },
6+
"cdn.min.js",
7+
"fp/cdn.min.js",
8+
{ src: "http://127.0.0.1:9182/jquery.js" },
9+
"locale/cdn.min.js",
10+
"locale/es/cdn.min.js",
11+
{ src: "http://127.0.0.1:9182/jquery.js" },
12+
],
13+
14+
run: (dom) => {
15+
const addDaysResult = dom.window.eval(
16+
`window.dateFns.addDays(new Date(1987, 1, 11), 1).getDate()`,
17+
);
18+
const fpResult = dom.window.eval(
19+
`window.dateFns.fp.startOfWeekWithOptions({ weekStartsOn: 1 }, new Date(1987, 1, 11)).getDate()`,
20+
);
21+
const localeResult = dom.window.eval(
22+
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.es })`,
23+
);
24+
25+
console.log(
26+
addDaysResult === 12 &&
27+
fpResult === 9 &&
28+
localeResult === "el domingo pasado a las 00:00" &&
29+
dom.window.$ === dom.window.jQuery &&
30+
dom.window.jQuery.version === "fixture" &&
31+
dom.window.jQuery.loaded === 3,
32+
);
33+
},
34+
35+
pkg: "date-fns",
36+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { testScript } from "./dom.js";
2+
3+
testScript({
4+
scripts: [
5+
{ src: "http://127.0.0.1:9182/jquery.js" },
6+
"cdn.min.js",
7+
"fp/cdn.min.js",
8+
{ src: "http://127.0.0.1:9182/jquery.js" },
9+
"locale/cdn.min.js",
10+
"locale/es/cdn.min.js",
11+
{ src: "http://127.0.0.1:9182/jquery.js" },
12+
],
13+
14+
beforeParse: (window) => {
15+
// Simulate a strict environment where document.write is not allowed
16+
window.document.write = () => {
17+
throw new Error("Nope");
18+
};
19+
},
20+
21+
run: (dom) => {
22+
dom.window.document.write = () => {
23+
throw new Error("Nope");
24+
};
25+
26+
const addDaysResult = dom.window.eval(
27+
`window.dateFns.addDays(new Date(1987, 1, 11), 1).getDate()`,
28+
);
29+
const fpResult = dom.window.eval(
30+
`window.dateFns.fp.startOfWeekWithOptions({ weekStartsOn: 1 }, new Date(1987, 1, 11)).getDate()`,
31+
);
32+
const localeResult = dom.window.eval(
33+
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.es })`,
34+
);
35+
36+
console.log(
37+
addDaysResult === 12 &&
38+
fpResult === 9 &&
39+
localeResult === "el domingo pasado a las 00:00" &&
40+
dom.window.$ === dom.window.jQuery &&
41+
dom.window.jQuery.version === "fixture" &&
42+
dom.window.jQuery.loaded === 3,
43+
);
44+
},
45+
46+
pkg: "date-fns",
47+
});

‎pkgs/core/examples/cdn/locale.js‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { testScript } from "./dom.js";
22

3-
testScript(["cdn.min.js", "locale/es/cdn.min.js"], (dom) => {
4-
const result = dom.window.eval(
5-
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.es })`,
6-
);
7-
console.log(result === "el domingo pasado a las 00:00");
3+
testScript({
4+
scripts: ["cdn.min.js", "locale/es/cdn.min.js"],
5+
6+
run: (dom) => {
7+
const result = dom.window.eval(
8+
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.es })`,
9+
);
10+
console.log(result === "el domingo pasado a las 00:00");
11+
},
812
});

‎pkgs/core/examples/cdn/locales.js‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { testScript } from "./dom.js";
22

3-
testScript(["cdn.min.js", "locale/cdn.min.js"], (dom) => {
4-
const esResult = dom.window.eval(
5-
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.es })`,
6-
);
7-
const ruResult = dom.window.eval(
8-
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.ru })`,
9-
);
10-
console.log(
11-
esResult === "el domingo pasado a las 00:00" &&
12-
ruResult === "в прошлое воскресенье в 0:00",
13-
);
3+
testScript({
4+
scripts: ["cdn.min.js", "locale/cdn.min.js"],
5+
6+
run: (dom) => {
7+
const esResult = dom.window.eval(
8+
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.es })`,
9+
);
10+
const ruResult = dom.window.eval(
11+
`window.dateFns.formatRelative(window.dateFns.subDays(new Date(1987, 1, 11), 3), new Date(1987, 1, 11), { locale: window.dateFns.locale.ru })`,
12+
);
13+
console.log(
14+
esResult === "el domingo pasado a las 00:00" &&
15+
ruResult === "в прошлое воскресенье в 0:00",
16+
);
17+
},
1418
});

0 commit comments

Comments
 (0)