Skip to content

Commit 3ff8080

Browse files
author
Robert Jackson
authored
Merge pull request #305 from tildeio/debugging-info
Add better Transition debugging information.
2 parents cfe549c + 8c06ca9 commit 3ff8080

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

ember-cli-build.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,27 @@ function resolveRelativeModulePath(name, child) {
3737
resolveRelativeModulePath.baseDir = () => __dirname;
3838

3939
function toAMD(tree) {
40+
const isProduction = process.env.EMBER_ENV === 'production';
41+
const isDebug = !isProduction;
42+
4043
return new Babel(tree, {
4144
moduleIds: true,
4245
getModuleId: getRelativeModulePath,
4346
plugins: [
4447
['module-resolver', { resolvePath: resolveRelativeModulePath }],
4548
['@babel/plugin-transform-modules-amd', { noInterop: true }],
49+
[
50+
'babel-plugin-debug-macros',
51+
{
52+
flags: [
53+
{
54+
source: '@glimmer/env',
55+
flags: { DEBUG: isDebug, CI: !!process.env.CI },
56+
},
57+
],
58+
},
59+
'@glimmer/env inlining',
60+
],
4661
],
4762
});
4863
}
@@ -95,7 +110,7 @@ module.exports = function () {
95110
});
96111
let rrAMD = toAMD(rr);
97112

98-
let backburner = findLib('backburner.js', 'dist/es6', {
113+
let backburner = new Funnel(findLib('backburner.js', 'dist/es6'), {
99114
files: ['backburner.js'],
100115
annotation: 'backburner es',
101116
});

lib/router/transition.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import TransitionAborted, { ITransitionAbortedError } from './transition-aborted
66
import { OpaqueIntent } from './transition-intent';
77
import TransitionState, { TransitionError } from './transition-state';
88
import { log, promiseLabel } from './utils';
9+
import { DEBUG } from '@glimmer/env';
910

1011
export type OnFulfilled<T, TResult1> =
1112
| ((value: T) => TResult1 | PromiseLike<TResult1>)
@@ -65,6 +66,35 @@ export default class Transition<T extends Route> implements Partial<Promise<T>>
6566
isCausedByAbortingReplaceTransition = false;
6667
_visibleQueryParams: Dict<unknown> = {};
6768

69+
/**
70+
In non-production builds, this function will return the stack that this Transition was
71+
created within. In production builds, this function will not be present.
72+
73+
@method debugCreationStack
74+
@return string
75+
*/
76+
declare debugCreationStack?: () => string | undefined;
77+
78+
/**
79+
In non-production builds, this function will return the stack that this Transition was
80+
aborted within (or `undefined` if the Transition has not been aborted yet). In production
81+
builds, this function will not be present.
82+
83+
@method debugAbortStack
84+
@return string
85+
*/
86+
declare debugAbortStack?: () => string | undefined;
87+
88+
/**
89+
In non-production builds, this property references the Transition that _this_ Transition
90+
was derived from or `undefined` if this transition did not derive from another. In
91+
production builds, this property will not be present.
92+
93+
@property debugPreviousTransition
94+
@type {Transition | undefined}
95+
*/
96+
declare debugPreviousTransition: Maybe<Transition<T>>;
97+
6898
constructor(
6999
router: Router<T>,
70100
intent: Maybe<OpaqueIntent>,
@@ -86,6 +116,17 @@ export default class Transition<T extends Route> implements Partial<Promise<T>>
86116
this.pivotHandler = undefined;
87117
this.sequence = -1;
88118

119+
if (DEBUG) {
120+
let error = new Error(`Transition creation stack`);
121+
122+
this.debugCreationStack = () => error.stack;
123+
124+
// not aborted yet, will be replaced when `this.isAborted` is set
125+
this.debugAbortStack = () => undefined;
126+
127+
this.debugPreviousTransition = previousTransition;
128+
}
129+
89130
if (error) {
90131
this.promise = Promise.reject(error);
91132
this.error = error;
@@ -250,9 +291,17 @@ export default class Transition<T extends Route> implements Partial<Promise<T>>
250291
rollback() {
251292
if (!this.isAborted) {
252293
log(this.router, this.sequence, this.targetName + ': transition was aborted');
294+
295+
if (DEBUG) {
296+
let error = new Error(`Transition aborted stack`);
297+
298+
this.debugAbortStack = () => error.stack;
299+
}
300+
253301
if (this.intent !== undefined && this.intent !== null) {
254302
this.intent.preTransitionState = this.router.state;
255303
}
304+
256305
this.isAborted = true;
257306
this.isActive = false;
258307
this.router.activeTransition = undefined;

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@
3131
"start": "ember server",
3232
"test": "ember test"
3333
},
34-
"dependencies": {},
34+
"dependencies": {
35+
"@glimmer/env": "^0.1.7"
36+
},
3537
"devDependencies": {
3638
"@babel/plugin-transform-modules-amd": "^7.10.5",
3739
"@babel/plugin-transform-modules-commonjs": "^7.10.4",
3840
"@types/node": "^12.7.5",
3941
"@types/qunit": "^2.9.1",
4042
"@typescript-eslint/eslint-plugin": "^3.7.0",
4143
"@typescript-eslint/parser": "^3.7.0",
44+
"babel-plugin-debug-macros": "^0.3.3",
4245
"backburner.js": "^2.6.0",
4346
"broccoli-babel-transpiler": "^7.6.0",
4447
"broccoli-concat": "^4.2.4",

yarn.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@
216216
exec-sh "^0.3.2"
217217
minimist "^1.2.0"
218218

219+
"@glimmer/env@^0.1.7":
220+
version "0.1.7"
221+
resolved "https://registry.yarnpkg.com/@glimmer/env/-/env-0.1.7.tgz#fd2d2b55a9029c6b37a6c935e8c8871ae70dfa07"
222+
integrity sha1-/S0rVakCnGs3psk16MiHGucN+gc=
223+
219224
220225
version "2.2.5"
221226
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
@@ -903,6 +908,13 @@ atob@^2.1.2:
903908
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
904909
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
905910

911+
babel-plugin-debug-macros@^0.3.3:
912+
version "0.3.3"
913+
resolved "https://registry.yarnpkg.com/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.3.3.tgz#29c3449d663f61c7385f5b8c72d8015b069a5cb7"
914+
integrity sha512-E+NI8TKpxJDBbVkdWkwHrKgJi696mnRL8XYrOPYw82veNHPDORM9WIQifl6TpIo8PNy2tU2skPqbfkmHXrHKQA==
915+
dependencies:
916+
semver "^5.3.0"
917+
906918
babel-plugin-dynamic-import-node@^2.3.3:
907919
version "2.3.3"
908920
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.3.3.tgz#84fda19c976ec5c6defef57f9427b3def66e17a3"
@@ -6310,7 +6322,7 @@ semver-diff@^3.1.1:
63106322
dependencies:
63116323
semver "^6.3.0"
63126324

6313-
"semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0:
6325+
"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0:
63146326
version "5.7.1"
63156327
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
63166328
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

0 commit comments

Comments
 (0)