Skip to content
This repository was archived by the owner on May 2, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/wrong-config-dir/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
edge_handlers = "does-not-exist"

[[plugins]]
package = "../../.."
6 changes: 6 additions & 0 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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"));
});