feat: Add codemod to migrate to subpaths#9839
Conversation
| ); | ||
| let indexPath: string; | ||
| try { | ||
| let pkgPath = path.dirname(Module.findPackageJSON(packages[pkg].monopackage, url.pathToFileURL(file.path || `${process.cwd()}/index`))!); |
There was a problem hiding this comment.
This makes the codemod work with pnpm, which doesn't put things directly in the root node_modules folder. Instead, we resolve it from the file we're transforming.
| parser: 'tsx', | ||
| ignorePattern: '**/node_modules/**', | ||
| path: '.', | ||
| extensions: 'js,jsx,mjs,cjs,ts,tsx', |
There was a problem hiding this comment.
Noticed that running the codemod seemed to produce a lot of errors even though it worked. This was due to it trying to parse every file, e.g. mdx, source maps, etc. I think this is the list of extensions we actually care about.
|
Build successful! 🎉 |
reidbarber
left a comment
There was a problem hiding this comment.
should we have a test for dynamic imports?
|
ah that's kinda harder to handle because you don't know which exports they used from the dynamic import, and rewriting a single dynamic import into multiple changes the runtime behavior. probably won't handle that for now. |
snowystinger
left a comment
There was a problem hiding this comment.
Should we have something on our getting started docs page which says when you should use the subpaths vs the monorepo?
|
yes we need to decide what our guidance is. for now the codemod is an "if you want to" thing. |
Adds a new codemod to migrate from monopackage imports to subpaths.
Tries to group related imports together. For example, even though
Itemis available via many different subpaths, it will be imported from the one that is being used elsewhere in the file.If you want to migrate from individual packages (e.g.
@react-aria/button) to subpaths, run theuse-monopackagescodemod first before runninguse-subpaths.