Git Product home page Git Product logo

ember-optional-features's Introduction

@ember/optional-features

This addon allows you to easily enable/disable optional features in ember-source. To clarify what we mean by optional, these are features that will be opt-in/opt-out and optional for the foreseeable future, not features that will be enabled by default. It is intended for use with apps only not addons.

Installation

ember install @ember/optional-features

Usage

From command-line

List available features

Features will only be available in versions of ember-source that included them. To list all available features run:

ember feature:list

Enable/disable features

To enable a feature, run:

ember feature:enable some-feature

Similarly, if you want to disable a feature, you can run:

ember feature:disable some-feature

At build-time (from an addon)

This addon exposes a build-time method called isFeatureEnabled, which can be called from an addon's index.js, e.g.:

included() {
  let optionalFeatues = this.addons.find(a => a.name === '@ember/optional-features');
  if (optionalFeatures.isFeatureEnabled('jquery-integration') {
    // ...
  }
}

It also exposes a method called isFeatureExplicitlySet, which can be used to check whether or not the user has explictly set the value of the option instead of using the default.

At run-time (from an app or addon)

WIP -- there does not yet exist a public API for accessing the state of optional features at runtime. This issue is tracking it.

ember-optional-features's People

Contributors

achambers avatar alkamin avatar bendemboski avatar bertdeblock avatar chancancode avatar cibernox avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar ember-tomster avatar locks avatar mansona avatar mike-north avatar nullvoxpopuli avatar pizza avatar robbiethewagner avatar rwjblue avatar simonihmig avatar turbo87 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-optional-features's Issues

Feature option is not being reflected when app renders

Summary

After disabling application-template-wrapper, the top-level wrapper div is still rendered and the application is still nested under it.

Steps to setup:

  1. Brand new ember application
  2. ember install @ember/optional-features
  3. ember feature:disable application-template-wrapper

My config/optional-features.json

{
  "application-template-wrapper": false
}

My application.hbs

<div class="ember-view">
  {{!-- The following component displays Ember's default welcome message. --}}
  {{welcome-page}}
  {{!-- Feel free to remove this! --}}

  {{outlet}}
</div>

Rendered in the browser:

image

Ember -v

ember-cli: 3.1.0-beta.1
node: 8.7.0
os: darwin x64

debugging console:

DEBUG: -------------------------------
DEBUG: Ember      : 3.1.0-beta.2
DEBUG: Ember Data : 3.1.0-beta.1
DEBUG: jQuery     : 3.3.1
DEBUG: -------------------------------

Here is a link to the ember app I set up for this: https://github.com/dorilla/ember-test-no-wrap

Thanks for your help! And I'm assuming i did something wrong somewhere in my setup, any help is appreciated.

Enable command is destructive in an addon

ember-cli: 3.7.1
node: 10.15.0
os: darwin x64
optional-features addon: 0.7.0
  1. Install addon ember install @ember/optional-features
  2. Enable jquery-integration ember feature:enable jquery-integration
➜  test-addon git:(master) ✗ node_modules/.bin/ember feature:enable jquery-integration
Enabled jquery-integration. Be sure to commit config/optional-features.json to source control!
➜  test-addon git:(master) ✗ cat tests/dummy/config/optional-features.json
{
  "jquery-integration": true
}
  1. Enable another feature e.g. template-only-glimmer-components
➜  test-addon git:(master) ✗ node_modules/.bin/ember feature:enable template-only-glimmer-components
Enabled template-only-glimmer-components. Be sure to commit config/optional-features.json to source control!
➜  test-addon git:(master) ✗ cat tests/dummy/config/optional-features.json
{
  "template-only-glimmer-components": true
}
  1. It should add your newly enabled feature to the list but instead it is destructive. The enable command is destructive and overwrites any previously added features in the addon's dummy app config.

Convert to TS or supply ambient definitions

As part of Ember.js RFC #0800, this package needs to supply type definitions. Preferably, this would happen by converting to TS and generating from the source; as an alternative, it can publish ambient types (presumably starting with the ones on DefinitelyTyped).

All the members of the Typed Ember team are happy to advise on how to do this; feel free to reach out in #dev-typescript on Discord if you have questions!

[template-only-glimmer-components]: TS component modules are ignored during installation

Currently, enabling template-only-glimmer-components will act like any TypeScript components (i.e., app/components/x-foo.ts) are template-only components because

let componentCandidates = yield p(glob)('**/*.js', { cwd: componentsRoot });

If a correctly-named TS file is found, it's a pretty strong sign that this isn't a template-only situation

Expose a module for runtime detection of opt-in/opt-out.

At times, addons will need to know if specific optional features are enabled or not. With the current architecture it is only possible to detect at runtime via window.EmberENV._SOME_FLAG_HERE, but we should not encourage that type of coupling to EmberENV.

As I see it we have a few options:

  • Provide a @ember/optional-features module that can be imported and checked for various opt-in's. This would allow consumers to use an import and conditionals in their code based on a given optional flag value.
  • Expose a custom babel plugin that can be used when an addon includes @ember/optional-features as a direct dependency. This babel plugin would provide custom build time replacement of @ember/optional-features based conditionals, and would therefore allow addons to include support for multiple variations of features without bloating the total asset size.

How do enable it inside an in-repo-addon?

I've included the @ember/optional-features in the addon's package.json. And I've tried creating a config/optional-features.json in the root directory of addon. Still no dice.

Edit:
I realized I haven't explained it in detail. I have a few template only components (or partials) that I am trying to use in the in of the addon templates. I couldn't find any documentation to include template only components into the application. I keep running into <component-name> is not a helper.

I suspect that the component files aren't being included in the application. I've read this issue and it's still not clear how to include a template that is not backed by a js file.

2nd Edit:
This is what my package.json looks like:

  "name": "ember-wizard",
  "dependencies": {
    "@ember/optional-features": "^0.5.2",
    "babel-plugin-htmlbars-inline-precompile": "^0.2.4",
    "ember-cli-babel": "^6.8.2",
    "ember-cli-htmlbars": "^2.0.3",
    "ember-cli-htmlbars-inline-precompile": "^1.0.0"
  }

feature:enable, feature:disable commands update the optional-fatures.js file thus replacing existing key:value with new ones. May want to append to the file, rather than replace/update.

Each time this one of feature:enable, feature:disable commands is executed, optional-features.js file is updated (existing key: value in the file are replaced with the new one) not appended. This caused a bit of a heartache for me as it put me in a loop for a bit. 🙂 I had to manually edit the file and the key:values to the object inside it.

Support reading options from process.env

The presence of process.env.EMBER_OPTIONAL_FEATURES should override config/optional-features.{js,json}.

This mechanism will be how ember-try scenarios can test different configurations...

more information rfc link results in 404

[email protected] shows the following for further information. The rendered rfc link however ends up in a 404:

  default-async-observers (Default: false)
    Makes all observers asynchronous (unless manually indicated as synchronous when calling addObserver/observes).
    More information: https://github.com/emberjs/rfcs/pull/494

Should we change the rfc link to the archive (assuming this is the official archive - just found the link through google)?
https://emberjs.github.io/rfcs/0494-async-observers.html

Handle Colocated template only components

app/components/foo.hbs is not handled by ember feature:enable template-only-glimmer-components --run-codemods

I don't get a warning or a generated class component for these components.

Codemod for `template-only-glimmer-components` doesn't support Addons

It appears that the codemod implementation only runs against components in the app/ directory, which will not work for addons, which store their components in the addon/ directory and may not re-export them at all (since doing so is dangerous and a bad pattern). In order for addons to successfully enable this feature, the codemod needs to be able to create backing classes for addon components.

https://github.com/emberjs/ember-optional-features/blob/master/features/template-only-glimmer-components.js#L55

How to hide deprecation warning in addons

Hi, in the readme of this addon, it's written

It is intended for use with apps only not addons.

Is there a way to hide the warning in the addon package (and also engine package)? Currently I'm seeing this warning in console.

DEPRECATION: The integration of jQuery into Ember has been deprecated and will be removed with Ember 4.0. You can either opt-out of using jQuery, or install the `@ember/jquery` addon to provide the jQuery integration. Please consult the deprecation guide for further details: https://emberjs.com/deprecations/v3.x#toc_jquery-apis

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.