Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update literal paths #21

Merged
merged 15 commits into from
Jul 29, 2019
Merged

Conversation

snewcomer
Copy link
Contributor

This PR attempts to replace examples like ember-data/model with @ember-data/model based on the mappings here: https://github.com/ember-data/ember-data-rfc395-data

Moreover, I removed the beautify code. I'm not sure this codemod should be modifying these imports as show here - ember-codemods/ember-modules-codemod#90. If you would like, I can add this in a different PR.

Copy link
Member

@dcyriller dcyriller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice addition!

I removed the beautify code. If you would like, I can add this in a different PR.

It would make sense in an other PR 😀.
I like this change. I was thinking of using Prettier to replace the beautifyImport function (scoped to the updated / added imports). But for now, it's probably better to remove the function.

To make the CI happy, you'll need to run yarn lint:js --fix.

@snewcomer snewcomer force-pushed the sn/replace-old-paths branch from 7e14528 to 47d5d20 Compare July 24, 2019 14:22
@snewcomer
Copy link
Contributor Author

Updated with master!

@@ -11,7 +11,7 @@ let cwd = process.cwd();
let pkgPath = path.join(cwd, 'package.json');

const DEFAULT_PATHS = [
'app',
'app'
'addon',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we have a typo here

@@ -0,0 +1,4 @@
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this output to show the failing test. My bad, this isn't ready to go. I ran it on our project and had to manually collapse so we didn't have duplicate imports. I'll try to fix.

Copy link
Member

@dcyriller dcyriller Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, let me know when you need another review.

Copy link
Contributor Author

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcyriller Ready for your review! Tested on a fairly large project and worked with no eslint errors.

* After modifying existing sources to their new paths, we need
* to make sure we clean up duplicate imports
*/
function cleanupDuplicateLiteralPaths() {
Copy link
Contributor Author

@snewcomer snewcomer Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to use the existing registry.modules somehow, but at this point in the codemod, they might contain old information. So in this solution, I went with iterating over the imports (post updating their source) and adding to the existing import if found.

@@ -0,0 +1,5 @@
import Model, { attr } from 'ember-data/model';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, it seems we have a wrong import. It should be:

 import Model from 'ember-data/model';
 import attr from 'ember-data/attr';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't make the test fail, because attr is identified in the modules lookup.

@dcyriller
Copy link
Member

Thank you very much @snewcomer! Do you prefer to rewrite a bit the git history or should I squash and merge?

@dcyriller
Copy link
Member

dcyriller commented Jul 29, 2019

Also, I'll fill an issue to update updateExistingLiteralPaths function to support default customly named imports.

For instance, import namedAttr from "ember-data/attr won't be supported yet. But we can iterate on this.

@snewcomer
Copy link
Contributor Author

@dcyriller Squash and merge. Also, yeah a follow up issue is something we can work on after (perhaps today)!

@dcyriller dcyriller merged commit 7e3fb9f into ember-codemods:master Jul 29, 2019
@dcyriller
Copy link
Member

🍻

Issue is here: #23

@dcyriller dcyriller added the enhancement New feature or request label Jul 30, 2019
@dcyriller
Copy link
Member

FYI @snewcomer I've noticed an issue regarding updating literal paths. I've opened here a PR with a failing test: #24

If you don't have time to look at it, I will have some on Friday. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants