forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-cli-build.js
304 lines (270 loc) · 8.71 KB
/
ember-cli-build.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
'use strict';
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const babelHelpers = require('./broccoli/babel-helpers');
const concatBundle = require('./lib/concat-bundle');
const testIndexHTML = require('./broccoli/test-index-html');
const rollupPackage = require('./broccoli/rollup-package');
const minify = require('./broccoli/minify');
const debugTree = require('broccoli-debug').buildDebugCallback('ember-source:ember-cli-build');
Error.stackTraceLimit = Infinity;
const {
routerES,
loader,
qunit,
handlebarsES,
rsvpES,
simpleHTMLTokenizerES,
backburnerES,
dagES,
routeRecognizerES,
glimmerES,
glimmerCompilerES,
emberVersionES,
emberLicense,
getPackagesES,
} = require('./broccoli/packages');
const { allSupportedBrowsers, modernBrowsers } = require('./config/browserlists');
const ENV = process.env.EMBER_ENV || 'development';
const SHOULD_ROLLUP = process.env.SHOULD_ROLLUP !== 'false';
const SHOULD_MINIFY = Boolean(process.env.SHOULD_MINIFY);
/**
* There isn't a way for us to override targets through ember-cli-babel, and we
* don't want to introduce that functionality for reasons. This is a quick and
* dirty way for us to accomplish custom targets. This is specifically for:
*
* 1. The ember-template-compiler.js file, which should always be built for all
* of our supported browsers.
* 2. The ember.debug.js file, which should always be built for modern browsers.
*
* This is not a recommended way of building standard Ember apps.
*/
function withTargets(project, fn) {
return (tree, isProduction = ENV === 'production', { targets } = {}) => {
let originalTargets = project.targets;
if (targets !== undefined) project._targets = targets;
let transpiled = fn(tree, isProduction);
project._targets = originalTargets;
return transpiled;
};
}
module.exports = function ({ project }) {
let emberSource = project.addons.find((a) => a.name === 'ember-source');
let transpileTree = withTargets(project, emberSource.transpileTree.bind(emberSource));
let emberBundles = withTargets(project, emberSource.buildEmberBundles.bind(emberSource));
let packages = debugTree(
new MergeTrees(
[
// packages/** (after typescript compilation)
getPackagesES(),
emberVersionES(),
// externalized helpers
babelHelpers(),
],
{
// we're replacing the ember/verion file with the actual version number
overwrite: true,
}
),
'packages:initial'
);
// Rollup
if (SHOULD_ROLLUP) {
packages = debugTree(
new MergeTrees([
new Funnel(packages, {
exclude: [
'@ember/-internals/browser-environment/index.js',
'@ember/-internals/browser-environment/lib/**',
'@ember/-internals/container/index.js',
'@ember/-internals/container/lib/**',
'@ember/-internals/environment/index.js',
'@ember/-internals/environment/lib/**',
'@ember/-internals/glimmer/index.js',
'@ember/-internals/glimmer/lib/**',
'@ember/-internals/metal/index.js',
'@ember/-internals/metal/lib/**',
'@ember/-internals/utils/index.js',
'@ember/-internals/utils/lib/**',
],
}),
rollupPackage(packages, '@ember/-internals/browser-environment'),
rollupPackage(packages, '@ember/-internals/environment'),
rollupPackage(packages, '@ember/-internals/glimmer'),
rollupPackage(packages, '@ember/-internals/metal'),
rollupPackage(packages, '@ember/-internals/utils'),
rollupPackage(packages, '@ember/-internals/container'),
]),
'packages:rollup'
);
}
let dist = debugTree(
new MergeTrees([
new Funnel(packages, {
destDir: 'packages',
exclude: [
'**/package.json',
'@ember/-internals/*/tests/**' /* internal packages */,
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'@ember/-internals/*/type-tests/**' /* internal packages */,
'*/*/type-tests/**' /* scoped packages */,
'*/type-tests/**' /* packages */,
'ember-template-compiler/**',
'internal-test-helpers/**',
],
}),
new Funnel(emberHeaderFiles(), { destDir: 'header' }),
new Funnel(emberDependencies(ENV), { destDir: 'dependencies' }),
]),
'dist'
);
// Test builds, tests, and test harness
let testFiles = debugTree(
new Funnel(
new MergeTrees([
emberBundles(dist),
testsBundle(packages, ENV, transpileTree),
testHarness(),
]),
{
destDir: 'tests',
}
),
'testFiles'
);
let preBuilt = debugTree(
new Funnel(emberBundles(dist, false, { targets: modernBrowsers, loose: false }), {
getDestinationPath(path) {
return path.replace('ember.', 'ember.debug.');
},
}),
'preBuilt'
);
if (SHOULD_MINIFY) {
preBuilt = minify(preBuilt);
}
return new MergeTrees([
// Distributed files
dist,
// Pre-built bundles
preBuilt,
debugTree(templateCompilerBundle(packages, transpileTree), 'template-compiler'),
testFiles,
]);
};
function emberDependencies(environment) {
// generate "loose" ES<latest> modules...
return debugTree(
new MergeTrees([
backburnerES(),
rsvpES(),
dagES(),
routerES(),
routeRecognizerES(),
glimmerES(environment),
]),
'dependencies'
);
}
function testsBundle(emberPackages, env, transpileTree) {
let exclude = env === 'production' ? ['@ember/debug/tests/**', 'ember-testing/tests/**'] : [];
let emberTestsFiles = transpileTree(
new MergeTrees([
new Funnel(emberPackages, {
include: [
'internal-test-helpers/**',
'@ember/-internals/*/tests/**' /* internal packages */,
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'ember-template-compiler/**',
],
exclude,
}),
])
);
return concatBundle(new MergeTrees([emberTestsFiles, emberHeaderFiles()]), {
outputFile: 'ember-tests.js',
});
}
function templateCompilerBundle(emberPackages, transpileTree) {
let templateCompilerFiles = transpileTree(
new MergeTrees([
new Funnel(emberPackages, {
include: [
'@ember/-internals/utils/**',
'@ember/-internals/environment/**',
'@ember/-internals/browser-environment/**',
'@ember/canary-features/**',
'@ember/debug/**',
'@ember/deprecated-features/**',
'ember/version.js',
'ember-babel.js',
'ember-template-compiler/**',
'node-module/**',
],
exclude: [
'@ember/-internals/*/tests/**' /* internal packages */,
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'*/*/type-tests/**' /* scoped packages */,
'*/type-tests/**' /* packages */,
],
}),
templateCompilerDependencies(),
]),
false,
{ targets: allSupportedBrowsers, loose: false }
);
return concatBundle(new MergeTrees([templateCompilerFiles, emberHeaderFiles()]), {
outputFile: 'ember-template-compiler.js',
footer: `
try {
// in the browser, the ember-template-compiler.js and ember.js bundles find each other via globalThis.require.
require('@ember/template-compilation');
} catch (err) {
// in node, that coordination is a no-op
define('@ember/template-compilation', ['exports'], function (e) {
e.__registerTemplateCompiler = function () {};
});
define('ember', [
'exports',
'@ember/-internals/environment',
'@ember/canary-features',
'ember/version',
], function (e, env, fea, ver) {
e.default = {
ENV: env.ENV,
FEATURES: fea.FEATURES,
VERSION: ver.default,
};
});
define('@ember/-internals/glimmer', ['exports'], function(e) {
e.template = undefined;
});
define('@ember/application', ['exports'], function(e) {});
}
(function (m) {
if (typeof module === 'object' && module.exports) {
module.exports = m;
}
})(require('ember-template-compiler'));
`,
});
}
function testHarness() {
return new MergeTrees([emptyTestem(), testIndexHTML(), loader(), qunit()]);
}
function emptyTestem() {
return new Funnel('tests', {
files: ['testem.js'],
destDir: '',
annotation: 'tests/testem.js',
});
}
function templateCompilerDependencies() {
return new MergeTrees([simpleHTMLTokenizerES(), handlebarsES(), glimmerCompilerES()]);
}
function emberHeaderFiles() {
return new MergeTrees([emberLicense(), loader()]);
}