Code Monkey home page Code Monkey logo

vue-migration-helper's Introduction

vue-migration-helper

CLI tool to aid in migration from Vue 1.x to 2.0. It scans files for Vue-specific code and provides detailed warnings when deprecated patterns are found. It cannot reliably catch every deprecation, but should get you 80% of the way there.

Screenshot

Usage

# install
npm install --global vue-migration-helper

# navigate to a Vue 1.x project directory
cd path/to/my-vue-project

# scan all files in the current directory
vue-migration-helper
# scan all files in specific sub-directories
vue-migration-helper src folder-a folder-b
# scan a specific file or files
vue-migration-helper src/app.vue

When you want to update, just run the install again:

npm install --global vue-migration-helper

Contributing

While the binary supports Node v4+, tests are written to take advantage of v6+, so you'll need that installed.

# clone the project
git clone https://github.com/vuejs/vue-migration-helper.git

# navigate to directory
cd vue-migration-helper

# install the dependencies
npm install

Then write a failing test for a rule you'd like to improve. Confirm that it fails with:

# run all tests
npm run test -s

If your regex skills aren't strong enough to fix the problem yourself, just submit a pull request with the failing test and we'll take it from there. Before you do though, make sure to lint the project for typos and style violations:

# lint all files
npm run lint -s

vue-migration-helper's People

Contributors

atomaka avatar chrisvfritz avatar dbpolito avatar hootlex avatar ivuorinen avatar kazupon avatar probil avatar sirlancelot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-migration-helper's Issues

Perhaps introduce a flag (e.g. --pessimistic) that includes any *possible* deprecations

I just ran the migration helper and none of my v-for="(... got flagged since I believe the migration helper is just looking for "index" or "key" etc. within the brackets.

However I think that anything should be matched. So as soon as the code contains v-for followed by an opening parenthese like so

v-for="( or v-for='(

it should throw a notice. Because every scenario is possible:

v-for="(month, day) in someObject"

Or am I thinking wrong?

Modules support

Hello there,
I was wondering if it was planned to extend the support to vuejs plugins such as vue-router and vue-loader since an RC is already available.

bash: vue-migration-tool: command not found

I've installed the tool using npm i --global vue-migration-helper, restarted the computer, navigated to my vue-1 project directory using node command prompt, then ran vue-migration-helper.

I receive an error: bash: vue-migration-helper: command not found.

I'm running Node v8 and npm v5 (newest LTS release as of this date) on Windows 10.

Suggest Dependent Versions

I experienced issues with using older versions of vuex and vue-loader. Could the helper suggest appropriate versions for these as well.

Add detection of router.beforeEach() without calls to next()

I just spent an embarrassingly large amount of time trying to debug why nothing worked during my migration from 1.0.28. Turns out that the added requirement of the router.beforeEach() methods having to resolve the hook manually with a call to next() was the culprit.

As far as I can see, there is nothing in this project that alerts about this. Now, I lack the vue/js savvy to add that myself, but I suppose this could be of help to others who were using the beforeEach() hooks in 1.0.

Cheers for a fantastic tool anyway!

check-for-deprecations.js -> TypeError: Cannot read property 'some' of undefined

Hi, I'm having this issue. Below the output.
Thanks

