From 1b59b273296cb6dfeebdd1008430eacd1096fe92 Mon Sep 17 00:00:00 2001 From: 0x0a0d Date: Sun, 5 Mar 2023 03:39:45 +0700 Subject: [PATCH 1/6] chore(runner): sync code between cjs and esm --- src/runner-esm.mjs | 8 ++++++-- src/runner.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runner-esm.mjs b/src/runner-esm.mjs index 45ba76e11..e9409dba7 100644 --- a/src/runner-esm.mjs +++ b/src/runner-esm.mjs @@ -406,7 +406,9 @@ export default class MoleculerRunner { return this.broker.logger.warn( kleur .yellow() - .bold(`There is no service files in directory: '${svcPath}'`) + .bold( + `There is no service files in directory: '${svcPath}'` + ) ); } else if (this.isServiceFile(svcPath)) { files = [svcPath.replace(/\\/g, "/")]; @@ -417,7 +419,9 @@ export default class MoleculerRunner { files = glob.sync(p, { cwd: svcDir, absolute: true }); if (files.length == 0) this.broker.logger.warn( - kleur.yellow().bold(`There is no matched file for pattern: '${p}'`) + kleur + .yellow() + .bold(`There is no matched file for pattern: '${p}'`) ); } diff --git a/src/runner.js b/src/runner.js index 27513b3c5..c288d2665 100644 --- a/src/runner.js +++ b/src/runner.js @@ -9,7 +9,7 @@ const ServiceBroker = require("./service-broker"); const utils = require("./utils"); const fs = require("fs"); const path = require("path"); -const glob = require("glob").sync; +const glob = require("glob"); const _ = require("lodash"); const Args = require("args"); const os = require("os"); @@ -403,7 +403,7 @@ class MoleculerRunner { if (this.config.hotReload) { this.watchFolders.push(svcPath); } - files = glob(svcPath + "/" + fileMask, { absolute: true }); + files = glob.sync(svcPath + "/" + fileMask, { absolute: true }); if (files.length == 0) return this.broker.logger.warn( kleur From 3c60ea56024758e12f3e46953dd3cbfd523d1024 Mon Sep 17 00:00:00 2001 From: 0x0a0d Date: Sun, 5 Mar 2023 03:48:22 +0700 Subject: [PATCH 2/6] feat(runner): allow load multiple .env files with --envfile using glob patterns --- src/runner-esm.mjs | 15 ++++++++++++--- src/runner.js | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/runner-esm.mjs b/src/runner-esm.mjs index e9409dba7..c7cccd844 100644 --- a/src/runner-esm.mjs +++ b/src/runner-esm.mjs @@ -69,7 +69,7 @@ export default class MoleculerRunner { * Available options: -c, --config Load the configuration from a file -e, --env Load .env file from the current directory - -E, --envfile Load a specified .env file + -E, --envfile Load specified .env files using glob patterns that are separated by commas. For example, '-E .env,.env.dev.*' loads the .env file and all .env.dev.* files. -h, --help Output usage information -H, --hot Hot reload services if changed (disabled by default) -i, --instances Launch [number] instances node (load balanced) @@ -116,8 +116,17 @@ export default class MoleculerRunner { try { const dotenv = await import("dotenv"); - if (this.flags.envfile) dotenv.config({ path: this.flags.envfile }); - else dotenv.config(); + if (this.flags.envfile) { + this.flags.envfile.split(",").forEach(envFile => { + glob.sync(path.join(process.cwd(), envFile), { absolute: true }).forEach( + envFile => { + dotenv.config({ path: envFile }); + } + ); + }); + } else { + dotenv.config(); + } } catch (err) { throw new Error( "The 'dotenv' package is missing! Please install it with 'npm install dotenv --save' command." diff --git a/src/runner.js b/src/runner.js index c288d2665..acd8e38da 100644 --- a/src/runner.js +++ b/src/runner.js @@ -66,7 +66,7 @@ class MoleculerRunner { * Available options: -c, --config Load the configuration from a file -e, --env Load .env file from the current directory - -E, --envfile Load a specified .env file + -E, --envfile Load specified .env files using glob patterns that are separated by commas. For example, '-E .env,.env.dev.*' loads the .env file and all .env.dev.* files. -h, --help Output usage information -H, --hot Hot reload services if changed (disabled by default) -i, --instances Launch [number] instances node (load balanced) @@ -113,8 +113,17 @@ class MoleculerRunner { try { const dotenv = require("dotenv"); - if (this.flags.envfile) dotenv.config({ path: this.flags.envfile }); - else dotenv.config(); + if (this.flags.envfile) { + this.flags.envfile.split(",").forEach(envFile => { + glob.sync(path.join(process.cwd(), envFile), { absolute: true }).forEach( + envFile => { + dotenv.config({ path: envFile }); + } + ); + }); + } else { + dotenv.config(); + } } catch (err) { throw new Error( "The 'dotenv' package is missing! Please install it with 'npm install dotenv --save' command." From 62a8a27d61168eb1bd2cd75c4f18864c1a5781c7 Mon Sep 17 00:00:00 2001 From: 0x0a0d Date: Mon, 30 Jan 2023 11:43:27 +0700 Subject: [PATCH 3/6] replace == by === --- src/runner-esm.mjs | 8 ++++---- src/runner.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/runner-esm.mjs b/src/runner-esm.mjs index c7cccd844..9a34ead13 100644 --- a/src/runner-esm.mjs +++ b/src/runner-esm.mjs @@ -270,7 +270,7 @@ export default class MoleculerRunner { level .split("_") .map((value, index) => { - if (index == 0) { + if (index === 0) { return value; } else { return value[0].toUpperCase() + value.substring(1); @@ -400,7 +400,7 @@ export default class MoleculerRunner { patterns .map(s => s.trim()) .forEach(p => { - const skipping = p[0] == "!"; + const skipping = p[0] === "!"; if (skipping) p = p.slice(1); let files; @@ -411,7 +411,7 @@ export default class MoleculerRunner { this.watchFolders.push(svcPath); } files = glob.sync(svcPath + "/" + fileMask, { absolute: true }); - if (files.length == 0) + if (files.length === 0) return this.broker.logger.warn( kleur .yellow() @@ -426,7 +426,7 @@ export default class MoleculerRunner { } else { // Load with glob files = glob.sync(p, { cwd: svcDir, absolute: true }); - if (files.length == 0) + if (files.length === 0) this.broker.logger.warn( kleur .yellow() diff --git a/src/runner.js b/src/runner.js index acd8e38da..79d7a7c34 100644 --- a/src/runner.js +++ b/src/runner.js @@ -268,7 +268,7 @@ class MoleculerRunner { level .split("_") .map((value, index) => { - if (index == 0) { + if (index === 0) { return value; } else { return value[0].toUpperCase() + value.substring(1); @@ -398,7 +398,7 @@ class MoleculerRunner { patterns .map(s => s.trim()) .forEach(p => { - const skipping = p[0] == "!"; + const skipping = p[0] === "!"; if (skipping) p = p.slice(1); if (p.startsWith("npm:")) { @@ -413,7 +413,7 @@ class MoleculerRunner { this.watchFolders.push(svcPath); } files = glob.sync(svcPath + "/" + fileMask, { absolute: true }); - if (files.length == 0) + if (files.length === 0) return this.broker.logger.warn( kleur .yellow() @@ -428,7 +428,7 @@ class MoleculerRunner { } else { // Load with glob files = glob(p, { cwd: svcDir, absolute: true }); - if (files.length == 0) + if (files.length === 0) this.broker.logger.warn( kleur .yellow() From b1f1dd0417216295f1e99113271dc0f2273f3820 Mon Sep 17 00:00:00 2001 From: 0x0a0d Date: Sun, 5 Mar 2023 04:32:36 +0700 Subject: [PATCH 4/6] prettier/prettier --- src/runner-esm.mjs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/runner-esm.mjs b/src/runner-esm.mjs index 9a34ead13..71d81222d 100644 --- a/src/runner-esm.mjs +++ b/src/runner-esm.mjs @@ -415,9 +415,7 @@ export default class MoleculerRunner { return this.broker.logger.warn( kleur .yellow() - .bold( - `There is no service files in directory: '${svcPath}'` - ) + .bold(`There is no service files in directory: '${svcPath}'`) ); } else if (this.isServiceFile(svcPath)) { files = [svcPath.replace(/\\/g, "/")]; @@ -428,9 +426,7 @@ export default class MoleculerRunner { files = glob.sync(p, { cwd: svcDir, absolute: true }); if (files.length === 0) this.broker.logger.warn( - kleur - .yellow() - .bold(`There is no matched file for pattern: '${p}'`) + kleur.yellow().bold(`There is no matched file for pattern: '${p}'`) ); } From 544af4028f55b8ed1a0f8433c448405934bff1c9 Mon Sep 17 00:00:00 2001 From: 0x0a0d Date: Sun, 5 Mar 2023 05:07:01 +0700 Subject: [PATCH 5/6] chore(runner): more detail how to use envfile new option --- src/runner-esm.mjs | 7 +++++-- src/runner.js | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/runner-esm.mjs b/src/runner-esm.mjs index 71d81222d..bb7f3623d 100644 --- a/src/runner-esm.mjs +++ b/src/runner-esm.mjs @@ -69,7 +69,7 @@ export default class MoleculerRunner { * Available options: -c, --config Load the configuration from a file -e, --env Load .env file from the current directory - -E, --envfile Load specified .env files using glob patterns that are separated by commas. For example, '-E .env,.env.dev.*' loads the .env file and all .env.dev.* files. + -E, --envfile Load specified .env files using glob patterns that are separated by commas. Example "-E '.env.dev.\*'": loads the all .env.dev.* files. -h, --help Output usage information -H, --hot Hot reload services if changed (disabled by default) -i, --instances Launch [number] instances node (load balanced) @@ -84,7 +84,10 @@ export default class MoleculerRunner { .option(["H", "hot"], "Hot reload services if changed", false) .option("silent", "Silent mode. No logger", false) .option("env", "Load .env file from the current directory") - .option("envfile", "Load a specified .env file") + .option( + "envfile", + "Load specified .env files using glob patterns that are separated by commas. Example \"-E '.env.dev.*'\": loads the all .env.dev.* files." + ) .option("instances", "Launch [number] instances node (load balanced)") .option("mask", "Filemask for service loading"); diff --git a/src/runner.js b/src/runner.js index 79d7a7c34..bd3ebf400 100644 --- a/src/runner.js +++ b/src/runner.js @@ -66,7 +66,7 @@ class MoleculerRunner { * Available options: -c, --config Load the configuration from a file -e, --env Load .env file from the current directory - -E, --envfile Load specified .env files using glob patterns that are separated by commas. For example, '-E .env,.env.dev.*' loads the .env file and all .env.dev.* files. + -E, --envfile Load specified .env files using glob patterns that are separated by commas. Example "-E '.env.dev.\*'": loads the all .env.dev.* files. -h, --help Output usage information -H, --hot Hot reload services if changed (disabled by default) -i, --instances Launch [number] instances node (load balanced) @@ -81,7 +81,10 @@ class MoleculerRunner { .option(["H", "hot"], "Hot reload services if changed", false) .option("silent", "Silent mode. No logger", false) .option("env", "Load .env file from the current directory") - .option("envfile", "Load a specified .env file") + .option( + "envfile", + "Load specified .env files using glob patterns that are separated by commas. Example \"-E '.env.dev.*'\": loads the all .env.dev.* files." + ) .option("instances", "Launch [number] instances node (load balanced)") .option("mask", "Filemask for service loading"); From 423569c5cc445504c9f0aac540b0e743f636795e Mon Sep 17 00:00:00 2001 From: 0x0a0d Date: Mon, 6 Mar 2023 10:04:37 +0700 Subject: [PATCH 6/6] fix(runner): missing .sync --- src/runner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner.js b/src/runner.js index bd3ebf400..297410051 100644 --- a/src/runner.js +++ b/src/runner.js @@ -430,7 +430,7 @@ class MoleculerRunner { files = [svcPath.replace(/\\/g, "/") + ".service.js"]; } else { // Load with glob - files = glob(p, { cwd: svcDir, absolute: true }); + files = glob.sync(p, { cwd: svcDir, absolute: true }); if (files.length === 0) this.broker.logger.warn( kleur