Skip to content

Commit 92a9381

Browse files
hasezoeynodkz
andcommitted
feat: add support for Linux Mint (tnx @hasezoey)
* use promisify, remove wrapper function * Add support for Linux Mint >= 17 - set "getos" version to git from hasezoey/getos with branch "symlink" * Update getos? * Remove commented out code * remove "async" again * More cleanup add "unkown" to getLinuxOSVersionString matching add "a = b" (whitespace) support for -release files add function "isLinuxOS" add structure comment to "getLinuxInfomation" add extra case for archlinux add tsdoc to some functions * Upgrade typescript & ts-jest versions apply npm run lint -- --fix more cleanup * chore: update dependencies * chore: update eslint configs * remove "debug: true" * replace all "/data" with "tmpDir.name" move "tmp.setGracefulCleanup();" call outside, like other tests * add "tmp.setGracefulCleanup();" to "resolve-config-test" * adding cleanup script to clean form all old code & old version of mongodb * fix lint Co-authored-by: Pablo Damnhorns <[email protected]>
1 parent 73d0925 commit 92a9381

File tree

13 files changed

+719
-431
lines changed

13 files changed

+719
-431
lines changed

.eslintrc

Lines changed: 0 additions & 47 deletions
This file was deleted.

.eslintrc.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const path = require('path');
2+
3+
module.exports = {
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint', 'prettier'],
6+
extends: [
7+
'plugin:@typescript-eslint/recommended',
8+
'prettier/@typescript-eslint',
9+
'plugin:prettier/recommended',
10+
],
11+
parserOptions: {
12+
sourceType: 'module',
13+
useJSXTextNode: true,
14+
project: [
15+
path.resolve(__dirname, 'tsconfig.test.json'),
16+
path.resolve(__dirname, 'packages/mongodb-memory-server-core/tsconfig.json'),
17+
],
18+
},
19+
rules: {
20+
'no-underscore-dangle': 0,
21+
'arrow-body-style': 0,
22+
'no-unused-expressions': 0,
23+
'no-plusplus': 0,
24+
'no-console': 0,
25+
'func-names': 0,
26+
'comma-dangle': [
27+
'error',
28+
{
29+
arrays: 'always-multiline',
30+
objects: 'always-multiline',
31+
imports: 'always-multiline',
32+
exports: 'always-multiline',
33+
functions: 'ignore',
34+
},
35+
],
36+
'no-prototype-builtins': 0,
37+
'prefer-destructuring': 0,
38+
'no-else-return': 0,
39+
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
40+
'@typescript-eslint/explicit-member-accessibility': 0,
41+
'@typescript-eslint/no-explicit-any': 0,
42+
'@typescript-eslint/no-inferrable-types': 0,
43+
'@typescript-eslint/explicit-function-return-type': 0,
44+
'@typescript-eslint/no-use-before-define': 0,
45+
'@typescript-eslint/no-empty-function': 0,
46+
},
47+
env: {
48+
jasmine: true,
49+
jest: true,
50+
},
51+
globals: {
52+
Class: true,
53+
Iterator: true,
54+
},
55+
};

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"javascriptreact",
77
{ "language": "typescript", "autoFix": true },
88
{ "language": "typescriptreact", "autoFix": true }
9-
]
9+
],
10+
"typescript.tsdk": "node_modules/typescript/lib"
1011
}

