Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit a84c37c

Browse files
committed
Clean up
1 parent 0872030 commit a84c37c

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

server/css.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class CSSProcessor {
99
#isProd: boolean
1010
#options: Required<CSSOptions>
1111
#postcss: any
12-
#modulesJSON: Record<string, Record<string, string>>
12+
#modulesJSON: Map<string, Record<string, string>>
1313

1414
constructor() {
1515
this.#isProd = false
@@ -18,7 +18,7 @@ export class CSSProcessor {
1818
postcss: { plugins: ['autoprefixer'] },
1919
}
2020
this.#postcss = null
21-
this.#modulesJSON = {}
21+
this.#modulesJSON = new Map()
2222
}
2323

2424
config(isProd: boolean, options: CSSOptions) {
@@ -36,21 +36,13 @@ export class CSSProcessor {
3636
plugins.push(['postcss-modules', {
3737
...options.modules,
3838
getJSON: (url: string, json: Record<string, string>) => {
39-
this.#modulesJSON = { [url]: json }
39+
this.#modulesJSON.set(url, json)
4040
},
4141
}])
4242
this.#options.postcss.plugins = plugins
4343
}
4444
}
4545

46-
private getModulesJSON(url: string) {
47-
const json = this.#modulesJSON[url] || {}
48-
if (url in this.#modulesJSON) {
49-
delete this.#modulesJSON[url]
50-
}
51-
return json
52-
}
53-
5446
async transform(url: string, content: string): Promise<{ code: string, map?: string, classNames?: Record<string, string> }> {
5547
if (util.isLikelyHttpURL(url)) {
5648
return {
@@ -67,7 +59,6 @@ export class CSSProcessor {
6759
}
6860

6961
const { content: pcss } = await this.#postcss.process(content, { from: url }).async()
70-
const modulesJSON = this.getModulesJSON(url)
7162

7263
let css = pcss
7364
if (this.#isProd) {
@@ -91,6 +82,9 @@ export class CSSProcessor {
9182
}
9283
}
9384

85+
const modulesJSON = this.#modulesJSON.get(url) || {}
86+
this.#modulesJSON.delete(url)
87+
9488
return {
9589
code: [
9690
`import { applyCSS } from "https://deno.land/x/aleph/framework/core/style.ts"`,

0 commit comments

Comments
 (0)