feat: limited npm: specifier support (#1245)
This commit adds limited support for `npm:` specifiers. Right now, `npm:` specifiers are unsupported on Deno Deploy. Towards #978
This commit is contained in:
+4
-4
@@ -7,14 +7,14 @@ export { escape as regexpEscape } from "https://deno.land/std@0.190.0/regexp/esc
|
||||
|
||||
// -- esbuild --
|
||||
// @deno-types="https://deno.land/x/esbuild@v0.17.11/mod.d.ts"
|
||||
import * as esbuildWasm from "https://deno.land/x/esbuild@v0.17.11/wasm.js";
|
||||
import * as esbuildNative from "https://deno.land/x/esbuild@v0.17.11/mod.js";
|
||||
import * as esbuildWasm from "https://deno.land/x/esbuild@v0.17.19/wasm.js";
|
||||
import * as esbuildNative from "https://deno.land/x/esbuild@v0.17.19/mod.js";
|
||||
// @ts-ignore trust me
|
||||
// deno-lint-ignore no-deprecated-deno-api
|
||||
const esbuild: typeof esbuildWasm = Deno.run === undefined
|
||||
? esbuildWasm
|
||||
: esbuildNative;
|
||||
const esbuildWasmURL = new URL("./esbuild_v0.17.11.wasm", import.meta.url).href;
|
||||
const esbuildWasmURL = new URL("./esbuild_v0.17.19.wasm", import.meta.url).href;
|
||||
export { esbuild, esbuildWasm as esbuildTypes, esbuildWasmURL };
|
||||
|
||||
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.7.2/mod.ts";
|
||||
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.8.1/mod.ts";
|
||||
|
||||
@@ -54,7 +54,7 @@ export class EsbuildBuilder implements Builder {
|
||||
const bundle = await esbuild.build({
|
||||
entryPoints: opts.entrypoints,
|
||||
|
||||
platform: "neutral",
|
||||
platform: "browser",
|
||||
target: ["chrome99", "firefox99", "safari15"],
|
||||
|
||||
format: "esm",
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"lock": false,
|
||||
"imports": {
|
||||
"$fresh/": "../../",
|
||||
"preact": "https://esm.sh/preact@10.15.1",
|
||||
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3",
|
||||
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||
},
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "preact"
|
||||
}
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||
|
||||
import dev from "$fresh/dev.ts";
|
||||
|
||||
await dev(import.meta.url, "./main.ts");
|
||||
@@ -0,0 +1,18 @@
|
||||
// DO NOT EDIT. This file is generated by fresh.
|
||||
// This file SHOULD be checked into source version control.
|
||||
// This file is automatically updated during development when running `dev.ts`.
|
||||
|
||||
import * as $0 from "./routes/index.tsx";
|
||||
import * as $$0 from "./islands/Test.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/index.tsx": $0,
|
||||
},
|
||||
islands: {
|
||||
"./islands/Test.tsx": $$0,
|
||||
},
|
||||
baseUrl: import.meta.url,
|
||||
};
|
||||
|
||||
export default manifest;
|
||||
@@ -0,0 +1,8 @@
|
||||
import { IS_BROWSER } from "../../../runtime.ts";
|
||||
import isNumber from "npm:is-number";
|
||||
|
||||
export default function Test() {
|
||||
let id = IS_BROWSER ? "browser" : "server";
|
||||
id += "-" + String(isNumber(1));
|
||||
return <div id={id}>{id}</div>;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference no-default-lib="true" />
|
||||
/// <reference lib="dom" />
|
||||
/// <reference lib="dom.iterable" />
|
||||
/// <reference lib="dom.asynciterable" />
|
||||
/// <reference lib="deno.ns" />
|
||||
|
||||
import { start } from "$fresh/server.ts";
|
||||
import routes from "./fresh.gen.ts";
|
||||
|
||||
await start(routes);
|
||||
@@ -0,0 +1,9 @@
|
||||
import Test from "../islands/Test.tsx";
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div>
|
||||
<Test />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+25
-2
@@ -58,9 +58,13 @@ Deno.test({
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
async function withPage(fn: (page: Page) => Promise<void>) {
|
||||
function withPage(fn: (page: Page) => Promise<void>) {
|
||||
return withPageName("./tests/fixture/main.ts", fn);
|
||||
}
|
||||
|
||||
async function withPageName(name: string, fn: (page: Page) => Promise<void>) {
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
args: ["run", "-A", "./tests/fixture/main.ts"],
|
||||
args: ["run", "-A", name],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
}).spawn();
|
||||
@@ -222,3 +226,22 @@ Deno.test({
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "island using `npm:` specifiers",
|
||||
|
||||
async fn(_t) {
|
||||
await withPageName("./tests/fixture_npm/main.ts", async (page) => {
|
||||
await page.setJavaScriptEnabled(false);
|
||||
await page.goto("http://localhost:8000/", { waitUntil: "networkidle2" });
|
||||
assert(await page.waitForSelector("#server-true"));
|
||||
|
||||
await page.setJavaScriptEnabled(true);
|
||||
await page.reload({ waitUntil: "networkidle2" });
|
||||
assert(await page.waitForSelector("#browser-true"));
|
||||
});
|
||||
},
|
||||
|
||||
sanitizeOps: false,
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user