|
1 |
| -import { clearRequireCache } from '@nx/devkit/src/utils/config-utils'; |
2 |
| -import { registerTsProject } from '@nx/js/src/internal'; |
| 1 | +import { loadConfigFile } from '@nx/devkit/src/utils/config-utils'; |
3 | 2 |
|
4 |
| -export function resolveUserDefinedRspackConfig( |
| 3 | +export async function resolveUserDefinedRspackConfig( |
5 | 4 | path: string,
|
6 | 5 | tsConfig: string,
|
7 | 6 | /** Skip require cache and return latest content */
|
8 | 7 | reload = false
|
9 | 8 | ) {
|
10 |
| - if (reload) { |
11 |
| - // Clear cache if the path is in the cache |
12 |
| - if (require.cache[path]) { |
13 |
| - // Clear all entries because config may import other modules |
14 |
| - clearRequireCache(); |
15 |
| - } |
16 |
| - } |
17 |
| - |
18 |
| - // Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths. |
19 |
| - // There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors. |
20 |
| - if (!/\.(ts|mts|cts)$/.test(path)) { |
21 |
| - return require(path); |
22 |
| - } |
23 |
| - |
24 |
| - const cleanupTranspiler = registerTsProject(tsConfig); |
25 |
| - // eslint-disable-next-line @typescript-eslint/no-var-requires |
26 |
| - const maybeCustomRspackConfig = require(path); |
27 |
| - cleanupTranspiler(); |
28 |
| - |
29 |
| - // If the user provides a configuration in TS file |
30 |
| - // then there are 3 cases for exploring an object. The first one is: |
31 |
| - // `module.exports = { ... }`. And the second one is: |
32 |
| - // `export default { ... }`. The ESM format is compiled into: |
33 |
| - // `{ default: { ... } }` |
34 |
| - // There is also a case of |
35 |
| - // `{ default: { default: { ... } }` |
36 |
| - const customRspackConfig = |
37 |
| - 'default' in maybeCustomRspackConfig |
38 |
| - ? 'default' in maybeCustomRspackConfig.default |
39 |
| - ? maybeCustomRspackConfig.default.default |
40 |
| - : maybeCustomRspackConfig.default |
41 |
| - : maybeCustomRspackConfig; |
42 |
| - |
43 |
| - return customRspackConfig; |
| 9 | + return await loadConfigFile(path); |
44 | 10 | }
|
0 commit comments