MCPcopy Create free account
hub / github.com/Effect-TS/effect / extractModuleMetadata

Function extractModuleMetadata

packages/tools/utils/src/Codegen.ts:74–115  ·  view source on GitHub ↗
(file: string, content: string)

Source from the content-addressed store, hash-verified

72}
73
74const extractModuleMetadata = (file: string, content: string): Effect.Effect<ModuleMetadata, BarrelCodegenError> => {
75 // allow triple-slash directives before the module JSDoc
76 const block = content.match(/^(?:\s*\/\/\/[^\n]*\n)*\s*(\/\*\*[\s\S]*?\*\/)/)?.[1]
77 if (block === undefined) {
78 return Effect.fail(
79 new BarrelCodegenError({
80 path: file,
81 reason: "missing top-level module JSDoc"
82 })
83 )
84 }
85 const matches = Array.from(block.matchAll(/^\s*\*\s*@since(?:\s+(.*))?$/gm))
86 if (matches.length !== 1) {
87 return Effect.fail(
88 new BarrelCodegenError({
89 path: file,
90 reason: matches.length === 0
91 ? "missing top-level module @since tag"
92 : "multiple top-level module @since tags"
93 })
94 )
95 }
96 const since = matches[0]?.[1]?.trim() ?? ""
97 if (since.length === 0) {
98 return Effect.fail(
99 new BarrelCodegenError({
100 path: file,
101 reason: "empty top-level module @since tag"
102 })
103 )
104 }
105 return Effect.succeed({
106 since,
107 stability: isInternalModule(file, block) ?
108 undefined :
109 /^\s*\*\s*@stability\s+(stable|unstable|experimental)\s*$/m.exec(block)?.[1] as
110 | "stable"
111 | "unstable"
112 | "experimental"
113 | undefined
114 })
115}
116
117const isInternalModule = (file: string, block: string): boolean =>
118 file.split(/[/\\]/).includes("internal") || /^\s*\*\s*@internal\s*$/m.test(block)

Callers 1

Codegen.tsFile · 0.85

Calls 6

isInternalModuleFunction · 0.85
fromMethod · 0.80
trimMethod · 0.80
failMethod · 0.65
succeedMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected