@ranger1/dx 0.1.54 → 0.1.56
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/lib/vercel-deploy.js +2 -55
- package/package.json +1 -1
package/lib/vercel-deploy.js
CHANGED
|
@@ -22,9 +22,6 @@ const TARGET_CONFIGS = {
|
|
|
22
22
|
},
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const EXPLICIT_ENV_VARS = ['APP_ENV', 'NODE_ENV']
|
|
26
|
-
const PUBLIC_ENV_PREFIXES = ['NEXT_PUBLIC_', 'VITE_']
|
|
27
|
-
|
|
28
25
|
const APP_ENV_MAP = {
|
|
29
26
|
development: 'dev',
|
|
30
27
|
staging: 'staging',
|
|
@@ -88,13 +85,9 @@ function listMissingConfigs(targetConfigs, projectRoot) {
|
|
|
88
85
|
return missing
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
function appendTargetArgs(baseArgs, { cwd, orgId
|
|
88
|
+
function appendTargetArgs(baseArgs, { cwd, orgId }) {
|
|
92
89
|
const args = [...baseArgs]
|
|
93
90
|
|
|
94
|
-
if (explicitEnvArgs.length > 0) {
|
|
95
|
-
args.push(...explicitEnvArgs)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
91
|
if (cwd) {
|
|
99
92
|
args.push('--cwd', cwd)
|
|
100
93
|
}
|
|
@@ -103,40 +96,9 @@ function appendTargetArgs(baseArgs, { cwd, orgId, projectId, explicitEnvArgs = [
|
|
|
103
96
|
args.push('--scope', orgId)
|
|
104
97
|
}
|
|
105
98
|
|
|
106
|
-
if (projectId) {
|
|
107
|
-
args.push('--project', projectId)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
99
|
return args
|
|
111
100
|
}
|
|
112
101
|
|
|
113
|
-
function collectExplicitVercelEnvEntries(sourceEnv = {}) {
|
|
114
|
-
const includeKeys = new Set(EXPLICIT_ENV_VARS)
|
|
115
|
-
|
|
116
|
-
Object.keys(sourceEnv).forEach(name => {
|
|
117
|
-
if (PUBLIC_ENV_PREFIXES.some(prefix => name.startsWith(prefix))) {
|
|
118
|
-
includeKeys.add(name)
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
return [...includeKeys]
|
|
123
|
-
.filter(name => {
|
|
124
|
-
const value = sourceEnv[name]
|
|
125
|
-
return !(
|
|
126
|
-
value === undefined ||
|
|
127
|
-
value === null ||
|
|
128
|
-
envManager.isPlaceholderEnvValue(value)
|
|
129
|
-
)
|
|
130
|
-
})
|
|
131
|
-
.sort()
|
|
132
|
-
.map(name => `${name}=${String(sourceEnv[name])}`)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function withEnvFlag(entries, flag) {
|
|
136
|
-
if (!Array.isArray(entries) || entries.length === 0) return []
|
|
137
|
-
return entries.flatMap(entry => [flag, entry])
|
|
138
|
-
}
|
|
139
|
-
|
|
140
102
|
function maskIdentifier(value) {
|
|
141
103
|
const raw = String(value || '').trim()
|
|
142
104
|
if (raw.length <= 10) return raw || '-'
|
|
@@ -308,7 +270,7 @@ export async function deployToVercel(target, options = {}) {
|
|
|
308
270
|
logger.info(' 1. VERCEL_TOKEN: vercel login 后查看 ~/Library/Application Support/com.vercel.cli/auth.json')
|
|
309
271
|
logger.info(' 2. PROJECT_ID: vercel project ls --scope <org> 或通过 Vercel Dashboard 获取')
|
|
310
272
|
logger.info('')
|
|
311
|
-
logger.info('提示:部署命令会显式校验 --scope
|
|
273
|
+
logger.info('提示:部署命令会显式校验 --scope 与环境变量上下文,避免环境漂移。')
|
|
312
274
|
}
|
|
313
275
|
|
|
314
276
|
if (missingConfigFiles.length > 0) {
|
|
@@ -373,17 +335,6 @@ export async function deployToVercel(target, options = {}) {
|
|
|
373
335
|
`[deploy-context] env=${environment} target=${t} strict=${strictContext ? 1 : 0} org=${maskIdentifier(orgId)} project=${maskIdentifier(projectId)} linked=${linkedContext.exists ? 'yes' : 'no'} token=env`,
|
|
374
336
|
)
|
|
375
337
|
|
|
376
|
-
const explicitEnvEntries = collectExplicitVercelEnvEntries({
|
|
377
|
-
...process.env,
|
|
378
|
-
APP_ENV: buildEnv,
|
|
379
|
-
NODE_ENV: envManager.mapAppEnvToNodeEnv(environment),
|
|
380
|
-
VERCEL_ORG_ID: orgId,
|
|
381
|
-
VERCEL_PROJECT_ID: projectId,
|
|
382
|
-
})
|
|
383
|
-
|
|
384
|
-
const buildEnvArgs = withEnvFlag(explicitEnvEntries, '--build-env')
|
|
385
|
-
const deployEnvArgs = withEnvFlag(explicitEnvEntries, '--env')
|
|
386
|
-
|
|
387
338
|
const envVars = {
|
|
388
339
|
...process.env,
|
|
389
340
|
VERCEL_PROJECT_ID: projectId,
|
|
@@ -422,8 +373,6 @@ export async function deployToVercel(target, options = {}) {
|
|
|
422
373
|
{
|
|
423
374
|
cwd: projectRoot,
|
|
424
375
|
orgId,
|
|
425
|
-
projectId,
|
|
426
|
-
explicitEnvArgs: buildEnvArgs,
|
|
427
376
|
},
|
|
428
377
|
)
|
|
429
378
|
|
|
@@ -442,8 +391,6 @@ export async function deployToVercel(target, options = {}) {
|
|
|
442
391
|
{
|
|
443
392
|
cwd: projectRoot,
|
|
444
393
|
orgId,
|
|
445
|
-
projectId,
|
|
446
|
-
explicitEnvArgs: deployEnvArgs,
|
|
447
394
|
},
|
|
448
395
|
)
|
|
449
396
|
|