Skip to content

Commit

Permalink
chore: resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
nyqykk committed Dec 4, 2024
2 parents 4346e15 + f04210d commit 096924c
Show file tree
Hide file tree
Showing 35 changed files with 683 additions and 657 deletions.
7 changes: 6 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
"socket.io-client",
"react-router-dom",
"tsx",
"@types/estree"
"@types/estree",
"playwright",
"@babel/code-frame",
"get-port",
"chalk",
"deep-eql"
]
}
1 change: 0 additions & 1 deletion .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh
HUSKY_SCRIPT="$(dirname "$0")/_/husky.sh"

if [ -f "$HUSKY_SCRIPT" ]; then
. "$HUSKY_SCRIPT"
Expand Down
1 change: 0 additions & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install nano-staged
56 changes: 56 additions & 0 deletions e2e/cases/doctor-webpack/plugins/multi-plugin-brief.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { expect, test } from '@playwright/test';
import { getSDK } from '@rsdoctor/core/plugins';
import { compileByWebpack5 } from '@scripts/test-helper';
import path from 'path';
import { Compiler } from 'webpack';
import { createRsdoctorMultiPlugin } from '../test-utils';

async function webpack(tapName: string, compile: typeof compileByWebpack5) {
const file = path.resolve(__dirname, '../fixtures/a.js');
const loader = path.resolve(__dirname, '../fixtures/loaders/comment.js');
const res = await compile(file, {
module: {
rules: [
{
test: /\.js/,
use: loader,
},
],
},
plugins: [
createRsdoctorMultiPlugin({
mode: 'brief',
brief: {
reportHtmlName: '111.html',
writeDataJson: false,
},
}),
{
name: tapName,
apply(compiler: Compiler) {
compiler.hooks.done.tapPromise(tapName, async () => {
// nothing
});
compiler.hooks.thisCompilation.tap(tapName, (compilation) => {
compilation.hooks.seal.tap(tapName, () => {
return 'seal end';
});
});
},
},
],
});
return res;
}

test('rsdoctor webpack5 multi-plugins options tests', async () => {
const tapName = 'Foo';
await webpack(tapName, compileByWebpack5);
const sdk = getSDK();
expect(sdk.type).toBe(0);
expect(sdk.extraConfig?.mode).toBe('brief');
expect(sdk.extraConfig?.brief).toMatchObject({
reportHtmlName: '111.html',
writeDataJson: false,
});
});
36 changes: 35 additions & 1 deletion e2e/cases/doctor-webpack/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { RsdoctorWebpackPluginOptions } from '@rsdoctor/core/types';
import { RsdoctorWebpackPlugin } from '@rsdoctor/webpack-plugin';
import {
RsdoctorWebpackPlugin,
RsdoctorWebpackMultiplePlugin,
} from '@rsdoctor/webpack-plugin';
import { Linter } from '@rsdoctor/types';
import { File } from '@rsdoctor/utils/build';
import { tmpdir } from 'os';
Expand Down Expand Up @@ -35,3 +38,34 @@ export function createRsdoctorPlugin<T extends Linter.ExtendRuleData[]>(

return plugin;
}

export function createRsdoctorMultiPlugin<T extends Linter.ExtendRuleData[]>(
options: RsdoctorWebpackPluginOptions<T> = {},
) {
const plugin = new RsdoctorWebpackMultiplePlugin({
...options,
disableClientServer:
typeof options.disableClientServer === 'boolean'
? options.disableClientServer
: true,
});

const outdir = path.resolve(
tmpdir(),
`./${Date.now()}/web_doctor_webpack_plugin_test`,
);

plugin.sdk.hooks.afterSaveManifest.tapPromise(
{ name: 'REMOVE_TMP_DIR', stage: -9999 },
async () => {
plugin.sdk.setOutputDir(outdir);
try {
await File.fse.remove(plugin.sdk.outputDir);
} catch (e) {
console.error(e);
}
},
);

return plugin;
}
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"@rsdoctor/webpack-plugin": "workspace:*",
"@rspack/core": "^1.1.1",
"@rspack/core": "^1.1.4",
"@types/lodash": "^4.17.13",
"@types/node": "^16",
"@types/react": "^18.3.12",
Expand Down
1 change: 1 addition & 0 deletions e2e/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { defineConfig } from '@playwright/test';

export default defineConfig({
testMatch: ['/cases/**/**.test.ts'],
timeout: 60000,
});
2 changes: 1 addition & 1 deletion examples/rspack-banner-minimal/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const config = {
new ReactRefreshPlugin(),
new RsdoctorRspackPlugin({
disableClientServer: process.env.ENABLE_CLIENT_SERVER === 'false',
features: ['bundle', 'plugins', 'loader'],
features: ['bundle', 'plugins', 'loader', 'treeShaking', 'resolver'],
}),
new rspack.BannerPlugin({
test: /\.js/,
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"dev:doc": "cd document && pnpm run dev",
"e2e": "cd ./e2e && cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm test",
"lint": "biome lint . --diagnostic-level=error",
"prepare": "pnpm run build && husky install",
"prepare": "pnpm run build && husky",
"test": "cross-env NODE_OPTIONS=--max-old-space-size=8192 pnpm run ut",
"test:all": "pnpm run test && pnpm run e2e",
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
Expand All @@ -33,14 +33,14 @@
},
"devDependencies": {
"@biomejs/biome": "1.5.1",
"@changesets/cli": "^2.27.9",
"@modern-js/module-tools": "^2.62.0",
"@changesets/cli": "^2.27.10",
"@modern-js/module-tools": "^2.63.0",
"@rsdoctor/tsconfig": "workspace:*",
"@scripts/test-helper": "workspace:*",
"check-dependency-version-consistency": "^4.1.0",
"cross-env": "^7.0.3",
"cspell-ban-words": "^0.0.4",
"husky": "^8.0.3",
"husky": "^9.1.7",
"nano-staged": "^0.8.0",
"nx": "^17.3.2",
"prettier": "^3.3.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/cli",
"version": "0.4.8",
"version": "0.4.11",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down Expand Up @@ -32,10 +32,10 @@
"@rsdoctor/sdk": "workspace:*",
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"axios": "^1.7.7",
"axios": "^1.7.8",
"ora": "^5.4.1",
"picocolors": "^1.1.1",
"tslib": "2.7.0",
"tslib": "2.8.1",
"yargs": "17.7.2"
},
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/client",
"version": "0.4.8",
"version": "0.4.11",
"main": "dist/index.html",
"repository": {
"type": "git",
Expand Down Expand Up @@ -28,11 +28,11 @@
"dist/"
],
"devDependencies": {
"@rsbuild/core": "^1.1.3",
"@rsbuild/core": "^1.1.7",
"@rsbuild/plugin-node-polyfill": "^1.2.0",
"@rsbuild/plugin-react": "^1.0.7",
"@rsbuild/plugin-sass": "^1.1.1",
"@rsbuild/plugin-type-check": "^1.0.1",
"@rsbuild/plugin-type-check": "^1.1.0",
"@rsdoctor/components": "workspace:*",
"@rsdoctor/types": "workspace:*",
"@types/node": "^16",
Expand Down
6 changes: 3 additions & 3 deletions packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/components",
"version": "0.4.8",
"version": "0.4.11",
"main": "./dist/index.js",
"license": "MIT",
"module": "dist/index.js",
Expand Down Expand Up @@ -50,8 +50,8 @@
"dist/"
],
"devDependencies": {
"@ant-design/icons": "5.5.2",
"@rsbuild/plugin-check-syntax": "1.2.0-beta.1",
"@ant-design/icons": "5.5.1",
"@monaco-editor/react": "4.6.0",
"@rsdoctor/graph": "workspace:*",
"@rsdoctor/types": "workspace:*",
Expand All @@ -64,7 +64,7 @@
"@types/url-parse": "1.4.11",
"ansi-to-react": "6.1.6",
"antd": "5.15.3",
"axios": "^1.7.7",
"axios": "^1.7.8",
"dayjs": "1.11.13",
"echarts": "^5.5.1",
"echarts-for-react": "^3.0.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/core",
"version": "0.4.8",
"version": "0.4.11",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down Expand Up @@ -72,7 +72,7 @@
"@rsdoctor/sdk": "workspace:*",
"@rsdoctor/types": "workspace:*",
"@rsdoctor/utils": "workspace:*",
"axios": "^1.7.7",
"axios": "^1.7.8",
"enhanced-resolve": "5.12.0",
"filesize": "^10.1.6",
"fs-extra": "^11.1.1",
Expand All @@ -85,7 +85,7 @@
"browserslist-load-config": "^1.0.0"
},
"devDependencies": {
"@rspack/core": "^1.1.1",
"@rspack/core": "^1.1.4",
"@scripts/test-helper": "workspace:*",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.13",
Expand All @@ -97,7 +97,7 @@
"babel-loader": "9.1.3",
"string-loader": "0.0.1",
"ts-loader": "^9.5.1",
"tslib": "2.7.0",
"tslib": "2.8.1",
"typescript": "^5.2.2",
"webpack": "^5.95.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/build-utils/common/webpack/compatible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export function isExternalModule(mod: Module): mod is ExternalModule {
export function getModuleSource(mod: NormalModule): string {
return isExternalModule(mod)
? ''
: mod.originalSource?.()?.source().toString() ?? '';
: (mod.originalSource?.()?.source().toString() ?? '');
}

export function getResolveModule(dep: Dependency, graph?: ModuleGraph) {
// webpack5
if (graph) {
if (graph && 'getResolvedModule' in graph) {
return graph.getResolvedModule(dep);
}

Expand Down
14 changes: 11 additions & 3 deletions packages/core/src/inner-plugins/plugins/ensureModulesChunkGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RsdoctorPluginInstance } from '@/types';
import { ModuleGraph } from '@rsdoctor/graph';
import { Linter, Plugin, Constants, Manifest } from '@rsdoctor/types';
import { Process } from '@rsdoctor/utils/build';
import { debug } from '@rsdoctor/utils/logger';
import { chalk, debug, logger } from '@rsdoctor/utils/logger';
import fse from 'fs-extra';
import {
Chunks as ChunksBuildUtils,
Expand Down Expand Up @@ -37,8 +37,7 @@ export const ensureModulesChunksGraphFn = (
internalPluginTapPreOptions('moduleGraph'),
async (_stats: any) => {
const stats = _stats as Plugin.Stats;
const statsJson = stats.toJson();

const statsJson = stats.toJson(); // TODO: need optimize this stats.toJSON 's stats options.
debug(Process.getMemoryUsageMessage, '[Before Generate ModuleGraph]');

_this.chunkGraph = ChunksBuildUtils.chunkTransform(new Map(), statsJson);
Expand All @@ -57,6 +56,15 @@ export const ensureModulesChunksGraphFn = (

/** Tree Shaking */
if (_this.options.features.treeShaking) {
if ('rspackVersion' in compiler.webpack) {
logger.info(
chalk.yellow(
'Rspack currently does not support treeShaking capabilities.',
),
);
return;
}

_this.modulesGraph =
ModuleGraphBuildUtils.appendTreeShaking(
_this.modulesGraph,
Expand Down
6 changes: 3 additions & 3 deletions packages/document/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/docs",
"version": "0.4.8",
"version": "0.4.11",
"scripts": {
"dev": "rspress dev",
"build": "rspress build",
Expand All @@ -25,7 +25,7 @@
},
"devDependencies": {
"@rsdoctor/types": "workspace:*",
"@rspress/plugin-rss": "^1.36.0",
"@rspress/plugin-rss": "^1.37.3",
"@types/node": "^16",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
Expand All @@ -40,6 +40,6 @@
"dependencies": {
"@rstack-dev/doc-ui": "1.5.4",
"react-markdown": "^9.0.1",
"rspress": "^1.36.0"
"rspress": "^1.37.3"
}
}
4 changes: 2 additions & 2 deletions packages/graph/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/graph",
"version": "0.4.8",
"version": "0.4.11",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@types/lodash": "^4.17.13",
"@types/node": "^16",
"fs-extra": "^11.1.1",
"tslib": "2.7.0",
"tslib": "2.8.1",
"typescript": "^5.2.2"
},
"publishConfig": {
Expand Down
6 changes: 3 additions & 3 deletions packages/rspack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsdoctor/rspack-plugin",
"version": "0.4.8",
"version": "0.4.11",
"repository": {
"type": "git",
"url": "https://github.com/web-infra-dev/rsdoctor",
Expand All @@ -27,11 +27,11 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@rspack/core": "^1.1.1",
"@rspack/core": "^1.1.4",
"@types/lodash": "^4.17.13",
"@types/node": "^16",
"@types/tapable": "2.2.7",
"tslib": "2.7.0",
"tslib": "2.8.1",
"typescript": "^5.2.2"
},
"peerDependencies": {
Expand Down
Loading

0 comments on commit 096924c

Please sign in to comment.