diff --git a/package.json b/package.json index 94b01519..fcf4d435 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "jest": "jest --coverage", "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" @@ -53,7 +54,7 @@ "husky": "^2.3.0", "jest": "^29.3.1", "lint-staged": "^13.0.4", - "prettier": "^1.17.1", + "prettier": "^3.4.2", "ts-jest": "^29.0.0", "typedoc": "~0.24.8", "typescript": "^4.9.3" diff --git a/src/Cache.ts b/src/Cache.ts index 04f5107f..26bc83b2 100644 --- a/src/Cache.ts +++ b/src/Cache.ts @@ -20,10 +20,7 @@ export class Cache { const { search, hash, pathname, ...rest } = parsedDownloadUrl; const strippedUrl = url.format({ ...rest, pathname: path.dirname(pathname || 'electron') }); - return crypto - .createHash('sha256') - .update(strippedUrl) - .digest('hex'); + return crypto.createHash('sha256').update(strippedUrl).digest('hex'); } public getCachePath(downloadUrl: string, fileName: string): string { diff --git a/src/GotDownloader.ts b/src/GotDownloader.ts index d67c3c4c..ee6c7f0f 100644 --- a/src/GotDownloader.ts +++ b/src/GotDownloader.ts @@ -13,7 +13,7 @@ const PROGRESS_BAR_DELAY_IN_SECONDS = 30; * @category Downloader * @see {@link https://github.com/sindresorhus/got/tree/v11.8.5?tab=readme-ov-file#options | `got#options`} for possible keys/values. */ -export type GotDownloaderOptions = (GotOptions) & { isStream?: true } & { +export type GotDownloaderOptions = GotOptions & { isStream?: true } & { /** * if defined, triggers every time `got`'s * {@link https://github.com/sindresorhus/got/tree/v11.8.5?tab=readme-ov-file#downloadprogress | `downloadProgress``} event callback is triggered. @@ -66,7 +66,7 @@ export class GotDownloader implements Downloader { } await new Promise((resolve, reject) => { const downloadStream = got.stream(url, gotOptions); - downloadStream.on('downloadProgress', async progress => { + downloadStream.on('downloadProgress', async (progress) => { progressPercent = progress.percent; if (bar) { bar.update(progress.percent); @@ -75,7 +75,7 @@ export class GotDownloader implements Downloader { await getProgressCallback(progress); } }); - downloadStream.on('error', error => { + downloadStream.on('error', (error) => { if (error instanceof HTTPError && error.response.statusCode === 404) { error.message += ` for ${error.response.url}`; } @@ -85,7 +85,7 @@ export class GotDownloader implements Downloader { reject(error); }); - writeStream.on('error', error => reject(error)); + writeStream.on('error', (error) => reject(error)); writeStream.on('close', () => resolve()); downloadStream.pipe(writeStream); diff --git a/src/index.ts b/src/index.ts index 23686955..21cc78f6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -50,7 +50,7 @@ async function validateArtifact( ): Promise { return await withTempDirectoryIn( artifactDetails.tempDirectory, - async tempFolder => { + async (tempFolder) => { // Don't try to verify the hash of the hash file itself // and for older versions that don't have a SHASUMS256.txt if ( @@ -69,7 +69,7 @@ async function validateArtifact( ); } const generatedChecksums = fileNames - .map(fileName => `${checksums[fileName]} *${fileName}`) + .map((fileName) => `${checksums[fileName]} *${fileName}`) .join('\n'); await fs.writeFile(shasumPath, generatedChecksums); } else { @@ -205,7 +205,7 @@ export async function downloadArtifact( return await withTempDirectoryIn( details.tempDirectory, - async tempFolder => { + async (tempFolder) => { const tempDownloadPath = path.resolve(tempFolder, getArtifactFileName(details)); const downloader = details.downloader || (await getDownloaderForSystem()); diff --git a/src/utils.ts b/src/utils.ts index 284b6c95..a89ce93d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -62,10 +62,7 @@ export function normalizeVersion(version: string): string { * Runs the `uname` command and returns the trimmed output. */ export function uname(): string { - return childProcess - .execSync('uname -m') - .toString() - .trim(); + return childProcess.execSync('uname -m').toString().trim(); } /** diff --git a/test/GotDownloader.network.spec.ts b/test/GotDownloader.network.spec.ts index e2a7e3dd..525cabf3 100644 --- a/test/GotDownloader.network.spec.ts +++ b/test/GotDownloader.network.spec.ts @@ -10,7 +10,7 @@ describe('GotDownloader', () => { it('should download a remote file to the given file path', async () => { const downloader = new GotDownloader(); let progressCallbackCalled = false; - await withTempDirectory(async dir => { + await withTempDirectory(async (dir) => { const testFile = path.resolve(dir, 'test.txt'); expect(await fs.pathExists(testFile)).toEqual(false); await downloader.download( @@ -29,9 +29,9 @@ describe('GotDownloader', () => { }, TempDirCleanUpMode.CLEAN); }); - it('should throw an error if the file does not exist', async function() { + it('should throw an error if the file does not exist', async function () { const downloader = new GotDownloader(); - await withTempDirectory(async dir => { + await withTempDirectory(async (dir) => { const testFile = path.resolve(dir, 'test.txt'); const url = 'https://github.com/electron/electron/releases/download/v2.0.18/bad.file'; const snapshot = `[HTTPError: Response code 404 (Not Found) for ${url}]`; @@ -47,7 +47,7 @@ describe('GotDownloader', () => { setTimeout(() => emitter.emit('error', 'bad write error thing'), 10); return emitter as fs.WriteStream; }); - await withTempDirectory(async dir => { + await withTempDirectory(async (dir) => { const testFile = path.resolve(dir, 'test.txt'); await expect( downloader.download( @@ -60,7 +60,7 @@ describe('GotDownloader', () => { it('should download to a deep uncreated path', async () => { const downloader = new GotDownloader(); - await withTempDirectory(async dir => { + await withTempDirectory(async (dir) => { const testFile = path.resolve(dir, 'f', 'b', 'test.txt'); expect(await fs.pathExists(testFile)).toEqual(false); await expect( diff --git a/test/utils.spec.ts b/test/utils.spec.ts index 73dd02bb..00fa9194 100644 --- a/test/utils.spec.ts +++ b/test/utils.spec.ts @@ -37,7 +37,7 @@ describe('utils', () => { describe('withTempDirectory()', () => { it('should generate a new and empty directory', async () => { - await withTempDirectory(async dir => { + await withTempDirectory(async (dir) => { expect(await fs.pathExists(dir)).toEqual(true); expect(await fs.readdir(dir)).toEqual([]); }, TempDirCleanUpMode.CLEAN); @@ -48,7 +48,7 @@ describe('utils', () => { }); it('should delete the directory when the function terminates', async () => { - const mDir = await withTempDirectory(async dir => { + const mDir = await withTempDirectory(async (dir) => { return dir; }, TempDirCleanUpMode.CLEAN); expect(mDir).not.toBeUndefined(); @@ -58,7 +58,7 @@ describe('utils', () => { it('should delete the directory and reject correctly even if the function throws', async () => { let mDir: string | undefined; await expect( - withTempDirectory(async dir => { + withTempDirectory(async (dir) => { mDir = dir; throw 'my error'; }, TempDirCleanUpMode.CLEAN), @@ -69,7 +69,7 @@ describe('utils', () => { }); it('should not delete the directory if told to orphan the temp dir', async () => { - const mDir = await withTempDirectory(async dir => { + const mDir = await withTempDirectory(async (dir) => { return dir; }, TempDirCleanUpMode.ORPHAN); expect(mDir).not.toBeUndefined(); diff --git a/yarn.lock b/yarn.lock index 6f056f7b..9e8c7f1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3445,10 +3445,10 @@ prelude-ls@~1.1.2: resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ= -prettier@^1.17.1: - version "1.17.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.1.tgz#ed64b4e93e370cb8a25b9ef7fef3e4fd1c0995db" - integrity sha512-TzGRNvuUSmPgwivDqkZ9tM/qTGW9hqDKWOE9YHiyQdixlKbv7kvEqsmDPrcHJTKwthU774TQwZXVtaQ/mMsvjg== +prettier@^3.4.2: + version "3.4.2" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.4.2.tgz#a5ce1fb522a588bf2b78ca44c6e6fe5aa5a2b13f" + integrity sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ== pretty-format@^29.0.0, pretty-format@^29.3.1: version "29.3.1"