Skip to content

Commit

Permalink
Cleanup ember-environment not to mutate the picked up EmberENV global.
Browse files Browse the repository at this point in the history
  • Loading branch information
krisselden committed Apr 17, 2018
1 parent 90cc5c0 commit 77e033e
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 146 deletions.
283 changes: 158 additions & 125 deletions packages/ember-environment/lib/env.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
import global from './global';
import { defaultFalse, defaultTrue, normalizeExtendPrototypes } from './utils';

export interface Environment {
ENABLE_ALL_FEATURES: boolean;
ENABLE_OPTIONAL_FEATURES: boolean;
EXTEND_PROTOTYPES: {
Array: boolean;
Function: boolean;
String: boolean;
};
LOG_STACKTRACE_ON_DEPRECATION: boolean;
LOG_VERSION: boolean;
RAISE_ON_DEPRECATION: boolean;
_APPLICATION_TEMPLATE_WRAPPER: boolean;
_TEMPLATE_ONLY_GLIMMER_COMPONENTS: boolean;
_ENABLE_EMBER_K_SUPPORT: boolean;
_ENABLE_SAFE_STRING_SUPPORT: boolean;
_ENABLE_ENUMERABLE_CONTAINS_SUPPORT: boolean;
_ENABLE_UNDERSCORE_ACTIONS_SUPPORT: boolean;
_ENABLE_REVERSED_OBSERVER_SUPPORT: boolean;
_ENABLE_INITIALIZER_ARGUMENTS_SUPPORT: boolean;
_ENABLE_ROUTER_RESOURCE: boolean;
_ENABLE_CURRENT_WHEN_SUPPORT: boolean;
_ENABLE_CONTROLLER_WRAPPED_SUPPORT: boolean;
_ENABLE_DEPRECATED_REGISTRY_SUPPORT: boolean;
_ENABLE_IMMEDIATE_OBSERVER_SUPPORT: boolean;
_ENABLE_STRING_FMT_SUPPORT: boolean;
_ENABLE_FREEZABLE_SUPPORT: boolean;
_ENABLE_COMPONENT_DEFAULTLAYOUT_SUPPORT: boolean;
_ENABLE_BINDING_SUPPORT: boolean;
_ENABLE_INPUT_TRANSFORM_SUPPORT: boolean;
_ENABLE_DEPRECATION_OPTIONS_SUPPORT: boolean;
_ENABLE_ORPHANED_OUTLETS_SUPPORT: boolean;
_ENABLE_WARN_OPTIONS_SUPPORT: boolean;
_ENABLE_RESOLVER_FUNCTION_SUPPORT: boolean;
_ENABLE_DID_INIT_ATTRS_SUPPORT: boolean;
_ENABLE_RENDER_SUPPORT: boolean;
_ENABLE_PROPERTY_REQUIRED_SUPPORT: boolean;
}

/**
The hash of environment variables used to control various configuration
Expand All @@ -50,93 +11,165 @@ export interface Environment {
@type Object
@public
*/
export const ENV: Environment =

This comment has been minimized.

Copy link
@runspired

runspired Apr 18, 2018

Contributor

I believe doing this broke (a feature we are removing) on ember-data against ember canary. Example: https://travis-ci.org/emberjs/data/jobs/364748250

We were relying on merging feature flags, but we only have one feature flag that used ENV in this way and it is on its way out: emberjs/data#5437

This comment has been minimized.

Copy link
@rwjblue

rwjblue Apr 18, 2018

Member

Just to clarify, ember-data (and its users) suggested folks add additional flags to EmberENV that are (as of this commit) not being copied over from window.EmberENV into Ember.ENV, correct? Assuming that is correct, I feel its important to point out that this type of EmberENV usage is exactly what we were trying to avoid with this change (so its generally speaking "working as intended").

I think we would accept a PR adding that specific flag here (undocumented, completely private, and scheduled for culling in 3.5) to ease the short term pain....

This comment has been minimized.

Copy link
@runspired

runspired Apr 18, 2018

Contributor

@rwjblue I'll bring a PR for the flag, should I add a deprecation with it prompting users to upgrade their version of ember-data-filter ?

