Skip to content

Commit

Permalink
fix: expriments.backCompat problem (#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
easy1090 authored Feb 6, 2025
1 parent 522b2d2 commit 87f25ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
37 changes: 37 additions & 0 deletions e2e/cases/doctor-webpack/experiments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expect, test } from '@playwright/test';
import { getSDK } from '@rsdoctor/core/plugins';
import path from 'path';
import { compileByWebpack5 } from '@scripts/test-helper';
import { createRsdoctorPlugin } from './test-utils';

async function webpack(compile: typeof compileByWebpack5) {
const file = path.resolve(__dirname, './fixtures/b.js');
const loader = path.resolve(__dirname, './fixtures/loaders/comment.js');
const res = await compile(file, {
module: {
rules: [
{
test: /\.js/,
use: loader,
},
],
},
experiments: {
backCompat: false,
},
optimization: {
minimize: true,
},
plugins: [createRsdoctorPlugin({})],
});
return res;
}

test('webpack5', async () => {
await webpack(compileByWebpack5);
const sdk = getSDK();
const { configs } = sdk.getStoreData();

expect(configs[0]).toBeInstanceOf(Object);
expect(configs[0].name).toEqual('webpack');
});
3 changes: 2 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"name": "@rsdoctor/e2e",
"version": "0.0.1",
"scripts": {
"test": "playwright test"
"test": "playwright test",
"test:local": "npx playwright install chromium && playwright test"
},
"dependencies": {
"devcert": "1.2.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/build-utils/build/utils/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ export type IHook =

export function shouldInterceptPluginHook<T extends IHook>(hook: T) {
// webpack5 use fakehook for deprecated hook.
if ((hook as Common.PlainObject)._fakeHook) {
if (hook && (hook as Common.PlainObject)._fakeHook) {
return false;
}

// Hook
if (typeof hook.isUsed === 'function') {
if (hook?.isUsed && typeof hook.isUsed === 'function') {
return hook.isUsed();
}

// HookMap
if (
(hook as Common.PlainObject)._map &&
(hook as Common.PlainObject)?._map &&
((hook as Common.PlainObject)._map as Map<string, unknown>).size === 0
) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/inner-plugins/utils/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function interceptPluginHook(
name: string,
hook: IHook,
) {
if (!hook.intercept) {
if (!hook?.intercept) {
return;
}

Expand Down

0 comments on commit 87f25ac

Please sign in to comment.