Skip to content

Commit f082d40

Browse files
authored
chore: remove proxyquire-bun-shim.cjs and runner flags (#9646)
## Description Removes bin/proxyquire-bun-shim.cjs and all remaining Mocha and runner shim configuration. ## Impact Eliminates the global Bun proxyquire preload shim from the test runner. ## Changes - **Part 5 of 5 in stacked PR series**: #9642 -> #9643 -> #9644 -> #9645 -> **#9646** (b/570680750). - Stacked on #9645. - Delete `bin/proxyquire-bun-shim.cjs`. - Remove `--proxyquire-shim`, `BUN_ENABLE_PROXYQUIRE_SHIM`, and `proxyquire-bun-shim.cjs` preloading from `bin/run-test.cjs`. - Remove `proxyquire-bun-shim.cjs` from `.mocharc.cjs` and all 11 `core/packages/*/.mocharc.js` configuration files. ## Testing - Verified unit tests across all migrated packages pass under both Node.js and Bun (`JS_RUNTIME=bun`) without `bin/proxyquire-bun-shim.cjs`. - Verified strict lint and type checks pass via `bin/linter.mjs --strict`. ## Alternatives - Not merging this pull request was considered, which would leave dead shim code and unused `--proxyquire-shim` runner flags in the repository.
1 parent 455d228 commit f082d40

15 files changed

Lines changed: 9 additions & 275 deletions

File tree

‎.mocharc.cjs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
const path = require('path');
16-
1715
const config = {
1816
"enable-source-maps": true,
1917
"throw-deprecation": true,
@@ -28,7 +26,6 @@ if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2826
config.parallel = false;
2927
}
3028
if (typeof Bun !== 'undefined') {
31-
config.require = [path.resolve(__dirname, 'bin/proxyquire-bun-shim.cjs')];
3229
config.exit = true;
3330
}
3431
if (process.env.MOCHA_REPORTER) {

‎bin/proxyquire-bun-shim.cjs‎

Lines changed: 0 additions & 189 deletions
This file was deleted.

‎bin/run-test.cjs‎

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
// coverage and Mocha worker-thread parallelism (`parallel: true`).
2121
// - Under Bun (`typeof Bun !== 'undefined'` or `JS_RUNTIME === 'bun'`):
2222
// Skips `c8` (which relies on Node's `NODE_V8_COVERAGE`), disables Mocha
23-
// worker-thread parallelism (`--no-parallel`), preloads the Bun `proxyquire`
24-
// shim (`bin/proxyquire-bun-shim.cjs`) when `--proxyquire-shim` is passed,
25-
// and loads `mocha/bin/mocha.js` directly in-process so `#!/usr/bin/env node`
26-
// shebangs never switch back to Node.js.
23+
// worker-thread parallelism (`--no-parallel`), and loads `mocha/bin/mocha.js`
24+
// directly in-process so `#!/usr/bin/env node` shebangs never switch back to
25+
// Node.js.
2726
'use strict';
2827

2928
const {spawnSync} = require('child_process');
@@ -32,26 +31,7 @@ const fs = require('fs');
3231

3332
const rawArgs = process.argv.slice(2);
3433
const noC8 = rawArgs.includes('--no-c8');
35-
36-
const SHIM_FLAGS = [
37-
{
38-
flag: '--proxyquire-shim',
39-
envIn: 'BUN_PROXYQUIRE_SHIM',
40-
envOut: 'BUN_ENABLE_PROXYQUIRE_SHIM',
41-
},
42-
];
43-
44-
const shimFlagSet = new Set(SHIM_FLAGS.map(s => s.flag));
45-
const shimEnvVars = {};
46-
for (const {flag, envIn, envOut} of SHIM_FLAGS) {
47-
const enabled =
48-
rawArgs.includes(flag) ||
49-
process.env[envIn] === 'true' ||
50-
process.env[envOut] === 'true';
51-
shimEnvVars[envOut] = enabled ? 'true' : 'false';
52-
}
53-
54-
const args = rawArgs.filter(a => a !== '--no-c8' && !shimFlagSet.has(a));
34+
const args = rawArgs.filter(a => a !== '--no-c8');
5535

5636
const isBunRuntime = typeof Bun !== 'undefined';
5737
const isBunUserAgent = /^bun\//i.test(process.env.npm_config_user_agent || '');
@@ -650,7 +630,6 @@ if (require.main === module) {
650630

651631
if (wantsBunRuntime) {
652632
process.env.MOCHA_PARALLEL = 'false';
653-
Object.assign(process.env, shimEnvVars);
654633

655634
// If Bun was requested (via JS_RUNTIME=bun or `bun run test`) but this
656635
// script was launched via Node.js, re-exec under the `bun` binary.
@@ -660,7 +639,6 @@ if (require.main === module) {
660639
env: {
661640
...process.env,
662641
MOCHA_PARALLEL: 'false',
663-
...shimEnvVars,
664642
},
665643
});
666644
if (res.error) {
@@ -678,15 +656,6 @@ if (require.main === module) {
678656
mochaArgs.unshift('--no-parallel');
679657
}
680658

681-
// Only preload the proxyquire shim when `--proxyquire-shim` is requested.
682-
if (shimEnvVars.BUN_ENABLE_PROXYQUIRE_SHIM === 'true') {
683-
const shimPath = path.resolve(__dirname, 'proxyquire-bun-shim.cjs');
684-
require(shimPath);
685-
if (!mochaArgs.includes(shimPath)) {
686-
mochaArgs.unshift('--require', shimPath);
687-
}
688-
}
689-
690659
if (!mochaArgs.includes('--exit')) {
691660
mochaArgs.unshift('--exit');
692661
}

‎core/packages/gapic-node-processing/.mocharc.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
const path = require('path');
1514
const config = {
1615
"enable-source-maps": true,
1716
"throw-deprecation": true,
@@ -24,9 +23,6 @@ if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
2423
if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2524
config.parallel = false;
2625
}
27-
if (typeof Bun !== 'undefined') {
28-
config.require = [path.resolve(__dirname, '../../../bin/proxyquire-bun-shim.cjs')];
29-
}
3026
if (process.env.MOCHA_REPORTER) {
3127
config.reporter = process.env.MOCHA_REPORTER;
3228
}

‎core/packages/gax/.mocharc.js‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
const path = require('path');
1514
const config = {
1615
"enable-source-maps": true,
1716
"throw-deprecation": true,
@@ -24,10 +23,6 @@ if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
2423
if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2524
config.parallel = false;
2625
}
27-
if (typeof Bun !== 'undefined') {
28-
// Preload Bun compatibility shim for proxyquire and nock when running under Bun
29-
config.require = [path.resolve(__dirname, '../../../bin/proxyquire-bun-shim.cjs')];
30-
}
3126
if (process.env.MOCHA_REPORTER) {
3227
config.reporter = process.env.MOCHA_REPORTER;
3328
}

‎core/packages/gaxios/.mocharc.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
const path = require('path');
1514
const config = {
1615
"enable-source-maps": true,
1716
"throw-deprecation": true,
@@ -24,9 +23,6 @@ if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
2423
if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2524
config.parallel = false;
2625
}
27-
if (typeof Bun !== 'undefined') {
28-
config.require = [path.resolve(__dirname, '../../../bin/proxyquire-bun-shim.cjs')];
29-
}
3026
if (process.env.MOCHA_REPORTER) {
3127
config.reporter = process.env.MOCHA_REPORTER;
3228
}

‎core/packages/gcp-metadata/.mocharc.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
const path = require('path');
1514
const config = {
1615
"enable-source-maps": true,
1716
"throw-deprecation": true,
@@ -24,9 +23,6 @@ if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
2423
if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2524
config.parallel = false;
2625
}
27-
if (typeof Bun !== 'undefined') {
28-
config.require = [path.resolve(__dirname, '../../../bin/proxyquire-bun-shim.cjs')];
29-
}
3026
if (process.env.MOCHA_REPORTER) {
3127
config.reporter = process.env.MOCHA_REPORTER;
3228
}

‎core/packages/google-auth-library-nodejs/.mocharc.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
const path = require('path');
1514
const config = {
1615
"enable-source-maps": true,
1716
"throw-deprecation": true,
@@ -24,9 +23,6 @@ if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
2423
if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2524
config.parallel = false;
2625
}
27-
if (typeof Bun !== 'undefined') {
28-
config.require = [path.resolve(__dirname, '../../../bin/proxyquire-bun-shim.cjs')];
29-
}
3026
if (process.env.MOCHA_REPORTER) {
3127
config.reporter = process.env.MOCHA_REPORTER;
3228
}

‎core/packages/nodejs-googleapis-common/.mocharc.js‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14-
const path = require('path');
1514
const config = {
1615
"enable-source-maps": true,
1716
"throw-deprecation": true,
@@ -24,9 +23,6 @@ if (process.env.MOCHA_THROW_DEPRECATION === 'false') {
2423
if (process.env.MOCHA_PARALLEL === 'false' || typeof Bun !== 'undefined') {
2524
config.parallel = false;
2625
}
27-
if (typeof Bun !== 'undefined') {
28-
config.require = [path.resolve(__dirname, '../../../bin/proxyquire-bun-shim.cjs')];
29-
}
3026
if (process.env.MOCHA_REPORTER) {
3127
config.reporter = process.env.MOCHA_REPORTER;
3228
}

0 commit comments

Comments
 (0)