From 8921292872d95336a194f023465600110c47dae8 Mon Sep 17 00:00:00 2001 From: Sam Cook Date: Mon, 23 Oct 2023 20:14:09 -0500 Subject: [PATCH] fix router bug, rmv types --- .changeset/early-readers-rule.md | 8 - .changeset/famous-adults-push.md | 12 - .changeset/large-worms-sparkle.md | 8 - .changeset/light-carpets-cough.md | 8 - .changeset/neat-moles-brush.md | 8 - .changeset/poor-phones-lie.md | 8 - .changeset/pre.json | 21 -- .changeset/rude-kiwis-approve.md | 8 - docs/tsconfig.json | 3 +- .../router/get-matching-path-data-internal.ts | 23 +- packages/create-hwy/src/get-tsconfig.ts | 13 +- packages/dev/index.ts | 260 ------------------ testers/cf-pages/src/pages/_index.client.ts | 4 +- testers/cf-pages/src/pages/_index.page.tsx | 4 +- testers/cf-pages/tsconfig.json | 2 +- testers/routes/hwy.config.ts | 8 + testers/routes/src/components/sidebar.tsx | 5 + .../routes/src/pages/articles/_index.page.tsx | 3 + .../articles/test/articles/_index.page.tsx | 3 + testers/routes/tsconfig.json | 3 +- 20 files changed, 51 insertions(+), 361 deletions(-) delete mode 100644 .changeset/early-readers-rule.md delete mode 100644 .changeset/famous-adults-push.md delete mode 100644 .changeset/large-worms-sparkle.md delete mode 100644 .changeset/light-carpets-cough.md delete mode 100644 .changeset/neat-moles-brush.md delete mode 100644 .changeset/poor-phones-lie.md delete mode 100644 .changeset/pre.json delete mode 100644 .changeset/rude-kiwis-approve.md create mode 100644 testers/routes/hwy.config.ts create mode 100644 testers/routes/src/pages/articles/_index.page.tsx create mode 100644 testers/routes/src/pages/articles/test/articles/_index.page.tsx diff --git a/.changeset/early-readers-rule.md b/.changeset/early-readers-rule.md deleted file mode 100644 index ee2cea9d..00000000 --- a/.changeset/early-readers-rule.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -Using typescript built-ins instead of Preact types, and added some type munging and fixes to match Hwy's use cases diff --git a/.changeset/famous-adults-push.md b/.changeset/famous-adults-push.md deleted file mode 100644 index bb419783..00000000 --- a/.changeset/famous-adults-push.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -1. Update all dependencies. - -2. Add `JSX.IntrinsicElements` types for better type safety when drafting JSX using standard HTML elements and attributes. This is done through `@hwy-js/dev` and requires Hwy projects to have `@hwy-js/dev` in the types array of their `tsconfig.json` files in order to use these intrisic element types. - -3. Update `create-hwy` to use the new `@hwy-js/dev` types in the `tsconfig.json` of generated projects. diff --git a/.changeset/large-worms-sparkle.md b/.changeset/large-worms-sparkle.md deleted file mode 100644 index 92effbd7..00000000 --- a/.changeset/large-worms-sparkle.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -clean up types diff --git a/.changeset/light-carpets-cough.md b/.changeset/light-carpets-cough.md deleted file mode 100644 index e0abcd53..00000000 --- a/.changeset/light-carpets-cough.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -update types diff --git a/.changeset/neat-moles-brush.md b/.changeset/neat-moles-brush.md deleted file mode 100644 index a7c44337..00000000 --- a/.changeset/neat-moles-brush.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -Update types diff --git a/.changeset/poor-phones-lie.md b/.changeset/poor-phones-lie.md deleted file mode 100644 index 4db09864..00000000 --- a/.changeset/poor-phones-lie.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -Add style types diff --git a/.changeset/pre.json b/.changeset/pre.json deleted file mode 100644 index 248515c0..00000000 --- a/.changeset/pre.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "mode": "pre", - "tag": "beta", - "initialVersions": { - "@hwy-js/build": "0.4.2-beta.0", - "hwy": "0.4.2-beta.0", - "create-hwy": "0.4.2-beta.0", - "@hwy-js/dev": "0.4.2-beta.0", - "cf-pages-tester": "0.0.0", - "tester": "0.0.0" - }, - "changesets": [ - "early-readers-rule", - "famous-adults-push", - "large-worms-sparkle", - "light-carpets-cough", - "neat-moles-brush", - "poor-phones-lie", - "rude-kiwis-approve" - ] -} diff --git a/.changeset/rude-kiwis-approve.md b/.changeset/rude-kiwis-approve.md deleted file mode 100644 index 16fa815f..00000000 --- a/.changeset/rude-kiwis-approve.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -"create-hwy": patch -"@hwy-js/build": patch -"hwy": patch -"@hwy-js/dev": patch ---- - -Update JSX types diff --git a/docs/tsconfig.json b/docs/tsconfig.json index 8b73bb7e..b5973c66 100644 --- a/docs/tsconfig.json +++ b/docs/tsconfig.json @@ -9,8 +9,7 @@ "skipLibCheck": true, "esModuleInterop": true, "jsx": "react-jsx", - "jsxImportSource": "hono/jsx", - "types": ["@hwy-js/dev"] + "jsxImportSource": "hono/jsx" }, "exclude": ["node_modules", "dist"] } diff --git a/packages/core/src/router/get-matching-path-data-internal.ts b/packages/core/src/router/get-matching-path-data-internal.ts index e3aecc5d..db511f4f 100644 --- a/packages/core/src/router/get-matching-path-data-internal.ts +++ b/packages/core/src/router/get-matching-path-data-internal.ts @@ -13,7 +13,28 @@ function get_matching_paths_internal(__paths: Array) { : x.realSegmentsLength; // make sure any remaining matches are not longer than the path itself - return x.segments.length <= index_adjusted_real_segments_length; + const should_move_on = + x.segments.length <= index_adjusted_real_segments_length; + + if (!should_move_on) { + return false; + } + + // now we need to remove ineligible indices + if (!x.isIndex) { + // if not an index, then you're already confirmed good + return true; + } + + const truthy_segments_length = x.segments.filter((x) => x.segment).length; + + const path_segments_length = x.path.split("/").filter(Boolean).length; + + if (truthy_segments_length === path_segments_length) { + return true; + } + + return false; }); // if there are multiple matches, filter out the ultimate catch-all diff --git a/packages/create-hwy/src/get-tsconfig.ts b/packages/create-hwy/src/get-tsconfig.ts index 18b137ae..3e468484 100644 --- a/packages/create-hwy/src/get-tsconfig.ts +++ b/packages/create-hwy/src/get-tsconfig.ts @@ -13,7 +13,6 @@ const ts_config = { esModuleInterop: true, jsx: "react-jsx", jsxImportSource: "hono/jsx", - types: ["@hwy-js/dev"], }, exclude: ["node_modules", "dist"], }; @@ -22,7 +21,6 @@ const js_config = { compilerOptions: { jsx: "react-jsx", jsxImportSource: "hono/jsx", - types: ["@hwy-js/dev"], }, }; @@ -30,7 +28,6 @@ const deno_config = { compilerOptions: { jsx: "react-jsx", jsxImportSource: "npm:hono/jsx", - types: ["@hwy-js/dev"], }, }; @@ -48,21 +45,17 @@ function get_ts_config(options: Options) { options.deployment_target === "vercel-lambda" ) { // @ts-ignore - ts_config.compilerOptions.types = ["@hwy-js/dev", "node"]; + ts_config.compilerOptions.types = ["node"]; } if (options.deployment_target === "bun") { // @ts-ignore - ts_config.compilerOptions.types = ["@hwy-js/dev", "bun-types"]; + ts_config.compilerOptions.types = ["bun-types"]; } if (options.deployment_target === "cloudflare-pages") { // @ts-ignore - ts_config.compilerOptions.types = [ - "@hwy-js/dev", - "@cloudflare/workers-types", - "node", - ]; + ts_config.compilerOptions.types = ["@cloudflare/workers-types", "node"]; } return JSON.stringify(ts_config).trim() + "\n"; diff --git a/packages/dev/index.ts b/packages/dev/index.ts index 2dd8e140..92c82a37 100644 --- a/packages/dev/index.ts +++ b/packages/dev/index.ts @@ -1,261 +1 @@ -import type { HtmlEscapedString } from "hono/utils/html"; - -type BooleanLike = boolean | `${boolean}`; -type NumberLike = number | `${number}`; - -type BooleanToBooleanLike = T extends boolean ? BooleanLike : T; -type NumberToNumberLike = T extends number ? NumberLike : T; - -type StripNever = { - [K in keyof T as T[K] extends never ? never : K]: T[K]; -}; - -type FunctionToStringOrStrip< - T extends { - [key: string]: any; - }, -> = StripNever<{ - [K in keyof T]: K extends `on${string}` - ? T[K] extends ((...args: any[]) => any) | null - ? string - : T[K] - : T[K] extends ((...args: any[]) => any) | null - ? never - : T[K]; -}>; - -type HandleConversions = BooleanToBooleanLike>; - -type Child = string | number | boolean | null | undefined | HtmlEscapedString; - -type AdditionalAttributes = { - children: Child | Child[]; - class: string; - dangerouslySetInnerHTML: { - __html: string; - }; - style: Partial; -}; - -type HTMLAttributesOuter = Partial< - AdditionalAttributes & - Omit< - { - [K in keyof E]: HandleConversions; - }, - keyof AdditionalAttributes - > ->; - -type HTMLAttributes< - E extends { - [key: string]: any; - }, -> = HTMLAttributesOuter>>; - -/* -BEGIN ADAPTED YUDAI-NKT CODE -Adapted from: https://github.com/yudai-nkt/hono-jsx-types/blob/main/index.d.ts -Original license: MIT -Copied from source on: October 22, 2023 -*/ - -interface CustomIntrinsicElements { - a: HTMLAttributes; - abbr: HTMLAttributes; - address: HTMLAttributes; - area: HTMLAttributes; - article: HTMLAttributes; - aside: HTMLAttributes; - audio: HTMLAttributes; - b: HTMLAttributes; - base: HTMLAttributes; - bdi: HTMLAttributes; - bdo: HTMLAttributes; - big: HTMLAttributes; - blockquote: HTMLAttributes; - body: HTMLAttributes; - br: HTMLAttributes; - button: HTMLAttributes; - canvas: HTMLAttributes; - caption: HTMLAttributes; - cite: HTMLAttributes; - code: HTMLAttributes; - col: HTMLAttributes; - colgroup: HTMLAttributes; - data: HTMLAttributes; - datalist: HTMLAttributes; - dd: HTMLAttributes; - del: HTMLAttributes; - details: HTMLAttributes; - dfn: HTMLAttributes; - dialog: HTMLAttributes; - div: HTMLAttributes; - dl: HTMLAttributes; - dt: HTMLAttributes; - em: HTMLAttributes; - embed: HTMLAttributes; - fieldset: HTMLAttributes; - figcaption: HTMLAttributes; - figure: HTMLAttributes; - footer: HTMLAttributes; - form: HTMLAttributes; - h1: HTMLAttributes; - h2: HTMLAttributes; - h3: HTMLAttributes; - h4: HTMLAttributes; - h5: HTMLAttributes; - h6: HTMLAttributes; - head: HTMLAttributes; - header: HTMLAttributes; - hgroup: HTMLAttributes; - hr: HTMLAttributes; - html: HTMLAttributes; - i: HTMLAttributes; - iframe: HTMLAttributes; - img: HTMLAttributes; - input: HTMLAttributes; - ins: HTMLAttributes; - kbd: HTMLAttributes; - keygen: HTMLAttributes; - label: HTMLAttributes; - legend: HTMLAttributes; - li: HTMLAttributes; - link: HTMLAttributes; - main: HTMLAttributes; - map: HTMLAttributes; - mark: HTMLAttributes; - /** - * @deprecated - */ - marquee: HTMLAttributes; - menu: HTMLAttributes; - menuitem: HTMLAttributes; - meta: HTMLAttributes | { charset: string }; - meter: HTMLAttributes; - nav: HTMLAttributes; - noscript: HTMLAttributes; - object: HTMLAttributes; - ol: HTMLAttributes; - optgroup: HTMLAttributes; - option: HTMLAttributes; - output: HTMLAttributes; - p: HTMLAttributes; - /** - * @deprecated - */ - param: HTMLAttributes; - picture: HTMLAttributes; - pre: HTMLAttributes; - progress: HTMLAttributes; - q: HTMLAttributes; - rp: HTMLAttributes; - rt: HTMLAttributes; - ruby: HTMLAttributes; - s: HTMLAttributes; - samp: HTMLAttributes; - script: HTMLAttributes; - section: HTMLAttributes; - select: HTMLAttributes; - slot: HTMLAttributes; - small: HTMLAttributes; - source: HTMLAttributes; - span: HTMLAttributes; - strong: HTMLAttributes; - style: HTMLAttributes; - sub: HTMLAttributes; - summary: HTMLAttributes; - sup: HTMLAttributes; - table: HTMLAttributes; - tbody: HTMLAttributes; - td: HTMLAttributes; - textarea: HTMLAttributes; - tfoot: HTMLAttributes; - th: HTMLAttributes; - thead: HTMLAttributes; - time: HTMLAttributes; - title: HTMLAttributes; - tr: HTMLAttributes; - track: HTMLAttributes; - u: HTMLAttributes; - ul: HTMLAttributes; - var: HTMLAttributes; - video: HTMLAttributes; - wbr: HTMLAttributes; - - //SVG - svg: Partial; - animate: Partial; - circle: Partial; - animateMotion: Partial; - animateTransform: Partial; - clipPath: Partial; - defs: Partial; - desc: Partial; - ellipse: Partial; - feBlend: Partial; - feColorMatrix: Partial; - feComponentTransfer: Partial; - feComposite: Partial; - feConvolveMatrix: Partial; - feDiffuseLighting: Partial; - feDisplacementMap: Partial; - feDistantLight: Partial; - feDropShadow: Partial; - feFlood: Partial; - feFuncA: Partial; - feFuncB: Partial; - feFuncG: Partial; - feFuncR: Partial; - feGaussianBlur: Partial; - feImage: Partial; - feMerge: Partial; - feMergeNode: Partial; - feMorphology: Partial; - feOffset: Partial; - fePointLight: Partial; - feSpecularLighting: Partial; - feSpotLight: Partial; - feTile: Partial; - feTurbulence: Partial; - filter: Partial; - foreignObject: Partial; - g: Partial; - image: Partial; - line: Partial; - linearGradient: Partial; - marker: Partial; - mask: Partial; - metadata: Partial; - mpath: Partial; - path: Partial; - pattern: Partial; - polygon: Partial; - polyline: Partial; - radialGradient: Partial; - rect: Partial; - set: Partial; - stop: Partial; - switch: Partial; - symbol: Partial; - text: Partial; - textPath: Partial; - tspan: Partial; - use: Partial; - view: Partial; -} - -/* -END ADAPTED YUDAI-NKT CODE -*/ - -declare global { - namespace JSX { - interface IntrinsicElements extends CustomIntrinsicElements {} - } -} - -/* -HWY EXPORTS -*/ export { setupLiveRefreshEndpoints } from "./src/dev-init.js"; diff --git a/testers/cf-pages/src/pages/_index.client.ts b/testers/cf-pages/src/pages/_index.client.ts index 6a1d9486..19099d0f 100644 --- a/testers/cf-pages/src/pages/_index.client.ts +++ b/testers/cf-pages/src/pages/_index.client.ts @@ -11,4 +11,6 @@ function increment() { } } -const bob = "hi1"; +if (el) { + el.addEventListener("click", increment); +} diff --git a/testers/cf-pages/src/pages/_index.page.tsx b/testers/cf-pages/src/pages/_index.page.tsx index 3384e543..fb532ce0 100644 --- a/testers/cf-pages/src/pages/_index.page.tsx +++ b/testers/cf-pages/src/pages/_index.page.tsx @@ -1,8 +1,6 @@ export default function () { return ( // Number will increment when you click - + ); } diff --git a/testers/cf-pages/tsconfig.json b/testers/cf-pages/tsconfig.json index a0205b86..35618a42 100644 --- a/testers/cf-pages/tsconfig.json +++ b/testers/cf-pages/tsconfig.json @@ -10,7 +10,7 @@ "esModuleInterop": true, "jsx": "react-jsx", "jsxImportSource": "hono/jsx", - "types": ["@hwy-js/dev", "@cloudflare/workers-types", "node"] + "types": ["@cloudflare/workers-types", "node"] }, "exclude": ["node_modules", "dist"] } diff --git a/testers/routes/hwy.config.ts b/testers/routes/hwy.config.ts new file mode 100644 index 00000000..327c2ed1 --- /dev/null +++ b/testers/routes/hwy.config.ts @@ -0,0 +1,8 @@ +import type { HwyConfig } from "@hwy-js/build"; + +export default { + dev: { + port: 9872, + }, + deploymentTarget: "node", +} satisfies HwyConfig; diff --git a/testers/routes/src/components/sidebar.tsx b/testers/routes/src/components/sidebar.tsx index 825372d3..e5fa1a94 100644 --- a/testers/routes/src/components/sidebar.tsx +++ b/testers/routes/src/components/sidebar.tsx @@ -23,6 +23,11 @@ function Sidebar() { + ------------- + + + + ); } diff --git a/testers/routes/src/pages/articles/_index.page.tsx b/testers/routes/src/pages/articles/_index.page.tsx new file mode 100644 index 00000000..28ded82c --- /dev/null +++ b/testers/routes/src/pages/articles/_index.page.tsx @@ -0,0 +1,3 @@ +import { TesterComp } from "~/src/components/tester-comp.js"; + +export default TesterComp; diff --git a/testers/routes/src/pages/articles/test/articles/_index.page.tsx b/testers/routes/src/pages/articles/test/articles/_index.page.tsx new file mode 100644 index 00000000..28ded82c --- /dev/null +++ b/testers/routes/src/pages/articles/test/articles/_index.page.tsx @@ -0,0 +1,3 @@ +import { TesterComp } from "~/src/components/tester-comp.js"; + +export default TesterComp; diff --git a/testers/routes/tsconfig.json b/testers/routes/tsconfig.json index f2c073cf..22b3a71d 100644 --- a/testers/routes/tsconfig.json +++ b/testers/routes/tsconfig.json @@ -12,8 +12,7 @@ "jsxImportSource": "hono/jsx", "paths": { "~/*": ["./*"] - }, - "types": ["@hwy-js/dev"] + } }, "exclude": ["node_modules", "dist"] }