Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8400c019e0 | ||
|
|
0e6aa1d232 | ||
|
|
dd635e0fbe | ||
|
|
cc42b17dfb | ||
|
|
dda4a30f9c |
@@ -73,12 +73,12 @@
|
||||
"jsr:@zip-js/zip-js@^2.7.52": "2.8.24",
|
||||
"npm:@babel/core@^7.28.0": "7.28.5",
|
||||
"npm:@babel/preset-react@^7.27.1": "7.28.5_@babel+core@7.28.5",
|
||||
"npm:@docsearch/js@^3.5.2": "3.9.0_@algolia+client-search@5.50.0_search-insights@2.17.3",
|
||||
"npm:@docsearch/js@^3.5.2": "3.9.0_preact-render-to-string@6.6.7__preact@10.29.8",
|
||||
"npm:@opentelemetry/api@^1.9.0": "1.9.1",
|
||||
"npm:@preact/signals@2": "2.9.0_preact@10.29.1",
|
||||
"npm:@preact/signals@^2.2.1": "2.9.0_preact@10.29.1",
|
||||
"npm:@preact/signals@^2.5.1": "2.9.0_preact@10.29.1",
|
||||
"npm:@prefresh/vite@^2.4.8": "2.4.11_preact@10.29.1_vite@7.3.1",
|
||||
"npm:@preact/signals@2": "2.9.0_preact@10.29.8_preact-render-to-string@6.6.7__preact@10.29.8",
|
||||
"npm:@preact/signals@^2.2.1": "2.9.0_preact@10.29.8_preact-render-to-string@6.6.7__preact@10.29.8",
|
||||
"npm:@preact/signals@^2.5.1": "2.9.0_preact@10.29.8_preact-render-to-string@6.6.7__preact@10.29.8",
|
||||
"npm:@prefresh/vite@^2.4.8": "2.4.11_preact@10.29.8_vite@7.3.1_preact-render-to-string@6.6.7__preact@10.29.8",
|
||||
"npm:@radix-ui/themes@^3.2.1": "3.2.1_react@19.1.1_react-dom@19.1.1",
|
||||
"npm:@remix-run/node-fetch-server@0.12": "0.12.0",
|
||||
"npm:@supabase/postgrest-js@^1.21.4": "1.21.4",
|
||||
@@ -108,13 +108,13 @@
|
||||
"npm:pg@^8.16.3": "8.16.3",
|
||||
"npm:postcss@8.5.6": "8.5.6",
|
||||
"npm:postcss@^8.5.6": "8.5.6",
|
||||
"npm:preact-render-to-string@^6.6.3": "6.6.7_preact@10.29.1",
|
||||
"npm:preact-render-to-string@^6.6.5": "6.6.7_preact@10.29.1",
|
||||
"npm:preact@^10.22.0": "10.29.1",
|
||||
"npm:preact@^10.26.9": "10.29.1",
|
||||
"npm:preact@^10.27.0": "10.29.1",
|
||||
"npm:preact@^10.28.2": "10.29.1",
|
||||
"npm:preact@^10.29.1": "10.29.1",
|
||||
"npm:preact-render-to-string@^6.6.3": "6.6.7_preact@10.29.8",
|
||||
"npm:preact-render-to-string@^6.6.5": "6.6.7_preact@10.29.8",
|
||||
"npm:preact@^10.22.0": "10.29.8_preact-render-to-string@6.6.7",
|
||||
"npm:preact@^10.26.9": "10.29.8_preact-render-to-string@6.6.7",
|
||||
"npm:preact@^10.27.0": "10.29.8_preact-render-to-string@6.6.7",
|
||||
"npm:preact@^10.28.2": "10.29.8_preact-render-to-string@6.6.7",
|
||||
"npm:preact@^10.29.8": "10.29.8_preact-render-to-string@6.6.7",
|
||||
"npm:prismjs@^1.29.0": "1.30.0",
|
||||
"npm:qs@^6.14.0": "6.14.0",
|
||||
"npm:redis@^5.8.2": "5.9.0_@redis+client@5.9.0",
|
||||
@@ -1357,7 +1357,7 @@
|
||||
"@docsearch/css@3.9.0": {
|
||||
"integrity": "sha512-cQbnVbq0rrBwNAKegIac/t6a8nWoUAn8frnkLFW6YARaRmAQr5/Eoe6Ln2fqkUCZ40KpdrKbpSAmgrkviOxuWA=="
|
||||
},
|
||||
"@docsearch/js@3.9.0_@algolia+client-search@5.50.0_search-insights@2.17.3": {
|
||||
"@docsearch/js@3.9.0_preact-render-to-string@6.6.7__preact@10.29.8": {
|
||||
"integrity": "sha512-4bKHcye6EkLgRE8ze0vcdshmEqxeiJM77M0JXjef7lrYZfSlMunrDOCqyLjiZyo1+c0BhUqA2QpFartIjuHIjw==",
|
||||
"dependencies": [
|
||||
"@docsearch/react",
|
||||
@@ -1741,7 +1741,7 @@
|
||||
"@preact/signals-core@1.14.0": {
|
||||
"integrity": "sha512-AowtCcCU/33lFlh1zRFf/u+12rfrhtNakj7UpaGEsmMwUKpKWMVvcktOGcwBBNiB4lWrZWc01LhiyyzVklJyaQ=="
|
||||
},
|
||||
"@preact/signals@2.9.0_preact@10.29.1": {
|
||||
"@preact/signals@2.9.0_preact@10.29.8_preact-render-to-string@6.6.7__preact@10.29.8": {
|
||||
"integrity": "sha512-hYrY0KyUqkDgOl1qba/JGn6y81pXnurn21PMaxfcMwdncdZ3M/oVdmpTvEnsGjh48dIwDVc7bjWHqIsngSjYug==",
|
||||
"dependencies": [
|
||||
"@preact/signals-core",
|
||||
@@ -1751,7 +1751,7 @@
|
||||
"@prefresh/babel-plugin@0.5.2": {
|
||||
"integrity": "sha512-AOl4HG6dAxWkJ5ndPHBgBa49oo/9bOiJuRDKHLSTyH+Fd9x00shTXpdiTj1W41l6oQIwUOAgJeHMn4QwIDpHkA=="
|
||||
},
|
||||
"@prefresh/core@1.5.8_preact@10.29.1": {
|
||||
"@prefresh/core@1.5.8_preact@10.29.8_preact-render-to-string@6.6.7__preact@10.29.8": {
|
||||
"integrity": "sha512-T7HMpakS1iPVCFZvfDLMGyrWAcO3toUN9/RkJUqqoRr/vNhQrZgHjidfhq3awDzAQtw1emDWH8dsOeu0DWqtgA==",
|
||||
"dependencies": [
|
||||
"preact"
|
||||
@@ -1760,7 +1760,7 @@
|
||||
"@prefresh/utils@1.2.1": {
|
||||
"integrity": "sha512-vq/sIuN5nYfYzvyayXI4C2QkprfNaHUQ9ZX+3xLD8nL3rWyzpxOm1+K7RtMbhd+66QcaISViK7amjnheQ/4WZw=="
|
||||
},
|
||||
"@prefresh/vite@2.4.11_preact@10.29.1_vite@7.3.1": {
|
||||
"@prefresh/vite@2.4.11_preact@10.29.8_vite@7.3.1_preact-render-to-string@6.6.7__preact@10.29.8": {
|
||||
"integrity": "sha512-/XjURQqdRiCG3NpMmWqE9kJwrg9IchIOWHzulCfqg2sRe/8oQ1g5De7xrk9lbqPIQLn7ntBkKdqWXIj4E9YXyg==",
|
||||
"dependencies": [
|
||||
"@babel/core",
|
||||
@@ -4827,14 +4827,20 @@
|
||||
"xtend"
|
||||
]
|
||||
},
|
||||
"preact-render-to-string@6.6.7_preact@10.29.1": {
|
||||
"preact-render-to-string@6.6.7_preact@10.29.8": {
|
||||
"integrity": "sha512-3XdbsX3+vn9dQW+jJI/FsI9rlkgl6dbeUpqLsChak6jp3j3auFqBCkno7VChbMFs5Q8ylBj6DrUkKRwtVN3nvw==",
|
||||
"dependencies": [
|
||||
"preact"
|
||||
]
|
||||
},
|
||||
"preact@10.29.1": {
|
||||
"integrity": "sha512-gQCLc/vWroE8lIpleXtdJhTFDogTdZG9AjMUpVkDf2iTCNwYNWA+u16dL41TqUDJO4gm2IgrcMv3uTpjd4Pwmg=="
|
||||
"preact@10.29.8_preact-render-to-string@6.6.7": {
|
||||
"integrity": "sha512-ej2aVZ+vZ8WO7tvlQWRM9N63A0KzF9q4mWJfDUHgYaIofWY9hu74QdnQrjoPMmZi2/nZ5gN0bJCQF49xQqx09Q==",
|
||||
"dependencies": [
|
||||
"preact-render-to-string"
|
||||
],
|
||||
"optionalPeers": [
|
||||
"preact-render-to-string"
|
||||
]
|
||||
},
|
||||
"pretty-bytes@5.6.0": {
|
||||
"integrity": "sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg=="
|
||||
@@ -6085,7 +6091,7 @@
|
||||
"npm:@types/node@^24.2.1",
|
||||
"npm:esbuild-wasm@~0.25.11",
|
||||
"npm:preact-render-to-string@^6.6.3",
|
||||
"npm:preact@^10.29.1"
|
||||
"npm:preact@^10.29.8"
|
||||
]
|
||||
},
|
||||
"packages/plugin-tailwindcss-v3": {
|
||||
|
||||
@@ -102,6 +102,12 @@ export default define.page<typeof handler>(function Upload(props) {
|
||||
});
|
||||
```
|
||||
|
||||
## Other HTTP methods
|
||||
|
||||
Browsers can only submit forms as `GET` or `POST`. To submit a form as `DELETE`,
|
||||
`PATCH` or `PUT` and update part of the page with the response, use
|
||||
[Partials](/docs/advanced/partials#using-other-http-methods).
|
||||
|
||||
## A note of caution
|
||||
|
||||
These examples are simplified to demonstrate how Deno and Fresh handle HTTP
|
||||
|
||||
@@ -145,6 +145,80 @@ two links and _only_ load the content rendered by our optimized partial route.
|
||||
> Currently, `f-partial` is scoped to `<a>`, `<button>` and `<form>` elements.
|
||||
> This might be extended to more elements in the future.
|
||||
|
||||
## Submitting forms
|
||||
|
||||
Forms inside an `f-client-nav` element can be submitted as a partial request.
|
||||
For `GET` and `POST` forms, this happens when the form opts in through one of
|
||||
these attributes:
|
||||
|
||||
- an `action` attribute on the `<form>`
|
||||
- an `f-partial` attribute on the `<form>`
|
||||
- a `formaction` or `f-partial` attribute on the submit button
|
||||
|
||||
A `GET` form sends its fields as URL search parameters. Every other method sends
|
||||
them as a `multipart/form-data` request body. If the submit button has a `name`,
|
||||
its value is included too.
|
||||
|
||||
A `GET` or `POST` form without any of these attributes is submitted the normal
|
||||
way, with a full page load. Forms with `method="dialog"` are never intercepted.
|
||||
|
||||
### Using other HTTP methods
|
||||
|
||||
Browsers can only submit forms as `GET` or `POST`. Fresh lets forms inside
|
||||
`f-client-nav` use any other method too, like `DELETE`, `PATCH` or `PUT`. You
|
||||
set it with the `method` attribute on the form or the `formmethod` attribute on
|
||||
a submit button, and Fresh sends the request with `fetch()`.
|
||||
|
||||
```tsx routes/index.tsx
|
||||
import { Partial } from "sweet/runtime";
|
||||
import { define } from "../utils.ts";
|
||||
|
||||
export const handler = define.handlers({
|
||||
POST(ctx) {
|
||||
return ctx.render(<Partial name="body">post!</Partial>);
|
||||
},
|
||||
DELETE(ctx) {
|
||||
return ctx.render(<Partial name="body">delete!</Partial>);
|
||||
},
|
||||
PATCH(ctx) {
|
||||
return ctx.render(<Partial name="body">patch!</Partial>);
|
||||
},
|
||||
});
|
||||
|
||||
export default define.page(function Home() {
|
||||
return (
|
||||
<div f-client-nav>
|
||||
<form action="/">
|
||||
<button type="submit" formmethod="POST">post</button>
|
||||
<button type="submit" formmethod="DELETE">delete</button>
|
||||
<button type="submit" formmethod="PATCH">patch</button>
|
||||
</form>
|
||||
<Partial name="body">nothing submitted yet</Partial>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
```
|
||||
|
||||
A form that uses another method is always submitted as a partial request. It
|
||||
doesn't need an `action` or `f-partial` attribute. Without them, the request
|
||||
goes to the current page. You can write the method in any case: Fresh converts
|
||||
it to uppercase, so `formmethod="patch"` reaches your `PATCH` handler.
|
||||
|
||||
The `POST` button above only submits as a partial because the form has an
|
||||
`action` attribute. Without it, `POST` would cause a full page load, while the
|
||||
`DELETE` and `PATCH` buttons would still work as partials.
|
||||
|
||||
Keep the following in mind when using other methods:
|
||||
|
||||
- **Redirects:** To redirect after a `DELETE`, `PATCH` or `PUT`, respond with
|
||||
status `303 See Other`. With a `301` or `302`, `fetch()` sends the request to
|
||||
the new URL again with the same method.
|
||||
- **Without JavaScript:** If JavaScript isn't loaded, the browser doesn't
|
||||
recognize the method and submits the form as a `GET` request instead, with the
|
||||
fields in the URL. If a form has to work without JavaScript, use `POST`.
|
||||
- **CSRF protection:** The [CSRF middleware](/docs/plugins/csrf) treats these
|
||||
methods like `POST`, so they get the same checks.
|
||||
|
||||
## Sending multiple Partials at the same time
|
||||
|
||||
A neat aspect of partials in Fresh is that a response can return as many
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@paulaboks/sweet",
|
||||
"version": "2.3.3",
|
||||
"version": "2.3.5",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": "./src/mod.ts",
|
||||
@@ -27,7 +27,7 @@
|
||||
"@std/uuid": "jsr:@std/uuid@^1.0.9",
|
||||
"@types/node": "npm:@types/node@^24.2.1",
|
||||
"esbuild-wasm": "npm:esbuild-wasm@^0.25.11",
|
||||
"preact": "npm:preact@^10.29.1",
|
||||
"preact": "npm:preact@^10.29.8",
|
||||
"preact-render-to-string": "npm:preact-render-to-string@^6.6.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,14 +262,17 @@ document.addEventListener("submit", async (e) => {
|
||||
return;
|
||||
}
|
||||
|
||||
const lowerMethod =
|
||||
e.submitter?.getAttribute("formmethod")?.toLowerCase() ??
|
||||
el.method.toLowerCase();
|
||||
if (lowerMethod !== "get" && lowerMethod !== "post") {
|
||||
const method = e.submitter?.getAttribute("formmethod")?.toLowerCase() ||
|
||||
el.getAttribute("method")?.toLowerCase() || "get";
|
||||
|
||||
if (method === "dialog") {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasExplicitPartial = e.submitter?.hasAttribute(PARTIAL_ATTR) ||
|
||||
const isCustomMethod = method !== "get" && method !== "post";
|
||||
|
||||
const hasExplicitPartial = isCustomMethod ||
|
||||
e.submitter?.hasAttribute(PARTIAL_ATTR) ||
|
||||
e.submitter?.hasAttribute("formaction") ||
|
||||
el.hasAttribute(PARTIAL_ATTR) ||
|
||||
el.hasAttribute("action");
|
||||
@@ -300,13 +303,16 @@ document.addEventListener("submit", async (e) => {
|
||||
let init: RequestInit | undefined;
|
||||
|
||||
// GET method appends form data via url search params
|
||||
if (lowerMethod === "get") {
|
||||
if (method === "get") {
|
||||
// TODO: Looks like constructor type for URLSearchParam is wrong
|
||||
// deno-lint-ignore no-explicit-any
|
||||
const qs = new URLSearchParams(new FormData(el, e.submitter) as any);
|
||||
qs.forEach((value, key) => partialUrl.searchParams.append(key, value));
|
||||
} else {
|
||||
init = { body: new FormData(el, e.submitter), method: lowerMethod };
|
||||
init = {
|
||||
body: new FormData(el, e.submitter),
|
||||
method: method?.toUpperCase(),
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { App, staticFiles } from "sweet";
|
||||
import { App, type Context, staticFiles } from "sweet";
|
||||
import { Partial } from "sweet/runtime";
|
||||
import {
|
||||
ALL_ISLAND_DIR,
|
||||
@@ -1955,6 +1955,201 @@ Deno.test({
|
||||
},
|
||||
});
|
||||
|
||||
async function renderMethodPartial(ctx: Context<unknown>) {
|
||||
const data = await ctx.req.formData();
|
||||
const name = data.get("name");
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<Partial name="foo">
|
||||
<p class={`done-${ctx.req.method}-${name}`}>done</p>
|
||||
</Partial>
|
||||
</Doc>,
|
||||
);
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "partials - submit form with formmethod DELETE, PATCH and PUT",
|
||||
fn: async () => {
|
||||
const app = testApp()
|
||||
.delete("/", renderMethodPartial)
|
||||
.patch("/", renderMethodPartial)
|
||||
.put("/", renderMethodPartial)
|
||||
.get("/", (ctx) => {
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<div f-client-nav>
|
||||
<form>
|
||||
<input name="name" value="foo" />
|
||||
<SelfCounter />
|
||||
<button type="submit" class="delete" formmethod="DELETE">
|
||||
delete
|
||||
</button>
|
||||
<button type="submit" class="patch" formmethod="PATCH">
|
||||
patch
|
||||
</button>
|
||||
<button type="submit" class="put" formmethod="put">
|
||||
put
|
||||
</button>
|
||||
</form>
|
||||
<Partial name="foo">
|
||||
<p class="init">init</p>
|
||||
</Partial>
|
||||
</div>
|
||||
</Doc>,
|
||||
);
|
||||
});
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "load" });
|
||||
await page.locator(".ready").wait();
|
||||
|
||||
await page.locator(".increment").click();
|
||||
await waitForText(page, ".output", "1");
|
||||
|
||||
await page.locator(".delete").click();
|
||||
await page.locator(".done-DELETE-foo").wait();
|
||||
|
||||
await page.locator(".patch").click();
|
||||
await page.locator(".done-PATCH-foo").wait();
|
||||
|
||||
await page.locator(".put").click();
|
||||
await page.locator(".done-PUT-foo").wait();
|
||||
|
||||
// Island state survives, so no full page reload happened
|
||||
await waitForText(page, ".output", "1");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "partials - submit form with custom method on form element",
|
||||
fn: async () => {
|
||||
const app = testApp()
|
||||
.patch("/", renderMethodPartial)
|
||||
.get("/", (ctx) => {
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<div f-client-nav>
|
||||
<form method="patch">
|
||||
<input name="name" value="foo" />
|
||||
<SelfCounter />
|
||||
<Partial name="foo">
|
||||
<p class="init">init</p>
|
||||
</Partial>
|
||||
<button type="submit" class="update">update</button>
|
||||
</form>
|
||||
</div>
|
||||
</Doc>,
|
||||
);
|
||||
});
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "load" });
|
||||
await page.locator(".ready").wait();
|
||||
|
||||
await page.locator(".increment").click();
|
||||
await waitForText(page, ".output", "1");
|
||||
|
||||
await page.locator(".update").click();
|
||||
await page.locator(".done-PATCH-foo").wait();
|
||||
await waitForText(page, ".output", "1");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "partials - form without method inside f-client-nav not intercepted",
|
||||
fn: async () => {
|
||||
const app = testApp()
|
||||
.get("/", (ctx) => {
|
||||
if (ctx.url.searchParams.has("name")) {
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<p class="submitted">form submitted normally</p>
|
||||
</Doc>,
|
||||
);
|
||||
}
|
||||
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<div f-client-nav>
|
||||
<form>
|
||||
<input name="name" value="foo" />
|
||||
<Partial name="foo">
|
||||
<p class="init">init</p>
|
||||
</Partial>
|
||||
<button type="submit" class="update">update</button>
|
||||
</form>
|
||||
</div>
|
||||
</Doc>,
|
||||
);
|
||||
});
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "load" });
|
||||
await page.locator(".init").wait();
|
||||
|
||||
await Promise.all([
|
||||
page.waitForNavigation(),
|
||||
page.locator(".update").click(),
|
||||
]);
|
||||
await page.locator(".submitted").wait();
|
||||
|
||||
const search = await page.evaluate(() => window.location.search);
|
||||
expect(search).toEqual("?name=foo");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "partials - submit form DELETE with 303 redirect",
|
||||
fn: async () => {
|
||||
const app = testApp()
|
||||
.get("/done", (ctx) => {
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<Partial name="foo">
|
||||
<h1 class="done">deleted</h1>
|
||||
</Partial>
|
||||
</Doc>,
|
||||
);
|
||||
})
|
||||
.delete("/", () => {
|
||||
return new Response(null, {
|
||||
status: 303,
|
||||
headers: { Location: "/done" },
|
||||
});
|
||||
})
|
||||
.get("/", (ctx) => {
|
||||
return ctx.render(
|
||||
<Doc>
|
||||
<div f-client-nav>
|
||||
<form>
|
||||
<Partial name="foo">
|
||||
<p class="init">init</p>
|
||||
</Partial>
|
||||
<button type="submit" class="update" formmethod="DELETE">
|
||||
delete
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</Doc>,
|
||||
);
|
||||
});
|
||||
|
||||
await withBrowserApp(app, async (page, address) => {
|
||||
await page.goto(address, { waitUntil: "load" });
|
||||
await page.locator(".init").wait();
|
||||
|
||||
await page.locator(".update").click();
|
||||
await page.locator(".done").wait();
|
||||
|
||||
const pathname = await page.evaluate(() => window.location.pathname);
|
||||
expect(pathname).toEqual("/done");
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "partials - submit form via external submitter",
|
||||
fn: async () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@paulaboks/sweet-init",
|
||||
"version": "2.3.3",
|
||||
"version": "2.3.5",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": "./src/mod.ts",
|
||||
|
||||
@@ -5,11 +5,11 @@ import * as semver from "@std/semver";
|
||||
import initConfig from "../deno.json" with { type: "json" };
|
||||
|
||||
// Keep these as is, as we replace these version in our release script
|
||||
const FRESH_VERSION = "2.3.3";
|
||||
const FRESH_VERSION = "2.3.5";
|
||||
const FRESH_TAILWIND_VERSION = "1.0.0";
|
||||
const FRESH_VITE_PLUGIN = "1.1.2";
|
||||
const PREACT_VERSION = "10.29.1";
|
||||
const PREACT_SIGNALS_VERSION = "2.9.0";
|
||||
const PREACT_VERSION = "10.29.8";
|
||||
const PREACT_SIGNALS_VERSION = "2.11.4";
|
||||
const TAILWINDCSS_VERSION = "4.1.10";
|
||||
const TAILWINDCSS_POSTCSS_VERSION = "4.1.10";
|
||||
const POSTCSS_VERSION = "8.5.6";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@fresh/update",
|
||||
"version": "2.3.3",
|
||||
"version": "2.3.5",
|
||||
"license": "MIT",
|
||||
"exports": "./src/mod.ts",
|
||||
"exclude": ["**/tmp/*"],
|
||||
|
||||
@@ -7,9 +7,9 @@ import { walk } from "@std/fs/walk";
|
||||
|
||||
export const SyntaxKind = tsmorph.ts.SyntaxKind;
|
||||
|
||||
export const FRESH_VERSION = "2.3.3";
|
||||
export const PREACT_VERSION = "10.29.1";
|
||||
export const PREACT_SIGNALS_VERSION = "2.9.0";
|
||||
export const FRESH_VERSION = "2.3.5";
|
||||
export const PREACT_VERSION = "10.29.8";
|
||||
export const PREACT_SIGNALS_VERSION = "2.11.4";
|
||||
|
||||
// Directories to skip when walking the project tree. Covers hidden directories,
|
||||
// dependency caches, and common build output folders.
|
||||
|
||||
+18
-3
@@ -104,7 +104,11 @@ function replaceJsonVersion(version: string) {
|
||||
await replaceInFile(denoJsonPath, replaceJsonVersion(nextVersion));
|
||||
await replaceInFile(updateJsonPath, replaceJsonVersion(nextVersion));
|
||||
|
||||
async function getNpmVersion(name: string) {
|
||||
/** Sweet stays on Preact 10; don't follow npm's `latest` to a new major. */
|
||||
const PREACT_MAJOR = 10;
|
||||
|
||||
/** Latest stable version on npm, optionally limited to one major version. */
|
||||
async function getNpmVersion(name: string, major?: number): Promise<string> {
|
||||
const res = await fetch(`https://registry.npmjs.org/${name}`, {
|
||||
headers: {
|
||||
"Accept":
|
||||
@@ -112,11 +116,22 @@ async function getNpmVersion(name: string) {
|
||||
},
|
||||
});
|
||||
const json = await res.json();
|
||||
return json["dist-tags"].latest;
|
||||
if (major === undefined) return json["dist-tags"].latest;
|
||||
|
||||
const versions = Object.keys(json.versions)
|
||||
.map((v) => semver.tryParse(v))
|
||||
.filter((v): v is semver.SemVer =>
|
||||
v !== undefined && v.major === major && !v.prerelease?.length
|
||||
)
|
||||
.sort(semver.compare);
|
||||
if (versions.length === 0) {
|
||||
exitError(`No ${major}.x release of ${name} found on npm`);
|
||||
}
|
||||
return semver.format(versions.at(-1)!);
|
||||
}
|
||||
|
||||
const [preactVersion, preactSignalsVersion] = await Promise.all([
|
||||
getNpmVersion("preact"),
|
||||
getNpmVersion("preact", PREACT_MAJOR),
|
||||
getNpmVersion("@preact/signals"),
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user