Skip to content

Commit c0a639b

Browse files
committed
Conditionally use the esm package as a fallback, rather than default
1 parent 8401494 commit c0a639b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

lib/load_brocfile.ts

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import path from 'path';
22
import findup from 'findup-sync';
3-
import esm from 'esm';
4-
5-
const esmRequire = esm(module);
63

74
interface LoadBrocfileOptions {
85
brocfilePath?: string;
@@ -37,8 +34,22 @@ function requireBrocfile(brocfilePath: string) {
3734
// Load brocfile via ts-node
3835
brocfile = require(brocfilePath);
3936
} else {
37+
/**
38+
* because 'esm' patches global modules,
39+
* let's only load 'esm' if we absolutely have to.
40+
* See context: https://github.com/broccolijs/broccoli/issues/498
41+
* (and related linkes)
42+
*/
43+
try {
44+
brocfile = require(brocfilePath);
45+
} catch {
46+
// eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-missing-require
47+
const esm = require('esm');
48+
const esmRequire = esm(module);
49+
50+
brocfile = esmRequire(brocfilePath);
51+
}
4052
// Load brocfile via esm shim
41-
brocfile = esmRequire(brocfilePath);
4253
}
4354

4455
// ESM `export default X` is represented as module.exports = { default: X }

0 commit comments

Comments
 (0)