MCPcopy Create free account
hub / github.com/contentlayerdev/contentlayer / makeSource

Function makeSource

packages/@contentlayer/source-files/src/index.ts:78–134  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

76 Partial<Flags>
77
78export const makeSource: core.MakeSourcePlugin<Args> = (args) => async (sourceKey) => {
79 const {
80 options,
81 extensions,
82 restArgs: {
83 documentTypes,
84 contentDirPath: contentDirPath_,
85 contentDirInclude: contentDirInclude_,
86 contentDirExclude: contentDirExclude_,
87 onUnknownDocuments = 'skip-warn',
88 onMissingOrIncompatibleData = 'skip-warn',
89 onExtraFieldData = 'warn',
90 },
91 } = await processArgs(args, sourceKey)
92
93 const flags: Flags = { onUnknownDocuments, onExtraFieldData, onMissingOrIncompatibleData }
94
95 const documentTypeDefs = (Array.isArray(documentTypes) ? documentTypes : Object.values(documentTypes)).map((_) =>
96 _.def(),
97 )
98
99 return {
100 type: 'local',
101 extensions: extensions ?? {},
102 options,
103 provideSchema: (esbuildHash) =>
104 pipe(
105 makeCoreSchema({ documentTypeDefs, options, esbuildHash }),
106 T.mapError((error) => new SourceProvideSchemaError({ error })),
107 ),
108 fetchData: ({ schemaDef, verbose, skipCachePersistence }) =>
109 pipe(
110 S.fromEffect(core.getCwd),
111 S.chain((cwd) => {
112 const contentDirPath = unknownToAbsolutePosixFilePath(contentDirPath_, cwd)
113 const contentDirExclude = (contentDirExclude_ ?? contentDirExcludeDefault).map((_) =>
114 unknownToRelativePosixFilePath(_, contentDirPath),
115 )
116 const contentDirInclude = (contentDirInclude_ ?? []).map((_) =>
117 unknownToRelativePosixFilePath(_, contentDirPath),
118 )
119
120 return fetchData({
121 coreSchemaDef: schemaDef,
122 documentTypeDefs,
123 flags,
124 options,
125 contentDirPath,
126 contentDirExclude,
127 contentDirInclude,
128 verbose,
129 skipCachePersistence,
130 })
131 }),
132 ),
133 }
134}
135

Callers 14

index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
index.test.tsFile · 0.90
makeSchemaFunction · 0.90

Calls 6

processArgsFunction · 0.90
makeCoreSchemaFunction · 0.85
mapMethod · 0.80
fetchDataFunction · 0.50

Tested by 1

renderTypeSourceFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…