Skip to content

Commit 541d4d1

Browse files
committed
fix: build style i metropolis when fixing multiple tabs(close:#53 )
1 parent fb51878 commit 541d4d1

File tree

5 files changed

+84
-9
lines changed

5 files changed

+84
-9
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"peerDependencies": {
7676
"baiwusanyu-utils": "^1.0.5",
7777
"chalk": "^4.1.2",
78-
"estree-walker-ts": "^1.0.0-beta.2",
78+
"estree-walker-ts": "^1.0.0",
7979
"fast-glob": "^3.2.12",
8080
"fs-extra": "^11.1.1",
8181
"hash-sum": "^2.0.0",
@@ -86,7 +86,7 @@
8686
"dependencies": {
8787
"baiwusanyu-utils": "^1.0.5",
8888
"chalk": "^4.1.2",
89-
"estree-walker-ts": "^1.0.0-beta.2",
89+
"estree-walker-ts": "^1.0.0",
9090
"fast-glob": "^3.2.12",
9191
"fs-extra": "^11.1.1",
9292
"hash-sum": "^2.0.0",

packages/core/inject/__test__/__snapshots__/inject-css.spec.ts.snap

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`inject-css > injectCssOnBuild: basic 1`] = `
4-
"<style lang=\\"scss\\" >
4+
"
5+
<style lang=\\"scss\\" >
56
67
body { background-color: black; }
78
/* foo.scss -> test2.css -> test.css */
@@ -14,8 +15,30 @@ div {
1415
</style>"
1516
`;
1617

18+
exports[`inject-css > injectCssOnBuild: mutiple style tags 1`] = `
19+
"
20+
<style lang=\\"scss\\" >
21+
22+
body { background-color: black; }
23+
/* foo.scss -> test2.css -> test.css */
24+
/* foo.scss -> test.scss -> test2.css */
25+
26+
/*@import \\"./assets/less/less-foo\\";*/
27+
div {
28+
color: v-bind(color)
29+
}
30+
</style>
31+
<style lang=\\"scss\\" >
32+
.el-popup-parent--hidden {
33+
.fixed-header {
34+
padding-right: 17px;
35+
}
36+
} </style> "
37+
`;
38+
1739
exports[`inject-css > injectCssOnBuild: no lang 1`] = `
18-
"<style lang=\\"css\\" >
40+
"
41+
<style lang=\\"css\\" >
1942
2043
body { background-color: black; }
2144
/* foo.scss -> test2.css -> test.css */

packages/core/inject/__test__/inject-css.spec.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,58 @@ describe('inject-css', () => {
112112
expect(result.toString()).toMatchSnapshot()
113113
})
114114

115+
// fix: #53
116+
test('injectCssOnBuild: mutiple style tags', () => {
117+
const code = '<style lang="scss">\n'
118+
+ '/* foo.scss -> test2.css -> test.css */\n'
119+
+ '/* foo.scss -> test.scss -> test2.css */\n'
120+
+ '\n'
121+
+ '/*@import "./assets/less/less-foo";*/\n'
122+
+ 'div {\n'
123+
+ ' color: v-bind(color)\n'
124+
+ '}\n'
125+
+ "@import './assets/scss/foo.scss';\n"
126+
+ '</style> '
127+
+ '<style lang="scss">\n'
128+
+ ' .el-popup-parent--hidden {\n'
129+
+ ' .fixed-header {\n'
130+
+ ' padding-right: 17px;\n'
131+
+ ' }\n'
132+
+ ' }\n'
133+
+ '</style>'
134+
const mgcStr = new MagicString(code)
135+
const injectCSSContent = new Set([{
136+
content: '@import \'./assets/scss/foo.scss\';\nbody { background-color: black; }',
137+
lang: 'scss',
138+
styleTagIndex: 0,
139+
}])
140+
const descriptor = {
141+
styles: [
142+
{
143+
lang: 'scss',
144+
content: '/* foo.scss -> test2.css -> test.css */\n'
145+
+ '/* foo.scss -> test.scss -> test2.css */\n'
146+
+ '\n'
147+
+ '/*@import "./assets/less/less-foo";*/\n'
148+
+ 'div {\n'
149+
+ ' color: v-bind(color)\n'
150+
+ '}\n'
151+
+ "@import './assets/scss/foo.scss';",
152+
},
153+
{
154+
lang: 'scss',
155+
content: ' .el-popup-parent--hidden {\n'
156+
+ ' .fixed-header {\n'
157+
+ ' padding-right: 17px;\n'
158+
+ ' }\n'
159+
+ ' }',
160+
},
161+
],
162+
}
163+
const result = injectCssOnBuild(mgcStr, injectCSSContent, descriptor as any)
164+
expect(result.toString()).toMatchSnapshot()
165+
})
166+
115167
test('injectCssOnBuild: no styles', () => {
116168
const code = 'test'
117169
const injectCSSContent = new Set([{

packages/core/inject/inject-css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function injectCssOnBuild(
3737
})
3838
const lang = value.lang || 'css'
3939
const scoped = value.scoped ? 'scoped' : ''
40-
resCode = `<style lang="${lang}" ${scoped}> ${injectCssCode}\n${transformInjectCSS(value.content, parseImports(value.content).imports)} </style>`
40+
resCode = `${resCode}\n<style lang="${lang}" ${scoped}> ${injectCssCode}\n${transformInjectCSS(value.content, parseImports(value.content).imports)} </style>`
4141
})
4242
resCode && (mgcStr = removeStyleTagsAndContent(mgcStr))
4343
return mgcStr.prependRight(mgcStr.length(), resCode)

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)