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

Enable TS Strict mode and fix linting errors #63

Closed
wants to merge 2 commits into from

Conversation

chrste90
Copy link
Contributor

@chrste90 chrste90 commented Apr 6, 2018

TSLint was complaining about shadowed variable filter in mqtt.service.
Instead of renaming all instances of filter, i just renamed the filter operator of from rxjs import.
I also enabled linting on travis.

Based on #61, so only the second commit is important.

@chrste90 chrste90 changed the title Enable TS Strict mode and fix linting errors WIP: Enable TS Strict mode and fix linting errors Apr 6, 2018
@chrste90 chrste90 changed the title WIP: Enable TS Strict mode and fix linting errors Enable TS Strict mode and fix linting errors Apr 6, 2018
@sclausen
Copy link
Owner

sclausen commented Apr 8, 2018

I checked out this pull request to test your work, but unfortunately, I have some problems building. Did you encountered something like this?

username@hostname ~/git/username/ngx-mqtt (git)-[angular-cli] % npm run build

> ngx-mqtt@6.0.0 build /home/username/git/username/ngx-mqtt
> ng build

Building Angular Package
Building entry point 'ngx-mqtt'
Cleaning build directory
Rendering Stylesheets
Rendering Templates
Compiling TypeScript sources through ngc
Bundling to FESM15
Bundling to FESM5
Bundling to UMD
Minifying UMD bundle

BUILD ERROR
ENOENT: no such file or directory, open '/home/username/git/username/ngx-mqtt/projects/ngx-mqtt/.ng_pkg_build/ngx-mqtt/out/lib/mqtt.service.ts'
Error: ENOENT: no such file or directory, open '/home/username/git/username/ngx-mqtt/projects/ngx-mqtt/.ng_pkg_build/ngx-mqtt/out/lib/mqtt.service.ts'

ENOENT: no such file or directory, open '/home/username/git/username/ngx-mqtt/projects/ngx-mqtt/.ng_pkg_build/ngx-mqtt/out/lib/mqtt.service.ts'
Error: ENOENT: no such file or directory, open '/home/username/git/username/ngx-mqtt/projects/ngx-mqtt/.ng_pkg_build/ngx-mqtt/out/lib/mqtt.service.ts'

@chrste90
Copy link
Contributor Author

chrste90 commented Apr 9, 2018

I didn't have such problems. Do you have them on all three pull request or only on this one?

I also tried it on my windows machine and it worked there too. Did you run a fresh npm install with deleting node_modules and package-lock.json? I often have some problems which are only related to corrupt npm installations.

@sclausen
Copy link
Owner

sclausen commented Apr 9, 2018

I tried at work again and building/publishing ngx-mqtt works like a charm. I have a few questions about the source code though:

  1. Is there a reason behind moving the source to projects/ngx-mqtt? Or could you change from projects/ngx-mqtt to lib?
    the package.json of the root folder?
  2. I'm a bit confused about the two package.json files. package.json contains the fields name, version, main, module, typings and keywords, but to publish ngx-mqtt I have to run npm publish in projects/ngx-mqtt, which also has name and version. Shouldn't have projects/ngx-mqtt/package.json those fields instead? It seems a source of errors to have two package.json with the same name and version fields.

Unfortunately, I can't serve with ngx-mqtt@6.0.0. ng build and ng serve works without an error, but in the browser the following error occurs:
error
Here is the package.json and ng --version

{
  "name": "test123",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^6.0.0-rc.1",
    "@angular/common": "^6.0.0-rc.1",
    "@angular/compiler": "^6.0.0-rc.1",
    "@angular/core": "^6.0.0-rc.1",
    "@angular/forms": "^6.0.0-rc.1",
    "@angular/http": "^6.0.0-rc.1",
    "@angular/platform-browser": "^6.0.0-rc.1",
    "@angular/platform-browser-dynamic": "^6.0.0-rc.1",
    "@angular/router": "^6.0.0-rc.1",
    "core-js": "^2.5.4",
    "ngx-mqtt": "^6.0.0",
    "rxjs": "^6.0.0-rc.0",
    "zone.js": "^0.8.24"
  },
  "devDependencies": {
    "@angular/compiler-cli": "^6.0.0-rc.1",
    "@angular-devkit/build-angular": "~0.5.0",
    "typescript": "~2.7.2",
    "@angular/cli": "~6.0.0-rc.2",
    "@angular/language-service": "^6.0.0-rc.1",
    "@types/jasmine": "~2.8.6",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.2.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~1.4.2",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.3.0",
    "ts-node": "~5.0.1",
    "tslint": "~5.9.1"
  }
}
username@hostname /tmp/test123 (git)-[master] % ng --version

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 6.0.0-rc.2
Node: 8.11.1
OS: linux x64
Angular: 6.0.0-rc.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 6.0.0-rc.2
@angular-devkit/architect: 0.5.4
@angular-devkit/build-angular: 0.5.4
@angular-devkit/build-optimizer: 0.5.4
@angular-devkit/core: 0.5.4
@angular-devkit/schematics: 0.5.4
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 6.0.0-rc.2.4
@schematics/angular: 0.5.4
@schematics/update: 0.5.4
typescript: 2.7.2
webpack: 4.5.0

@chrste90
Copy link
Contributor Author

chrste90 commented Apr 9, 2018

  1. The only reason was that it's the folder which is created by angular-cli when you create a new library. I moved the code to lib folder (the originally created folder inside projects is especially useful for multiple projects inside one repo).

  2. Yes you are right, i forgot to move all these things to the new package.json (it is now inside lib/package.json). About the two package.json: The root package.json contains all possible dependencies you could need for the development, while the lib/package.json is only used for deployment. I think it is good to have a seperate package.json for this because it is small and clean and the published package.json doesn't contain any boilerplate which isn't needed for consumers.

For the error: I will now investigate and try to reproduce on my machine. I think it is also a good idea to merge this one first: #61. There i didn't make so much changes, only the one which were needed for rxjs and angular v6. Maybe the error don't show up there. (The changes i described in 1. and 2. are also only there for now, i didn't had time to rebase this PR yet).
It would also be nice if you could try the branch and check if you have the error there.

@chrste90
Copy link
Contributor Author

chrste90 commented Apr 9, 2018

I think i found the reason for the error:
angular/angular-cli#9827 (comment)

The angular cli v6 no longer provides a shim for process but mqtt.js relies on this: https://github.com/mqttjs/MQTT.js/blob/master/lib/store.js#L76

So the best for now should be to add a new step to guide to let consumers know that they need to include a node shim to their builds and probably file an issue at mqtt.js.

I'm now trying to get ngx-mqtt working with a shim.

@chrste90
Copy link
Contributor Author

chrste90 commented Apr 9, 2018

I got it working again (but the solution is really dirty):
Go to node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs/browser.js and change

node: false

to

node: {
    process: true
},

I also filed mqttjs/MQTT.js#804.
Otherwise i don't know what else to do.

@sclausen
Copy link
Owner

Oh that's sad. I'm really amazed by your PR. Let's hope someone on mqtt.js is answering soon and this issue can be solved in a smart way.

@sclausen
Copy link
Owner

Many many thanks for your great effort! @chrste90! This PR is now in large parts superseded.

@sclausen sclausen closed this Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants