Skip to content

Commit

Permalink
RSC: Include entries.ts in paths (#8888)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe committed Jul 12, 2023
1 parent 8610d58 commit db271db
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 8 deletions.
3 changes: 1 addition & 2 deletions packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ export const handler = async ({ force, verbose }) => {
path.resolve(__dirname, 'templates', 'rsc', 'entries.ts.template'),
'utf-8'
)
const entriesPath = path.join(rwPaths.web.src, 'entries.ts')

writeFile(entriesPath, entriesTemplate, {
writeFile(rwPaths.web.entries, entriesTemplate, {
overwriteExisting: force,
})
},
Expand Down
32 changes: 32 additions & 0 deletions packages/project-config/src/__tests__/paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,19 @@ describe('paths', () => {
'routeHooks'
),
distServer: path.join(FIXTURE_BASEDIR, 'web', 'dist', 'server'),
distServerEntries: path.join(
FIXTURE_BASEDIR,
'web',
'dist',
'server',
'entries.js'
),
types: path.join(FIXTURE_BASEDIR, 'web', 'types'),
// Vite paths ~ not configured in empty-project
viteConfig: null,
entryClient: null,
entryServer: null,
entries: null,
},
}

Expand Down Expand Up @@ -419,11 +427,19 @@ describe('paths', () => {
'routeHooks'
),
distServer: path.join(FIXTURE_BASEDIR, 'web', 'dist', 'server'),
distServerEntries: path.join(
FIXTURE_BASEDIR,
'web',
'dist',
'server',
'entries.js'
),
types: path.join(FIXTURE_BASEDIR, 'web', 'types'),
// New Vite paths
viteConfig: path.join(FIXTURE_BASEDIR, 'web', 'vite.config.ts'),
entryClient: null, // doesn't exist in example-todo-main
entryServer: null, // doesn't exist in example-todo-main
entries: null, // doesn't exist in example-todo-main
},
}

Expand Down Expand Up @@ -713,6 +729,7 @@ describe('paths', () => {
),
entryClient: null,
entryServer: null,
entries: null,
dist: path.join(FIXTURE_BASEDIR, 'web', 'dist'),
distEntryServer: path.join(
FIXTURE_BASEDIR,
Expand All @@ -729,6 +746,13 @@ describe('paths', () => {
'routeHooks'
),
distServer: path.join(FIXTURE_BASEDIR, 'web', 'dist', 'server'),
distServerEntries: path.join(
FIXTURE_BASEDIR,
'web',
'dist',
'server',
'entries.js'
),
types: path.join(FIXTURE_BASEDIR, 'web', 'types'),
},
}
Expand Down Expand Up @@ -992,11 +1016,19 @@ describe('paths', () => {
'routeHooks'
),
distServer: path.join(FIXTURE_BASEDIR, 'web', 'dist', 'server'),
distServerEntries: path.join(
FIXTURE_BASEDIR,
'web',
'dist',
'server',
'entries.js'
),
types: path.join(FIXTURE_BASEDIR, 'web', 'types'),
// Vite paths
viteConfig: path.join(FIXTURE_BASEDIR, 'web', 'vite.config.ts'),
entryClient: path.join(FIXTURE_BASEDIR, 'web/src/entry.client.tsx'),
entryServer: null,
entries: null,
},
}

