Skip to content

Commit

Permalink
fix(rari-npm): fix download and node < 22
Browse files Browse the repository at this point in the history
  • Loading branch information
fiji-flo committed Oct 21, 2024
1 parent cf07c78 commit 11ec9ee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
25 changes: 21 additions & 4 deletions rari-npm/lib/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,31 @@ const isWindows = platform() === "win32";

const REPO = "mdn/rari";

/**
*
* @param {string | URL} url
* @param {string | URL} [base]
*/
function URLparse(url, base) {
if (URL?.parse) {
return URL.parse(url, base);
} else {
try {
return new URL(url, base);
} catch {
return null;
}
}
}

/**
* This function is adapted from vscode-ripgrep (https://github.com/microsoft/vscode-ripgrep)
* Copyright (c) Microsoft, licensed under the MIT License
*
* @param {string} url
*/
function isGithubUrl(url) {
return URL.parse(url)?.hostname === "api.github.com";
return URLparse(url)?.hostname === "api.github.com";
}

/**
Expand All @@ -46,7 +63,7 @@ export async function exists(path) {
* @param {any} opts
*/
export async function do_download(url, dest, opts) {
const proxy = getProxyForUrl(URL.parse(url));
const proxy = getProxyForUrl(URLparse(url));
if (proxy !== "") {
const HttpsProxyAgent = await import("https-proxy-agent");
opts = {
Expand Down Expand Up @@ -100,7 +117,7 @@ export async function do_download(url, dest, opts) {
function get(_url, opts) {
console.log(`GET ${_url}`);

const proxy = getProxyForUrl(URL.parse(_url));
const proxy = getProxyForUrl(URLparse(_url));
if (proxy !== "") {
var HttpsProxyAgent = require("https-proxy-agent");
opts = {
Expand All @@ -113,7 +130,7 @@ function get(_url, opts) {
let result = "";
https.get(_url, opts, (response) => {
if (response.statusCode !== 200) {
reject(new Error("Request failed: " + response.statusCode));
reject(new Error(`Request (${_url}) failed: ${response.statusCode}`));
}

response.on("data", (d) => {
Expand Down
4 changes: 2 additions & 2 deletions rari-npm/lib/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { arch, platform } from "os";
import { join } from "path";

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

const VERSION = packageJson.version;
const VERSION = `v${packageJson.version}`;
const BIN_PATH = join(import.meta.dirname, "../bin");
const FORCE = JSON.parse(process.env.FORCE || "false");
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
Expand Down
3 changes: 3 additions & 0 deletions rari-npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rari-npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
},
"author": "Florian Dieminger <[email protected]>",
"license": "MPL-2.0",
"engines": {
"node": ">=20"
},
"dependencies": {
"extract-zip": "^2.0.1",
"https-proxy-agent": "^7.0.2",
Expand Down

0 comments on commit 11ec9ee

Please sign in to comment.