@ranger1/dx 0.1.61 → 0.1.63

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.
@@ -2,6 +2,36 @@ import { logger } from '../../logger.js'
2
2
  import { envManager } from '../../env.js'
3
3
  import { validateEnvironment } from '../../validate-env.js'
4
4
 
5
+ export function mergeLayeredDeployEnv(layeredEnv, manager, runtimeEnv = process.env) {
6
+ const vercelCriticalKeys = new Set([
7
+ 'VERCEL_TOKEN',
8
+ 'VERCEL_ORG_ID',
9
+ 'VERCEL_PROJECT_ID_FRONT',
10
+ 'VERCEL_PROJECT_ID_ADMIN',
11
+ 'VERCEL_PROJECT_ID_TELEGRAM_BOT',
12
+ ])
13
+
14
+ for (const [key, value] of Object.entries(layeredEnv)) {
15
+ if (vercelCriticalKeys.has(key)) {
16
+ const currentValue = runtimeEnv[key]
17
+ const currentUsable =
18
+ currentValue !== undefined && currentValue !== null && !manager.isPlaceholderEnvValue(currentValue)
19
+ const incomingIsPlaceholder = manager.isPlaceholderEnvValue(value)
20
+
21
+ // 保留外部显式注入的真实凭据,避免被 .env.<env> 的占位符回退污染。
22
+ if (currentUsable && incomingIsPlaceholder) continue
23
+
24
+ runtimeEnv[key] = value
25
+ continue
26
+ }
27
+
28
+ const currentValue = runtimeEnv[key]
29
+ if (!currentValue || manager.isPlaceholderEnvValue(currentValue)) {
30
+ runtimeEnv[key] = value
31
+ }
32
+ }
33
+ }
34
+
5
35
  export function parseTelegramWebhookFlags(argv = []) {
6
36
  const args = Array.isArray(argv) ? argv : []
7
37
 
@@ -86,27 +116,8 @@ export async function handleDeploy(cli, args) {
86
116
  })
87
117
  }
88
118
 
89
- // 默认仅在缺失/占位时覆盖,避免破坏显式传入的环境变量。
90
- // 但对 Vercel 部署关键变量,强制使用当前环境层,确保不受 shell 残留值影响。
91
- const vercelCriticalKeys = new Set([
92
- 'VERCEL_TOKEN',
93
- 'VERCEL_ORG_ID',
94
- 'VERCEL_PROJECT_ID_FRONT',
95
- 'VERCEL_PROJECT_ID_ADMIN',
96
- 'VERCEL_PROJECT_ID_TELEGRAM_BOT',
97
- ])
98
-
99
- for (const [key, value] of Object.entries(layeredEnv)) {
100
- if (vercelCriticalKeys.has(key)) {
101
- process.env[key] = value
102
- continue
103
- }
104
-
105
- const currentValue = process.env[key]
106
- if (!currentValue || envManager.isPlaceholderEnvValue(currentValue)) {
107
- process.env[key] = value
108
- }
109
- }
119
+ // 默认仅在缺失/占位时覆盖;Vercel 关键变量额外避免“真实值被占位符覆盖”的回退污染。
120
+ mergeLayeredDeployEnv(layeredEnv, envManager, process.env)
110
121
  envManager.syncEnvironments(environment)
111
122
 
112
123
  const { deployToVercel } = await import('../../vercel-deploy.js')
@@ -101,13 +101,17 @@ function listMissingConfigs(targetConfigs, projectRoot) {
101
101
  return missing
102
102
  }
103
103
 
104
- function appendTargetArgs(baseArgs, { orgId }) {
104
+ function appendTargetArgs(baseArgs, { orgId, token }) {
105
105
  const args = [...baseArgs]
106
106
 
107
107
  if (orgId) {
108
108
  args.push('--scope', orgId)
109
109
  }
110
110
 
111
+ if (token) {
112
+ args.push('--token', token)
113
+ }
114
+
111
115
  return args
112
116
  }
113
117
 
@@ -431,7 +435,8 @@ export async function deployToVercel(target, options = {}) {
431
435
  // 第一步:本地构建
432
436
  logger.step(`本地构建 ${t} (${environment})`)
433
437
  const buildArgs = appendTargetArgs(['build', '--local-config', configPath, '--yes'], {
434
- orgId
438
+ orgId,
439
+ token
435
440
  })
436
441
 
437
442
  // staging 和 production 环境需要 --prod 标志,确保构建产物与部署环境匹配
@@ -447,7 +452,8 @@ export async function deployToVercel(target, options = {}) {
447
452
  const baseDeployArgs = appendTargetArgs(
448
453
  ['deploy', '--prebuilt', '--local-config', configPath, '--yes'],
449
454
  {
450
- orgId
455
+ orgId,
456
+ token
451
457
  }
452
458
  )
453
459
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ranger1/dx",
3
- "version": "0.1.61",
3
+ "version": "0.1.63",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {