Skip to content

Commit

Permalink
rename importModule to requireOrImportModule
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiAnAn committed Mar 15, 2021
1 parent f6cf308 commit b464cff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/jest-transform/src/ScriptTransformer.ts
Expand Up @@ -20,9 +20,9 @@ import type {Config} from '@jest/types';
import HasteMap from 'jest-haste-map';
import {
createDirectory,
importModule,
interopRequireDefault,
isPromise,
requireOrImportModule,
tryRealpath,
} from 'jest-util';
import handlePotentialSyntaxError from './enhanceUnexpectedTokenMessage';
Expand Down Expand Up @@ -252,7 +252,9 @@ class ScriptTransformer {
await Promise.all(
this._config.transform.map(
async ([, transformPath, transformerConfig]) => {
let transformer: Transformer = await importModule(transformPath);
let transformer: Transformer = await requireOrImportModule(
transformPath,
);

if (!transformer) {
throw new TypeError('Jest: a transform must export something.');
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-util/src/index.ts
Expand Up @@ -23,4 +23,4 @@ export * as preRunMessage from './preRunMessage';
export {default as pluralize} from './pluralize';
export {default as formatTime} from './formatTime';
export {default as tryRealpath} from './tryRealpath';
export {default as importModule} from './importModule';
export {default as requireOrImportModule} from './requireOrImportModule';
@@ -1,7 +1,9 @@
import {pathToFileURL} from 'url';
import interopRequireDefault from './interopRequireDefault';

export default async function importModule<T>(filePath: string): Promise<T> {
export default async function requireOrImportModule<T>(
filePath: string,
): Promise<T> {
let module: T;
try {
module = interopRequireDefault(require(filePath)).default;
Expand Down

0 comments on commit b464cff

Please sign in to comment.