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

Commit c90875c

Browse files
committed
Fix css testing
1 parent 2368ea6 commit c90875c

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

bundler/mod.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @deno-types="https://deno.land/x/[email protected]/mod.d.ts"
2-
import { build, stop as stopEsbuild } from 'https://deno.land/x/[email protected]/mod.js'
31
import { dim } from 'https://deno.land/[email protected]/fmt/colors.ts'
42
import { basename, dirname, join } from 'https://deno.land/[email protected]/path/mod.ts'
53
import { ensureDir, } from 'https://deno.land/[email protected]/fs/ensure_dir.ts'
@@ -11,7 +9,7 @@ import util from '../shared/util.ts'
119
import { VERSION } from '../version.ts'
1210
import type { Application, Module } from '../server/app.ts'
1311
import { cache } from '../server/cache.ts'
14-
import { computeHash, getAlephPkgUri } from '../server/helper.ts'
12+
import { computeHash, esbuild, stopEsbuild, getAlephPkgUri } from '../server/helper.ts'
1513

1614
const hashShort = 8
1715
const reHashJS = new RegExp(`\\.[0-9a-fx]{${hashShort}}\\.js$`, 'i')
@@ -254,7 +252,7 @@ export class Bundler {
254252
const { buildTarget, browserslist } = this.#app.config
255253

256254
await clearBuildCache(bundleFile)
257-
await build({
255+
await esbuild({
258256
entryPoints: [entryFile],
259257
outfile: bundleFile,
260258
platform: 'browser',

server/css.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// @deno-types="https://deno.land/x/[email protected]/mod.d.ts"
2-
import { build } from 'https://deno.land/x/[email protected]/mod.js'
31
import util from '../shared/util.ts'
42
import { PostCSSPlugin, CSSOptions } from '../types.ts'
3+
import { esbuild } from './helper.ts'
54

65
const postcssVersion = '8.2.8'
76
const productionOnlyPostcssPlugins = ['autoprefixer']
@@ -72,7 +71,7 @@ export class CSSProcessor {
7271

7372
let css = pcss
7473
if (this.#isProd) {
75-
const ret = await build({
74+
const ret = await esbuild({
7675
stdin: {
7776
loader: 'css',
7877
sourcefile: url,
@@ -104,11 +103,6 @@ export class CSSProcessor {
104103
}
105104
}
106105

107-
async function initCleanCSS() {
108-
const { default: CleanCSS } = await import('https://esm.sh/[email protected]?no-check')
109-
return new CleanCSS({ compatibility: '*' /* Internet Explorer 10+ */ })
110-
}
111-
112106
async function initPostCSS(plugins: PostCSSPlugin[]) {
113107
const { default: PostCSS } = await import(`https://esm.sh/postcss@${postcssVersion}`)
114108
const isDev = Deno.env.get('ALEPH_BUILD_MODE') === 'development'

server/css_test.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { assertEquals } from 'std/testing/asserts.ts'
22
import { CSSProcessor } from './css.ts'
3+
import { stopEsbuild } from './helper.ts'
34

45
Deno.test('css processor', async () => {
56
const processor = new CSSProcessor()
@@ -15,20 +16,26 @@ Deno.test('css processor', async () => {
1516
].join('\n'))
1617
})
1718

18-
Deno.test('css processor in production mode', async () => {
19-
const processor = new CSSProcessor()
20-
processor.config(true, { modules: false, postcss: { plugins: [] } })
21-
const { code } = await processor.transform(
22-
'/test.css',
23-
'h1 { font-size: 18px; }'
24-
)
19+
Deno.test({
20+
name: 'css processor in production mode',
21+
sanitizeResources: false,
22+
fn: async () => {
23+
const processor = new CSSProcessor()
24+
processor.config(true, { modules: false, postcss: { plugins: [] } })
25+
const { code } = await processor.transform(
26+
'/test.css',
27+
'h1 { font-size: 18px; }'
28+
)
2529

26-
assertEquals(code, [
27-
'import { applyCSS } from "https://deno.land/x/aleph/framework/core/style.ts"',
28-
'const css = "h1{font-size:18px}"',
29-
'applyCSS("/test.css", css)',
30-
'export default { __url$: "/test.css", __css$: css, }'
31-
].join('\n'))
30+
assertEquals(code, [
31+
'import { applyCSS } from "https://deno.land/x/aleph/framework/core/style.ts"',
32+
'const css = "h1{font-size:18px}\\n"',
33+
'applyCSS("/test.css", css)',
34+
'export default { __url$: "/test.css", __css$: css, }'
35+
].join('\n'))
36+
37+
stopEsbuild()
38+
}
3239
})
3340

3441
Deno.test('css processor of remote CSS', async () => {

server/helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @deno-types="https://deno.land/x/[email protected]/mod.d.ts"
2+
export { build as esbuild, stop as stopEsbuild } from 'https://deno.land/x/[email protected]/mod.js'
13
import { dim, red, yellow } from 'https://deno.land/[email protected]/fmt/colors.ts'
24
import { createHash } from 'https://deno.land/[email protected]/hash/mod.ts'
35
import { relative } from 'https://deno.land/[email protected]/path/mod.ts'

0 commit comments

Comments
 (0)