Files
vercel__next.js/examples/cms-agilitycms/lib/dependencies.ts
Jam Balaya 555838ecbe examples: fix typos in cms-agilitycms (#82504)
## Summary

Correct spelling errors in the cms-agilitycms example, including the
image prop spelling and dependency imports.

Bug Fixes:
- Fix misspelled intersectionTreshold prop to intersectionThreshold in
the Image component and its useInView configuration

Enhancements:
- Rename dependancies.ts to dependencies.ts and update
requireComponentDependancyByName to requireComponentDependencyByName
across API and component imports

### Adding or Updating Examples

- [x] The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- [x] Make sure the linting passes by running `pnpm build && pnpm lint`.
See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

Co-authored-by: Joseph <joseph.chamochumbi@vercel.com>
2025-11-26 00:05:18 +01:00

52 lines
1.5 KiB
TypeScript

import { convertPascalToKebabCase } from "./utils";
const path = require("path");
const userComponentsPath = path.resolve("./components");
const libComponentsPath = path.resolve("./lib/components");
const requireComponent = (name) => {
let Component = null;
try {
//check the user path first (must be relative paths)
Component = require(`../components/${name}.tsx`).default;
} catch {}
if (!Component)
try {
//fallback to lib path (must be relative paths)
Component = require(`./components/${name}.tsx`).default;
} catch {}
return Component;
};
//Bug: when dynamic imports are used within the module, it doest not get outputted server-side
//let AgilityModule = dynamic(() => import ('../components/' + m.moduleName));
export const requireComponentDependencyByName = (name) => {
let pascalCaseName = name;
let kebabCaseName = convertPascalToKebabCase(name);
let Component = null;
try {
Component = requireComponent(kebabCaseName);
} catch {}
if (!Component) {
try {
Component = requireComponent(pascalCaseName);
} catch {}
}
if (!Component) {
// eslint-disable-next-line no-throw-literal
throw `Could not find a component with the name ${name}. Tried searching:
${userComponentsPath}/${kebabCaseName}.tsx',
${libComponentsPath}/${kebabCaseName}.tsx',
${userComponentsPath}/${pascalCaseName}.tsx',
${libComponentsPath}/${pascalCaseName}.tsx'.`;
}
return Component;
};