Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
fix(one-app-bundler): hash css module classes from files in node_modu…
Browse files Browse the repository at this point in the history
…les (#613)

Co-authored-by: Matthew Mallimo <[email protected]>
  • Loading branch information
zacowan and Matthew-Mallimo authored Mar 7, 2024
1 parent 42c2858 commit 4c24846
Show file tree
Hide file tree
Showing 7 changed files with 444 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,9 @@ describe('styles-loader', () => {
getOptions: mockGetOptions,
});
});
it('should call the loadStyles util with the correct params, for non-node_modules', () => {
it('should call the loadStyles util from the dev bundler with the correct params', () => {
expect(stylesLoader()).toBe('let mockJsContent = "helloMockContent"');
expect(loadStyles).toHaveBeenCalledTimes(1);
expect(loadStyles).toHaveBeenCalledWith({ bundleType: BUNDLE_TYPES.BROWSER, cssModulesOptions: { generateScopedName: undefined }, path: 'style/path/mock.scss' });
});
it('should call the loadStyles util with the correct params, for node_modules', () => {
stylesLoader = unboundStylesLoader.bind({
resourcePath: 'node_modules/style/path/mock.scss',
getOptions: mockGetOptions,
});

expect(stylesLoader()).toBe('let mockJsContent = "helloMockContent"');

expect(loadStyles).toHaveBeenCalledTimes(1);
expect(loadStyles).toHaveBeenCalledWith({ bundleType: BUNDLE_TYPES.BROWSER, cssModulesOptions: { generateScopedName: '[local]' }, path: 'node_modules/style/path/mock.scss' });
});
});
6 changes: 2 additions & 4 deletions packages/one-app-bundler/webpack/loaders/styles-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
import { loadStyles } from '@americanexpress/one-app-dev-bundler';

function stylesLoader() {
const options = { ...this.getOptions() };
// use default for directly imported, dont scope for node_module
options.cssModulesOptions.generateScopedName = this.resourcePath.includes('node_modules') ? '[local]' : undefined;
return loadStyles({ path: this.resourcePath, ...options });
// Use the same implementation as the dev bundler for consistency
return loadStyles({ path: this.resourcePath, ...this.getOptions() });
}

export default stylesLoader;
Loading

0 comments on commit 4c24846

Please sign in to comment.