-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add more test packages (#664)
- Loading branch information
Showing
18 changed files
with
211 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports.test = "[ok]"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
packages/react-server/examples/basic/deps/cjs/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
packages/react-server/examples/basic/deps/context/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
packages/react-server/examples/basic/deps/context/client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
packages/react-server/examples/basic/deps/context/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
packages/react-server/examples/basic/deps/context/server2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/react-server/examples/basic/src/routes/test/deps/examples/cjs/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/react-server/examples/basic/src/routes/test/deps/examples/cjs2/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/react-server/examples/basic/src/routes/test/deps/examples/context/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/react-server/examples/basic/src/routes/test/deps/examples/context2/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.