|
1 | 1 | import path from 'path';
|
2 | 2 | import findup from 'findup-sync';
|
3 |
| -import esm from 'esm'; |
4 |
| - |
5 |
| -const esmRequire = esm(module); |
6 | 3 |
|
7 | 4 | interface LoadBrocfileOptions {
|
8 | 5 | brocfilePath?: string;
|
@@ -37,8 +34,29 @@ function requireBrocfile(brocfilePath: string) {
|
37 | 34 | // Load brocfile via ts-node
|
38 | 35 | brocfile = require(brocfilePath);
|
39 | 36 | } else {
|
40 |
| - // Load brocfile via esm shim |
41 |
| - brocfile = esmRequire(brocfilePath); |
| 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 | + * If this function (requireBrocfile) were to be async, we could use |
| 44 | + * await import here instead and get rid of the esm package altogether. |
| 45 | + * |
| 46 | + * However, it may mean that all of broccoli then needs to be converted to ESM (idk) |
| 47 | + * |
| 48 | + * Definitely, all of broccoli would need to be converted to async. |
| 49 | + * the CLI and brocifile loading is currently all sync. |
| 50 | + */ |
| 51 | + try { |
| 52 | + brocfile = require(brocfilePath); |
| 53 | + } catch { |
| 54 | + // eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-missing-require |
| 55 | + const esm = require('esm'); |
| 56 | + const esmRequire = esm(module); |
| 57 | + |
| 58 | + brocfile = esmRequire(brocfilePath); |
| 59 | + } |
42 | 60 | }
|
43 | 61 |
|
44 | 62 | // ESM `export default X` is represented as module.exports = { default: X }
|
|
0 commit comments