create-waku 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +118 -7731
  4. package/package.json +5 -6
  5. package/src/cli.ts +3 -7
  6. package/template/01_counter/dist/components/App.js +6 -0
  7. package/template/01_counter/dist/components/Counter.js +7 -0
  8. package/template/01_counter/dist/entries.js +31 -0
  9. package/template/01_counter/dist/main.js +6 -0
  10. package/template/01_counter/node_modules/.bin/tsc +2 -2
  11. package/template/01_counter/node_modules/.bin/tsserver +2 -2
  12. package/template/01_counter/node_modules/.bin/waku +2 -2
  13. package/template/01_counter/package.json +6 -6
  14. package/template/01_counter/src/entries.tsx +2 -2
  15. package/template/01_counter/tsconfig.json +3 -1
  16. package/template/02_async/dist/.tsbuildinfo +1 -0
  17. package/template/02_async/dist/node/.tsbuildinfo +1 -0
  18. package/template/02_async/dist/node/vite.config.d.ts +2 -0
  19. package/template/02_async/dist/node/vite.config.js +14 -0
  20. package/template/02_async/dist/src/components/App.d.ts +4 -0
  21. package/template/02_async/dist/src/components/App.js +16 -0
  22. package/template/02_async/dist/src/components/Counter.d.ts +1 -0
  23. package/template/02_async/dist/src/components/Counter.js +7 -0
  24. package/template/02_async/dist/src/entries.d.ts +6 -0
  25. package/template/02_async/dist/src/entries.js +31 -0
  26. package/template/02_async/dist/src/main.d.ts +1 -0
  27. package/template/02_async/dist/src/main.js +15 -0
  28. package/template/02_async/node_modules/.bin/tsc +2 -2
  29. package/template/02_async/node_modules/.bin/tsserver +2 -2
  30. package/template/02_async/node_modules/.bin/waku +2 -2
  31. package/template/02_async/package.json +6 -6
  32. package/template/02_async/src/components/App.tsx +2 -0
  33. package/template/02_async/src/entries.tsx +2 -2
  34. package/template/02_async/tsconfig.json +11 -2
  35. package/template/02_async/tsconfig.node.json +9 -0
  36. package/template/03_promise/dist/components/App.js +9 -0
  37. package/template/03_promise/dist/components/Counter.js +8 -0
  38. package/template/03_promise/dist/entries.js +32 -0
  39. package/template/03_promise/dist/main.js +6 -0
  40. package/template/03_promise/node_modules/.bin/tsc +2 -2
  41. package/template/03_promise/node_modules/.bin/tsserver +2 -2
  42. package/template/03_promise/node_modules/.bin/waku +2 -2
  43. package/template/03_promise/package.json +6 -6
  44. package/template/03_promise/src/entries.tsx +2 -2
  45. package/template/03_promise/tsconfig.json +3 -1
  46. package/template/04_callserver/dist/components/App.js +7 -0
  47. package/template/04_callserver/dist/components/Counter.js +14 -0
  48. package/template/04_callserver/dist/components/funcs.js +2 -0
  49. package/template/04_callserver/dist/entries.js +31 -0
  50. package/template/04_callserver/dist/main.js +6 -0
  51. package/template/04_callserver/node_modules/.bin/tsc +2 -2
  52. package/template/04_callserver/node_modules/.bin/tsserver +2 -2
  53. package/template/04_callserver/node_modules/.bin/waku +2 -2
  54. package/template/04_callserver/package.json +6 -6
  55. package/template/04_callserver/src/entries.tsx +2 -2
  56. package/template/04_callserver/tsconfig.json +3 -1
  57. package/template/05_mutation/dist/components/App.js +7 -0
  58. package/template/05_mutation/dist/components/Counter.js +13 -0
  59. package/template/05_mutation/dist/components/funcs.js +9 -0
  60. package/template/05_mutation/dist/entries.js +31 -0
  61. package/template/05_mutation/dist/main.js +6 -0
  62. package/template/05_mutation/node_modules/.bin/tsc +2 -2
  63. package/template/05_mutation/node_modules/.bin/tsserver +2 -2
  64. package/template/05_mutation/node_modules/.bin/waku +2 -2
  65. package/template/05_mutation/package.json +6 -6
  66. package/template/05_mutation/src/entries.tsx +2 -2
  67. package/template/05_mutation/tsconfig.json +3 -1
  68. package/template/06_nesting/dist/components/App.js +6 -0
  69. package/template/06_nesting/dist/components/Counter.js +24 -0
  70. package/template/06_nesting/dist/components/InnerApp.js +6 -0
  71. package/template/06_nesting/dist/entries.js +45 -0
  72. package/template/06_nesting/dist/main.js +6 -0
  73. package/template/06_nesting/node_modules/.bin/tsc +2 -2
  74. package/template/06_nesting/node_modules/.bin/tsserver +2 -2
  75. package/template/06_nesting/node_modules/.bin/waku +2 -2
  76. package/template/06_nesting/package.json +6 -6
  77. package/template/06_nesting/src/entries.tsx +2 -2
  78. package/template/06_nesting/tsconfig.json +3 -1
  79. package/template/07_router/dist/.tsbuildinfo +1 -0
  80. package/template/07_router/dist/node/.tsbuildinfo +1 -0
  81. package/template/07_router/dist/node/vite.config.d.ts +2 -0
  82. package/template/07_router/dist/node/vite.config.js +16 -0
  83. package/template/07_router/dist/src/components/Counter.d.ts +1 -0
  84. package/template/07_router/dist/src/components/Counter.js +8 -0
  85. package/template/07_router/dist/src/components/ErrorBoundary.d.ts +7 -0
  86. package/template/07_router/dist/src/components/ErrorBoundary.js +17 -0
  87. package/template/07_router/dist/src/entries.d.ts +6 -0
  88. package/template/07_router/dist/src/entries.js +29 -0
  89. package/template/07_router/dist/src/main.d.ts +1 -0
  90. package/template/07_router/dist/src/main.js +7 -0
  91. package/template/07_router/dist/src/routes/bar/page.d.ts +2 -0
  92. package/template/07_router/dist/src/routes/bar/page.js +4 -0
  93. package/template/07_router/dist/src/routes/foo/page.d.ts +2 -0
  94. package/template/07_router/dist/src/routes/foo/page.js +4 -0
  95. package/template/07_router/dist/src/routes/layout.d.ts +5 -0
  96. package/template/07_router/dist/src/routes/layout.js +9 -0
  97. package/template/07_router/dist/src/routes/nested/baz/page.d.ts +2 -0
  98. package/template/07_router/dist/src/routes/nested/baz/page.js +3 -0
  99. package/template/07_router/dist/src/routes/nested/layout.d.ts +5 -0
  100. package/template/07_router/dist/src/routes/nested/layout.js +4 -0
  101. package/template/07_router/dist/src/routes/nested/qux/page.d.ts +2 -0
  102. package/template/07_router/dist/src/routes/nested/qux/page.js +3 -0
  103. package/template/07_router/dist/src/routes/page.d.ts +2 -0
  104. package/template/07_router/dist/src/routes/page.js +3 -0
  105. package/template/07_router/node_modules/.bin/glob +4 -4
  106. package/template/07_router/node_modules/.bin/tsc +2 -2
  107. package/template/07_router/node_modules/.bin/tsserver +2 -2
  108. package/template/07_router/node_modules/.bin/waku +2 -2
  109. package/template/07_router/package.json +7 -7
  110. package/template/07_router/src/entries.tsx +1 -1
  111. package/template/07_router/tsconfig.json +11 -2
  112. package/template/07_router/tsconfig.node.json +9 -0
  113. package/template/08_cookies/dev.js +1 -1
  114. package/template/08_cookies/dist/components/App.js +8 -0
  115. package/template/08_cookies/dist/components/Counter.js +7 -0
  116. package/template/08_cookies/dist/entries.js +22 -0
  117. package/template/08_cookies/dist/main.js +6 -0
  118. package/template/08_cookies/node_modules/.bin/tsc +2 -2
  119. package/template/08_cookies/node_modules/.bin/tsserver +2 -2
  120. package/template/08_cookies/node_modules/.bin/waku +2 -2
  121. package/template/08_cookies/package.json +6 -6
  122. package/template/08_cookies/src/entries.tsx +2 -2
  123. package/template/08_cookies/tsconfig.json +3 -1
  124. package/template/09_cssmodules/dist/components/App.js +8 -0
  125. package/template/09_cssmodules/dist/components/Counter.js +7 -0
  126. package/template/09_cssmodules/dist/entries.js +31 -0
  127. package/template/09_cssmodules/dist/main.js +6 -0
  128. package/template/09_cssmodules/node_modules/.bin/tsc +2 -2
  129. package/template/09_cssmodules/node_modules/.bin/tsserver +2 -2
  130. package/template/09_cssmodules/node_modules/.bin/waku +2 -2
  131. package/template/09_cssmodules/package.json +6 -6
  132. package/template/09_cssmodules/src/entries.tsx +2 -2
  133. package/template/09_cssmodules/tsconfig.json +3 -1
  134. package/template/10_dynamicroute/dist/.tsbuildinfo +1 -0
  135. package/template/10_dynamicroute/dist/node/.tsbuildinfo +1 -0
  136. package/template/10_dynamicroute/dist/node/vite.config.d.ts +2 -0
  137. package/template/10_dynamicroute/dist/node/vite.config.js +16 -0
  138. package/template/10_dynamicroute/dist/src/entries.d.ts +6 -0
  139. package/template/10_dynamicroute/dist/src/entries.js +61 -0
  140. package/template/10_dynamicroute/dist/src/main.d.ts +1 -0
  141. package/template/10_dynamicroute/dist/src/main.js +6 -0
  142. package/template/10_dynamicroute/dist/src/routes/[name]/page.d.ts +4 -0
  143. package/template/10_dynamicroute/dist/src/routes/[name]/page.js +3 -0
  144. package/template/10_dynamicroute/dist/src/routes/layout.d.ts +5 -0
  145. package/template/10_dynamicroute/dist/src/routes/layout.js +4 -0
  146. package/template/10_dynamicroute/dist/src/routes/page.d.ts +2 -0
  147. package/template/10_dynamicroute/dist/src/routes/page.js +3 -0
  148. package/template/10_dynamicroute/node_modules/.bin/glob +17 -0
  149. package/template/10_dynamicroute/node_modules/.bin/tsc +17 -0
  150. package/template/10_dynamicroute/node_modules/.bin/tsserver +17 -0
  151. package/template/10_dynamicroute/node_modules/.bin/waku +17 -0
  152. package/template/10_dynamicroute/package.json +24 -0
  153. package/template/10_dynamicroute/src/entries.tsx +75 -0
  154. package/template/10_dynamicroute/src/index.html +36 -0
  155. package/template/10_dynamicroute/src/main.tsx +11 -0
  156. package/template/10_dynamicroute/src/routes/[name]/page.tsx +7 -0
  157. package/template/10_dynamicroute/src/routes/layout.tsx +25 -0
  158. package/template/10_dynamicroute/src/routes/page.tsx +7 -0
  159. package/template/10_dynamicroute/tsconfig.json +22 -0
  160. package/template/10_dynamicroute/tsconfig.node.json +9 -0
  161. package/template/10_dynamicroute/vite.config.ts +22 -0
  162. package/template/11_form/dist/components/App.js +8 -0
  163. package/template/11_form/dist/components/Counter.js +13 -0
  164. package/template/11_form/dist/components/Form.js +10 -0
  165. package/template/11_form/dist/components/funcs.js +10 -0
  166. package/template/11_form/dist/entries.js +31 -0
  167. package/template/11_form/dist/main.js +6 -0
  168. package/template/11_form/node_modules/.bin/tsc +17 -0
  169. package/template/11_form/node_modules/.bin/tsserver +17 -0
  170. package/template/11_form/node_modules/.bin/waku +17 -0
  171. package/template/11_form/package.json +23 -0
  172. package/template/11_form/src/components/App.tsx +25 -0
  173. package/template/11_form/src/components/Counter.tsx +29 -0
  174. package/template/11_form/src/components/Form.tsx +35 -0
  175. package/template/11_form/src/components/funcs.ts +15 -0
  176. package/template/11_form/src/entries.tsx +34 -0
  177. package/template/11_form/src/index.html +36 -0
  178. package/template/11_form/src/main.tsx +13 -0
  179. package/template/11_form/tsconfig.json +15 -0
