File tree Expand file tree Collapse file tree 4 files changed +38
-13
lines changed
packages/mongodb-memory-server-core/src/util Expand file tree Collapse file tree 4 files changed +38
-13
lines changed Original file line number Diff line number Diff line change @@ -201,7 +201,9 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
201201
202202 // warn for the fallback
203203 console . warn (
204- `Unknown/unsupported linux "${ os . dist } (${ os . id_like } )". Falling back to legacy MongoDB build!`
204+ `Unknown/unsupported linux "${ os . dist } (${ os . id_like ?. join (
205+ ', '
206+ ) } )". Falling back to legacy MongoDB build!`
205207 ) ;
206208
207209 return this . getLegacyVersionString ( ) ;
@@ -452,5 +454,8 @@ export default MongoBinaryDownloadUrl;
452454 * Helper function to reduce code / regex duplication
453455 */
454456function regexHelper ( regex : RegExp , os : LinuxOS ) : boolean {
455- return regex . test ( os . dist ) || ( ! isNullOrUndefined ( os . id_like ) ? regex . test ( os . id_like ) : false ) ;
457+ return (
458+ regex . test ( os . dist ) ||
459+ ( ! isNullOrUndefined ( os . id_like ) ? os . id_like . filter ( ( v ) => regex . test ( v ) ) . length >= 1 : false )
460+ ) ;
456461}
Original file line number Diff line number Diff line change @@ -216,7 +216,7 @@ describe('MongoBinaryDownloadUrl', () => {
216216 os : 'linux' ,
217217 dist : 'ManjaroLinux' ,
218218 release : '20.2' ,
219- id_like : 'arch' ,
219+ id_like : [ 'arch' ] ,
220220 } ,
221221 } ) ;
222222 expect ( await du . getDownloadUrl ( ) ) . toBe (
@@ -236,7 +236,7 @@ describe('MongoBinaryDownloadUrl', () => {
236236 os : 'linux' ,
237237 dist : 'Arch' ,
238238 release : 'rolling' ,
239- id_like : 'arch' ,
239+ id_like : [ 'arch' ] ,
240240 } ,
241241 } ) ;
242242 expect ( await du . getDownloadUrl ( ) ) . toBe (
@@ -256,7 +256,7 @@ describe('MongoBinaryDownloadUrl', () => {
256256 os : 'linux' ,
257257 dist : 'ArchStrike' ,
258258 release : 'rolling' ,
259- id_like : 'arch' ,
259+ id_like : [ 'arch' ] ,
260260 } ,
261261 } ) ;
262262 expect ( await du . getDownloadUrl ( ) ) . toBe (
@@ -275,7 +275,7 @@ describe('MongoBinaryDownloadUrl', () => {
275275 os : 'linux' ,
276276 dist : 'elementary OS' ,
277277 release : '0.3' ,
278- id_like : 'ubuntu' ,
278+ id_like : [ 'ubuntu' ] ,
279279 } ,
280280 } ) ;
281281
@@ -293,7 +293,7 @@ describe('MongoBinaryDownloadUrl', () => {
293293 os : 'linux' ,
294294 dist : 'elementary OS' ,
295295 release : '5.1' ,
296- id_like : 'ubuntu' ,
296+ id_like : [ 'ubuntu' ] ,
297297 } ,
298298 } ) ;
299299
@@ -314,7 +314,7 @@ describe('MongoBinaryDownloadUrl', () => {
314314 os : 'linux' ,
315315 dist : 'Linux Mint' ,
316316 release : '' ,
317- id_like : 'ubuntu' ,
317+ id_like : [ 'ubuntu' ] ,
318318 } ,
319319 } ) ;
320320 } ) ;
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ UBUNTU_CODENAME=focal`;
5959 dist : 'linuxmint' ,
6060 release : '20.1' ,
6161 codename : 'ulyssa' ,
62- id_like : 'ubuntu' ,
62+ id_like : [ 'ubuntu' ] ,
6363 } ) ;
6464 } ) ;
6565
@@ -82,7 +82,27 @@ UBUNTU_CODENAME=focal`;
8282 dist : 'linuxmint' ,
8383 release : '20.2' ,
8484 codename : 'uma' ,
85- id_like : 'ubuntu' ,
85+ id_like : [ 'ubuntu' ] ,
86+ } ) ;
87+ } ) ;
88+
89+ it ( 'should parse multiple "id_like"' , ( ) => {
90+ const example = `NAME="Amazon Linux"
91+ VERSION="2"
92+ ID="amzn"
93+ ID_LIKE="centos rhel fedora"
94+ VERSION_ID="2"
95+ PRETTY_NAME="Amazon Linux 2"
96+ ANSI_COLOR="0;33"
97+ CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
98+ HOME_URL="https://amazonlinux.com/"` ;
99+
100+ expect ( getos . parseOS ( example ) ) . toEqual < getos . LinuxOS > ( {
101+ os : 'linux' ,
102+ dist : 'amzn' ,
103+ release : '2' ,
104+ codename : undefined ,
105+ id_like : [ 'centos' , 'rhel' , 'fedora' ] ,
86106 } ) ;
87107 } ) ;
88108 } ) ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ const OSRegex = {
1717 name : / ^ i d \s * = \s * " ? ( \w * ) " ? $ / im,
1818 codename : / ^ v e r s i o n _ c o d e n a m e \s * = \s * ( .* ) $ / im,
1919 release : / ^ v e r s i o n _ i d \s * = \s * " ? ( \d * (?: \. \d * ) ? ) " ? $ / im,
20- id_like : / ^ i d _ l i k e \s * = \s * " ? ( \w * ) " ? $ / im,
20+ id_like : / ^ i d _ l i k e \s * = \s * " ? ( [ \w \s ] * ) " ? $ / im,
2121} ;
2222
2323export interface OtherOS {
@@ -29,7 +29,7 @@ export interface LinuxOS extends OtherOS {
2929 dist : string ;
3030 release : string ;
3131 codename ?: string ;
32- id_like ?: string ;
32+ id_like ?: string [ ] ;
3333}
3434
3535export type AnyOS = OtherOS | LinuxOS ;
@@ -128,6 +128,6 @@ export function parseOS(input: string): LinuxOS {
128128 dist : input . match ( OSRegex . name ) ?. [ 1 ] . toLocaleLowerCase ( ) ?? 'unknown' ,
129129 codename : input . match ( OSRegex . codename ) ?. [ 1 ] . toLocaleLowerCase ( ) ,
130130 release : input . match ( OSRegex . release ) ?. [ 1 ] . toLocaleLowerCase ( ) ?? '' ,
131- id_like : input . match ( OSRegex . id_like ) ?. [ 1 ] . toLocaleLowerCase ( ) ,
131+ id_like : input . match ( OSRegex . id_like ) ?. [ 1 ] . toLocaleLowerCase ( ) . split ( ' ' ) ,
132132 } ;
133133}
You can’t perform that action at this time.
0 commit comments