Skip to content

Commit a50332b

Browse files
committed
Improve the Embroider and non-Embroider stories
1 parent 2b37d81 commit a50332b

File tree

3 files changed

+87
-107
lines changed

3 files changed

+87
-107
lines changed

README.md

+31-6
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,43 @@ addressing a single deprecation at a time, and prevents backsliding
4343

4444
### Getting started
4545

46-
The initial steps needed to get started:
46+
#### Normal setup routine
4747

4848
1. Install the ember-cli-deprecation-workflow addon (`ember install ember-cli-deprecation-workflow`).
49-
3. Run your test suite\* with `ember test --server`.
50-
4. Navigate to your tests (default: http://localhost:7357/)
51-
5. Run `deprecationWorkflow.flushDeprecations()` from your browsers console.
52-
6. Copy the string output into `app/deprecation-workflow.js` in your project.
53-
7. In your `app/app.js`, do:
49+
2. Run your test suite\* with `ember test --server`.
50+
3. Navigate to your tests (default: http://localhost:7357/)
51+
4. Run `deprecationWorkflow.flushDeprecations()` from your browsers console.
52+
5. Copy the string output into a new `app/deprecation-workflow.js` file in your project.
53+
6. In your `app/app.js`, do:
54+
55+
```js
56+
import './deprecation-workflow';
57+
```
58+
59+
#### Setup routine for Embroider in strict mode
60+
61+
1. Install the ember-cli-deprecation-workflow addon (`ember install ember-cli-deprecation-workflow`).
62+
2. Create an `app/deprecation-workflow.js` file with the following content:
63+
64+
```js
65+
import setupDeprecationWorkflow from 'ember-cli-deprecation-workflow';
66+
67+
setupDeprecationWorkflow();
68+
```
69+
70+
3. In your `app/app.js`, do:
71+
5472
```js
5573
import './deprecation-workflow';
5674
```
5775

76+
4. Run your test suite\* with `ember test --server`.
77+
5. Navigate to your tests (default: http://localhost:7357/)
78+
6. Run `deprecationWorkflow.flushDeprecations()` in your browsers console.
79+
7. Copy the string output and overwrite the content of `app/deprecation-workflow.js`.
80+
81+
In Chrome, use right click → "Copy string contents" to avoid escape characters.
82+
5883
Once this initial setup is completed the "deprecation spew" should be largely
5984
"fixed". Only unhandled deprecations will be displayed in your console.
6085

index.js

+50
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,54 @@
22

33
module.exports = {
44
name: require('./package').name,
5+
6+
_shouldInclude() {
7+
// the presence of `this.app.tests` shows that we are in one of:
8+
//
9+
// * running non-production build
10+
// * running tests against production
11+
//
12+
var app = this.app || this._findHost();
13+
let addonOptions = app.options['ember-cli-deprecation-workflow'];
14+
15+
if (addonOptions) {
16+
return addonOptions.enabled;
17+
} else {
18+
return app.tests;
19+
}
20+
},
21+
22+
included() {
23+
// From https://github.com/rwjblue/ember-debug-handlers-polyfill/blob/master/index.js
24+
var app = this.app || this._findHost();
25+
26+
if (this._shouldInclude()) {
27+
app.import(
28+
'vendor/ember-cli-deprecation-workflow/deprecation-workflow.js',
29+
);
30+
app.import('vendor/ember-cli-deprecation-workflow/main.js');
31+
}
32+
},
33+
34+
treeForVendor(tree) {
35+
var root = process.env._DUMMY_CONFIG_ROOT_PATH || this.project.root;
36+
var configDir = '/config';
37+
38+
if (
39+
this.project.pkg['ember-addon'] &&
40+
this.project.pkg['ember-addon']['configPath']
41+
) {
42+
configDir = '/' + this.project.pkg['ember-addon']['configPath'];
43+
}
44+
45+
var mergeTrees = require('broccoli-merge-trees');
46+
var Funnel = require('broccoli-funnel');
47+
var configTree = new Funnel(root + configDir, {
48+
include: ['deprecation-workflow.js'],
49+
50+
destDir: 'ember-cli-deprecation-workflow',
51+
});
52+
53+
return mergeTrees([tree, configTree], { overwrite: true });
54+
},
555
};
+6-101
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,8 @@
1-
/* eslint-disable ember/new-module-imports, prettier/prettier */
2-
/* global require Ember */
1+
/* eslint-disable no-empty */
2+
/* global require */
33

4-
const LOG_LIMIT = 100;
5-
6-
(function(){
7-
self.deprecationWorkflow = self.deprecationWorkflow || {};
8-
self.deprecationWorkflow.deprecationLog = {
9-
messages: { }
10-
};
11-
self.deprecationWorkflow.logCounts = {};
12-
13-
function detectWorkflow(config, message, options) {
14-
if (!config || !config.workflow) {
15-
return;
16-
}
17-
18-
let i, workflow, matcher, idMatcher;
19-
for (i=0; i<config.workflow.length; i++) {
20-
workflow = config.workflow[i];
21-
matcher = workflow.matchMessage;
22-
idMatcher = workflow.matchId;
23-
24-
if (typeof idMatcher === 'string' && options && idMatcher === options.id) {
25-
return workflow;
26-
} else if (typeof matcher === 'string' && matcher === message) {
27-
return workflow;
28-
} else if (matcher instanceof RegExp && matcher.exec(message)) {
29-
return workflow;
30-
}
31-
}
32-
}
33-
34-
let registerDeprecationHandler = require.has('@ember/debug') ? require('@ember/debug').registerDeprecationHandler : Ember.Debug.registerDeprecationHandler;
35-
36-
registerDeprecationHandler(function handleDeprecationWorkflow(message, options, next){
37-
let config = self.deprecationWorkflow.config || {};
38-
39-
let matchingWorkflow = detectWorkflow(config, message, options);
40-
if (!matchingWorkflow) {
41-
if (config && config.throwOnUnhandled) {
42-
throw new Error(message);
43-
} else {
44-
next(message, options);
45-
}
46-
} else {
47-
switch(matchingWorkflow.handler) {
48-
case 'silence':
49-
// no-op
50-
break;
51-
case 'log': {
52-
let key = (options && options.id) || message;
53-
let count = self.deprecationWorkflow.logCounts[key] || 0;
54-
self.deprecationWorkflow.logCounts[key] = ++count;
55-
56-
if (count <= LOG_LIMIT) {
57-
console.warn('DEPRECATION: ' + message);
58-
if (count === LOG_LIMIT) {
59-
console.warn('To avoid console overflow, this deprecation will not be logged any more in this run.');
60-
}
61-
}
62-
63-
break;
64-
}
65-
case 'throw':
66-
throw new Error(message);
67-
default:
68-
next(message, options);
69-
break;
70-
}
71-
}
72-
});
73-
74-
registerDeprecationHandler(function deprecationCollector(message, options, next){
75-
let key = options && options.id || message;
76-
let matchKey = options && key === options.id ? 'matchId' : 'matchMessage';
77-
78-
self.deprecationWorkflow.deprecationLog.messages[key] = ' { handler: "silence", ' + matchKey + ': ' + JSON.stringify(key) + ' }';
79-
next(message, options);
80-
});
81-
82-
let preamble = [
83-
'self.deprecationWorkflow = self.deprecationWorkflow || {};',
84-
'self.deprecationWorkflow.config = {\n workflow: [\n',
85-
].join('\n');
86-
87-
let postamble = [
88-
' ]\n};'
89-
].join('\n');
90-
91-
self.deprecationWorkflow.flushDeprecations = function flushDeprecations() {
92-
let messages = self.deprecationWorkflow.deprecationLog.messages;
93-
let logs = [];
94-
95-
for (let message in messages) {
96-
logs.push(messages[message]);
97-
}
98-
99-
let deprecations = logs.join(',\n') + '\n';
100-
101-
return preamble + deprecations + postamble;
102-
};
4+
(function () {
5+
try {
6+
require('ember-cli-deprecation-workflow').default();
7+
} catch (e) {}
1038
})();

0 commit comments

Comments
 (0)