升级feathersJS framework


  • administrators

    半年前装备的feathersJS,挺好的东西。刚好在新项目里派上用场。nodeJS的世界里,各种模块包更新太快,feathersJS也不例外。既然是新项目,应该用最新版吧。
    NCU (npm check updates)这个模块可以自动更新模块包,但是一定要谨慎使用,因为很多新版本是不兼容旧版本的。因为是新项目,就不用太担心,有错就改,影响不大。

    ncu
    Checking /Projects/next-feathers/feathers/package.json
    [====================] 30/30 100%
    
     @feathersjs/authentication        ^2.1.11  →   ^4.5.3 
     @feathersjs/authentication-jwt     ^2.0.5  →  ^2.0.10 
     @feathersjs/authentication-local   ^1.2.5  →   ^4.5.3 
     @feathersjs/configuration          ^2.0.4  →   ^4.5.3 
     @feathersjs/errors                 ^3.3.4  →   ^4.5.3 
     @feathersjs/express                ^1.2.7  →   ^4.5.3 
     @feathersjs/feathers               ^3.2.3  →   ^4.5.3 
     @feathersjs/socketio               ^3.2.6  →   ^4.5.3 
     compression                        ^1.7.3  →   ^1.7.4 
     cors                               ^2.8.4  →   ^2.8.5 
     feathers-blob                      ^2.0.1  →   ^2.2.0 
     feathers-mongodb                   ^3.4.0  →   ^6.1.0 
     feathers-mongoose                  ^6.1.4  →   ^8.3.0 
     helmet                            ^3.21.1  →  ^3.22.0 
     json-server                       ^0.14.0  →  ^0.16.1 
     mongodb                            ^3.1.6  →   ^3.5.6 
     mongodb-core                       ^3.1.0  →   ^3.2.7 
     mongoose                           ^5.3.0  →  ^5.9.10 
     multer                             ^1.4.1  →   ^1.4.2 
     python-shell                       ^1.0.6  →   ^1.0.8 
     winston                            ^3.1.0  →   ^3.2.1 
     xlsx                              ^0.14.0  →  ^0.15.6 
     eslint                             ^5.5.0  →   ^6.8.0 
     mocha                              ^5.2.0  →   ^7.1.1 
     nodemon                           ^1.18.4  →   ^2.0.3 
     request                           ^2.88.0  →  ^2.88.2 
     request-promise                    ^4.2.2  →   ^4.2.5 
    

    这是v2 到 v4的变动,估计升级之后,是跑不动了。果然ncu -u之后,起不来了。

    throw new Error('The hashPassword hook requires a field name option');
    TypeError: authentication is not a function
    

    到feathersjs官网查了一下,看了Authentication这块做了不少改动。好在他们提供了命令行的自动升级:feathers upgrade(非常厚道啊)细看这里:https://docs.feathersjs.com/guides/migrating.html

    这个之后,还有一个warning,这个和feathersjs的升级没关系

    (node:52539) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
    

    这个看似好改,但是在feathers下,它涉及两个文件:mongodb.js 和 mongoose.js。改动如下:

    // mongodb.js
    const promise = MongoClient.connect(config, {
        useUnifiedTopology: true,
        useNewUrlParser: true,
      }).then((client) => {
        // For mongodb <= 2.2
        if (client.collection) {
          return client;
        }
    
        const dbName = parse(config, () => {});
        return client.db(dbName);
      });
    
    //mongoose.js
    mongoose.connect(app.get("mongodb"), {
        useNewUrlParser: true,
        useUnifiedTopology: true,
        auth: {
          user: app.get("mongoUser"),
          password: app.get("mongoPass"),
        },
      });
    

    好了就这些!