Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions ember_debug/lib/get-applications.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* eslint-disable ember/new-module-imports */
import { Application, Namespace, guidFor } from '../utils/ember';

/**
* Get all the Ember.Application instances from Ember.Namespace.NAMESPACES
* and add our own applicationId and applicationName to them
* @return {*}
*/
export default function getApplications(Ember) {
var namespaces = Ember.A(Ember.Namespace.NAMESPACES);
export default function getApplications() {
var namespaces = Namespace.NAMESPACES;

var apps = namespaces.filter(function (namespace) {
return namespace instanceof Ember.Application;
return namespace instanceof Application;
});

return apps.map(function (app) {
// Add applicationId and applicationName to the app
var applicationId = Ember.guidFor(app);
var applicationId = guidFor(app);
var applicationName =
app.name || app.modulePrefix || `(unknown app - ${applicationId})`;

Expand Down
2 changes: 2 additions & 0 deletions ember_debug/lib/load-ember-debug-in-webpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default function loadEmberDebugInWebpage(callback) {
*/
if (window.Ember) return resolve();

if (globalThis.emberInspectorApps) return resolve();

window.addEventListener('Ember', resolve, { once: true });
});
waitForEmberLoad.then(callback);
Expand Down
7 changes: 4 additions & 3 deletions ember_debug/lib/setup-instance-initializer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable ember/new-module-imports */
export default function setupInstanceInitializer(Ember, app, callback) {
import { guidFor } from '../utils/ember';

export default function setupInstanceInitializer(app, callback) {
if (!app.__inspector__setup) {
app.__inspector__setup = true;

// We include the app's guid in the initializer name because in Ember versions < 3
// registering an instance initializer with the same name, even if on a different app,
// triggers an error because instance initializers seem to be global instead of per app.
app.instanceInitializer({
name: 'ember-inspector-app-instance-booted-' + Ember.guidFor(app),
name: 'ember-inspector-app-instance-booted-' + guidFor(app),
initialize: function (instance) {
callback(instance);
},
Expand Down
66 changes: 27 additions & 39 deletions ember_debug/lib/start-inspector.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* eslint-disable ember/new-module-imports, ember/no-test-import-export */

/* eslint-disable ember/no-test-import-export */
import versionTest from './version-test';
import { EMBER_VERSIONS_SUPPORTED } from './versions';
import sendApps from './send-apps';
import getApplications from './get-applications';
import bootEmberInspector from './boot-ember-inspector';
import setupInstanceInitializer from './setup-instance-initializer';
import sendVersionMiss from './send-version-miss';

let Ember;
import { guidFor, Application } from '../utils/ember';

function onReady(callback) {
if (
Expand Down Expand Up @@ -36,27 +34,6 @@ export function onEmberReady(callback) {
return;
}

if (!Ember) {
try {
Ember = requireModule('ember/barrel')['default'];
} catch {
// noop
}
try {
Ember = Ember || requireModule('ember')['default'];
} catch {
Ember = window.Ember;
}
}

if (!Ember) {
return;
}
// `Ember.Application` load hook triggers before all of Ember is ready.
// In this case we ignore and wait for the `Ember` load hook.
if (!Ember.RSVP) {
return;
}
triggered = true;
callback();
};
Expand All @@ -74,21 +51,17 @@ export function startInspector(adapter) {
// to determine when the application starts
// but this definitely works
function onApplicationStart(callback) {
if (typeof Ember === 'undefined') {
return;
}

const adapterInstance = new adapter();

adapterInstance.onMessageReceived(function (message) {
if (message.type === 'app-picker-loaded') {
sendApps(adapterInstance, getApplications(Ember));
sendApps(adapterInstance, getApplications());
}

if (message.type === 'app-selected') {
let current = window.EmberInspector._application;
let selected = getApplications(Ember).find(
(app) => Ember.guidFor(app) === message.applicationId,
let selected = getApplications().find(
(app) => guidFor(app) === message.applicationId,
);

if (
Expand All @@ -101,7 +74,7 @@ export function startInspector(adapter) {
}
});

var apps = getApplications(Ember);
var apps = getApplications();

sendApps(adapterInstance, apps);

Expand All @@ -112,7 +85,7 @@ export function startInspector(adapter) {
let instance = app.__deprecatedInstance__ || applicationInstances[0];
if (instance) {
// App started
setupInstanceInitializer(Ember, app, callback);
setupInstanceInitializer(app, callback);
callback(instance);
return true;
}
Expand Down Expand Up @@ -143,7 +116,7 @@ export function startInspector(adapter) {
},
});
}
Ember.Application.initializer({
Application.initializer({
name: 'ember-inspector-booted',
initialize: function (app) {
setupInstanceInitializer(app, callback);
Expand All @@ -157,14 +130,29 @@ export function startInspector(adapter) {
return;
}

// If Ember doesn't exist, we should stop here to avoid issues with accessing `Ember.VERSION`
if (!Ember) {
/**
* If we don't have a way to know the Ember version at this point
* because the Ember app has not loaded and provided it somehow,
* we can't continue (we need the version to know what version of
* the Inspector to load).
*/
if (!globalThis.Ember && !globalThis.emberInspectorApps) {
return;
}

if (!versionTest(Ember.VERSION, EMBER_VERSIONS_SUPPORTED)) {
/**
* This is used to redirect to an old snapshot of the Inspector if the
* inspected app uses an older Ember version than supported versions.
* The code fits the Inspector supporting Ember back to 3.16: any version
* before 3.16 is necessarily a classic Ember app with Ember defined.
*/
if (
globalThis.Ember &&
globalThis.Ember.VERSION &&
!versionTest(globalThis.Ember.VERSION, EMBER_VERSIONS_SUPPORTED)
) {
// Wrong inspector version. Redirect to the correct version.
sendVersionMiss(Ember);
sendVersionMiss(globalThis.Ember);
return;
}

Expand Down
5 changes: 4 additions & 1 deletion ember_debug/object-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const OWNER_SYMBOL = '__owner__'; // can't use actual symbol because it can't be

// Try to use the most recent library (GlimmerValidator), else
// fallback on the previous implementation (GlimmerReference).
if (GlimmerValidator) {
// The global checks if the inspected app is Vite, in that case
// we can't execute that block because the properties it tries to
// assign are readonly.
if (GlimmerValidator && !globalThis.emberInspectorApps) {
tagValue = GlimmerValidator.value || GlimmerValidator.valueForTag;
tagValidate = GlimmerValidator.validate || GlimmerValidator.validateTag;
track = GlimmerValidator.track;
Expand Down
5 changes: 4 additions & 1 deletion ember_debug/utils/ember-object-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ const emberNames = new Map([
[NativeArray, 'NativeArray Mixin'],
[Observable, 'Observable Mixin'],
[ControllerMixin, 'Controller Mixin'],
[ActionHandler, 'ActionHandler Mixin'],
[CoreObject, 'CoreObject'],
[EmberObject, 'EmberObject'],
[Component, 'Component'],
]);

if (ActionHandler) {
emberNames.set(ActionHandler, 'ActionHandler Mixin');
}

if (compareVersion(VERSION, '3.27.0') === -1) {
const TargetActionSupport = InternalsRuntime?.TargetActionSupport;
emberNames.set(TargetActionSupport, 'TargetActionSupport Mixin');
Expand Down
Loading
Loading