From acf409c1a353a77141bd2994b2133a995f7c1c9f Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Wed, 19 Feb 2025 20:48:24 -0800 Subject: [PATCH 1/8] temporary include tsup to tsconfig --- packages/shared/tsconfig.json | 2 +- packages/shared/tsup.config.ts | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index f120c796cd0..c26f908c172 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -20,5 +20,5 @@ "allowJs": true }, "exclude": ["node_modules"], - "include": ["src", "global.d.ts"] + "include": ["src", "global.d.ts", "tsup.config.ts"] } diff --git a/packages/shared/tsup.config.ts b/packages/shared/tsup.config.ts index 6515b9da11d..668fb7a5b56 100644 --- a/packages/shared/tsup.config.ts +++ b/packages/shared/tsup.config.ts @@ -24,9 +24,8 @@ export default defineConfig(overrideOptions => { minify: false, sourcemap: true, dts: true, - target: 'es2020', external: ['react', 'react-dom'], - esbuildPlugins: [WebWorkerMinifyPlugin as any], + esbuildPlugins: [WebWorkerMinifyPlugin as any, preserveImportMetaPlugin], define: { PACKAGE_NAME: `"${name}"`, PACKAGE_VERSION: `"${version}"`, @@ -49,3 +48,28 @@ export const WebWorkerMinifyPlugin: Plugin = { }); }, }; + +/** + * Preserves import.meta functionality in ESM builds while maintaining ES5 compatibility. + * We originally used target: 'es2020' to handle this but it broke support for older browsers (e.g. iOS 12). + */ +const preserveImportMetaPlugin: Plugin = { + name: 'preserve-import-meta', + setup(build) { + build.onEnd(async result => { + if (!result.outputFiles) return; + + result.outputFiles.forEach(file => { + if (!file.path.endsWith('.mjs')) return; + + const contents = file.contents; + const text = new TextDecoder().decode(contents); + + // Remove esbuild's var import_meta = {} transformation and restore original import.meta references + const modified = text.replace(/var\s+import_meta\s*=\s*{};/g, '').replace(/import_meta/g, 'import.meta'); + + file.contents = new TextEncoder().encode(modified); + }); + }); + }, +}; From 06dde1a8dd9c9dcc00bf7134e443fa4cfbe3a93e Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Wed, 19 Feb 2025 20:48:39 -0800 Subject: [PATCH 2/8] revert previous commit --- packages/shared/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index c26f908c172..f120c796cd0 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -20,5 +20,5 @@ "allowJs": true }, "exclude": ["node_modules"], - "include": ["src", "global.d.ts", "tsup.config.ts"] + "include": ["src", "global.d.ts"] } From 2421d1851fc9bbd359f906c4a57d855e23305ed8 Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Wed, 19 Feb 2025 20:52:03 -0800 Subject: [PATCH 3/8] remove unused async keyword --- packages/shared/tsconfig.json | 2 +- packages/shared/tsup.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index f120c796cd0..c26f908c172 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -20,5 +20,5 @@ "allowJs": true }, "exclude": ["node_modules"], - "include": ["src", "global.d.ts"] + "include": ["src", "global.d.ts", "tsup.config.ts"] } diff --git a/packages/shared/tsup.config.ts b/packages/shared/tsup.config.ts index 668fb7a5b56..626973a6ee4 100644 --- a/packages/shared/tsup.config.ts +++ b/packages/shared/tsup.config.ts @@ -56,7 +56,7 @@ export const WebWorkerMinifyPlugin: Plugin = { const preserveImportMetaPlugin: Plugin = { name: 'preserve-import-meta', setup(build) { - build.onEnd(async result => { + build.onEnd(result => { if (!result.outputFiles) return; result.outputFiles.forEach(file => { From 0b52af5e7b32d4c1a16fe9d61894af792df73874 Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Wed, 19 Feb 2025 20:52:17 -0800 Subject: [PATCH 4/8] remove tsup config from tsconfig --- packages/shared/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index c26f908c172..f120c796cd0 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -20,5 +20,5 @@ "allowJs": true }, "exclude": ["node_modules"], - "include": ["src", "global.d.ts", "tsup.config.ts"] + "include": ["src", "global.d.ts"] } From 6aed6a662ebbe96ce3266ed15e589569534d3d64 Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Wed, 19 Feb 2025 21:13:19 -0800 Subject: [PATCH 5/8] chore: add changeset --- .changeset/fuzzy-radios-tease.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/fuzzy-radios-tease.md diff --git a/.changeset/fuzzy-radios-tease.md b/.changeset/fuzzy-radios-tease.md new file mode 100644 index 00000000000..7183e3f391d --- /dev/null +++ b/.changeset/fuzzy-radios-tease.md @@ -0,0 +1,5 @@ +--- +"@clerk/shared": patch +--- + +Fix compatibility with iOS 12 and older browsers while maintaining Vite support From e479de3adea07ed202f2aec76ff708bbbb0aec56 Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Wed, 19 Feb 2025 21:13:57 -0800 Subject: [PATCH 6/8] clean up plugin name --- packages/shared/tsconfig.json | 2 +- packages/shared/tsup.config.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index f120c796cd0..c26f908c172 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -20,5 +20,5 @@ "allowJs": true }, "exclude": ["node_modules"], - "include": ["src", "global.d.ts"] + "include": ["src", "global.d.ts", "tsup.config.ts"] } diff --git a/packages/shared/tsup.config.ts b/packages/shared/tsup.config.ts index 626973a6ee4..cc44db2df56 100644 --- a/packages/shared/tsup.config.ts +++ b/packages/shared/tsup.config.ts @@ -25,7 +25,7 @@ export default defineConfig(overrideOptions => { sourcemap: true, dts: true, external: ['react', 'react-dom'], - esbuildPlugins: [WebWorkerMinifyPlugin as any, preserveImportMetaPlugin], + esbuildPlugins: [WebWorkerMinifyPlugin as any, PreserveImportMetaPlugin], define: { PACKAGE_NAME: `"${name}"`, PACKAGE_VERSION: `"${version}"`, @@ -53,8 +53,8 @@ export const WebWorkerMinifyPlugin: Plugin = { * Preserves import.meta functionality in ESM builds while maintaining ES5 compatibility. * We originally used target: 'es2020' to handle this but it broke support for older browsers (e.g. iOS 12). */ -const preserveImportMetaPlugin: Plugin = { - name: 'preserve-import-meta', +const PreserveImportMetaPlugin: Plugin = { + name: 'PreserveImportMetaPlugin', setup(build) { build.onEnd(result => { if (!result.outputFiles) return; From 67d81c27c3d9f1c5c48c8c2435c44b22f2e7a5bf Mon Sep 17 00:00:00 2001 From: wobsoriano Date: Wed, 19 Feb 2025 21:14:09 -0800 Subject: [PATCH 7/8] remove tsup config from tsconfig --- packages/shared/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared/tsconfig.json b/packages/shared/tsconfig.json index c26f908c172..f120c796cd0 100644 --- a/packages/shared/tsconfig.json +++ b/packages/shared/tsconfig.json @@ -20,5 +20,5 @@ "allowJs": true }, "exclude": ["node_modules"], - "include": ["src", "global.d.ts", "tsup.config.ts"] + "include": ["src", "global.d.ts"] } From 322f1b618e7f6b51d5764ef9797c0ee8d0ba3d9e Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Wed, 19 Feb 2025 21:44:21 -0800 Subject: [PATCH 8/8] chore: update changeset --- .changeset/fuzzy-radios-tease.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/fuzzy-radios-tease.md b/.changeset/fuzzy-radios-tease.md index 7183e3f391d..2b1e1a5be4a 100644 --- a/.changeset/fuzzy-radios-tease.md +++ b/.changeset/fuzzy-radios-tease.md @@ -1,5 +1,5 @@ --- -"@clerk/shared": patch +"@clerk/shared": minor --- Fix compatibility with iOS 12 and older browsers while maintaining Vite support