Skip to content

Commit

Permalink
fix: hardcodes export-application-global
Browse files Browse the repository at this point in the history
  • Loading branch information
Pixelik committed Jun 15, 2023
1 parent b56d8cf commit 1d2ecd9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion addon/initializers/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function normalizeConfig(userConfig: GivenConfig): ObjectConfig {
}

export function initialize(application: Application): void {

const env = application.resolveRegistration('config:environment') as { embedded?: GivenConfig }
const embeddedConfig: ObjectConfig = normalizeConfig(env.embedded)

Expand Down Expand Up @@ -126,5 +127,5 @@ export function initialize(application: Application): void {
export default {
name: 'ember-cli-embedded',
after: 'export-application-global',
initialize,
initialize
}
42 changes: 42 additions & 0 deletions addon/initializers/export-application-global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import Application from '@ember/application'
import { classify } from '@ember/string'

// @ts-ignore: because TS doesn't like this import
import config from "../config/environment"

export function initialize(application: Application): void {
if (config.exportApplicationGlobal !== false) {
let theGlobal

if (typeof window !== 'undefined') {
theGlobal = window
} else if (typeof global !== 'undefined') {
theGlobal = global
} else if (typeof self !== 'undefined') {
theGlobal = self
} else {
return
}

const value = config.exportApplicationGlobal

let globalName

if (typeof value === 'string') {
globalName = value
} else {
globalName = classify(config.modulePrefix)
}

// @ts-ignore: until there's a way to access a dynamic propertyName of window in TS
if (!theGlobal[globalName]) {
// @ts-ignore: until there's a way to set a dynamic propertyName to the window in TS
theGlobal[globalName] = application
}
}
}

export default {
name: 'export-application-global',
initialize
}

0 comments on commit 1d2ecd9

Please sign in to comment.