From dedc2b9d5dffe034e49339921eb635b437202422 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sun, 1 Apr 2018 13:18:24 -0700 Subject: [PATCH 1/2] Throw error if source and compiled dirs are the same --- lib/build.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/build.js b/lib/build.js index f1130872..bc7266d4 100644 --- a/lib/build.js +++ b/lib/build.js @@ -22,6 +22,14 @@ function webpackConfig(dir, additionalConfig) { ]; } + var functionsDir = config.build.functions || config.build.Functions; + var functionsPath = path.join(process.cwd(), functionsDir); + var dirPath = path.join(process.cwd(), dir); + + if (dirPath === functionsPath) { + throw new Error("Function source directory and compiled directory are the same"); + } + var webpackConfig = { module: { rules: [ @@ -35,21 +43,18 @@ function webpackConfig(dir, additionalConfig) { } ] }, - context: path.join(process.cwd(), dir), + context: dirPath, entry: {}, target: "node", plugins: [new webpack.IgnorePlugin(/vertx/)], output: { - path: path.join( - process.cwd(), - config.build.functions || config.build.Functions - ), + path: functionsPath, filename: "[name].js", libraryTarget: "commonjs" }, devtool: false }; - fs.readdirSync(path.join(process.cwd(), dir)).forEach(function(file) { + fs.readdirSync(dirPath).forEach(function(file) { if (file.match(/\.js$/)) { var name = file.replace(/\.js$/, ""); webpackConfig.entry[name] = "./" + name; From 711b1da07968fa36ef7ef9b037cef45f1cf57896 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sun, 1 Apr 2018 13:26:58 -0700 Subject: [PATCH 2/2] Update wording --- lib/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/build.js b/lib/build.js index bc7266d4..6439179c 100644 --- a/lib/build.js +++ b/lib/build.js @@ -27,7 +27,7 @@ function webpackConfig(dir, additionalConfig) { var dirPath = path.join(process.cwd(), dir); if (dirPath === functionsPath) { - throw new Error("Function source directory and compiled directory are the same"); + throw new Error("Function source and publish folder should be in different locations"); } var webpackConfig = {