Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: bump engines to Node.js >=22.12.0 #312

Merged
merged 20 commits into from
Feb 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"prettier",
"prettier/@typescript-eslint"
]
}
17 changes: 3 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -17,35 +17,24 @@ jobs:
strategy:
matrix:
node-version:
- '20.10'
- '18.18'
- '16.20'
- '14.16'
- '22.13'
os:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: "${{ matrix.os }}"
steps:
- run: git config --global core.autocrlf input
- name: Install Rosetta
if: ${{ matrix.os == 'macos-latest' && matrix.node-version == '14.16' }}
run: /usr/sbin/softwareupdate --install-rosetta --agree-to-license
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: "${{ matrix.node-version }}"
cache: 'yarn'
architecture: ${{ matrix.os == 'macos-latest' && matrix.node-version == '14.16' && 'x64' || env.RUNNER_ARCH }}
- name: Install (Node.js v16+)
if : ${{ matrix.node-version != '14.16' }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install (Node.js < v16)
if : ${{ matrix.node-version == '14.16' }}
run: yarn install --frozen-lockfile --ignore-engines
- name: Test
run: yarn test
run: yarn lint && yarn test
- name: Build docs
run: yarn build:docs
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.13
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const path = require('node:path');

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['node_modules', path.resolve(__dirname, 'lib')]
};
testPathIgnorePatterns: ['node_modules', path.resolve(__dirname, 'lib')],
};
58 changes: 12 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -14,89 +14,55 @@
"build": "tsc && tsc -p tsconfig.esm.json",
"build:docs": "npx typedoc",
"eslint": "eslint --ext .ts src test",
"jest": "jest --coverage",
"test": "jest",
"lint": "npm run prettier && npm run eslint",
"prettier": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
"prettier:write": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"prepublishOnly": "npm run build",
"test": "npm run lint && npm run jest",
"test:nonetwork": "npm run lint && npm run jest -- --testPathIgnorePatterns network.spec"
},
"files": [
"dist/",
"README.md"
],
"files": ["dist/", "README.md"],
"engines": {
"node": ">=14"
"node": ">=22.0.0"
},
"dependencies": {
"debug": "^4.1.1",
"env-paths": "^2.2.0",
"fs-extra": "^8.1.0",
"got": "^11.8.5",
"progress": "^2.0.3",
"semver": "^6.2.0",
"sumchecker": "^3.0.1"
},
"devDependencies": {
"@types/debug": "^4.1.4",
"@types/fs-extra": "^8.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^12.20.55",
"@types/node": "^22.10.5",
"@types/progress": "^2.0.3",
"@types/semver": "^6.2.0",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"eslint": "^6.8.0",
"@typescript-eslint/eslint-plugin": "^8.19.1",
"@typescript-eslint/parser": "^8.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "< 24.0.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest": "^28.10.0",
"husky": "^2.3.0",
"jest": "^29.3.1",
"lint-staged": "^13.0.4",
"prettier": "^3.4.2",
"ts-jest": "^29.0.0",
"typedoc": "~0.24.8",
"typescript": "^4.9.3"
},
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"prettier",
"prettier/@typescript-eslint"
]
"typescript": "^5.4.5"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.ts": [
"eslint --fix",
"prettier --write"
]
"*.ts": ["eslint --fix", "prettier --write"]
},
"keywords": [
"electron",
"download",
"prebuild",
"get",
"artifact",
"release"
],
"keywords": ["electron", "download", "prebuild", "get", "artifact", "release"],
"optionalDependencies": {
"global-agent": "^3.0.0"
},
"resolutions": {
"eslint/inquirer": "< 7.3.0",
"**/@typescript-eslint/typescript-estree/semver": "^6.3.0"
}
}
25 changes: 15 additions & 10 deletions src/Cache.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import debug from 'debug';
import envPaths from 'env-paths';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as url from 'url';
import * as crypto from 'crypto';

import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import url from 'node:url';

const d = debug('@electron/get:cache');

@@ -27,9 +28,9 @@ export class Cache {
return path.resolve(this.cacheRoot, Cache.getCacheDirectory(downloadUrl), fileName);
}

public async getPathForFileInCache(url: string, fileName: string): Promise<string | null> {
public getPathForFileInCache(url: string, fileName: string): string | null {
const cachePath = this.getCachePath(url, fileName);
if (await fs.pathExists(cachePath)) {
if (fs.existsSync(cachePath)) {
return cachePath;
}

@@ -39,12 +40,16 @@ export class Cache {
public async putFileInCache(url: string, currentPath: string, fileName: string): Promise<string> {
const cachePath = this.getCachePath(url, fileName);
d(`Moving ${currentPath} to ${cachePath}`);
if (await fs.pathExists(cachePath)) {
d('* Replacing existing file');
await fs.remove(cachePath);

if (!fs.existsSync(path.dirname(cachePath))) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this new clause is needed because fs.rename will fail if the target directory doesn't exist, while fs.move creates the directory.

This also doesn't work across disks, but we could catch the resulting error and fall back to an fs.copy call if necessary.

await fs.promises.mkdir(path.dirname(cachePath), { recursive: true });
}

await fs.move(currentPath, cachePath);
if (fs.existsSync(cachePath)) {
d('* Replacing existing file');
await fs.promises.rm(cachePath, { recursive: true, force: true });
}
await fs.promises.rename(currentPath, cachePath);

return cachePath;
}
8 changes: 4 additions & 4 deletions src/GotDownloader.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'fs-extra';
import got, { HTTPError, Progress as GotProgress, Options as GotOptions } from 'got';
import * as path from 'path';
import * as ProgressBar from 'progress';
import fs from 'node:fs';
import path from 'node:path';
import ProgressBar from 'progress';

import { Downloader } from './Downloader';

@@ -44,7 +44,7 @@ export class GotDownloader implements Downloader<GotDownloaderOptions> {
let bar: ProgressBar | undefined;
let progressPercent: number;
let timeout: NodeJS.Timeout | undefined = undefined;
await fs.mkdirp(path.dirname(targetFilePath));
await fs.promises.mkdir(path.dirname(targetFilePath), { recursive: true });
const writeStream = fs.createWriteStream(targetFilePath);

if (!quiet || !process.env.ELECTRON_GET_NO_PROGRESS) {
17 changes: 10 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import debug from 'debug';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as semver from 'semver';
import * as sumchecker from 'sumchecker';
import fs from 'node:fs/promises';
import path from 'node:path';
import semver from 'semver';
import sumchecker from 'sumchecker';

import { getArtifactFileName, getArtifactRemoteURL, getArtifactVersion } from './artifact-utils';
import {
@@ -110,7 +110,7 @@ async function validateArtifact(
}
} finally {
// Once we're done make sure we clean up the shasum temp dir
await fs.remove(path.dirname(shasumPath));
await fs.rm(path.dirname(shasumPath), { recursive: true, force: true });
}
}
},
@@ -162,7 +162,7 @@ export async function downloadArtifact(
// Do not check if the file exists in the cache when force === true
if (shouldTryReadCache(cacheMode)) {
d(`Checking the cache (${details.cacheRoot}) for ${fileName} (${url})`);
const cachedPath = await cache.getPathForFileInCache(url, fileName);
const cachedPath = cache.getPathForFileInCache(url, fileName);

if (cachedPath === null) {
d('Cache miss');
@@ -182,7 +182,7 @@ export async function downloadArtifact(
return artifactPath;
} catch (err) {
if (doesCallerOwnTemporaryOutput(cacheMode)) {
await fs.remove(path.dirname(artifactPath));
await fs.rm(path.dirname(artifactPath), { recursive: true, force: true });
}
d("Artifact in cache didn't match checksums", err);
d('falling back to re-download');
@@ -216,8 +216,11 @@ export async function downloadArtifact(
);
await downloader.download(url, tempDownloadPath, details.downloadOptions);

d('attempting to validate artifact...', { details });
await validateArtifact(details, tempDownloadPath, downloadArtifact);

d('artifact validated');

if (doesCallerOwnTemporaryOutput(cacheMode)) {
return tempDownloadPath;
} else {
3 changes: 2 additions & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as debug from 'debug';
import debug from 'debug';
import { getEnv, setEnv } from './utils';

const d = debug('@electron/get:proxy');
@@ -32,6 +32,7 @@ export function initializeProxy(): void {
* TODO: replace global-agent with a hpagent. @BlackHole1
* https://github.com/sindresorhus/got/blob/HEAD/documentation/tips.md#proxying
*/
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('global-agent').bootstrap();
} catch (e) {
d('Could not load either proxy modules, built-in proxy support not available:', e);
12 changes: 7 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as childProcess from 'child_process';
import * as fs from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import childProcess from 'node:child_process';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';

import {
ElectronDownloadCacheMode,
ElectronGenericArtifactDetails,
@@ -16,8 +17,9 @@ async function useAndRemoveDirectory<T>(
try {
result = await fn(directory);
} finally {
await fs.remove(directory);
await fs.rm(directory, { recursive: true, force: true });
}

return result;
}

Loading