Skip to content

Commit 0ba7163

Browse files
committed
fix(ember): Fix Ember to work with Embroider and Fastboot
This removes the ember-get-config dependency and opts to use Embroiders macros instead to have backwards and forwards compatibility.
1 parent 996d5bc commit 0ba7163

File tree

10 files changed

+1538
-173
lines changed

10 files changed

+1538
-173
lines changed

packages/ember/addon/config.d.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

packages/ember/addon/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import * as Sentry from '@sentry/browser';
22
import { SDK_VERSION, BrowserOptions } from '@sentry/browser';
3-
import environmentConfig from 'ember-get-config';
4-
import { macroCondition, isDevelopingApp } from '@embroider/macros';
3+
import { macroCondition, isDevelopingApp, getOwnConfig } from '@embroider/macros';
54
import { next } from '@ember/runloop';
65
import { assert, warn } from '@ember/debug';
76
import Ember from 'ember';
87
import { timestampWithMs } from '@sentry/utils';
8+
import { OwnConfig } from './types';
99

1010
declare module '@ember/debug' {
1111
export function assert(desc: string, test: unknown): void;
1212
}
1313

1414
export function InitSentryForEmber(_runtimeConfig: BrowserOptions | undefined) {
15-
const config = environmentConfig['@sentry/ember'];
16-
assert('Missing configuration', config);
17-
assert('Missing configuration for Sentry.', config.sentry);
15+
const config = getOwnConfig<OwnConfig>().sentryConfig;
16+
17+
assert('Missing configuration.', config);
18+
assert('Missing configuration for Sentry.', config.sentry || _runtimeConfig);
1819

1920
const initConfig = Object.assign({}, config.sentry, _runtimeConfig || {});
2021

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import ApplicationInstance from '@ember/application/instance';
22
import Ember from 'ember';
33
import { run } from '@ember/runloop';
4-
import environmentConfig from 'ember-get-config';
54
import * as Sentry from '@sentry/browser';
65
import { Span, Transaction, Integration } from '@sentry/types';
76
import { EmberRunQueues } from '@ember/runloop/-private/types';
87
import { getActiveTransaction } from '..';
98
import { timestampWithMs } from '@sentry/utils';
10-
import { macroCondition, isTesting } from '@embroider/macros';
9+
import { macroCondition, isTesting, getOwnConfig } from '@embroider/macros';
10+
import { EmberSentryConfig, OwnConfig } from '../types';
11+
12+
function getSentryConfig() {
13+
return getOwnConfig<OwnConfig>().sentryConfig;
14+
}
1115

1216
export function initialize(appInstance: ApplicationInstance): void {
13-
const config = environmentConfig['@sentry/ember'];
17+
const config = getSentryConfig();
1418
if (config['disablePerformance']) {
1519
return;
1620
}
@@ -32,7 +36,7 @@ function getTransitionInformation(transition: any, router: any) {
3236
export function _instrumentEmberRouter(
3337
routerService: any,
3438
routerMain: any,
35-
config: typeof environmentConfig['@sentry/ember'],
39+
config: EmberSentryConfig,
3640
startTransaction: Function,
3741
startTransactionOnPageLoad?: boolean,
3842
) {
@@ -106,7 +110,7 @@ export function _instrumentEmberRouter(
106110
};
107111
}
108112

109-
function _instrumentEmberRunloop(config: typeof environmentConfig['@sentry/ember']) {
113+
function _instrumentEmberRunloop(config: EmberSentryConfig) {
110114
const { disableRunloopPerformance, minimumRunloopQueueDuration } = config;
111115
if (disableRunloopPerformance) {
112116
return;
@@ -227,7 +231,7 @@ function processComponentRenderAfter(
227231
}
228232
}
229233

230-
function _instrumentComponents(config: typeof environmentConfig['@sentry/ember']) {
234+
function _instrumentComponents(config: EmberSentryConfig) {
231235
const { disableInstrumentComponents, minimumComponentRenderDuration, enableComponentDefinitions } = config;
232236
if (disableInstrumentComponents) {
233237
return;
@@ -264,7 +268,7 @@ function _instrumentComponents(config: typeof environmentConfig['@sentry/ember']
264268
_subscribeToRenderEvents();
265269
}
266270

267-
function _instrumentInitialLoad(config: typeof environmentConfig['@sentry/ember']) {
271+
function _instrumentInitialLoad(config: EmberSentryConfig) {
268272
const startName = '@sentry/ember:initial-load-start';
269273
const endName = '@sentry/ember:initial-load-end';
270274

@@ -309,7 +313,7 @@ function _instrumentInitialLoad(config: typeof environmentConfig['@sentry/ember'
309313
}
310314

311315
export async function instrumentForPerformance(appInstance: ApplicationInstance) {
312-
const config = environmentConfig['@sentry/ember'];
316+
const config = getSentryConfig();
313317
const sentryConfig = config.sentry;
314318

315319
const tracing = await import('@sentry/tracing');

packages/ember/addon/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { BrowserOptions } from '@sentry/browser';
2+
3+
export type EmberSentryConfig = {
4+
sentry: BrowserOptions;
5+
transitionTimeout: number;
6+
ignoreEmberOnErrorWarning: boolean;
7+
disableInstrumentComponents: boolean;
8+
disablePerformance: boolean;
9+
disablePostTransitionRender: boolean;
10+
disableRunloopPerformance: boolean;
11+
disableInitialLoadInstrumentation: boolean;
12+
enableComponentDefinitions: boolean;
13+
minimumRunloopQueueDuration: number;
14+
minimumComponentRenderDuration: number;
15+
};
16+
17+
export type OwnConfig = {
18+
sentryConfig: EmberSentryConfig;
19+
};

packages/ember/config/ember-try.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const getChannelURL = require('ember-source-channel-url');
4+
const { embroiderSafe } = require('@embroider/test-setup');
45

56
module.exports = async function() {
67
return {
@@ -47,6 +48,7 @@ module.exports = async function() {
4748
},
4849
},
4950
},
51+
embroiderSafe(),
5052
// The default `.travis.yml` runs this scenario via `npm test`,
5153
// not via `ember try`. It's still included here so that running
5254
// `ember try:each` manually or from a customized CI config will run it

packages/ember/ember-cli-build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ module.exports = function(defaults) {
1313
This build file does *not* influence how the addon or the app using it
1414
behave. You most likely want to be modifying `./index.js` or app's build file
1515
*/
16-
17-
return app.toTree();
16+
const { maybeEmbroider } = require('@embroider/test-setup');
17+
return maybeEmbroider(app);
1818
};

packages/ember/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const fs = require('fs');
3+
const path = require('path');
34

45
function readSnippet(fileName) {
56
return `<script>${fs.readFileSync(`${__dirname}/vendor/${fileName}`, 'utf8')}</script>`;
@@ -11,10 +12,18 @@ module.exports = {
1112
babel: {
1213
plugins: [require.resolve('ember-auto-import/babel-plugin')],
1314
},
15+
'@embroider/macros': {
16+
setOwnConfig: {},
17+
},
1418
},
1519

1620
contentFor(type, config) {
1721
const addonConfig = config['@sentry/ember'] || {};
22+
const app = this._findHost(this);
23+
this.app = app;
24+
const options = Object.assign({}, addonConfig);
25+
this.options['@embroider/macros'].setOwnConfig.sentryConfig = options;
26+
1827
const { disablePerformance, disableInitialLoadInstrumentation } = addonConfig;
1928
if (disablePerformance || disableInitialLoadInstrumentation) {
2029
return;

packages/ember/package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,32 @@
3232
},
3333
"dependencies": {
3434
"@embroider/macros": ">=0.25.0",
35+
"@embroider/test-setup": "^0.35.1",
3536
"@sentry/browser": "5.30.0",
3637
"@sentry/tracing": "5.30.0",
3738
"@sentry/types": "5.30.0",
3839
"@sentry/utils": "5.30.0",
3940
"ember-auto-import": "^1.6.0",
4041
"ember-cli-babel": "^7.20.5",
4142
"ember-cli-htmlbars": "^5.1.2",
42-
"ember-cli-typescript": "^3.1.4",
43-
"ember-get-config": "^0.2.4"
43+
"ember-cli-typescript": "^3.1.4"
4444
},
4545
"devDependencies": {
4646
"@ember/optional-features": "^1.3.0",
47+
"@embroider/compat": "^0.35.1",
48+
"@embroider/core": "^0.35.1",
49+
"@embroider/webpack": "^0.35.1",
4750
"@glimmer/component": "^1.0.0",
4851
"@glimmer/tracking": "^1.0.0",
4952
"@sentry-internal/eslint-config-sdk": "5.30.0",
50-
"@types/ember": "^3.16.0",
53+
"@types/ember": "^3.16.3",
5154
"@types/ember-qunit": "^3.4.9",
5255
"@types/ember__test-helpers": "^1.7.0",
5356
"@types/qunit": "^2.9.1",
5457
"@types/rsvp": "^4.0.3",
5558
"babel-eslint": "^10.1.0",
5659
"broccoli-asset-rev": "^3.0.0",
57-
"ember-cli": "^3.21.2",
60+
"ember-cli": "^3.24.0",
5861
"ember-cli-dependency-checker": "^3.2.0",
5962
"ember-cli-inject-live-reload": "^2.0.2",
6063
"ember-cli-sri": "^2.1.1",
@@ -67,7 +70,7 @@
6770
"ember-qunit": "^4.6.0",
6871
"ember-resolver": "^8.0.0",
6972
"ember-sinon-qunit": "^5.0.0",
70-
"ember-source": "^3.21.1",
73+
"ember-source": "^3.24.0",
7174
"ember-source-channel-url": "^2.0.1",
7275
"ember-template-lint": "^2.9.1",
7376
"ember-test-selectors": "^4.1.0",
@@ -91,7 +94,7 @@
9194
"configPath": "tests/dummy/config"
9295
},
9396
"volta": {
94-
"node": "12.18.3",
97+
"node": "14.15.4",
9598
"yarn": "1.22.5"
9699
}
97100
}

packages/ember/tests/dummy/config/targets.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ if (isCI || isProduction) {
1414
}
1515

1616
module.exports = {
17-
browsers
17+
browsers,
18+
node: 'current'
1819
};

0 commit comments

Comments
 (0)