-
Notifications
You must be signed in to change notification settings - Fork 361
fix(shared): Preserve import.meta
without requiring ES2020 target
#5203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
acf409c
temporary include tsup to tsconfig
wobsoriano 06dde1a
revert previous commit
wobsoriano 2421d18
remove unused async keyword
wobsoriano 0b52af5
remove tsup config from tsconfig
wobsoriano 6aed6a6
chore: add changeset
wobsoriano e479de3
clean up plugin name
wobsoriano 67d81c2
remove tsup config from tsconfig
wobsoriano 322f1b6
chore: update changeset
wobsoriano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@clerk/shared": minor | ||
--- | ||
|
||
Fix compatibility with iOS 12 and older browsers while maintaining Vite support |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: 'PreserveImportMetaPlugin', | ||
setup(build) { | ||
build.onEnd(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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This restores the original Example built file: ![]() without the plugin and ES2020 target, it gets transformed to: var import_meta = {};
// ... other code
if (typeof import_meta !== "undefined" && import_meta.env && typeof import_meta.env[name] === "string") {
return import_meta.env[name];
} |
||
|
||
file.contents = new TextEncoder().encode(modified); | ||
}); | ||
}); | ||
}, | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're removing the target...