Skip to content

Commit

Permalink
chore: some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Feb 27, 2022
1 parent af4e0e7 commit acfcb95
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/vite/src/node/utils.ts
Expand Up @@ -189,21 +189,13 @@ const knownTsOutputRE = /\.(js|mjs|cjs|jsx)$/
export const isTsRequest = (url: string) => knownTsRE.test(cleanUrl(url))
export const isPossibleTsOutput = (url: string) =>
knownTsOutputRE.test(cleanUrl(url))
export const getPotentialTsSrcPaths = (filename: string) => {
const fileParts = filename.split(/(\.[cm]?js\?|\.[cm]?js$)/)

// If there are three parts, the file uses a .js, .mjs or .cjs extension.
// We replace the 'js' part with 'ts' and 'tsx'.
if (fileParts.length === 3) {
const [namePart, extension, queryPart] = fileParts

return [
`${namePart}${extension.replace('js', 'ts')}${queryPart}`,
`${namePart}${extension.replace('js', 'tsx')}${queryPart}`
]
export function getPotentialTsSrcPaths(filePath: string) {
const [name, type, query = ''] = filePath.split(/(\.(?:[cm]?js|jsx))(\?.*)?$/)
const paths = [name + '.tsx' + query]
if (!type.endsWith('x')) {
paths.push(name + '.ts' + query)
}

return [filename.replace(/\.([cm])?(js)(x?)(\?|$)/, '.$1ts$3')]
return paths
}

const importQueryRE = /(\?|&)import=?(?:&|$)/
Expand Down

0 comments on commit acfcb95

Please sign in to comment.