(file: string, content: string)
| 72 | } |
| 73 | |
| 74 | const 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 | |
| 117 | const isInternalModule = (file: string, block: string): boolean => |
| 118 | file.split(/[/\\]/).includes("internal") || /^\s*\*\s*@internal\s*$/m.test(block) |
no test coverage detected