Skip to content

Commit 3e8bafd

Browse files
Removing node-fetch as a dependency. Adding disclaimer at README. (#114)
1 parent c38831b commit 3e8bafd

File tree

4 files changed

+27
-50
lines changed

4 files changed

+27
-50
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ const outXmlString = xslt.xsltProcess( // Not async.
123123

124124
Version 3 received `<xsl:include>` which relies on Fetch API, which is asynchronous. Version 2 doesn't support `<xsl:include>`.
125125

126+
If using Node.js older than version v17.5.0, please use version 3.2.3, that uses `node-fetch` package. Versions 3.3.0 onward require at least Node.js version v17.5.0, since they use native `fetch()` function.
127+
126128
#### Version 1
127129

128130
Until version 1.2.8, use like the example below:

package.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"@rollup/plugin-typescript": "^11.1.1",
4949
"@types/he": "^1.2.0",
5050
"@types/jest": "^29.5.12",
51+
"@types/node": "^22.9.0",
5152
"@types/node-fetch": "^2.6.11",
5253
"@typescript-eslint/eslint-plugin": "^8.4.0",
5354
"@typescript-eslint/parser": "^8.4.0",
@@ -70,16 +71,7 @@
7071
"typescript": "^5.5.4"
7172
},
7273
"dependencies": {
73-
"he": "^1.2.0",
74-
"node-fetch": "release-2.x"
75-
},
76-
"overrides": {
77-
78-
"whatwg-url": "14.x"
79-
}
80-
},
81-
"resolutions": {
82-
"whatwg-url": "14.x"
74+
"he": "^1.2.0"
8375
},
8476
"copyFiles": [
8577
{

src/xslt/xslt.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//
66
// Original author: Steffen Meschkat <[email protected]>
77

8-
import fetch, { Headers, Request, Response } from 'node-fetch';
9-
108
import {
119
XDocument,
1210
XNode,
@@ -647,6 +645,11 @@ export class Xslt {
647645
* @param output The output.
648646
*/
649647
protected async xsltImport(context: ExprContext, template: XNode, output?: XNode) {
648+
const [major, minor, patch] = process.versions.node.split('.').map(Number);
649+
if (major <= 17 && minor < 5) {
650+
throw new Error('Your Node.js version does not support `<xsl:import>`. If possible, please update your Node.js version to at least version 17.5.0.');
651+
}
652+
650653
if (this.firstTemplateRan) {
651654
throw new Error('<xsl:import> should be the first child node of <xsl:stylesheet> or <xsl:transform>.');
652655
}
@@ -665,6 +668,7 @@ export class Xslt {
665668
if (hrefAttributeFind.length <= 0) {
666669
throw new Error('<xsl:import> with no href attribute defined.');
667670
}
671+
668672
const hrefAttribute = hrefAttributeFind[0];
669673

670674
const fetchTest = await global.globalThis.fetch(hrefAttribute.nodeValue);
@@ -680,6 +684,11 @@ export class Xslt {
680684
* @param output The output.
681685
*/
682686
protected async xsltInclude(context: ExprContext, template: XNode, output?: XNode) {
687+
const [major, minor, patch] = process.versions.node.split('.').map(Number);
688+
if (major <= 17 && minor < 5) {
689+
throw new Error('Your Node.js version does not support `<xsl:include>`. If possible, please update your Node.js version to at least version 17.5.0.');
690+
}
691+
683692
// We need to test here whether `window.fetch` is available or not.
684693
// If it is a browser environemnt, it should be.
685694
// Otherwise, we will need to import an equivalent library, like 'node-fetch'.
@@ -694,6 +703,7 @@ export class Xslt {
694703
if (hrefAttributeFind.length <= 0) {
695704
throw new Error('<xsl:include> with no href attribute defined.');
696705
}
706+
697707
const hrefAttribute = hrefAttributeFind[0];
698708

699709
const fetchTest = await global.globalThis.fetch(hrefAttribute.nodeValue);

yarn.lock

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,7 +1842,7 @@
18421842
"@types/node" "*"
18431843
form-data "^4.0.0"
18441844

1845-
"@types/node@*":
1845+
"@types/node@*", "@types/node@^22.9.0":
18461846
version "22.9.0"
18471847
resolved "https://registry.yarnpkg.com/@types/node/-/node-22.9.0.tgz#b7f16e5c3384788542c72dc3d561a7ceae2c0365"
18481848
integrity sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==
@@ -2456,9 +2456,9 @@ camelcase@^8.0.0:
24562456
integrity sha512-8WB3Jcas3swSvjIeA2yvCJ+Miyz5l1ZmB6HFb9R1317dt9LCQoswg/BGrmAmkWVEszSrrg4RwmO46qIm2OEnSA==
24572457

24582458
caniuse-lite@^1.0.30001669:
2459-
version "1.0.30001677"
2460-
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001677.tgz#27c2e2c637e007cfa864a16f7dfe7cde66b38b5f"
2461-
integrity sha512-fmfjsOlJUpMWu+mAAtZZZHz7UEwsUxIIvu1TJfO1HqFQvB/B+ii0xr9B5HpbZY/mC4XZ8SvjHJqtAY6pDPQEog==
2459+
version "1.0.30001678"
2460+
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001678.tgz#b930b04cd0b295136405634aa32ad540d7eeb71e"
2461+
integrity sha512-RR+4U/05gNtps58PEBDZcPWTgEO2MBeoPZ96aQcjmfkBWRIDfN451fW2qyDA9/+HohLLIL5GqiMwA+IB1pWarw==
24622462

24632463
[email protected], chalk@^5.0.1, chalk@^5.2.0, chalk@^5.3.0:
24642464
version "5.3.0"
@@ -2764,9 +2764,9 @@ create-require@^1.1.0:
27642764
integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==
27652765

27662766
cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
2767-
version "7.0.3"
2768-
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
2769-
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
2767+
version "7.0.5"
2768+
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.5.tgz#910aac880ff5243da96b728bc6521a5f6c2f2f82"
2769+
integrity sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==
27702770
dependencies:
27712771
path-key "^3.1.0"
27722772
shebang-command "^2.0.0"
@@ -2926,9 +2926,9 @@ ejs@^3.1.10:
29262926
jake "^10.8.5"
29272927

29282928
electron-to-chromium@^1.5.41:
2929-
version "1.5.52"
2930-
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.52.tgz#2bed832c95a56a195504f918150e548474687da8"
2931-
integrity sha512-xtoijJTZ+qeucLBDNztDOuQBE1ksqjvNjvqFoST3nGC7fSpqJ+X6BdTBaY5BHG+IhWWmpc6b/KfpeuEDupEPOQ==
2929+
version "1.5.54"
2930+
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.54.tgz#1b8d2e012a7edfc8c0b778a0b86ece99c892cd24"
2931+
integrity sha512-TX6vHleisn5i/4pekTyy1sdoLXQNy8VFvBK/fJRXSyp7GUO27KioLTG0Qo5wFjM3ZF4ryKinDo4m+IJ+rwUWSw==
29322932

29332933
emittery@^0.13.1:
29342934
version "0.13.1"
@@ -5022,13 +5022,6 @@ [email protected]:
50225022
dependencies:
50235023
type-fest "^2.5.1"
50245024

5025-
5026-
version "2.7.0"
5027-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
5028-
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
5029-
dependencies:
5030-
whatwg-url "^5.0.0"
5031-
50325025
node-gyp@^9.0.0:
50335026
version "9.4.1"
50345027
resolved "https://registry.yarnpkg.com/node-gyp/-/node-gyp-9.4.1.tgz#8a1023e0d6766ecb52764cc3a734b36ff275e185"
@@ -5634,7 +5627,7 @@ proxy-from-env@^1.1.0:
56345627
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
56355628
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==
56365629

5637-
punycode@^2.1.0, punycode@^2.3.1:
5630+
punycode@^2.1.0:
56385631
version "2.3.1"
56395632
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
56405633
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==
@@ -6501,13 +6494,6 @@ to-regex-range@^5.0.1:
65016494
dependencies:
65026495
is-number "^7.0.0"
65036496

6504-
tr46@^5.0.0:
6505-
version "5.0.0"
6506-
resolved "https://registry.yarnpkg.com/tr46/-/tr46-5.0.0.tgz#3b46d583613ec7283020d79019f1335723801cec"
6507-
integrity sha512-tk2G5R2KRwBd+ZN0zaEXpmzdKyOYksXwywulIX95MBODjSzMIuQnQ3m8JxgbhnL1LeVo7lqQKsYa1O3Htl7K5g==
6508-
dependencies:
6509-
punycode "^2.3.1"
6510-
65116497
ts-api-utils@^1.3.0:
65126498
version "1.4.0"
65136499
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.4.0.tgz#709c6f2076e511a81557f3d07a0cbd566ae8195c"
@@ -6797,19 +6783,6 @@ wcwidth@^1.0.1:
67976783
dependencies:
67986784
defaults "^1.0.3"
67996785

6800-
webidl-conversions@^7.0.0:
6801-
version "7.0.0"
6802-
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a"
6803-
integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==
6804-
6805-
[email protected], whatwg-url@^5.0.0:
6806-
version "14.0.0"
6807-
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-14.0.0.tgz#00baaa7fd198744910c4b1ef68378f2200e4ceb6"
6808-
integrity sha512-1lfMEm2IEr7RIV+f4lUNPOqfFL+pO+Xw3fJSqmjX9AbXcXcYOkCe1P6+9VBZB6n94af16NfZf+sSk0JCBZC9aw==
6809-
dependencies:
6810-
tr46 "^5.0.0"
6811-
webidl-conversions "^7.0.0"
6812-
68136786
when-exit@^2.1.1:
68146787
version "2.1.3"
68156788
resolved "https://registry.yarnpkg.com/when-exit/-/when-exit-2.1.3.tgz#5831cdbed8ad4984645da98c4a00d4ee3a3757e7"

0 commit comments

Comments
 (0)