-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the logic for handling --test-reporter out of the general module loader and into the test_runner subsystem.
- Loading branch information
1 parent
8398f85
commit 722fb95
Showing
5 changed files
with
37 additions
and
61 deletions.
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
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,55 +0,0 @@ | ||
'use strict'; | ||
|
||
const { | ||
ObjectCreate, | ||
StringPrototypeEndsWith, | ||
} = primordials; | ||
const { getOptionValue } = require('internal/options'); | ||
|
||
|
||
function shouldUseESMLoader(filePath) { | ||
/** | ||
* @type {string[]} userLoaders A list of custom loaders registered by the user | ||
* (or an empty list when none have been registered). | ||
*/ | ||
const userLoaders = getOptionValue('--experimental-loader'); | ||
/** | ||
* @type {string[]} userImports A list of preloaded modules registered by the user | ||
* (or an empty list when none have been registered). | ||
*/ | ||
const userImports = getOptionValue('--import'); | ||
if (userLoaders.length > 0 || userImports.length > 0) | ||
return true; | ||
// Determine the module format of the main | ||
if (filePath && StringPrototypeEndsWith(filePath, '.mjs')) | ||
return true; | ||
if (!filePath || StringPrototypeEndsWith(filePath, '.cjs')) | ||
return false; | ||
const { readPackageScope } = require('internal/modules/cjs/loader'); | ||
const pkg = readPackageScope(filePath); | ||
return pkg?.data?.type === 'module'; | ||
} | ||
|
||
/** | ||
* @param {string} filePath | ||
* @returns {any} | ||
* requireOrImport imports a module if the file is an ES module, otherwise it requires it. | ||
*/ | ||
function requireOrImport(filePath) { | ||
const useESMLoader = shouldUseESMLoader(filePath); | ||
if (useESMLoader) { | ||
const { esmLoader } = require('internal/process/esm_loader'); | ||
const { pathToFileURL } = require('internal/url'); | ||
const { isAbsolute } = require('path'); | ||
const file = isAbsolute(filePath) ? pathToFileURL(filePath).href : filePath; | ||
return esmLoader.import(file, undefined, ObjectCreate(null)); | ||
} | ||
const { Module } = require('internal/modules/cjs/loader'); | ||
|
||
return new Module._load(filePath, null, false); | ||
} | ||
|
||
module.exports = { | ||
shouldUseESMLoader, | ||
requireOrImport, | ||
}; | ||
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