Repository: mozilla/nunjucks (js)

Issue:
npm warning about postinstall-build deprecation
> warning @11ty/eleventy > nunjucks > postinstall-build@5.0.3: postinstall-build's behavior is now built into npm! You should migrate off of postinstall-build and use the new `prepare` lifecycle script with npm 5.0.0 or greater.

As reported in https://github.com/11ty/eleventy/issues/311 by @AmeliaBR and clarified by @jevets.

Pull request:
Removed postinstall-build in favor of npm prepare script
## Summary

Proposed change:

[postinstall-build is now deprecated](https://github.com/exogen/postinstall-build) because of [npm@4 `prepare` lifecycle script](https://docs.npmjs.com/misc/scripts).

This will break for people using nunjucks as a git dependency with npm < 4. As node 6 end-of-life is coming close, less people will be using npm@3.x. This will help with the third Purpose item:

> * Works in all node releases that are
  [actively maintained by the Node Foundation](https://github.com/nodejs/Release#release-schedule)

Also, npm@5 is the actual LTS version, so npm@3 and npm@4 should be considered deprecated.

Closes #1167.


## Checklist

I've completed the checklist below to ensure I didn't forget anything. This makes reviewing this PR as easy as possible for the maintainers. And it gets this change released as soon as possible.

* [x] Proposed change helps towards [*purpose of this project*](https://github.com/mozilla/nunjucks/blob/master/CONTRIBUTING.md#purpose).
* [ ] [*Documentation*](https://github.com/mozilla/nunjucks/tree/master/docs/) is added / updated to describe proposed change.
* [ ] [*Tests*](https://github.com/mozilla/nunjucks/tree/master/tests) are added / updated to cover proposed change.
* [x] [*Changelog*](https://github.com/mozilla/nunjucks/blob/master/CHANGELOG.md) has an entry for proposed change (if user-facing fix or feature).

<!-- Tick of items by replacing `[ ]` by `[x]` -->

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 169e41f..9c065bf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,21 @@
 Changelog
 =========
 
+3.1.6 (unreleased)
+------------------
+
+* Fix bug where exceptions were silently swallowed with synchronous render.
+  Fixes [#678](https://github.com/mozilla/nunjucks/issues/678),
+  [#1116](https://github.com/mozilla/nunjucks/issues/1116),
+  [#1127](https://github.com/mozilla/nunjucks/issues/1127), and
+  [#1164](https://github.com/mozilla/nunjucks/issues/1164)
+
+3.1.5 (Dec 13 2018)
+-------------------
+
+* Fix engine dependency version for Node versions > 11.1.0;
+  Fixes [#1168](https://github.com/mozilla/nunjucks/issues/1168).
+
 3.1.4 (Nov 9 2018)
 ------------------
 
diff --git a/docs/templating.md b/docs/templating.md
index bdbc212..32c7efe 100644
--- a/docs/templating.md
+++ b/docs/templating.md
@@ -43,6 +43,7 @@ Plugins are available in various editors to support the `jinja` syntax highlight
 * brackets <https://github.com/axelboc/nunjucks-brackets>
 * sublime <https://github.com/mogga/sublime-nunjucks/blob/master/Nunjucks.tmLanguage>
 * emacs <http://web-mode.org>
+* vscode <https://github.com/ronnidc/vscode-nunjucks>
 
 ## Variables
 
diff --git a/nunjucks/src/environment.js b/nunjucks/src/environment.js
index e7fd163..bb1c3b9 100644
--- a/nunjucks/src/environment.js
+++ b/nunjucks/src/environment.js
@@ -468,7 +468,11 @@ class Template extends Obj {
     this.rootRenderFunc(this.env, context, frame, globalRuntime, (err, res) => {
       if (didError) {
         // prevent multiple calls to cb
-        return;
+        if (cb) {
+          return;
+        } else {
+          throw err;
+        }
       }
       if (err) {
         err = lib._prettifyError(this.path, this.env.opts.dev, err);
diff --git a/package.json b/package.json
index 3b7e0f2..6378dcf 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,11 @@
 {
   "name": "nunjucks",
   "description": "A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)",
-  "version": "3.1.4",
+  "version": "3.1.6",
   "author": "James Long <longster@gmail.com>",
   "dependencies": {
     "a-sync-waterfall": "^1.0.0",
     "asap": "^2.0.3",
-    "postinstall-build": "^5.0.1",
     "yargs": "^3.32.0"
   },
   "browser": "./browser/nunjucks.js",
@@ -63,7 +62,7 @@
     "babel-register": "@babel/register"
   },
   "engines": {
-    "node": ">= 6.9.0 <= 11.1.0"
+    "node": ">= 6.9.0"
   },
   "scripts": {
     "build:transpile": "babel nunjucks --out-dir .",
@@ -72,7 +71,7 @@
     "codecov": "codecov",
     "mocha": "mocha -R spec tests",
     "lint": "eslint nunjucks scripts tests",
-    "postinstall": "node postinstall-build.js src",
+    "prepare": "npm run build",
     "test:instrument": "cross-env NODE_ENV=test scripts/bundle.js",
     "test:runner": "cross-env NODE_ENV=test scripts/testrunner.js",
     "test": "npm run lint && npm run test:instrument && npm run test:runner"
diff --git a/postinstall-build.js b/postinstall-build.js
deleted file mode 100755
index 010954f..0000000
--- a/postinstall-build.js
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/env node
-require('postinstall-build/index')();
-


Test patch:
diff --git a/tests/compiler.js b/tests/compiler.js
index d6b590d..a282ecc 100644
--- a/tests/compiler.js
+++ b/tests/compiler.js
@@ -795,6 +795,14 @@
     });
 
     if (!isSlim) {
+      it('should throw exceptions when called synchronously', function() {
+        var tmpl = new Template('{% from "doesnotexist" import foo %}');
+        function templateRender() {
+          tmpl.render();
+        }
+        expect(templateRender).to.throwException(/template not found: doesnotexist/);
+      });
+
       it('should include error line in raised TemplateError', function(done) {
         var tmplStr = [
           '{% set items = ["a", "b",, "c"] %}',
diff --git a/tests/core.js b/tests/core.js
index 948f589..56c2406 100644
--- a/tests/core.js
+++ b/tests/core.js
@@ -20,7 +20,7 @@
 
   function rmdir(dirPath) {
     fs.emptyDirSync(dirPath);
-    fs.rmdir(dirPath);
+    fs.rmdirSync(dirPath);
   }
 
   describe('nunjucks.configure', function() {