Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
fix download
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Feb 19, 2020
1 parent 97c8b52 commit 856ff91
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/fetch-engine/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePathIgnorePatterns: ['build/', 'dist/', 'generator/', 'runtime/', 'scripts/'],
}
8 changes: 6 additions & 2 deletions packages/fetch-engine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@
"author": "Tim Suchanek <suchanek@prisma.io>",
"devDependencies": {
"@types/fs-extra": "8.0.1",
"@types/jest": "^25.1.2",
"@types/node": "^12.12.25",
"@types/node-fetch": "^2.5.4",
"@types/progress": "^2.0.3",
"jest": "^25.1.0",
"ncc": "^0.3.6",
"ts-jest": "^25.2.1",
"typescript": "^3.7.5"
},
"dependencies": {
"@prisma/get-platform": "workspace:*",
"chalk": "^3.0.0",
"debug": "^4.1.1",
"execa": "3.4",
"execa": "~3.4.0",
"find-cache-dir": "^3.2.0",
"htmlparser2": "^4.0.0",
"http-proxy-agent": "^2.1.0",
Expand All @@ -32,7 +35,8 @@
},
"scripts": {
"build": "tsc -d",
"prepublishOnly": "pnpm run build"
"prepublishOnly": "pnpm run build",
"test": "jest"
},
"files": [
"dist"
Expand Down
25 changes: 25 additions & 0 deletions packages/fetch-engine/src/__tests__/download.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import fs from 'fs'
import path from 'path'
import { download, getBinaryName } from '../download'
import { getPlatform } from '@prisma/get-platform'

describe('download', () => {
test('basic download', async () => {
const platform = await getPlatform()
const targetPath = path.join(__dirname, getBinaryName('query-engine', platform))
if (fs.existsSync(targetPath)) {
try {
fs.unlinkSync(targetPath)
} catch (e) {
console.error(e)
}
}
await download({
binaries: {
'query-engine': __dirname,
},
})

expect(fs.existsSync(targetPath))
})
})
6 changes: 5 additions & 1 deletion packages/fetch-engine/src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export async function versionCommandWorks(enginePath: string): Promise<boolean>
}
}

function getBinaryName(binaryName: string, platform: string): string {
export function getBinaryName(binaryName: string, platform: string): string {
const extension = platform === 'windows' ? '.exe' : ''
return `${binaryName}-${platform}${extension}`
}
Expand All @@ -271,6 +271,10 @@ async function getCachedBinaryPath({

const cachedTargetPath = path.join(cacheDir, binaryName)

if (!fs.existsSync(cachedTargetPath)) {
return null
}

// All versions not called 'latest' are unique
// only latest needs more checks
if (version !== 'latest') {
Expand Down

0 comments on commit 856ff91

Please sign in to comment.