@crossdelta/infrastructure 0.8.3 → 0.8.5

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.
@@ -0,0 +1,51 @@
1
+ export const resolveStringVariable = (variableName: string, fileContent: string): string | undefined => {
2
+ const pattern = new RegExp(
3
+ `(?:const|let|var)\\s+${variableName}\\s*=\\s*['"]([^'"]+)['"]`,
4
+ )
5
+ return fileContent.match(pattern)?.[1]
6
+ }
7
+
8
+ export const resolveArrayJoin = (variableName: string, separator: string, fileContent: string): string | undefined => {
9
+ const arrayPattern = new RegExp(
10
+ `(?:const|let|var)\\s+${variableName}\\s*=\\s*\\[([^\\]]*)]`,
11
+ 's',
12
+ )
13
+ const arrayMatch = fileContent.match(arrayPattern)
14
+ if (!arrayMatch?.[1]) return undefined
15
+
16
+ const elements = arrayMatch[1]
17
+ .split(',')
18
+ .map((element) => element.trim().replace(/^['"]|['"]$/g, ''))
19
+ .filter(Boolean)
20
+
21
+ return elements.length > 0 ? elements.join(separator) : undefined
22
+ }
23
+
24
+ export const extractEnvLiterals = (content: string): Record<string, string> | undefined => {
25
+ const envBlockMatch = content.match(/(?<!\w)env:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/)
26
+ if (!envBlockMatch?.[1]) return undefined
27
+
28
+ const literals: Record<string, string> = {}
29
+ const literalPattern = /^\s*(\w+):\s*['"]([^'"]+)['"]/gm
30
+ for (const [, key, value] of envBlockMatch[1].matchAll(literalPattern)) {
31
+ if (key && value) literals[key] = value
32
+ }
33
+
34
+ const joinPattern = /^\s*(\w+):\s*(\w+)\.join\(\s*['"]([^'"]*)['"]\s*\)/gm
35
+ for (const [, key, variableName, separator] of envBlockMatch[1].matchAll(joinPattern)) {
36
+ if (key && variableName) {
37
+ const resolved = resolveArrayJoin(variableName, separator ?? ',', content)
38
+ if (resolved) literals[key] = resolved
39
+ }
40
+ }
41
+
42
+ const variablePattern = /^\s*(\w+):\s*(\w+)\s*,?$/gm
43
+ for (const [, key, variableName] of envBlockMatch[1].matchAll(variablePattern)) {
44
+ if (key && variableName && !(key in literals)) {
45
+ const resolved = resolveStringVariable(variableName, content)
46
+ if (resolved) literals[key] = resolved
47
+ }
48
+ }
49
+
50
+ return Object.keys(literals).length > 0 ? literals : undefined
51
+ }
@@ -4,6 +4,50 @@
4
4
  import { execSync } from "node:child_process";
5
5
  import { existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
6
6
  import { join } from "node:path";
7
+
8
+ // bin/env-parsing.ts
9
+ var resolveStringVariable = (variableName, fileContent) => {
10
+ const pattern = new RegExp(`(?:const|let|var)\\s+${variableName}\\s*=\\s*['"]([^'"]+)['"]`);
11
+ return fileContent.match(pattern)?.[1];
12
+ };
13
+ var resolveArrayJoin = (variableName, separator, fileContent) => {
14
+ const arrayPattern = new RegExp(`(?:const|let|var)\\s+${variableName}\\s*=\\s*\\[([^\\]]*)]`, "s");
15
+ const arrayMatch = fileContent.match(arrayPattern);
16
+ if (!arrayMatch?.[1])
17
+ return;
18
+ const elements = arrayMatch[1].split(",").map((element) => element.trim().replace(/^['"]|['"]$/g, "")).filter(Boolean);
19
+ return elements.length > 0 ? elements.join(separator) : undefined;
20
+ };
21
+ var extractEnvLiterals = (content) => {
22
+ const envBlockMatch = content.match(/(?<!\w)env:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/);
23
+ if (!envBlockMatch?.[1])
24
+ return;
25
+ const literals = {};
26
+ const literalPattern = /^\s*(\w+):\s*['"]([^'"]+)['"]/gm;
27
+ for (const [, key, value] of envBlockMatch[1].matchAll(literalPattern)) {
28
+ if (key && value)
29
+ literals[key] = value;
30
+ }
31
+ const joinPattern = /^\s*(\w+):\s*(\w+)\.join\(\s*['"]([^'"]*)['"]\s*\)/gm;
32
+ for (const [, key, variableName, separator] of envBlockMatch[1].matchAll(joinPattern)) {
33
+ if (key && variableName) {
34
+ const resolved = resolveArrayJoin(variableName, separator ?? ",", content);
35
+ if (resolved)
36
+ literals[key] = resolved;
37
+ }
38
+ }
39
+ const variablePattern = /^\s*(\w+):\s*(\w+)\s*,?$/gm;
40
+ for (const [, key, variableName] of envBlockMatch[1].matchAll(variablePattern)) {
41
+ if (key && variableName && !(key in literals)) {
42
+ const resolved = resolveStringVariable(variableName, content);
43
+ if (resolved)
44
+ literals[key] = resolved;
45
+ }
46
+ }
47
+ return Object.keys(literals).length > 0 ? literals : undefined;
48
+ };
49
+
50
+ // bin/generate-env.ts
7
51
  var LOCK_FILES = ["bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
8
52
  var toEnvKey = (name) => name.toUpperCase().replace(/-/g, "_");
9
53
  var resolveNumber = (value, fileContent) => {
@@ -27,18 +71,6 @@ var extract = {
27
71
  return numbers.length > 0 ? numbers : undefined;
28
72
  }
29
73
  };
30
- var extractEnvLiterals = (content) => {
31
- const envBlockMatch = content.match(/(?<!\w)env:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/);
32
- if (!envBlockMatch?.[1])
33
- return;
34
- const literals = {};
35
- const literalPattern = /^\s*(\w+):\s*['"]([^'"]+)['"]/gm;
36
- for (const [, key, value] of envBlockMatch[1].matchAll(literalPattern)) {
37
- if (key && value)
38
- literals[key] = value;
39
- }
40
- return Object.keys(literals).length > 0 ? literals : undefined;
41
- };
42
74
  var getServicePort = (config) => {
43
75
  if (config.primaryPort)
44
76
  return config.primaryPort;
@@ -13,6 +13,7 @@
13
13
  import { execSync } from 'node:child_process'
14
14
  import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs'
15
15
  import { join } from 'node:path'
16
+ import { extractEnvLiterals } from './env-parsing'
16
17
 
17
18
  type PulumiConfigEntry = {
18
19
  value?: string
@@ -62,18 +63,6 @@ const extract = {
62
63
  },
63
64
  }
64
65
 
65
- const extractEnvLiterals = (content: string): Record<string, string> | undefined => {
66
- const envBlockMatch = content.match(/(?<!\w)env:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/)
67
- if (!envBlockMatch?.[1]) return undefined
68
-
69
- const literals: Record<string, string> = {}
70
- const literalPattern = /^\s*(\w+):\s*['"]([^'"]+)['"]/gm
71
- for (const [, key, value] of envBlockMatch[1].matchAll(literalPattern)) {
72
- if (key && value) literals[key] = value
73
- }
74
- return Object.keys(literals).length > 0 ? literals : undefined
75
- }
76
-
77
66
  const getServicePort = (config: MinimalServiceConfig): number | undefined => {
78
67
  if (config.primaryPort) return config.primaryPort
79
68
  if (config.containerPort) return config.containerPort
package/dist/index.cjs CHANGED
@@ -1015,7 +1015,7 @@ var generateSetupScript = (streams) => {
1015
1015
  `echo "⏳ Waiting for NATS to become available..."`,
1016
1016
  `RETRIES=0`,
1017
1017
  `MAX_RETRIES=30`,
1018
- `until nats $NATS_OPTS server ping --count 1 > /dev/null 2>&1; do`,
1018
+ `until nats $NATS_OPTS rtt > /dev/null 2>&1; do`,
1019
1019
  ` RETRIES=$((RETRIES + 1))`,
1020
1020
  ` if [ "$RETRIES" -ge "$MAX_RETRIES" ]; then`,
1021
1021
  ` echo "❌ NATS not available after $MAX_RETRIES attempts"`,
package/dist/index.js CHANGED
@@ -921,7 +921,7 @@ var generateSetupScript = (streams) => {
921
921
  `echo "⏳ Waiting for NATS to become available..."`,
922
922
  `RETRIES=0`,
923
923
  `MAX_RETRIES=30`,
924
- `until nats $NATS_OPTS server ping --count 1 > /dev/null 2>&1; do`,
924
+ `until nats $NATS_OPTS rtt > /dev/null 2>&1; do`,
925
925
  ` RETRIES=$((RETRIES + 1))`,
926
926
  ` if [ "$RETRIES" -ge "$MAX_RETRIES" ]; then`,
927
927
  ` echo "❌ NATS not available after $MAX_RETRIES attempts"`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crossdelta/infrastructure",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@crossdelta/cloudevents": "^0.7.18"
38
+ "@crossdelta/cloudevents": "^0.7.19"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@pulumi/digitalocean": "^4.0.0",