-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #941 from eoneill/ember-cli-addon-proxy
- Loading branch information
Showing
2 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// As of [email protected], addon instances _may_ be proxied. This can become a | ||
// problem when patching (setting/restoring) methods on the addon instance or | ||
// comparing with the addon `__proto__`. The purpose of this util method is to | ||
// correctly return the _real_ (original) addon instance and not the proxy. | ||
// @see https://github.com/ember-cli/ember-cli/pull/9487 | ||
|
||
let TARGET_INSTANCE_SYMBOL: any; | ||
|
||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-require-imports | ||
const targetInstanceModule = require('ember-cli/lib/models/per-bundle-addon-cache/target-instance'); | ||
|
||
if (targetInstanceModule) { | ||
TARGET_INSTANCE_SYMBOL = targetInstanceModule.TARGET_INSTANCE; | ||
} | ||
} catch (e) { | ||
// we only want to handle the error when this module isn't found; i.e., | ||
// when a consumer of `ember-engines` is using an old version of `ember-cli` | ||
// (less than `ember-cli` 3.28) | ||
if (!e || e.code !== 'MODULE_NOT_FOUND') { | ||
throw e; | ||
} | ||
} | ||
|
||
/** | ||
* Given an addon instance, gets the _real_ addon instance | ||
* @param maybeProxyAddon - the addon instance, which may be a proxy | ||
* @returns the _real_ (not proxied) addon instance | ||
*/ | ||
export default function getRealAddon(maybeProxyAddon: any): any { | ||
return (TARGET_INSTANCE_SYMBOL && maybeProxyAddon[TARGET_INSTANCE_SYMBOL]) || maybeProxyAddon; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters