-
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.
feat(rspack): move logic for withNx to applyBaseConfig and bring in l…
…ine with webpack (#28825) <!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> `withNx` from `@nx/rspack` is not reflective of what `@nx/webpack` does. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Bring `withNx` in line with `@nx/webpack` ## Notes
- Loading branch information
Showing
27 changed files
with
1,226 additions
and
306 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
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
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
56 changes: 56 additions & 0 deletions
56
packages/rspack/src/executors/rspack/lib/normalize-options.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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { resolve } from 'path'; | ||
|
||
import { | ||
normalizeAssets, | ||
normalizeFileReplacements, | ||
} from '../../../plugins/utils/plugins/normalize-options'; | ||
import type { | ||
RspackExecutorSchema, | ||
NormalizedRspackExecutorSchema, | ||
} from '../schema'; | ||
|
||
export function normalizeOptions( | ||
options: RspackExecutorSchema, | ||
root: string, | ||
projectRoot: string, | ||
sourceRoot: string | ||
): NormalizedRspackExecutorSchema { | ||
const normalizedOptions = { | ||
...options, | ||
root, | ||
projectRoot, | ||
sourceRoot, | ||
target: options.target ?? 'web', | ||
outputFileName: options.outputFileName ?? 'main.js', | ||
rspackConfig: normalizePluginPath(options.rspackConfig, root), | ||
fileReplacements: normalizeFileReplacements(root, options.fileReplacements), | ||
optimization: | ||
typeof options.optimization !== 'object' | ||
? { | ||
scripts: options.optimization, | ||
styles: options.optimization, | ||
} | ||
: options.optimization, | ||
}; | ||
if (options.assets) { | ||
normalizedOptions.assets = normalizeAssets( | ||
options.assets, | ||
root, | ||
sourceRoot, | ||
projectRoot, | ||
false // executor assets are relative to workspace root for consistency | ||
); | ||
} | ||
return normalizedOptions as NormalizedRspackExecutorSchema; | ||
} | ||
|
||
export function normalizePluginPath(pluginPath: void | string, root: string) { | ||
if (!pluginPath) { | ||
return ''; | ||
} | ||
try { | ||
return require.resolve(pluginPath); | ||
} catch { | ||
return resolve(root, pluginPath); | ||
} | ||
} |
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
Oops, something went wrong.