Skip to content

Commit

Permalink
Start on eslint-plugin-ember 10 updates (#1592)
Browse files Browse the repository at this point in the history
* Start on eslint-plugin-ember 10 updates

* Use ember-ref-modifer to get element

* Explicitly import port service

* Add a couple missed port injections

* Silence deprecations for now

* Native class codemod

* Remove classic decorators

* Fix tests

* Remove 3.4 and 3.8 from tests
  • Loading branch information
RobbieTheWagner authored May 21, 2021
1 parent 8048168 commit c587830
Show file tree
Hide file tree
Showing 68 changed files with 912 additions and 741 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ module.exports = {

// Temporarily turn these off
'ember/avoid-leaking-state-in-ember-objects': 'off',
'ember/classic-decorator-hooks': 'off',
'ember/classic-decorator-no-classic-methods': 'off',
'ember/no-actions-hash': 'off',
'ember/no-classic-classes': 'off',
'ember/no-classic-components': 'off',
'ember/no-component-lifecycle-hooks': 'off',
'ember/no-computed-properties-in-native-classes': 'off',
'ember/no-get': 'off',
'ember/no-test-import-export': 'off',
'ember/require-tagless-components': 'off',

// Best practice
'no-duplicate-imports': 'error',
Expand Down
19 changes: 10 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ jobs:
fail-fast: false
matrix:
scenario:
- default-no-prototype-extensions
- release
- beta
- canary
- lts-3.4
- lts-3.8
- lts-3.12
- ember-lts-3.12
- ember-lts-3.16
- ember-lts-3.20
- ember-release
- ember-beta
- ember-canary
- ember-default-no-prototype-extensions

steps:
- name: Checkout
uses: actions/checkout@v1
Expand All @@ -102,10 +103,10 @@ jobs:
- name: Install dependencies (yarn)
run: yarn install
- name: Set NO_EXTEND_PROTOTYPES
if: matrix.scenario == 'default-no-prototype-extensions'
if: matrix.scenario == 'ember-default-no-prototype-extensions'
run: echo "NO_EXTEND_PROTOTYPES==true" >> .GITHUB_ENV
- name: Setup ember-try scenario
run: yarn ember try:one ember-${{ matrix.scenario }} --skip-cleanup --- cat package.json
run: yarn ember try:one ${{ matrix.scenario }} --skip-cleanup --- cat package.json
- name: Build
run: yarn ember build --environment test
- name: Run test
Expand Down
31 changes: 15 additions & 16 deletions app/adapters/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@
* ```
*/
import EmberObject from '@ember/object';

import { tracked } from '@glimmer/tracking';
import config from 'ember-inspector/config/environment';

export default EmberObject.extend({
export default class Basic extends EmberObject {
@tracked canOpenResource = false;
name = 'basic';

/**
* Called when the adapter is created (when
* the inspector app boots).
*
* @method init
*/
init() {
this._super(...arguments);
super.init(...arguments);
this._messageCallbacks = [];
this._checkVersion();
},
}

/**
* Listens to `EmberInspectorDebugger` message about
Expand Down Expand Up @@ -57,7 +60,7 @@ export default EmberObject.extend({
}
});
this.sendMessage({ type: 'check-version', from: 'devtools' });
},
}

/**
* Hook called when the Ember version is not
Expand All @@ -70,37 +73,33 @@ export default EmberObject.extend({
* @method onVersionMismatch
* @param {String} neededVersion (The version to go to)
*/
onVersionMismatch() {},

name: 'basic',
onVersionMismatch() {}

/**
Used to send messages to EmberDebug
@param type {Object} the message to the send
**/
sendMessage() {},
sendMessage() {}

/**
Register functions to be called
when a message from EmberDebug is received
**/
onMessageReceived(callback) {
this._messageCallbacks.push(callback);
},
}

_messageReceived(message) {
this._messageCallbacks.forEach((callback) => {
callback(message);
});
},
}

// Called when the "Reload" is clicked by the user
willReload() {},

canOpenResource: false,
openResource(/* file, line */) {},
});
willReload() {}
openResource /* file, line */() {}
}

/**
* Compares two Ember versions.
Expand Down
28 changes: 15 additions & 13 deletions app/adapters/bookmarklet.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint no-useless-escape: 0 */
/* eslint-disable no-useless-escape */
import { computed } from '@ember/object';

import BasicAdapter from './basic';

export default BasicAdapter.extend({
name: 'bookmarklet',
export default class Bookmarklet extends BasicAdapter {
name = 'bookmarklet';

/**
* Called when the adapter is created.
Expand All @@ -13,21 +13,23 @@ export default BasicAdapter.extend({
*/
init() {
this._connect();
return this._super(...arguments);
},
return super.init(...arguments);
}

inspectedWindow: computed(function () {
@computed
get inspectedWindow() {
return window.opener || window.parent;
}),
}

inspectedWindowURL: computed(function () {
@computed
get inspectedWindowURL() {
return loadPageVar('inspectedWindowURL');
}),
}

sendMessage(options) {
options = options || {};
this.inspectedWindow.postMessage(options, this.inspectedWindowURL);
},
}

/**
* Redirect to the correct inspector version.
Expand All @@ -41,7 +43,7 @@ export default BasicAdapter.extend({
/\./g,
'-'
)}/index.html${window.location.search}`;
},
}

