Skip to content

Commit

Permalink
feat!: enable Rspack config schema validation by default (#3295)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Aug 27, 2024
1 parent 5e84bdc commit bf0f684
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 13 deletions.
59 changes: 54 additions & 5 deletions e2e/cases/rspack-config-validate/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,67 @@
import { build, rspackOnlyTest } from '@e2e/helper';
import { build, proxyConsole, rspackOnlyTest } from '@e2e/helper';
import { expect } from '@playwright/test';

rspackOnlyTest('should allow to override rspack config validate', async () => {
const { RSPACK_CONFIG_VALIDATE } = process.env;
process.env.RSPACK_CONFIG_VALIDATE = 'strict';

rspackOnlyTest('should validate rspack config by default', async () => {
try {
await build({
cwd: __dirname,
rsbuildConfig: {
tools: {
// @ts-expect-error mock invalid config
rspack: {
entry: 1,
},
},
},
});
} catch (e) {
expect(e).toBeTruthy();
expect((e as Error).message).toContain('Expected object, received number');
}
});

rspackOnlyTest('should warn when passing unrecognized keys', async () => {
const { logs, restore } = proxyConsole();
await build({
cwd: __dirname,
rsbuildConfig: {
tools: {
rspack: {
// @ts-expect-error mock invalid config
unrecognized: 1,
},
},
},
});

expect(
logs.some((log) =>
log.includes(`Unrecognized key(s) in object: 'unrecognized'`),
),
);
restore();
});

rspackOnlyTest('should allow to override rspack config validate', async () => {
const { RSPACK_CONFIG_VALIDATE } = process.env;
process.env.RSPACK_CONFIG_VALIDATE = 'loose';

const { logs, restore } = proxyConsole();

await build({
cwd: __dirname,
rsbuildConfig: {
tools: {
// @ts-expect-error mock invalid config
rspack: {
entry: 1,
},
},
},
});

expect(logs.some((log) => log.includes('Expected object, received number')));

process.env.RSPACK_CONFIG_VALIDATE = RSPACK_CONFIG_VALIDATE;
restore();
});
7 changes: 0 additions & 7 deletions e2e/cases/rspack-config-validate/rsbuild.config.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/core/src/plugins/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export const pluginBasic = (): RsbuildPlugin => ({
);
}

process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-silent';
// enable Rspack config schema validation, unrecognized keys are allowed
process.env.RSPACK_CONFIG_VALIDATE ||= 'loose-unrecognized-keys';

// improve kill process performance
// https://github.com/web-infra-dev/rspack/pull/5486
Expand Down
1 change: 1 addition & 0 deletions scripts/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ subpage
subresource
subresources
svgr
sveltejs
swcrc
systemjs
tailwindcss
Expand Down

0 comments on commit bf0f684

Please sign in to comment.