MCPcopy
hub / github.com/redwoodjs/graphql / getPathsFromTypeScriptConfig

Function getPathsFromTypeScriptConfig

packages/babel-config/src/common.ts:142–182  ·  view source on GitHub ↗
(
  config: CompilerOptionsForPaths,
  rootDir: string,
)

Source from the content-addressed store, hash-verified

140 * @returns {Record<string, string>} The paths object
141 */
142export const getPathsFromTypeScriptConfig = (
143 config: CompilerOptionsForPaths,
144 rootDir: string,
145): Record<string, string> => {
146 if (!config) {
147 return {}
148 }
149
150 if (!config.compilerOptions?.paths) {
151 return {}
152 }
153
154 const { baseUrl, paths } = config.compilerOptions
155
156 let absoluteBase: string
157 if (baseUrl) {
158 // Convert it to absolute path - on windows the baseUrl is already absolute
159 absoluteBase = path.isAbsolute(baseUrl)
160 ? baseUrl
161 : path.join(rootDir, baseUrl)
162 } else {
163 absoluteBase = rootDir
164 }
165
166 const pathsObj: Record<string, string> = {}
167 for (const [key, value] of Object.entries(paths)) {
168 // exclude the default paths that are included in the tsconfig.json file
169 // "src/*"
170 // "$api/*"
171 // "types/*"
172 // "@redwoodjs/testing"
173 if (key.match(/src\/|\$api\/\*|types\/\*|\@redwoodjs\/.*/g)) {
174 continue
175 }
176 const aliasKey = key.replace('/*', '')
177 const aliasValue = path.join(absoluteBase, value[0].replace('/*', ''))
178
179 pathsObj[aliasKey] = aliasValue
180 }
181 return pathsObj
182}

Callers 3

getWebSideBabelPluginsFunction · 0.90
getApiSideBabelPluginsFunction · 0.90

Calls 1

entriesMethod · 0.80

Tested by

no test coverage detected