MAGMA-4673 Update sync-dynamic-imports reject unresolved imports with error and wrap require() with Promise.resolve#1030
Conversation
…ap require() calls with Promise.resolve().
🦋 Changeset detectedLatest commit: b96b9f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 114 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Missing ChangesetNo changeset found in PR. |
📊 Type Coverage ReportCoverage Comparison
Files with Most Type Issues (Top 15)
This report was generated by the Type Coverage GitHub Action |
📊 Benchmark Results✅ No significant performance changes detected. 📊 Benchmark ResultsOverall Performance
🔍 Detailed Phase AnalysisThree.js Real Repository (JS)
Three.js Real Repository (V3)
💾 Unified Memory AnalysisThree.js Real Repository (JS) Memory Statistics
Sample Counts: JS: 14, Native: 242 Three.js Real Repository (V3) Memory Statistics
Sample Counts: JS: 14, Native: 250 🖥️ Environment
|
OscarCookeAbbott
left a comment
There was a problem hiding this comment.
Is this change safe to just push up like this, not feature gated for rollout etc?
| fn create_rejecting_promise(&self, import_path: &Option<String>) -> Expr { | ||
| /// Legacy rejecting promise that rejects with a plain string. | ||
| /// Kept for backwards compatibility behind the `syncDynamicImportRejectWithError` feature flag. | ||
| fn create_rejecting_promise_old(&self, import_path: &Option<String>) -> Expr { |
There was a problem hiding this comment.
[nitpick] "old' is not particularly descriptive, string or 'warning' might be a better suffix for clarity here
Hey @OscarCookeAbbott I can't see exactly which code you're referring to. I believe this is feature gate safe because:
|
|
@OliverWessels Yes I just meant in general are these changes safe without rollout etc. It seems ok to me then, but given a recent change here needed a rollback @marcins do you have a second to review too please? |
Motivation
actual_require_pathscreates arequire(...)statement, which is not a promise. This is not correct becauseimport(...)returns a promise. This adds a new config namedsync_require_pathsintended to replace that, which wraps withPromise.resolve.activate_reject_on_unresolved_imports, which was added to feature-gate enable.Changes
activate_reject_on_unresolved_importsconfig option — unresolved dynamic imports now always generaterejecting promises
sync_require_pathsconfig option — behaves the same asactual_require_paths(substring matching) butwraps matched imports in
Promise.resolve(require(...))instead of barerequire(). Takes priority overactual_require_pathssyncDynamicImportRejectWithErrorfeature flag — when enabled, unresolved imports reject withnew Error(message)(with.skipSsr = true) instead of a plain stringsync_dynamic_import.rs,js_transformer.rs,lib.rs), TypeScript (JSTransformer.ts), and featureflags (
index.ts)