Skip to content

Commit

Permalink
fix(plugin-less): lessLoaderOptions.lessOptions.plugins has lose it's…
Browse files Browse the repository at this point in the history
… prototype.
  • Loading branch information
Sang-Sang33 committed Oct 25, 2024
1 parent 2f9d1a4 commit 7be4917
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export {
} from './config';
export type { InternalContext } from './types';
export { setHTMLPlugin, getHTMLPlugin } from './pluginHelper';
export { formatStats, getStatsOptions, prettyTime } from './helpers';
export {
formatStats,
getStatsOptions,
prettyTime,
isPlainObject,
} from './helpers';
export { registerBuildHook, registerDevHook, onCompileDone } from './hooks';
export { getChainUtils, getConfigUtils } from './provider/rspackConfig';
export { chainToConfig, modifyBundlerChain } from './configChain';
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-less/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
RsbuildPlugin,
Rspack,
} from '@rsbuild/core';
import { __internalHelper } from '@rsbuild/core';
import deepmerge from 'deepmerge';
import { reduceConfigsWithContext } from 'reduce-configs';

Expand Down Expand Up @@ -75,7 +76,9 @@ const getLessLoaderOptions = (
): LessLoaderOptions => {
const getLessOptions = () => {
if (defaults.lessOptions && userOptions.lessOptions) {
return deepmerge(defaults.lessOptions, userOptions.lessOptions);
return deepmerge(defaults.lessOptions, userOptions.lessOptions, {
isMergeableObject: __internalHelper.isPlainObject,
});
}
return userOptions.lessOptions || defaults.lessOptions;
};
Expand Down
26 changes: 26 additions & 0 deletions packages/plugin-less/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,30 @@ describe('plugin-less', () => {
const bundlerConfigs = await rsbuild.initConfigs();
expect(matchRules(bundlerConfigs[0], 'a.less')).toMatchSnapshot();
});

it('should add less-loader with plugins', async () => {
class MockPlugin {
options?: any;
constructor(options?: any) {
this.options = options;
}
install(less: any, pluginManager: any) {}
}
const mockPlugin = new MockPlugin();
const rsbuild = await createRsbuild({
rsbuildConfig: {
plugins: [
pluginLess({
lessLoaderOptions: {
lessOptions: {
plugins: [mockPlugin],
},
},
}),
],
},
});
const bundlerConfigs = await rsbuild.initConfigs();
expect(matchRules(bundlerConfigs[0], 'a.less')).toMatchSnapshot();

Check failure on line 90 in packages/plugin-less/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ut (macos-14)

packages/plugin-less/tests/index.test.ts > plugin-less > should add less-loader with plugins

Error: Snapshot `plugin-less > should add less-loader with plugins 1` mismatched ❯ packages/plugin-less/tests/index.test.ts:90:53

Check failure on line 90 in packages/plugin-less/tests/index.test.ts

View workflow job for this annotation

GitHub Actions / ut (windows-latest)

packages/plugin-less/tests/index.test.ts > plugin-less > should add less-loader with plugins

Error: Snapshot `plugin-less > should add less-loader with plugins 1` mismatched ❯ packages/plugin-less/tests/index.test.ts:90:53
});
});

0 comments on commit 7be4917

Please sign in to comment.