forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
245 lines (192 loc) · 7.82 KB
/
index.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
/* eslint-env node */
'use strict';
const path = require('path');
const SilentError = require('silent-error');
const Funnel = require('broccoli-funnel');
const Rollup = require('broccoli-rollup');
const Babel = require('broccoli-babel-transpiler');
const merge = require('broccoli-merge-trees');
const semver = require('semver');
const version = require('./lib/version');
const BroccoliDebug = require('broccoli-debug');
const calculateCacheKeyForTree = require('calculate-cache-key-for-tree');
// allow toggling of heimdall instrumentation
let INSTRUMENT_HEIMDALL = false;
let args = process.argv;
for (let i = 1; i < args.length; i++) {
if (args[i] === '--instrument') {
INSTRUMENT_HEIMDALL = true;
break;
}
}
const NOOP_TREE = function(dir) {
return { inputTree: dir, rebuild() { return []; } };
};
process.env.INSTRUMENT_HEIMDALL = INSTRUMENT_HEIMDALL;
function isProductionEnv() {
let isProd = /production/.test(process.env.EMBER_ENV);
let isTest = process.env.EMBER_CLI_TEST_COMMAND;
return isProd && !isTest;
}
function isInstrumentedBuild() {
return INSTRUMENT_HEIMDALL;
}
module.exports = {
name: 'ember-data',
_prodLikeWarning() {
let emberEnv = process.env.EMBER_ENV
if(emberEnv !== 'production' && /production/.test(emberEnv)) {
this._warn(`Production-like values for EMBER_ENV are deprecated (your EMBER_ENV is "${emberEnv}") and support will be removed in Ember Data 4.0.0. If using ember-cli-deploy, please configure your build using 'production'. Otherwise please set your EMBER_ENV to 'production' for production builds.`);
}
},
_warn(message) {
let chalk = require('chalk');
let warning = chalk.yellow('WARNING: ' + message);
if (this.ui && this.ui.writeWarnLine) {
this.ui.writeWarnLine(message);
} else if (this.ui) {
this.ui.writeLine(warning);
} else {
console.log(warning);
}
},
getOutputDirForVersion() {
let VersionChecker = require('ember-cli-version-checker');
let checker = new VersionChecker(this);
let emberCli = checker.for('ember-cli', 'npm');
let requiresModulesDir = emberCli.satisfies('< 3.0.0');
return requiresModulesDir ? 'modules' : '';
},
init() {
this._super.init && this._super.init.apply(this, arguments);
this._prodLikeWarning();
this.debugTree = BroccoliDebug.buildDebugCallback('ember-data');
let bowerDeps = this.project.bowerDependencies();
let VersionChecker = require('ember-cli-version-checker');
let options = this.options = this.options || {};
let checker = new VersionChecker(this);
// prevent errors when ember-cli-shims is no longer required
let shims = bowerDeps['ember-cli-shims'] && checker.for('ember-cli-shims', 'bower');
let version = require('./package').version;
if (process.env.EMBER_DATA_SKIP_VERSION_CHECKING_DO_NOT_USE_THIS_ENV_VARIABLE) {
// Skip for node tests as we can't currently override the version of ember-cli-shims
// before the test helpers run.
return;
}
let hasShims = !!shims;
let shimsHasEmberDataShims = hasShims && shims.satisfies('< 0.1.0');
let emberDataNPMWithShimsIncluded = semver.satisfies(version, '^2.3.0-beta.3');
if (bowerDeps['ember-data']) {
this._warn('Please remove `ember-data` from `bower.json`. As of Ember Data 2.3.0, only the NPM package is needed. If you need an ' +
'earlier version of ember-data (< 2.3.0), you can leave this unchanged for now, but we strongly suggest you upgrade your version of Ember Data ' +
'as soon as possible.');
this._forceBowerUsage = true;
let emberDataBower = checker.for('ember-data', 'bower');
let emberDataBowerWithShimsIncluded = emberDataBower.satisfies('>= 2.3.0-beta.3');
if (hasShims && !shimsHasEmberDataShims && !emberDataBowerWithShimsIncluded) {
throw new SilentError('Using a version of ember-cli-shims greater than or equal to 0.1.0 will cause errors while loading Ember Data < 2.3.0-beta.3 Please update ember-cli-shims from ' + shims.version + ' to 0.0.6');
}
if (hasShims && shimsHasEmberDataShims && !emberDataBowerWithShimsIncluded) {
throw new SilentError('Using a version of ember-cli-shims prior to 0.1.0 will cause errors while loading Ember Data 2.3.0-beta.3+. Please update ember-cli-shims from ' + shims.version + ' to 0.1.0.');
}
} else {
// NPM only, but ember-cli-shims does not match
if (hasShims && shimsHasEmberDataShims && emberDataNPMWithShimsIncluded) {
throw new SilentError('Using a version of ember-cli-shims prior to 0.1.0 will cause errors while loading Ember Data 2.3.0-beta.3+. Please update ember-cli-shims from ' + shims.version + ' to 0.1.0.');
}
}
},
blueprintsPath() {
return path.join(__dirname, 'blueprints');
},
treeForApp(dir) {
if (this._forceBowerUsage) { return NOOP_TREE(dir); }
// this._super.treeForApp is undefined in ember-cli (1.13) for some reason.
// TODO: investigate why treeForApp isn't on _super
return dir;
},
treeForAddon(tree) {
if (this._forceBowerUsage) { return NOOP_TREE(tree); }
tree = this.debugTree(tree, 'input');
let babel = this.addons.find(addon => addon.name === 'ember-cli-babel');
let treeWithVersion = merge([
tree,
version() // compile the VERSION into the build
]);
let withPrivate = new Funnel(tree, { include: ['-private/**'] });
let withoutPrivate = new Funnel(treeWithVersion, {
exclude: [
'-private',
isProductionEnv() && !isInstrumentedBuild() ? '-debug' : false
].filter(Boolean),
destDir: 'ember-data'
});
let privateTree = babel.transpileTree(this.debugTree(withPrivate, 'babel-private:input'), {
babel: this.buildBabelOptions(),
'ember-cli-babel': {
compileModules: false
}
});
privateTree = this.debugTree(privateTree, 'babel-private:output');
// use the default options
let publicTree = babel.transpileTree(this.debugTree(withoutPrivate, 'babel-public:input'));
publicTree = this.debugTree(publicTree, 'babel-public:output');
privateTree = new Rollup(privateTree, {
rollup: {
entry: '-private/index.js',
targets: [
{ dest: 'ember-data/-private.js', format: babel.shouldCompileModules() ? 'amd' : 'es', moduleId: 'ember-data/-private' }
],
external: [
'ember',
'ember-inflector',
'ember-data/version',
'ember-data/-debug',
'ember-data/adapters/errors',
'@ember/ordered-set'
]
// cache: true|false Defaults to true
}
});
privateTree = this.debugTree(privateTree, 'rollup-output');
let destDir = this.getOutputDirForVersion();
publicTree = new Funnel(publicTree, { destDir });
privateTree = new Funnel(privateTree, { destDir });
return this.debugTree(merge([
publicTree,
privateTree
]), 'final');
},
buildBabelOptions() {
let customPlugins = require('./lib/stripped-build-plugins')(process.env.EMBER_ENV);
return {
loose: true,
plugins: customPlugins.plugins,
postTransformPlugins: customPlugins.postTransformPlugins,
exclude: [
'transform-es2015-block-scoping',
'transform-es2015-typeof-symbol'
]
};
},
_setupBabelOptions() {
if (this._hasSetupBabelOptions) {
return;
}
this.options.babel = this.buildBabelOptions();
this._hasSetupBabelOptions = true;
},
included(app) {
this._super.included.apply(this, arguments);
this._setupBabelOptions();
if (this._forceBowerUsage) {
this.app.import({
development: app.bowerDirectory + '/ember-data/ember-data.js',
production: app.bowerDirectory + '/ember-data/ember-data.prod.js'
});
}
},
cacheKeyForTree(treeType) {
return calculateCacheKeyForTree(treeType, this);
}
};