-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
5 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 3 additions & 37 deletions
40
packages/rspack/src/utils/resolve-user-defined-rspack-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,10 @@ | ||
import { clearRequireCache } from '@nx/devkit/src/utils/config-utils'; | ||
import { registerTsProject } from '@nx/js/src/internal'; | ||
import { loadConfigFile } from '@nx/devkit/src/utils/config-utils'; | ||
|
||
export function resolveUserDefinedRspackConfig( | ||
export async function resolveUserDefinedRspackConfig( | ||
path: string, | ||
tsConfig: string, | ||
/** Skip require cache and return latest content */ | ||
reload = false | ||
) { | ||
if (reload) { | ||
// Clear cache if the path is in the cache | ||
if (require.cache[path]) { | ||
// Clear all entries because config may import other modules | ||
clearRequireCache(); | ||
} | ||
} | ||
|
||
// Don't transpile non-TS files. This prevents workspaces libs from being registered via tsconfig-paths. | ||
// There's an issue here with Nx workspace where loading plugins from source (via tsconfig-paths) can lead to errors. | ||
if (!/\.(ts|mts|cts)$/.test(path)) { | ||
return import(path); | ||
} | ||
|
||
const cleanupTranspiler = registerTsProject(tsConfig); | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const maybeCustomRspackConfig = require(path); | ||
cleanupTranspiler(); | ||
|
||
// If the user provides a configuration in TS file | ||
// then there are 3 cases for exploring an object. The first one is: | ||
// `module.exports = { ... }`. And the second one is: | ||
// `export default { ... }`. The ESM format is compiled into: | ||
// `{ default: { ... } }` | ||
// There is also a case of | ||
// `{ default: { default: { ... } }` | ||
const customRspackConfig = | ||
'default' in maybeCustomRspackConfig | ||
? 'default' in maybeCustomRspackConfig.default | ||
? maybeCustomRspackConfig.default.default | ||
: maybeCustomRspackConfig.default | ||
: maybeCustomRspackConfig; | ||
|
||
return customRspackConfig; | ||
return await loadConfigFile(path); | ||
} |