Skip to content

Commit 6f0976f

Browse files
build - v1.12.1
1 parent 9606499 commit 6f0976f

File tree

9 files changed

+37
-27
lines changed

9 files changed

+37
-27
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Download with your package manager of choice. The package name is `mysql-memory-
1717
- ```mysql-memory-server``` can run MySQL versions 5.7.19 and newer (if the version is already installed on your system)
1818
- ```mysql-memory-server``` can download and run MySQL versions (inclusive) 5.7.19 - 5.7.44, 8.0.0 - 8.0.43, 8.1.0 - 8.4.6, and 9.0.1 - 9.4.0 (if the version is not already installed on your system)
1919

20-
Extra system requirements apply when ```mysql-memory-server``` is downloading MySQL instead of running a version of MySQL that is already installed on the system. To see the requirements and learn more about the supported versions for download, [read the doc](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.0/docs/SUPPORTED_MYSQL_DOWNLOADS.md)
20+
Extra system requirements apply when ```mysql-memory-server``` is downloading MySQL instead of running a version of MySQL that is already installed on the system. To see the requirements and learn more about the supported versions for download, [read the doc](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.1/docs/SUPPORTED_MYSQL_DOWNLOADS.md)
2121

2222
## Example Usage - Application Code
2323

@@ -102,11 +102,11 @@ Description: Version of MySQL to use for the database. Uses semver for getting t
102102

103103
If left undefined:
104104
- If the system has MySQL installed, the system-installed version will be used. If the installed version is not supported by this package (currently <5.7.19), an error will be thrown unless `ignoreUnsupportedSystemVersion` is set to `true`.
105-
- If the system does not have MySQL installed, the latest version of MySQL that [this package supports downloading](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.0/docs/SUPPORTED_MYSQL_DOWNLOADS.md) will be downloaded.
105+
- If the system does not have MySQL installed, the latest version of MySQL that [this package supports downloading](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.1/docs/SUPPORTED_MYSQL_DOWNLOADS.md) will be downloaded.
106106

107107
If defined:
108108
- If the version is older than 5.7.19, an error will be thrown as this package does not currently support those versions of MySQL.
109-
- If the desired version of MySQL is already installed on the system, the installed version will be used. Otherwise the selected version will be downloaded as long as this package [supports downloading it](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.0/docs/SUPPORTED_MYSQL_DOWNLOADS.md). If this package does not support downloading the selected version, or your system does not [meet the requirements](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.0/docs/SUPPORTED_MYSQL_DOWNLOADS.md) for that version to be ran, an error will be thrown.
109+
- If the desired version of MySQL is already installed on the system, the installed version will be used. Otherwise the selected version will be downloaded as long as this package [supports downloading it](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.1/docs/SUPPORTED_MYSQL_DOWNLOADS.md). If this package does not support downloading the selected version, or your system does not [meet the requirements](https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.1/docs/SUPPORTED_MYSQL_DOWNLOADS.md) for that version to be ran, an error will be thrown.
110110

111111
- `dbName: string`
112112

dist/src/cli.js

100755100644
File mode changed.

dist/src/constants.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export declare const LOG_LEVELS: {
88
};
99
declare const internalOptions: {
1010
deleteDBAfterStopped: string;
11-
binaryDirectoryPath: string;
1211
cli: string;
1312
};
1413
export declare function getInternalEnvVariable(envVar: keyof typeof internalOptions): string;

dist/src/constants.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.MYSQL_LINUX_MINIMAL_REBUILD_VERSIONS = exports.MYSQL_LINUX_FILE_EXTENSIONS = exports.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE_ARM64 = exports.MYSQL_LINUX_MINIMAL_INSTALL_AVAILABLE = exports.MYSQL_LINUX_GLIBC_VERSIONS = exports.MYSQL_MACOS_VERSIONS_IN_FILENAME = exports.RC_MYSQL_VERSIONS = exports.DMR_MYSQL_VERSIONS = exports.MYSQL_MIN_OS_SUPPORT = exports.MYSQL_ARCH_SUPPORT = exports.DOWNLOADABLE_MYSQL_VERSIONS = exports.MySQLCDNArchivesBaseURL = exports.MySQLCDNDownloadsBaseURL = exports.MIN_SUPPORTED_MYSQL = exports.OPTION_TYPE_CHECKS = exports.LOG_LEVELS = exports.DEFAULT_OPTIONS_KEYS = exports.DEFAULT_OPTIONS = void 0;
44
exports.getInternalEnvVariable = getInternalEnvVariable;
5-
const path_1 = require("path");
6-
const os_1 = require("os");
75
const semver_1 = require("semver");
86
exports.DEFAULT_OPTIONS = {
97
version: undefined,
@@ -30,9 +28,6 @@ exports.LOG_LEVELS = {
3028
};
3129
const internalOptions = {
3230
deleteDBAfterStopped: 'true',
33-
//mysqlmsn = MySQL Memory Server Node.js
34-
databaseDirectoryPath: (0, path_1.normalize)(`${(0, os_1.tmpdir)()}/mysqlmsn/dbs`),
35-
binaryDirectoryPath: `${(0, os_1.tmpdir)()}/mysqlmsn/binaries`,
3631
cli: 'false'
3732
};
3833
function getInternalEnvVariable(envVar) {

dist/src/libraries/Downloader.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const crypto_1 = require("crypto");
4646
const child_process_1 = require("child_process");
4747
const FileLock_1 = require("./FileLock");
4848
const constants_1 = require("../constants");
49+
const os_1 = __importDefault(require("os"));
4950
function handleTarExtraction(filepath, extractedPath) {
5051
return new Promise((resolve, reject) => {
5152
(0, child_process_1.execFile)(`tar`, ['-xf', filepath, '-C', extractedPath], (error, stdout, stderr) => {
@@ -253,7 +254,7 @@ function extractBinary(url, archiveLocation, extractedLocation, binaryInfo, logg
253254
function downloadBinary(binaryInfo, options, logger) {
254255
return new Promise(async (resolve, reject) => {
255256
const { url, version } = binaryInfo;
256-
const dirpath = (0, constants_1.getInternalEnvVariable)('binaryDirectoryPath');
257+
const dirpath = `${os_1.default.tmpdir()}/mysqlmsn/binaries`;
257258
logger.log('Binary path:', dirpath);
258259
await fsPromises.mkdir(dirpath, { recursive: true });
259260
const lastDashIndex = url.lastIndexOf('-');

dist/src/libraries/Executor.js

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class Executor {
164164
}
165165
});
166166
let retries = 0;
167-
this.databasePath = (0, path_1.normalize)(`${(0, constants_1.getInternalEnvVariable)('databaseDirectoryPath')}/${(0, crypto_1.randomUUID)().replaceAll("-", '')}`);
167+
this.databasePath = (0, path_1.normalize)(`${os.tmpdir()}/mysqlmsn/dbs/${(0, crypto_1.randomUUID)().replaceAll("-", '')}`);
168168
const datadir = (0, path_1.normalize)(`${this.databasePath}/data`);
169169
do {
170170
await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_setupDataDirectories).call(this, options, installedMySQLBinary, datadir, true);
@@ -199,20 +199,25 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
199199
});
200200
});
201201
}, _Executor_killProcess = async function _Executor_killProcess(process) {
202-
let killed = false;
202+
// If the process has already been killed, return true
203+
if (process.kill(0) === false) {
204+
this.logger.warn('Called #killProcess to kill mysqld but it has already been killed.');
205+
return true;
206+
}
203207
if (os.platform() === 'win32') {
204208
const { error, stderr } = await __classPrivateFieldGet(this, _Executor_instances, "m", _Executor_executeFile).call(this, 'taskkill', ['/pid', String(process.pid), '/t', '/f']);
205-
if (!error && !stderr) {
206-
killed = true;
209+
const message = error || stderr;
210+
if (!message) {
211+
return true;
207212
}
208-
else {
209-
this.logger.error(error || stderr);
213+
if (message.toString().includes('There is no running instance of the task')) {
214+
this.logger.warn('Called #killProcess and tried to kill mysqld process but taskkill could not because it is not running. Error received:', message);
215+
return true;
210216
}
217+
this.logger.error(message, '| Error toString:', message.toString());
218+
return false;
211219
}
212-
else {
213-
killed = process.kill();
214-
}
215-
return killed;
220+
return process.kill('SIGKILL');
216221
}, _Executor_returnBinaryPathToDelete = function _Executor_returnBinaryPathToDelete(binaryFilepath, options) {
217222
if (binaryFilepath.includes(os.tmpdir()) && !options.downloadBinaryOnce) {
218223
const splitPath = binaryFilepath.split(os.platform() === 'win32' ? '\\' : '/');
@@ -282,8 +287,10 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
282287
// This unwatch will prevent the watch from watching when the process has stopped.
283288
fs.unwatchFile(errorLogFile);
284289
if (signal) {
285-
this.logger.log('Exiting because of aborted signal.');
286-
return;
290+
this.logger.log('Exiting because the process received a signal:', signal);
291+
}
292+
else {
293+
this.logger.log('Exiting with code:', code);
287294
}
288295
let errorLog;
289296
try {
@@ -314,7 +321,9 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
314321
}
315322
try {
316323
if ((0, constants_1.getInternalEnvVariable)('deleteDBAfterStopped') === 'true') {
324+
this.logger.log('Deleting database path as deleteDBAfterStopped is true...');
317325
await fsPromises.rm(dbPath, { recursive: true, force: true, maxRetries: 50, retryDelay: 100 });
326+
this.logger.log('Database deletion was successful.');
318327
}
319328
}
320329
catch (e) {
@@ -340,7 +349,13 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
340349
return reject(`Database exited early.\nError log: ${errorLog}\nError string: "${errorString}`);
341350
}
342351
if (code) {
343-
const errorMessage = `The database exited early with code ${code}. The error log was:\n${errorLog}\nThe error string was: "${errorString}".`;
352+
let errorMessage = '';
353+
if (os.platform() === 'win32' && code === 3221225781) {
354+
errorMessage = `The MySQL database exited early with code 3221225781. A possible cause is that the Microsoft Visual C++ Redistributable Package is not installed. Please refer to the following link for this package's requirements on your system - this may help solve this error: https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.1/docs/SUPPORTED_MYSQL_DOWNLOADS.md#required-dependencies. If you are sure you have this installed, check the following for more details: The error log was:\n${errorLog}\nThe error string was: "${errorString}".`;
355+
}
356+
else {
357+
errorMessage = `The database exited early with code ${code}. The error log was:\n${errorLog}\nThe error string was: "${errorString}".`;
358+
}
344359
this.logger.error(errorMessage);
345360
return reject(errorMessage);
346361
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mysql-memory-server",
3-
"version": "1.12.0",
3+
"version": "1.12.1",
44
"description": "Spin up an ephemeral MySQL database from your JavaScript code",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",

src/libraries/Executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class Executor {
212212
let errorMessage: string = ''
213213

214214
if (os.platform() === 'win32' && code === 3221225781) {
215-
errorMessage = `The MySQL database exited early with code 3221225781. A possible cause is that the Microsoft Visual C++ Redistributable Package is not installed. Please refer to the following link for this package's requirements on your system - this may help solve this error: https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.0/docs/SUPPORTED_MYSQL_DOWNLOADS.md#required-dependencies. If you are sure you have this installed, check the following for more details: The error log was:\n${errorLog}\nThe error string was: "${errorString}".`
215+
errorMessage = `The MySQL database exited early with code 3221225781. A possible cause is that the Microsoft Visual C++ Redistributable Package is not installed. Please refer to the following link for this package's requirements on your system - this may help solve this error: https://github.com/Sebastian-Webster/mysql-memory-server-nodejs/blob/v1.12.1/docs/SUPPORTED_MYSQL_DOWNLOADS.md#required-dependencies. If you are sure you have this installed, check the following for more details: The error log was:\n${errorLog}\nThe error string was: "${errorString}".`
216216
} else {
217217
errorMessage = `The database exited early with code ${code}. The error log was:\n${errorLog}\nThe error string was: "${errorString}".`
218218
}

0 commit comments

Comments
 (0)