Skip to content

Commit 0de535e

Browse files
fix: do not redirect third party css file (#1069)
Co-authored-by: Wei <[email protected]>
1 parent a64be69 commit 0de535e

File tree

10 files changed

+79
-14
lines changed

10 files changed

+79
-14
lines changed

packages/core/src/css/cssConfig.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ export async function cssExternalHandler(
9898
let resolvedRequest = request;
9999

100100
if (styleRedirectPath) {
101-
const resolved = await redirectPath(resolvedRequest);
102-
if (resolved) {
103-
resolvedRequest = resolved;
101+
const redirectedPath = await redirectPath(resolvedRequest);
102+
if (redirectedPath === undefined) {
103+
return callback(undefined, request);
104104
}
105+
resolvedRequest = redirectedPath;
105106
}
106107

107108
if (!isCssFile(resolvedRequest)) {

pnpm-lock.yaml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/redirect/js.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ test('redirect.js default', async () => {
2121

2222
expect(indexContent).toMatchInlineSnapshot(`
2323
"import lodash from "lodash";
24+
import lodash_merge from "lodash.merge";
2425
import prettier from "prettier";
2526
import { bar } from "./bar/index.js";
2627
import { foo } from "./foo.js";
2728
import { baz } from "./baz.js";
28-
const src = lodash.toUpper(foo + bar + foo + bar + baz + typeof prettier.version);
29+
const src = lodash.toUpper(lodash_merge(foo) + bar + foo + bar + baz + typeof prettier.version);
2930
export { src as default };
3031
"
3132
`);
@@ -45,13 +46,14 @@ test('redirect.js.path false', async () => {
4546

4647
expect(indexContent).toMatchInlineSnapshot(`
4748
"import lodash from "lodash";
49+
import lodash_merge from "lodash.merge";
4850
import prettier from "prettier";
4951
import { bar } from "@/bar";
5052
import { foo } from "@/foo";
5153
import { baz } from "~/baz";
5254
import { bar as external_bar_js_bar } from "./bar.js";
5355
import { foo as external_foo_js_foo } from "./foo.js";
54-
const src = lodash.toUpper(external_foo_js_foo + external_bar_js_bar + foo + bar + baz + typeof prettier.version);
56+
const src = lodash.toUpper(lodash_merge(external_foo_js_foo) + external_bar_js_bar + foo + bar + baz + typeof prettier.version);
5557
export { src as default };
5658
"
5759
`);
@@ -69,13 +71,14 @@ test('redirect.js.path with user override externals', async () => {
6971

7072
expect(indexContent).toMatchInlineSnapshot(`
7173
"import lodash from "lodash";
74+
import lodash_merge from "lodash.merge";
7275
import prettier from "prettier";
7376
import { bar } from "./others/bar/index.js";
7477
import { foo } from "./others/foo.js";
7578
import { baz } from "./baz.js";
7679
import { bar as index_js_bar } from "./bar/index.js";
7780
import { foo as external_foo_js_foo } from "./foo.js";
78-
const src = lodash.toUpper(external_foo_js_foo + index_js_bar + foo + bar + baz + typeof prettier.version);
81+
const src = lodash.toUpper(lodash_merge(external_foo_js_foo) + index_js_bar + foo + bar + baz + typeof prettier.version);
7982
export { src as default };
8083
"
8184
`);
@@ -101,13 +104,14 @@ test('redirect.js.path with user override alias', async () => {
101104

102105
expect(indexContent).toMatchInlineSnapshot(`
103106
"import lodash from "lodash";
107+
import lodash_merge from "lodash.merge";
104108
import prettier from "prettier";
105109
import { bar } from "./others/bar/index.js";
106110
import { foo } from "./others/foo.js";
107111
import { baz } from "./baz.js";
108112
import { bar as index_js_bar } from "./bar/index.js";
109113
import { foo as external_foo_js_foo } from "./foo.js";
110-
const src = lodash.toUpper(external_foo_js_foo + index_js_bar + foo + bar + baz + typeof prettier.version);
114+
const src = lodash.toUpper(lodash_merge(external_foo_js_foo) + index_js_bar + foo + bar + baz + typeof prettier.version);
111115
export { src as default };
112116
"
113117
`);
@@ -128,11 +132,12 @@ test('redirect.js.extension: false', async () => {
128132
);
129133
expect(indexContent).toMatchInlineSnapshot(`
130134
"import lodash from "lodash";
135+
import lodash_merge from "lodash.merge";
131136
import prettier from "prettier";
132137
import { bar } from "./bar/index.ts";
133138
import { foo } from "./foo.ts";
134139
import { baz } from "./baz.ts";
135-
const src = lodash.toUpper(foo + bar + foo + bar + baz + typeof prettier.version);
140+
const src = lodash.toUpper(lodash_merge(foo) + bar + foo + bar + baz + typeof prettier.version);
136141
export { src as default };
137142
"
138143
`);

tests/integration/redirect/js/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
"type": "module",
66
"devDependencies": {
77
"@types/lodash": "^4.17.17",
8-
"lodash": "^4.17.21"
9-
},
10-
"peerDependencies": {
11-
"lodash": "^4.17.21"
8+
"@types/lodash.merge": "^4.6.9",
9+
"lodash": "^4.17.21",
10+
"lodash.merge": "^4.6.2"
1211
}
1312
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
// can not be resolved
22
import lodash from 'lodash';
3+
// can be resolved, 3rd party packages
4+
import merge from 'lodash.merge';
35
// can be resolved but not specified -- phantom dependency
46
import prettier from 'prettier';
57

68
import { bar as bar2 } from '@/bar';
79
import { foo as foo2 } from '@/foo';
10+
// @ts-expect-error test case for unresolved paths import
811
import { baz } from '~/baz';
912
import { bar } from './bar';
1013
import { foo } from './foo';
1114

1215
export default lodash.toUpper(
13-
foo + bar + foo2 + bar2 + baz + typeof prettier.version,
16+
merge(foo) + bar + foo2 + bar2 + baz + typeof prettier.version,
1417
);

tests/integration/redirect/style.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ test('should external 3rd packages CSS', async () => {
159159
expect(pkgIndexJs).toMatchInlineSnapshot(`
160160
"import "element-ui/lib/theme-chunk/index.css";
161161
import "element-ui/lib/theme-chunk/index";
162+
import "third-party/index.module.scss";
162163
"
163164
`);
164165
expect(pkgIndexCjs).toContain(
165166
`require("element-ui/lib/theme-chunk/index.css");
166-
require("element-ui/lib/theme-chunk/index");`,
167+
require("element-ui/lib/theme-chunk/index");
168+
require("third-party/index.module.scss");`,
167169
);
168170
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!node_modules/

tests/integration/redirect/style/node_modules/third-party/index.module.scss

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/redirect/style/node_modules/third-party/package.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
// https://github.com/web-infra-dev/rslib/issues/617
22
import 'element-ui/lib/theme-chunk/index.css';
33
import 'element-ui/lib/theme-chunk/index';
4+
// can be resolved, 3rd party packages
5+
import 'third-party/index.module.scss';

0 commit comments

Comments
 (0)