(typeof global.EmberENV === 'object' && global.EmberENV) ||
(typeof global.ENV === 'object' && global.ENV) ||
{};
export const ENV = {
ENABLE_OPTIONAL_FEATURES: false,

/**
Determines whether Ember should add to `Array`, `Function`, and `String`
native object prototypes, a few extra methods in order to provide a more
friendly API.
We generally recommend leaving this option set to true however, if you need
to turn it off, you can add the configuration property
`EXTEND_PROTOTYPES` to `EmberENV` and set it to `false`.
Note, when disabled (the default configuration for Ember Addons), you will
instead have to access all methods and functions from the Ember
namespace.
@property EXTEND_PROTOTYPES
@type Boolean
@default true
@for EmberENV
@public
*/
EXTEND_PROTOTYPES: {
Array: true,
Function: true,
String: true,
},

/**
The `LOG_STACKTRACE_ON_DEPRECATION` property, when true, tells Ember to log
a full stack trace during deprecation warnings.
@property LOG_STACKTRACE_ON_DEPRECATION
@type Boolean
@default true
@for EmberENV
@public
*/
LOG_STACKTRACE_ON_DEPRECATION: true,

/**
The `LOG_VERSION` property, when true, tells Ember to log versions of all
dependent libraries in use.
@property LOG_VERSION
@type Boolean
@default true
@for EmberENV
@public
*/
LOG_VERSION: true,

RAISE_ON_DEPRECATION: false,

/**
Whether to insert a `<div class="ember-view" />` wrapper around the
application template. See RFC #280.
This is not intended to be set directly, as the implementation may change in
the future. Use `@ember/optional-features` instead.
@property _APPLICATION_TEMPLATE_WRAPPER
@for EmberENV
@type Boolean
@default true
@private
*/
_APPLICATION_TEMPLATE_WRAPPER: true,

/**
Whether to use Glimmer Component semantics (as opposed to the classic "Curly"
components semantics) for template-only components. See RFC #278.
This is not intended to be set directly, as the implementation may change in
the future. Use `@ember/optional-features` instead.
@property _TEMPLATE_ONLY_GLIMMER_COMPONENTS
@for EmberENV
@type Boolean
@default false
@private
*/
_TEMPLATE_ONLY_GLIMMER_COMPONENTS: false,

// the following for addon support
_ENABLE_EMBER_K_SUPPORT: false,
_ENABLE_SAFE_STRING_SUPPORT: false,
_ENABLE_ENUMERABLE_CONTAINS_SUPPORT: false,
_ENABLE_UNDERSCORE_ACTIONS_SUPPORT: false,
_ENABLE_REVERSED_OBSERVER_SUPPORT: false,
_ENABLE_INITIALIZER_ARGUMENTS_SUPPORT: false,
_ENABLE_ROUTER_RESOURCE: false,
_ENABLE_CURRENT_WHEN_SUPPORT: false,
_ENABLE_CONTROLLER_WRAPPED_SUPPORT: false,
_ENABLE_DEPRECATED_REGISTRY_SUPPORT: false,
_ENABLE_IMMEDIATE_OBSERVER_SUPPORT: false,
_ENABLE_STRING_FMT_SUPPORT: false,
_ENABLE_FREEZABLE_SUPPORT: false,
_ENABLE_COMPONENT_DEFAULTLAYOUT_SUPPORT: false,
_ENABLE_BINDING_SUPPORT: false,
_ENABLE_INPUT_TRANSFORM_SUPPORT: false,
_ENABLE_DEPRECATION_OPTIONS_SUPPORT: false,
_ENABLE_ORPHANED_OUTLETS_SUPPORT: false,
_ENABLE_WARN_OPTIONS_SUPPORT: false,
_ENABLE_RESOLVER_FUNCTION_SUPPORT: false,
_ENABLE_DID_INIT_ATTRS_SUPPORT: false,
_ENABLE_RENDER_SUPPORT: false,
_ENABLE_PROPERTY_REQUIRED_SUPPORT: false,

EMBER_LOAD_HOOKS: {} as {
[hook: string]: Function[];
},
};

