Atlas › Test
helpers.mjs|title=applyExtends loads a JSON file if one is referenced by "extends" key|occurrence=1
Exact test identity: mocha:v1|namespace=yargs@4153e0f097aeaf43a71a2530db6dda51dff2c544:main|file=test/helpers.mjs|title=applyExtends loads a JSON file if one is referenced by "extends" key|occurrence=1
- Package
mocha:v1|namespace=yargs@4153e0f097aeaf43a71a2530db6dda51dff2c544:main|file=test
- Suite / test hierarchy
helpers.mjs|title=applyExtends loads a JSON file if one is referenced by "extends" key|occurrence=1
- Test
helpers.mjs|title=applyExtends loads a JSON file if one is referenced by "extends" key|occurrence=1
- Introduced at
- helpers.mjs|title=applyExtends loads a JSON file if one is referenced by "extends" key|occurrence=1 Frontier kind: Test frontier
- Covered ranges
- 22
- Covered lines
- 71
- Covered files
- 3
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
lib/utils/apply-extends.ts 54 covered LOC · 15 ranges
Open complete file
1
>
import {Dictionary, PlatformShim} from '../typings/common-types.js';
apply-extends.ts
2
>
import {YError} from '../yerror.js';
3
>
4
>
let previouslyVisitedConfigs: string[] = [];
5
>
let shim: PlatformShim;
6
>
export function applyExtends(
8
>
cwd: string,
9
>
mergeExtends: boolean,
10
>
_shim: PlatformShim
11
>
): Dictionary {
12
>
shim = _shim;
13
>
let defaultConfig = {};
14
>
15
>
if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
16
>
if (typeof config.extends !== 'string') return defaultConfig;
apply-extends.ts
17
>
const isPath = /\.json|\..*rc$/.test(config.extends);
18
>
let pathToDefault: string | null = null;
19
>
if (!isPath) {
20
try {
21
pathToDefault = import.meta.resolve(config.extends);
25
return config;
26
}
28
>
pathToDefault = getPathToDefaultConfig(cwd, config.extends);
apply-extends.ts
29
>
}
31
>
checkForCircularExtends(pathToDefault);
32
>
33
>
previouslyVisitedConfigs.push(pathToDefault);
34
>
35
>
defaultConfig = isPath
36
>
? JSON.parse(shim.readFileSync(pathToDefault, 'utf8'))
38
>
delete config.extends;
39
>
defaultConfig = applyExtends(
40
>
defaultConfig,
41
>
shim.path.dirname(pathToDefault),
42
>
mergeExtends,
43
>
shim
44
>
);
45
>
}
47
>
previouslyVisitedConfigs = [];
48
>
49
>
return mergeExtends
50
>
? mergeDeep(defaultConfig, config)
52
>
}
55
>
if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
56
throw new YError(`Circular extended configurations: '${cfgPath}'.`);
57
}
60
>
function getPathToDefaultConfig(cwd: string, pathToExtend: string) {
apply-extends.ts
61
>
return shim.path.resolve(cwd, pathToExtend);
62
>
}
64
function mergeDeep(config1: Dictionary, config2: Dictionary) {
65
const target: Dictionary = {};
lib/utils/process-argv.ts 13 covered LOC · 5 ranges
Open complete file
8
return 1;
9
}
11
function isBundledElectronApp() {
12
// process.defaultApp is either set by electron in an electron unbundled app, or undefined
14
return isElectronApp() && !(process as ElectronProcess).defaultApp;
15
}
17
function isElectronApp() {
18
// process.versions.electron is either set by electron, or undefined
20
return !!(process as ElectronProcess).versions.electron;
21
}
23
>
export function hideBin(argv: string[]) {
24
return argv.slice(getProcessArgvBinIndex() + 1);
25
}
27
>
export function getProcessArgvBin() {
28
return process.argv[getProcessArgvBinIndex()];
29
}
31
>
interface ElectronProcess extends NodeJS.Process {
32
>
defaultApp?: boolean;
33
>
versions: NodeJS.ProcessVersions & {
34
>
electron: string;
35
>
};
36
>
}
lib/yerror.ts 4 covered LOC · 2 ranges
Open complete file
1
>
export class YError extends Error {
yerror.ts
2
>
name = 'YError';
3
>
constructor(msg?: string | null) {
4
super(msg || 'yargs error');
5
if (Error.captureStackTrace) {