* Transforms the source code of the inputs to be used locally. * @param exportData - The code to export. * @returns
(exportData: string, type: string)
| 112 | * @returns |
| 113 | */ |
| 114 | function transformSource(exportData: string, type: string): string | never { |
| 115 | if (exportData) { |
| 116 | // Change the exports from relative to npm package based. |
| 117 | exportData = exportData.replace( |
| 118 | /(}\sfrom\s['"])\.\.\/(?:index(?:\.mjs)?)?(['"])?/g, |
| 119 | '$1@formkit/inputs$2' |
| 120 | ) |
| 121 | const memoKey = token() |
| 122 | exportData = exportData.replace( |
| 123 | /(schemaMemoKey:\s?['"])[a-zA-Z0-9]+(['"])/g, |
| 124 | `$1${memoKey}$2` |
| 125 | ) |
| 126 | // Inject the forceTypeProp in the definition. |
| 127 | exportData = exportData.replace( |
| 128 | /^ props: \[(.*)\],/gm, |
| 129 | ` props: [$1], |
| 130 | /** |
| 131 | * Forces node.props.type to be this explicit value. |
| 132 | */ |
| 133 | forceTypeProp: '${type}',` |
| 134 | ) |
| 135 | } else { |
| 136 | error('Unable to export the input file because it cannot be located.') |
| 137 | } |
| 138 | return exportData |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Determine the language the user wants to export. |
no test coverage detected