Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use esm for requiring default and deprecated features #18218

Closed
wants to merge 13 commits into from
Closed
29 changes: 3 additions & 26 deletions broccoli/features.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
'use strict';

const fs = require('fs');
const ts = require('./typescript');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the deprecated features also relies upon this module; I can remove it and merge the deprecated features functionality with this new approach once I sort how the typescript particulars below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, sounds good to me.


const requireEsm = require('esm')(module);
function getFeatures() {
let fileName = 'packages/@ember/canary-features/index.ts';
let fileContents = fs.readFileSync(fileName).toString();

let sourceFile = ts.createSourceFile(
fileName,
fileContents,
ts.ScriptTarget.ES2017,
/*setParentNodes */ true
const { default: features } = requireEsm(
'../packages/@ember/canary-features/default-features.js'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not use @ember/canary-features/default-features.js for the path. Would this be because ember.js' internal package structure differs from ember data?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the local require (e.g. starting with ../packages/) is totally correct here.

);

let features;

ts.forEachChild(sourceFile, processVariableDeclarations);

function processVariableDeclarations(node) {
if (node.kind === ts.SyntaxKind.VariableDeclaration && node.name.text === 'DEFAULT_FEATURES') {
let featuresText = node.initializer.getFullText();
features = new Function(`return ${featuresText}`)();
return;
}

ts.forEachChild(node, processVariableDeclarations);
}

let featureName;

if (process.env.BUILD_TYPE === 'alpha') {
for (featureName in features) {
if (features[featureName] === null) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"eslint-plugin-node": "^8.0.1",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-qunit": "^4.0.0",
"esm": "^3.2.25",
"execa": "^2.0.1",
"express": "^4.17.1",
"finalhandler": "^1.1.2",
Expand Down
23 changes: 23 additions & 0 deletions packages/@ember/canary-features/default-features.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
This list of features is used both at build time (by `broccoli/features.js`)
and at runtime (by `@ember/canary-features`).

The valid values are:

- true - The feature is enabled at all times, and cannot be disabled.
- false - The feature is disabled at all times, and cannot be enabled.
- null - The feature is disabled by default, but can be enabled at runtime via `EmberENV`.
*/
export default {
EMBER_LIBRARIES_ISREGISTERED: null,
EMBER_IMPROVED_INSTRUMENTATION: null,
EMBER_MODULE_UNIFICATION: false,
EMBER_METAL_TRACKED_PROPERTIES: true,
EMBER_GLIMMER_FORWARD_MODIFIERS_WITH_SPLATTRIBUTES: true,
EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS: true,
EMBER_NATIVE_DECORATOR_SUPPORT: true,
EMBER_GLIMMER_FN_HELPER: true,
EMBER_CUSTOM_COMPONENT_ARG_PROXY: true,
EMBER_FRAMEWORK_OBJECT_OWNER_ARGUMENT: true,
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE: null,
};
15 changes: 2 additions & 13 deletions packages/@ember/canary-features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@ import { assign } from '@ember/polyfills';
@public
*/

export const DEFAULT_FEATURES = {
EMBER_LIBRARIES_ISREGISTERED: null,
EMBER_IMPROVED_INSTRUMENTATION: null,
EMBER_MODULE_UNIFICATION: false,
EMBER_METAL_TRACKED_PROPERTIES: true,
EMBER_GLIMMER_FORWARD_MODIFIERS_WITH_SPLATTRIBUTES: true,
EMBER_GLIMMER_ANGLE_BRACKET_BUILT_INS: true,
EMBER_NATIVE_DECORATOR_SUPPORT: true,
EMBER_GLIMMER_FN_HELPER: true,
EMBER_CUSTOM_COMPONENT_ARG_PROXY: true,
EMBER_FRAMEWORK_OBJECT_OWNER_ARGUMENT: true,
EMBER_GLIMMER_SET_COMPONENT_TEMPLATE: null,
};
import { default: DEFAULT_FEATURES } from '@ember/canary-features/default-features';
This conversation was marked as resolved.
Show resolved Hide resolved
This conversation was marked as resolved.
Show resolved Hide resolved
export const DEFAULT_FEATURES;

/**
The hash of enabled Canary features. Add to this, any canary features
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3390,6 +3390,11 @@ eslint@^5.16.0:
table "^5.2.3"
text-table "^0.2.0"

esm@^3.2.25:
version "3.2.25"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.25.tgz#342c18c29d56157688ba5ce31f8431fbb795cc10"
integrity sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==

esm@^3.2.4:
version "3.2.22"
resolved "https://registry.yarnpkg.com/esm/-/esm-3.2.22.tgz#5062c2e22fee3ccfee4e8f20da768330da90d6e3"
Expand Down