Skip to content

Commit

Permalink
fix: some @types/webpack types error (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 authored Sep 9, 2024
1 parent 8d667db commit 7f93640
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 233 deletions.
2 changes: 1 addition & 1 deletion e2e/cases/doctor-webpack/plugins/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ test('webpack5 plugins tests', async () => {
expect(assets[0].content.length).toBeGreaterThan(10);
os.EOL === '\n' &&
expect(assets[0].content).toStrictEqual(
"/******/ (() => { // webpackBootstrap\nvar __webpack_exports__ = {};\nconsole.log('a');\n\n// hello world\n/******/ })()\n;",
"/******/ (() => { // webpackBootstrap\nconsole.log('a');\n\n// hello world\n/******/ })()\n;",
);

expect(chunks.length).toBe(1);
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"vue": "^3.4.38"
},
"devDependencies": {
"webpack": "^5.90.0",
"@playwright/test": "1.33.0",
"@rsdoctor/core": "workspace:*",
"@rsdoctor/rspack-plugin": "workspace:*",
Expand All @@ -27,7 +28,6 @@
"@types/node": "^16",
"@types/react": "^18.3.5",
"@types/react-dom": "^18",
"@types/webpack": "5.28.5",
"fast-glob": "^3.3.2",
"loader-utils": "^2.0.4",
"playwright": "1.33.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/multiple-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"tslib": "2.4.1",
"tsm": "2.3.0",
"typescript": "^5.2.2",
"webpack": "5.89.0"
"webpack": "^5.90.0"
}
}
2 changes: 1 addition & 1 deletion examples/webpack-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"tslib": "2.4.1",
"tsm": "2.3.0",
"typescript": "^5.2.2",
"webpack": "5.89.0",
"webpack": "^5.90.0",
"webpack-cli": "5.0.0"
}
}
1 change: 0 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@types/react": "^18.3.5",
"@types/react-dom": "^18",
"@types/serve-static": "1.15.7",
"@types/webpack": "5.28.5",
"antd": "5.15.3",
"normalize.css": "8.0.1",
"react": "18.2.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,13 @@
"@types/path-browserify": "1.0.3",
"@types/semver": "^7.5.8",
"@types/tapable": "2.2.7",
"@types/webpack": "5.28.5",
"@types/webpack-sources": "^3.2.3",
"babel-loader": "9.1.3",
"string-loader": "0.0.1",
"ts-loader": "^9.5.1",
"tslib": "2.4.1",
"typescript": "^5.2.2",
"webpack": "^5.89.0"
"webpack": "^5.90.0"
},
"publishConfig": {
"access": "public",
Expand Down
23 changes: 9 additions & 14 deletions packages/core/src/inner-plugins/plugins/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

import { Manifest, Plugin } from '@rsdoctor/types';
import { InternalBasePlugin } from './base';
import { Chunks } from '@/build-utils/common';


export class InternalBundlePlugin<
T extends Plugin.BaseCompiler,
> extends InternalBasePlugin<T> {
Expand Down Expand Up @@ -34,7 +32,7 @@ export class InternalBundlePlugin<
) {
compilation.hooks.afterOptimizeAssets.tap(
this.tapPostOptions,
(assets) => {
(assets: any) => {
Object.keys(assets).forEach((file) => {
const v = this.ensureAssetContent(file);
v.content = assets[file].source().toString();
Expand All @@ -44,18 +42,15 @@ export class InternalBundlePlugin<
} else if (
compilation.hooks.processAssets &&
'afterProcessAssets' in compilation.hooks
) {
) {
// This is for rspack hooks.
compilation.hooks.afterProcessAssets.tap(
this.tapPostOptions,
() => {
Object.keys(compilation.assets).forEach((file) => {
const v = this.ensureAssetContent(file);
v.content = compilation.assets[file].source().toString();
});
},
);
} else if ('afterOptimizeChunkAssets' in compilation.hooks) {
compilation.hooks.afterProcessAssets.tap(this.tapPostOptions, () => {
Object.keys(compilation.assets).forEach((file) => {
const v = this.ensureAssetContent(file);
v.content = compilation.assets[file].source().toString();
});
});
} else if ('afterOptimizeChunkAssets' in compilation.hooks) {
compilation.hooks.afterOptimizeChunkAssets.tap(
this.tapPostOptions,
(chunks) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"source-map": "^0.7.4"
},
"devDependencies": {
"@types/webpack": "5.28.5",
"@types/node": "^16",
"@types/react": "^18.3.5",
"tslib": "2.4.1",
"typescript": "^5.2.2",
"@rspack/core": "0.7.5"
},
"peerDependencies": {
"@rspack/core": "*"
"@rspack/core": "*",
"webpack": "5.x"
},
"peerDependenciesMeta": {
"@rspack/core": {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/sdk/server/apis/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ServerResponse } from 'http';
import { SDK } from 'src';
import { PlainObject, Get } from '../../../common';
import { connect } from '../../../thirdparty';
import { RsdoctorBuilderSDKInstance } from '../../index';
Expand All @@ -12,6 +11,7 @@ import { PluginAPIResponse, PluginAPIResquestBody } from './plugin';
import { GraphAPIResponse, GraphAPIResquestBody } from './graph';
import { AlertsAPIResponse, AlertsAPIResquestBody } from './alerts';
import { RsdoctorManifestMappingKeys } from '../../../manifest';
import { SDK } from '@/index';

export * from './pagination';

Expand Down
3 changes: 1 addition & 2 deletions packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"webpack": "^5.89.0",
"webpack": "^5.90.0",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.7",
"@types/node": "^16",
"@types/tapable": "2.2.7",
"@types/webpack": "5.28.5",
"tslib": "2.4.1",
"typescript": "^5.2.2"
},
Expand Down
14 changes: 13 additions & 1 deletion packages/webpack-plugin/src/plugins/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
import { Manifest, SDK } from '@rsdoctor/types';
import { Time } from '@rsdoctor/utils/common';
import path from 'path';
import type { Compiler, ResolvePluginInstance, Resolver } from 'webpack';
import type { Compiler, Resolver } from 'webpack';

interface RsdoctorResolverPluginOptions {}

Expand All @@ -16,6 +16,18 @@ interface ResolveRequestWithContext {
context: ResolveRequestContext;
}

/**
* Plugin instance. ResolvePluginInstance in [email protected] is not the interface, it's a type.
*/
declare interface ResolvePluginInstance {
[index: string]: any;

/**
* The run point of the plugin, required method.
*/
apply: (resolver: Resolver) => void;
}

export class RsdoctorResolverPlugin implements ResolvePluginInstance {
protected tapOptions = {
name: 'RsdoctorResolverPlugin',
Expand Down
Loading

0 comments on commit 7f93640

Please sign in to comment.