Skip to content

Commit

Permalink
deduplicate interopRequireDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Jul 6, 2022
1 parent 4390cea commit 7124023
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
11 changes: 1 addition & 10 deletions lib/core-common/src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from './types';
import { loadCustomPresets } from './utils/load-custom-presets';
import { safeResolve, safeResolveFrom } from './utils/safeResolve';
import { interopRequireDefault } from './utils/interpret-require';

const isObject = (val: unknown): val is Record<string, any> =>
val != null && typeof val === 'object' && Array.isArray(val) === false;
Expand Down Expand Up @@ -153,16 +154,6 @@ const map =
return undefined;
};

function interopRequireDefault(filePath: string) {
// eslint-disable-next-line global-require,import/no-dynamic-require
const result = require(filePath);

const isES6DefaultExported =
typeof result === 'object' && result !== null && typeof result.default !== 'undefined';

return isES6DefaultExported ? result.default : result;
}

function getContent(input: any) {
if (input.type === 'virtual') {
const { type, name, ...rest } = input;
Expand Down
2 changes: 1 addition & 1 deletion lib/core-common/src/utils/interpret-require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function registerCompiler(moduleDescriptor: Extension): number {
return registered;
}

function interopRequireDefault(filePath: string) {
export function interopRequireDefault(filePath: string) {
// eslint-disable-next-line import/no-dynamic-require,global-require
const result = require(filePath);

Expand Down

0 comments on commit 7124023

Please sign in to comment.