/usr/local/lib/node_modules/vue-migration-helper/helpers/check-for-deprecations.js:43
return ignorableExtensions[warning.type].some(function (extension) {
^
TypeError: Cannot read property 'some' of undefined
at shouldIgnoreWarning (/usr/local/lib/node_modules/vue-migration-helper/helpers/check-for-deprecations.js:43:45)
at /usr/local/lib/node_modules/vue-migration-helper/helpers/check-for-deprecations.js:52:21
at Array.some (native)
at module.exports (/usr/local/lib/node_modules/vue-migration-helper/helpers/check-for-deprecations.js:50:16)
at Stream. (/usr/local/lib/node_modules/vue-migration-helper/index.js:37:38)
at emitOne (events.js:96:13)
at Stream.emit (events.js:188:7)
at drain (/usr/local/lib/node_modules/vue-migration-helper/node_modules/through/index.js:36:16)
at Stream.stream.queue.stream.push (/usr/local/lib/node_modules/vue-migration-helper/node_modules/through/index.js:45:5)
at emit (/usr/local/lib/node_modules/vue-migration-helper/node_modules/split/index.js:37:14)

Can't run the migration-helper

I can't run the migration helper. I installed it via npm install --global vue-migration-helper. Navigated to my project, then ran vue-migration-helper. I get the following message:

A newer version of vue-migration-helper is available.

  latest:    1.1.6
  installed: 1.1.1

Please update with:

  npm update --global vue-migration-helper

I ran npm update --global vue-migration-helper and then ran vue-migration-helper again, same message. I tried deleting the package and re-installing it, same message. Please advise.

Warning about outdated versions of vue libs in package.json

Migration-helper not scan package.json. so the project package.json dependencies still 1.*

    "babel-runtime": "^6.0.0",
    "es6-promise": "^3.2.1",
    "vue": "^1.0.21",
    "vue-async-data": "^1.0.2",
    "vue-resource": "^1.0.0",
    "vue-router": "^0.7.13"

install error

when I run install command

npm install --global git://github.com/vuejs/vue-migration-helper.git

I get this

npm ERR! git clone --template=/root/.npm/_git-remotes/_templates --mirror git://github.com/vuejs/vue-migration-helper.git /root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2: Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2'...
npm ERR! git clone --template=/root/.npm/_git-remotes/_templates --mirror git://github.com/vuejs/vue-migration-helper.git /root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2: fatal: Unable to look up github.com (port 9418) (Temporary failure in name resolution)
npm ERR! Linux 2.6.32-573.7.1.el6.x86_64
npm ERR! argv "/root/.nvm/versions/node/v6.5.0/bin/node" "/root/.nvm/versions/node/v6.5.0/bin/npm" "install" "--global" "git://github.com/vuejs/vue-migration-helper.git"
npm ERR! node v6.5.0
npm ERR! npm  v3.10.3
npm ERR! code 128

npm ERR! Command failed: git clone --template=/root/.npm/_git-remotes/_templates --mirror git://github.com/vuejs/vue-migration-helper.git /root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2
npm ERR! Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2'...
npm ERR! fatal: Unable to look up github.com (port 9418) (Temporary failure in name resolution)
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /root/npm-debug.log

the npm-debug.log is

25 verbose stack Error: Command failed: git clone --template=/root/.npm/_git-remotes/_templates --mirror git://github.com/vue
js/vue-migration-helper.git /root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2
25 verbose stack Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2
'...
25 verbose stack fatal: Unable to look up github.com (port 9418) (Temporary failure in name resolution)
25 verbose stack
25 verbose stack     at ChildProcess.exithandler (child_process.js:206:12)
25 verbose stack     at emitTwo (events.js:106:13)
25 verbose stack     at ChildProcess.emit (events.js:191:7)
25 verbose stack     at maybeClose (internal/child_process.js:877:16)
25 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
26 verbose cwd /root
27 error Linux 2.6.32-573.7.1.el6.x86_64
28 error argv "/root/.nvm/versions/node/v6.5.0/bin/node" "/root/.nvm/versions/node/v6.5.0/bin/npm" "install" "--global" "git:
//github.com/vuejs/vue-migration-helper.git"
29 error node v6.5.0
30 error npm  v3.10.3
31 error code 128
32 error Command failed: git clone --template=/root/.npm/_git-remotes/_templates --mirror git://github.com/vuejs/vue-migratio
n-helper.git /root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2
32 error Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-vuejs-vue-migration-helper-git-adfefcb2'...
32 error fatal: Unable to look up github.com (port 9418) (Temporary failure in name resolution)
33 error If you need help, you may report this error at:
33 error     <https://github.com/npm/npm/issues>
34 verbose exit [ 1, true ]

Support files as arguments

Supporting files instead of only directories would be helpful in case there are too many files in a directory and you get too many migration messages.
vue-migration-helper MyComponent.vue

Cannot read property 1 of null

node -v outputs v6.6.0

MacOSX

Command line output:

  var library = fileData.file.match(/([^\/]+)\/[^\/]+\.js/)[1]
                                                           ^

TypeError: Cannot read property '1' of null
    at module.exports (/usr/local/lib/node_modules/vue-migration-helper/helpers/report-warning.js:11:60)
    at /usr/local/lib/node_modules/vue-migration-helper/helpers/check-for-deprecations.js:22:7
    at Array.some (native)
    at module.exports (/usr/local/lib/node_modules/vue-migration-helper/helpers/check-for-deprecations.js:19:16)
    at Stream.<anonymous> (/usr/local/lib/node_modules/vue-migration-helper/index.js:35:36)
    at emitOne (events.js:96:13)
    at Stream.emit (events.js:188:7)
    at drain (/usr/local/lib/node_modules/vue-migration-helper/node_modules/through/index.js:36:16)
    at Stream.stream.queue.stream.push (/usr/local/lib/node_modules/vue-migration-helper/node_modules/through/index.js:45:5)
    at emit (/usr/local/lib/node_modules/vue-migration-helper/node_modules/split/index.js:37:14)```

`require` path error related to `recursive-readdir-sync`

It seems that recursive-readdir-sync returns full abspath instead of relative path when passed in an abspath. So this line will cause problem...

Me@localhost:~/Workspace/helloworld $> ./node_modules/.bin/vue-migration-helper

Error: Cannot find module '/Users/Me/Workspace/helloworld/node_modules/vue-migration-helper/rules/Users/Me/Workspace/helloworld/node_modules/vue-migration-helper/rules/vue/array-prototype-remove.js'

Tried on OSX w/ node v6.6.0 & Ubuntu w/ node v6.4.0, recursive-readdir-sync is v1.0.6. Not tried on Windows yet.

Add check for interpolated value in "value" attribute

Old 1.x code in template:
<input value="{{ example }}">

Should be easily detectable and suggest to rewrite to:
<input v-bind:value="example">

Just had a project with lots of these. Vue-loader picks them up but not the (very useful! Thank you!) migration tool.

Better detection within Laravel's .blade.php files

I ran the migration helper on a project and it is falsely detecting "Interpolation within attributes" for blade files within a Laravel project.

It thinks href="{{ $url }}" should be :href="$url"

I have to write it like href="@{{ url }}" for Vue. :)

Add Vue-Router Deprecations

  • Update history: true to mode: 'history'
  • router.map should be a routes option on a new router instance. The route definition should also be an array instead of an object.
  • router.start - should provide the router instance to the root vue instance (new Vue({ router }))
  • activate -> beforeRouteEnter in component
  • canActivate -> beforeEnter in route
  • deactivate -> component lifecycle
  • canDeactivate -> beforeRouteLeave in component
  • canReuse -> removed
  • v-link -> <router-link>
  • saveScrollPosition -> scrollBehavior in Router options
  • router.redirect -> redirect in routes in Router options
  • router.alias -> alias in routes in Router options
  • abstract (replaced by mode)
  • root (replaced by base)
  • hashbang (removed since the hashbang is no longer required for Google to crawl the URL)
  • transitionOnLoad (removed because Vue 2.0 has explicit appear transition control)
  • suppressTransitionError (removed due to hooks simplification)
  • The old router.go() is now router.push(), but router.go(number) is now a thing
  • subroutes -> children in route definition
  • keepAlive -> keep-alive attribute is deprecated, please use <keep-alive> component to wrap around <router-view>, and refer to Vue 2.0 docs.
  • v-link-active -> v-link-active is deprecated, please use <router-link> component's activeClass prop.
  • data -> Use a watcher on $route to react to route changes (e.g. fetch new data based on new route params - Example) // copied from release notes
  • router.on -> Removed. XXX router.match = createMatcher([routeConfig, ...router.options.routes])
  • $loadingRouteData should be replaced with a custom property, e.g. loading
  • /category/*tax should be changed to /category/:tax+ (uses path-to-regexp)
  • Route records of the matched routes are no longer merged into $route.

For the router, it might also be worth building a plugin that validates a router object with Joi or something.

Null exception during first run

Got this error when running on our project:

C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\helpers\report-warning.js:10
  var library = rule.file.match(/([^\/]+)\/[^\/]+\.js/)[1]
   ^

TypeError: Cannot read property '1' of null
    at module.exports (C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\helpers\report-warning.js:10:56)
    at C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\helpers\check-for-deprecations.js:26:7
    at Array.some (native)
    at module.exports (C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\helpers\check-for-deprecations.js:23:16)
    at Stream.<anonymous> (C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\index.js:35:36)
    at emitOne (events.js:96:13)
    at Stream.emit (events.js:188:7)
    at drain (C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\node_modules\through\index.js:36:16)
    at Stream.stream.queue.stream.push (C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\node_modules\through\index.js:45:5)
    at emit (C:\Users\VueRocks\AppData\Roaming\npm\node_modules\vue-migration-helper\node_modules\split\index.js:37:14)

[proposal]add `autofix` option

This tool is great. can we go further, to provide an option like--autofix? As some problems can be easily fixed. eg.

<a href="{{ $url }}">test</a>

can be fixed to something like:

<a :href="$url">test</a>

This can be very useful to some developers.you recon?:laughing:

vue-migration-tool vue-migration-tool runs out of memory

I just installed the vue migration helper on my machine and I tried running vue-migration-tool src ~/Code/CSToss and I get the following error:

er src ~/Code/CSToss
events.js:154
throw er; // Unhandled 'error' event
^

Error: ENOMEM: not enough memory, open '/home/vagrant/Code/CSToss/vendor/psy/psysh/test/fixtures/config.php'
at Error (native)

I have no idea what's going on. i have not used Vue.js that much and I am not sure why this error is comming up. I am using Laravel Homestead to run this command.

Add Vuex 2.0 Deprecations (lower priority, as upgrading to Vuex 2.0 is optional for Vue 2)

Patterns:

  • vuex: { should be replaced by action/mutation/getter/state helpers on methods and computed properties
  • store.watch('XXX', ...) -> store.watch(state => state.XXX, ...) The 1st argument of watch should be the function that returns sub state tree.
  • middlewares -> plugins
  • store.dispatch -> store.commit mutations are now triggered by commit method.
  • The arguments of store.dispatch and store.commit is no longer variadic. It now accepts a single payload value as the 2nd argument.
  • silent flag for silent dispatch is now declared in 3rd argument options object.
  • payload arguments changes (see #2 (comment))

Tool does not detect changes in *.vue component files.

While I understand this tool is in its infancy, I just want to raise the issue that *.vue files are not checked for deprecations.

I'm creating this issue more for the community so that they understand that *.vue file detection isn't supported yet.

Command failed: git -c core.longpaths=true config --get remote.origin.url

When I run this command:

npm install --global git://github.com/vuejs/vue-migration-helper.git

I get this:

npm WARN addRemoteGit Error: Command failed: git -c core.longpaths=true config --get remote.origin.url
npm WARN addRemoteGit
npm WARN addRemoteGit at ChildProcess.exithandler (child_process.js:207:12)
npm WARN addRemoteGit at emitTwo (events.js:106:13)
npm WARN addRemoteGit at ChildProcess.emit (events.js:191:7)
npm WARN addRemoteGit at maybeClose (internal/child_process.js:852:16)
npm WARN addRemoteGit at Socket. (internal/child_process.js:323:11)
npm WARN addRemoteGit at emitOne (events.js:96:13)
npm WARN addRemoteGit at Socket.emit (events.js:188:7)
npm WARN addRemoteGit at Pipe._handle.close as _onclose

I don't know why this is happening but I do have git installed.

Environment:

OS: Windows 7, running in admin mode.
NPM: 3.9.5
Node: 6.2.2

problem with detecting `value=""`

1. Update v-bind:value="{{ client.id }}" to v-bind:v-bind:value="client.id"
  Line 47: app/src/components/files.vue
  Reason: Interpolation within attributes has been removed
  More info: http://vuejs.org/guide/migration.html#Interpolation-within-Attributes

Package version constraint parsing seems off

Running vue-migration-helper with vue-router:^3.0.2 and vuex:^3.0.1 suggests following migrations:

1. Replace "vue-router": "^3.0.2" with "vue-router": "^2.0.0", then run: npm install
  Line 22: package.json
  Reason: If you are using pre-2.0 Vue Router through NPM, you have to update it in your package.json file
  More info: http://vuejs.org/guide/migration-vue-router.html#

2. Replace "vuex": "^3.1.0" with "vuex": "^1.0.0", then run: npm install
  Line 23: package.json
  Reason: Vuex 1.0 is the earliest supported version compatible with Vue 2.0
  More info: http://vuejs.org/guide/migration-vuex.html#

It looks like the check assumes anything that's not 2.* (for vue-router) is wrong:

Should/Could it be changed to use semver.satisfies('^2.0.0', [package.json data]) and ^1.0.0?

Assistant finds deprecations in images.

When running the migration assistant, some it warns about router changes within images, I assume this is unintended?

16. Replace "����0u�Q �T*ߝ���Xcf1J����.(�/����+>�:�C.+W/�f;fJ�1ʙy�_�������e���k�Gm~����Ԁ8��5�3@M�SF��#��ýڹ�2rײ����˟u����$v3�^C�Y�QA�+�nm�&��J�������/*�*8�a�m,�����" with "����0u�Q �T*ߝ���Xcf1J����.(�/����+>�:�C.+W/�f;fJ�1ʙy�_�������e���k�Gm~����Ԁ8��5�3@M�SF��#��ýڹ�2rײ����˟u����$v3�^C�Y�QA�+�nm�&��J�������/:�*8�a�m,�����+"
  Line 412: src/assets/backgrounds/editor-bg.jpg
  Reason: The syntax for route matching has changed since Vue Router now uses path-to-regexp under the hood
  More info: http://vuejs.org/guide/migration-vue-router.html#One-or-More-Named-Parameters

17. Replace "S-C �o!�wv.$�2<5O�ɦ��AH��m/*��8ɟ�F���J�c�Ò�F���+` with "S-C �o!�wv.$�2<5O�ɦ��AH��m/:��8ɟ�F���J�c�Ò�F���++`
  Line 524: src/assets/backgrounds/editor-bg.jpg
  Reason: The syntax for route matching has changed since Vue Router now uses path-to-regexp under the hood
  More info: http://vuejs.org/guide/migration-vue-router.html#One-or-More-Named-Parameters

18. Replace 'M��.g���?xN��h�oY�����/*]�l�:vB
                                            �/kE��L�Hy�FQ�%��W(r��DK�:�p��
x��RK�hP4���A��L��  9�!u���Ю^�q�Q��0vA����&=߻[L�L0{��l�q��BA27o�%�߲` with 'M��.g���?xN��h�oY�����/:]�l�:vB+
                    �/kE��L�Hy�FQ�%��W(r��DK�:�p��
x��RK�hP4���A��L��  9�!u���Ю^�q�Q��0vA����&=߻[L�L0{��l�q��BA27o�%�߲`
  Line 1180: src/assets/backgrounds/editor-bg.jpg
  Reason: The syntax for route matching has changed since Vue Router now uses path-to-regexp under the hood
  More info: http://vuejs.org/guide/migration-vue-router.html#One-or-More-Named-Parameters

helper is also reading unrelated files ex. .scss

The helper is reading files that aren't relevant.

For example:

 Rename $index to index and explicity declare it (e.g. v-for="(item, index) in items")
  Line 9: src/assets/scss/_font-loader.scss

the $index in that file has nothing to do with vue its a sass variable in a sass function

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.