diff --git a/package-lock.json b/package-lock.json index 120851dc..6e8c4333 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7521,13 +7521,9 @@ } }, "path-type": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", - "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", - "dev": true, - "requires": { - "pify": "^2.0.0" - } + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==" }, "picomatch": { "version": "2.2.2", @@ -7869,6 +7865,17 @@ "load-json-file": "^2.0.0", "normalize-package-data": "^2.3.2", "path-type": "^2.0.0" + }, + "dependencies": { + "path-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "integrity": "sha1-8BLMuEFbcJb8LaoQVMPXI4lZTHM=", + "dev": true, + "requires": { + "pify": "^2.0.0" + } + } } }, "read-pkg-up": { diff --git a/package.json b/package.json index 5cd88e20..bc86e714 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@types/node": "^14.0.27", "make-dir": "^3.1.0", "node-fetch": "^2.6.1", + "path-type": "^4.0.0", "rollup": "^2.23.1", "typescript": "^3.9.7" }, diff --git a/src/index.js b/src/index.js index 2c0cae30..2c83f5a5 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ const commonjs = require("@rollup/plugin-commonjs"); const json = require("@rollup/plugin-json"); const nodeResolve = require("@rollup/plugin-node-resolve"); const makeDir = require("make-dir"); +const { isDirectory } = require("path-type"); const rollup = require("rollup"); const babel = nodeBabel.babel; @@ -165,6 +166,10 @@ function serializeHandler(handler) { module.exports = { onPostBuild: async ({ constants: { IS_LOCAL, NETLIFY_API_TOKEN, EDGE_HANDLERS_SRC }, utils }) => { + if (!(await isDirectory(EDGE_HANDLERS_SRC))) { + return utils.build.failBuild(`Edge handlers directory does not exist: ${EDGE_HANDLERS_SRC}`); + } + const { mainFile, handlers } = await assemble(EDGE_HANDLERS_SRC); if (handlers.length === 0) { diff --git a/test/fixtures/wrong-config-dir/netlify.toml b/test/fixtures/wrong-config-dir/netlify.toml new file mode 100644 index 00000000..1a846b25 --- /dev/null +++ b/test/fixtures/wrong-config-dir/netlify.toml @@ -0,0 +1,5 @@ +[build] +edge_handlers = "does-not-exist" + +[[plugins]] +package = "../../.." diff --git a/test/main.js b/test/main.js index 9e956122..6837d8c2 100644 --- a/test/main.js +++ b/test/main.js @@ -7,6 +7,7 @@ const { runNetlifyBuild } = require("./helpers/run"); const INTEGRATION_TEST_DIR = `${__dirname}/../integration-test`; const FIXTURES_DIR = `${__dirname}/fixtures`; const CONFIG_FIXTURE_DIR = `${FIXTURES_DIR}/config-dir`; +const WRONG_CONFIG_FIXTURE_DIR = `${FIXTURES_DIR}/wrong-config-dir`; test("Edge handlers should be bundled", async (t) => { await runNetlifyBuild(t, INTEGRATION_TEST_DIR); @@ -29,3 +30,8 @@ test("Edge handlers directory can be configured using build.edge_handlers", asyn const { manifest } = loadBundle(t, CONFIG_FIXTURE_DIR); t.deepEqual(manifest.handlers, ["example"]); }); + +test("Edge handlers directory build.edge_handlers misconfiguration is reported", async (t) => { + const { output } = await runNetlifyBuild(t, WRONG_CONFIG_FIXTURE_DIR, { expectedSuccess: false }); + t.true(output.includes("does-not-exist")); +});