@jayfong/x-server 2.97.0 → 2.98.0

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.
@@ -123,10 +123,26 @@ class EnvUtil {
123
123
  static parseContent(src) {
124
124
  const envs = [];
125
125
  const envObj = (0, _yaml.parse)(src);
126
+ const inlineVars = value => {
127
+ if (Array.isArray(value)) {
128
+ return value.map(inlineVars);
129
+ }
130
+ if ((0, _vtils.isPlainObject)(value)) {
131
+ return Object.keys(value).reduce((acc, key) => {
132
+ acc[key] = inlineVars(value[key]);
133
+ return acc;
134
+ }, {});
135
+ }
136
+ if (typeof value === 'string') {
137
+ return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => (0, _vtils.get)(envObj, key) || process.env[key] || '');
138
+ }
139
+ return value;
140
+ };
126
141
  Object.keys(envObj).forEach(key => {
142
+ const value = inlineVars(envObj[key]);
127
143
  envs.push({
128
144
  key: key,
129
- value: envObj[key],
145
+ value: value,
130
146
  comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${(0, _vtils.escapeRegExp)(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, '').trim() || ''
131
147
  });
132
148
  });
@@ -2,7 +2,7 @@ import path from 'node:path';
2
2
  import fs from 'fs-extra';
3
3
  import globby from 'globby';
4
4
  import { pinyin } from 'pinyin-pro';
5
- import { asyncLimit, dedent, difference, escapeRegExp, isPlainObject, uniq } from 'vtils';
5
+ import { asyncLimit, dedent, difference, escapeRegExp, get, isPlainObject, uniq } from 'vtils';
6
6
  import { parse as yamlParse } from 'yaml';
7
7
  export class EnvUtil {
8
8
  static async getAllChannel(cwd, excludeChannels) {
@@ -118,10 +118,26 @@ export class EnvUtil {
118
118
  static parseContent(src) {
119
119
  const envs = [];
120
120
  const envObj = yamlParse(src);
121
+ const inlineVars = value => {
122
+ if (Array.isArray(value)) {
123
+ return value.map(inlineVars);
124
+ }
125
+ if (isPlainObject(value)) {
126
+ return Object.keys(value).reduce((acc, key) => {
127
+ acc[key] = inlineVars(value[key]);
128
+ return acc;
129
+ }, {});
130
+ }
131
+ if (typeof value === 'string') {
132
+ return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => get(envObj, key) || process.env[key] || '');
133
+ }
134
+ return value;
135
+ };
121
136
  Object.keys(envObj).forEach(key => {
137
+ const value = inlineVars(envObj[key]);
122
138
  envs.push({
123
139
  key: key,
124
- value: envObj[key],
140
+ value: value,
125
141
  comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${escapeRegExp(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, '').trim() || ''
126
142
  });
127
143
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.97.0",
3
+ "version": "2.98.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",