Skip to content

Commit 957dbc6

Browse files
committed
Ensure Ember 3.27+ can determine global for template compilation.
Node 12+ has access to `globalThis` (including within a VM context), but older versions do not. Due to the detection done in https://git.io/Jtb7s, when we can't find `globalThis` (and don't define `global` global) evaluating `ember-template-compiler.js` throws an error "unable to locate global object". This ensures that either `globalThis` or `global` are defined.
1 parent 20184be commit 957dbc6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/utils.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,21 @@ function getTemplateCompiler(templateCompilerPath, EmberENV = {}) {
143143
// the shared global config
144144
let clonedEmberENV = JSON.parse(JSON.stringify(EmberENV));
145145

146-
let context = vm.createContext({
146+
let sandbox = {
147147
EmberENV: clonedEmberENV,
148148
module: { require, exports: {} },
149149
require,
150-
});
150+
};
151+
152+
// if we are running on a Node version _without_ a globalThis
153+
// we must provide a `global`
154+
//
155+
// this is due to https://git.io/Jtb7s (Ember 3.27+)
156+
if (typeof globalThis === 'undefined') {
157+
sandbox.global = sandbox;
158+
}
159+
160+
let context = vm.createContext(sandbox);
151161

152162
script.runInContext(context);
153163

0 commit comments

Comments
 (0)