Skip to content

Commit 5166a1e

Browse files
arbrandesclaude
andcommitted
fix: classify named packages by package.json name
Webpack's `descriptionData` matches against the nearest `package.json`, so paragon, shell, and brand classification now works regardless of filesystem layout (workspace symlinks, bind-mounts, renamed checkouts). The site/app split stays path-based (broadened to cover `/packages/`) since it's a project-vs-dep question. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5039161 commit 5166a1e

2 files changed

Lines changed: 62 additions & 5 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { APP_RESOURCE, BRAND_RESOURCE, PARAGON_RESOURCE, SHELL_RESOURCE } from './getStylesheetRule';
2+
3+
describe('stylesheet resource patterns', () => {
4+
describe('PARAGON_RESOURCE', () => {
5+
it('matches an installed-package path', () => {
6+
expect(PARAGON_RESOURCE.test('/site/node_modules/@openedx/paragon/dist/core.min.css')).toBe(true);
7+
});
8+
9+
it('matches an npm-workspace symlink target', () => {
10+
expect(PARAGON_RESOURCE.test('/site/packages/paragon/dist/core.min.css')).toBe(true);
11+
});
12+
13+
it('does not match an unrelated path containing "paragon"', () => {
14+
expect(PARAGON_RESOURCE.test('/site/src/paragon-overrides.scss')).toBe(false);
15+
});
16+
});
17+
18+
describe('SHELL_RESOURCE', () => {
19+
it('matches an installed-package path', () => {
20+
expect(SHELL_RESOURCE.test('/site/node_modules/@openedx/frontend-base/dist/shell/style.scss')).toBe(true);
21+
});
22+
23+
it('matches an npm-workspace symlink target with dist/', () => {
24+
expect(SHELL_RESOURCE.test('/site/packages/frontend-base/dist/shell/style.scss')).toBe(true);
25+
});
26+
27+
it('matches a dev:shell in-place source path', () => {
28+
expect(SHELL_RESOURCE.test('/home/u/frontend-base/shell/style.scss')).toBe(true);
29+
});
30+
});
31+
32+
describe('APP_RESOURCE', () => {
33+
it('matches a node_modules path', () => {
34+
expect(APP_RESOURCE.test('/site/node_modules/some-pkg/index.js')).toBe(true);
35+
});
36+
37+
it('matches an npm-workspace packages path', () => {
38+
expect(APP_RESOURCE.test('/site/packages/some-pkg/index.js')).toBe(true);
39+
});
40+
41+
it('does not match a site source path', () => {
42+
expect(APP_RESOURCE.test('/site/src/component.scss')).toBe(false);
43+
});
44+
});
45+
46+
describe('BRAND_RESOURCE', () => {
47+
it('matches an installed-package path', () => {
48+
expect(BRAND_RESOURCE.test('/site/node_modules/@openedx/brand-openedx/paragon.scss')).toBe(true);
49+
});
50+
51+
it('matches an npm-workspace symlink target', () => {
52+
expect(BRAND_RESOURCE.test('/site/packages/brand-openedx/paragon.scss')).toBe(true);
53+
});
54+
});
55+
});

tools/webpack/common-config/all/getStylesheetRule.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ import postcssWrapLayer from './postcssWrapLayer';
2121
* precedence of runtime brand CSS (which is injected unlayered via
2222
* <link> tags and thus beats every layered rule).
2323
*/
24-
const PARAGON_RESOURCE = /@openedx[\\/]paragon[\\/]/;
25-
const SHELL_RESOURCE = /(@openedx[\\/]frontend-base|frontend-base[\\/]shell)[\\/]/;
26-
const BRAND_RESOURCE = /@(open)?edx[\\/]brand(-[^\\/]+)?[\\/]/;
27-
const NODE_MODULES = /[\\/]node_modules[\\/]/;
24+
// Also match `packages/<pkg>` so that npm-workspace symlink targets
25+
// (where webpack's symlink resolution lands) classify correctly.
26+
export const PARAGON_RESOURCE = /(@openedx|packages)[\\/]paragon[\\/]/;
27+
export const SHELL_RESOURCE = /((@openedx|packages)[\\/]frontend-base|frontend-base[\\/](dist[\\/])?shell)[\\/]/;
28+
export const BRAND_RESOURCE = /(@(open)?edx[\\/]brand(-[^\\/]+)?|packages[\\/]brand(-[^\\/]+)?)[\\/]/;
29+
export const APP_RESOURCE = /[\\/](node_modules|packages)[\\/]/;
2830

2931
/*
3032
* There are a few things we need to do here.
@@ -64,7 +66,7 @@ export default function getStylesheetRule(mode: 'dev' | 'production'): RuleSetRu
6466
],
6567
},
6668
{
67-
resource: { not: [NODE_MODULES] },
69+
resource: { not: [APP_RESOURCE] },
6870
use: [
6971
getFirstLoader(mode),
7072
...getStyleUseConfig(mode, 'site'),

0 commit comments

Comments
 (0)