hereya-cli 0.100.5 → 0.100.6

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.
@@ -4,7 +4,7 @@ import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import { pipeline } from 'node:stream/promises';
6
6
  import { Extract as decompress } from 'unzip-stream';
7
- import { mapObject } from '../lib/object-utils.js';
7
+ import { mapObject, paramToEnvString } from '../lib/object-utils.js';
8
8
  import { runShell } from '../lib/shell.js';
9
9
  export class Terraform {
10
10
  async apply(input) {
@@ -46,12 +46,12 @@ export class Terraform {
46
46
  env: {
47
47
  ...mapObject(input.env ?? {}, (key, value) => [
48
48
  `TF_VAR_${key}`,
49
- typeof value === 'object' ? JSON.stringify(value) : value,
49
+ paramToEnvString(value),
50
50
  ]),
51
51
  ...input.env,
52
52
  ...mapObject(input.parameters ?? {}, (key, value) => [
53
53
  `TF_VAR_${key}`,
54
- typeof value === 'object' ? JSON.stringify(value) : value,
54
+ paramToEnvString(value),
55
55
  ]),
56
56
  },
57
57
  logger: input.logger,
@@ -61,12 +61,12 @@ export class Terraform {
61
61
  env: {
62
62
  ...mapObject(input.env ?? {}, (key, value) => [
63
63
  `TF_VAR_${key}`,
64
- typeof value === 'object' ? JSON.stringify(value) : value,
64
+ paramToEnvString(value),
65
65
  ]),
66
66
  ...input.env,
67
67
  ...mapObject(input.parameters ?? {}, (key, value) => [
68
68
  `TF_VAR_${key}`,
69
- typeof value === 'object' ? JSON.stringify(value) : value,
69
+ paramToEnvString(value),
70
70
  ]),
71
71
  },
72
72
  logger: input.logger,
@@ -124,12 +124,12 @@ export class Terraform {
124
124
  env: {
125
125
  ...mapObject(input.env ?? {}, (key, value) => [
126
126
  `TF_VAR_${key}`,
127
- typeof value === 'object' ? JSON.stringify(value) : value,
127
+ paramToEnvString(value),
128
128
  ]),
129
129
  ...input.env,
130
130
  ...mapObject(input.parameters ?? {}, (key, value) => [
131
131
  `TF_VAR_${key}`,
132
- typeof value === 'object' ? JSON.stringify(value) : value,
132
+ paramToEnvString(value),
133
133
  ]),
134
134
  },
135
135
  logger: input.logger,
@@ -140,12 +140,12 @@ export class Terraform {
140
140
  env: {
141
141
  ...mapObject(input.env ?? {}, (key, value) => [
142
142
  `TF_VAR_${key}`,
143
- typeof value === 'object' ? JSON.stringify(value) : value,
143
+ paramToEnvString(value),
144
144
  ]),
145
145
  ...input.env,
146
146
  ...mapObject(input.parameters ?? {}, (key, value) => [
147
147
  `TF_VAR_${key}`,
148
- typeof value === 'object' ? JSON.stringify(value) : value,
148
+ paramToEnvString(value),
149
149
  ]),
150
150
  },
151
151
  logger: input.logger,
@@ -1,4 +1,24 @@
1
1
  export declare function mapObject(obj: object, fn: (key: string, value: any) => [string, any]): object;
2
+ /**
3
+ * Coerce a parameter value (as parsed from a hereyavars YAML file or
4
+ * forwarded through the executor) into the string form expected by the
5
+ * package's CDK/Terraform process when injected as an environment variable
6
+ * or CLI argument.
7
+ *
8
+ * - Strings (including pre-stringified JSON) pass through unchanged so the
9
+ * existing "stringify it yourself" workaround keeps working.
10
+ * - Numbers and booleans become their plain string representation
11
+ * (matching the previous behavior of `String(value)`).
12
+ * - Arrays and objects are JSON-encoded so the receiving package can
13
+ * `JSON.parse(process.env.foo)` instead of receiving "[object Object]"
14
+ * or a comma-joined `Array.prototype.toString()`.
15
+ * - `null` and `undefined` become an empty string.
16
+ *
17
+ * Intended to be applied at the single boundary where the env map for the
18
+ * package process is built — not earlier in the pipeline, so the parsed
19
+ * YAML can stay structured everywhere else in the CLI.
20
+ */
21
+ export declare function paramToEnvString(value: unknown): string;
2
22
  export declare function arrayOfStringToObject(arr: string[], keyValueSeparator?: string): {
3
23
  [k: string]: string;
4
24
  };
@@ -1,6 +1,36 @@
1
1
  export function mapObject(obj, fn) {
2
2
  return Object.fromEntries(Object.entries(obj).map(([key, value]) => fn(key, value)));
3
3
  }
4
+ /**
5
+ * Coerce a parameter value (as parsed from a hereyavars YAML file or
6
+ * forwarded through the executor) into the string form expected by the
7
+ * package's CDK/Terraform process when injected as an environment variable
8
+ * or CLI argument.
9
+ *
10
+ * - Strings (including pre-stringified JSON) pass through unchanged so the
11
+ * existing "stringify it yourself" workaround keeps working.
12
+ * - Numbers and booleans become their plain string representation
13
+ * (matching the previous behavior of `String(value)`).
14
+ * - Arrays and objects are JSON-encoded so the receiving package can
15
+ * `JSON.parse(process.env.foo)` instead of receiving "[object Object]"
16
+ * or a comma-joined `Array.prototype.toString()`.
17
+ * - `null` and `undefined` become an empty string.
18
+ *
19
+ * Intended to be applied at the single boundary where the env map for the
20
+ * package process is built — not earlier in the pipeline, so the parsed
21
+ * YAML can stay structured everywhere else in the CLI.
22
+ */
23
+ export function paramToEnvString(value) {
24
+ if (value === null || value === undefined)
25
+ return '';
26
+ if (typeof value === 'string')
27
+ return value;
28
+ if (typeof value === 'number' || typeof value === 'boolean') {
29
+ return String(value);
30
+ }
31
+ // Objects/arrays -> JSON. Round-trippable and what package authors expect.
32
+ return JSON.stringify(value);
33
+ }
4
34
  export function arrayOfStringToObject(arr, keyValueSeparator = '=') {
5
35
  return Object.fromEntries(arr.map((item) => {
6
36
  const [key, value] = item.split(keyValueSeparator);