_connect() {
window.addEventListener('message', (e) => {
Expand All @@ -57,8 +59,8 @@ export default BasicAdapter.extend({
this._messageReceived(message);
}
});
},
});
}
}

function loadPageVar(sVar) {
return decodeURI(
Expand Down
14 changes: 7 additions & 7 deletions app/adapters/chrome.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import WebExtension from './web-extension';
import { tracked } from '@glimmer/tracking';

export default WebExtension.extend({
name: 'chrome',

canOpenResource: true,
export default class Chrome extends WebExtension {
name = 'chrome';
@tracked canOpenResource = true;

openResource(file, line) {
/*global chrome */
// For some reason it opens the line after the one specified
chrome.devtools.panels.openResource(file, line - 1);
},
}

onResourceAdded() {
chrome.devtools.inspectedWindow.onResourceAdded.addListener((opts) => {
if (opts.type === 'document') {
this.sendIframes([opts.url]);
}
});
},
});
}
}
6 changes: 3 additions & 3 deletions app/adapters/firefox.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import WebExtension from './web-extension';

export default WebExtension.extend({
name: 'firefox',
});
export default class Firefox extends WebExtension {
name = 'firefox';
}
43 changes: 22 additions & 21 deletions app/adapters/web-extension.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/* globals chrome */
import { computed } from '@ember/object';
import { tracked } from '@glimmer/tracking';

import BasicAdapter from './basic';
import config from 'ember-inspector/config/environment';

let emberDebug = null;

export default BasicAdapter.extend({
export default class WebExtension extends BasicAdapter {
@tracked canOpenResource = false;
name = 'web-extension';

/**
* Called when the adapter is created.
*
Expand All @@ -18,19 +22,18 @@ export default BasicAdapter.extend({
this._injectDebugger();
this._setThemeColors();

return this._super(...arguments);
},

name: 'web-extension',
return super.init(...arguments);
}

sendMessage(options) {
options = options || {};
this._chromePort.postMessage(options);
},
}

_chromePort: computed(function () {
@computed
get _chromePort() {
return chrome.runtime.connect();
}),
}

_connect() {
let chromePort = this._chromePort;
Expand All @@ -42,15 +45,15 @@ export default BasicAdapter.extend({
}
this._messageReceived(message);
});
},
}

_handleReload() {
let self = this;
chrome.devtools.network.onNavigated.addListener(function () {
self._injectDebugger();
location.reload(true);
});
},
}

_injectDebugger() {
loadEmberDebug().then((emberDebug) => {
Expand All @@ -61,7 +64,7 @@ export default BasicAdapter.extend({
});
this.onResourceAdded();
});
},
}

_setThemeColors() {
// Remove old theme colors to ensure switching themes works
Expand All @@ -72,13 +75,13 @@ export default BasicAdapter.extend({
theme = 'theme--dark';
}
document.body.classList.add(theme);
},
}

onResourceAdded(/*callback*/) {},
onResourceAdded /*callback*/() {}

willReload() {
this._injectDebugger();
},
}

/**
* Open the devtools "Elements" tab and select a specific DOM node.
Expand All @@ -91,7 +94,7 @@ export default BasicAdapter.extend({
inspect(window[${JSON.stringify(name)}]);
delete window[${JSON.stringify(name)}];
`);
},
}

/**
* Redirect to the correct inspector version.
Expand All @@ -104,7 +107,7 @@ export default BasicAdapter.extend({
/\./g,
'-'
)}/index.html`;
},
}

/**
We handle the reload here so we can inject
Expand All @@ -114,18 +117,16 @@ export default BasicAdapter.extend({
loadEmberDebug().then((emberDebug) => {
chrome.devtools.inspectedWindow.reload({ injectedScript: emberDebug });
});
},

canOpenResource: false,
}

sendIframes(urls) {
loadEmberDebug().then((emberDebug) => {
urls.forEach((url) => {
chrome.devtools.inspectedWindow.eval(emberDebug, { frameURL: url });
});
});
},
});
}
}

function loadEmberDebug() {
let minimumVersion = config.emberVersionsSupported[0].replace(/\./g, '-');
Expand Down
Loading

0 comments on commit c587830

Please sign in to comment.