mysql-memory-server 1.4.0 → 1.4.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/dist/src/index.js CHANGED
@@ -31,16 +31,12 @@ const Logger_1 = __importDefault(require("./libraries/Logger"));
31
31
  const os = __importStar(require("node:os"));
32
32
  const Executor_1 = __importDefault(require("./libraries/Executor"));
33
33
  const semver_1 = require("semver");
34
- const AbortSignal_1 = __importDefault(require("./libraries/AbortSignal"));
35
34
  const Version_1 = __importDefault(require("./libraries/Version"));
36
35
  const versions_json_1 = __importDefault(require("./versions.json"));
37
36
  const Downloader_1 = require("./libraries/Downloader");
38
37
  const crypto_1 = require("crypto");
39
38
  const path_1 = require("path");
40
39
  const constants_1 = __importDefault(require("./constants"));
41
- process.on('exit', () => {
42
- AbortSignal_1.default.abort('Process is exiting');
43
- });
44
40
  async function createDB(opts) {
45
41
  const defaultOptions = {
46
42
  dbName: 'dbdata',
@@ -1,4 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const DBDestroySignal = new AbortController();
4
+ function abortSignal() {
5
+ if (!DBDestroySignal.signal.aborted) {
6
+ DBDestroySignal.abort('Process is exiting');
7
+ }
8
+ }
9
+ process.on('beforeExit', abortSignal);
10
+ process.on('exit', abortSignal);
4
11
  exports.default = DBDestroySignal;
@@ -107,7 +107,7 @@ function downloadFromCDN(url, downloadLocation, logger) {
107
107
  });
108
108
  });
109
109
  }
110
- function extractBinary(url, archiveLocation, extractedLocation) {
110
+ function extractBinary(url, archiveLocation, extractedLocation, logger) {
111
111
  return new Promise(async (resolve, reject) => {
112
112
  const lastDashIndex = url.lastIndexOf('-');
113
113
  const fileExtension = url.slice(lastDashIndex).split('.').splice(1).join('.');
@@ -140,8 +140,11 @@ function extractBinary(url, archiveLocation, extractedLocation) {
140
140
  try {
141
141
  await fsPromises.rm(archiveLocation);
142
142
  }
143
+ catch (e) {
144
+ logger.error('A non-fatal error occurred while removing no longer needed archive file:', e);
145
+ }
143
146
  finally {
144
- fsPromises.rename(`${extractedLocation}/${folderName}`, `${extractedLocation}/mysql`);
147
+ await fsPromises.rename(`${extractedLocation}/${folderName}`, `${extractedLocation}/mysql`);
145
148
  return resolve((0, path_1.normalize)(`${extractedLocation}/mysql/bin/mysqld.exe`));
146
149
  }
147
150
  }
@@ -149,8 +152,11 @@ function extractBinary(url, archiveLocation, extractedLocation) {
149
152
  try {
150
153
  await fsPromises.rm(archiveLocation);
151
154
  }
155
+ catch (e) {
156
+ logger.error('A non-fatal error occurred while removing no longer needed archive file:', e);
157
+ }
152
158
  finally {
153
- fsPromises.rename(`${extractedLocation}/${folderName}`, `${extractedLocation}/mysql`);
159
+ await fsPromises.rename(`${extractedLocation}/${folderName}`, `${extractedLocation}/mysql`);
154
160
  resolve(`${extractedLocation}/mysql/bin/mysqld`);
155
161
  }
156
162
  }).catch(error => {
@@ -180,7 +186,7 @@ function downloadBinary(binaryInfo, options, logger) {
180
186
  (0, proper_lockfile_1.lockSync)(extractedPath);
181
187
  lockedByUs = true;
182
188
  await downloadFromCDN(url, archivePath, logger);
183
- await extractBinary(url, archivePath, extractedPath);
189
+ await extractBinary(url, archivePath, extractedPath, logger);
184
190
  try {
185
191
  (0, proper_lockfile_1.unlockSync)(extractedPath);
186
192
  }
@@ -226,7 +232,7 @@ function downloadBinary(binaryInfo, options, logger) {
226
232
  reject(e);
227
233
  }
228
234
  try {
229
- const binaryPath = await extractBinary(url, zipFilepath, extractedPath);
235
+ const binaryPath = await extractBinary(url, zipFilepath, extractedPath, logger);
230
236
  resolve(binaryPath);
231
237
  }
232
238
  catch (e) {
@@ -226,6 +226,9 @@ _Executor_instances = new WeakSet(), _Executor_execute = function _Executor_exec
226
226
  await this.deleteDatabaseDirectory(dbPath);
227
227
  }
228
228
  }
229
+ catch (e) {
230
+ this.logger.error('An erorr occurred while deleting database directory at path:', dbPath, '| The error was:', e);
231
+ }
229
232
  finally {
230
233
  try {
231
234
  if (binaryFilepath.includes(os.tmpdir()) && !options.downloadBinaryOnce) {
@@ -237,6 +240,9 @@ _Executor_instances = new WeakSet(), _Executor_execute = function _Executor_exec
237
240
  await fsPromises.rm(splitPath.join('/'), { force: true, recursive: true });
238
241
  }
239
242
  }
243
+ catch (e) {
244
+ this.logger.error('An error occurred while deleting no longer needed MySQL binary:', e);
245
+ }
240
246
  finally {
241
247
  if (resolveFunction) {
242
248
  resolveFunction();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mysql-memory-server",
3
- "version": "1.4.0",
3
+ "version": "1.4.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",
@@ -24,10 +24,10 @@
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
26
  "@babel/core": "^7.24.9",
27
- "@babel/preset-env": "^7.24.8",
27
+ "@babel/preset-env": "^7.25.4",
28
28
  "@babel/preset-typescript": "^7.24.7",
29
29
  "@types/adm-zip": "^0.5.5",
30
- "@types/node": "^22.2.0",
30
+ "@types/node": "^22.5.0",
31
31
  "@types/proper-lockfile": "^4.1.4",
32
32
  "@types/semver": "^7.5.8",
33
33
  "babel-jest": "^29.7.0",