@@ -0,0 +1,16 @@
1
+ import url from "node:url";
2
+ import path from "node:path";
3
+ import { defineConfig } from "waku/config";
4
+ const modulesRoot = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "src");
5
+ export default defineConfig({
6
+ build: {
7
+ rollupOptions: {
8
+ output: {
9
+ // FIXME this doesn't seem to provide nice output.
10
+ // TODO we should use `input` instead.
11
+ preserveModules: true,
12
+ preserveModulesRoot: modulesRoot,
13
+ },
14
+ },
15
+ },
16
+ });
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ renderEntries: import("waku/server").RenderEntries;
3
+ getBuildConfig: import("waku/server").GetBuildConfig | undefined;
4
+ getSsrConfig: import("waku/server").GetSsrConfig | undefined;
5
+ };
6
+ export default _default;
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import url from "node:url";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ import { lazy } from "react";
6
+ import { glob } from "glob";
7
+ import { defineRouter } from "waku/router/server";
8
+ const routesDir = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "routes");
9
+ const getRoute = (items) => lazy(() => {
10
+ // HACK: replace "_slug_" to "[slug]"
11
+ items = items.map((item) => item.replace(/^_(\w+)_$/, "[$1]"));
12
+ switch (items.length) {
13
+ case 1:
14
+ return import(`./routes/${items[0]}.tsx`);
15
+ case 2:
16
+ return import(`./routes/${items[0]}/${items[1]}.tsx`);
17
+ case 3:
18
+ return import(`./routes/${items[0]}/${items[1]}/${items[2]}.tsx`);
19
+ default:
20
+ throw new Error("too deep route");
21
+ }
22
+ });
23
+ // HACK for vite dev server
24
+ const isReservedId = (id) => id.startsWith("@") || id.startsWith("main.tsx/");
25
+ export default defineRouter(
26
+ // getComponent (id is "**/layout" or "**/page")
27
+ async (id) => {
28
+ if (isReservedId(id)) {
29
+ return null;
30
+ }
31
+ const mapping = {};
32
+ const items = id.split("/");
33
+ for (let i = 0; i < items.length - 1; ++i) {
34
+ const dir = path.join(routesDir, ...items.slice(0, i));
35
+ if (!fs.existsSync(dir)) {
36
+ return null;
37
+ }
38
+ const files = fs.readdirSync(dir);
39
+ if (!files.includes(items[i])) {
40
+ const slug = files.find((file) => file.match(/^(\[\w+\]|_\w+_)$/));
41
+ if (slug) {
42
+ mapping[slug.slice(1, -1)] = items[i];
43
+ items[i] = slug;
44
+ }
45
+ }
46
+ }
47
+ if (!fs.existsSync(path.join(routesDir, ...items) + ".js") &&
48
+ !fs.existsSync(path.join(routesDir, ...items) + ".tsx")) {
49
+ return null;
50
+ }
51
+ const Route = getRoute(items);
52
+ const Component = (props) => (_jsx(Route, { ...props, ...mapping }));
53
+ return Component;
54
+ },
55
+ // getPathsForBuild
56
+ async () => {
57
+ const files = await glob("**/page.{tsx,js}", { cwd: routesDir });
58
+ return files
59
+ .filter((file) => !/(^|\/)(\[\w+\]|_\w+_)\//.test(file))
60
+ .map((file) => "/" + file.slice(0, Math.max(0, file.lastIndexOf("/"))));
61
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { StrictMode } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { Router } from "waku/router/client";
5
+ const rootElement = (_jsx(StrictMode, { children: _jsx(Router, { shouldSkip: () => true }) }));
6
+ createRoot(document.getElementById("root")).render(rootElement);
@@ -0,0 +1,4 @@
1
+ declare const Page: ({ name }: {
2
+ name: string;
3
+ }) => import("react/jsx-runtime").JSX.Element;
4
+ export default Page;
@@ -0,0 +1,3 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const Page = ({ name }) => (_jsx("div", { children: _jsx("h2", { children: name }) }));
3
+ export default Page;
@@ -0,0 +1,5 @@
1
+ import type { ReactNode } from "react";
2
+ declare const HomeLayout: ({ children }: {
3
+ children: ReactNode;
4
+ }) => import("react/jsx-runtime").JSX.Element;
5
+ export default HomeLayout;
@@ -0,0 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Link } from "waku/router/server";
3
+ const HomeLayout = ({ children }) => (_jsxs("div", { children: [_jsxs("ul", { children: [_jsx("li", { children: _jsx(Link, { href: "/", children: "Home" }) }), _jsx("li", { children: _jsx(Link, { href: "/foo", children: "Foo" }) }), _jsx("li", { children: _jsx(Link, { href: "/bar", children: "Bar" }) }), _jsx("li", { children: _jsx(Link, { href: "/baz", children: "Baz" }) })] }), children] }));
4
+ export default HomeLayout;
@@ -0,0 +1,2 @@
1
+ declare const Home: () => import("react/jsx-runtime").JSX.Element;
2
+ export default Home;
@@ -0,0 +1,3 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const Home = () => (_jsx("div", { children: _jsx("h1", { children: "Home" }) }));
3
+ export default Home;
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/esm/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules/glob/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/esm/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules/glob/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/glob@10.3.10/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../glob/dist/esm/bin.mjs" "$@"
15
+ else
16
+ exec node "$basedir/../glob/dist/esm/bin.mjs" "$@"
17
+ fi
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
15
+ else
16
+ exec node "$basedir/../typescript/bin/tsc" "$@"
17
+ fi
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
15
+ else
16
+ exec node "$basedir/../typescript/bin/tsserver" "$@"
17
+ fi
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/packages/waku/dist/node_modules:/home/runner/work/waku/waku/packages/waku/node_modules:/home/runner/work/waku/waku/packages/node_modules:/home/runner/work/waku/waku/node_modules:/home/runner/work/waku/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/packages/waku/dist/node_modules:/home/runner/work/waku/waku/packages/waku/node_modules:/home/runner/work/waku/waku/packages/node_modules:/home/runner/work/waku/waku/node_modules:/home/runner/work/waku/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../waku/dist/cli.js" "$@"
15
+ else
16
+ exec node "$basedir/../waku/dist/cli.js" "$@"
17
+ fi
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "waku-example",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "private": true,
6
+ "scripts": {
7
+ "dev": "waku dev --with-ssr",
8
+ "build": "waku build",
9
+ "start": "waku start --with-ssr"
10
+ },
11
+ "dependencies": {
12
+ "express": "^4.18.2",
13
+ "glob": "^10.3.10",
14
+ "react": "18.3.0-canary-a41957507-20231017",
15
+ "react-dom": "18.3.0-canary-a41957507-20231017",
16
+ "react-server-dom-webpack": "18.3.0-canary-a41957507-20231017",
17
+ "waku": "0.16.0"
18
+ },
19
+ "devDependencies": {
20
+ "@types/react": "^18.2.31",
21
+ "@types/react-dom": "^18.2.14",
22
+ "typescript": "^5.2.2"
23
+ }
24
+ }
@@ -0,0 +1,75 @@
1
+ import url from "node:url";
2
+ import path from "node:path";
3
+ import fs from "node:fs";
4
+
5
+ import { lazy } from "react";
6
+ import { glob } from "glob";
7
+ import { defineRouter } from "waku/router/server";
8
+
9
+ const routesDir = path.join(
10
+ path.dirname(url.fileURLToPath(import.meta.url)),
11
+ "routes",
12
+ );
13
+
14
+ const getRoute = (items: string[]) =>
15
+ lazy(() => {
16
+ // HACK: replace "_slug_" to "[slug]"
17
+ items = items.map((item) => item.replace(/^_(\w+)_$/, "[$1]"));
18
+ switch (items.length) {
19
+ case 1:
20
+ return import(`./routes/${items[0]}.tsx`);
21
+ case 2:
22
+ return import(`./routes/${items[0]}/${items[1]}.tsx`);
23
+ case 3:
24
+ return import(`./routes/${items[0]}/${items[1]}/${items[2]}.tsx`);
25
+ default:
26
+ throw new Error("too deep route");
27
+ }
28
+ });
29
+
30
+ // HACK for vite dev server
31
+ const isReservedId = (id: string) =>
32
+ id.startsWith("@") || id.startsWith("main.tsx/");
33
+
34
+ export default defineRouter(
35
+ // getComponent (id is "**/layout" or "**/page")
36
+ async (id) => {
37
+ if (isReservedId(id)) {
38
+ return null;
39
+ }
40
+ const mapping: Record<string, string> = {};
41
+ const items = id.split("/");
42
+ for (let i = 0; i < items.length - 1; ++i) {
43
+ const dir = path.join(routesDir, ...items.slice(0, i));
44
+ if (!fs.existsSync(dir)) {
45
+ return null;
46
+ }
47
+ const files = fs.readdirSync(dir);
48
+ if (!files.includes(items[i]!)) {
49
+ const slug = files.find((file) => file.match(/^(\[\w+\]|_\w+_)$/));
50
+ if (slug) {
51
+ mapping[slug.slice(1, -1)] = items[i]!;
52
+ items[i] = slug;
53
+ }
54
+ }
55
+ }
56
+ if (
57
+ !fs.existsSync(path.join(routesDir, ...items) + ".js") &&
58
+ !fs.existsSync(path.join(routesDir, ...items) + ".tsx")
59
+ ) {
60
+ return null;
61
+ }
62
+ const Route = getRoute(items);
63
+ const Component = (props: Record<string, unknown>) => (
64
+ <Route {...props} {...mapping} />
65
+ );
66
+ return Component;
67
+ },
68
+ // getPathsForBuild
69
+ async () => {
70
+ const files = await glob("**/page.{tsx,js}", { cwd: routesDir });
71
+ return files
72
+ .filter((file) => !/(^|\/)(\[\w+\]|_\w+_)\//.test(file))
73
+ .map((file) => "/" + file.slice(0, Math.max(0, file.lastIndexOf("/"))));
74
+ },
75
+ );
@@ -0,0 +1,36 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Waku example</title>
6
+ <style>
7
+ @keyframes spinner {
8
+ to {
9
+ transform: rotate(360deg);
10
+ }
11
+ }
12
+ .spinner {
13
+ width: 36px;
14
+ height: 36px;
15
+ margin: auto;
16
+ border: 2px solid #ddd;
17
+ border-top-color: #222;
18
+ border-radius: 50%;
19
+ animation: spinner 1s linear infinite;
20
+ }
21
+ #root > .spinner {
22
+ margin-top: calc(50% - 18px);
23
+ }
24
+ </style>
25
+ </head>
26
+ <body>
27
+ <!--placeholder1-->
28
+ <div id="root">
29
+ <div class="spinner"></div>
30
+ </div>
31
+ <!--/placeholder1-->
32
+ <script src="/main.tsx" async type="module"></script>
33
+ <!--placeholder2-->
34
+ <!--/placeholder2-->
35
+ </body>
36
+ </html>
@@ -0,0 +1,11 @@
1
+ import { StrictMode } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { Router } from "waku/router/client";
4
+
5
+ const rootElement = (
6
+ <StrictMode>
7
+ <Router shouldSkip={() => true} />
8
+ </StrictMode>
9
+ );
10
+
11
+ createRoot(document.getElementById("root")!).render(rootElement);
@@ -0,0 +1,7 @@
1
+ const Page = ({ name }: { name: string }) => (
2
+ <div>
3
+ <h2>{name}</h2>
4
+ </div>
5
+ );
6
+
7
+ export default Page;
@@ -0,0 +1,25 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ import { Link } from "waku/router/server";
4
+
5
+ const HomeLayout = ({ children }: { children: ReactNode }) => (
6
+ <div>
7
+ <ul>
8
+ <li>
9
+ <Link href="/">Home</Link>
10
+ </li>
11
+ <li>
12
+ <Link href="/foo">Foo</Link>
13
+ </li>
14
+ <li>
15
+ <Link href="/bar">Bar</Link>
16
+ </li>
17
+ <li>
18
+ <Link href="/baz">Baz</Link>
19
+ </li>
20
+ </ul>
21
+ {children}
22
+ </div>
23
+ );
24
+
25
+ export default HomeLayout;
@@ -0,0 +1,7 @@
1
+ const Home = () => (
2
+ <div>
3
+ <h1>Home</h1>
4
+ </div>
5
+ );
6
+
7
+ export default Home;
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "target": "esnext",
5
+ "downlevelIteration": true,
6
+ "esModuleInterop": true,
7
+ "module": "nodenext",
8
+ "skipLibCheck": true,
9
+ "noUncheckedIndexedAccess": true,
10
+ "exactOptionalPropertyTypes": true,
11
+ "jsx": "react-jsx",
12
+ "outDir": "./dist",
13
+ "tsBuildInfoFile": "./dist/.tsbuildinfo",
14
+ "composite": true
15
+ },
16
+ "include": ["./src"],
17
+ "references": [
18
+ {
19
+ "path": "./tsconfig.node.json"
20
+ }
21
+ ]
22
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/node",
5
+ "tsBuildInfoFile": "./dist/node/.tsbuildinfo",
6
+ "types": ["node"]
7
+ },
8
+ "include": ["vite.config.ts"]
9
+ }
@@ -0,0 +1,22 @@
1
+ import url from "node:url";
2
+ import path from "node:path";
3
+
4
+ import { defineConfig } from "waku/config";
5
+
6
+ const modulesRoot = path.join(
7
+ path.dirname(url.fileURLToPath(import.meta.url)),
8
+ "src",
9
+ );
10
+
11
+ export default defineConfig({
12
+ build: {
13
+ rollupOptions: {
14
+ output: {
15
+ // FIXME this doesn't seem to provide nice output.
16
+ // TODO we should use `input` instead.
17
+ preserveModules: true,
18
+ preserveModulesRoot: modulesRoot,
19
+ },
20
+ },
21
+ },
22
+ });
@@ -0,0 +1,8 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { Counter } from "./Counter.js";
3
+ import { Form } from "./Form.js";
4
+ import { getMessage, greet, increment } from "./funcs.js";
5
+ const App = ({ name }) => {
6
+ return (_jsxs("div", { style: { border: "3px red dashed", margin: "1em", padding: "1em" }, children: [_jsxs("h1", { children: ["Hello ", name, "!!"] }), _jsx("h3", { children: "This is a server component." }), _jsx(Counter, { increment: increment }), _jsx(Form, { message: getMessage(), greet: greet })] }));
7
+ };
8
+ export default App;
@@ -0,0 +1,13 @@
1
+ /// <reference types="react/canary" />
2
+ /// <reference types="react-dom/canary" />
3
+ "use client";
4
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
5
+ import { useFormState, useFormStatus } from "react-dom";
6
+ const FormStatus = () => {
7
+ const { pending } = useFormStatus();
8
+ return pending ? "Pending..." : null;
9
+ };
10
+ export const Counter = ({ increment, }) => {
11
+ const [count, dispatch] = useFormState(increment, 0);
12
+ return (_jsxs("div", { style: { border: "3px blue dashed", margin: "1em", padding: "1em" }, children: [_jsxs("form", { children: [_jsxs("p", { children: ["Count: ", count] }), _jsx("button", { formAction: dispatch, children: "Increment" }), _jsx(FormStatus, {})] }), _jsx("h3", { children: "This is a client component." })] }));
13
+ };
@@ -0,0 +1,10 @@
1
+ /// <reference types="react/canary" />
2
+ /// <reference types="react-dom/canary" />
3
+ "use client";
4
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
5
+ import { useFormStatus } from "react-dom";
6
+ const SubmitButton = () => {
7
+ const { pending } = useFormStatus();
8
+ return (_jsxs(_Fragment, { children: [_jsx("button", { disabled: pending, type: "submit", children: "Submit" }), pending ? "Pending..." : null] }));
9
+ };
10
+ export const Form = ({ message, greet, }) => (_jsxs("div", { style: { border: "3px blue dashed", margin: "1em", padding: "1em" }, children: [_jsx("p", { children: message }), _jsxs("form", { action: greet, children: ["Name: ", _jsx("input", { name: "name" }), _jsx(SubmitButton, {})] }), _jsx("h3", { children: "This is a client component." })] }));
@@ -0,0 +1,10 @@
1
+ "use server";
2
+ import { rerender } from "waku/server";
3
+ // module state on server
4
+ let message = "";
5
+ export const getMessage = () => message;
6
+ export const greet = (formData) => {
7
+ message = `Hello ${formData.get("name") || "Anonymous"} from server!`;
8
+ rerender("");
9
+ };
10
+ export const increment = (count) => count + 1;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { lazy } from "react";
3
+ import { defineEntries } from "waku/server";
4
+ const App = lazy(() => import("./components/App.js"));
5
+ export default defineEntries(
6
+ // renderEntries
7
+ async (input) => {
8
+ return {
9
+ App: _jsx(App, { name: input || "Waku" }),
10
+ };
11
+ },
12
+ // getBuildConfig
13
+ async () => {
14
+ return {
15
+ "/": {
16
+ entries: [[""]],
17
+ },
18
+ };
19
+ },
20
+ // getSsrConfig
21
+ () => ({
22
+ getInput: async (pathStr) => {
23
+ switch (pathStr) {
24
+ case "/":
25
+ return "";
26
+ default:
27
+ return null;
28
+ }
29
+ },
30
+ filter: (elements) => elements.App,
31
+ }));
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { StrictMode } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { Root, Slot } from "waku/client";
5
+ const rootElement = (_jsx(StrictMode, { children: _jsx(Root, { children: _jsx(Slot, { id: "App" }) }) }));
6
+ createRoot(document.getElementById("root")).render(rootElement);
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
15
+ else
16
+ exec node "$basedir/../typescript/bin/tsc" "$@"
17
+ fi
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/bin/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules/typescript/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/typescript@5.2.2/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
15
+ else
16
+ exec node "$basedir/../typescript/bin/tsserver" "$@"
17
+ fi
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+ basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
+
4
+ case `uname` in
5
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
+ esac
7
+
8
+ if [ -z "$NODE_PATH" ]; then
9
+ export NODE_PATH="/home/runner/work/waku/waku/packages/waku/dist/node_modules:/home/runner/work/waku/waku/packages/waku/node_modules:/home/runner/work/waku/waku/packages/node_modules:/home/runner/work/waku/waku/node_modules:/home/runner/work/waku/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules"
10
+ else
11
+ export NODE_PATH="/home/runner/work/waku/waku/packages/waku/dist/node_modules:/home/runner/work/waku/waku/packages/waku/node_modules:/home/runner/work/waku/waku/packages/node_modules:/home/runner/work/waku/waku/node_modules:/home/runner/work/waku/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/waku/waku/node_modules/.pnpm/node_modules:$NODE_PATH"
12
+ fi
13
+ if [ -x "$basedir/node" ]; then
14
+ exec "$basedir/node" "$basedir/../waku/dist/cli.js" "$@"
15
+ else
16
+ exec node "$basedir/../waku/dist/cli.js" "$@"
17
+ fi
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "waku-example",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "private": true,
6
+ "scripts": {
7
+ "dev": "waku dev --with-ssr",
8
+ "build": "waku build",
9
+ "start": "waku start --with-ssr"
10
+ },
11
+ "dependencies": {
12
+ "express": "^4.18.2",
13
+ "react": "18.3.0-canary-a41957507-20231017",
14
+ "react-dom": "18.3.0-canary-a41957507-20231017",
15
+ "react-server-dom-webpack": "18.3.0-canary-a41957507-20231017",
16
+ "waku": "0.16.0"
17
+ },
18
+ "devDependencies": {
19
+ "@types/react": "^18.2.31",
20
+ "@types/react-dom": "^18.2.14",
21
+ "typescript": "^5.2.2"
22
+ }
23
+ }