New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@prisma/fetch-engine

Package Overview
Dependencies
Maintainers
5
Versions
8100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prisma/fetch-engine - npm Package Compare versions

Comparing version 0.3.57 to 0.3.58

199

dist/__tests__/download.test.js

@@ -10,6 +10,32 @@ "use strict";

const get_platform_1 = require("@prisma/get-platform");
const cleanupCache_1 = require("../cleanupCache");
const del_1 = __importDefault(require("del"));
jest.setTimeout(20000);
describe('download', () => {
beforeAll(async () => {
// completely clean up the cache and keep nothing
await cleanupCache_1.cleanupCache(0);
await del_1.default(__dirname + '/**/*engine*');
});
test('basic download', async () => {
const platform = await get_platform_1.getPlatform();
const targetPath = path_1.default.join(__dirname, download_1.getBinaryName('query-engine', platform));
const queryEnginePath = path_1.default.join(__dirname, download_1.getBinaryName('query-engine', platform));
const introspectionEnginePath = path_1.default.join(__dirname, download_1.getBinaryName('introspection-engine', platform));
const migrationEnginePath = path_1.default.join(__dirname, download_1.getBinaryName('migration-engine', platform));
await download_1.download({
binaries: {
'query-engine': __dirname,
'introspection-engine': __dirname,
'migration-engine': __dirname,
},
version: 'a78fee833bcf4e202645e7cc7df5c3839f658e6a',
});
expect(await download_1.getVersion(queryEnginePath)).toMatchInlineSnapshot(`"prisma a78fee833bcf4e202645e7cc7df5c3839f658e6a"`);
expect(await download_1.getVersion(introspectionEnginePath)).toMatchInlineSnapshot(`"a78fee833bcf4e202645e7cc7df5c3839f658e6a"`);
expect(await download_1.getVersion(migrationEnginePath)).toMatchInlineSnapshot(`"a78fee833bcf4e202645e7cc7df5c3839f658e6a"`);
});
test('auto heal corrupt binary', async () => {
const platform = await get_platform_1.getPlatform();
const baseDir = path_1.default.join(__dirname, 'corruption');
const targetPath = path_1.default.join(baseDir, download_1.getBinaryName('query-engine', platform));
if (fs_1.default.existsSync(targetPath)) {

@@ -25,8 +51,177 @@ try {

binaries: {
'query-engine': baseDir,
},
version: 'd20d1e6b1525ae45e3cc39784ad16c97d463f61c',
});
fs_1.default.writeFileSync(targetPath, 'incorrect-binary');
// please heal it
await download_1.download({
binaries: {
'query-engine': baseDir,
},
version: 'd20d1e6b1525ae45e3cc39784ad16c97d463f61c',
});
expect(fs_1.default.existsSync(targetPath)).toBe(true);
expect(await download_1.checkVersionCommand(targetPath)).toBe(true);
});
test('handle non-existent binary target', async () => {
expect(download_1.download({
binaries: {
'query-engine': __dirname,
},
version: 'd20d1e6b1525ae45e3cc39784ad16c97d463f61c',
binaryTargets: ['darwin', 'marvin'],
})).rejects.toThrowErrorMatchingInlineSnapshot(`"Unknown binaryTargets marvin"`);
});
test('download all binaries & cache them', async () => {
const baseDir = path_1.default.join(__dirname, 'all');
await download_1.download({
binaries: {
'query-engine': baseDir,
'introspection-engine': baseDir,
'migration-engine': baseDir,
},
binaryTargets: [
'darwin',
'debian-openssl-1.0.x',
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'windows',
],
version: 'd20d1e6b1525ae45e3cc39784ad16c97d463f61c',
});
expect(fs_1.default.existsSync(targetPath));
const files = getFiles(baseDir);
expect(files).toMatchInlineSnapshot(`
Array [
Object {
"name": ".gitkeep",
"size": 0,
},
Object {
"name": "introspection-engine-darwin",
"size": 10818024,
},
Object {
"name": "introspection-engine-debian-openssl-1.0.x",
"size": 13686432,
},
Object {
"name": "introspection-engine-debian-openssl-1.1.x",
"size": 13672616,
},
Object {
"name": "introspection-engine-rhel-openssl-1.0.x",
"size": 13727413,
},
Object {
"name": "introspection-engine-rhel-openssl-1.1.x",
"size": 13714821,
},
Object {
"name": "introspection-engine-windows.exe",
"size": 22851591,
},
Object {
"name": "migration-engine-darwin",
"size": 14451544,
},
Object {
"name": "migration-engine-debian-openssl-1.0.x",
"size": 17538960,
},
Object {
"name": "migration-engine-debian-openssl-1.1.x",
"size": 17529464,
},
Object {
"name": "migration-engine-rhel-openssl-1.0.x",
"size": 17592124,
},
Object {
"name": "migration-engine-rhel-openssl-1.1.x",
"size": 17588083,
},
Object {
"name": "migration-engine-windows.exe",
"size": 27487354,
},
Object {
"name": "query-engine-darwin",
"size": 16302864,
},
Object {
"name": "query-engine-debian-openssl-1.0.x",
"size": 19595240,
},
Object {
"name": "query-engine-debian-openssl-1.1.x",
"size": 19576464,
},
Object {
"name": "query-engine-rhel-openssl-1.0.x",
"size": 19635768,
},
Object {
"name": "query-engine-rhel-openssl-1.1.x",
"size": 19622446,
},
Object {
"name": "query-engine-windows.exe",
"size": 29855371,
},
]
`);
await del_1.default(baseDir + '/*engine*');
const before = Date.now();
await download_1.download({
binaries: {
'query-engine': baseDir,
'introspection-engine': baseDir,
'migration-engine': baseDir,
},
binaryTargets: [
'darwin',
'debian-openssl-1.0.x',
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'windows',
],
version: 'd20d1e6b1525ae45e3cc39784ad16c97d463f61c',
});
const after = Date.now();
// cache should take less than 2s
// value on Mac: 1440
expect(after - before).toBeLessThan(2000);
const before2 = Date.now();
await download_1.download({
binaries: {
'query-engine': baseDir,
'introspection-engine': baseDir,
'migration-engine': baseDir,
},
binaryTargets: [
'darwin',
'debian-openssl-1.0.x',
'debian-openssl-1.1.x',
'rhel-openssl-1.0.x',
'rhel-openssl-1.1.x',
'windows',
],
version: 'd20d1e6b1525ae45e3cc39784ad16c97d463f61c',
});
const after2 = Date.now();
// if binaries are already there, it should take less than 100ms to check all of them
// value on Mac: 33ms
expect(after2 - before2).toBeLessThan(100);
});
});
function getFiles(dir) {
const files = fs_1.default.readdirSync(dir, 'utf8');
return files.map(name => {
const size = fs_1.default.statSync(path_1.default.join(dir, name)).size;
return { name, size };
});
}
//# sourceMappingURL=download.test.js.map

