refactoring-codemods
refactoring-codemods copied to clipboard
Assume index.js when path resolves to a directory
import app from './app'
where ./app was a folder containing an index.js
require.resolve
should handle this. Wonder if it would be as simple as switching to that from path.resolve
?
Giving it a shot now.
it looks like require.resolve
is a no-go. It try's to resolve the file relative to the closure e.g.https://github.com/jurassix/refactoring-codemods/blob/master/src/transformers/fileHelpers/filterMatchingPaths.js#L7 . I'll hack at it from a different vector.
https://github.com/substack/node-resolve lets you resolve relative to a basedir. I believe this is what browserify uses.
i added paths to see if that would help. Looking for more outs. I think I will also have to have a whitelist even with resolve
since it defaults to just .js
Ok was approaching it wrong. This is closer.
error:
FAIL src/transformers/__tests__/import-specifier-transform-test.js (1.704s)
● import-specifier-transform › it transforms correctly
- Error: Cannot find module './bar' from '/Users/cayres/projects/refactoring-codemods/src/transformers/__testfixtures__'
code:
import resolve from 'resolve';
import { normalize } from 'path';
import removeExtension from './removeExtension';
export default function filterMatchingPaths(basedir, filePath) {
const normalizedFilePath = normalize(filePath);
return path => {
const testPath = resolve.sync(path.value.value, { basedir });
return testPath === normalizedFilePath;
};
}