Expand Down
6 changes: 6 additions & 0 deletions packages/project-config/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface WebPaths {
viteConfig: string | null // because vite is opt-in only
entryClient: string | null
entryServer: string | null
entries: string | null
postcss: string
storybookConfig: string
storybookPreviewConfig: string
Expand All @@ -48,6 +49,7 @@ export interface WebPaths {
distServer: string
distEntryServer: string
distRouteHooks: string
distServerEntries: string
routeManifest: string
types: string
}
Expand Down Expand Up @@ -107,6 +109,7 @@ const PATH_WEB_DIR_CONFIG_WEBPACK = 'web/config/webpack.config.js'
const PATH_WEB_DIR_CONFIG_VITE = 'web/vite.config' // .js,.ts
const PATH_WEB_DIR_ENTRY_CLIENT = 'web/src/entry.client' // .jsx,.tsx
const PATH_WEB_DIR_ENTRY_SERVER = 'web/src/entry.server' // .jsx,.tsx
const PATH_WEB_DIR_ENTRIES = 'web/src/entries' // .jsx,.tsx

const PATH_WEB_DIR_CONFIG_POSTCSS = 'web/config/postcss.config.js'
const PATH_WEB_DIR_CONFIG_STORYBOOK_CONFIG = 'web/config/storybook.config.js'
Expand All @@ -117,6 +120,7 @@ const PATH_WEB_DIR_DIST = 'web/dist'
const PATH_WEB_DIR_DIST_SERVER = 'web/dist/server'
const PATH_WEB_DIR_DIST_SERVER_ENTRY_SERVER = 'web/dist/server/entry.server.js'
const PATH_WEB_DIR_DIST_SERVER_ROUTEHOOKS = 'web/dist/server/routeHooks'
const PATH_WEB_DIR_DIST_SERVER_ENTRIES = 'web/dist/server/entries.js'
const PATH_WEB_DIR_ROUTE_MANIFEST = 'web/dist/server/route-manifest.json'

/**
Expand Down Expand Up @@ -228,10 +232,12 @@ export const getPaths = (BASE_DIR: string = getBaseDir()): Paths => {
PATH_WEB_DIR_DIST_SERVER_ENTRY_SERVER
),
distRouteHooks: path.join(BASE_DIR, PATH_WEB_DIR_DIST_SERVER_ROUTEHOOKS),
distServerEntries: path.join(BASE_DIR, PATH_WEB_DIR_DIST_SERVER_ENTRIES),
routeManifest: path.join(BASE_DIR, PATH_WEB_DIR_ROUTE_MANIFEST),
types: path.join(BASE_DIR, 'web/types'),
entryClient: resolveFile(path.join(BASE_DIR, PATH_WEB_DIR_ENTRY_CLIENT)), // new vite/stream entry point for client
entryServer: resolveFile(path.join(BASE_DIR, PATH_WEB_DIR_ENTRY_SERVER)),
entries: resolveFile(path.join(BASE_DIR, PATH_WEB_DIR_ENTRIES)),
},
}

Expand Down
10 changes: 6 additions & 4 deletions packages/vite/src/buildRscFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const buildFeServer = async ({ verbose: _verbose }: BuildOptions) => {
throw new Error('Vite config not found')
}

if (!rwPaths.web.entries) {
throw new Error('RSC entries file not found')
}

const clientEntryFileSet = new Set<string>()
const serverEntryFileSet = new Set<string>()

Expand Down Expand Up @@ -62,8 +66,7 @@ export const buildFeServer = async ({ verbose: _verbose }: BuildOptions) => {
ssr: true,
rollupOptions: {
input: {
// entries: rwPaths.web.entryServer,
entries: path.join(rwPaths.web.src, 'entries.ts'),
entries: rwPaths.web.entries,
},
},
},
Expand Down Expand Up @@ -148,8 +151,7 @@ export const buildFeServer = async ({ verbose: _verbose }: BuildOptions) => {
}

const serverBuildOutput = await serverBuild(
// rwPaths.web.entryServer,
path.join(rwPaths.web.src, 'entries.ts'),
rwPaths.web.entries,
clientEntryFiles,
serverEntryFiles,
{}
Expand Down
3 changes: 1 addition & 2 deletions packages/vite/src/waku-lib/rsc-handler-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ const getEntriesFile = async (
)
}

// TODO: Don't hardcode the name of the entries file
return path.join(rwPaths.web.distServer, 'entries.js') // path.join(config.root, config.framework.entriesJs)
return rwPaths.web.distServerEntries
}

const getFunctionComponent = async (
Expand Down

0 comments on commit db271db

Please sign in to comment.