UNPKG

825 BPlain TextView Raw
1// importing the factory directly, as we feed it our own fs, and don't want graceful-fs to be implicitly imported
2// this allows @stylable/core to be bundled for browser usage without special custom configuration
3const ResolverFactory = require('enhanced-resolve/lib/ResolverFactory') as typeof import('enhanced-resolve').ResolverFactory;
4
5import { ModuleResolver } from './types';
6import { MinimalFS } from './cached-process-file';
7
8const resolverContext = {};
9
10export function createDefaultResolver(fileSystem: MinimalFS, resolveOptions: any): ModuleResolver {
11 const eResolver = ResolverFactory.createResolver({
12 useSyncFileSystemCalls: true,
13 fileSystem,
14 ...resolveOptions,
15 });
16
17 return (directoryPath, request) =>
18 eResolver.resolveSync(resolverContext, directoryPath, request);
19}