package.json

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
"description": "In-memory MongoDB Server. Designed with testing in mind, the server will allow you to connect your favourite ODM or client library to the MongoDB Server and run integration tests isolated from each other.",
66
"repository": "https://github.com/nodkz/mongodb-memory-server",
77
"devDependencies": {
8-
"@types/jest": "^24.0.19",
9-
"@types/mongodb": "^3.3.6",
10-
"@types/node": "^12.11.2",
11-
"@typescript-eslint/eslint-plugin": "^2.5.0",
12-
"@typescript-eslint/parser": "^2.5.0",
8+
"@types/jest": "24.0.24",
9+
"@types/mongodb": "3.3.13",
10+
"@types/node": "12.12.21",
11+
"@typescript-eslint/eslint-plugin": "2.12.0",
12+
"@typescript-eslint/parser": "2.12.0",
1313
"cross-env": "^6.0.3",
14-
"eslint": "^6.5.1",
15-
"eslint-config-prettier": "^6.4.0",
16-
"eslint-plugin-prettier": "^3.1.1",
14+
"eslint": "6.7.2",
15+
"eslint-config-prettier": "6.7.0",
16+
"eslint-plugin-prettier": "3.1.2",
1717
"flowgen": "^1.10.0",
1818
"jest": "^24.9.0",
19-
"lerna": "^3.18.2",
20-
"mongodb": "^3.2.7",
19+
"lerna": "3.19.0",
20+
"mongodb": "3.4.0",
2121
"npm-run-all": "^4.1.5",
22-
"prettier": "^1.18.2",
23-
"ts-jest": "^24.1.0",
24-
"typescript": "^3.6.4"
22+
"prettier": "1.19.1",
23+
"ts-jest": "^24.2.0",
24+
"typescript": "^3.7.3"
2525
},
2626
"workspaces": {
2727
"packages": [
@@ -31,7 +31,8 @@
3131
"scripts": {
3232
"test": "lerna run test --stream",
3333
"lint": "lerna run lint --stream",
34-
"watch": "jest --watch",
34+
"watch": "jest --env node --watch",
35+
"jest": "jest --env node",
3536
"build": "tsc --build tsconfig.build.json",
3637
"release": "yarn build && lerna publish",
3738
"postinstall": "yarn build"

packages/mongodb-memory-server-core/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@
3434
"@types/find-cache-dir": "^2.0.0",
3535
"@types/find-package-json": "^1.1.0",
3636
"@types/get-port": "^4.0.1",
37-
"@types/getos": "^3.0.0",
3837
"@types/lockfile": "^1.0.1",
3938
"@types/md5-file": "^4.0.0",
4039
"@types/mkdirp": "^0.5.2",
4140
"@types/tmp": "0.1.0",
42-
"@types/uuid": "^3.4.5",
41+
"@types/uuid": "3.4.6",
4342
"rimraf": "^3.0.0"
4443
},
4544
"dependencies": {
@@ -48,11 +47,10 @@
4847
"debug": "^4.1.1",
4948
"decompress": "^4.2.0",
5049
"dedent": "^0.7.0",
51-
"find-cache-dir": "^3.0.0",
50+
"find-cache-dir": "3.2.0",
5251
"find-package-json": "^1.2.0",
53-
"get-port": "^5.0.0",
54-
"getos": "^3.1.1",
55-
"https-proxy-agent": "^3.0.0",
52+
"get-port": "5.0.0",
53+
"https-proxy-agent": "4.0.0",
5654
"lockfile": "^1.0.4",
5755
"md5-file": "^4.0.0",
5856
"mkdirp": "^0.5.1",
@@ -63,6 +61,7 @@
6361
"mongodb": "^3.2.7"
6462
},
6563
"scripts": {
64+
"cleanup": "rimraf tmp lib coverage node_modules/.cache",
6665
"build": "npm-run-all build:*",
6766
"build:ts": "rimraf ./lib && tsc -p ./tsconfig.json",
6867
"disabled-build:flow": "find ./lib -name \"*.d.ts\" -exec bash -c './node_modules/.bin/flowgen --add-flow-header \"$1\" -o \"${1%.d.ts}\".js.flow' - '{}' \\;",

packages/mongodb-memory-server-core/src/util/MongoBinaryDownloadUrl.ts

Lines changed: 51 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import getos from 'getos';
1+
import getOS, { AnyOS, LinuxOS } from './getos';
22
import { execSync } from 'child_process';
33
import resolveConfig from './resolve-config';
44

55
export interface MongoBinaryDownloadUrlOpts {
66
version: string;
77
platform: string;
88
arch: string;
9-
os?: getos.Os;
9+
os?: AnyOS;
1010
}
1111

1212
export default class MongoBinaryDownloadUrl {
1313
platform: string;
1414
arch: string;
1515
version: string;
16-
os: getos.Os | undefined;
16+
os: AnyOS | undefined;
1717

1818
constructor({ platform, arch, version, os }: MongoBinaryDownloadUrlOpts) {
1919
this.version = version;
@@ -83,10 +83,13 @@ export default class MongoBinaryDownloadUrl {
8383
let name = `mongodb-linux`;
8484
name += `-${this.arch}`;
8585

86-
let osString;
86+
let osString: string | undefined;
8787
if (this.arch !== 'i686') {
88-
if (!this.os) this.os = await this.getos();
89-
osString = this.getLinuxOSVersionString(this.os as getos.LinuxOs);
88+
if (!this.os) {
89+
this.os = await getOS();
90+
console.log('got back:', this.os);
91+
}
92+
osString = this.getLinuxOSVersionString(this.os as LinuxOS);
9093
}
9194
if (osString) {
9295
name += `-${osString}`;
@@ -97,16 +100,7 @@ export default class MongoBinaryDownloadUrl {
97100
return name;
98101
}
99102

100-
async getos(): Promise<getos.Os> {
101-
return new Promise((resolve, reject) => {
102-
getos((e: any, os: any) => {
103-
if (e) reject(e);
104-
resolve(os);
105-
});
106-
});
107-
}
108-
109-
getLinuxOSVersionString(os: getos.LinuxOs): string {
103+
getLinuxOSVersionString(os: LinuxOS): string {
110104
if (/ubuntu/i.test(os.dist)) {
111105
return this.getUbuntuVersionString(os);
112106
} else if (/elementary OS/i.test(os.dist)) {
@@ -121,15 +115,22 @@ export default class MongoBinaryDownloadUrl {
121115
return this.getDebianVersionString(os);
122116
} else if (/mint/i.test(os.dist)) {
123117
return this.getMintVersionString(os);
118+
} else if (/unkown/i.test(os.dist)) {
119+
// in some cases this is redundant, but this is here to notify users to report if their Distro couldnt be parsed
120+
console.warn(
121+
'Couldnt parse dist infomation, please report this to https://github.com/nodkz/mongodb-memory-server/issues'
122+
);
124123
}
124+
// this is when the os.dist couldnt be handled by MongoBinaryDownloadUrl
125125
console.warn(`Unknown linux distro ${os.dist}, falling back to legacy MongoDB build`);
126+
126127
return this.getLegacyVersionString(os);
127128
}
128129

129-
getDebianVersionString(os: getos.Os): string {
130+
getDebianVersionString(os: LinuxOS): string {
130131
let name = 'debian';
131-
const release: number = parseFloat((os as getos.LinuxOs).release);
132-
if (release >= 10 || (os as getos.LinuxOs).release === 'unstable') {
132+
const release: number = parseFloat(os.release);
133+
if (release >= 10 || os.release === 'unstable') {
133134
name += '10';
134135
} else if (release >= 9) {
135136
name += '92';
@@ -141,9 +142,9 @@ export default class MongoBinaryDownloadUrl {
141142
return name;
142143
}
143144

144-
getFedoraVersionString(os: getos.Os): string {
145+
getFedoraVersionString(os: LinuxOS): string {
145146
let name = 'rhel';
146-
const fedoraVer: number = parseInt((os as getos.LinuxOs).release, 10);
147+
const fedoraVer: number = parseInt(os.release, 10);
147148
if (fedoraVer > 18) {
148149
name += '70';
149150
} else if (fedoraVer < 19 && fedoraVer >= 12) {
@@ -154,9 +155,9 @@ export default class MongoBinaryDownloadUrl {
154155
return name;
155156
}
156157

157-
getRhelVersionString(os: getos.Os): string {
158+
getRhelVersionString(os: LinuxOS): string {
158159
let name = 'rhel';
159-
const { release } = os as getos.LinuxOs;
160+
const { release } = os;
160161
if (release) {
161162
if (/^7/.test(release)) {
162163
name += '70';
@@ -170,35 +171,53 @@ export default class MongoBinaryDownloadUrl {
170171
}
171172

172173
// eslint-disable-next-line @typescript-eslint/no-unused-vars
173-
getElementaryOSVersionString(os: getos.Os): string {
174+
getElementaryOSVersionString(os: LinuxOS): string {
174175
const ubuntuVersion = execSync('/usr/bin/lsb_release -u -rs');
175176
return `ubuntu${ubuntuVersion
176177
.toString()
177178
.replace('.', '')
178179
.trim()}`;
179180
}
180181

181-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
182-
getMintVersionString(os: getos.Os): string {
183-
// unfortunately getos doesn't return version for Mint
184-
return 'ubuntu1404';
182+
getMintVersionString(os: LinuxOS): string {
183+
let name = 'ubuntu';
184+
const mintMajorVer = parseInt(os.release ? os.release.split('.')[0] : os.release);
185+
if (mintMajorVer < 17) {
186+
throw new Error('Mint Versions under 17 are not supported!');
187+
}
188+
189+
switch (mintMajorVer) {
190+
case 17:
191+
name += '1404';
192+
break;
193+
case 18:
194+
name += '1604';
195+
break;
196+
case 19:
197+
default:
198+
// a default to support versions > 19
199+
name += '1804';
200+
break;
201+
}
202+
203+
return name;
185204
}
186205

187206
// eslint-disable-next-line @typescript-eslint/no-unused-vars
188-
getLegacyVersionString(os: getos.Os): string {
207+
getLegacyVersionString(os: AnyOS): string {
189208
return '';
190209
}
191210

192-
getSuseVersionString(os: getos.Os): string {
193-
const releaseMatch: RegExpMatchArray | null = (os as getos.LinuxOs).release.match(/(^11|^12)/);
211+
getSuseVersionString(os: LinuxOS): string {
212+
const releaseMatch: RegExpMatchArray | null = os.release.match(/(^11|^12)/);
194213

195214
if (releaseMatch) {
196215
return `suse${releaseMatch[0]}`;
197216
}
198217
return '';
199218
}
200219

201-
getUbuntuVersionString(os: getos.LinuxOs): string {
220+
getUbuntuVersionString(os: LinuxOS): string {
202221
let name = 'ubuntu';
203222
const ubuntuVer: string[] = os.release ? os.release.split('.') : [];
204223
const majorVer: number = parseInt(ubuntuVer[0], 10);

packages/mongodb-memory-server-core/src/util/__tests__/MongoBinaryDownload-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ MONGOMS_MD5_CHECK environment variable`, () => {
5050
expect(du.httpDownload).toHaveBeenCalledTimes(1);
5151
const callArg1 = (du.httpDownload as jest.Mock).mock.calls[0][0];
5252
expect(callArg1.agent).toBeDefined();
53-
expect(callArg1.agent.options.href).toBe('http://user:pass@proxy:8080/');
53+
expect(callArg1.agent.proxy.href).toBe('http://user:pass@proxy:8080/');
5454
});
5555

5656
it(`makeMD5check returns true if md5 of downloaded mongoDBArchive is

0 commit comments

Comments
 (0)