@architect/inventory 3.0.0-RC.3 → 3.0.0-RC.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md CHANGED
@@ -40,6 +40,8 @@
40
40
  - Improved memory footprint of Inventory object by preserving references in `lambdaSrcDirs`, `lambdasBySrcDir`
41
41
  - Added `pragma` property to all Lambdas to aid in reference preservation
42
42
  - Tidy up order of enumerated properties in each Lambda
43
+ Update CI
44
+ - Stop publishing to the GitHub Package registry
43
45
 
44
46
  ---
45
47
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@architect/inventory",
3
- "version": "3.0.0-RC.3",
3
+ "version": "3.0.0-RC.4",
4
4
  "description": "Architect project resource enumeration utility",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -29,15 +29,15 @@
29
29
  "devDependencies": {
30
30
  "@architect/eslint-config": "~2.0.1",
31
31
  "aws-sdk": "2.880.0",
32
- "aws-sdk-mock": "~5.5.0",
32
+ "aws-sdk-mock": "~5.6.0",
33
33
  "cross-env": "~7.0.3",
34
- "dotenv": "~12.0.3",
35
- "eslint": "~8.5.0",
34
+ "dotenv": "~14.3.2",
35
+ "eslint": "~8.7.0",
36
36
  "mock-fs": "~5.1.2",
37
37
  "mock-require": "~3.0.3",
38
38
  "nyc": "~15.1.0",
39
39
  "tap-spec": "^5.0.0",
40
- "tape": "^5.3.2"
40
+ "tape": "^5.4.1"
41
41
  },
