-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: #22038 support esm import for windows #22042
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5599f51
fix: #22038 better windows ESM interop
tgriesser 7d3169f
attempt to get failing tests first
tgriesser 5588c8f
fix typo, don't throw originalError
tgriesser 36e8740
add pathToFileURL for windows interop
tgriesser b6b9e05
Merge branch 'develop' into tgriesser/fix/22038-esm-import-windows
tgriesser 98608d8
typo again
tgriesser 7353283
Merge branch 'tgriesser/fix/22038-esm-import-windows' of github.com:c…
tgriesser c83af1a
updates from @flotwig feedback
tgriesser 0a43737
remove invalid snapshot
tgriesser 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 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
require('graceful-fs').gracefulify(require('fs')) | ||
const stripAnsi = require('strip-ansi') | ||
const debug = require('debug')(`cypress:lifecycle:child:run_require_async_child:${process.pid}`) | ||
const { pathToFileURL } = require('url') | ||
const tsNodeUtil = require('./ts_node') | ||
const util = require('../util') | ||
const { RunPlugins } = require('./run_plugins') | ||
|
@@ -97,12 +98,10 @@ function run (ipc, file, projectRoot) { | |
// 3a. Yes: Use bundleRequire | ||
// 3b. No: Continue through to `await import(configFile)` | ||
// 4. Use node's dynamic import to import the configFile | ||
let originalError | ||
|
||
try { | ||
return require(file) | ||
} catch (err) { | ||
originalError = err | ||
if (!err.stack.includes('[ERR_REQUIRE_ESM]') && !err.stack.includes('SyntaxError: Cannot use import statement outside a module')) { | ||
throw err | ||
} | ||
|
@@ -124,16 +123,10 @@ function run (ipc, file, projectRoot) { | |
debug(`User doesn't have esbuild. Going to use native node imports.`) | ||
|
||
// We cannot replace the initial `require` with `await import` because | ||
// Certain modules cannot be dynamically imported. If this throws, however, we want | ||
// to show the original error that was thrown, because that's ultimately the source of the problem | ||
try { | ||
return await import(file) | ||
} catch (e) { | ||
// If we aren't able to import the file at all, throw the original error, since that has more accurate information | ||
// of what failed to begin with | ||
debug('esbuild fallback for loading config failed, throwing original error. node import error: %o', e) | ||
throw originalError | ||
} | ||
// Certain modules cannot be dynamically imported. | ||
|
||
// pathToFileURL for windows interop: https://github.com/nodejs/node/issues/31710 | ||
return await import(pathToFileURL(file).href) | ||
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. If the file is a |
||
} | ||
|
||
throw err | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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
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.
We weren't confirming the flow completed, which meant we were missing a failure here