Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViteBuildManifest and note about import-attributes #8818

Merged
merged 2 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions packages/vite/src/buildFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from 'fs/promises'
import path from 'path'

import { build as esbuildBuild, PluginBuild } from 'esbuild'
import type { Manifest as ViteManifest } from 'vite'
import type { Manifest as ViteBuildManifest } from 'vite'

import { getRouteHookBabelPlugins } from '@redwoodjs/internal'
import { transformWithBabel } from '@redwoodjs/internal/dist/build/babel/api'
Expand Down Expand Up @@ -96,9 +96,26 @@ export const buildFeServer = async ({ verbose }: BuildOptions) => {
})

// Step 3: Generate route-manifest.json

// TODO When https://github.com/tc39/proposal-import-attributes and
// https://github.com/microsoft/TypeScript/issues/53656 have both landed we
// should try to do this instead:
// const clientBuildManifest: ViteBuildManifest = await import(
// path.join(getPaths().web.dist, 'build-manifest.json'),
// { with: { type: 'json' } }
// )
// NOTES:
// * There's a related babel plugin here
// https://babeljs.io/docs/babel-plugin-syntax-import-attributes
// * Included in `preset-env` if you set `shippedProposals: true`
// * We had this before, but with `assert` instead of `with`. We really
// should be using `with`. See motivation in issues linked above.
// * With `assert` and `@babel/plugin-syntax-import-assertions` the
// code compiled and ran properly, but Jest tests failed, complaining
// about the syntax.
const manifestPath = path.join(getPaths().web.dist, 'build-manifest.json')
const buildManifestStr = await fs.readFile(manifestPath, 'utf-8')
const clientBuildManifest: ViteManifest = JSON.parse(buildManifestStr)
const clientBuildManifest: ViteBuildManifest = JSON.parse(buildManifestStr)

const routesList = getProjectRoutes()

Expand Down
20 changes: 18 additions & 2 deletions packages/vite/src/runFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import express from 'express'
import { createProxyMiddleware } from 'http-proxy-middleware'
import isbot from 'isbot'
import { renderToPipeableStream } from 'react-dom/server'
import type { Manifest as ViteManifest } from 'vite'
import type { Manifest as ViteBuildManifest } from 'vite'

import { getConfig, getPaths } from '@redwoodjs/project-config'
import { matchPath } from '@redwoodjs/router'
Expand Down Expand Up @@ -50,12 +50,28 @@ export async function runFeServer() {
const rwPaths = getPaths()
const rwConfig = getConfig()

// TODO When https://github.com/tc39/proposal-import-attributes and
// https://github.com/microsoft/TypeScript/issues/53656 have both landed we
// should try to do this instead:
// const routeManifest: RWRouteManifest = await import(
// rwPaths.web.routeManifest, { with: { type: 'json' } }
// )
// NOTES:
// * There's a related babel plugin here
// https://babeljs.io/docs/babel-plugin-syntax-import-attributes
// * Included in `preset-env` if you set `shippedProposals: true`
// * We had this before, but with `assert` instead of `with`. We really
// should be using `with`. See motivation in issues linked above.
// * With `assert` and `@babel/plugin-syntax-import-assertions` the
// code compiled and ran properly, but Jest tests failed, complaining
// about the syntax.
const routeManifestStr = await fs.readFile(rwPaths.web.routeManifest, 'utf-8')
const routeManifest: RWRouteManifest = JSON.parse(routeManifestStr)

// TODO See above about using `import { with: { type: 'json' } }` instead
const manifestPath = path.join(getPaths().web.dist, 'build-manifest.json')
const buildManifestStr = await fs.readFile(manifestPath, 'utf-8')
const buildManifest: ViteManifest = JSON.parse(buildManifestStr)
const buildManifest: ViteBuildManifest = JSON.parse(buildManifestStr)

const indexEntry = Object.values(buildManifest).find((manifestItem) => {
return manifestItem.isEntry
Expand Down
Loading