-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,13 +179,13 @@ import { NinetyRing, NinetyRingWithBg } from "https://esm.sh/react-svg-spinners@ | |
esm.sh is a **Deno-friendly** CDN that resolves Node's built-in modules (such as **fs**, **os**, etc.), making it compatible with Deno. | ||
|
||
```javascript | ||
import postcss from "https://esm.sh/postcss" | ||
import autoprefixer from "https://esm.sh/autoprefixer" | ||
import express from "https://esm.sh/express"; | ||
|
||
const { css } = await postcss([ autoprefixer ]).process(` | ||
backdrop-filter: blur(5px); | ||
user-select: none; | ||
.async() | ||
const app = express(); | ||
app.get("/", (req, res) => { | ||
res.send("Hello World"); | ||
}); | ||
app.listen(3000) | ||
``` | ||
|
||
For users using deno `< 1.31`, esm.sh uses [deno.land/[email protected]/node](https://deno.land/[email protected]/node) as node compatibility layer. You can specify a different version by adding the `?deno-std=$VER` query: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -885,25 +885,17 @@ esbuild: | |
} | ||
} | ||
|
||
// most of npm packages check for window object to detect browser environment, but Deno also has the window object | ||
// so we need to replace the check with document object | ||
if task.Target == "deno" || task.Target == "denonext" { | ||
// inject xhr polyfill for axios | ||
switch task.Pkg.Name { | ||
case "axios", "cross-fetch", "whatwg-fetch": | ||
outputContent = bytes.Join([][]byte{ | ||
[]byte(`import "https://deno.land/x/[email protected]/mod.ts";`), | ||
outputContent, | ||
}, []byte{}) | ||
} | ||
// most of npm packages check for window object to detect browser environment, but Deno also has the window object | ||
// so we need to replace the check with document object | ||
if task.DevMode { | ||
outputContent = bytes.Replace(outputContent, []byte("typeof window !== \"undefined\""), []byte("typeof document !== \"undefined\""), -1) | ||
} else { | ||
outputContent = bytes.Replace(outputContent, []byte("typeof window<\"u\""), []byte("typeof document<\"u\""), -1) | ||
} | ||
} | ||
|
||
_, err = buf.Write(outputContent) | ||
_, err = buf.Write(rewriteJS(task, outputContent)) | ||
if err != nil { | ||
return | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package server | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
) | ||
|
||
func rewriteJS(task *BuildTask, js []byte) []byte { | ||
denoTarget := task.Target == "deno" || task.Target == "denonext" | ||
switch task.Pkg.Name { | ||
case "axios", "cross-fetch", "whatwg-fetch": | ||
if denoTarget { | ||
xhr := []byte(`import "https://deno.land/x/[email protected]/mod.ts";`) | ||
buf := make([]byte, len(js)+len(xhr)) | ||
copy(buf, xhr) | ||
copy(buf[len(xhr):], js) | ||
js = buf | ||
} | ||
case "iconv-lite": | ||
if denoTarget && semver.MustParse(task.Pkg.Version).LessThan(semver.MustParse("0.5.0")) { | ||
js = bytes.Replace(js, []byte("__Process$.versions.node"), []byte("void 0"), 1) | ||
} | ||
} | ||
return js | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
|
||
import express, { | ||
type Request, | ||
type Response, | ||
} from "http://localhost:8080/express@4"; | ||
|
||
Deno.test( | ||
"express", | ||
{ sanitizeOps: false, sanitizeResources: false }, | ||
async () => { | ||
const app = express(); | ||
app.get("/", (_req: Request, res: Response) => { | ||
// @ts-ignore | ||
res.send("Hello World"); | ||
}); | ||
|
||
const ac = new AbortController(); | ||
await new Promise<void>((resolve, reject) => { | ||
const server = app.listen({ port: 3333 }, (err?: Error) => { | ||
if (err) reject(err); | ||
resolve(); | ||
}); | ||
ac.signal.onabort = () => { | ||
server.close(); | ||
}; | ||
}); | ||
|
||
const res = await fetch("http://localhost:3333"); | ||
assertEquals(await res.text(), "Hello World"); | ||
ac.abort(); | ||
}, | ||
); |