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

Commit 55334b6

Browse files
committed
Clean up
1 parent b13703e commit 55334b6

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

bundler/esbuild.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export const denoPlugin: Plugin = {
4040
const isRemote = util.isLikelyHttpURL(args.path)
4141
const path = isRemote ? args.path : util.trimPrefix(args.path, 'file://')
4242

43-
44-
console.log(args)
4543
if (
4644
args.kind === 'url-token' ||
4745
(args.kind === 'import-rule' && (isRemote || path.startsWith('/')))

bundler/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export class Bundler {
167167
}
168168
)
169169

170+
// in production(bundle) mode we need to replace the star export with names
170171
if (starExports && starExports.length > 0) {
171172
for (let index = 0; index < starExports.length; index++) {
172173
const specifier = starExports[index]

compiler/build.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { exists } from 'https://deno.land/[email protected]/fs/exists.ts'
44
import { ensureDir } from 'https://deno.land/[email protected]/fs/ensure_dir.ts'
55
import { createHash } from 'https://deno.land/[email protected]/hash/mod.ts'
66
import { compress } from 'https://deno.land/x/[email protected]/mod.ts'
7-
import util from '../shared/util.ts'
87

98
async function run(cmd: string[]) {
109
const p = Deno.run({

plugins/css.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,15 @@ export const cssLoader = async ({ specifier, data }: LoadInput, aleph: Aleph): P
108108
css = sourceCode
109109
}
110110

111+
// in testing env, we don't bundle the css
111112
if (!Deno.env.get('DENO_TESTING')) {
112113
try {
113114
const ret = await esbuild({
114115
stdin: {
115116
loader: 'css',
117+
contents: css,
118+
sourcefile: join(aleph.workingDir, specifier),
116119
resolveDir: join(aleph.workingDir, dirname(specifier)),
117-
sourcefile: specifier,
118-
contents: css
119120
},
120121
write: false,
121122
bundle: true,

server/aleph.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import { cache } from './cache.ts'
2121
import type { RequiredConfig } from './config.ts'
2222
import { defaultConfig, fixConfigAndImportMap, getDefaultImportMap, loadConfig, loadImportMap } from './config.ts'
2323
import {
24-
checkAlephDev, checkDenoVersion, clearBuildCache, computeHash, findFile,
25-
getAlephPkgUri, getSourceType, isLocalUrl, moduleExclude, toLocalPath, toRelativePath
24+
checkAlephDev, checkDenoVersion, clearBuildCache, computeHash, decoder, encoder, findFile,
25+
getAlephPkgUri, getSourceType, isLocalUrl, moduleExclude, toLocalPath, toRelativePath,
2626
} from './helper.ts'
2727
import { getContentType } from './mime.ts'
2828
import { buildHtml, Renderer } from './renderer.ts'
@@ -798,7 +798,7 @@ export class Aleph implements IAleph {
798798
if (sourceType === SourceType.Unknown || sourceType === SourceType.CSS) {
799799
return []
800800
}
801-
const code = (new TextDecoder).decode(content)
801+
const code = decoder.decode(content)
802802
const names = await parseExportNames(specifier, code, { sourceType })
803803
return (await Promise.all(names.map(async name => {
804804
if (name.startsWith('{') && name.endsWith('}')) {
@@ -827,7 +827,7 @@ export class Aleph implements IAleph {
827827
if (type !== 'css') {
828828
for (const { test, load } of this.#loadListeners) {
829829
if (test.test(`.${type}`)) {
830-
const { code, type: codeType } = await load({ specifier: key, data: (new TextEncoder).encode(tpl) })
830+
const { code, type: codeType } = await load({ specifier: key, data: encoder.encode(tpl) })
831831
if (codeType === 'css') {
832832
type = 'css'
833833
tpl = code
@@ -836,7 +836,7 @@ export class Aleph implements IAleph {
836836
}
837837
}
838838
}
839-
const { code } = await cssLoader({ specifier: key, data: (new TextEncoder).encode(tpl) }, this)
839+
const { code } = await cssLoader({ specifier: key, data: encoder.encode(tpl) }, this)
840840
return code
841841
},
842842
isDev: this.isDev,
@@ -969,7 +969,7 @@ export class Aleph implements IAleph {
969969
return module.jsBuffer
970970
}
971971

972-
let code = new TextDecoder().decode(module.jsBuffer)
972+
let code = decoder.decode(module.jsBuffer)
973973
if (module.denoHooks?.length || module.ssrPropsFn || module.ssgPathsFn) {
974974
if ('csrCode' in module) {
975975
code = (module as any).csrCode
@@ -992,7 +992,7 @@ export class Aleph implements IAleph {
992992
// todo: merge source map
993993
}
994994
}
995-
return new TextEncoder().encode([
995+
return encoder.encode([
996996
`import.meta.hot = $createHotContext(${JSON.stringify(specifier)});`,
997997
'',
998998
code,
@@ -1075,7 +1075,7 @@ export class Aleph implements IAleph {
10751075
const source = await this.fetchModule(specifier)
10761076
sourceType = getSourceType(specifier, source.contentType || undefined)
10771077
if (sourceType !== SourceType.Unknown) {
1078-
sourceCode = (new TextDecoder).decode(source.content)
1078+
sourceCode = decoder.decode(source.content)
10791079
}
10801080
}
10811081

@@ -1234,7 +1234,6 @@ export class Aleph implements IAleph {
12341234
}
12351235

12361236
const ms = new Measure()
1237-
const encoder = new TextEncoder()
12381237
const { code, deps = [], denoHooks, ssrPropsFn, ssgPathsFn, starExports, jsxStaticClassNames, map } = await transform(specifier, source.code, {
12391238
...this.commonCompilerOptions,
12401239
sourceMap: this.isDev,
@@ -1405,7 +1404,7 @@ export class Aleph implements IAleph {
14051404

14061405
/** replace dep hash in the `jsBuffer` and remove `csrCode` cache if it exits */
14071406
private async replaceDepHash(module: Module, hashLoc: number, hash: string) {
1408-
const hashData = (new TextEncoder()).encode(hash.substr(0, 6))
1407+
const hashData = encoder.encode(hash.substr(0, 6))
14091408
const jsBuffer = await this.getModuleJS(module)
14101409
if (jsBuffer && !equals(hashData, jsBuffer.slice(hashLoc, hashLoc + 6))) {
14111410
copy(hashData, jsBuffer, hashLoc)

server/helper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export function checkAlephDev() {
5050
}
5151
}
5252

53+
export const encoder = new TextEncoder()
54+
export const decoder = new TextDecoder()
55+
5356
export const moduleExclude = [
5457
/(^|\/|\\)\./,
5558
/\.d\.ts$/i,
@@ -84,7 +87,7 @@ export async function getDenoDir() {
8487
stdout: 'piped',
8588
stderr: 'null'
8689
})
87-
const output = (new TextDecoder).decode(await p.output())
90+
const output = decoder.decode(await p.output())
8891
const { denoDir } = JSON.parse(output)
8992
p.close()
9093
if (denoDir === undefined || !await existsDir(denoDir)) {

server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import util from '../shared/util.ts'
99
import { APIContext } from '../types.d.ts'
1010
import { Aleph } from './aleph.ts'
1111
import compress from './compress.ts'
12+
import { encoder } from './helper.ts'
1213
import { getContentType } from './mime.ts'
1314
import { APIResponse } from './response.ts'
1415

@@ -102,7 +103,7 @@ export class Server {
102103
if (compress.enable && acceptEncoding && body && contentType) {
103104
let data = new Uint8Array()
104105
if (typeof body === 'string') {
105-
data = new TextEncoder().encode(body)
106+
data = encoder.encode(body)
106107
} else if (body instanceof Uint8Array) {
107108
data = body
108109
} else if (body instanceof ArrayBuffer) {

0 commit comments

Comments
 (0)