-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathload-ember.js
More file actions
49 lines (35 loc) · 1.54 KB
/
load-ember.js
File metadata and controls
49 lines (35 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const path = require('path');
const emberSourceRoot = path.dirname(require.resolve('ember-source/package.json'));
const distPath = path.join(emberSourceRoot, 'dist');
const emberPath = path.join(distPath, 'ember.debug.js');
const templateCompilerPath = path.join(distPath, 'ember-template-compiler');
// We store the global symbols beforehand so that we can reset the state
// properly to avoid the @glimmer/validator assertion
const originalGlobalSymbols = Object.getOwnPropertySymbols(global).map((sym) => [sym, global[sym]]);
module.exports.emberPath = require.resolve(emberPath);
module.exports.loadEmber = function () {
let Ember = require(emberPath);
let _precompile = require(templateCompilerPath).precompile;
let precompile = function (templateString, options) {
let templateSpec = _precompile(templateString, options);
return `Ember.HTMLBars.template(${templateSpec})`;
};
let compile = function (templateString, options) {
let templateSpec = _precompile(templateString, options);
let template = new Function('return ' + templateSpec)();
return Ember.HTMLBars.template(template);
};
return { Ember, compile, precompile };
};
module.exports.clearEmber = function () {
delete global.Ember;
Object.getOwnPropertySymbols(global).forEach((sym) => {
delete global[sym];
});
originalGlobalSymbols.forEach(([sym, value]) => {
global[sym] = value;
});
// clear the previously cached version of this module
delete require.cache[emberPath + '.js'];
delete require.cache[templateCompilerPath + '.js'];
};