From bdba13c4d4634fe9461fe751a18ba4d878fd8fbe Mon Sep 17 00:00:00 2001 From: Bartlomiej Dudzik Date: Mon, 3 Apr 2023 09:19:03 +0200 Subject: [PATCH] feat: import @ember/polyfills assign conditionally --- packages/ember-cookies/package.json | 3 +- .../ember-cookies/src/services/cookies.js | 2 +- .../src/test-support/clear-all-cookies.js | 2 +- packages/ember-cookies/src/utils/assign.js | 12 ++++++++ yarn.lock | 28 +++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 packages/ember-cookies/src/utils/assign.js diff --git a/packages/ember-cookies/package.json b/packages/ember-cookies/package.json index 0b920966..2764313a 100644 --- a/packages/ember-cookies/package.json +++ b/packages/ember-cookies/package.json @@ -33,7 +33,8 @@ "test": "echo 'A v2 addon does not have tests, run tests in test-app'" }, "dependencies": { - "@embroider/addon-shim": "^1.7.1" + "@embroider/addon-shim": "^1.7.1", + "@embroider/macros": "^1.10.0" }, "devDependencies": { "@babel/core": "^7.18.2", diff --git a/packages/ember-cookies/src/services/cookies.js b/packages/ember-cookies/src/services/cookies.js index a071fc69..40c5421f 100644 --- a/packages/ember-cookies/src/services/cookies.js +++ b/packages/ember-cookies/src/services/cookies.js @@ -3,8 +3,8 @@ import { get } from '@ember/object'; import { assert } from '@ember/debug'; import { getOwner } from '@ember/application'; import Service from '@ember/service'; -import { assign as emberAssign } from '@ember/polyfills'; import { serializeCookie } from '../utils/serialize-cookie'; +import emberAssign from 'ember-cookies/utils/assign'; const { keys } = Object; const assign = Object.assign || emberAssign; const DEFAULTS = { raw: false }; diff --git a/packages/ember-cookies/src/test-support/clear-all-cookies.js b/packages/ember-cookies/src/test-support/clear-all-cookies.js index 8c8bbc19..a77cb68a 100644 --- a/packages/ember-cookies/src/test-support/clear-all-cookies.js +++ b/packages/ember-cookies/src/test-support/clear-all-cookies.js @@ -1,5 +1,5 @@ import { assert } from '@ember/debug'; -import { assign as emberAssign } from '@ember/polyfills'; +import emberAssign from 'ember-cookies/utils/assign'; import { isEmpty } from '@ember/utils'; import { serializeCookie } from '../utils/serialize-cookie'; diff --git a/packages/ember-cookies/src/utils/assign.js b/packages/ember-cookies/src/utils/assign.js new file mode 100644 index 00000000..b9484b0f --- /dev/null +++ b/packages/ember-cookies/src/utils/assign.js @@ -0,0 +1,12 @@ +import { importSync } from '@embroider/macros'; + +let assign; + +try { + assign = importSync('@ember/polyfills').assign; +} catch (error) { + // Couldn't import @ember/polyfills, doesn't exist in v5. + // This is needed for Ember v5 support where the polyfill is already removed. +} + +export default Object.assign || assign; diff --git a/yarn.lock b/yarn.lock index 28daf822..a4a7b82c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1123,6 +1123,20 @@ resolve "^1.20.0" semver "^7.3.2" +"@embroider/macros@^1.10.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== + dependencies: + "@embroider/shared-internals" "2.0.0" + assert-never "^1.2.1" + babel-import-util "^1.1.0" + ember-cli-babel "^7.26.6" + find-up "^5.0.0" + lodash "^4.17.21" + resolve "^1.20.0" + semver "^7.3.2" + "@embroider/shared-internals@1.8.3", "@embroider/shared-internals@^1.0.0", "@embroider/shared-internals@^1.8.3": version "1.8.3" resolved "https://registry.yarnpkg.com/@embroider/shared-internals/-/shared-internals-1.8.3.tgz#52d868dc80016e9fe983552c0e516f437bf9b9f9" @@ -1137,6 +1151,20 @@ semver "^7.3.5" typescript-memoize "^1.0.1" +"@embroider/shared-internals@2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@embroider/shared-internals/-/shared-internals-2.0.0.tgz#d8205ec6944362aeecfbb51143db352430ced316" + integrity sha512-qZ2/xky9mWm5YC6noOa6AiAwgISEQ78YTZNv4SNu2PFgEK/H+Ha/3ddngzGSsnXkVnIHZyxIBzhxETonQYHY9g== + dependencies: + babel-import-util "^1.1.0" + ember-rfc176-data "^0.3.17" + fs-extra "^9.1.0" + js-string-escape "^1.0.1" + lodash "^4.17.21" + resolve-package-path "^4.0.1" + semver "^7.3.5" + typescript-memoize "^1.0.1" + "@embroider/test-setup@1.8.3": version "1.8.3" resolved "https://registry.yarnpkg.com/@embroider/test-setup/-/test-setup-1.8.3.tgz#445b9fe5a363ce50367ac2114750597f98d7806d"