[ENV] Use new env/pull endpoint for vc env pull, vc pull (#8751)

### Related Issues

We introduced a new endpoint: `/env/pull/:projectId/:target?/:gitBranch?` which will return a complete list of key/value pairs (environment variables) for the proper target environment, using the same logic as we use for deployments. 

This means that we don't need to fetch env variables from multiple sources (system, project, shared) and stitch them on the client anymore. 

- removes unused logic for fetching & merging environment variables on the CLI client
- offloads env variables generation to the API
  - new: shared env variables are now supported in vc env pull! 


### 📋 Checklist

<!--
  Please keep your PR as a Draft until the checklist is complete
-->

#### Tests

- [x] The code changed/added as part of this PR has been covered with tests
- [x] All tests pass locally with `yarn test-unit`

#### Code Review

- [x] This PR has a concise title and thorough description useful to a reviewer
- [x] Issue from task tracker has a link to this PR
This commit is contained in:
Baruch-Adi Hen
2022-10-21 16:18:15 -04:00
committed by GitHub
parent df9accfd6c
commit 30a9183836
10 changed files with 181 additions and 193 deletions

View File

@@ -85,8 +85,7 @@ import {
HttpHeadersConfig,
EnvConfigs,
} from './types';
import { ProjectEnvVariable, ProjectSettings } from '../../types';
import exposeSystemEnvs from './expose-system-envs';
import { ProjectSettings } from '../../types';
import { treeKill } from '../tree-kill';
import { nodeHeadersToFetchHeaders } from './headers';
import { formatQueryString, parseQueryString } from './parse-query-string';
@@ -168,15 +167,13 @@ export default class DevServer {
private blockingBuildsPromise: Promise<void> | null;
private startPromise: Promise<void> | null;
private systemEnvValues: string[];
private projectEnvs: ProjectEnvVariable[];
private envValues: Record<string, string>;
constructor(cwd: string, options: DevServerOptions) {
this.cwd = cwd;
this.output = options.output;
this.envConfigs = { buildEnv: {}, runEnv: {}, allEnv: {} };
this.systemEnvValues = options.systemEnvValues || [];
this.projectEnvs = options.projectEnvs || [];
this.envValues = options.envValues || {};
this.files = {};
this.originalProjectSettings = options.projectSettings;
this.projectSettings = options.projectSettings;
@@ -684,16 +681,13 @@ export default class DevServer {
// If no .env/.build.env is present, use cloud environment variables
if (Object.keys(allEnv).length === 0) {
const cloudEnv = exposeSystemEnvs(
this.projectEnvs || [],
this.systemEnvValues || [],
this.projectSettings?.autoExposeSystemEnvs,
this.address.host
);
allEnv = { ...cloudEnv };
runEnv = { ...cloudEnv };
buildEnv = { ...cloudEnv };
const envValues = { ...this.envValues };
if (this.address.host) {
envValues['VERCEL_URL'] = this.address.host;
}
allEnv = { ...envValues };
runEnv = { ...envValues };
buildEnv = { ...envValues };
}
// legacy NOW_REGION env variable