Skip to content

Commit 336d4d8

Browse files
rwjblueRobert Jackson
authored andcommitted
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. (cherry picked from commit 957dbc6)
1 parent 41afd22 commit 336d4d8

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
@@ -130,11 +130,21 @@ function getTemplateCompiler(templateCompilerPath, EmberENV = {}) {
130130
// the shared global config
131131
let clonedEmberENV = JSON.parse(JSON.stringify(EmberENV));
132132

133-
let context = vm.createContext({
133+
let sandbox = {
134134
EmberENV: clonedEmberENV,
135135
module: { require, exports: {} },
136136
require,
137-
});
137+
};
138+
139+
// if we are running on a Node version _without_ a globalThis
140+
// we must provide a `global`
141+
//
142+
// this is due to https://git.io/Jtb7s (Ember 3.27+)
143+
if (typeof globalThis === 'undefined') {
144+
sandbox.global = sandbox;
145+
}
146+
147+
let context = vm.createContext(sandbox);
138148

139149
script.runInContext(context);
140150

0 commit comments

Comments
 (0)