Skip to content

Commit

Permalink
fix(rspack): move main validation to implementation (#28794)
Browse files Browse the repository at this point in the history
<!-- 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 -->
We currently have validation for the `main` property in the `executor`
schema, however, this value could be defined in the `rspack.config`
file.
This can cause an inaccurate schema validation error

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
After loading the config file and applying the executor options, run
validation over the config.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
  • Loading branch information
Coly010 authored Nov 5, 2024
1 parent 75a73ed commit 7e3f256
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/generated/packages/rspack/executors/rspack.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated."
}
},
"required": ["main", "outputPath", "tsConfig", "rspackConfig"],
"required": ["outputPath", "tsConfig", "rspackConfig"],
"definitions": {
"assetPattern": {
"oneOf": [
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/executors/rspack/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Mode } from '@rspack/core';

export interface RspackExecutorSchema {
target?: 'web' | 'node';
main: string;
main?: string;
index?: string;
tsConfig: string;
typeCheck?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/executors/rspack/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"description": "Generates a `package.json` and pruned lock file with the project's `node_module` dependencies populated for installing in a container. If a `package.json` exists in the project's directory, it will be reused with dependencies populated."
}
},
"required": ["main", "outputPath", "tsConfig", "rspackConfig"],
"required": ["outputPath", "tsConfig", "rspackConfig"],
"definitions": {
"assetPattern": {
"oneOf": [
Expand Down
15 changes: 15 additions & 0 deletions packages/rspack/src/utils/create-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export async function createCompiler(
config.devServer ??= options.devServer;
}

validateConfig(config);

return rspack(config);
}

Expand All @@ -49,3 +51,16 @@ export function isMultiCompiler(
): compiler is MultiCompiler {
return 'compilers' in compiler;
}

function validateConfig(config: Configuration) {
if (!config.entry) {
throw new Error(
'Entry is required. Please set the `main` option in the executor or the `entry` property in the rspack config.'
);
}
if (!config.output) {
throw new Error(
'Output is required. Please set the `outputPath` option in the executor or the `output` property in the rspack config.'
);
}
}

0 comments on commit 7e3f256

Please sign in to comment.