Fixes ignored --file-download-options (PR #1350, fix #1275)

This commit is contained in:
Abhishek Mehandiratta 2022-02-06 10:32:49 +05:30 committed by GitHub
parent e7483549af
commit 372c1d0b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import yargs from 'yargs';
import { DEFAULT_ELECTRON_VERSION } from './constants';
import {
camelCased,
checkInternet,
getProcessEnvs,
isArgFormatInvalid,
@ -582,6 +583,10 @@ export function parseArgs(args: yargs.Argv<RawOptions>): RawOptions {
]) {
if (parsed[arg] && typeof parsed[arg] === 'string') {
parsed[arg] = parseJson(parsed[arg] as string);
// sets fileDownloadOptions and browserWindowOptions
// as parsed object as they were still strings in `nativefier.json`
// because only their snake-cased variants were being parsed above
parsed[camelCased(arg)] = parsed[arg];
}
}
if (parsed['process-envs'] && typeof parsed['process-envs'] === 'string') {

View File

@ -1,4 +1,8 @@
import { isArgFormatInvalid, generateRandomSuffix } from './helpers';
import {
isArgFormatInvalid,
generateRandomSuffix,
camelCased,
} from './helpers';
describe('isArgFormatInvalid', () => {
test('is false for correct short args', () => {
@ -56,3 +60,25 @@ describe('generateRandomSuffix', () => {
expect(generateRandomSuffix(10).length).toBe(10);
});
});
describe('camelCased', () => {
test('has no hyphens in camel case', () => {
expect(camelCased('file-download')).toEqual(expect.not.stringMatching(/-/));
});
test('returns camel cased string', () => {
expect(camelCased('file-download')).toBe('fileDownload');
});
test('has no spaces in camel case', () => {
expect(camelCased('--file--download--')).toBe('fileDownload');
});
test('handles multiple hyphens properly', () => {
expect(camelCased('file--download--options')).toBe('fileDownloadOptions');
});
test('does not affect non-snake cased strings', () => {
expect(camelCased('win32options')).toBe('win32options');
});
});

View File

@ -184,3 +184,17 @@ export function checkInternet(): void {
}
});
}
/**
* Takes in a snake-cased string and converts to camelCase
*/
export function camelCased(str: string): string {
return str
.split('-')
.filter((s) => s.length > 0)
.map((word, i) => {
if (i === 0) return word;
return `${word[0].toUpperCase()}${word.substring(1)}`;
})
.join('');
}