-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(esm/cjs): Make the router package dual & move RSC router (#10957)
- Loading branch information
Showing
64 changed files
with
528 additions
and
259 deletions.
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
2 changes: 1 addition & 1 deletion
2
__fixtures__/test-project-rsa/web/src/layouts/NavigationLayout/NavigationLayout.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
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
4 changes: 2 additions & 2 deletions
4
__fixtures__/test-project-rsc-kitchen-sink/web/src/layouts/AuthLayout/AuthLayout.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
6 changes: 3 additions & 3 deletions
6
...res__/test-project-rsc-kitchen-sink/web/src/layouts/NavigationLayout/NavigationLayout.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
4 changes: 2 additions & 2 deletions
4
__fixtures__/test-project-rsc-kitchen-sink/web/src/pages/LoginPage/LoginPage.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
4 changes: 2 additions & 2 deletions
4
__fixtures__/test-project-rsc-kitchen-sink/web/src/pages/SignupPage/SignupPage.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
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
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,41 @@ | ||
import { $ } from 'zx' | ||
|
||
interface Problem { | ||
kind: string | ||
entrypoint?: string | ||
resolutionKind?: string | ||
} | ||
|
||
/*** | ||
* Excluded entry points: | ||
* - ./bins/rw-vite-build.mjs: this is only used in the build handler | ||
* - SsrRouter, Router: this should be moved out of the Vite package anyway, and is only used in ESM | ||
* - ./react-node-loader: used to run the Worker | ||
* - | ||
*/ | ||
|
||
await $({ | ||
nothrow: true, | ||
})`yarn attw -P -f json > .attw.json` | ||
const output = await $`cat .attw.json` | ||
await $`rm .attw.json` | ||
|
||
const json = JSON.parse(output.stdout) | ||
|
||
if (!json.analysis.problems || json.analysis.problems.length === 0) { | ||
console.log('No errors found') | ||
process.exit(0) | ||
} | ||
|
||
if ( | ||
json.analysis.problems.every( | ||
(problem: Problem) => problem.resolutionKind === 'node10', | ||
) | ||
) { | ||
console.log("Only found node10 problems, which we don't care about") | ||
process.exit(0) | ||
} | ||
|
||
console.log('Errors found') | ||
console.log(json.analysis.problems) | ||
process.exit(1) |
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,35 @@ | ||
import { | ||
build, | ||
defaultBuildOptions, | ||
} from '@redwoodjs/framework-tools' | ||
|
||
import { generateCjsTypes} from '@redwoodjs/framework-tools/cjsTypes' | ||
import { writeFileSync } from 'node:fs' | ||
|
||
// CJS build | ||
await build({ | ||
buildOptions: { | ||
...defaultBuildOptions, | ||
outdir: 'dist/cjs', | ||
packages: 'external', | ||
}, | ||
}) | ||
|
||
// ESM build | ||
await build({ | ||
buildOptions: { | ||
...defaultBuildOptions, | ||
format: 'esm', | ||
packages: 'external', | ||
}, | ||
}) | ||
|
||
// Place a package.json file with `type: commonjs` in the dist/cjs folder so that | ||
// all .js files are treated as CommonJS files. | ||
writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' })) | ||
|
||
// Place a package.json file with `type: module` in the dist folder so that | ||
// all .js files are treated as ES Module files. | ||
writeFileSync('dist/package.json', JSON.stringify({ type: 'module' })) | ||
|
||
await generateCjsTypes() |
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
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,107 @@ | ||
declare module 'react-server-dom-webpack/node-loader' | ||
declare module 'react-server-dom-webpack/client.edge' | ||
|
||
// https://github.com/facebook/react/blob/b09e102ff1e2aaaf5eb6585b04609ac7ff54a5c8/packages/react-server-dom-webpack/src/shared/ReactFlightImportMetadata.js#L10 | ||
type ImportManifestEntry = { | ||
id: string | ||
// chunks is a double indexed array of chunkId / chunkFilename pairs | ||
chunks: Array<string> | ||
name: string | ||
} | ||
|
||
type ClientReferenceManifestEntry = ImportManifestEntry | ||
|
||
type ClientManifest = { | ||
[id: string]: ClientReferenceManifestEntry | ||
} | ||
|
||
declare module 'react-server-dom-webpack/server.edge' { | ||
type Options = { | ||
environmentName?: string | ||
identifierPrefix?: string | ||
signal?: AbortSignal | ||
onError?: (error: mixed) => void | ||
onPostpone?: (reason: string) => void | ||
} | ||
|
||
// https://github.com/facebook/react/blob/0711ff17638ed41f9cdea712a19b92f01aeda38f/packages/react-server-dom-webpack/src/ReactFlightDOMServerEdge.js#L48 | ||
export function renderToReadableStream( | ||
model: ReactClientValue, | ||
webpackMap: ClientManifest, | ||
options?: Options, | ||
): ReadableStream | ||
} | ||
|
||
// Should be able to use just react-dom/server, but right now we can't | ||
// See https://github.com/facebook/react/issues/26906 | ||
declare module 'react-dom/server.edge' { | ||
export * from 'react-dom/server' | ||
} | ||
|
||
declare module 'react-server-dom-webpack/client' { | ||
// https://github.com/facebook/react/blob/dfaed5582550f11b27aae967a8e7084202dd2d90/packages/react-server-dom-webpack/src/ReactFlightDOMClientBrowser.js#L31 | ||
export type Options<A, T> = { | ||
callServer?: (id: string, args: A) => Promise<T> | ||
} | ||
|
||
export function createFromFetch<A, T>( | ||
// `Response` is a Web Response: | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Response | ||
promiseForResponse: Promise<Response>, | ||
options?: Options<A, T>, | ||
): Thenable<T> | ||
|
||
export function encodeReply( | ||
// https://github.com/facebook/react/blob/dfaed5582550f11b27aae967a8e7084202dd2d90/packages/react-client/src/ReactFlightReplyClient.js#L65 | ||
value: ReactServerValue, | ||
): Promise<string | URLSearchParams | FormData> | ||
} | ||
|
||
declare module 'react-server-dom-webpack/server' { | ||
import type { Writable } from 'stream' | ||
|
||
import type { Busboy } from 'busboy' | ||
|
||
// It's difficult to know the true type of `ServerManifest`. | ||
// A lot of react's source files are stubs that are replaced at build time. | ||
// Going off this reference for now: https://github.com/facebook/react/blob/b09e102ff1e2aaaf5eb6585b04609ac7ff54a5c8/packages/react-server-dom-webpack/src/ReactFlightClientConfigBundlerWebpack.js#L40 | ||
type ServerManifest = { | ||
[id: string]: ImportManifestEntry | ||
} | ||
|
||
// The types for `decodeReply` and `decodeReplyFromBusboy` were taken from | ||
// https://github.com/facebook/react/blob/b09e102ff1e2aaaf5eb6585b04609ac7ff54a5c8/packages/react-server-dom-webpack/src/ReactFlightDOMServerNode.js | ||
// which is what 'react-server-dom-webpack/server' resolves to with the 'react-server' condition. | ||
|
||
/** | ||
* WARNING: The types for this were handwritten by looking at React's source and could be wrong. | ||
*/ | ||
export function decodeReply<T>( | ||
body: string | FormData, | ||
webpackMap?: ServerManifest, | ||
): Promise<T> | ||
|
||
/** | ||
* WARNING: The types for this were handwritten by looking at React's source and could be wrong. | ||
*/ | ||
export function decodeReplyFromBusboy<T>( | ||
busboyStream: Busboy, | ||
webpackMap?: ServerManifest, | ||
): Promise<T> | ||
|
||
type PipeableStream = { | ||
abort(reason: any): void | ||
pipe<T extends Writable>(destination: T): T | ||
} | ||
|
||
// The types for `renderToPipeableStream` are incomplete and were taken from | ||
// https://github.com/facebook/react/blob/b09e102ff1e2aaaf5eb6585b04609ac7ff54a5c8/packages/react-server-dom-webpack/src/ReactFlightDOMServerNode.js#L75. | ||
|
||
/** | ||
* WARNING: The types for this were handwritten by looking at React's source and could be wrong. | ||
*/ | ||
export function renderToPipeableStream( | ||
model: ReactClientValue, | ||
webpackMap: ClientManifest, | ||
): PipeableStream | ||
} |
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
Oops, something went wrong.