feathers-plus / cli

FeathersJS CLI supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
43 stars 7 forks source link

Generated TypeScript authentication for Google/Facebook does not run / fails compiling #9

Closed iva2k closed 6 years ago

iva2k commented 6 years ago

Steps to reproduce

npm install -g @feathers-plus/cli
mkdir feathers-app
cd feathers-app
feathers-plus generate options
# choose all defaults, except "Generate TypeScript code?" Yes

feathers-plus generate app
# choose all defaults

feathers-plus generate authentication
# choose all defaults, except select Google, Facebook

Edit src/services/users/users.schema.?s file, add fields to required: and properties:

  ...
  // Required fields.
  required: [
    // !code: schema_required
    'email',
    'firstName',
    'lastName',
    'roleId'
    // !end
  ],
  ...

  // Fields in the model.
  properties: {
    // !code: schema_properties
    id: { type: 'ID' },
    email: {},
    firstName: {},
    lastName: {},
    password: {},
    roleId: { type: 'ID' }
    // !end
  },

Run re-generator:

feathers-plus generate service
# Enter "users" for prompt "What is the name of the service?", choose defaults for the rest.

feathers-plus generate all ;# current workaround for TypeScript only, regenerates src/typings.d.ts
npm start

Expected behavior

Should have running server.

Actual behavior

Fails compiling:

C:\dev\ionic3-feathersplus-try2\api.ts>npm start

> api@0.0.0 start C:\dev\ionic3-feathersplus-try2\api.ts
> ts-node --files src/

C:\dev\ionic3-feathersplus-try2\api.ts\node_modules\ts-node\src\index.ts:261
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: Γ¿» Unable to compile TypeScript:
src/authentication.ts(6,20): error TS7016: Could not find a declaration file for module '@feathersjs/authentication-oauth2'. 'C:/dev/ionic3-feathersplus-try2/api.ts/node_modules/@feathersjs/authentication-oauth2/li
b/index.js' implicitly has an 'any' type.
  Try `npm install @types/feathersjs__authentication-oauth2` if it exists or add a new declaration (.d.ts) file containing `declare module 'feathersjs__authentication-oauth2';`

    at createTSError (C:\dev\ionic3-feathersplus-try2\api.ts\node_modules\ts-node\src\index.ts:261:12)
    at getOutput (C:\dev\ionic3-feathersplus-try2\api.ts\node_modules\ts-node\src\index.ts:367:40)
    at Object.compile (C:\dev\ionic3-feathersplus-try2\api.ts\node_modules\ts-node\src\index.ts:557:11)
    at Module.m._compile (C:\dev\ionic3-feathersplus-try2\api.ts\node_modules\ts-node\src\index.ts:439:43)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\dev\ionic3-feathersplus-try2\api.ts\node_modules\ts-node\src\index.ts:442:12)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! api@0.0.0 start: `ts-node --files src/`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the api@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\iivanchenko\AppData\Roaming\npm-cache\_logs\2018-07-17T22_53_29_559Z-debug.log

Workaround

npm install --save-dev @types/feathersjs__authentication-oauth2
npm start
# runs ok
eddyystop commented 6 years ago

The authentication packages need the respective types packages e.g. @types/feathersjs__authentication-oauth2

eddyystop commented 6 years ago

Upon generating authentication with all options selected, the package.json contains

  "dependencies": {
    "@feathersjs/authentication": "^2.1.7",
    "@feathersjs/authentication-jwt": "^2.0.1",
    "@feathersjs/authentication-local": "^1.2.1",
    "@feathersjs/authentication-oauth2": "^1.1.0",
    "@feathersjs/configuration": "^1.0.2",
    "@feathersjs/errors": "^3.3.0",
    "@feathersjs/express": "^1.2.3",
    "@feathersjs/feathers": "^3.1.7",
    "@feathersjs/socketio": "^3.2.2",
    "ajv": "^6.5.2",
    "compression": "^1.7.3",
    "cors": "^2.8.4",
    "feathers-hooks-common": "^4.14.3",
    "feathers-nedb": "^3.1.0",
    "helmet": "^3.12.1",
    "lodash.merge": "^4.6.1",
    "nedb": "^1.8.0",
    "passport-auth0": "^1.0.0",
    "passport-facebook": "^2.1.1",
    "passport-github": "^1.1.0",
    "passport-google-oauth20": "^1.0.0",
    "serve-favicon": "^2.5.0",
    "winston": "^3.0.0"
  },
  "devDependencies": {
    "@types/feathersjs__authentication": "^2.1.1",
    "@types/feathersjs__authentication-jwt": "^1.0.3",
    "@types/feathersjs__authentication-local": "^1.0.2",
    "@types/feathersjs__authentication-oauth2": "^1.0.3",
    "@types/nedb": "^1.8.5",
    "@types/passport-facebook": "^2.1.8",
    "@types/passport-github": "^1.1.3",
    "eslint": "^5.1.0",
    "mocha": "^5.2.0",
    "request": "^2.87.0",
    "request-promise": "^4.2.2"
  }

So the types packages seem to be included.

iva2k commented 6 years ago

@eddyystop You say "all options selected"... I selected all authentication options except auth0 and github, and then I get "@feathersjs/authentication-oauth2": "^1.1.0" in dependencies, but no corresponding devDependencies for types.

I guess there's a missing dependency on types for google and facebook options.

Here's the tail of the log (note there is no @types/feathersjs__authentication-oauth2 anywhere):

...
We are adding the first connection in dir api

? What is the database connection string? nedb://../data
    force config\default.json
   create src\authentication.ts
    force src\app.ts
   create test\services\users.test.ts
   create src\models\users.model.ts
   create src\services\users\users.service.ts
   create src\services\users\users.interface.ts
   create src\services\users\users.schema.ts
   create src\services\users\users.mongo.ts
   create src\services\users\users.mongoose.ts
   create src\services\users\users.sequelize.ts
   create src\services\users\users.validate.ts
   create src\services\users\users.hooks.ts
    force src\services\index.ts
    force src\app.interface.ts
    force src\typings.d.ts
npm WARN api@0.0.0 No repository field.
npm WARN api@0.0.0 No license field.

+ @feathersjs/authentication-jwt@2.0.1
+ @feathersjs/authentication@2.1.6
+ @feathersjs/authentication-local@1.2.1
+ passport-facebook@2.1.1
+ @feathersjs/authentication-oauth2@1.1.0
+ @feathersjs/authentication-oauth2@1.1.0
+ passport-google-oauth20@1.0.0
added 34 packages from 27 contributors and audited 868 packages in 4.764s
found 0 vulnerabilities

npm WARN api@0.0.0 No repository field.
npm WARN api@0.0.0 No license field.

+ @types/feathersjs__authentication-local@1.0.2
+ @types/feathersjs__authentication@2.1.1
+ @types/feathersjs__authentication-jwt@1.0.3
+ @types/passport-facebook@2.1.8
added 5 packages from 9 contributors and audited 933 packages in 4.242s
found 0 vulnerabilities

npm WARN api@0.0.0 No repository field.
npm WARN api@0.0.0 No license field.

+ @feathersjs/authentication-local@1.2.1
+ ajv@6.5.2
+ passport-google-oauth20@1.0.0
+ passport-facebook@2.1.1
+ @feathersjs/authentication-oauth2@1.1.0
+ @feathersjs/authentication-oauth2@1.1.0
+ feathers-nedb@3.0.1
added 9 packages from 7 contributors, updated 7 packages and audited 946 packages in 4.779s
found 0 vulnerabilities

npm WARN api@0.0.0 No repository field.
npm WARN api@0.0.0 No license field.

+ @types/nedb@1.8.5
added 1 package from 2 contributors and audited 947 packages in 4.157s
found 0 vulnerabilities

npm WARN api@0.0.0 No repository field.
npm WARN api@0.0.0 No license field.

+ nedb@1.8.0
added 7 packages from 9 contributors and audited 957 packages in 4.738s
found 0 vulnerabilities

Here's the resulting package.json:

{
  "name": "api",
  "description": "Project api",
  "version": "0.0.0",
  "homepage": "",
  "main": "src",
  "keywords": [
    "feathers"
  ],
  "author": {
    "name": "iva2k",
    "email": "iva2k@yahoo.com"
  },
  "contributors": [],
  "bugs": {},
  "directories": {
    "lib": "src",
    "test": "test/"
  },
  "engines": {
    "node": "^8.0.0",
    "npm": ">= 3.0.0"
  },
  "scripts": {
    "test": "npm run tslint && npm run mocha",
    "tslint": "tslint -p tsconfig.json -c tslint.json && tslint -p tsconfig.test.json -c tslint.json",
    "start": "ts-node --files src/",
    "mocha": "ts-mocha -p tsconfig.test.json 'test/**/*.test.ts' --timeout 10000 --exit",
    "compile": "tsc -p tsconfig.json"
  },
  "dependencies": {
    "@feathersjs/authentication": "^2.1.6",
    "@feathersjs/authentication-jwt": "^2.0.1",
    "@feathersjs/authentication-local": "^1.2.1",
    "@feathersjs/authentication-oauth2": "^1.1.0",
    "@feathersjs/configuration": "^1.0.2",
    "@feathersjs/errors": "^3.3.0",
    "@feathersjs/express": "^1.2.3",
    "@feathersjs/feathers": "^3.1.7",
    "@feathersjs/socketio": "^3.2.2",
    "ajv": "^6.5.2",
    "compression": "^1.7.2",
    "cors": "^2.8.4",
    "feathers-hooks-common": "^4.14.3",
    "feathers-nedb": "^3.0.1",
    "helmet": "^3.12.1",
    "lodash.merge": "^4.6.1",
    "nedb": "^1.8.0",
    "passport-facebook": "^2.1.1",
    "passport-google-oauth20": "^1.0.0",
    "serve-favicon": "^2.5.0",
    "winston": "^3.0.0"
  },
  "devDependencies": {
    "@types/compression": "0.0.36",
    "@types/cors": "^2.8.4",
    "@types/feathersjs__authentication": "^2.1.1",
    "@types/feathersjs__authentication-jwt": "^1.0.3",
    "@types/feathersjs__authentication-local": "^1.0.2",
    "@types/feathersjs__configuration": "^1.0.1",
    "@types/feathersjs__errors": "^3.2.1",
    "@types/feathersjs__express": "^1.1.4",
    "@types/feathersjs__feathers": "^3.0.4",
    "@types/feathersjs__socketio": "^3.0.3",
    "@types/helmet": "0.0.38",
    "@types/lodash.merge": "^4.6.3",
    "@types/mocha": "^5.2.3",
    "@types/nedb": "^1.8.5",
    "@types/passport-facebook": "^2.1.8",
    "@types/request-promise": "^4.1.41",
    "@types/serve-favicon": "^2.2.30",
    "@types/winston": "^2.3.9",
    "mocha": "^5.2.0",
    "request": "^2.87.0",
    "request-promise": "^4.2.2",
    "ts-mocha": "^1.2.0",
    "ts-node": "^7.0.0",
    "tslint": "^5.10.0",
    "typescript": "^2.9.2"
  }
}

If I rerun feathers-plus generate authentication and select Auth0, then, @types/feathersjs__authentication-oauth2 are installed.

eddyystop commented 6 years ago

The issue seems to have been that the auth0 typing was not included for the Google strategy.

Fix published as f+/cli v0.4.16.

Please confirm it fixes the situation. Thanks.

iva2k commented 6 years ago

Yes, fixed for Google auth.

However, if I select only Facebook, the same typings error remains.

eddyystop commented 6 years ago

Fix published to f+/cli as v0.4.18 running generator v0.2.24.

Please confirm it fixes the situation. Thanks.

eddyystop commented 6 years ago

@iva2k any news?

iva2k commented 6 years ago

I was out for few days. Just tested Facebook, npm start works fine.