Skip to content

Commit 11ec9ee

Browse files
committed
fix(rari-npm): fix download and node < 22
1 parent cf07c78 commit 11ec9ee

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

rari-npm/lib/download.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,31 @@ const isWindows = platform() === "win32";
1515

1616
const REPO = "mdn/rari";
1717

18+
/**
19+
*
20+
* @param {string | URL} url
21+
* @param {string | URL} [base]
22+
*/
23+
function URLparse(url, base) {
24+
if (URL?.parse) {
25+
return URL.parse(url, base);
26+
} else {
27+
try {
28+
return new URL(url, base);
29+
} catch {
30+
return null;
31+
}
32+
}
33+
}
34+
1835
/**
1936
* This function is adapted from vscode-ripgrep (https://github.com/microsoft/vscode-ripgrep)
2037
* Copyright (c) Microsoft, licensed under the MIT License
2138
*
2239
* @param {string} url
2340
*/
2441
function isGithubUrl(url) {
25-
return URL.parse(url)?.hostname === "api.github.com";
42+
return URLparse(url)?.hostname === "api.github.com";
2643
}
2744

2845
/**
@@ -46,7 +63,7 @@ export async function exists(path) {
4663
* @param {any} opts
4764
*/
4865
export async function do_download(url, dest, opts) {
49-
const proxy = getProxyForUrl(URL.parse(url));
66+
const proxy = getProxyForUrl(URLparse(url));
5067
if (proxy !== "") {
5168
const HttpsProxyAgent = await import("https-proxy-agent");
5269
opts = {
@@ -100,7 +117,7 @@ export async function do_download(url, dest, opts) {
100117
function get(_url, opts) {
101118
console.log(`GET ${_url}`);
102119

103-
const proxy = getProxyForUrl(URL.parse(_url));
120+
const proxy = getProxyForUrl(URLparse(_url));
104121
if (proxy !== "") {
105122
var HttpsProxyAgent = require("https-proxy-agent");
106123
opts = {
@@ -113,7 +130,7 @@ function get(_url, opts) {
113130
let result = "";
114131
https.get(_url, opts, (response) => {
115132
if (response.statusCode !== 200) {
116-
reject(new Error("Request failed: " + response.statusCode));
133+
reject(new Error(`Request (${_url}) failed: ${response.statusCode}`));
117134
}
118135

119136
response.on("data", (d) => {

rari-npm/lib/postinstall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { arch, platform } from "os";
33
import { join } from "path";
44

55
import { download, exists } from "./download.js";
6-
import * as packageJson from "../package.json" with { type: "json" };
6+
import packageJson from "../package.json" with { type: "json" };
77

8-
const VERSION = packageJson.version;
8+
const VERSION = `v${packageJson.version}`;
99
const BIN_PATH = join(import.meta.dirname, "../bin");
1010
const FORCE = JSON.parse(process.env.FORCE || "false");
1111
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;

rari-npm/package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rari-npm/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
},
1313
"author": "Florian Dieminger <[email protected]>",
1414
"license": "MPL-2.0",
15+
"engines": {
16+
"node": ">=20"
17+
},
1518
"dependencies": {
1619
"extract-zip": "^2.0.1",
1720
"https-proxy-agent": "^7.0.2",

0 commit comments

Comments
 (0)