(EmberENV => {
if (typeof EmberENV !== 'object' || EmberENV === null) return;

for (let flag in EmberENV) {
if (
!EmberENV.hasOwnProperty(flag) ||
flag === 'EXTEND_PROTOTYPES' ||
flag === 'EMBER_LOAD_HOOKS'
)
continue;
let defaultValue = ENV[flag];
if (defaultValue === true) {
ENV[flag] = EmberENV[flag] !== false;
} else if (defaultValue === false) {
ENV[flag] = EmberENV[flag] === true;
}
}

let { EXTEND_PROTOTYPES } = EmberENV;
if (EXTEND_PROTOTYPES !== undefined) {
if (typeof EXTEND_PROTOTYPES === 'object' && EXTEND_PROTOTYPES === null) {
ENV.EXTEND_PROTOTYPES.String = EXTEND_PROTOTYPES.String !== false;
ENV.EXTEND_PROTOTYPES.Function = EXTEND_PROTOTYPES.Function !== false;
ENV.EXTEND_PROTOTYPES.Array = EXTEND_PROTOTYPES.Array !== false;
} else {
ENV.EXTEND_PROTOTYPES.String = EXTEND_PROTOTYPES !== false;
ENV.EXTEND_PROTOTYPES.Function = EXTEND_PROTOTYPES !== false;
ENV.EXTEND_PROTOTYPES.Array = EXTEND_PROTOTYPES !== false;
}
}

// TODO this does not seem to be used by anything,
// can we remove it? do we need to deprecate it?
let { EMBER_LOAD_HOOKS } = EmberENV;
if (typeof EMBER_LOAD_HOOKS === 'object' && EMBER_LOAD_HOOKS !== null) {
for (let hookName in EMBER_LOAD_HOOKS) {
if (!EMBER_LOAD_HOOKS.hasOwnProperty(hookName)) continue;
let hooks = EMBER_LOAD_HOOKS[hookName];
if (Array.isArray(hooks)) {
ENV.EMBER_LOAD_HOOKS[hookName] = hooks.filter(hook => typeof hook === 'function');
}
}
}
})(global.EmberENV || global.ENV);

export function getENV() {
return ENV;
}

// ENABLE_ALL_FEATURES was documented, but you can't actually enable non optional features.
if (ENV.ENABLE_ALL_FEATURES) {
ENV.ENABLE_OPTIONAL_FEATURES = true;
}

/**
Determines whether Ember should add to `Array`, `Function`, and `String`
native object prototypes, a few extra methods in order to provide a more
friendly API.
We generally recommend leaving this option set to true however, if you need
to turn it off, you can add the configuration property
`EXTEND_PROTOTYPES` to `EmberENV` and set it to `false`.
Note, when disabled (the default configuration for Ember Addons), you will
instead have to access all methods and functions from the Ember
namespace.
@property EXTEND_PROTOTYPES
@type Boolean
@default true
@for EmberENV
@public
*/
ENV.EXTEND_PROTOTYPES = normalizeExtendPrototypes(ENV.EXTEND_PROTOTYPES);

/**
The `LOG_STACKTRACE_ON_DEPRECATION` property, when true, tells Ember to log
a full stack trace during deprecation warnings.
@property LOG_STACKTRACE_ON_DEPRECATION
@type Boolean
@default true
@for EmberENV
@public
*/
ENV.LOG_STACKTRACE_ON_DEPRECATION = defaultTrue(ENV.LOG_STACKTRACE_ON_DEPRECATION);

/**
The `LOG_VERSION` property, when true, tells Ember to log versions of all
dependent libraries in use.
@property LOG_VERSION
@type Boolean
@default true
@for EmberENV
@public
*/
ENV.LOG_VERSION = defaultTrue(ENV.LOG_VERSION);

ENV.RAISE_ON_DEPRECATION = defaultFalse(ENV.RAISE_ON_DEPRECATION);

/**
Whether to insert a `<div class="ember-view" />` wrapper around the
application template. See RFC #280.
This is not intended to be set directly, as the implementation may change in
the future. Use `@ember/optional-features` instead.
@property _APPLICATION_TEMPLATE_WRAPPER
@for EmberENV
@type Boolean
@default true
@private
*/
ENV._APPLICATION_TEMPLATE_WRAPPER = defaultTrue(ENV._APPLICATION_TEMPLATE_WRAPPER);

/**
Whether to use Glimmer Component semantics (as opposed to the classic "Curly"
components semantics) for template-only components. See RFC #278.
This is not intended to be set directly, as the implementation may change in
the future. Use `@ember/optional-features` instead.
@property _TEMPLATE_ONLY_GLIMMER_COMPONENTS
@for EmberENV
@type Boolean
@default false
@private
*/
ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS = defaultFalse(ENV._TEMPLATE_ONLY_GLIMMER_COMPONENTS);
21 changes: 0 additions & 21 deletions packages/ember-environment/lib/utils.ts

This file was deleted.

0 comments on commit 77e033e

Please sign in to comment.