diff --git a/package.json b/package.json index 7feab887..e270b096 100644 --- a/package.json +++ b/package.json @@ -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", "node-abi": "^3.45.0", "node-api-version": "^0.2.0", "ora": "^5.1.0", @@ -66,7 +66,7 @@ "@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": "~22.10.7", "@types/node-abi": "^3.0.0", diff --git a/src/cache.ts b/src/cache.ts index 3b03f55f..6d792f39 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,6 +1,6 @@ import crypto from 'node:crypto'; import debug from 'debug'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import zlib from 'node:zlib'; @@ -31,14 +31,14 @@ type CacheOptions = { const takeSnapshot = async (dir: string, relativeTo = dir): Promise => { 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, @@ -51,10 +51,10 @@ const takeSnapshot = async (dir: string, relativeTo = dir): Promise => const writeSnapshot = async (diff: Snapshot, dir: string): Promise => { 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); } } @@ -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(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; export const lookupModuleState = async (cachePath: string, key: string): Promise => { - if (await fs.pathExists(path.resolve(cachePath, key))) { + if (fs.existsSync(path.resolve(cachePath, key))) { return async function applyDiff(dir: string): Promise { - 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); @@ -133,7 +133,7 @@ async function hashDirectory(dir: string, relativeTo?: string): Promise { + 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; @@ -143,10 +143,10 @@ async function hashDirectory(dir: string, relativeTo?: string): Promise { for (const moduleName of electronModuleNames) { try { const modulePath = path.resolve(require.resolve(path.join(moduleName, 'package.json')), '..'); - if (await fs.pathExists(path.join(modulePath, 'package.json'))) { + if (fs.existsSync(path.join(modulePath, 'package.json'))) { return modulePath; } } catch { // eslint-disable-line no-empty @@ -26,7 +26,7 @@ export async function locateElectronModule( for (const moduleName of electronModuleNames) { const electronPaths = await searchForModule(startDir, moduleName, projectRootPath); - const electronPath = electronPaths.find(async (ePath: string) => await fs.pathExists(path.join(ePath, 'package.json'))); + const electronPath = electronPaths.find((ePath: string) => fs.existsSync(path.join(ePath, 'package.json'))); if (electronPath) { return electronPath; diff --git a/src/module-rebuilder.ts b/src/module-rebuilder.ts index 5ee6e11d..45384943 100644 --- a/src/module-rebuilder.ts +++ b/src/module-rebuilder.ts @@ -1,5 +1,5 @@ import debug from 'debug'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { cacheModuleState } from './cache'; @@ -38,8 +38,8 @@ export class ModuleRebuilder { } async alreadyBuiltByRebuild(): Promise { - if (await fs.pathExists(this.metaPath)) { - const meta = await fs.readFile(this.metaPath, 'utf8'); + if (fs.existsSync(this.metaPath)) { + const meta = await fs.promises.readFile(this.metaPath, 'utf8'); return meta === this.metaData; } @@ -120,25 +120,26 @@ export class ModuleRebuilder { const buildLocation = path.resolve(this.modulePath, 'build', this.rebuilder.buildType); d('searching for .node file', buildLocation); - const buildLocationFiles = await fs.readdir(buildLocation); + const buildLocationFiles = await fs.promises.readdir(buildLocation); d('testing files', buildLocationFiles); const nodeFile = buildLocationFiles.find((file) => file !== '.node' && file.endsWith('.node')); const nodePath = nodeFile ? path.resolve(buildLocation, nodeFile) : undefined; - if (nodePath && await fs.pathExists(nodePath)) { + if (nodePath && fs.existsSync(nodePath)) { d('found .node file', nodePath); if (!this.rebuilder.disablePreGypCopy) { const abiPath = path.resolve(this.modulePath, `bin/${this.rebuilder.platform}-${this.rebuilder.arch}-${this.rebuilder.ABI}`); d('copying to prebuilt place:', abiPath); - await fs.mkdir(abiPath, { recursive: true }); - await fs.copyFile(nodePath, path.join(abiPath, `${this.nodeGyp.moduleName}.node`)); + await fs.promises.mkdir(abiPath, { recursive: true }); + await fs.promises.copyFile(nodePath, path.join(abiPath, `${this.nodeGyp.moduleName}.node`)); } } } async writeMetadata(): Promise { - await fs.outputFile(this.metaPath, this.metaData); + await fs.promises.mkdir(path.dirname(this.metaPath), { recursive: true }); + await fs.promises.writeFile(this.metaPath, this.metaData); } async rebuild(cacheKey: string): Promise { diff --git a/src/module-type/index.ts b/src/module-type/index.ts index f4850612..626fd55b 100644 --- a/src/module-type/index.ts +++ b/src/module-type/index.ts @@ -1,4 +1,4 @@ -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { NodeAPI } from '../node-api'; @@ -80,7 +80,7 @@ export async function locateBinary(basePath: string, suffix: string): Promise { - return fs.pathExists(path.resolve(this.modulePath, 'prebuilds', `${this.rebuilder.platform}-${this.rebuilder.arch}`, `electron-${this.rebuilder.ABI}.node`)); + return fs.existsSync(path.resolve(this.modulePath, 'prebuilds', `${this.rebuilder.platform}-${this.rebuilder.arch}`, `electron-${this.rebuilder.ABI}.node`)); } async getPrebuildInstallRuntimeArgs(): Promise { diff --git a/src/module-type/prebuildify.ts b/src/module-type/prebuildify.ts index 16c62526..4700d83a 100644 --- a/src/module-type/prebuildify.ts +++ b/src/module-type/prebuildify.ts @@ -1,5 +1,5 @@ import debug from 'debug'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { ConfigVariables, getNodeArch } from '../arch'; @@ -40,7 +40,7 @@ export class Prebuildify extends NativeModule { d(`Checking for prebuilds for "${this.moduleName}"`); const prebuildsDir = path.join(this.modulePath, 'prebuilds'); - if (!(await fs.pathExists(prebuildsDir))) { + if (!(fs.existsSync(prebuildsDir))) { d(`Could not find the prebuilds directory at "${prebuildsDir}"`); return false; } @@ -52,10 +52,10 @@ export class Prebuildify extends NativeModule { const nodejsNapiModuleFilename = path.join(prebuiltModuleDir, `node.napi.${nativeExt}`); const abiModuleFilename = path.join(prebuiltModuleDir, `electron.abi${this.rebuilder.ABI}.${nativeExt}`); - if (await fs.pathExists(electronNapiModuleFilename) || await fs.pathExists(nodejsNapiModuleFilename)) { + if (fs.existsSync(electronNapiModuleFilename) || fs.existsSync(nodejsNapiModuleFilename)) { this.nodeAPI.ensureElectronSupport(); d(`Found prebuilt Node-API module in ${prebuiltModuleDir}"`); - } else if (await fs.pathExists(abiModuleFilename)) { + } else if (fs.existsSync(abiModuleFilename)) { d(`Found prebuilt module: "${abiModuleFilename}"`); } else { d(`Could not locate "${electronNapiModuleFilename}", "${nodejsNapiModuleFilename}", or "${abiModuleFilename}"`); diff --git a/src/module-walker.ts b/src/module-walker.ts index 02ab0ff8..df80c7a9 100644 --- a/src/module-walker.ts +++ b/src/module-walker.ts @@ -1,5 +1,5 @@ import debug from 'debug'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { readPackageJson } from './read-package-json'; @@ -82,7 +82,7 @@ export class ModuleWalker { } async markChildrenAsProdDeps(modulePath: string): Promise { - if (!await fs.pathExists(modulePath)) { + if (!fs.existsSync(modulePath)) { return; } @@ -113,7 +113,7 @@ export class ModuleWalker { // Some package managers use symbolic links when installing node modules // we need to be sure we've never tested the a package before by resolving // all symlinks in the path and testing against a set - const realNodeModulesPath = await fs.realpath(nodeModulesPath); + const realNodeModulesPath = await fs.promises.realpath(nodeModulesPath); if (this.realNodeModulesPaths.has(realNodeModulesPath)) { return; } @@ -121,12 +121,12 @@ export class ModuleWalker { d('scanning:', realNodeModulesPath); - for (const modulePath of await fs.readdir(realNodeModulesPath)) { + for (const modulePath of await fs.promises.readdir(realNodeModulesPath)) { // Ignore the magical .bin directory if (modulePath === '.bin') continue; // Ensure that we don't mark modules as needing to be rebuilt more than once // by ignoring / resolving symlinks - const realPath = await fs.realpath(path.resolve(nodeModulesPath, modulePath)); + const realPath = await fs.promises.realpath(path.resolve(nodeModulesPath, modulePath)); if (this.realModulePaths.has(realPath)) { continue; @@ -141,7 +141,7 @@ export class ModuleWalker { await this.findAllModulesIn(realPath, `${modulePath}/`); } - if (await fs.pathExists(path.resolve(nodeModulesPath, modulePath, 'node_modules'))) { + if (fs.existsSync(path.resolve(nodeModulesPath, modulePath, 'node_modules'))) { await this.findAllModulesIn(path.resolve(realPath, 'node_modules')); } } diff --git a/src/read-package-json.ts b/src/read-package-json.ts index 9ea8bce3..1b3349cb 100644 --- a/src/read-package-json.ts +++ b/src/read-package-json.ts @@ -1,10 +1,12 @@ -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; // eslint-disable-next-line @typescript-eslint/no-explicit-any export async function readPackageJson(dir: string, safe = false): Promise { try { - return await fs.readJson(path.resolve(dir, 'package.json')); + return JSON.parse(await fs.promises.readFile(path.resolve(dir, 'package.json'), { + encoding: 'utf-8', + })); } catch (err) { if (safe) { return {}; diff --git a/src/rebuild.ts b/src/rebuild.ts index 5ccc1652..cc56ff23 100644 --- a/src/rebuild.ts +++ b/src/rebuild.ts @@ -1,6 +1,6 @@ import debug from 'debug'; import { EventEmitter } from 'node:events'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import nodeAbi from 'node-abi'; import os from 'node:os'; import path from 'node:path'; @@ -262,7 +262,7 @@ export class Rebuilder implements IRebuilder { } async rebuildModuleAt(modulePath: string): Promise { - if (!(await fs.pathExists(path.resolve(modulePath, 'binding.gyp')))) { + if (!(fs.existsSync(path.resolve(modulePath, 'binding.gyp')))) { return; } diff --git a/src/search-module.ts b/src/search-module.ts index eae57adf..4551c105 100644 --- a/src/search-module.ts +++ b/src/search-module.ts @@ -1,11 +1,11 @@ -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; async function shouldContinueSearch(traversedPath: string, rootPath?: string, stopAtPackageJSON?: boolean): Promise { if (rootPath) { return Promise.resolve(traversedPath !== path.dirname(rootPath)); } else if (stopAtPackageJSON) { - return fs.pathExists(path.join(traversedPath, 'package.json')); + return fs.existsSync(path.join(traversedPath, 'package.json')); } else { return true; } @@ -25,7 +25,7 @@ async function traverseAncestorDirectories( while (await shouldContinueSearch(traversedPath, rootPath, stopAtPackageJSON)) { const generatedPath = pathGenerator(traversedPath); - if (await fs.pathExists(generatedPath)) { + if (fs.existsSync(generatedPath)) { paths.push(generatedPath); } diff --git a/src/sysroot-fetcher.ts b/src/sysroot-fetcher.ts index 67906555..37402d36 100644 --- a/src/sysroot-fetcher.ts +++ b/src/sysroot-fetcher.ts @@ -1,7 +1,7 @@ import { spawn } from '@malept/cross-spawn-promise'; import crypto from 'node:crypto'; import debug from 'debug'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { ELECTRON_GYP_DIR } from './constants'; @@ -19,8 +19,8 @@ const SYSROOT_BASE_URL = 'https://dev-cdn.electronjs.org/linux-sysroots'; export async function downloadLinuxSysroot(electronVersion: string, targetArch: string): Promise { d('fetching sysroot for Electron:', electronVersion); const sysrootDir = path.resolve(ELECTRON_GYP_DIR, `${electronVersion}-sysroot`); - if (await fs.pathExists(path.resolve(sysrootDir, 'lib'))) return sysrootDir; - if (!await fs.pathExists(sysrootDir)) await fs.mkdirp(sysrootDir); + if (fs.existsSync(path.resolve(sysrootDir, 'lib'))) return sysrootDir; + await fs.promises.mkdir(sysrootDir, { recursive: true }); const linuxArch = sysrootArchAliases[targetArch] || targetArch; const electronSysroots = JSON.parse(await fetch(`https://raw.githubusercontent.com/electron/electron/v${electronVersion}/script/sysroots.json`, 'text')); @@ -36,8 +36,8 @@ export async function downloadLinuxSysroot(electronVersion: string, targetArch: d('writing sysroot to disk'); const tmpTarFile = path.resolve(ELECTRON_GYP_DIR, `${electronVersion}-${fileName}`); - if (await fs.pathExists(tmpTarFile)) await fs.remove(tmpTarFile); - await fs.writeFile(tmpTarFile, sysrootBuffer); + if (fs.existsSync(tmpTarFile)) await fs.promises.rm(tmpTarFile, { recursive: true, force: true }); + await fs.promises.writeFile(tmpTarFile, sysrootBuffer); d('decompressing sysroot'); await spawn('tar', ['-xf', tmpTarFile, '-C', sysrootDir], { stdio: 'ignore' }); diff --git a/test/electron-locator.ts b/test/electron-locator.ts index e3f95133..743cc514 100644 --- a/test/electron-locator.ts +++ b/test/electron-locator.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { locateElectronModule } from '../lib/electron-locator'; @@ -11,7 +11,7 @@ async function expectElectronCanBeFound(projectRootPath: string, startDir: strin const electronPath = await locateElectronModule(projectRootPath, startDir); expect(electronPath).to.be.a('string'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - expect(await fs.pathExists(electronPath!)).to.be.equal(true); + expect(fs.existsSync(electronPath!)).to.be.equal(true); }); } @@ -20,7 +20,7 @@ describe('locateElectronModule', () => { const electronDir = path.resolve(__dirname, '..', 'node_modules', 'electron'); before(async () => { - await fs.rename(electronDir, `${electronDir}-moved`); + await fs.promises.rename(electronDir, `${electronDir}-moved`); }); it('should return null when electron is not installed', async () => { @@ -29,7 +29,7 @@ describe('locateElectronModule', () => { }); after(async () => { - await fs.rename(`${electronDir}-moved`, electronDir); + await fs.promises.rename(`${electronDir}-moved`, electronDir); }); }); diff --git a/test/helpers/electron-version.ts b/test/helpers/electron-version.ts index ce1d8b7a..2a8c41e9 100644 --- a/test/helpers/electron-version.ts +++ b/test/helpers/electron-version.ts @@ -1,4 +1,4 @@ -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; function electronVersionPath() { diff --git a/test/helpers/module-setup.ts b/test/helpers/module-setup.ts index df640523..7df8e979 100644 --- a/test/helpers/module-setup.ts +++ b/test/helpers/module-setup.ts @@ -1,6 +1,6 @@ import debug from 'debug'; import crypto from 'node:crypto'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import os from 'node:os'; import path from 'node:path'; import { spawn } from '@malept/cross-spawn-promise'; @@ -25,24 +25,24 @@ const testModuleTmpPath = fs.mkdtempSync(path.resolve(os.tmpdir(), 'e-r-test-mod export async function resetTestModule(testModulePath: string, installModules = true, fixtureName = 'native-app1'): Promise { const oneTimeModulePath = path.resolve(testModuleTmpPath, `${crypto.createHash('SHA1').update(testModulePath).digest('hex')}-${fixtureName}-${installModules}`); - if (!await fs.pathExists(oneTimeModulePath)) { + if (!fs.existsSync(oneTimeModulePath)) { d(`creating test module '%s' in %s`, fixtureName, oneTimeModulePath); - await fs.mkdir(oneTimeModulePath, { recursive: true }); - await fs.copy(path.resolve(__dirname, `../../test/fixture/${ fixtureName }`), oneTimeModulePath); + await fs.promises.mkdir(oneTimeModulePath, { recursive: true }); + await fs.promises.cp(path.resolve(__dirname, `../../test/fixture/${ fixtureName }`), oneTimeModulePath, { recursive: true, force: true }); if (installModules) { await spawn('yarn', ['install'], { cwd: oneTimeModulePath }); } } - await fs.remove(testModulePath); - await fs.copy(oneTimeModulePath, testModulePath); + await fs.promises.rm(testModulePath, { recursive: true, force: true }); + await fs.promises.cp(oneTimeModulePath, testModulePath, { recursive: true, force: true }); resetMSVSVersion(); } export async function cleanupTestModule(testModulePath: string): Promise { - await fs.rm(testModulePath, { recursive: true, maxRetries: 10 }); + await fs.promises.rm(testModulePath, { recursive: true, force: true, maxRetries: 10 }); resetMSVSVersion(); } process.on('exit', () => { - fs.removeSync(testModuleTmpPath); + fs.rmSync(testModuleTmpPath, { recursive: true, force: true }); }); diff --git a/test/helpers/rebuild.ts b/test/helpers/rebuild.ts index 0178a606..36a77db8 100644 --- a/test/helpers/rebuild.ts +++ b/test/helpers/rebuild.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; type ExpectRebuildOptions = { @@ -16,7 +16,7 @@ export async function expectNativeModuleToBeRebuilt( const message = `${path.basename(modulePath)} build meta should ${metaShouldExist ? '' : 'not '}exist`; const buildType = options.buildType || 'Release'; const metaPath = path.resolve(basePath, 'node_modules', modulePath, 'build', buildType, '.forge-meta'); - expect(await fs.pathExists(metaPath), message).to.equal(metaShouldExist); + expect(fs.existsSync(metaPath), message).to.equal(metaShouldExist); } export async function expectNativeModuleToNotBeRebuilt( diff --git a/test/module-type-node-gyp.ts b/test/module-type-node-gyp.ts index 1bde1fd4..7936ff0e 100644 --- a/test/module-type-node-gyp.ts +++ b/test/module-type-node-gyp.ts @@ -74,7 +74,7 @@ describe('node-gyp', () => { platform }); const nodeGyp = new NodeGyp(rebuilder, testModulePath); - + const errorMessage = "node-gyp does not support cross-compiling native modules from source."; expect(nodeGyp.rebuildModule()).to.eventually.be.rejectedWith(new Error(errorMessage)); }); diff --git a/test/module-type-prebuildify.ts b/test/module-type-prebuildify.ts index 5990d04c..d79165ab 100644 --- a/test/module-type-prebuildify.ts +++ b/test/module-type-prebuildify.ts @@ -113,21 +113,21 @@ describe('prebuildify', () => { }); }); }); - + describe('cross-platform downloads', async () => { it('should download for target platform', async () => { const fixtureDir = path.join(fixtureBaseDir, 'napi'); let rebuilder = createRebuilder(); let prebuildify = new Prebuildify(rebuilder, fixtureDir); expect(await prebuildify.findPrebuiltModule()).to.equal(true); - + let alternativePlatform: NodeJS.Platform; if (process.platform === 'win32') { alternativePlatform = 'darwin'; } else { alternativePlatform = 'win32'; } - + rebuilder = createRebuilder({ platform: alternativePlatform }); prebuildify = new Prebuildify(rebuilder, fixtureDir); expect(await prebuildify.findPrebuiltModule()).to.equal(true); diff --git a/test/rebuild-napibuildversion.ts b/test/rebuild-napibuildversion.ts index e9df2302..0e8eee10 100644 --- a/test/rebuild-napibuildversion.ts +++ b/test/rebuild-napibuildversion.ts @@ -1,4 +1,4 @@ -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { expect } from 'chai'; @@ -29,11 +29,9 @@ describe('rebuild with napi_build_versions in binary config', async function () it(`${ arch } arch should have rebuilt binary with 'napi_build_versions' array and 'libc' provided`, async () => { const libc = await detectLibc.family() || 'unknown'; const binaryPath = napiBuildVersionSpecificPath(arch, libc); - - if (await fs.pathExists(binaryPath)) { - fs.removeSync(binaryPath); - } - expect(await fs.pathExists(binaryPath)).to.be.false; + + await fs.promises.rm(binaryPath, { recursive: true, force: true }); + expect(fs.existsSync(binaryPath)).to.be.false; await rebuild({ buildPath: testModulePath, @@ -41,9 +39,9 @@ describe('rebuild with napi_build_versions in binary config', async function () arch, buildFromSource: true, // need to skip node-pre-gyp prebuilt binary }); - + await expectNativeModuleToBeRebuilt(testModulePath, 'sqlite3'); - expect(await fs.pathExists(binaryPath)).to.be.true; + expect(fs.existsSync(binaryPath)).to.be.true; }); } diff --git a/test/rebuild.ts b/test/rebuild.ts index 5a049899..322127ce 100644 --- a/test/rebuild.ts +++ b/test/rebuild.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'node:events'; import { expect } from 'chai'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import path from 'node:path'; import { cleanupTestModule, MINUTES_IN_MILLISECONDS, TEST_MODULE_PATH as testModulePath, resetMSVSVersion, resetTestModule, TIMEOUT_IN_MILLISECONDS } from './helpers/module-setup'; @@ -51,7 +51,7 @@ describe('rebuilder', () => { it('should not download files in the module directory', async () => { const modulePath = path.resolve(testModulePath, 'node_modules/ref-napi'); - const fileNames = await fs.readdir(modulePath); + const fileNames = await fs.promises.readdir(modulePath); expect(fileNames).to.not.contain(testElectronVersion); }); @@ -148,9 +148,9 @@ describe('rebuilder', () => { it('should rebuild only specified modules', async () => { const nativeModuleBinary = path.join(testModulePath, 'node_modules', 'native-hello-world', 'build', 'Release', 'hello_world.node'); - expect(await fs.pathExists(nativeModuleBinary)).to.be.true; - await fs.remove(nativeModuleBinary); - expect(await fs.pathExists(nativeModuleBinary)).to.be.false; + expect(fs.existsSync(nativeModuleBinary)).to.be.true; + await fs.promises.rm(nativeModuleBinary, { recursive: true, force: true }); + expect(fs.existsSync(nativeModuleBinary)).to.be.false; const rebuilder = rebuild({ buildPath: testModulePath, electronVersion: testElectronVersion, @@ -162,7 +162,7 @@ describe('rebuilder', () => { rebuilder.lifecycle.on('module-done', () => built++); await rebuilder; expect(built).to.equal(1); - expect(await fs.pathExists(nativeModuleBinary)).to.be.true; + expect(fs.existsSync(nativeModuleBinary)).to.be.true; }); it('should rebuild multiple specified modules via --only option', async () => { diff --git a/test/search-module.ts b/test/search-module.ts index 17125c94..45a227aa 100644 --- a/test/search-module.ts +++ b/test/search-module.ts @@ -1,5 +1,5 @@ import { expect } from 'chai'; -import fs from 'fs-extra'; +import fs from 'graceful-fs'; import os from 'node:os'; import path from 'node:path'; @@ -8,11 +8,11 @@ import { getProjectRootPath } from '../lib/search-module'; let baseDir: string; async function createTempDir(): Promise { - baseDir = await fs.mkdtemp(path.join(os.tmpdir(), 'electron-rebuild-test-')); + baseDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'electron-rebuild-test-')); } async function removeTempDir(): Promise { - await fs.remove(baseDir); + await fs.promises.rm(baseDir, { recursive: true, force: true }); } describe('search-module', () => { @@ -22,8 +22,14 @@ describe('search-module', () => { describe(lockFile, () => { before(async () => { await createTempDir(); - await fs.copy(path.resolve(__dirname, 'fixture', 'multi-level-workspace'), baseDir); - await fs.ensureFile(path.join(baseDir, lockFile)); + await fs.promises.cp(path.resolve(__dirname, 'fixture', 'multi-level-workspace'), baseDir, { recursive: true, force: true }); + + const lockfilePath = path.join(baseDir, lockFile); + + if(!fs.existsSync(lockfilePath)) { + await fs.promises.mkdir(baseDir, { recursive: true }); + await fs.promises.writeFile(lockFile, Buffer.from([])); + } }); it('finds the folder with the lockfile', async () => { diff --git a/yarn.lock b/yarn.lock index 2d02e203..c32278f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -527,10 +527,10 @@ dependencies: "@types/ms" "*" -"@types/fs-extra@^9.0.1": - version "9.0.13" - resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-9.0.13.tgz#7594fbae04fe7f1918ce8b3d213f74ff44ac1f45" - integrity sha512-nEnwB++1u5lVDM2UI4c1+5R+FYaKfaAzS4OococimjVm3nQw3TuzH5UNsocrcTBbhnerblyHj4A49qXbIiZdpA== +"@types/graceful-fs@^4.1.9": + version "4.1.9" + resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.9.tgz#2a06bc0f68a20ab37b3e36aa238be6abdf49e8b4" + integrity sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ== dependencies: "@types/node" "*" @@ -1626,15 +1626,6 @@ fromentries@^1.2.0: resolved "https://registry.yarnpkg.com/fromentries/-/fromentries-1.3.2.tgz#e4bca6808816bf8f93b52750f1127f5a6fd86e3a" integrity sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg== -fs-extra@^10.0.0: - version "10.0.1" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.1.tgz#27de43b4320e833f6867cc044bfce29fdf0ef3b8" - integrity sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag== - dependencies: - graceful-fs "^4.2.0" - jsonfile "^6.0.1" - universalify "^2.0.0" - fs-extra@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0" @@ -1788,7 +1779,7 @@ graceful-fs@^4.1.15, graceful-fs@^4.1.6, graceful-fs@^4.2.0: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a" integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg== -graceful-fs@^4.2.6: +graceful-fs@^4.2.11, graceful-fs@^4.2.6: version "4.2.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== @@ -2121,15 +2112,6 @@ jsonfile@^4.0.0: optionalDependencies: graceful-fs "^4.1.6" -jsonfile@^6.0.1: - version "6.1.0" - resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" - integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== - dependencies: - universalify "^2.0.0" - optionalDependencies: - graceful-fs "^4.1.6" - keyv@^4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.0.3.tgz#4f3aa98de254803cafcd2896734108daa35e4254" @@ -3195,11 +3177,6 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== -universalify@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" - integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== - uri-js@^4.2.2: version "4.4.1" resolved "https://registry.yarnpkg.com/uri-js/-/uri-js-4.4.1.tgz#9b1a52595225859e55f669d928f88c6c57f2a77e"