From 1ad85bd68d47f4cfe6f1e69b09558bee3e982519 Mon Sep 17 00:00:00 2001 From: BobrImperator Date: Fri, 31 Mar 2023 13:21:53 +0200 Subject: [PATCH 1/3] feat: use embroider macro to conditionally import assign polyfill --- packages/ember-simple-auth/addon/utils/assign.js | 8 +++++++- packages/ember-simple-auth/package.json | 7 ++++--- yarn.lock | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/ember-simple-auth/addon/utils/assign.js b/packages/ember-simple-auth/addon/utils/assign.js index 10fa68eb4..c48bb0226 100644 --- a/packages/ember-simple-auth/addon/utils/assign.js +++ b/packages/ember-simple-auth/addon/utils/assign.js @@ -1,3 +1,9 @@ -import { assign } from '@ember/polyfills'; +import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros'; + +let assign; + +if (macroCondition(dependencySatisfies('ember-source', '<5.x'))) { + assign = importSync('@ember/polyfills').assign; +} export default Object.assign || assign; diff --git a/packages/ember-simple-auth/package.json b/packages/ember-simple-auth/package.json index 7709b2169..9a1ad8f60 100644 --- a/packages/ember-simple-auth/package.json +++ b/packages/ember-simple-auth/package.json @@ -28,15 +28,16 @@ "ember-cli-babel": "^7.20.5", "ember-cli-is-package-missing": "^1.0.0", "ember-cookies": "^0.5.0", - "silent-error": "^1.0.0" + "silent-error": "^1.0.0", + "@embroider/macros": "^1.10.0" }, "devDependencies": { + "@babel/eslint-parser": "^7.11.0", "@ember/optional-features": "^2.0.0", "@ember/test-helpers": "~2.7.0", "@embroider/test-setup": "^2.0.0", "@glimmer/component": "^1.0.0", "@glimmer/tracking": "^1.0.0", - "@babel/eslint-parser": "^7.11.0", "broccoli-asset-rev": "^3.0.0", "ember-auto-import": "^2.4.2", "ember-cli": "~4.3.0", @@ -45,7 +46,6 @@ "ember-cli-dependency-checker": "^3.2.0", "ember-cli-htmlbars": "^6.0.0", "ember-cli-inject-live-reload": "^2.0.1", - "pretender": "3.4.7", "ember-cli-sri": "^2.1.1", "ember-cli-terser": "4.0.2", "ember-cli-yuidoc": "^0.9.1", @@ -70,6 +70,7 @@ "marked": "^4.0.0", "mocha": "^10.0.0", "npm-run-all": "^4.1.5", + "pretender": "3.4.7", "qunit": "^2.17.2", "qunit-dom": "^2.0.0", "sinon": "15.0.0", diff --git a/yarn.lock b/yarn.lock index 1ea35f0ae..ae275e949 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1199,7 +1199,7 @@ ember-cli-version-checker "^5.1.2" semver "^7.3.5" -"@embroider/macros@^1.0.0", "@embroider/macros@^1.3.0": +"@embroider/macros@^1.0.0", "@embroider/macros@^1.10.0", "@embroider/macros@^1.3.0": version "1.10.0" resolved "https://registry.yarnpkg.com/@embroider/macros/-/macros-1.10.0.tgz#af3844d5db48f001b85cfb096c76727c72ad6c1e" integrity sha512-LMbfQGk/a+f6xtvAv5fq/wf2LRxETnbgSCLUf/z6ebzmuskOUxrke+uP55chF/loWrARi9g6erFQ7RDOUoBMSg== From 079d50faacd64debb38acc5c007772f0ba8d5d26 Mon Sep 17 00:00:00 2001 From: BobrImperator Date: Fri, 31 Mar 2023 13:27:41 +0200 Subject: [PATCH 2/3] chore: fix ember-canary scenario --- packages/ember-simple-auth/config/ember-try.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/ember-simple-auth/config/ember-try.js b/packages/ember-simple-auth/config/ember-try.js index 3abcd0b8b..e42632fee 100644 --- a/packages/ember-simple-auth/config/ember-try.js +++ b/packages/ember-simple-auth/config/ember-try.js @@ -175,6 +175,9 @@ module.exports = function() { 'ember-qunit': '^5.1.4', qunit: '^2.17.2', 'ember-cli-app-version': '~5.0.0', + 'ember-resolver': '10.0.0', + '@ember/string': '3.0.1', + torii: null, }, }, }, From cb12c0fecada6e89903ee683c5cc5a96f1b6311b Mon Sep 17 00:00:00 2001 From: Bartlomiej Dudzik Date: Mon, 3 Apr 2023 09:01:14 +0200 Subject: [PATCH 3/3] feat: wrap importSync in try catch --- packages/ember-simple-auth/addon/utils/assign.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/ember-simple-auth/addon/utils/assign.js b/packages/ember-simple-auth/addon/utils/assign.js index c48bb0226..752ebbb8a 100644 --- a/packages/ember-simple-auth/addon/utils/assign.js +++ b/packages/ember-simple-auth/addon/utils/assign.js @@ -1,9 +1,12 @@ -import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros'; +import { importSync } from '@embroider/macros'; let assign; -if (macroCondition(dependencySatisfies('ember-source', '<5.x'))) { +try { assign = importSync('@ember/polyfills').assign; +} catch (error) { + // Couldn't import @ember/polyfills + // Doesn't exist in v5 } export default Object.assign || assign;