Last active
March 12, 2023 12:35
-
-
Save stefanprobst/66f6992e6df69048ccbea89f0d920d83 to your computer and use it in GitHub Desktop.
add .js extension to imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function ( | |
/** @type {import('jscodeshift').FileInfo} */ fileInfo, | |
/** @type {import('jscodeshift').API} */ api, | |
) { | |
const ast = api.jscodeshift(fileInfo.source); | |
const nodes = ast.find("ImportDeclaration"); | |
nodes.forEach((node) => { | |
const path = node.value.source.value | |
if (path.startsWith('@/') && !path.endsWith('.js')) { | |
node.value.source.value = node.value.source.value + '.js' | |
} | |
}); | |
return ast.toSource(); | |
}; | |
module.exports.parser = "tsx"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment