diff --git a/.babelrc.js b/.babelrc.js index 5e1a0a0c..dfc5795b 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -2,7 +2,10 @@ module.exports = (api) => { const isTest = api.env('test'); return { - plugins: ['@babel/plugin-proposal-explicit-resource-management'], + plugins: [ + '@babel/plugin-proposal-explicit-resource-management', + ...(isTest ? [] : ['module:@reactioncommerce/babel-remove-es-create-require']), + ], presets: [ [ '@babel/preset-env', diff --git a/package.json b/package.json index 734c8eea..ec2a3241 100644 --- a/package.json +++ b/package.json @@ -67,6 +67,7 @@ "@babel/preset-typescript": "7.24.1", "@hapi/wreck": "18.0.1", "@jest/globals": "29.7.0", + "@reactioncommerce/babel-remove-es-create-require": "1.0.0", "@semantic-release/changelog": "6.0.3", "@semantic-release/git": "10.0.1", "@types/deasync": "0.1.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b7d7e36e..e94e2a0e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,6 +42,9 @@ devDependencies: '@jest/globals': specifier: 29.7.0 version: 29.7.0 + '@reactioncommerce/babel-remove-es-create-require': + specifier: 1.0.0 + version: 1.0.0(@babel/core@7.24.3) '@semantic-release/changelog': specifier: 6.0.3 version: 6.0.3(semantic-release@22.0.12) @@ -2111,6 +2114,14 @@ packages: config-chain: 1.1.13 dev: true + /@reactioncommerce/babel-remove-es-create-require@1.0.0(@babel/core@7.24.3): + resolution: {integrity: sha512-yR1vMj76hK5D9/VcXjFpk2OMoYpQdbvEgGcJ79cEzTL/jkFwIs53Zl6PNBjcC608P8qHl5eypEYRwG7CCGLzwQ==} + peerDependencies: + '@babel/core': ^7.0.0-0 + dependencies: + '@babel/core': 7.24.3 + dev: true + /@semantic-release/changelog@6.0.3(semantic-release@22.0.12): resolution: {integrity: sha512-dZuR5qByyfe3Y03TpmCvAxCyTnp7r5XwtHRf/8vD9EAn4ZWbavUX8adMtXYzE86EVh0gyLA7lm5yW4IV30XUag==} engines: {node: '>=14.17'} diff --git a/src/utils/create_cookie_header_value.ts b/src/utils/create_cookie_header_value.ts index e143a4a0..6b32ee9f 100644 --- a/src/utils/create_cookie_header_value.ts +++ b/src/utils/create_cookie_header_value.ts @@ -4,7 +4,7 @@ import { Cookie } from 'tough-cookie'; import type { CookieOptions } from '../cookie_options'; -const require = 'require' in globalThis ? globalThis.require : createRequire(import.meta.url); +const require = createRequire(import.meta.url); type Params = { cookieOptions: CookieOptions; diff --git a/src/utils/save_cookies_from_header.ts b/src/utils/save_cookies_from_header.ts index 496a1b14..d79e8916 100644 --- a/src/utils/save_cookies_from_header.ts +++ b/src/utils/save_cookies_from_header.ts @@ -2,7 +2,7 @@ import { createRequire } from 'node:module'; import type { CookieOptions } from '../cookie_options'; -const require = 'require' in globalThis ? globalThis.require : createRequire(import.meta.url); +const require = createRequire(import.meta.url); type Params = { cookieOptions: CookieOptions; diff --git a/src/utils/validate_cookie_options.ts b/src/utils/validate_cookie_options.ts index 79acd450..49afba92 100644 --- a/src/utils/validate_cookie_options.ts +++ b/src/utils/validate_cookie_options.ts @@ -2,7 +2,7 @@ import { createRequire } from 'node:module'; import type { CookieOptions } from '../cookie_options'; -const require = 'require' in globalThis ? globalThis.require : createRequire(import.meta.url); +const require = createRequire(import.meta.url); type ModuleResolver = (id: string) => string;