Skip to content

Commit 0368f65

Browse files
Merge pull request #153 from Sebastian-Webster/151-add-option-for-mysql-binary-architecture
Add arch option (add support for Windows on ARM)
2 parents 2cec502 + 821c850 commit 0368f65

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ Description: A string with MySQL queries to run before the database starts to ac
218218

219219
The internal queries that are ran before the queries in ```initSQLString``` are renaming the user from ```root``` to the username specified in the ```username``` option if it's set, and creating a database with the name from the ```dbName``` option.
220220

221+
- `arch: "arm64" | "x64"`
222+
223+
Required: No
224+
225+
Default: process.arch
226+
227+
Description: The MySQL binary architecture to execute. MySQL does not offer server builds for Windows on ARM, so to get this package working on Windows on ARM, set the arch option to "x64" and Windows will emulate MySQL.
228+
221229
***
222230
### :warning: Internal Options :warning:
223231

src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const DEFAULT_OPTIONS_GENERATOR: () => InternalServerOptions = () => ({
2020
xPort: 0,
2121
downloadRetries: 10,
2222
initSQLString: '',
23+
arch: process.arch,
2324
_DO_NOT_USE_deleteDBAfterStopped: true,
2425
//mysqlmsn = MySQL Memory Server Node.js
2526
_DO_NOT_USE_dbPath: normalizePath(`${tmpdir()}/mysqlmsn/dbs/${randomUUID().replace(/-/g, '')}`),
@@ -38,6 +39,7 @@ export const LOG_LEVELS = {
3839

3940
export const INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath', '_DO_NOT_USE_beforeSignalCleanup', '_DO_NOT_USE_afterSignalCleanup'] as const;
4041

42+
const allowedArches = ['x64', 'arm64', undefined]
4143
export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
4244
version: {
4345
check: (opt: any) => opt === undefined || typeof opt === 'string' && validSemver(opt) !== null,
@@ -104,6 +106,11 @@ export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
104106
errorMessage: 'Option initSQLString must be either undefined or a string.',
105107
definedType: 'string'
106108
},
109+
arch: {
110+
check: (opt: any) => allowedArches.includes(opt),
111+
errorMessage: `Option arch must be either of the following: ${allowedArches.join(', ')}`,
112+
definedType: 'string'
113+
},
107114
_DO_NOT_USE_deleteDBAfterStopped: {
108115
check: (opt: any) => opt === undefined || typeof opt === 'boolean',
109116
errorMessage: 'Option _DO_NOT_USE_deleteDBAfterStopped must be either undefined or a boolean.',

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function createDB(opts?: ServerOptions) {
6060
let binaryInfo: BinaryInfo;
6161
let binaryFilepath: string;
6262
try {
63-
binaryInfo = getBinaryURL(MySQLVersions, options.version)
63+
binaryInfo = getBinaryURL(MySQLVersions, options.version, options)
6464
logger.log('Using MySQL binary version:', binaryInfo.version, 'from URL:', binaryInfo.url)
6565
} catch (e) {
6666
logger.error(e)

src/libraries/Version.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { MySQLVersion } from "../../types";
1+
import { InternalServerOptions, MySQLVersion } from "../../types";
22
import * as os from 'os'
33
import { satisfies, coerce } from "semver";
44

5-
export default function getBinaryURL(versions: MySQLVersion[], versionToGet: string = "x") {
5+
export default function getBinaryURL(versions: MySQLVersion[], versionToGet: string = "x", options: InternalServerOptions) {
66
let availableVersions = versions;
77

8-
availableVersions = availableVersions.filter(v => v.arch === process.arch)
8+
availableVersions = availableVersions.filter(v => v.arch === options.arch)
99

10-
if (availableVersions.length === 0) throw `No MySQL binary could be found for your CPU architecture: ${process.arch}`
10+
if (availableVersions.length === 0) throw `No MySQL binary could be found for your CPU architecture: ${options.arch}. ${process.platform === 'win32' && process.arch === 'arm64' ? 'This package has detected you are running Windows on ARM. MySQL does not support Windows on ARM. To get this package working, please try setting the "arch" option to "x64".' : ''}`
1111

1212
availableVersions = availableVersions.filter(v => v.os === process.platform)
1313

types/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export type ServerOptions = {
1515
port?: number | undefined,
1616
xPort?: number | undefined,
1717
downloadRetries?: number | undefined,
18-
initSQLString?: string | undefined
18+
initSQLString?: string | undefined,
19+
arch?: "arm64" | "x64" | undefined,
1920
_DO_NOT_USE_deleteDBAfterStopped?: boolean | undefined,
2021
_DO_NOT_USE_dbPath?: string | undefined,
2122
_DO_NOT_USE_binaryDirectoryPath?: string | undefined,
@@ -36,7 +37,8 @@ export type InternalServerOptions = {
3637
port: number,
3738
xPort: number,
3839
downloadRetries: number,
39-
initSQLString: string
40+
initSQLString: string,
41+
arch: string,
4042
_DO_NOT_USE_deleteDBAfterStopped: boolean,
4143
_DO_NOT_USE_dbPath: string,
4244
_DO_NOT_USE_binaryDirectoryPath: string,

0 commit comments

Comments
 (0)