Atlas › Test

helpers.mjs|title=helpers applyExtends exposes applyExtends helper|occurrence=1

Exact test identity: mocha:v1|namespace=yargs@4153e0f097aeaf43a71a2530db6dda51dff2c544:esm|file=test/esm/helpers.mjs|title=helpers applyExtends exposes applyExtends helper|occurrence=1

Package
mocha:v1|namespace=yargs@4153e0f097aeaf43a71a2530db6dda51dff2c544:esm|file=test/esm
Suite / test hierarchy
helpers.mjs|title=helpers applyExtends exposes applyExtends helper|occurrence=1
Test
helpers.mjs|title=helpers applyExtends exposes applyExtends helper|occurrence=1
Introduced at
apply-extends.ts ×2 Frontier kind: Joint frontier
Covered ranges
27
Covered lines
86
Covered files
3

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

lib/utils/apply-extends.ts 69 covered LOC · 20 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(
7 > config: Dictionary, apply-extends.ts
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 }
27 > } else { apply-extends.ts
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'))
37 > : _shim.require(config.extends); apply-extends.ts
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)
51 > : Object.assign({}, defaultConfig, config); apply-extends.ts
52 > }
54 > function checkForCircularExtends(cfgPath: string) { apply-extends.ts
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) { apply-extends.ts
65 > const target: Dictionary = {};
66 > function isObject(obj: Dictionary | any): obj is Dictionary {
67 > return obj && typeof obj === 'object' && !Array.isArray(obj); apply-extends.ts
68 > }
69 > Object.assign(target, config1); apply-extends.ts
70 > for (const key of Object.keys(config2)) {
71 > if (key === '__proto__') continue;
72 > if (isObject(config2[key]) && isObject(target[key])) {
73 target[key] = mergeDeep(config1[key], config2[key]);
74 > } else { apply-extends.ts
75 > target[key] = config2[key];
76 > }
78 > return target;
79 > }
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) {