ramda#mergeDeepRight TypeScript Examples
The following examples show how to use
ramda#mergeDeepRight.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: metadata.ts From express-zod-api with MIT License | 6 votes |
copyMeta = <A extends z.ZodTypeAny, B extends z.ZodTypeAny>(
src: A,
dest: B
): B | WithMeta<B> => {
if (!hasMeta(src)) {
return dest;
}
dest = withMeta(dest);
const def = dest._def as MetaDef<B>;
const examplesCombinations = combinations(
def[metaProp].examples,
src._def[metaProp].examples
);
// general deep merge except examples
def[metaProp] = mergeDeepRight(
{ ...def[metaProp], examples: [] },
{ ...src._def[metaProp], examples: [] }
);
if (examplesCombinations.type === "single") {
def[metaProp].examples = examplesCombinations.value;
} else {
for (const [destExample, srcExample] of examplesCombinations.value) {
def[metaProp].examples.push(
mergeDeepRight({ ...destExample }, { ...srcExample })
);
}
}
return dest;
}
Example #2
Source File: index.ts From reskript with MIT License | 6 votes |
resolveJestConfig = async (jestConfigOptions: JestConfigOptions): Promise<string> => {
const {cwd} = jestConfigOptions;
// find out jest.config
const jestConfigFile = path.resolve(cwd, 'jest.config.js');
// if no jest config ,return getJestConfig
if (!fs.existsSync(jestConfigFile)) {
return JSON.stringify(getJestConfig(jestConfigOptions));
}
// 用`import`拿一个CommonJS的模块,拿到的东西要是里面的`default`
try {
// NOTE: 这里没用`importUserModule`是因为反正Jest就不支持ESM,真干了也没用
const {default: jestConfig} = await import(pathToFileURL(jestConfigFile).toString());
if ('preset' in jestConfig) {
// 如果用户的配置里有`preset`,那它应该已经声明了基于`@reskript/config-jest`来配置,直接返回就行
return JSON.stringify(jestConfig);
}
else {
// 如果没有`preset`,那我们认为用户自己声明的是一个“扩展”的配置,需要我们把默认配置合并进去
const skrConfig = getJestConfig(jestConfigOptions);
// 用户的覆盖skr的
return JSON.stringify(mergeDeepRight(skrConfig, jestConfig));
}
}
catch {
logger.warn('Failed to parse your custom jest.config.js, fallback to default configuration');
return JSON.stringify(getJestConfig(jestConfigOptions));
}
}
Example #3
Source File: preset.ts From reskript with MIT License | 6 votes |
getJestPresetConfig = (target: 'react' | 'node', configBasePath: string, options?: JestConfigOptions) => {
const baseConfig = {
moduleNameMapper: {
'\\.(css|less)$': resolve.sync('identity-obj-proxy'),
[`\\.(${STATIC_EXTENSIONS.join('|')})$`]: `${unixify(configBasePath)}/mockStatic`,
'\\.svg\\?react$': `${unixify(configBasePath)}/mockComponent`,
'@/(.*)$': '<rootDir>/src/$1',
},
globals: {
skr: {
build: {
mode: 'production',
// TODO: 现在是写死的,后续看`--test-target`参数
target: 'dev',
},
// 如果自己有`jest.config.js`,需要自己写`skr.features`才行
features: options?.features ?? {},
},
},
moduleDirectories: ['src', 'node_modules'],
moduleFileExtensions: ['js', 'ts', 'jsx', 'tsx'],
transform: {
'node_modules/.+\\.(js|jsx|ts|tsx)$': `${unixify(configBasePath)}/thirdPartyTransformer`,
'^.+\\.(js|jsx|ts|tsx)$': `${unixify(configBasePath)}/transformer`,
'^.+\\.(md|mdx|txt|tpl)$': resolve.sync('jest-raw-loader'),
},
// 默认会忽略`node_modules`,所以这里要设置
transformIgnorePatterns: [],
coverageReporters: ['json-summary', 'lcov', 'text', 'clover'],
testMatch: ['**/__tests__/**/*.test.{js,jsx,ts,tsx}'],
collectCoverageFrom: ['<rootDir>/src/**/*.{js,jsx,ts,tsx}'],
coveragePathIgnorePatterns: ['/node_modules/', '/__tests__/'],
};
const targetConfig = target === 'react' ? reactJestConfig(configBasePath) : nodeJestConfig;
return mergeDeepRight(baseConfig, targetConfig);
}