Add proxy to create-app tasks

Signed-off-by: enyineer <nico.enking@gmail.com>
This commit is contained in:
enyineer
2025-10-10 10:09:47 +02:00
parent 944d3fa82e
commit cdbec2e0d5
8 changed files with 171 additions and 42 deletions
+4 -1
View File
@@ -47,16 +47,19 @@
"chalk": "^4.0.0",
"commander": "^12.0.0",
"fs-extra": "^11.2.0",
"global-agent": "^3.0.0",
"handlebars": "^4.7.3",
"inquirer": "^8.2.0",
"ora": "^5.3.0",
"recursive-readdir": "^2.2.2"
"recursive-readdir": "^2.2.2",
"undici": "^7.2.3"
},
"devDependencies": {
"@backstage/backend-test-utils": "workspace:^",
"@backstage/cli": "workspace:^",
"@types/command-exists": "^1.2.0",
"@types/fs-extra": "^11.0.0",
"@types/global-agent": "^3",
"@types/inquirer": "^8.1.3",
"@types/node": "^20.16.0",
"@types/recursive-readdir": "^2.2.0",
@@ -36,6 +36,15 @@ import {
import { http, HttpResponse, delay } from 'msw';
import { setupServer } from 'msw/node';
// Avoid mutating the global agents used in other tests
jest.mock('global-agent', () => ({
bootstrap: jest.fn(),
}));
jest.mock('undici', () => ({
setGlobalDispatcher: jest.fn(),
EnvHttpProxyAgent: class {},
}));
jest.spyOn(Task, 'log').mockReturnValue(undefined);
jest.spyOn(Task, 'error').mockReturnValue(undefined);
jest.spyOn(Task, 'section').mockReturnValue(undefined);
+1 -20
View File
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { maybeBootstrapProxy } from '@backstage/cli-common';
maybeBootstrapProxy();
@@ -32,26 +33,6 @@ import { packageVersions } from './versions';
import { promisify } from 'util';
import os from 'os';
function maybeBootstrapProxy() {
// see https://www.npmjs.com/package/global-agent
const globalAgentNamespace =
process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE ?? 'GLOBAL_AGENT_';
if (
process.env[`${globalAgentNamespace}HTTP_PROXY`] ||
process.env[`${globalAgentNamespace}HTTPS_PROXY`]
) {
const globalAgent =
require('global-agent') as typeof import('global-agent');
globalAgent.bootstrap();
}
if (process.env.HTTP_PROXY || process.env.HTTPS_PROXY) {
const { setGlobalDispatcher, EnvHttpProxyAgent } =
require('undici') as typeof import('undici');
setGlobalDispatcher(new EnvHttpProxyAgent());
}
}
const TASK_NAME_MAX_LENGTH = 14;
const TEN_MINUTES_MS = 1000 * 60 * 10;
const exec = promisify(execCb);