-
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
10 changed files
with
368 additions
and
18 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
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
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
Oops, something went wrong.