Skip to content

Commit

Permalink
chore: add more test packages (#664)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Dec 15, 2024
1 parent cec21bc commit c091d41
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/react-server/examples/basic/deps/cjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
```jsx
// in server component
import { TestServer } from "@hiogawa/test-dep-cjs/server"

export default function Page() {
return <TestServer /> // should show [ok]
}
```

```jsx
// in server component
import { TestServer } from "@hiogawa/test-dep-cjs/server2"

export default function Page() {
return <TestServer /> // should show [ok]
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.test = "[ok]";
8 changes: 8 additions & 0 deletions packages/react-server/examples/basic/deps/cjs/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use client";

import React from "react";
import dep from "./client-dep.cjs";

export function TestClient() {
return React.createElement("span", null, dep.test);
}
16 changes: 16 additions & 0 deletions packages/react-server/examples/basic/deps/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@hiogawa/test-dep-cjs",
"private": true,
"type": "module",
"exports": {
"./server": "./server.js",
"./server2": "./server2.js",
"./client": "./client.js"
},
"dependencies": {
"react": "*"
},
"peerDependencies": {
"react": "*"
}
}
9 changes: 9 additions & 0 deletions packages/react-server/examples/basic/deps/cjs/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";

// when consuming client component internally,
// this cannot be optimized and thus cjs dep fails.
import { TestClient } from "./client.js";

export function TestServer() {
return React.createElement(TestClient);
}
6 changes: 6 additions & 0 deletions packages/react-server/examples/basic/deps/cjs/server2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TestClient } from "@hiogawa/test-dep-cjs/client";
import React from "react";

export function TestServer() {
return React.createElement(TestClient);
}
21 changes: 21 additions & 0 deletions packages/react-server/examples/basic/deps/context/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
```jsx
// in server component

import { TestServer } from "@hiogawa/test-dep-context/server"
import { TestClient } from "@hiogawa/test-dep-context/client"

export default function Page() {
return <TestServer><TestClient/></TestServer> // should show [ok]
}
```

```jsx
// in server component

import { TestServer } from "@hiogawa/test-dep-context/server2"
import { TestClient } from "@hiogawa/test-dep-context/client"

export default function Page() {
return <TestServer><TestClient/></TestServer> // should show [ok]
}
```
19 changes: 19 additions & 0 deletions packages/react-server/examples/basic/deps/context/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"use client";

import React from "react";

const MyContext = React.createContext("not-ok");

export function MyContextProvider(props) {
return React.createElement(
MyContext.Provider,
{ value: "ok" },
props.children,
);
}

// consume own context in client entry
export function TestClient() {
const value = React.useContext(MyContext);
return React.createElement("span", null, `[context: ${value}]`);
}
16 changes: 16 additions & 0 deletions packages/react-server/examples/basic/deps/context/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@hiogawa/test-dep-context",
"private": true,
"type": "module",
"exports": {
"./server": "./server.js",
"./server2": "./server2.js",
"./client": "./client.js"
},
"dependencies": {
"react": "*"
},
"peerDependencies": {
"react": "*"
}
}
6 changes: 6 additions & 0 deletions packages/react-server/examples/basic/deps/context/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import { MyContextProvider } from "./client.js";

export function TestServer(props) {
return React.createElement(MyContextProvider, null, props.children);
}
10 changes: 10 additions & 0 deletions packages/react-server/examples/basic/deps/context/server2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// difference from `server.js` is that
// this uses self exports reference `@hiogawa/test-dep-context/client`
// instead of relative reference `./client.js`
import { MyContextProvider } from "@hiogawa/test-dep-context/client";
import React from "react";

// consume own provider in server entr
export function TestServer(props) {
return React.createElement(MyContextProvider, null, props.children);
}
2 changes: 2 additions & 0 deletions packages/react-server/examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
},
"dependencies": {
"@hiogawa/react-server": "latest",
"@hiogawa/test-dep-cjs": "file:deps/cjs",
"@hiogawa/test-dep-context": "file:deps/context",
"@hiogawa/test-dep-mixed": "file:deps/mixed",
"@hiogawa/test-dep-server-component": "file:deps/server-component",
"@hiogawa/test-dep-use-client": "file:deps/use-client",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-ignore
import { TestServer } from "@hiogawa/test-dep-cjs/server";

export default function Page() {
return (
<div>
<TestServer />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-ignore
import { TestServer } from "@hiogawa/test-dep-cjs/server2";

export default function Page() {
return (
<div>
<TestServer />
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-ignore
import { TestClient } from "@hiogawa/test-dep-context/client";
// @ts-ignore
import { TestServer } from "@hiogawa/test-dep-context/server";

export default function Page() {
return (
<TestServer>
<TestClient />
</TestServer>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-ignore
import { TestClient } from "@hiogawa/test-dep-context/client";
// @ts-ignore
import { TestServer } from "@hiogawa/test-dep-context/server2";

export default function Page() {
return (
<div>
<TestServer>
<TestClient />
</TestServer>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ export default function Layout(props: LayoutProps) {
return (
<div className="flex flex-col gap-2 p-2">
<h4 className="font-bold">Test Dependencies</h4>
<NavMenu links={["/test/deps", "/test/deps/react-tweet"]} />
<NavMenu
links={[
"/test/deps",
"/test/deps/react-tweet",
"/test/deps/examples/cjs",
"/test/deps/examples/cjs2",
"/test/deps/examples/context",
"/test/deps/examples/context2",
]}
/>
{props.children}
</div>
);
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c091d41

Please sign in to comment.