Skip to content

Commit

Permalink
chore: move _importDynamic to inner scope
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobator committed Oct 7, 2024
1 parent 1a0c9d3 commit ac6cca2
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/core/src/config/config-resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ import type { Document, ResolvedRefMap } from '../resolve';

const DEFAULT_PROJECT_PLUGIN_PATHS = ['@theme/plugin.js', '@theme/plugin.cjs', '@theme/plugin.mjs'];

// Workaround for dynamic imports being transpiled to require by Typescript: https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
const _importDynamic = new Function('modulePath', 'return import(modulePath)');

// Cache instantiated plugins during a single execution
const pluginsCache: Map<string, Plugin> = new Map();

Expand Down Expand Up @@ -151,6 +148,8 @@ export async function resolvePlugins(
// @ts-ignore
requiredPlugin = __non_webpack_require__(absolutePluginPath);
} else {
// Workaround for dynamic imports being transpiled to require by Typescript: https://github.com/microsoft/TypeScript/issues/43329#issuecomment-811606238
const _importDynamic = new Function('modulePath', 'return import(modulePath)');
// you can import both cjs and mjs
const mod = await _importDynamic(pathToFileURL(absolutePluginPath).href);
requiredPlugin = mod.default || mod;
Expand Down

0 comments on commit ac6cca2

Please sign in to comment.