forked from emberjs/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
206 lines (164 loc) · 6.32 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
/* 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');
// 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;
}
module.exports = {
name: 'ember-data',
_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);
}
},
init() {
this._super.init && this._super.init.apply(this, arguments);
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); }
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() ? '-debug' : false
].filter(Boolean),
destDir: 'ember-data'
});
let privateTree = babel.transpileTree(withPrivate, {
babel: this.buildBabelOptions(),
'ember-cli-babel': {
compileModules: false
}
});
// use the default options
let publicTree = babel.transpileTree(withoutPrivate);
privateTree = new Rollup(privateTree, {
rollup: {
entry: '-private/index.js',
targets: [
{ dest: '-private.js', format: 'amd', moduleId: 'ember-data/-private' }
],
external: [
'ember',
'ember-inflector',
'ember-data/version',
'ember-data/-debug',
'ember-data/adapters/errors'
]
// cache: true|false Defaults to true
}
});
// the output of treeForAddon is required to be modules/<your files>
publicTree = new Funnel(publicTree, { destDir: 'modules' });
privateTree = new Funnel(privateTree, { destDir: 'modules' });
return merge([
publicTree,
privateTree
]);
},
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'
});
}
}
};