diff --git a/broccoli/deprecated-features.js b/broccoli/deprecated-features.js index 743c974812d..066d62f302d 100644 --- a/broccoli/deprecated-features.js +++ b/broccoli/deprecated-features.js @@ -1,54 +1,16 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); -const ts = require('./typescript'); +const requireEsm = require('esm')(module); /** * @param name {string} * @param source {string} */ const DEPRECATED_FEATURES = (function getFeatures() { - let fileName = path.join( - __dirname, - '..', - 'packages', - '@ember', - 'deprecated-features', - 'index.ts' + const { default: flags } = requireEsm( + '../packages/@ember/deprecated-features/deprecated-features.js' ); - let contents = fs.readFileSync(fileName, 'utf8'); - let sourceFile = ts.createSourceFile(fileName, contents, ts.ScriptTarget.ES2017); - let flags = {}; - - sourceFile.statements.forEach(statement => { - if ( - statement.kind === ts.SyntaxKind.VariableStatement && - statement.modifiers.some(m => m.kind === ts.SyntaxKind.ExportKeyword) - ) { - handleExportedDeclaration(statement, flags); - } - }); - return flags; })(); -/** - * @param d {ts.VariableStatement} - * @param map {{[flag: string]: string}} - */ -function handleExportedDeclaration(d, map) { - let declaration = d.declarationList.declarations[0]; - /** @type {ts.StringLiteral} */ - let initializer = declaration.initializer; - if ( - initializer && - initializer.kind === ts.SyntaxKind.PrefixUnaryExpression && - initializer.operand.kind === ts.SyntaxKind.PrefixUnaryExpression && - initializer.operand.operand.kind === ts.SyntaxKind.StringLiteral - ) { - map[declaration.name.text] = initializer.operand.operand.text; - } -} - module.exports = DEPRECATED_FEATURES; diff --git a/broccoli/features.js b/broccoli/features.js index 3c0299b8e9a..caae0a9d457 100644 --- a/broccoli/features.js +++ b/broccoli/features.js @@ -1,35 +1,12 @@ 'use strict'; -const fs = require('fs'); -const ts = require('./typescript'); - +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' ); - 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) { diff --git a/broccoli/typescript.js b/broccoli/typescript.js deleted file mode 100644 index e43043afa8b..00000000000 --- a/broccoli/typescript.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -const resolve = require('resolve'); -const path = require('path'); - -// our typescript version comes from a dependency in -// broccoli-typescript-compiler, so we look typescript up -// from there... -let broccoliTypescriptCompilerRoot = path.dirname( - resolve.sync('broccoli-typescript-compiler/package.json'), - { basedir: __dirname } -); -let typescriptEntryPoint = resolve.sync('typescript', { - basedir: broccoliTypescriptCompilerRoot, -}); - -module.exports = require(typescriptEntryPoint); diff --git a/package.json b/package.json index 4f2605a60f5..37c3ddd60aa 100644 --- a/package.json +++ b/package.json @@ -141,6 +141,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", diff --git a/packages/@ember/canary-features/default-features.d.ts b/packages/@ember/canary-features/default-features.d.ts new file mode 100644 index 00000000000..64b8925e227 --- /dev/null +++ b/packages/@ember/canary-features/default-features.d.ts @@ -0,0 +1,5 @@ +export interface DefaultFeatures { + [key: string]: null | boolean; +} +declare const DEFAULT_FEATURES: DefaultFeatures; +export default DEFAULT_FEATURES; diff --git a/packages/@ember/canary-features/default-features.js b/packages/@ember/canary-features/default-features.js new file mode 100644 index 00000000000..b0b96acea05 --- /dev/null +++ b/packages/@ember/canary-features/default-features.js @@ -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, +}; diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index 4df22887a0d..97982b23ec1 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -12,19 +12,9 @@ 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: true, -}; +export { default as DEFAULT_FEATURES } from './default-features'; + +import DEFAULT_FEATURES from './default-features'; /** The hash of enabled Canary features. Add to this, any canary features diff --git a/packages/@ember/deprecated-features/index.d.ts b/packages/@ember/deprecated-features/index.d.ts new file mode 100644 index 00000000000..993f82565a6 --- /dev/null +++ b/packages/@ember/deprecated-features/index.d.ts @@ -0,0 +1,11 @@ +export declare const SEND_ACTION: boolean; +export declare const EMBER_EXTEND_PROTOTYPES: boolean; +export declare const LOGGER: boolean; +export declare const MERGE: boolean; +export declare const ROUTER_EVENTS: boolean; +export declare const COMPONENT_MANAGER_STRING_LOOKUP: boolean; +export declare const JQUERY_INTEGRATION: boolean; +export declare const ALIAS_METHOD: boolean; +export declare const APP_CTRL_ROUTER_PROPS: boolean; +export declare const FUNCTION_PROTOTYPE_EXTENSIONS: boolean; +export declare const MOUSE_ENTER_LEAVE_MOVE_EVENTS: boolean; diff --git a/packages/@ember/deprecated-features/index.js b/packages/@ember/deprecated-features/index.js new file mode 100644 index 00000000000..724ffb311f3 --- /dev/null +++ b/packages/@ember/deprecated-features/index.js @@ -0,0 +1,16 @@ +/* eslint-disable no-implicit-coercion */ + +// These versions should be the version that the deprecation was _introduced_, +// not the version that the feature will be removed. + +export const SEND_ACTION = !!'3.4.0'; +export const EMBER_EXTEND_PROTOTYPES = !!'3.2.0-beta.5'; +export const LOGGER = !!'3.2.0-beta.1'; +export const MERGE = !!'3.6.0-beta.1'; +export const ROUTER_EVENTS = !!'4.0.0'; +export const COMPONENT_MANAGER_STRING_LOOKUP = !!'3.8.0'; +export const JQUERY_INTEGRATION = !!'3.9.0'; +export const ALIAS_METHOD = !!'3.9.0'; +export const APP_CTRL_ROUTER_PROPS = !!'3.10.0-beta.1'; +export const FUNCTION_PROTOTYPE_EXTENSIONS = !!'3.11.0-beta.1'; +export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = !!'3.13.0-beta.1'; diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index 724ffb311f3..73f38f8c40a 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -1,16 +1,11 @@ -/* eslint-disable no-implicit-coercion */ - -// These versions should be the version that the deprecation was _introduced_, -// not the version that the feature will be removed. - -export const SEND_ACTION = !!'3.4.0'; -export const EMBER_EXTEND_PROTOTYPES = !!'3.2.0-beta.5'; -export const LOGGER = !!'3.2.0-beta.1'; -export const MERGE = !!'3.6.0-beta.1'; -export const ROUTER_EVENTS = !!'4.0.0'; -export const COMPONENT_MANAGER_STRING_LOOKUP = !!'3.8.0'; -export const JQUERY_INTEGRATION = !!'3.9.0'; -export const ALIAS_METHOD = !!'3.9.0'; -export const APP_CTRL_ROUTER_PROPS = !!'3.10.0-beta.1'; -export const FUNCTION_PROTOTYPE_EXTENSIONS = !!'3.11.0-beta.1'; -export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = !!'3.13.0-beta.1'; +export const SEND_ACTION = Boolean('3.4.0'); +export const EMBER_EXTEND_PROTOTYPES = Boolean('3.2.0-beta.5'); +export const LOGGER = Boolean('3.2.0-beta.1'); +export const MERGE = Boolean('3.6.0-beta.1'); +export const ROUTER_EVENTS = Boolean('4.0.0'); +export const COMPONENT_MANAGER_STRING_LOOKUP = Boolean('3.8.0'); +export const JQUERY_INTEGRATION = Boolean('3.9.0'); +export const ALIAS_METHOD = Boolean('3.9.0'); +export const APP_CTRL_ROUTER_PROPS = Boolean('3.10.0-beta.1'); +export const FUNCTION_PROTOTYPE_EXTENSIONS = Boolean('3.11.0-beta.1'); +export const MOUSE_ENTER_LEAVE_MOVE_EVENTS = Boolean('3.13.0-beta.1'); diff --git a/yarn.lock b/yarn.lock index f80c6bab018..1ee1e1fefcf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"