2

dist/cleanupCache.d.ts

@@ -1,1 +0,1 @@

export declare function cleanupCache(): Promise<void>;
export declare function cleanupCache(n?: number): Promise<void>;

@@ -17,3 +17,3 @@ "use strict";

const stat = util_2.promisify(fs_1.default.stat);
async function cleanupCache() {
async function cleanupCache(n = 5) {
try {

@@ -34,3 +34,3 @@ const rootCacheDir = await util_1.getRootCacheDir();

dirsWithMeta.sort((a, b) => (a.created < b.created ? 1 : -1));
const dirsToRemove = dirsWithMeta.slice(5);
const dirsToRemove = dirsWithMeta.slice(n);
await p_map_1.default(dirsToRemove, dir => del(dir.dir), { concurrency: 20 });

@@ -37,0 +37,0 @@ }

@@ -28,4 +28,5 @@ import { Platform } from '@prisma/get-platform';

export declare function download(options: DownloadOptions): Promise<BinaryPaths>;
export declare function versionCommandWorks(enginePath: string): Promise<boolean>;
export declare function getVersion(enginePath: string): Promise<string>;
export declare function checkVersionCommand(enginePath: string): Promise<boolean>;
export declare function getBinaryName(binaryName: string, platform: string): string;
export declare function getBinaryEnvVarPath(binaryName: string): string | null;

@@ -41,2 +41,8 @@ "use strict";

}
if (options.binaryTargets && Array.isArray(options.binaryTargets)) {
const unknownTargets = options.binaryTargets.filter(t => !get_platform_1.platforms.includes(t));
if (unknownTargets.length > 0) {
throw new Error(`Unknown binaryTargets ${unknownTargets.join(', ')}`);
}
}
// merge options

@@ -50,3 +56,3 @@ options = {

const binaryJobs = flatMap_1.flatMap(Object.entries(options.binaries), ([binaryName, targetFolder]) => options.binaryTargets.map(binaryTarget => {
const fileName = getBinaryName(binaryName, platform);
const fileName = getBinaryName(binaryName, binaryTarget);
return {

@@ -164,3 +170,3 @@ binaryName,

if (job.binaryTarget === nativePlatform) {
const works = await versionCommandWorks(job.targetFilePath);
const works = await checkVersionCommand(job.targetFilePath);
debug({ works });

@@ -171,7 +177,13 @@ return !works;

}
async function versionCommandWorks(enginePath) {
async function getVersion(enginePath) {
const result = await execa_1.default(enginePath, ['--version']);
debug(`Getting version of ${enginePath}. Result: `, result);
return result.stdout;
}
exports.getVersion = getVersion;
async function checkVersionCommand(enginePath) {
try {
const result = await execa_1.default(enginePath, ['--version']);
debug(`Getting version of ${enginePath}. Result: `, result);
return result.stdout.length > 0;
const version = await getVersion(enginePath);
debug(`Getting version of ${enginePath}. Result: `, version);
return version.length > 0;
}

@@ -183,3 +195,3 @@ catch (e) {

}
exports.versionCommandWorks = versionCommandWorks;
exports.checkVersionCommand = checkVersionCommand;
function getBinaryName(binaryName, platform) {

@@ -236,16 +248,6 @@ const extension = platform === 'windows' ? '.exe' : '';

try {
fs_1.default.accessSync(targetDir, fs_1.default.constants.W_OK);
await make_dir_1.default(targetDir);
}
catch (e) {
if (failSilent) {
return;
}
else {
throw e;
}
}
try {
fs_1.default.accessSync(targetDir, fs_1.default.constants.W_OK);
}
catch (e) {
if (options.failSilent || e.code !== 'EACCES') {

@@ -252,0 +254,0 @@ return;

{
"name": "@prisma/fetch-engine",
"version": "0.3.57",
"version": "0.3.58",
"main": "dist/index.js",

@@ -14,4 +14,6 @@ "types": "dist/index.d.ts",

"@types/progress": "^2.0.3",
"del": "^5.1.0",
"jest": "^25.1.0",
"ncc": "^0.3.6",
"prettier": "^1.19.1",
"ts-jest": "^25.2.1",

@@ -18,0 +20,0 @@ "typescript": "^3.7.5"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc