mysql-memory-server 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ Download with your package manager of choice. The package name is `mysql-memory-
17
17
  - ```mysql-memory-server``` can run MySQL versions 5.7.19 and newer (if the version is already installed on your system)
18
18
  - ```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)
19
19
 
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)
21
21
 
22
22
  ## Example Usage - Application Code
23
23
 
@@ -88,7 +88,7 @@ If on Windows, this is the name of the named pipe that MySQL is listening on. If
88
88
  - `xSocket: string`
89
89
  If on Windows, this is the name of the named pipe that the MySQL X Plugin is listening on. If not on Windows, this is the path that the MySQL X Plugin is listening on. If ```options.xEnabled``` is set to "OFF", this value will be an empty string.
90
90
  - `mysql: {version: string, versionIsInstalledOnSystem: boolean}`
91
- An object with three properties. ```version``` is the version of MySQL used to create the database. ```versionIsInstalledOnSystem``` will be true if the MySQL version used is already installed on the system and false if the version had to be downloaded from MySQL's CDN.
91
+ An object with two properties. ```version``` is the version of MySQL used to create the database. ```versionIsInstalledOnSystem``` will be true if the MySQL version used is already installed on the system and false if the version had to be downloaded from MySQL's CDN.
92
92
  - `stop: () => Promise<void>`
93
93
  The method to stop the database. The returned promise resolves when the database has successfully stopped.
94
94
 
@@ -102,11 +102,11 @@ Description: Version of MySQL to use for the database. Uses semver for getting t
102
102
 
103
103
  If left undefined:
104
104
  - 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.
106
106
 
107
107
  If defined:
108
108
  - 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.
110
110
 
111
111
  - `dbName: string`
112
112
 
package/dist/src/cli.js CHANGED
File without changes
@@ -8,8 +8,6 @@ export declare const LOG_LEVELS: {
8
8
  };
9
9
  declare const internalOptions: {
10
10
  deleteDBAfterStopped: string;
11
- databaseDirectoryPath: string;
12
- binaryDirectoryPath: string;
13
11
  cli: string;
14
12
  };
15
13
  export declare function getInternalEnvVariable(envVar: keyof typeof internalOptions): string;
@@ -2,8 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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;
4
4
  exports.getInternalEnvVariable = getInternalEnvVariable;
5
- const path_1 = require("path");
6
- const os_1 = require("os");
7
5
  const semver_1 = require("semver");
8
6
  exports.DEFAULT_OPTIONS = {
9
7
  version: undefined,
@@ -30,9 +28,6 @@ exports.LOG_LEVELS = {
30
28
  };
31
29
  const internalOptions = {
32
30
  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`,
36
31
  cli: 'false'
37
32
  };
38
33
  function getInternalEnvVariable(envVar) {
@@ -46,6 +46,7 @@ const crypto_1 = require("crypto");
46
46
  const child_process_1 = require("child_process");
47
47
  const FileLock_1 = require("./FileLock");
48
48
  const constants_1 = require("../constants");
49
+ const os_1 = __importDefault(require("os"));
49
50
  function handleTarExtraction(filepath, extractedPath) {
50
51
  return new Promise((resolve, reject) => {
51
52
  (0, child_process_1.execFile)(`tar`, ['-xf', filepath, '-C', extractedPath], (error, stdout, stderr) => {
@@ -253,7 +254,7 @@ function extractBinary(url, archiveLocation, extractedLocation, binaryInfo, logg
253
254
  function downloadBinary(binaryInfo, options, logger) {
254
255
  return new Promise(async (resolve, reject) => {
255
256
  const { url, version } = binaryInfo;
256
- const dirpath = (0, constants_1.getInternalEnvVariable)('binaryDirectoryPath');
257
+ const dirpath = `${os_1.default.tmpdir()}/mysqlmsn/binaries`;
257
258
  logger.log('Binary path:', dirpath);
258
259
  await fsPromises.mkdir(dirpath, { recursive: true });
259
260
  const lastDashIndex = url.lastIndexOf('-');
@@ -164,7 +164,7 @@ class Executor {
164
164
  }
165
165
  });
166
166
  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("-", '')}`);
168
168
  const datadir = (0, path_1.normalize)(`${this.databasePath}/data`);
169
169
  do {
170
170
  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_
199
199
  });
200
200
  });
201
201
  }, _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
+ }
203
207
  if (os.platform() === 'win32') {
204
208
  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;
207
212
  }
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;
210
216
  }
217
+ this.logger.error(message, '| Error toString:', message.toString());
218
+ return false;
211
219
  }
212
- else {
213
- killed = process.kill();
214
- }
215
- return killed;
220
+ return process.kill('SIGKILL');
216
221
  }, _Executor_returnBinaryPathToDelete = function _Executor_returnBinaryPathToDelete(binaryFilepath, options) {
217
222
  if (binaryFilepath.includes(os.tmpdir()) && !options.downloadBinaryOnce) {
218
223
  const splitPath = binaryFilepath.split(os.platform() === 'win32' ? '\\' : '/');
@@ -282,8 +287,10 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
282
287
  // This unwatch will prevent the watch from watching when the process has stopped.
283
288
  fs.unwatchFile(errorLogFile);
284
289
  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);
287
294
  }
288
295
  let errorLog;
289
296
  try {
@@ -314,7 +321,9 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
314
321
  }
315
322
  try {
316
323
  if ((0, constants_1.getInternalEnvVariable)('deleteDBAfterStopped') === 'true') {
324
+ this.logger.log('Deleting database path as deleteDBAfterStopped is true...');
317
325
  await fsPromises.rm(dbPath, { recursive: true, force: true, maxRetries: 50, retryDelay: 100 });
326
+ this.logger.log('Database deletion was successful.');
318
327
  }
319
328
  }
320
329
  catch (e) {
@@ -340,7 +349,13 @@ _Executor_instances = new WeakSet(), _Executor_executeFile = function _Executor_
340
349
  return reject(`Database exited early.\nError log: ${errorLog}\nError string: "${errorString}`);
341
350
  }
342
351
  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
+ }
344
359
  this.logger.error(errorMessage);
345
360
  return reject(errorMessage);
346
361
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql-memory-server",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "Spin up an ephemeral MySQL database from your JavaScript code",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",