From c0e484a1c30cb0a30f2db4b6c097c86c454b56c1 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Wed, 24 Jul 2019 15:39:32 -0400 Subject: [PATCH 01/11] attempt to use esm for requiring features See https://github.com/emberjs/data/pull/6231#issuecomment-510088422 for the motivation. --- broccoli/features.js | 29 ++----------------- package.json | 1 + .../canary-features/default-features.js | 23 +++++++++++++++ packages/@ember/canary-features/index.ts | 15 ++-------- yarn.lock | 5 ++++ 5 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 packages/@ember/canary-features/default-features.js 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/package.json b/package.json index a73032215a7..d2b95b29dea 100644 --- a/package.json +++ b/package.json @@ -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", 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 9099973e3d8..af45473d1be 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -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'; +export const DEFAULT_FEATURES; /** The hash of enabled Canary features. Add to this, any canary features 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" From e2fd4b51a4bb4784b3edc45d1dbf46a44f824eb4 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 25 Jul 2019 12:08:12 -0400 Subject: [PATCH 02/11] Update packages/@ember/canary-features/index.ts Co-Authored-By: Robert Jackson --- packages/@ember/canary-features/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index af45473d1be..1be4c16485d 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -12,7 +12,7 @@ import { assign } from '@ember/polyfills'; @public */ -import { default: DEFAULT_FEATURES } from '@ember/canary-features/default-features'; +import DEFAULT_FEATURES from '@ember/canary-features/default-features'; export const DEFAULT_FEATURES; /** From e2de50c743004d46e5a998a3ce0156ba715044da Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 25 Jul 2019 12:10:03 -0400 Subject: [PATCH 03/11] redeclare and export to fix typescript linting --- packages/@ember/canary-features/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index 1be4c16485d..8874b34ba1e 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -12,8 +12,8 @@ import { assign } from '@ember/polyfills'; @public */ -import DEFAULT_FEATURES from '@ember/canary-features/default-features'; -export const DEFAULT_FEATURES; +import defaultFeatures from '@ember/canary-features/default-features'; +export const DEFAULT_FEATURES = defaultFeatures; /** The hash of enabled Canary features. Add to this, any canary features From fedf1d4cd2b39e3a4fe0168ee31c1941397721de Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 25 Jul 2019 12:28:47 -0400 Subject: [PATCH 04/11] add a loose declaration of default features hash --- packages/@ember/canary-features/default-features.d.ts | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 packages/@ember/canary-features/default-features.d.ts 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..7b07e2419e6 --- /dev/null +++ b/packages/@ember/canary-features/default-features.d.ts @@ -0,0 +1,2 @@ +declare let DEFAULT_FEATURES: any; +export default DEFAULT_FEATURES; From 15cdeaa021783a7566f7403a040695153cb264f2 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 25 Jul 2019 13:42:28 -0400 Subject: [PATCH 05/11] Update packages/@ember/canary-features/index.ts Co-Authored-By: Robert Jackson --- packages/@ember/canary-features/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index 8874b34ba1e..8d99d522d03 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -13,7 +13,6 @@ import { assign } from '@ember/polyfills'; */ import defaultFeatures from '@ember/canary-features/default-features'; -export const DEFAULT_FEATURES = defaultFeatures; /** The hash of enabled Canary features. Add to this, any canary features From 6a54e1a1402d4d889f45aa9ecb32a33fbe860d0c Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 25 Jul 2019 13:42:39 -0400 Subject: [PATCH 06/11] Update packages/@ember/canary-features/index.ts Co-Authored-By: Robert Jackson --- packages/@ember/canary-features/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/@ember/canary-features/index.ts b/packages/@ember/canary-features/index.ts index 8d99d522d03..97982b23ec1 100644 --- a/packages/@ember/canary-features/index.ts +++ b/packages/@ember/canary-features/index.ts @@ -12,7 +12,9 @@ import { assign } from '@ember/polyfills'; @public */ -import defaultFeatures from '@ember/canary-features/default-features'; +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 From 222e2187ca4957e0dd6d79cef33b3122583d063e Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 25 Jul 2019 13:43:33 -0400 Subject: [PATCH 07/11] tighten the type declaration for default features Made a breakthrough reading https://basarat.gitbooks.io/typescript/content/docs/types/ambient/variables.html --- packages/@ember/canary-features/default-features.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/@ember/canary-features/default-features.d.ts b/packages/@ember/canary-features/default-features.d.ts index 7b07e2419e6..64b8925e227 100644 --- a/packages/@ember/canary-features/default-features.d.ts +++ b/packages/@ember/canary-features/default-features.d.ts @@ -1,2 +1,5 @@ -declare let DEFAULT_FEATURES: any; +export interface DefaultFeatures { + [key: string]: null | boolean; +} +declare const DEFAULT_FEATURES: DefaultFeatures; export default DEFAULT_FEATURES; From b3d35e62f660ad331037b6f2d6e0ac68013f6dcf Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Fri, 26 Jul 2019 11:30:55 -0400 Subject: [PATCH 08/11] use esm for consuming deprecated features --- broccoli/deprecated-features.js | 44 ++----------------- broccoli/typescript.js | 17 ------- .../deprecated-features.d.ts | 10 +++++ .../deprecated-features.js | 15 +++++++ packages/@ember/deprecated-features/index.ts | 16 +------ 5 files changed, 29 insertions(+), 73 deletions(-) delete mode 100644 broccoli/typescript.js create mode 100644 packages/@ember/deprecated-features/deprecated-features.d.ts create mode 100644 packages/@ember/deprecated-features/deprecated-features.js 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/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/packages/@ember/deprecated-features/deprecated-features.d.ts b/packages/@ember/deprecated-features/deprecated-features.d.ts new file mode 100644 index 00000000000..ba5017ff62a --- /dev/null +++ b/packages/@ember/deprecated-features/deprecated-features.d.ts @@ -0,0 +1,10 @@ +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; diff --git a/packages/@ember/deprecated-features/deprecated-features.js b/packages/@ember/deprecated-features/deprecated-features.js new file mode 100644 index 00000000000..bf488ee0bf2 --- /dev/null +++ b/packages/@ember/deprecated-features/deprecated-features.js @@ -0,0 +1,15 @@ +/* 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'; diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index bf488ee0bf2..c2bc249ab19 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -1,15 +1 @@ -/* 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 * from './deprecated-features'; From 32695e2bc385c082825b94667b4f095e3bffc4fc Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Fri, 26 Jul 2019 11:33:23 -0400 Subject: [PATCH 09/11] merge with master Add newly deprecated feature from #18214 --- packages/@ember/deprecated-features/deprecated-features.d.ts | 1 + packages/@ember/deprecated-features/deprecated-features.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/@ember/deprecated-features/deprecated-features.d.ts b/packages/@ember/deprecated-features/deprecated-features.d.ts index ba5017ff62a..993f82565a6 100644 --- a/packages/@ember/deprecated-features/deprecated-features.d.ts +++ b/packages/@ember/deprecated-features/deprecated-features.d.ts @@ -8,3 +8,4 @@ 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/deprecated-features.js b/packages/@ember/deprecated-features/deprecated-features.js index bf488ee0bf2..724ffb311f3 100644 --- a/packages/@ember/deprecated-features/deprecated-features.js +++ b/packages/@ember/deprecated-features/deprecated-features.js @@ -13,3 +13,4 @@ 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'; From 95892c8ec6048a445b4171cabc7ff178ed3ac318 Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Thu, 1 Aug 2019 12:21:45 -0400 Subject: [PATCH 10/11] rename to index --- .../{deprecated-features.d.ts => index.d.ts} | 0 .../deprecated-features/{deprecated-features.js => index.js} | 0 packages/@ember/deprecated-features/index.ts | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename packages/@ember/deprecated-features/{deprecated-features.d.ts => index.d.ts} (100%) rename packages/@ember/deprecated-features/{deprecated-features.js => index.js} (100%) diff --git a/packages/@ember/deprecated-features/deprecated-features.d.ts b/packages/@ember/deprecated-features/index.d.ts similarity index 100% rename from packages/@ember/deprecated-features/deprecated-features.d.ts rename to packages/@ember/deprecated-features/index.d.ts diff --git a/packages/@ember/deprecated-features/deprecated-features.js b/packages/@ember/deprecated-features/index.js similarity index 100% rename from packages/@ember/deprecated-features/deprecated-features.js rename to packages/@ember/deprecated-features/index.js diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index c2bc249ab19..ee01cc9bd32 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -1 +1 @@ -export * from './deprecated-features'; +export * from './index.js'; From 6c02e4e04300504d638ea376159eaca1eb9d995c Mon Sep 17 00:00:00 2001 From: Eli Flanagan Date: Wed, 7 Aug 2019 13:34:20 -0400 Subject: [PATCH 11/11] copy and paste to fix typescript errors *I know not typescript* This makes it work but now there are 2 copies of these flags in `index.js` and `index.ts`. I am pushing up to avoid blocking and we can consider a follow up PR or any intervening TS guidance to solve the duplication. --- packages/@ember/deprecated-features/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/@ember/deprecated-features/index.ts b/packages/@ember/deprecated-features/index.ts index ee01cc9bd32..73f38f8c40a 100644 --- a/packages/@ember/deprecated-features/index.ts +++ b/packages/@ember/deprecated-features/index.ts @@ -1 +1,11 @@ -export * from './index.js'; +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');