Description
Problem: After mean init <project>
completes, <project>/package.json
is malformed. Exact problems with the file vary, but tend to be the last few characters of the file repeated. For example:
$ tail project/package.json
"gulp-rimraf": "^0.1.1",
"gulp-uglify": "^1.0.1",
"gulp-util": "^3.0.1",
"jshint-stylish": "^1.0.0",
"through": "^2.3.6"
}
}
6"
}
}
I suspect a race condition, I don't have a patch yet, but here are some of my findings so far:
https://github.com/linnovate/mean-cli/blob/master/lib/cli.js#L920
jsonFile() on that line returns a promise, so execution continues down to this write:
https://github.com/linnovate/mean-cli/blob/master/lib/cli.js#L953
In fact, if I sprinkle some console.log calls in there, the write on line 953 executes before the one on line 927. This confirms the race theory.
For reference, this is the relevant jsonFile() source (pkg json-file-plus):
https://github.com/ljharb/node-json-file/blob/master/index.js#L46