Skip to content

Instantly share code, notes, and snippets.

@stefanprobst
Last active March 12, 2023 12:35
Show Gist options
  • Save stefanprobst/66f6992e6df69048ccbea89f0d920d83 to your computer and use it in GitHub Desktop.
Save stefanprobst/66f6992e6df69048ccbea89f0d920d83 to your computer and use it in GitHub Desktop.
add .js extension to imports
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