Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/cli",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/client",
"version": "1.5.9",
"version": "1.5.10",
"main": "dist/index.html",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/components",
"version": "1.5.9",
"version": "1.5.10",
"license": "MIT",
"types": "dist/index.d.ts",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/core",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
27 changes: 24 additions & 3 deletions packages/core/src/inner-plugins/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
RsdoctorRspackPluginOptions,
RsdoctorRspackPluginOptionsNormalized,
} from '@/types';
import { Linter, Plugin, SDK } from '@rsdoctor/types';
import { Config, Linter, Plugin, SDK } from '@rsdoctor/types';
import { chalk, logger } from '@rsdoctor/utils/logger';
import assert from 'assert';
import {
Expand Down Expand Up @@ -33,6 +33,9 @@ function getDefaultSupports() {
gzip: true, // change the gzip to true by default.
};
}
function isJsonOutputEnv(value: unknown): boolean {
return value === 'json';
}
function normalizeFeatures(features: any, mode: keyof typeof SDK.IMode) {
if (Array.isArray(features)) {
return {
Expand Down Expand Up @@ -71,20 +74,38 @@ function isValidMode(mode: any): mode is keyof typeof SDK.IMode {
export function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(
config: Plugin.RsdoctorWebpackPluginOptions<Rules> = {},
): Plugin.RsdoctorPluginOptionsNormalized<Rules> {
const userOutput = config.output;
const defaultOutput = getDefaultOutput();
const outputConfig: Config.IOutput<'brief' | 'normal'> = isJsonOutputEnv(
process.env.RSDOCTOR_OUTPUT,
)
? {
reportDir: userOutput?.reportDir,
compressData: userOutput?.compressData,
mode: 'brief' as const,
options: {
type: ['json'] as Array<'json'>,
},
}
: (userOutput ?? defaultOutput);
const normalizedConfig = {
...config,
output: outputConfig,
};
const {
linter = {},
features = {},
loaderInterceptorOptions = {},
disableClientServer: userDisableClientServer = false,
sdkInstance,
innerClientPath = '',
output = getDefaultOutput(),
output = outputConfig,
supports = getDefaultSupports(),
port,
printLog = { serverUrls: true },
mode = undefined,
brief = undefined,
} = config;
} = normalizedConfig;
// If process.env.RSTEST is set to true, disableClientServer should be false
// Otherwise, if process.env.CI is set, disableClientServer should be true
const disableClientServer =
Expand Down
30 changes: 30 additions & 0 deletions packages/core/tests/build/utils/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const originalConsoleLog = console.log;
let consoleOutput: string[] = [];
const originalEnvCI = process.env.CI;
const originalEnvRSTEST = process.env.RSTEST;
const originalEnvRSDOCTOROUTPUT = process.env.RSDOCTOR_OUTPUT;

beforeEach(() => {
consoleOutput = [];
Expand All @@ -15,6 +16,7 @@ beforeEach(() => {
};
delete process.env.CI;
delete process.env.RSTEST;
delete process.env.RSDOCTOR_OUTPUT;
});

afterEach(() => {
Expand All @@ -29,6 +31,11 @@ afterEach(() => {
} else {
delete process.env.RSTEST;
}
if (originalEnvRSDOCTOROUTPUT !== undefined) {
process.env.RSDOCTOR_OUTPUT = originalEnvRSDOCTOROUTPUT;
} else {
delete process.env.RSDOCTOR_OUTPUT;
}
});

describe('normalizeUserConfig', () => {
Expand Down Expand Up @@ -228,6 +235,29 @@ describe('normalizeUserConfig', () => {
});

describe('mode priority', () => {
it('should use brief json output when RSDOCTOR_OUTPUT is json', () => {
process.env.RSDOCTOR_OUTPUT = 'json';

const result = normalizeUserConfig();

expect(result.output.mode).toBe('brief');
expect(result.output.options).toEqual({
type: ['json'],
htmlOptions: {
reportHtmlName: undefined,
writeDataJson: false,
},
jsonOptions: {
fileName: 'rsdoctor-data.json',
sections: {
moduleGraph: true,
chunkGraph: true,
rules: true,
},
},
});
});

it('should prioritize output.mode over mode', () => {
const result = normalizeUserConfig({
mode: 'normal',
Expand Down
2 changes: 1 addition & 1 deletion packages/document/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/docs",
"version": "1.5.9",
"version": "1.5.10",
"scripts": {
"dev": "cross-env RSPRESS_PERSIST_CACHE=false rspress dev",
"build": "cross-env RSPRESS_PERSIST_CACHE=false rspress build && sh build.sh",
Expand Down
2 changes: 1 addition & 1 deletion packages/graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/graph",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/rspack-plugin",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/sdk",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/types",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/utils",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/webpack-plugin",
"version": "1.5.9",
"version": "1.5.10",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down
Loading