@prisma/fetch-engine
Advanced tools
Comparing version 0.0.10 to 0.0.11
@@ -0,1 +1,2 @@ | ||
export declare function downloadMigrationBinary(migrationBinary: string, version: string): Promise<void>; | ||
/** | ||
@@ -2,0 +3,0 @@ * TODO: Check if binary already exists and if checksum is the same! |
@@ -27,2 +27,60 @@ "use strict"; | ||
const readFile = util_1.promisify(fs_1.default.readFile); | ||
async function downloadMigrationBinary(migrationBinary, version) { | ||
try { | ||
fs_1.default.writeFileSync(migrationBinary, '#!/usr/bin/env node\n' + 'console.log("Please wait until the \'prisma\' installation completes!")\n'); | ||
} | ||
catch (err) { | ||
if (err.code === 'EACCES') { | ||
log_1.warn('Please try installing Prisma CLI again with the `--unsafe-perm` option.'); | ||
log_1.info('Example: `npm i -g --unsafe-perm prisma`'); | ||
process.exit(); | ||
} | ||
throw err; | ||
} | ||
death_1.default(() => { | ||
fs_1.default.writeFileSync(migrationBinary, '#!/usr/bin/env node\n' + | ||
'console.log("The \'prisma\' installation did not complete successfully.")\n' + | ||
'console.log("Please run \'npm i -g prisma\' to reinstall!")\n'); | ||
process.exit(); | ||
}); | ||
log_1.info('For the source code, check out: https://github.com/prisma/lift'); | ||
// Print an empty line | ||
const platform = await getPlatform(); | ||
const cacheDir = await getCacheDir(platform); | ||
const cachedMigrationEnginePath = path_1.default.join(cacheDir, 'migration-engine'); | ||
const cachedLastModifiedPath = path_1.default.join(cacheDir, 'lastModifiedMigrationEngine'); | ||
const [cachedMigrationEngineExists, localLastModified] = await Promise.all([ | ||
exists(cachedMigrationEnginePath), | ||
getLocalLastModified(cachedLastModifiedPath), | ||
]); | ||
if (cachedMigrationEngineExists && localLastModified) { | ||
const remoteLastModified = await getRemoteLastModified(getMigrationEngineDownloadUrl(platform)); | ||
// If there is no new binary and we have it localy, copy it over | ||
if (localLastModified >= remoteLastModified) { | ||
console.log(`Taking migration engine binary from local cache from ${localLastModified.toISOString()}`); | ||
await Promise.all([copy_1.copy(cachedMigrationEnginePath, migrationBinary)]); | ||
return; | ||
} | ||
} | ||
log_1.enableProgress('Downloading Prisma Binary ' + version); | ||
log_1.showProgress(0); | ||
const lastModified = await downloadFile(getMigrationEngineDownloadUrl(platform), migrationBinary, 100); | ||
log_1.showProgress(100); | ||
log_1.disableProgress(); | ||
chmod_1.default(migrationBinary); | ||
/** | ||
* Cache the result only on Mac for better dev experience | ||
*/ | ||
if (platform === 'darwin') { | ||
try { | ||
await copy_1.copy(migrationBinary, cachedMigrationEnginePath); | ||
await writeFile(cachedLastModifiedPath, lastModified); | ||
} | ||
catch (e) { | ||
// console.error(e) | ||
// let this fail silently - the CI system may have reached the file size limit | ||
} | ||
} | ||
} | ||
exports.downloadMigrationBinary = downloadMigrationBinary; | ||
/** | ||
@@ -85,3 +143,3 @@ * TODO: Check if binary already exists and if checksum is the same! | ||
await copy_1.copy(schemaInferrerBinPath, cachedSchemaInferrerPath); | ||
writeFile(cachedLastModifiedPath, lastModified); | ||
await writeFile(cachedLastModifiedPath, lastModified); | ||
} | ||
@@ -205,2 +263,5 @@ catch (e) { | ||
} | ||
function getMigrationEngineDownloadUrl(platform) { | ||
return `https://s3-eu-west-1.amazonaws.com/prisma-native/alpha/latest/${platform}/migration-engine`; | ||
} | ||
//# sourceMappingURL=download.js.map |
export declare function ensureBinaries(resultPath?: string): Promise<void>; | ||
export declare function ensureMigrationBinary(resultPath: string): Promise<void>; |
@@ -20,2 +20,8 @@ "use strict"; | ||
exports.ensureBinaries = ensureBinaries; | ||
async function ensureMigrationBinary(resultPath) { | ||
await make_dir_1.default(resultPath); | ||
const prisma = path_1.default.join(resultPath, 'migration-engine'); | ||
await download_1.downloadMigrationBinary(prisma, '0.0.1'); | ||
} | ||
exports.ensureMigrationBinary = ensureMigrationBinary; | ||
async function getRuntimeDir() { | ||
@@ -22,0 +28,0 @@ let runtimeDir = path_1.default.join(__dirname, '../runtime'); |
{ | ||
"name": "@prisma/fetch-engine", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29679
414