Skip to content

Commit

Permalink
streamline bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
phryneas committed Nov 14, 2024
1 parent 88e5e63 commit ecc65ff
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 15 deletions.
16 changes: 12 additions & 4 deletions packages/client-react-streaming/package-shape.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,25 @@
]
},
"@apollo/client-react-streaming/stream-utils": {
"react-server": ["built_for_other"],
"browser": ["built_for_other"],
"react-server": [
"built_for_browser",
"JSONDecodeStream",
"JSONEncodeStream"
],
"browser": ["built_for_browser", "JSONDecodeStream", "JSONEncodeStream"],
"node": [
"built_for_ssr",
"createInjectionTransformStream",
"pipeReaderToResponse"
"pipeReaderToResponse",
"JSONDecodeStream",
"JSONEncodeStream"
],
"edge-light,worker,browser": [
"built_for_ssr",
"createInjectionTransformStream",
"pipeReaderToResponse"
"pipeReaderToResponse",
"JSONDecodeStream",
"JSONEncodeStream"
]
}
}
6 changes: 3 additions & 3 deletions packages/client-react-streaming/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@
},
"./stream-utils": {
"require": {
"types": "./dist/stream-utils.ssr.d.cts",
"types": "./dist/stream-utils.combined.d.cts",
"react-server": "./dist/stream-utils.cjs",
"edge-light": "./dist/stream-utils.ssr.cjs",
"browser": "./dist/stream-utils.cjs",
"node": "./dist/stream-utils.ssr.cjs"
},
"import": {
"types": "./dist/stream-utils.rsc.d.ts",
"types": "./dist/stream-utils.combined.d.ts",
"react-server": "./dist/stream-utils.js",
"edge-light": "./dist/stream-utils.ssr.js",
"browser": "./dist/stream-utils.js",
Expand All @@ -100,7 +100,7 @@
"./dist/manual-transport.ssr.d.ts"
],
"stream-utils": [
"./dist/stream-utils.node.d.ts"
"./dist/stream-utils.combined.d.ts"
]
}
},
Expand Down
17 changes: 17 additions & 0 deletions packages/client-react-streaming/src/stream-utils/combined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* TypeScript does not have the concept of these environments,
* so we need to create a single entry point that combines all
* possible exports.
* That means that users will be offered "RSC" exports in a
* "SSR/Browser" code file, but those will error in a compilation
* step.
*
* This is a limitation of TypeScript, and we can't do anything
* about it.
*
* The build process will only create `.d.ts`/`d.cts` files from
* this, and not actual runtime code.
*/

export * from "./index.ssr.js";
export * from "./index.js";
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { renderToString } from "react-dom/server";
import * as React from "react";

/**
* > This export is only available in streaming SSR Server environments
*
* Used to create a `TransformStream` that can be used for piping a React stream rendered by
* `renderToReadableStream` and using the callback to insert chunks of HTML between React Chunks.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {
JSONDecodeStream,
JSONEncodeStream,
type JsonString,
} from "./JSONTransformStreams.js";
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from "./index.js";
export * from "./index.shared.js";
export { createInjectionTransformStream } from "./createInjectionTransformStream.js";
export { pipeReaderToResponse } from "./pipeReaderToResponse.js";
6 changes: 1 addition & 5 deletions packages/client-react-streaming/src/stream-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export {
JSONDecodeStream,
JSONEncodeStream,
JsonString,
} from "./JSONTransformStreams.js";
export * from "./index.shared.js";
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/**
* > This export is only available in streaming SSR Server environments
*
* Used to pipe a `ReadableStreamDefaultReader` to a `ServerResponse`.
*
* @example
Expand Down
2 changes: 1 addition & 1 deletion packages/client-react-streaming/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"./src/combined.ts"
],
"@apollo/client-react-streaming/stream-utils": [
"./src/stream-utils/index.ts"
"src/stream-utils/index.shared.ts"
]
}
},
Expand Down
10 changes: 9 additions & 1 deletion packages/client-react-streaming/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ export default defineConfig((options) => {
"manual-transport.browser"
),
entry("ssr", "src/stream-utils/index.ssr.ts", "stream-utils.ssr"),
entry("other", "src/stream-utils/index.ts", "stream-utils"),
entry("browser", "src/stream-utils/index.ts", "stream-utils"),
{
...entry(
"other",
"src/stream-utils/combined.ts",
"stream-utils.combined"
),
dts: { only: true },
},
{
...entry("browser", "src/index.cc.tsx", "index.cc"),
treeshake: false, // would remove the "use client" directive
Expand Down

0 comments on commit ecc65ff

Please sign in to comment.