Skip to content

Commit 16ccba6

Browse files
build - 1.2.0
1 parent 203f21b commit 16ccba6

File tree

9 files changed

+196
-106
lines changed

9 files changed

+196
-106
lines changed

dist/src/index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,24 @@ const AbortSignal_1 = __importDefault(require("./libraries/AbortSignal"));
3535
const Version_1 = __importDefault(require("./libraries/Version"));
3636
const versions_json_1 = __importDefault(require("./versions.json"));
3737
const Downloader_1 = require("./libraries/Downloader");
38-
const defaultOptions = {
39-
dbName: 'dbdata',
40-
logLevel: 'ERROR',
41-
portRetries: 10,
42-
downloadBinaryOnce: true,
43-
lockRetries: 1000,
44-
lockRetryWait: 1000,
45-
username: 'root'
46-
};
38+
const crypto_1 = require("crypto");
39+
const path_1 = require("path");
4740
process.on('exit', () => {
4841
AbortSignal_1.default.abort('Process is exiting');
4942
});
50-
async function createDB(opts = defaultOptions) {
43+
async function createDB(opts) {
44+
const defaultOptions = {
45+
dbName: 'dbdata',
46+
logLevel: 'ERROR',
47+
portRetries: 10,
48+
downloadBinaryOnce: true,
49+
lockRetries: 1000,
50+
lockRetryWait: 1000,
51+
username: 'root',
52+
deleteDBAfterStopped: true,
53+
//mysqlmsn = MySQL Memory Server Node.js
54+
dbPath: (0, path_1.normalize)(`${os.tmpdir()}/mysqlmsn/dbs/${(0, crypto_1.randomUUID)().replace(/-/g, '')}`)
55+
};
5156
const options = { ...defaultOptions, ...opts };
5257
const logger = new Logger_1.default(options.logLevel);
5358
const executor = new Executor_1.default(logger);
@@ -63,16 +68,16 @@ async function createDB(opts = defaultOptions) {
6368
catch (e) {
6469
logger.error(e);
6570
if (options.version) {
66-
throw `A MySQL version ${options.version} binary could not be found that supports your OS (${os.platform()} | ${os.version()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support the version you want to use, feel free to make a pull request to add support!`;
71+
throw `A MySQL version ${options.version} binary could not be found that supports your OS (${os.platform()} | ${os.version()} | ${os.release()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support the version you want to use, feel free to make a pull request to add support!`;
6772
}
68-
throw `A MySQL binary could not be found that supports your OS (${os.platform()} | ${os.version()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support your OS and CPU architecture, feel free to make a pull request to add support!`;
73+
throw `A MySQL binary could not be found that supports your OS (${os.platform()} | ${os.version()} | ${os.release()}) and CPU architecture (${os.arch()}). Please check you have the latest version of mysql-memory-server. If the latest version still doesn't support your OS and CPU architecture, feel free to make a pull request to add support!`;
6974
}
7075
try {
7176
binaryFilepath = await (0, Downloader_1.downloadBinary)(binaryInfo, options, logger);
7277
}
7378
catch (error) {
7479
logger.error('Failed to download binary');
75-
throw error;
80+
throw `Failed to download binary. The error was: "${error}"`;
7681
}
7782
logger.log('Running downloaded binary');
7883
return await executor.startMySQL(options, binaryFilepath);

dist/src/libraries/Downloader.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import Logger from './Logger';
2-
import { BinaryInfo, ServerOptions } from '../../types';
2+
import { BinaryInfo, InternalServerOptions } from '../../types';
33
export declare function downloadVersions(): Promise<string>;
4-
export declare function downloadBinary(binaryInfo: BinaryInfo, options: ServerOptions, logger: Logger): Promise<string>;
4+
export declare function downloadBinary(binaryInfo: BinaryInfo, options: InternalServerOptions, logger: Logger): Promise<string>;

dist/src/libraries/Downloader.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,26 +77,31 @@ function downloadVersions() {
7777
function downloadFromCDN(url, downloadLocation, logger) {
7878
return new Promise((resolve, reject) => {
7979
const fileStream = fs.createWriteStream(downloadLocation);
80+
let error;
8081
fileStream.on('open', () => {
8182
const request = https.get(url, (response) => {
8283
response.pipe(fileStream);
8384
});
8485
request.on('error', (err) => {
86+
error = err;
8587
logger.error(err);
8688
fileStream.close();
87-
fs.unlink(downloadLocation, (err) => {
88-
reject(err);
89+
fs.unlink(downloadLocation, () => {
90+
reject(err.message);
8991
});
9092
});
9193
});
9294
fileStream.on('finish', () => {
93-
resolve();
95+
if (!error) {
96+
resolve();
97+
}
9498
});
9599
fileStream.on('error', (err) => {
100+
error = err;
96101
logger.error(err);
97102
fileStream.end();
98103
fs.unlink(downloadLocation, () => {
99-
reject(err);
104+
reject(err.message);
100105
});
101106
});
102107
});
@@ -106,7 +111,11 @@ function extractBinary(url, archiveLocation, extractedLocation) {
106111
const lastDashIndex = url.lastIndexOf('-');
107112
const fileExtension = url.slice(lastDashIndex).split('.').splice(1).join('.');
108113
await fsPromises.mkdir(extractedLocation, { recursive: true });
109-
const folderName = url.split('/').at(-1).replace(`.${fileExtension}`, '');
114+
const mySQLFolderName = url.split('/').at(-1);
115+
if (!mySQLFolderName) {
116+
return reject(`Folder name is undefined for url: ${url}`);
117+
}
118+
const folderName = mySQLFolderName.replace(`.${fileExtension}`, '');
110119
if (fileExtension === 'zip') {
111120
//Only Windows MySQL files use the .zip extension
112121
const zip = new adm_zip_1.default(archiveLocation);

dist/src/libraries/Executor.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ declare class Executor {
44
#private;
55
logger: Logger;
66
constructor(logger: Logger);
7+
deleteDatabaseDirectory(path: string): Promise<void>;
78
getMySQLVersion(preferredVersion?: string): Promise<InstalledMySQLVersion | null>;
89
startMySQL(options: InternalServerOptions, binaryFilepath: string): Promise<MySQLDB>;
910
}

0 commit comments

Comments
 (0)