@znemz/cfn-include 2.1.21 → 2.1.22

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/bin/cli.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const exec = require('child_process').execSync;
4
4
  const path = require('path');
5
5
  const _ = require('lodash');
6
- const pathParse = require('path-parse');
6
+ // path.parse is native in Node.js - no need for path-parse package
7
7
 
8
8
  const include = require('../index');
9
9
  const yaml = require('../lib/yaml');
@@ -118,7 +118,7 @@ if (opts.path) {
118
118
  let location;
119
119
  const protocol = opts.path.match(/^\w+:\/\//);
120
120
  if (protocol) location = opts.path;
121
- else if (pathParse(opts.path).root) location = `file://${opts.path}`;
121
+ else if (path.parse(opts.path).root) location = `file://${opts.path}`;
122
122
  else location = `file://${path.join(process.cwd(), opts.path)}`;
123
123
  promise = include({
124
124
  url: location,
package/index.js CHANGED
@@ -2,12 +2,11 @@ const url = require('url');
2
2
  const path = require('path');
3
3
  const _ = require('lodash');
4
4
  const { glob } = require('glob');
5
- const Promise = require('bluebird');
6
5
  const sortObject = require('@znemz/sort-object');
7
6
  const { S3Client, GetObjectCommand } = require('@aws-sdk/client-s3');
8
7
  const { addProxyToClient } = require('aws-sdk-v3-proxy');
9
8
 
10
- const pathParse = require('path-parse');
9
+ // path.parse is native in Node.js - no need for path-parse package
11
10
  const deepMerge = require('deepmerge');
12
11
  const { isTaggableResource } = require('@znemz/cft-utils/src/resources/taggable');
13
12
 
@@ -27,6 +26,7 @@ const { isOurExplicitFunction } = require('./lib/schema');
27
26
  const { getAwsPseudoParameters, buildResourceArn } = require('./lib/internals');
28
27
  const { cachedReadFile } = require('./lib/cache');
29
28
  const { createChildScope } = require('./lib/scope');
29
+ const { promiseProps } = require('./lib/promise-utils');
30
30
 
31
31
  /**
32
32
  * @param {object} options
@@ -585,7 +585,7 @@ async function recurse({ base, scope, cft, rootTemplate, caller, ...opts }) {
585
585
  });
586
586
  }
587
587
 
588
- return Promise.props(
588
+ return promiseProps(
589
589
  _.mapValues(cft, (template, key) => recurse({ base, scope, cft: template, key, rootTemplate, caller: 'recurse:isPlainObject:end', ...opts })),
590
590
  );
591
591
  }
@@ -743,7 +743,7 @@ async function fnInclude({ base, scope, cft, ...opts }) {
743
743
  body = cachedReadFile(absolute).then(procTemplate);
744
744
  absolute = `${location.protocol}://${absolute}`;
745
745
  } else if (location.protocol === 's3') {
746
- const basedir = pathParse(base.path).dir;
746
+ const basedir = path.parse(base.path).dir;
747
747
  const bucket = location.relative ? base.host : location.host;
748
748
 
749
749
  let key = location.relative ? url.resolve(`${basedir}/`, location.raw) : location.path;
@@ -759,7 +759,7 @@ async function fnInclude({ base, scope, cft, ...opts }) {
759
759
  .then((res) => res.Body.toString())
760
760
  .then(procTemplate);
761
761
  } else if (location.protocol && location.protocol.match(/^https?$/)) {
762
- const basepath = `${pathParse(base.path).dir}/`;
762
+ const basepath = `${path.parse(base.path).dir}/`;
763
763
 
764
764
  absolute = location.relative
765
765
  ? url.resolve(`${location.protocol}://${base.host}${basepath}`, location.raw)
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Native Promise utilities to replace bluebird.
3
+ * These are drop-in replacements for the bluebird methods we use.
4
+ */
5
+
6
+ /**
7
+ * Promise.props replacement - resolves an object of promises.
8
+ * @param {Object} obj - Object with promise values
9
+ * @returns {Promise<Object>} Object with resolved values
10
+ */
11
+ async function promiseProps(obj) {
12
+ const keys = Object.keys(obj);
13
+ const values = await Promise.all(keys.map((key) => obj[key]));
14
+ const result = {};
15
+ keys.forEach((key, i) => {
16
+ result[key] = values[i];
17
+ });
18
+ return result;
19
+ }
20
+
21
+ /**
22
+ * Promise.try replacement - wraps a function to catch sync errors.
23
+ * @param {Function} fn - Function to execute
24
+ * @returns {Promise} Promise that resolves to fn result or rejects on error
25
+ */
26
+ function promiseTry(fn) {
27
+ return new Promise((resolve, reject) => {
28
+ try {
29
+ resolve(fn());
30
+ } catch (err) {
31
+ reject(err);
32
+ }
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Promise.map replacement - maps over array with concurrency.
38
+ * @param {Array} arr - Array to map over
39
+ * @param {Function} fn - Async function to apply
40
+ * @returns {Promise<Array>} Array of resolved values
41
+ */
42
+ function promiseMap(arr, fn) {
43
+ return Promise.all(arr.map(fn));
44
+ }
45
+
46
+ module.exports = {
47
+ promiseProps,
48
+ promiseTry,
49
+ promiseMap,
50
+ };
package/lib/promise.js CHANGED
@@ -1,17 +1,17 @@
1
- const Promise = require('bluebird');
2
- const _ = require('lodash');
1
+ const { promiseTry, promiseMap } = require('./promise-utils');
3
2
 
4
3
  /*
5
4
  Maps over objects or iterables just like lodash.
6
5
  */
7
6
  const mapWhatever = (promises, cb) =>
8
- Promise.try(() =>
7
+ promiseTry(() =>
9
8
  Promise.resolve(promises).then((arrayOrObject) => {
10
- if (_.isArray(arrayOrObject)) {
11
- return Promise.map(arrayOrObject, cb);
9
+ if (Array.isArray(arrayOrObject)) {
10
+ return promiseMap(arrayOrObject, cb);
12
11
  }
13
12
  const size = Object.values(arrayOrObject).length;
14
- return Promise.all(_.map(arrayOrObject, (value, key) => cb(value, key, size)));
13
+ const entries = Object.entries(arrayOrObject);
14
+ return Promise.all(entries.map(([key, value]) => cb(value, key, size)));
15
15
  }),
16
16
  );
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@znemz/cfn-include",
3
- "version": "2.1.21",
3
+ "version": "2.1.22",
4
4
  "description": "Preprocessor for CloudFormation templates with support for loops and flexible include statements",
5
5
  "keywords": [
6
6
  "aws",
@@ -48,14 +48,12 @@
48
48
  "@znemz/cft-utils": "0.1.33",
49
49
  "@znemz/sort-object": "^3.0.4",
50
50
  "aws-sdk-v3-proxy": "2.2.0",
51
- "bluebird": "^3.7.2",
52
51
  "deepmerge": "^4.2.2",
53
52
  "glob": "^13.0.0",
54
53
  "jmespath": "^0.16.0",
55
54
  "js-yaml": "^4.1.1",
56
55
  "jsonminify": "^0.4.1",
57
56
  "lodash": "^4.17.21",
58
- "path-parse": "~1.0.7",
59
57
  "proxy-agent": "6.5.0",
60
58
  "yargs": "~18.0.0"
61
59
  },