42
42
  "eslintConfig": {
43
43
  "extends": "@architect/eslint-config"
@@ -11,7 +11,7 @@ module.exports = function setEnvPlugins (params, project) {
11
11
  envPlugins.forEach(fn => {
12
12
  let errType = `plugin: ${fn.plugin}, method: set.env`
13
13
  try {
14
- let result = fn({ inventory: inv })
14
+ let result = fn({ inventory: { inv } })
15
15
  if (!is.object(result) || !Object.keys(result).length) {
16
16
  return errors.push(`Env plugin returned invalid data, must return an Object with one or more keys + values: ${errType}`)
17
17
  }
@@ -15,7 +15,7 @@ module.exports = function setRuntimePlugins (params, project) {
15
15
  runtimePlugins.forEach(fn => {
16
16
  let errType = `plugin: ${fn.plugin}, method: set.runtimes`
17
17
  try {
18
- let result = fn({ inventory: inv })
18
+ let result = fn({ inventory: { inv } })
19
19
  result = is.array(result) ? result : [ result ]
20
20
  result.forEach(runtime => {
21
21
  // TODO add more validation
@@ -11,21 +11,38 @@ function log(message) {
11
11
  console.log(`[dotenv][DEBUG] ${message}`);
12
12
  }
13
13
  var NEWLINE = "\n";
14
- var RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*(.*)?\s*$/;
14
+ var RE_INI_KEY_VAL = /^\s*([\w.-]+)\s*=\s*("[^"]*"|'[^']*'|.*?)(\s+#.*)?$/;
15
15
  var RE_NEWLINES = /\\n/g;
16
16
  var NEWLINES_MATCH = /\r\n|\n|\r/;
17
17
  function parse(src, options) {
18
18
  const debug = Boolean(options && options.debug);
19
+ const multiline = Boolean(options && options.multiline);
19
20
  const obj = {};
20
- src.toString().split(NEWLINES_MATCH).forEach(function(line, idx) {
21
+ const lines = src.toString().split(NEWLINES_MATCH);
22
+ for (let idx = 0; idx < lines.length; idx++) {
23
+ let line = lines[idx];
21
24
  const keyValueArr = line.match(RE_INI_KEY_VAL);
22
25
  if (keyValueArr != null) {
23
26
  const key = keyValueArr[1];
24
27
  let val = keyValueArr[2] || "";
25
- const end = val.length - 1;
28
+ let end = val.length - 1;
26
29
  const isDoubleQuoted = val[0] === '"' && val[end] === '"';
27
30
  const isSingleQuoted = val[0] === "'" && val[end] === "'";
28
- if (isSingleQuoted || isDoubleQuoted) {
31
+ const isMultilineDoubleQuoted = val[0] === '"' && val[end] !== '"';
32
+ const isMultilineSingleQuoted = val[0] === "'" && val[end] !== "'";
33
+ if (multiline && (isMultilineDoubleQuoted || isMultilineSingleQuoted)) {
34
+ const quoteChar = isMultilineDoubleQuoted ? '"' : "'";
35
+ val = val.substring(1);
36
+ while (idx++ < lines.length - 1) {
37
+ line = lines[idx];
38
+ end = line.length - 1;
39
+ if (line[end] === quoteChar) {
40
+ val += NEWLINE + line.substring(0, end);
41
+ break;
42
+ }
43
+ val += NEWLINE + line;
44
+ }
45
+ } else if (isSingleQuoted || isDoubleQuoted) {
29
46
  val = val.substring(1, end);
30
47
  if (isDoubleQuoted) {
31
48
  val = val.replace(RE_NEWLINES, NEWLINE);
@@ -35,9 +52,12 @@ function parse(src, options) {
35
52
  }
36
53
  obj[key] = val;
37
54
  } else if (debug) {
38
- log(`did not match key and value when parsing line ${idx + 1}: ${line}`);
55
+ const trimmedLine = line.trim();
56
+ if (trimmedLine.length && trimmedLine[0] !== "#") {
57
+ log(`Failed to match key and value when parsing line ${idx + 1}: ${line}`);
58
+ }
39
59
  }
40
- });
60
+ }
41
61
  return obj;
42
62
  }
43
63
  function resolveHome(envPath) {
@@ -47,6 +67,8 @@ function config(options) {
47
67
  let dotenvPath = path.resolve(process.cwd(), ".env");
48
68
  let encoding = "utf8";
49
69
  const debug = Boolean(options && options.debug);
70
+ const override = Boolean(options && options.override);
71
+ const multiline = Boolean(options && options.multiline);
50
72
  if (options) {
51
73
  if (options.path != null) {
52
74
  dotenvPath = resolveHome(options.path);
@@ -56,18 +78,35 @@ function config(options) {
56
78
  }
57
79
  }
58
80
  try {
59
- const parsed = parse(fs.readFileSync(dotenvPath, { encoding }), { debug });
81
+ const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }), { debug, multiline });
60
82
  Object.keys(parsed).forEach(function(key) {
61
83
  if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
62
84
  process.env[key] = parsed[key];
63
- } else if (debug) {
64
- log(`"${key}" is already defined in \`process.env\` and will not be overwritten`);
85
+ } else {
86
+ if (override === true) {
87
+ process.env[key] = parsed[key];
88
+ }
89
+ if (debug) {
90
+ if (override === true) {
91
+ log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
92
+ } else {
93
+ log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
94
+ }
95
+ }
65
96
  }
66
97
  });
67
98
  return { parsed };
68
99
  } catch (e) {
100
+ if (debug) {
101
+ log(`Failed to load ${dotenvPath} ${e.message}`);
102
+ }
69
103
  return { error: e };
70
104
  }
71
105
  }
72
- module.exports.config = config;
73
- module.exports.parse = parse;
106
+ var DotenvModule = {
107
+ config,
108
+ parse
109
+ };
110
+ module.exports.config = DotenvModule.config;
111
+ module.exports.parse = DotenvModule.parse;
112
+ module.exports = DotenvModule;
@@ -2,12 +2,19 @@ let { is } = require('./../../../lib')
2
2
 
3
3
  module.exports = function validatePreferences (preferences, errors) {
4
4
  // Env checks
5
- let { env } = preferences
6
- if (!env) return
7
- if (env && !is.object(env)) errors.push(`Invalid preferences setting: @env ${env}`)
8
-
5
+ let { env, sandbox } = preferences
9
6
  let envs = [ 'testing', 'staging', 'production' ]
10
- envs.forEach(e => {
11
- if (env[e] && !is.object(env[e])) errors.push(`Invalid preferences setting: @env ${e}`)
12
- })
7
+
8
+ if (env && !is.object(env)) {
9
+ errors.push(`Invalid preferences setting: @env ${env}`)
10
+ }
11
+ else if (env) {
12
+ envs.forEach(e => {
13
+ if (env[e] && !is.object(env[e])) errors.push(`Invalid preferences setting: @env ${e}`)
14
+ })
15
+ }
16
+
17
+ if (sandbox?.env && !envs.includes(sandbox.env)) {
18
+ errors.push(`Invalid preferences setting: @sandbox env ${sandbox.env}`)
19
+ }
13
20
  }