forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ember-cli-build.js
353 lines (311 loc) · 10.4 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
'use strict';
const path = require('path');
const MergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const Rollup = require('broccoli-rollup');
const babelHelpers = require('./broccoli/babel-helpers');
const bootstrapModule = require('./broccoli/bootstrap-modules');
const concatBundle = require('./broccoli/concat-bundle');
const concat = require('broccoli-concat');
const testIndexHTML = require('./broccoli/test-index-html');
const testPolyfills = require('./broccoli/test-polyfills');
const toES5 = require('./broccoli/to-es5');
const toNamedAMD = require('./broccoli/to-named-amd');
const stripForProd = require('./broccoli/strip-for-prod');
const debugMacros = require('./broccoli/debug-macros');
const minify = require('./broccoli/minify');
const rename = require('./broccoli/rename');
const testBabelPluginsTransform = require('./broccoli/transforms/test-babel-plugins');
const {
routerES,
jquery,
internalLoader,
qunit,
handlebarsES,
rsvpES,
simpleHTMLTokenizerES,
backburnerES,
dagES,
routeRecognizerES,
glimmerTrees,
emberVersionES,
emberLicense,
nodeTests,
buildEmberEnvFlagsES,
getPackagesES,
} = require('./broccoli/packages');
const BroccoliDebug = require('broccoli-debug');
const ENV = process.env.EMBER_ENV || 'development';
let debugTree = BroccoliDebug.buildDebugCallback('ember-source:ember-cli-build');
module.exports = function() {
let loader = internalLoader();
// generate "loose" ES<latest> modules...
let dependenciesES = new MergeTrees([
backburnerES(),
rsvpES(),
dagES(),
routerES(),
routeRecognizerES(),
...glimmerDependenciesES(),
]);
let templateCompilerDependenciesES = new MergeTrees([
simpleHTMLTokenizerES(),
handlebarsES(),
...glimmerTrees(['@glimmer/compiler']),
]);
let packagesES = new MergeTrees([
// dynamically generated packages
emberVersionES(),
// packages/** (after typescript compilation)
getPackagesES(),
// externalized helpers
babelHelpers(),
]);
let es = new MergeTrees([packagesES, dependenciesES, templateCompilerDependenciesES], {
overwrite: true,
});
let pkgAndTestESInAMD = toNamedAMD(es);
let emberEnvFlagsDebug = toNamedAMD(buildEmberEnvFlagsES({ DEBUG: true }));
let pkgAndTestESBundleDebug = concat(
new MergeTrees([pkgAndTestESInAMD, loader, emberEnvFlagsDebug]),
{
headerFiles: ['loader.js'],
inputFiles: ['**/*.js'],
outputFile: 'ember-all.debug.js',
}
);
// Rollup
let packagesRollupES = new MergeTrees([
new Funnel(packagesES, {
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(packagesES, '@ember/-internals/browser-environment'),
rollupPackage(packagesES, '@ember/-internals/environment'),
rollupPackage(packagesES, '@ember/-internals/glimmer'),
rollupPackage(packagesES, '@ember/-internals/metal'),
rollupPackage(packagesES, '@ember/-internals/utils'),
rollupPackage(packagesES, '@ember/-internals/container'),
]);
// Bundling
let bundleTrees = [
buildBundles(packagesRollupES, dependenciesES, templateCompilerDependenciesES),
];
if (ENV === 'production') {
let bundlesES5 = buildBundles(
toES5(packagesRollupES),
toES5(dependenciesES),
toES5(templateCompilerDependenciesES)
);
bundleTrees.push(new Funnel(bundlesES5, { destDir: 'legacy' }));
}
let emberTestsEmptyTestem = new Funnel('tests', {
files: ['testem.js'],
destDir: '',
annotation: 'tests/testem.js',
});
return new MergeTrees([
new Funnel(es, { destDir: 'es' }),
...bundleTrees,
pkgAndTestESBundleDebug,
emberTestsEmptyTestem,
nodeTests(),
// test harness
testPolyfills(),
testIndexHTML(),
jquery(),
qunit(),
]);
};
function buildBundles(packagesES, dependenciesES, templateCompilerDependenciesES) {
let packagesDevES = debugMacros(packagesES, 'development');
let dependenciesDevES = debugMacros(dependenciesES, 'development');
let templateCompilerDependenciesDevES = debugMacros(
templateCompilerDependenciesES,
'development'
);
let emberDebugFiles = new MergeTrees([
new Funnel(packagesDevES, {
exclude: [
'@ember/-internals/*/tests/**' /* internal packages */,
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'ember-template-compiler/**',
'internal-test-helpers/**',
],
}),
dependenciesDevES,
bootstrapModule('sideeffects', 'ember'),
]);
let emberTestsFiles = new MergeTrees([
new Funnel(packagesDevES, {
include: [
'internal-test-helpers/**',
'@ember/-internals/*/tests/**' /* internal packages */,
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'license.js',
],
}),
bootstrapModule('empty'),
]);
let emberTestingFiles = new MergeTrees([
new Funnel(packagesDevES, {
include: [
'@ember/debug/lib/**',
'@ember/debug/index.js',
'ember-testing/index.js',
'ember-testing/lib/**',
'license.js',
],
}),
bootstrapModule('testing'),
]);
let templateCompilerFiles = new MergeTrees([
new Funnel(packagesDevES, {
include: [
'@ember/-internals/utils.js',
'@ember/-internals/environment.js',
'@ember/-internals/browser-environment.js',
'@ember/canary-features/**',
'@ember/debug/index.js',
'@ember/debug/lib/**',
'@ember/deprecated-features/**',
'@ember/error/index.js',
'@ember/polyfills/index.js',
'@ember/polyfills/lib/**',
'ember/version.js',
'ember-babel.js',
'ember-template-compiler/**',
'node-module/**',
],
}),
templateCompilerDependenciesDevES,
bootstrapModule('umd', 'ember-template-compiler'),
]);
let emberProdFiles, emberTestsProdFiles;
if (ENV === 'production') {
let packagesProdES = stripForProd(debugMacros(packagesES, 'production'));
let dependenciesProdES = stripForProd(debugMacros(dependenciesES, 'production'));
emberProdFiles = new MergeTrees([
new Funnel(packagesProdES, {
exclude: [
'@ember/-internals/*/tests/**' /* internal packages */,
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'ember-template-compiler/**',
'ember-testing/**',
'internal-test-helpers/**',
],
}),
dependenciesProdES,
bootstrapModule('sideeffects', 'ember'),
]);
emberTestsProdFiles = testBabelPluginsTransform(
MergeTrees([
new Funnel(packagesProdES, {
include: [
'@ember/-internals/*/tests/**' /* internal packages */,
'internal-test-helpers/**',
'*/*/tests/**' /* scoped packages */,
'*/tests/**' /* packages */,
'license.js',
],
exclude: ['@ember/debug/tests/**', 'ember-testing/tests/**'],
}),
bootstrapModule('empty'),
])
);
// apply the babel transforms for legacy tests
emberTestsFiles = testBabelPluginsTransform(emberTestsFiles);
// Note:
// We have to build custom production template compiler
// because we strip babel helpers in the prod build
templateCompilerFiles = stripForProd(templateCompilerFiles);
}
// Files that are prebuilt and should not be AMD transformed
let vendor = [internalLoader(), emberLicense()];
let emberProdBundle = emberProdFiles && buildBundle('ember.prod.js', emberProdFiles, vendor);
let emberMinBundle =
emberProdBundle && minify(rename(emberProdBundle, { 'ember.prod.js': 'ember.min.js' }));
let emberProdTestsBundle =
emberTestsProdFiles && buildBundle('ember-tests.prod.js', emberTestsProdFiles, vendor);
return new MergeTrees(
[
emberProdBundle,
process.env.DISABLE_MINIFICATION !== '1' && emberMinBundle,
emberProdTestsBundle,
buildBundle('ember.debug.js', emberDebugFiles, vendor),
buildBundle('ember-tests.js', emberTestsFiles, vendor),
buildBundle('ember-testing.js', emberTestingFiles, vendor),
buildBundle('ember-template-compiler.js', templateCompilerFiles, vendor),
].filter(Boolean)
);
}
function buildBundle(name, tree, extras) {
let bundleWithExtras = new MergeTrees([toNamedAMD(tree, true), ...extras]);
return concatBundle(bundleWithExtras, {
outputFile: name,
});
}
function glimmerDependenciesES() {
let glimmerEntries = ['@glimmer/node', '@glimmer/opcode-compiler', '@glimmer/runtime'];
if (ENV === 'development') {
let hasGlimmerDebug = true;
try {
require.resolve('@glimmer/debug');
} catch (e) {
hasGlimmerDebug = false;
}
if (hasGlimmerDebug) {
glimmerEntries.push('@glimmer/debug', '@glimmer/local-debug-flags');
}
}
return glimmerTrees(glimmerEntries);
}
function rollupPackage(packagesES, name) {
// this prevents broccoli-rollup from "seeing" changes in
// its input that are unrelated to what we are building
// and therefore noop on rebuilds...
let rollupRestrictedInput = new Funnel(packagesES, {
srcDir: name,
destDir: name,
});
rollupRestrictedInput = debugTree(rollupRestrictedInput, `rollup-package:${name}:input`);
let output = new Rollup(rollupRestrictedInput, {
annotation: `rollup ${name}`,
rollup: {
input: `${name}/index.js`,
external(importee, importer) {
// importer of null/undefined means entry module
if (!importer) {
return false;
}
// import is relative initially, then expanded to absolute
// when resolveId is called. this checks for either...
if (importee[0] === '.' || path.isAbsolute(importee)) {
return false;
}
return true;
},
output: {
file: `${name}.js`,
format: 'es',
exports: 'named',
},
},
});
return debugTree(output, `rollup-package:${name}:output`);
}