From 96be5d14d8477e69641912c992479e3e7a854fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 19 Jun 2024 14:44:35 +0200 Subject: [PATCH 1/2] try to debug the _a.destroy problem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .github/workflows/ci.yml | 27 +++++++++++- ...-interceptors-npm-0.17.10-c1199a9424.patch | 18 ++++++++ ...s-interceptors-npm-0.29.1-b5be72ad54.patch | 36 ++++++++++++++++ package.json | 3 ++ packages/cli/src/commands/versions/bump.ts | 20 ++++++++- yarn.lock | 42 ++++++++++++++++++- 6 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 .yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch create mode 100644 .yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 135076ba40..95d6bbee34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -150,7 +150,32 @@ jobs: strategy: fail-fast: false matrix: - node-version: [18.x, 20.x] + node-version: + [ + 18.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + 20.x, + ] name: Test ${{ matrix.node-version }} services: diff --git a/.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch b/.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch new file mode 100644 index 0000000000..3b6e9c1fbf --- /dev/null +++ b/.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch @@ -0,0 +1,18 @@ +diff --git a/lib/interceptors/ClientRequest/NodeClientRequest.js b/lib/interceptors/ClientRequest/NodeClientRequest.js +index 9bcc5a6adfd3c84541d686c3d0039f5e79dd34f5..f72d47b02a437eaefead4ec1543a0dd70dd1bb6f 100644 +--- a/lib/interceptors/ClientRequest/NodeClientRequest.js ++++ b/lib/interceptors/ClientRequest/NodeClientRequest.js +@@ -382,6 +382,13 @@ var NodeClientRequest = /** @class */ (function (_super) { + */ + NodeClientRequest.prototype.terminate = function () { + var _a; ++ const tempAgent = this.agent; ++ if (tempAgent && typeof tempAgent === 'object' && typeof tempAgent.destroy !== 'function') { ++ console.log( ++ `No agent to destroy, found '${typeof tempAgent}'->'${typeof tempAgent.destroy}':`, ++ tempAgent ++ ); ++ } + // @ts-ignore + (_a = this.agent) === null || _a === void 0 ? void 0 : _a.destroy(); + }; diff --git a/.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch b/.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch new file mode 100644 index 0000000000..946777f134 --- /dev/null +++ b/.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch @@ -0,0 +1,36 @@ +diff --git a/lib/node/chunk-CVV3L375.mjs b/lib/node/chunk-CVV3L375.mjs +index c37d61d709235efebe4ea19703a901bfbc05c9e3..4085c9b33075e18f7e4e3ad82fdd3fa5f6bb31e2 100644 +--- a/lib/node/chunk-CVV3L375.mjs ++++ b/lib/node/chunk-CVV3L375.mjs +@@ -540,6 +540,13 @@ var _NodeClientRequest = class extends ClientRequest { + * Terminates a pending request. + */ + terminate() { ++ const tempAgent = this.agent; ++ if (tempAgent && typeof tempAgent === 'object' && typeof tempAgent.destroy !== 'function') { ++ console.log( ++ `No agent to destroy, found '${typeof tempAgent}'->'${typeof tempAgent.destroy}':`, ++ tempAgent ++ ); ++ } + var _a; + (_a = this.agent) == null ? void 0 : _a.destroy(); + } +diff --git a/lib/node/chunk-SXGRMPXP.js b/lib/node/chunk-SXGRMPXP.js +index a5129f18a9b754acf2bfb3b1545df2378b01a95a..8228b6d4f649937559f45aefbdb8c8df275c5285 100644 +--- a/lib/node/chunk-SXGRMPXP.js ++++ b/lib/node/chunk-SXGRMPXP.js +@@ -540,6 +540,13 @@ var _NodeClientRequest = class extends _http.ClientRequest { + * Terminates a pending request. + */ + terminate() { ++ const tempAgent = this.agent; ++ if (tempAgent && typeof tempAgent === 'object' && typeof tempAgent.destroy !== 'function') { ++ console.log( ++ `No agent to destroy, found '${typeof tempAgent}'->'${typeof tempAgent.destroy}':`, ++ tempAgent ++ ); ++ } + var _a; + (_a = this.agent) == null ? void 0 : _a.destroy(); + } diff --git a/package.json b/package.json index 39c5d021c1..47dad4b2a2 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,8 @@ "@changesets/assemble-release-plan@^6.0.0": "patch:@changesets/assemble-release-plan@npm%3A6.0.0#./.yarn/patches/@changesets-assemble-release-plan-npm-6.0.0-f7b3005037.patch", "@material-ui/pickers@^3.2.10": "patch:@material-ui/pickers@npm%3A3.3.11#./.yarn/patches/@material-ui-pickers-npm-3.3.11-1c8f68ea20.patch", "@material-ui/pickers@^3.3.10": "patch:@material-ui/pickers@npm%3A3.3.11#./.yarn/patches/@material-ui-pickers-npm-3.3.11-1c8f68ea20.patch", + "@mswjs/interceptors@^0.17.10": "patch:@mswjs/interceptors@npm%3A0.17.10#.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch", + "@mswjs/interceptors@^0.29.0": "patch:@mswjs/interceptors@npm%3A0.29.1#./.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch", "@types/react": "^18", "@types/react-dom": "^18", "jest-haste-map@^29.7.0": "patch:jest-haste-map@npm%3A29.7.0#./.yarn/patches/jest-haste-map-npm-29.7.0-e3be419eff.patch" @@ -94,6 +96,7 @@ "dependencies": { "@backstage/errors": "workspace:^", "@manypkg/get-packages": "^1.1.3", + "@types/global-agent": "^2.1.3", "@useoptic/optic": "^0.50.10" }, "devDependencies": { diff --git a/packages/cli/src/commands/versions/bump.ts b/packages/cli/src/commands/versions/bump.ts index 1544240704..d6d5f424ba 100644 --- a/packages/cli/src/commands/versions/bump.ts +++ b/packages/cli/src/commands/versions/bump.ts @@ -14,6 +14,12 @@ * limitations under the License. */ +import { bootstrap } from 'global-agent'; + +if (shouldUseGlobalAgent()) { + bootstrap(); +} + import fs from 'fs-extra'; import chalk from 'chalk'; import ora from 'ora'; @@ -38,10 +44,22 @@ import { getManifestByVersion, ReleaseManifest, } from '@backstage/release-manifests'; -import 'global-agent/bootstrap'; import { PackageGraph } from '@backstage/cli-node'; import { migrateMovedPackages } from './migrate'; +function shouldUseGlobalAgent(): boolean { + // see https://www.npmjs.com/package/global-agent + const namespace = + process.env.GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE ?? 'GLOBAL_AGENT_'; + if ( + process.env[`${namespace}HTTP_PROXY`] || + process.env[`${namespace}HTTPS_PROXY`] + ) { + return true; + } + return false; +} + const DEP_TYPES = [ 'dependencies', 'devDependencies', diff --git a/yarn.lock b/yarn.lock index a0a385ca66..2b8090e00d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10782,7 +10782,7 @@ __metadata: languageName: node linkType: hard -"@mswjs/interceptors@npm:^0.17.10": +"@mswjs/interceptors@npm:0.17.10": version: 0.17.10 resolution: "@mswjs/interceptors@npm:0.17.10" dependencies: @@ -10798,7 +10798,7 @@ __metadata: languageName: node linkType: hard -"@mswjs/interceptors@npm:^0.29.0": +"@mswjs/interceptors@npm:0.29.1": version: 0.29.1 resolution: "@mswjs/interceptors@npm:0.29.1" dependencies: @@ -10812,6 +10812,36 @@ __metadata: languageName: node linkType: hard +"@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.17.10#.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch::locator=root%40workspace%3A.": + version: 0.17.10 + resolution: "@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.17.10#.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch::version=0.17.10&hash=652df3&locator=root%40workspace%3A." + dependencies: + "@open-draft/until": ^1.0.3 + "@types/debug": ^4.1.7 + "@xmldom/xmldom": ^0.8.3 + debug: ^4.3.3 + headers-polyfill: 3.2.5 + outvariant: ^1.2.1 + strict-event-emitter: ^0.2.4 + web-encoding: ^1.1.5 + checksum: 32ca2f2d4e8bc46e1f773ca440a0ec5ba9c69ea4d89c07fbd25a0fde73627a232eb7d0cf3ce426fbe1fd58863ab9c84386352ecdc55eeb2a5240ba126c0ba6f0 + languageName: node + linkType: hard + +"@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.29.1#./.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch::locator=root%40workspace%3A.": + version: 0.29.1 + resolution: "@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.29.1#./.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch::version=0.29.1&hash=d6ea98&locator=root%40workspace%3A." + dependencies: + "@open-draft/deferred-promise": ^2.2.0 + "@open-draft/logger": ^0.3.0 + "@open-draft/until": ^2.0.0 + is-node-process: ^1.2.0 + outvariant: ^1.2.1 + strict-event-emitter: ^0.5.1 + checksum: d7ce191736c8b5df2dcdb36d11dbf25ca37cd3c0d1319cf8594713c443c5bdf733c2aeb4863aba646a67b50813e64dc1b13fbd31cee238cc4c9f8a8fd2908486 + languageName: node + linkType: hard + "@mui/base@npm:5.0.0-beta.40": version: 5.0.0-beta.40 resolution: "@mui/base@npm:5.0.0-beta.40" @@ -17173,6 +17203,13 @@ __metadata: languageName: node linkType: hard +"@types/global-agent@npm:^2.1.3": + version: 2.1.3 + resolution: "@types/global-agent@npm:2.1.3" + checksum: 6129b6d5ba871b9d111ddf91e6f9a1725d3f28bf2aa6869ec83bebd14c688cde4275ebea6fa45b0b1c00d78109d022c935f952e9e4876d76289d4706484776c3 + languageName: node + linkType: hard + "@types/google-protobuf@npm:^3.7.2": version: 3.15.12 resolution: "@types/google-protobuf@npm:3.15.12" @@ -39395,6 +39432,7 @@ __metadata: "@spotify/eslint-plugin": ^15.0.0 "@spotify/prettier-config": ^15.0.0 "@techdocs/cli": "workspace:*" + "@types/global-agent": ^2.1.3 "@types/node": ^18.17.8 "@types/webpack": ^5.28.0 "@useoptic/optic": ^0.50.10 From 7652db4b9483e937712413ff59c73c5f3ab63836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Wed, 19 Jun 2024 14:44:35 +0200 Subject: [PATCH 2/2] fix the _a.destroy test flakiness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/gentle-avocados-obey.md | 5 +++ .github/workflows/ci.yml | 27 +------------- ...-interceptors-npm-0.17.10-c1199a9424.patch | 18 ---------- ...s-interceptors-npm-0.29.1-b5be72ad54.patch | 36 ------------------- package.json | 2 -- yarn.lock | 34 ++---------------- 6 files changed, 8 insertions(+), 114 deletions(-) create mode 100644 .changeset/gentle-avocados-obey.md delete mode 100644 .yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch delete mode 100644 .yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch diff --git a/.changeset/gentle-avocados-obey.md b/.changeset/gentle-avocados-obey.md new file mode 100644 index 0000000000..80bf5f89c7 --- /dev/null +++ b/.changeset/gentle-avocados-obey.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Only bootstrap global-agent if it's actually being used diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 95d6bbee34..135076ba40 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -150,32 +150,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: - [ - 18.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - 20.x, - ] + node-version: [18.x, 20.x] name: Test ${{ matrix.node-version }} services: diff --git a/.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch b/.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch deleted file mode 100644 index 3b6e9c1fbf..0000000000 --- a/.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch +++ /dev/null @@ -1,18 +0,0 @@ -diff --git a/lib/interceptors/ClientRequest/NodeClientRequest.js b/lib/interceptors/ClientRequest/NodeClientRequest.js -index 9bcc5a6adfd3c84541d686c3d0039f5e79dd34f5..f72d47b02a437eaefead4ec1543a0dd70dd1bb6f 100644 ---- a/lib/interceptors/ClientRequest/NodeClientRequest.js -+++ b/lib/interceptors/ClientRequest/NodeClientRequest.js -@@ -382,6 +382,13 @@ var NodeClientRequest = /** @class */ (function (_super) { - */ - NodeClientRequest.prototype.terminate = function () { - var _a; -+ const tempAgent = this.agent; -+ if (tempAgent && typeof tempAgent === 'object' && typeof tempAgent.destroy !== 'function') { -+ console.log( -+ `No agent to destroy, found '${typeof tempAgent}'->'${typeof tempAgent.destroy}':`, -+ tempAgent -+ ); -+ } - // @ts-ignore - (_a = this.agent) === null || _a === void 0 ? void 0 : _a.destroy(); - }; diff --git a/.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch b/.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch deleted file mode 100644 index 946777f134..0000000000 --- a/.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch +++ /dev/null @@ -1,36 +0,0 @@ -diff --git a/lib/node/chunk-CVV3L375.mjs b/lib/node/chunk-CVV3L375.mjs -index c37d61d709235efebe4ea19703a901bfbc05c9e3..4085c9b33075e18f7e4e3ad82fdd3fa5f6bb31e2 100644 ---- a/lib/node/chunk-CVV3L375.mjs -+++ b/lib/node/chunk-CVV3L375.mjs -@@ -540,6 +540,13 @@ var _NodeClientRequest = class extends ClientRequest { - * Terminates a pending request. - */ - terminate() { -+ const tempAgent = this.agent; -+ if (tempAgent && typeof tempAgent === 'object' && typeof tempAgent.destroy !== 'function') { -+ console.log( -+ `No agent to destroy, found '${typeof tempAgent}'->'${typeof tempAgent.destroy}':`, -+ tempAgent -+ ); -+ } - var _a; - (_a = this.agent) == null ? void 0 : _a.destroy(); - } -diff --git a/lib/node/chunk-SXGRMPXP.js b/lib/node/chunk-SXGRMPXP.js -index a5129f18a9b754acf2bfb3b1545df2378b01a95a..8228b6d4f649937559f45aefbdb8c8df275c5285 100644 ---- a/lib/node/chunk-SXGRMPXP.js -+++ b/lib/node/chunk-SXGRMPXP.js -@@ -540,6 +540,13 @@ var _NodeClientRequest = class extends _http.ClientRequest { - * Terminates a pending request. - */ - terminate() { -+ const tempAgent = this.agent; -+ if (tempAgent && typeof tempAgent === 'object' && typeof tempAgent.destroy !== 'function') { -+ console.log( -+ `No agent to destroy, found '${typeof tempAgent}'->'${typeof tempAgent.destroy}':`, -+ tempAgent -+ ); -+ } - var _a; - (_a = this.agent) == null ? void 0 : _a.destroy(); - } diff --git a/package.json b/package.json index 47dad4b2a2..59150dedc9 100644 --- a/package.json +++ b/package.json @@ -87,8 +87,6 @@ "@changesets/assemble-release-plan@^6.0.0": "patch:@changesets/assemble-release-plan@npm%3A6.0.0#./.yarn/patches/@changesets-assemble-release-plan-npm-6.0.0-f7b3005037.patch", "@material-ui/pickers@^3.2.10": "patch:@material-ui/pickers@npm%3A3.3.11#./.yarn/patches/@material-ui-pickers-npm-3.3.11-1c8f68ea20.patch", "@material-ui/pickers@^3.3.10": "patch:@material-ui/pickers@npm%3A3.3.11#./.yarn/patches/@material-ui-pickers-npm-3.3.11-1c8f68ea20.patch", - "@mswjs/interceptors@^0.17.10": "patch:@mswjs/interceptors@npm%3A0.17.10#.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch", - "@mswjs/interceptors@^0.29.0": "patch:@mswjs/interceptors@npm%3A0.29.1#./.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch", "@types/react": "^18", "@types/react-dom": "^18", "jest-haste-map@^29.7.0": "patch:jest-haste-map@npm%3A29.7.0#./.yarn/patches/jest-haste-map-npm-29.7.0-e3be419eff.patch" diff --git a/yarn.lock b/yarn.lock index 2b8090e00d..dd05b8d157 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10782,7 +10782,7 @@ __metadata: languageName: node linkType: hard -"@mswjs/interceptors@npm:0.17.10": +"@mswjs/interceptors@npm:^0.17.10": version: 0.17.10 resolution: "@mswjs/interceptors@npm:0.17.10" dependencies: @@ -10798,7 +10798,7 @@ __metadata: languageName: node linkType: hard -"@mswjs/interceptors@npm:0.29.1": +"@mswjs/interceptors@npm:^0.29.0": version: 0.29.1 resolution: "@mswjs/interceptors@npm:0.29.1" dependencies: @@ -10812,36 +10812,6 @@ __metadata: languageName: node linkType: hard -"@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.17.10#.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch::locator=root%40workspace%3A.": - version: 0.17.10 - resolution: "@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.17.10#.yarn/patches/@mswjs-interceptors-npm-0.17.10-c1199a9424.patch::version=0.17.10&hash=652df3&locator=root%40workspace%3A." - dependencies: - "@open-draft/until": ^1.0.3 - "@types/debug": ^4.1.7 - "@xmldom/xmldom": ^0.8.3 - debug: ^4.3.3 - headers-polyfill: 3.2.5 - outvariant: ^1.2.1 - strict-event-emitter: ^0.2.4 - web-encoding: ^1.1.5 - checksum: 32ca2f2d4e8bc46e1f773ca440a0ec5ba9c69ea4d89c07fbd25a0fde73627a232eb7d0cf3ce426fbe1fd58863ab9c84386352ecdc55eeb2a5240ba126c0ba6f0 - languageName: node - linkType: hard - -"@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.29.1#./.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch::locator=root%40workspace%3A.": - version: 0.29.1 - resolution: "@mswjs/interceptors@patch:@mswjs/interceptors@npm%3A0.29.1#./.yarn/patches/@mswjs-interceptors-npm-0.29.1-b5be72ad54.patch::version=0.29.1&hash=d6ea98&locator=root%40workspace%3A." - dependencies: - "@open-draft/deferred-promise": ^2.2.0 - "@open-draft/logger": ^0.3.0 - "@open-draft/until": ^2.0.0 - is-node-process: ^1.2.0 - outvariant: ^1.2.1 - strict-event-emitter: ^0.5.1 - checksum: d7ce191736c8b5df2dcdb36d11dbf25ca37cd3c0d1319cf8594713c443c5bdf733c2aeb4863aba646a67b50813e64dc1b13fbd31cee238cc4c9f8a8fd2908486 - languageName: node - linkType: hard - "@mui/base@npm:5.0.0-beta.40": version: 5.0.0-beta.40 resolution: "@mui/base@npm:5.0.0-beta.40"