Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52d8050

Browse files
authored
fix: respectdefault when loading postcss esm configs
1 parentfdd5448 commit52d8050

File tree

10 files changed

+111
-0
lines changed

10 files changed

+111
-0
lines changed

‎src/utils.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ async function loadConfig(loaderContext, config, postcssOptions) {
108108
}
109109
}
110110

111+
if(result.default){
112+
returnresult.default;
113+
}
114+
111115
returnresult;
112116
},
113117
".cjs":defaultLoadersSync[".cjs"],
@@ -130,6 +134,10 @@ async function loadConfig(loaderContext, config, postcssOptions) {
130134
thrownewError("ESM is not supported");
131135
}
132136

137+
if(result.default){
138+
returnresult.default;
139+
}
140+
133141
returnresult;
134142
},
135143
};

‎test/config-autoload.test.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,45 @@ describe("autoload config", () => {
116116
);
117117
});
118118

119+
it('should load ESM version of "postcss.config.js" with "Array" syntax of plugins',async()=>{
120+
constloadedConfig=awaitloadConfig(
121+
loaderContext,
122+
path.resolve(testDirectory,"js/array-esm-js"),
123+
);
124+
125+
expect(loadedConfig.config.map).toEqual(false);
126+
expect(loadedConfig.config.from).toEqual(
127+
"./test/fixtures/config-autoload/js/object/index.css",
128+
);
129+
expect(loadedConfig.config.to).toEqual(
130+
"./test/fixtures/config-autoload/js/object/expect/index.css",
131+
);
132+
expect(Object.keys(loadedConfig.config.plugins).length).toEqual(4);
133+
expect(loadedConfig.filepath).toEqual(
134+
path.resolve(testDirectory,"js/array-esm-js","postcss.config.js"),
135+
);
136+
});
137+
138+
// TODO Test manually with NODE_OPTIONS=--experimental-vm-modules to enable ESM support in jest
139+
it.skip('should load "postcss.config.mjs" with "Array" syntax of plugins',async()=>{
140+
constloadedConfig=awaitloadConfig(
141+
loaderContext,
142+
path.resolve(testDirectory,"js/array-mjs"),
143+
);
144+
145+
expect(loadedConfig.config.map).toEqual(false);
146+
expect(loadedConfig.config.from).toEqual(
147+
"./test/fixtures/config-autoload/js/object/index.css",
148+
);
149+
expect(loadedConfig.config.to).toEqual(
150+
"./test/fixtures/config-autoload/js/object/expect/index.css",
151+
);
152+
expect(Object.keys(loadedConfig.config.plugins).length).toEqual(4);
153+
expect(loadedConfig.filepath).toEqual(
154+
path.resolve(testDirectory,"js/array-mjs","postcss.config.mjs"),
155+
);
156+
});
157+
119158
it('should load "postcss.config.ts" with "Array" syntax of plugins',async()=>{
120159
constloadedConfig=awaitloadConfig(
121160
loaderContext,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.import {
2+
color: goldenrod;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import'imports/section.css';
2+
3+
.test {
4+
color: cyan;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
importstylefrom'./index.css'
2+
3+
exportdefaultstyle
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
importpostcssNestedfrom'postcss-nested';
2+
exportdefaultfunction(api){
3+
return{
4+
parser:'sugarss',
5+
syntax:'sugarss',
6+
map:api.mode==='development' ?'inline' :false,
7+
from:'./test/fixtures/config-autoload/js/object/index.css',
8+
to:'./test/fixtures/config-autoload/js/object/expect/index.css',
9+
plugins:[
10+
'postcss-import',
11+
[
12+
'postcss-nested',
13+
{
14+
// Options
15+
}
16+
],
17+
postcssNested,
18+
postcssNested({/* Options */}),
19+
]
20+
}
21+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.import {
2+
color: goldenrod;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import'imports/section.css';
2+
3+
.test {
4+
color: cyan;
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
importstylefrom'./index.css'
2+
3+
exportdefaultstyle
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
importpostcssNestedfrom'postcss-nested';
2+
exportdefaultfunction(api){
3+
return{
4+
parser:'sugarss',
5+
syntax:'sugarss',
6+
map:api.mode==='development' ?'inline' :false,
7+
from:'./test/fixtures/config-autoload/js/object/index.css',
8+
to:'./test/fixtures/config-autoload/js/object/expect/index.css',
9+
plugins:[
10+
'postcss-import',
11+
[
12+
'postcss-nested',
13+
{
14+
// Options
15+
}
16+
],
17+
postcssNested,
18+
postcssNested({/* Options */}),
19+
]
20+
}
21+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp