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 requirement to Node 22 #1167

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.d.ts
Copy link
Member

Choose a reason for hiding this comment

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

Interesting! I'm not against it, just surprised that eslint can't handle d.ts files.

/node_modules
30 changes: 30 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2025,
sourceType: 'module',
},
plugins: ['mocha', '@typescript-eslint'],
env: {
es6: true,
mocha: true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'mocha/no-exclusive-tests': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
vars: 'all',
},
],
semi: 'off',
'@typescript-eslint/semi': 'error',
'no-unexpected-multiline': 'error',
},
};
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: 20.x
node-version: 22.12.x
cache: 'yarn'
- name: Install
run: yarn install --frozen-lockfile
Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ jobs:
strategy:
matrix:
node-version:
- '20.9'
- '18.17'
- '16.20'
- '14.16'
- '22.12.x'
os:
- macos-latest
- ubuntu-latest
Expand All @@ -33,9 +30,6 @@ jobs:
GYP_MSVS_VERSION: '2022'
steps:
- run: git config --global core.autocrlf input
- name: Install Rosetta
if: ${{ matrix.os == 'macos-latest' && (matrix.node-version == '14.16' || matrix.node-version == '12.22') }}
run: /usr/sbin/softwareupdate --install-rosetta --agree-to-license
- name: Enable Long Paths (Windows)
if : ${{ matrix.os == 'windows-latest' }}
run: |
Expand All @@ -53,11 +47,7 @@ jobs:
with:
node-version: "${{ matrix.node-version }}"
cache: 'yarn'
architecture: ${{ matrix.os == 'macos-latest' && (matrix.node-version == '14.16' || matrix.node-version == '12.22') && 'x64' || env.RUNNER_ARCH }}
- name: Update npm
if: ${{ matrix.node-version == '14.16' || matrix.node-version == '12.22' }}
run: npm install -g npm@8 # Update npm so it works with latest Python 3
- name: Install
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Lint
run: yarn run lint
Expand Down
10 changes: 10 additions & 0 deletions .mocharc.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// See also: https://github.com/mochajs/mocha/blob/b720ec1b3ca630a90f80311da391b2a0cdfead4e/example/config/.mocharc.js
{
"$schema": "https://json.schemastore.org/mocharc",
"color": false,
"extensions": [
"ts"
],
"import": "tsx",
"spec": ["test/*.ts"]
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.12
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ npm run rebuild

### What are the requirements?

Node v12.13.0 or higher is required. Building native modules from source uses
Node v22.12.0 or higher is required. Building native modules from source uses
[`node-gyp`](https://github.com/nodejs/node-gyp#installation), refer to the link for its
installation/runtime requirements.

Expand Down Expand Up @@ -102,7 +102,7 @@ for Electron Packager. For example:

```javascript
import packager from '@electron/packager';
import rebuild from '@electron/rebuild';
import { rebuild } from '@electron/rebuild';
Copy link
Member

Choose a reason for hiding this comment

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

👏


packager({
// … other options
Expand All @@ -128,7 +128,7 @@ electron-rebuild is also a library that you can require into your app or
build process. It has a very simple API:

```javascript
import rebuild from '@electron/rebuild';
import { rebuild } from '@electron/rebuild';

// Public: Rebuilds a node_modules directory with the given Electron version.
//
Expand All @@ -155,7 +155,7 @@ const childProcess = require('child_process');
const pathToElectron = require('electron');

rebuild({
buildPath: __dirname,
buildPath: import.meta.dirname,
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should document both here, I know that the __dirname vs import.meta.dirname thing keeps tripping people up quite a bit.

electronVersion: '1.4.12'
})
.then(() => console.info('Rebuild Successful'))
Expand Down
76 changes: 15 additions & 61 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "@electron/rebuild",
"version": "0.0.0-development",
"description": "Electron supporting package to rebuild native node modules against the currently installed electron",
"main": "lib/main.js",
"type": "module",
"exports": "./lib/main.js",
"typings": "lib/main.d.ts",
"scripts": {
"compile": "tsc",
"build": "tsc",
"coverage": "npm run prewarm-headers && nyc npm run spec",
"coverage:report": "nyc report --reporter=text-lcov > coverage.lcov",
"watch": "tsc -w",
"prepare": "npm run compile",
"mocha": "cross-env TS_NODE_FILES=true mocha",
"prepare": "npm run build",
"lint": "eslint --ext .ts .",
"spec": "tsc && npm run mocha -- test/*.ts",
"spec": "tsc && mocha",
"test": "npm run prewarm-headers && npm run lint && npm run spec",
"prewarm-headers": "node-gyp install --ensure"
},
Expand All @@ -39,7 +39,7 @@
},
"homepage": "https://github.com/electron/rebuild",
"engines": {
"node": ">=12.13.0"
"node": ">=22.12.0"
},
"publishConfig": {
"provenance": true
Expand All @@ -50,8 +50,8 @@
"chalk": "^4.0.0",
"debug": "^4.1.1",
"detect-libc": "^2.0.1",
"fs-extra": "^10.0.0",
"got": "^11.7.0",
"graceful-fs": "^4.2.11",
Copy link
Member

Choose a reason for hiding this comment

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

Appreciate it, thank you

"node-abi": "^3.45.0",
"node-api-version": "^0.2.0",
"ora": "^5.1.0",
Expand All @@ -62,74 +62,28 @@
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@tsconfig/node22": "^22.0.0",
"@types/chai": "^4.2.12",
"@types/chai-as-promised": "^7.1.3",
"@types/debug": "^4.1.5",
"@types/fs-extra": "^9.0.1",
"@types/graceful-fs": "^4.1.9",
"@types/mocha": "^10.0.10",
"@types/node": "^17.0.8",
"@types/node": "~22.10.7",
"@types/node-abi": "^3.0.0",
"@types/semver": "^7.3.9",
"@types/tar": "^6.1.0",
"@types/yargs": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^4.0.1",
"@typescript-eslint/parser": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.2",
"electron": "^22.0.0",
"eslint": "^7.7.0",
"eslint-plugin-mocha": "^9.0.0",
"mocha": "^10.8.2",
"mocha": "^11.1.0",
"nyc": "^15.1.0",
"ts-node": "^10.0.0",
"typescript": "^4.0.2"
},
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "module"
},
"plugins": [
"mocha",
"@typescript-eslint"
],
"env": {
"es6": true,
"mocha": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"mocha/no-exclusive-tests": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"args": "after-used",
"argsIgnorePattern": "^_",
"ignoreRestSiblings": true,
"vars": "all"
}
],
"semi": "off",
"@typescript-eslint/semi": "error",
"no-unexpected-multiline": "error"
}
},
"eslintIgnore": [
"*.d.ts",
"node_modules"
],
"mocha": {
"extensions": [
"ts"
],
"require": "ts-node/register"
"tsx": "^4.19.3",
"typescript": "~5.4.5"
},
"nyc": {
"extends": "@istanbuljs/nyc-config-typescript"
Expand Down
2 changes: 1 addition & 1 deletion src/arch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync } from 'child_process';
import { execSync } from 'node:child_process';

/**
* Runs the `uname` command and returns the trimmed output.
Expand Down
36 changes: 18 additions & 18 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import crypto from 'crypto';
import crypto from 'node:crypto';
import debug from 'debug';
import fs from 'fs-extra';
import path from 'path';
import zlib from 'zlib';
import fs from 'graceful-fs';
import path from 'node:path';
import zlib from 'node:zlib';

const d = debug('electron-rebuild');

Expand Down Expand Up @@ -31,14 +31,14 @@ type CacheOptions = {

const takeSnapshot = async (dir: string, relativeTo = dir): Promise<Snapshot> => {
const snap: Snapshot = {};
await Promise.all((await fs.readdir(dir)).map(async (child) => {
await Promise.all((await fs.promises.readdir(dir)).map(async (child) => {
if (child === 'node_modules') return;
const childPath = path.resolve(dir, child);
const relative = path.relative(relativeTo, childPath);
if ((await fs.stat(childPath)).isDirectory()) {
if ((await fs.promises.stat(childPath)).isDirectory()) {
snap[relative] = await takeSnapshot(childPath, relativeTo);
} else {
const data = await fs.readFile(childPath);
const data = await fs.promises.readFile(childPath);
snap[relative] = new Snap(
crypto.createHash('SHA256').update(data).digest('hex'),
data,
Expand All @@ -51,10 +51,10 @@ const takeSnapshot = async (dir: string, relativeTo = dir): Promise<Snapshot> =>
const writeSnapshot = async (diff: Snapshot, dir: string): Promise<void> => {
for (const key in diff) {
if (diff[key] instanceof Snap) {
await fs.mkdirp(path.dirname(path.resolve(dir, key)));
await fs.writeFile(path.resolve(dir, key), (diff[key] as Snap).data);
await fs.promises.mkdir(path.dirname(path.resolve(dir, key)), { recursive: true });
await fs.promises.writeFile(path.resolve(dir, key), (diff[key] as Snap).data);
} else {
await fs.mkdirp(path.resolve(dir, key));
await fs.promises.mkdir(path.resolve(dir, key), { recursive: true });
await writeSnapshot(diff[key] as Snapshot, dir);
}
}
Expand Down Expand Up @@ -99,17 +99,17 @@ export const cacheModuleState = async (dir: string, cachePath: string, key: stri
const snap = await takeSnapshot(dir);

const moduleBuffer = Buffer.from(JSON.stringify(serialize(snap)));
const zipped = await new Promise(resolve => zlib.gzip(moduleBuffer, (_, result) => resolve(result)));
await fs.mkdirp(cachePath);
await fs.writeFile(path.resolve(cachePath, key), zipped);
const zipped = await new Promise<Buffer>(resolve => zlib.gzip(moduleBuffer, (_, result) => resolve(result)));
await fs.promises.mkdir(cachePath, { recursive: true });
await fs.promises.writeFile(path.resolve(cachePath, key), zipped);
};

type ApplyDiffFunction = (dir: string) => Promise<void>;

export const lookupModuleState = async (cachePath: string, key: string): Promise<ApplyDiffFunction | boolean> => {
if (await fs.pathExists(path.resolve(cachePath, key))) {
if (fs.existsSync(path.resolve(cachePath, key))) {
return async function applyDiff(dir: string): Promise<void> {
const zipped = await fs.readFile(path.resolve(cachePath, key));
const zipped = await fs.promises.readFile(path.resolve(cachePath, key));
const unzipped: Buffer = await new Promise(resolve => { zlib.gunzip(zipped, (_, result) => resolve(result)); });
const diff = unserialize(JSON.parse(unzipped.toString()));
await writeSnapshot(diff, dir);
Expand All @@ -133,7 +133,7 @@ async function hashDirectory(dir: string, relativeTo?: string): Promise<HashTree
relativeTo ??= dir;
d('hashing dir', dir);
const dirTree: HashTree = {};
await Promise.all((await fs.readdir(dir)).map(async (child) => {
await Promise.all((await fs.promises.readdir(dir)).map(async (child) => {
d('found child', child, 'in dir', dir);
// Ignore output directories
if (dir === relativeTo && (child === 'build' || child === 'bin')) return;
Expand All @@ -143,10 +143,10 @@ async function hashDirectory(dir: string, relativeTo?: string): Promise<HashTree
const childPath = path.resolve(dir, child);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const relative = path.relative(relativeTo!, childPath);
if ((await fs.stat(childPath)).isDirectory()) {
if ((await fs.promises.stat(childPath)).isDirectory()) {
dirTree[relative] = await hashDirectory(childPath, relativeTo);
} else {
dirTree[relative] = crypto.createHash('SHA256').update(await fs.readFile(childPath)).digest('hex');
dirTree[relative] = crypto.createHash('SHA256').update(await fs.promises.readFile(childPath)).digest('hex');
}
}));

Expand Down
Loading
Loading