From d468ae0540b92236b39699fee331a2c75e8fe1fe Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Tue, 18 Apr 2017 18:27:42 -0700 Subject: [PATCH 1/5] Added ignoremodule support --- README.md | 12 ++++++++++++ package.json | 32 ++++++++++++++++---------------- sample/excluded/function.json | 17 +++++++++++++++++ sample/excluded/index.js | 11 +++++++++++ sample/funcpack.config.json | 5 +++++ src/main.ts | 7 ++++++- src/utils/config-loader.ts | 18 ++++++++++++++++++ src/utils/index.ts | 1 + src/webpack-runner.ts | 9 +++++++++ test/runTests.ps1 | 1 + 10 files changed, 96 insertions(+), 17 deletions(-) create mode 100644 sample/excluded/function.json create mode 100644 sample/excluded/index.js create mode 100644 sample/funcpack.config.json create mode 100644 src/utils/config-loader.ts diff --git a/README.md b/README.md index 725f810..2a6884e 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,18 @@ Usage: pack [options] -o, --output Path for output directory ``` +### funcpack.config.json + +Pack will optionally take in a config file that will let you further customize the behavior. The config file must be in the directory you run the command from and named `funcpack.config.json`. + +Here are all the supported options: + +``` +{ + "ignoredModules":["chai"] +} +``` + ## License [MIT](LICENSE) diff --git a/package.json b/package.json index 902aa87..364bf83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azure-functions-pack", - "version": "0.1.2", + "version": "0.2.0", "description": "azure-functions-pack", "license": "MIT", "repository": "https://github.com/christopheranderson/azure-functions-pack", @@ -26,28 +26,28 @@ "e2etst": "npm run " }, "dependencies": { - "commander": "^2.9.0", - "debug": "^2.6.1", - "rimraf": "^2.5.4", + "commander": "~2.9.0", + "debug": "~2.6.1", + "rimraf": "~2.5.4", "webpack": "fulls1z3/webpack#v2.2.1-harmony", - "winston": "^2.3.1" + "winston": "~2.3.1" }, "devDependencies": { - "@types/chai": "^3.0.0", - "@types/commander": "^2.3.31", + "@types/chai": "3.5.0", + "@types/commander": "~2.3.31", "@types/debug": "0.0.29", - "@types/mocha": "^2.0.0", + "@types/mocha": "2.2.41", "@types/node": "6.0.31", "@types/rimraf": "0.0.28", - "@types/webpack": "^2.2.5", - "@types/winston": "^2.2.0", - "chai": "^3.0.0", - "mocha": "^3.0.0", - "ts-node": "^1.0.0", - "tslint": "^4.0.0", - "typescript": "^2.0.0" + "@types/webpack": "~2.2.5", + "@types/winston": "~2.2.0", + "chai": "~3.5.0", + "mocha": "~3.0.0", + "ts-node": "~1.0.0", + "tslint": "~4.0.0", + "typescript": "~2.2.0" }, "engines": { - "node": ">=4.0.0" + "node": ">=6.5.0" } } diff --git a/sample/excluded/function.json b/sample/excluded/function.json new file mode 100644 index 0000000..6807e61 --- /dev/null +++ b/sample/excluded/function.json @@ -0,0 +1,17 @@ +{ + "disabled": false, + "bindings": [ + { + "authLevel": "function", + "type": "httpTrigger", + "direction": "in", + "name": "req" + }, + { + "type": "http", + "direction": "out", + "name": "$return" + } + ], + "scriptFile": "index.js" +} \ No newline at end of file diff --git a/sample/excluded/index.js b/sample/excluded/index.js new file mode 100644 index 0000000..52b41d5 --- /dev/null +++ b/sample/excluded/index.js @@ -0,0 +1,11 @@ +const chai = require('chai'); + +module.exports = function (context, req) { + context.log('"simple" function called'); + const res = { + body: { + "success":true + } + } + context.done(null, res); +}; \ No newline at end of file diff --git a/sample/funcpack.config.json b/sample/funcpack.config.json new file mode 100644 index 0000000..aa3ae48 --- /dev/null +++ b/sample/funcpack.config.json @@ -0,0 +1,5 @@ +{ + "ignoredModules":[ + "chai" + ] +} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 5285a78..2e1fab4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,10 +4,11 @@ import * as program from "commander"; import * as path from "path"; import * as winston from "winston"; import { PackhostGenerator, Unpacker, WebpackRunner } from "./"; +import { ConfigLoader, IFuncpackConfig } from "./utils"; async function runCli() { const p = program - .version("0.1.2") + .version("0.2.0") .option("-d, --debug", "Emits debug messages"); p.command("unpack ") @@ -66,6 +67,9 @@ async function unpack(name: string, options: any) { } async function pack(name: string, options: any) { + // TBD - allow loadConfig to get a filename from options + const config: IFuncpackConfig = await ConfigLoader.loadConfig(); + if (options.debug) { process.env.DEBUG = "*"; } @@ -121,6 +125,7 @@ async function pack(name: string, options: any) { projectRootPath, uglify, outputPath, + ignoredModules: config.ignoredModules, }); } catch (error) { winston.error(error); diff --git a/src/utils/config-loader.ts b/src/utils/config-loader.ts new file mode 100644 index 0000000..972c270 --- /dev/null +++ b/src/utils/config-loader.ts @@ -0,0 +1,18 @@ +import { + FileHelper, +} from "./index"; + +import * as path from "path"; + +export class ConfigLoader { + public static async loadConfig(filename?: string): Promise { + const pathToFile = path.join(process.cwd(), (filename || "funcpack.config.json")); + if (await FileHelper.exists(pathToFile)) { + return await FileHelper.readFileAsJSON(pathToFile); + } + } +} + +export interface IFuncpackConfig { + ignoredModules?: string[]; +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 8f784ee..da47516 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1 +1,2 @@ export * from "./fs-helper"; +export * from "./config-loader"; \ No newline at end of file diff --git a/src/webpack-runner.ts b/src/webpack-runner.ts index 86970fe..dc7de4f 100644 --- a/src/webpack-runner.ts +++ b/src/webpack-runner.ts @@ -11,6 +11,7 @@ export interface IWebpackRunner { indexFileName?: string; outputPath?: string; uglify?: boolean; + ignoredModules?: string[]; } export class WebpackRunner { @@ -18,6 +19,7 @@ export class WebpackRunner { options.indexFileName = options.indexFileName || "index.js"; options.outputPath = options.outputPath || ".funcpack"; options.uglify = options.uglify || false; + options.ignoredModules = options.ignoredModules || []; return new Promise(async (resolve, reject) => { debug("Setting up paths"); @@ -27,9 +29,16 @@ export class WebpackRunner { const outputPath = path.join(options.projectRootPath, options.outputPath, "output.js"); + const ignoredModules: { [key: string]: string } = {}; + + for (const mod of options.ignoredModules) { + ignoredModules[mod.toLowerCase()] = mod; + } + debug("Creating Webpack Configuration"); const config: webpack.Configuration = { entry: oldPath, + externals: ignoredModules, node: { __dirname: false, __filename: false, diff --git a/test/runTests.ps1 b/test/runTests.ps1 index 42c6a8f..739ba5c 100644 --- a/test/runTests.ps1 +++ b/test/runTests.ps1 @@ -8,6 +8,7 @@ testOk $testName 'simple' testOk $testName 'entryPoint' + testOk $testName 'excluded' testOk $testName 'externalScriptFile' testOk $testName 'fs-ignoremeScriptFile' testOk $testName 'cs-ignoreme' From b9fce71993ec86404855173c3dfe54473940a961 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Tue, 18 Apr 2017 18:33:33 -0700 Subject: [PATCH 2/5] Rolling package version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 364bf83..1a03532 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azure-functions-pack", - "version": "0.2.0", + "version": "0.2.1", "description": "azure-functions-pack", "license": "MIT", "repository": "https://github.com/christopheranderson/azure-functions-pack", From 0f15e95c2743cabb4d69840a1b043f72dfaf4935 Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Wed, 19 Apr 2017 09:47:35 -0700 Subject: [PATCH 3/5] Fix issue where config file must exist --- package.json | 2 +- src/main.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1a03532..61463c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azure-functions-pack", - "version": "0.2.1", + "version": "0.2.2", "description": "azure-functions-pack", "license": "MIT", "repository": "https://github.com/christopheranderson/azure-functions-pack", diff --git a/src/main.ts b/src/main.ts index 2e1fab4..4de1fc1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ import { ConfigLoader, IFuncpackConfig } from "./utils"; async function runCli() { const p = program - .version("0.2.0") + .version("0.2.2") .option("-d, --debug", "Emits debug messages"); p.command("unpack ") @@ -68,7 +68,11 @@ async function unpack(name: string, options: any) { async function pack(name: string, options: any) { // TBD - allow loadConfig to get a filename from options - const config: IFuncpackConfig = await ConfigLoader.loadConfig(); + let config: IFuncpackConfig = await ConfigLoader.loadConfig(); + + config = config || { + ignoredModules: [], + }; if (options.debug) { process.env.DEBUG = "*"; From 111961c53e4c5f96d17de4482cb9790a58d4013b Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Wed, 19 Apr 2017 09:49:14 -0700 Subject: [PATCH 4/5] Update tests for ignored modules --- sample/excluded/index.js | 4 +++- sample/package.json | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/sample/excluded/index.js b/sample/excluded/index.js index 52b41d5..406e312 100644 --- a/sample/excluded/index.js +++ b/sample/excluded/index.js @@ -1,4 +1,6 @@ -const chai = require('chai'); +if(false) { // never called + require('chai'); +} module.exports = function (context, req) { context.log('"simple" function called'); diff --git a/sample/package.json b/sample/package.json index e56245c..6bc04b6 100644 --- a/sample/package.json +++ b/sample/package.json @@ -12,5 +12,8 @@ "azure": "^1.2.0-preview", "lodash": "^4.17.4", "tedious": "^1.14.0" + }, + "devDependencies": { + "chai":"3.5.0" } } From a3f016cc87b9ddea88226b55aed9b81863c17c9f Mon Sep 17 00:00:00 2001 From: Christopher Anderson Date: Wed, 28 Jun 2017 18:15:01 -0700 Subject: [PATCH 5/5] Update gitignore to exclude lib and test results --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 3cd27af..405725d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ coverage/ node_modules/ npm-debug.log + +lib + +**/*.csv \ No newline at end of file