|
1 | 1 | import path from 'node:path'; |
2 | | -import { createOptionsResolver, type FmtOptionsResolver } from './config.ts'; |
3 | 2 | import { discoverFmtPaths } from './discoverPaths.ts'; |
| 3 | +import { createFmtFileResolver } from './fileResolver.ts'; |
4 | 4 | import { createIgnoreMatcher } from './ignore.ts'; |
5 | | -import type { FmtPluginResolver } from './plugins.ts'; |
6 | 5 | import type { DiscoverFmtFilesOptions, FmtFileRequest } from './types.ts'; |
7 | 6 |
|
8 | | -const createFileRequest = ( |
9 | | - filePath: string, |
10 | | - resolveOptions: FmtOptionsResolver, |
11 | | -): FmtFileRequest => ({ |
12 | | - path: filePath, |
13 | | - options: resolveOptions(filePath), |
14 | | -}); |
15 | | - |
16 | | -/** Imports the plugin chunk on first use and shares the resolver across calls. */ |
17 | | -const createLazyPluginResolver = (rootPath: string): (() => Promise<FmtPluginResolver>) => { |
18 | | - let resolver: Promise<FmtPluginResolver> | undefined; |
19 | | - |
20 | | - return () => |
21 | | - (resolver ??= import( |
22 | | - /* rspackChunkName: 'fmtPlugins' */ |
23 | | - './plugins.ts' |
24 | | - ).then(({ createPluginResolver }) => createPluginResolver(rootPath))); |
25 | | -}; |
26 | | - |
27 | | -/** Resolves the plugin specifiers of a request whose options configure plugins. */ |
28 | | -const resolveFileRequestPlugins = async ( |
29 | | - file: FmtFileRequest, |
30 | | - getPluginResolver: () => Promise<FmtPluginResolver>, |
31 | | -): Promise<FmtFileRequest> => |
32 | | - file.options.plugins?.length |
33 | | - ? { ...file, options: (await getPluginResolver())(file.options) } |
34 | | - : file; |
35 | | - |
36 | 7 | const createDirMatcher = (dirPath: string): ((filePath: string) => boolean) => { |
37 | 8 | const prefix = dirPath.endsWith(path.sep) ? dirPath : `${dirPath}${path.sep}`; |
38 | 9 | return (filePath) => filePath === dirPath || filePath.startsWith(prefix); |
@@ -63,14 +34,9 @@ const discoverFmtFiles = async ({ |
63 | 34 | return []; |
64 | 35 | } |
65 | 36 |
|
66 | | - const resolveOptions = createOptionsResolver(config); |
67 | | - const getPluginResolver = createLazyPluginResolver(config.rootPath); |
| 37 | + const resolveFile = createFmtFileResolver(config); |
68 | 38 |
|
69 | | - return Promise.all( |
70 | | - filePaths.map((filePath) => |
71 | | - resolveFileRequestPlugins(createFileRequest(filePath, resolveOptions), getPluginResolver), |
72 | | - ), |
73 | | - ); |
| 39 | + return Promise.all(filePaths.map((filePath) => resolveFile(filePath))); |
74 | 40 | }; |
75 | 41 |
|
76 | | -export { createFileRequest, createLazyPluginResolver, discoverFmtFiles, resolveFileRequestPlugins }; |
| 42 | +export { discoverFmtFiles }; |
0 commit comments