From 8dc505ff16d41308a4b208b412bcb3fa7aad5891 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Wed, 28 Feb 2024 10:00:32 -0800 Subject: [PATCH 1/8] chore(release): update changelog --- CHANGELOG.md | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 880005b2e678..52f0fd5d8fce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,25 +69,9 @@ Note that this feature is mainly for local scripting. Most deploy providers don't let you upload dotfiles and usually have their own way of determining environments. -- fix(render): reduce memory and handle server file +## v7.0.3 - This PR improves Render deploys by reducing memory consumption and fixing it so that it uses the server file if it's present. - - Render deploys seems to consistently run out of memory during the data migration step. This step is configurable and its doubtful that every deploy has data migrations to apply, but it's enabled by default so it runs every time. The main issue is that the data migrate functionality is a plugin so a yarn install kicks off in Render's deploy container which must be more memory-constrained than the build container. (Assuming there are two different containers, which seems to be the case.) - - Instead of running data migrations, this PR issues a warning that if you want to run data migrations, you need to first add the `@redwoodjs/cli-data-migrate` package as a devDependency: - - ``` - yarn add -D @redwoodjs/cli-data-migrate - ``` - - That way a `yarn install` won't be necessary to run data migrations. - - Although this PR fixes Render deploy so that it uses the server file if present, realtime features still don't seem to work. We're still investigating; in the meantime, consider using another provider like Coherence if you're just getting started and want to try out realtime features. - -- Update MetaTags to be Metadata in Docs (#10053) - - The tutorial still used the `MetaTags` component instead of the newer `Metadata` component that the generator templates use. This PR updates all instances of `MetaTags` with `Metadata`. +- See https://github.com/redwoodjs/redwood/releases/tag/v7.0.3 ## v7.0.2 From d70989c466d3869f63c7d94e503852040e1974a4 Mon Sep 17 00:00:00 2001 From: Daniel Beitler Date: Wed, 28 Feb 2024 11:52:19 -0700 Subject: [PATCH 2/8] chore(docs): Add link to SuperTokens auth (#10067) Add a missing link to the SuperTokens auth page --------- Co-authored-by: Amy Haywood Dutton --- CHANGELOG.md | 3 +++ docs/docs/authentication.md | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52f0fd5d8fce..62cb0af89d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ Fix formatting of JSDocs in `scenario.ts` +- chore(docs): Add link to SuperTokens auth (#10067) + Add a missing link to the SuperTokens auth page in the docs. @danbtl + - fix(deps): update opentelemetry-js monorepo (#10065) Updates our opentelemetry packages. This is a breaking change for users of diff --git a/docs/docs/authentication.md b/docs/docs/authentication.md index 88506057eb2f..91bb3184de3a 100644 --- a/docs/docs/authentication.md +++ b/docs/docs/authentication.md @@ -26,7 +26,7 @@ Redwood has a simple API to integrate any auth provider you can think of. But to - [Firebase](./auth/firebase.md) - [Netlify](./auth/netlify.md) - [Supabase](./auth/supabase.md) -- SuperTokens +- [SuperTokens](./auth/supertokens.md) :::tip how to tell if an integration is official From 02a8dbeafb91221b6f917dea08b6dc60790d59d1 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Wed, 28 Feb 2024 14:48:13 -0800 Subject: [PATCH 3/8] chore(release): update changelog --- CHANGELOG.md | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62cb0af89d18..3ccaa70af4dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,26 +2,6 @@ ## Unreleased -- fix(coherence): update setup command to detect server file - - The `yarn rw setup deploy coherence` command now detects if your project has the server file and configures the api prod command accordingly: - - ```yml - # coherence.yml - - api: - # ... - prod: - command: ["yarn", "rw", "build", "api", "&&", "yarn", "node", "api/dist/server.js", "--apiRootPath=/api"] - ``` - -- Update jsdoc for ScenarioData type (#29166) - - Fix formatting of JSDocs in `scenario.ts` - -- chore(docs): Add link to SuperTokens auth (#10067) - Add a missing link to the SuperTokens auth page in the docs. @danbtl - - fix(deps): update opentelemetry-js monorepo (#10065) Updates our opentelemetry packages. This is a breaking change for users of @@ -72,6 +52,10 @@ Note that this feature is mainly for local scripting. Most deploy providers don't let you upload dotfiles and usually have their own way of determining environments. +## v7.0.4 + +- See https://github.com/redwoodjs/redwood/releases/tag/v7.0.4 + ## v7.0.3 - See https://github.com/redwoodjs/redwood/releases/tag/v7.0.3 From 3e87552c5c3747ee8c3e86c2a437e092ee6a8ff5 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 29 Feb 2024 12:30:02 +0530 Subject: [PATCH 4/8] RSC: Fix node-loader message typo (#10077) --- packages/vite/src/react-server-dom-webpack/node-loader.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/vite/src/react-server-dom-webpack/node-loader.ts b/packages/vite/src/react-server-dom-webpack/node-loader.ts index 11cc33f8cc83..726c12b8398a 100644 --- a/packages/vite/src/react-server-dom-webpack/node-loader.ts +++ b/packages/vite/src/react-server-dom-webpack/node-loader.ts @@ -411,10 +411,9 @@ async function transformClientModule( JSON.stringify( 'Attempted to call the default export of ' + url + - ' from the server' + - "but it's on the client. It's not possible to invoke a client function from " + - 'the server, it can only be rendered as a Component or passed to props of a' + - 'Client Component.' + " from the server but it's on the client. It's not possible to " + + 'invoke a client function from the server, it can only be ' + + 'rendered as a Component or passed to props of a Client Component.' ) + ');' } else { From 76e27ed089d2158ce820c5c00d4db09208a957d2 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Wed, 28 Feb 2024 23:13:04 -0800 Subject: [PATCH 5/8] fix(deploy): handle server file (#10061) At first this PR was similar to https://github.com/redwoodjs/redwood/pull/10055 but for Flightcontrol. But in the process of testing that and updating deploy target CI, I noticed a few other things were off: - coherence logic for the server file was flipped. fixed here - in general, a few duplicate ways of checking for the server file. tried to dedupe them the best i could without making massive changes - stylistic change to render - the flightcontrol setup wasn't handing corepack Test as much as I could locally. Going to get this one into next so I can test in deploy target CI. --- .vscode/settings.json | 2 + CHANGELOG.md | 4 ++ __fixtures__/test-project/web/package.json | 2 +- .../cli/src/commands/__tests__/dev.test.js | 3 + .../cli/src/commands/__tests__/serve.test.js | 5 +- .../cli/src/commands/deploy/flightcontrol.js | 63 ++++++++++--------- packages/cli/src/commands/devHandler.js | 10 +-- .../cli/src/commands/experimental/util.js | 13 +--- packages/cli/src/commands/serve.js | 10 +-- .../deploy/providers/coherenceHandler.js | 6 +- .../setup/deploy/templates/flightcontrol.js | 2 + .../commands/setup/deploy/templates/render.js | 2 +- .../setup/realtime/realtimeHandler.js | 4 +- packages/cli/src/lib/project.js | 9 +++ 14 files changed, 71 insertions(+), 64 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 42bee3163de2..89d70d0ff17e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -23,8 +23,10 @@ "peacock.color": "#b85833", "cSpell.words": [ "autoplay", + "corepack", "execa", "Fastify", + "Flightcontrol", "graphiql", "opentelemetry", "pino", diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ccaa70af4dc..3655c64980c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- fix(deploy): handle server file (#10061) + + This fixes the CLI commands for Coherence and Flightcontrol. For Coherence, it fixes a bug introduced in the last patch where the logic for detecting the server file in the setup command (`yarn rw setup deploy coherence`) was flipped. For Flightcontrol, it updates the setup command (`yarn rw setup deploy flightcontrol`) so that it handles Corepack and updates the corresponding deploy command (`yarn rw deploy flightcontrol`) so that it detects the server file similar to the Coherence fix. + - fix(deps): update opentelemetry-js monorepo (#10065) Updates our opentelemetry packages. This is a breaking change for users of diff --git a/__fixtures__/test-project/web/package.json b/__fixtures__/test-project/web/package.json index 433398a0e250..4f1e45de9425 100644 --- a/__fixtures__/test-project/web/package.json +++ b/__fixtures__/test-project/web/package.json @@ -25,7 +25,7 @@ "@types/react-dom": "^18.2.19", "autoprefixer": "^10.4.17", "postcss": "^8.4.35", - "postcss-loader": "^8.1.0", + "postcss-loader": "^8.1.1", "prettier-plugin-tailwindcss": "0.4.1", "tailwindcss": "^3.4.1" } diff --git a/packages/cli/src/commands/__tests__/dev.test.js b/packages/cli/src/commands/__tests__/dev.test.js index 861900942def..8de1625bc3fe 100644 --- a/packages/cli/src/commands/__tests__/dev.test.js +++ b/packages/cli/src/commands/__tests__/dev.test.js @@ -37,9 +37,12 @@ vi.mock('@redwoodjs/project-config', async () => { getPaths: () => { return { api: { + base: '/mocked/project/api', + src: '/mocked/project/api/src', dist: '/mocked/project/api/dist', }, web: { + base: '/mocked/project/web', dist: '/mocked/project/web/dist', }, generated: { diff --git a/packages/cli/src/commands/__tests__/serve.test.js b/packages/cli/src/commands/__tests__/serve.test.js index 78df9d19575d..33bbefa8468b 100644 --- a/packages/cli/src/commands/__tests__/serve.test.js +++ b/packages/cli/src/commands/__tests__/serve.test.js @@ -17,6 +17,7 @@ vi.mock('@redwoodjs/project-config', async (importOriginal) => { return { api: { base: '/mocked/project/api', + src: '/mocked/project/api/src', dist: '/mocked/project/api/dist', }, web: { @@ -39,8 +40,8 @@ vi.mock('fs-extra', async (importOriginal) => { default: { ...originalFsExtra, existsSync: (p) => { - // Don't detect the experimental server file, can't use path.sep here so the replaceAll is used - if (p.replaceAll('\\', '/') === '/mocked/project/api/dist/server.js') { + // Don't detect the server file, can't use path.sep here so the replaceAll is used + if (p.replaceAll('\\', '/') === '/mocked/project/api/src/server.ts') { return false } return true diff --git a/packages/cli/src/commands/deploy/flightcontrol.js b/packages/cli/src/commands/deploy/flightcontrol.js index 8179d3bc4f0a..03b879f353b5 100644 --- a/packages/cli/src/commands/deploy/flightcontrol.js +++ b/packages/cli/src/commands/deploy/flightcontrol.js @@ -1,23 +1,22 @@ import path from 'path' import execa from 'execa' +import fs from 'fs-extra' import terminalLink from 'terminal-link' -import { handler as apiServerHandler } from '@redwoodjs/api-server/dist/apiCLIConfigHandler' import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers' -import { getConfig } from '@redwoodjs/project-config' - -import { getPaths } from '../../lib' +import { getPaths } from '@redwoodjs/project-config' export const command = 'flightcontrol ' export const alias = 'fc' export const description = 'Build, Migrate, and Serve commands for Flightcontrol deploy' + export const builder = (yargs) => { yargs .positional('side', { choices: ['api', 'web'], - description: 'select side to build', + description: 'Side to deploy', type: 'string', }) .option('prisma', { @@ -31,7 +30,7 @@ export const builder = (yargs) => { default: false, }) .option('data-migrate', { - description: 'Migrate the data in your database', + description: 'Apply data migrations', type: 'boolean', default: true, alias: 'dm', @@ -55,45 +54,53 @@ export const handler = async ({ side, serve, prisma, dm: dataMigrate }) => { const rwjsPaths = getPaths() const execaConfig = { + cwd: rwjsPaths.base, shell: true, stdio: 'inherit', - cwd: rwjsPaths.base, - extendEnv: true, - cleanup: true, } async function runApiCommands() { - if (serve) { - console.log('\nStarting api...') - await apiServerHandler({ - port: getConfig().api?.port || 8911, - apiRootPath: '/', - }) - } else { - console.log('\nBuilding api...') - execa.sync('yarn rw build api', execaConfig) + if (!serve) { + console.log('Building api...') + execa.commandSync('yarn rw build api --verbose', execaConfig) - prisma && - execa.sync( - path.join(rwjsPaths.base, 'node_modules/.bin/prisma'), - ['migrate', 'deploy', '--schema', `"${rwjsPaths.api.dbSchema}"`], + if (prisma) { + console.log('Running database migrations...') + execa.commandSync( + `node_modules/.bin/prisma migrate deploy --schema "${rwjsPaths.api.dbSchema}"`, execaConfig ) - dataMigrate && execa.sync('yarn rw dataMigrate up', execaConfig) + } + + if (dataMigrate) { + console.log('Running data migrations...') + execa.commandSync('yarn rw dataMigrate up', execaConfig) + } + + return + } + + const serverFilePath = path.join(rwjsPaths.api.dist, 'server.js') + const hasServerFile = fs.pathExistsSync(serverFilePath) + + if (hasServerFile) { + execa(`yarn node ${serverFilePath}`, execaConfig) + } else { + const { handler } = await import( + '@redwoodjs/api-server/dist/apiCLIConfigHandler.js' + ) + handler() } } async function runWebCommands() { - execa.sync('yarn rw build web', execaConfig) + console.log('Building web...') + execa.commandSync('yarn rw build web --verbose', execaConfig) } if (side === 'api') { runApiCommands() } else if (side === 'web') { - console.log('\nBuilding web...') runWebCommands() - } else { - console.log('Error with arguments provided') - // you broke something, which should be caught by Yargs } } diff --git a/packages/cli/src/commands/devHandler.js b/packages/cli/src/commands/devHandler.js index 16ab1e2b71cd..bd1df26ff710 100644 --- a/packages/cli/src/commands/devHandler.js +++ b/packages/cli/src/commands/devHandler.js @@ -5,11 +5,7 @@ import fs from 'fs-extra' import { recordTelemetryAttributes } from '@redwoodjs/cli-helpers' import { shutdownPort } from '@redwoodjs/internal/dist/dev' -import { - getConfig, - getConfigPath, - resolveFile, -} from '@redwoodjs/project-config' +import { getConfig, getConfigPath } from '@redwoodjs/project-config' import { errorTelemetry } from '@redwoodjs/telemetry' import { getPaths } from '../lib' @@ -17,6 +13,7 @@ import c from '../lib/colors' import { exitWithError } from '../lib/exit' import { generatePrismaClient } from '../lib/generatePrismaClient' import { getFreePort } from '../lib/ports' +import { serverFileExists } from '../lib/project' const defaultApiDebugPort = 18911 @@ -36,8 +33,7 @@ export const handler = async ({ const rwjsPaths = getPaths() - // Check if experimental server file exists - const serverFile = resolveFile(`${rwjsPaths.api.dist}/server`) + const serverFile = serverFileExists() // Starting values of ports from config (redwood.toml) let apiPreferredPort = parseInt(getConfig().api.port) diff --git a/packages/cli/src/commands/experimental/util.js b/packages/cli/src/commands/experimental/util.js index d55b130e787a..7e0e5b9ecc57 100644 --- a/packages/cli/src/commands/experimental/util.js +++ b/packages/cli/src/commands/experimental/util.js @@ -5,7 +5,7 @@ import fs from 'fs-extra' import terminalLink from 'terminal-link' import { getPaths } from '../../lib' -import { isTypeScriptProject } from '../../lib/project' +import { isTypeScriptProject, serverFileExists } from '../../lib/project' const link = (topicId, isTerminal = false) => { const communityLink = `https://community.redwoodjs.com/t/${topicId}` @@ -44,17 +44,8 @@ export const printTaskEpilogue = (command, description, topicId) => { ) } -export const serverFileExists = () => { - const serverFilePath = path.join( - getPaths().api.src, - `server.${isTypeScriptProject() ? 'ts' : 'js'}` - ) - - return fs.existsSync(serverFilePath) -} - export const isServerFileSetup = () => { - if (!serverFileExists) { + if (!serverFileExists()) { throw new Error( 'RedwoodJS Realtime requires a serverful environment. Please run `yarn rw exp setup-server-file` first.' ) diff --git a/packages/cli/src/commands/serve.js b/packages/cli/src/commands/serve.js index 1696b66865cd..168b84558cd0 100644 --- a/packages/cli/src/commands/serve.js +++ b/packages/cli/src/commands/serve.js @@ -10,6 +10,7 @@ import * as webServerCLIConfig from '@redwoodjs/web-server' import { getPaths, getConfig } from '../lib' import c from '../lib/colors' +import { serverFileExists } from '../lib/project.js' import { webSsrServerHandler } from './serveWebHandler' @@ -17,11 +18,6 @@ export const command = 'serve [side]' export const description = 'Start a server for serving both the api and web sides' -function hasServerFile() { - const serverFilePath = path.join(getPaths().api.dist, 'server.js') - return fs.existsSync(serverFilePath) -} - export const builder = async (yargs) => { yargs .command({ @@ -37,7 +33,7 @@ export const builder = async (yargs) => { }) // Run the server file, if it exists, with web side also - if (hasServerFile()) { + if (serverFileExists()) { const { bothServerFileHandler } = await import( './serveBothHandler.js' ) @@ -69,7 +65,7 @@ export const builder = async (yargs) => { }) // Run the server file, if it exists, api side only - if (hasServerFile()) { + if (serverFileExists()) { const { apiServerFileHandler } = await import('./serveApiHandler.js') await apiServerFileHandler(argv) } else { diff --git a/packages/cli/src/commands/setup/deploy/providers/coherenceHandler.js b/packages/cli/src/commands/setup/deploy/providers/coherenceHandler.js index cca4593c5725..97ee306d6e81 100644 --- a/packages/cli/src/commands/setup/deploy/providers/coherenceHandler.js +++ b/packages/cli/src/commands/setup/deploy/providers/coherenceHandler.js @@ -13,6 +13,7 @@ import { import { errorTelemetry } from '@redwoodjs/telemetry' import { printSetupNotes } from '../../../../lib' +import { serverFileExists } from '../../../../lib/project' import { addFilesTask } from '../helpers' const redwoodProjectPaths = getPaths() @@ -106,11 +107,8 @@ async function getCoherenceConfigFileContent() { db = 'postgres' } - const hasServerFile = fs.pathExistsSync( - path.join(getPaths().api.dist, 'server.js') - ) const apiProdCommand = ['yarn', 'rw', 'build', 'api', '&&'] - if (!hasServerFile) { + if (serverFileExists()) { apiProdCommand.push( 'yarn', 'node', diff --git a/packages/cli/src/commands/setup/deploy/templates/flightcontrol.js b/packages/cli/src/commands/setup/deploy/templates/flightcontrol.js index 430d83427e49..9de6a55cbd0f 100644 --- a/packages/cli/src/commands/setup/deploy/templates/flightcontrol.js +++ b/packages/cli/src/commands/setup/deploy/templates/flightcontrol.js @@ -16,6 +16,7 @@ export const flightcontrolConfig = { buildType: 'nixpacks', cpu: 0.5, memory: 1, + installCommand: 'corepack enable && yarn install', buildCommand: 'yarn rw deploy flightcontrol api', startCommand: 'yarn rw deploy flightcontrol api --serve', port: 8911, @@ -32,6 +33,7 @@ export const flightcontrolConfig = { type: 'static', buildType: 'nixpacks', singlePageApp: true, + installCommand: 'corepack enable && yarn install', buildCommand: 'yarn rw deploy flightcontrol web', outputDirectory: 'web/dist', envVariables: { diff --git a/packages/cli/src/commands/setup/deploy/templates/render.js b/packages/cli/src/commands/setup/deploy/templates/render.js index 9c04c8f857bb..cee0297ebc81 100644 --- a/packages/cli/src/commands/setup/deploy/templates/render.js +++ b/packages/cli/src/commands/setup/deploy/templates/render.js @@ -38,7 +38,7 @@ services: plan: free env: node region: oregon - buildCommand: corepack enable && yarn && yarn rw build api + buildCommand: corepack enable && yarn install && yarn rw build api startCommand: yarn rw deploy render api envVars: diff --git a/packages/cli/src/commands/setup/realtime/realtimeHandler.js b/packages/cli/src/commands/setup/realtime/realtimeHandler.js index 006258bdca7d..606d8dcee429 100644 --- a/packages/cli/src/commands/setup/realtime/realtimeHandler.js +++ b/packages/cli/src/commands/setup/realtime/realtimeHandler.js @@ -9,9 +9,7 @@ import { errorTelemetry } from '@redwoodjs/telemetry' import { getPaths, transformTSToJS, writeFile } from '../../../lib' import c from '../../../lib/colors' -import { isTypeScriptProject } from '../../../lib/project' -// Move this check out of experimental when server file is moved as well -import { serverFileExists } from '../../experimental/util' +import { isTypeScriptProject, serverFileExists } from '../../../lib/project' import { setupServerFileTasks } from '../server-file/serverFileHandler' const { version } = JSON.parse( diff --git a/packages/cli/src/lib/project.js b/packages/cli/src/lib/project.js index e5b964c2b467..2be7a7a2cdc2 100644 --- a/packages/cli/src/lib/project.js +++ b/packages/cli/src/lib/project.js @@ -24,3 +24,12 @@ export const sides = () => { } return sides } + +export const serverFileExists = () => { + const serverFilePath = path.join( + getPaths().api.src, + `server.${isTypeScriptProject() ? 'ts' : 'js'}` + ) + + return fs.existsSync(serverFilePath) +} From 571fb251896dd0e3c6223e4a9adb5a137ad23059 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 29 Feb 2024 12:46:08 +0530 Subject: [PATCH 6/8] RSC: Add build step debug logs (#10078) --- packages/vite/src/rsc/rscBuildAnalyze.ts | 4 ++++ packages/vite/src/rsc/rscBuildClient.ts | 4 ++++ packages/vite/src/rsc/rscBuildClientEntriesFile.ts | 4 ++++ packages/vite/src/rsc/rscBuildCopyCssAssets.ts | 4 ++++ packages/vite/src/rsc/rscBuildRwEnvVars.ts | 4 ++++ packages/vite/src/rsc/rscBuildServer.ts | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/packages/vite/src/rsc/rscBuildAnalyze.ts b/packages/vite/src/rsc/rscBuildAnalyze.ts index d1da8a3bc234..d95d3a64f249 100644 --- a/packages/vite/src/rsc/rscBuildAnalyze.ts +++ b/packages/vite/src/rsc/rscBuildAnalyze.ts @@ -15,6 +15,10 @@ import { rscAnalyzePlugin } from './rscVitePlugins' * Doesn't output any files, only collects a list of RSCs and RSFs */ export async function rscBuildAnalyze(viteConfigPath: string) { + console.log('\n') + console.log('1. rscBuildAnalyze') + console.log('==================\n') + const rwPaths = getPaths() const clientEntryFileSet = new Set() const serverEntryFileSet = new Set() diff --git a/packages/vite/src/rsc/rscBuildClient.ts b/packages/vite/src/rsc/rscBuildClient.ts index f1e1b4ce4c13..324a9f873673 100644 --- a/packages/vite/src/rsc/rscBuildClient.ts +++ b/packages/vite/src/rsc/rscBuildClient.ts @@ -21,6 +21,10 @@ export async function rscBuildClient( webDist: string, clientEntryFiles: Record ) { + console.log('\n') + console.log('2. rscBuildClient') + console.log('=================\n') + const rwPaths = getPaths() const clientBuildOutput = await viteBuild({ diff --git a/packages/vite/src/rsc/rscBuildClientEntriesFile.ts b/packages/vite/src/rsc/rscBuildClientEntriesFile.ts index 4c65f2a9d455..3a2797fa2014 100644 --- a/packages/vite/src/rsc/rscBuildClientEntriesFile.ts +++ b/packages/vite/src/rsc/rscBuildClientEntriesFile.ts @@ -14,6 +14,10 @@ export function rscBuildClientEntriesMappings( clientEntryFiles: Record, webDistServerEntries: string ) { + console.log('\n') + console.log('5. rscBuildClientEntriesMapping') + console.log('===============================\n') + const clientEntries: Record = {} for (const item of clientBuildOutput) { const { name, fileName } = item diff --git a/packages/vite/src/rsc/rscBuildCopyCssAssets.ts b/packages/vite/src/rsc/rscBuildCopyCssAssets.ts index 37bf0927246f..893369a1f8f0 100644 --- a/packages/vite/src/rsc/rscBuildCopyCssAssets.ts +++ b/packages/vite/src/rsc/rscBuildCopyCssAssets.ts @@ -12,6 +12,10 @@ export function rscBuildCopyCssAssets( webDist: string, webDistServer: string ) { + console.log('\n') + console.log('4. rscBuildCopyCssAssets') + console.log('========================\n') + // TODO (RSC) Some css is now duplicated in two files (i.e. for client // components). Probably don't want that. // Also not sure if this works on "soft" rerenders (i.e. not a full page diff --git a/packages/vite/src/rsc/rscBuildRwEnvVars.ts b/packages/vite/src/rsc/rscBuildRwEnvVars.ts index d0c767eacea2..4c3fe1d4ef2f 100644 --- a/packages/vite/src/rsc/rscBuildRwEnvVars.ts +++ b/packages/vite/src/rsc/rscBuildRwEnvVars.ts @@ -9,6 +9,10 @@ import fs from 'fs/promises' * RSC worker we've got set up */ export async function rscBuildRwEnvVars(webDistServerEntries: string) { + console.log('\n') + console.log('6. rscBuildRwEnvVars') + console.log('====================\n') + await fs.appendFile( webDistServerEntries, ` diff --git a/packages/vite/src/rsc/rscBuildServer.ts b/packages/vite/src/rsc/rscBuildServer.ts index af3003e08f10..e87735f4c1f5 100644 --- a/packages/vite/src/rsc/rscBuildServer.ts +++ b/packages/vite/src/rsc/rscBuildServer.ts @@ -22,6 +22,10 @@ export async function rscBuildServer( serverEntryFiles: Record, customModules: Record ) { + console.log('\n') + console.log('3. rscBuildServer') + console.log('=================\n') + const input = { entries: entriesFile, ...clientEntryFiles, From fe30874b4072a131720f302bcd88740c52220f54 Mon Sep 17 00:00:00 2001 From: Dominic Saadi Date: Thu, 29 Feb 2024 01:58:43 -0800 Subject: [PATCH 7/8] chore(release): update changelog --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3655c64980c5..edb472409826 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,6 @@ ## Unreleased -- fix(deploy): handle server file (#10061) - - This fixes the CLI commands for Coherence and Flightcontrol. For Coherence, it fixes a bug introduced in the last patch where the logic for detecting the server file in the setup command (`yarn rw setup deploy coherence`) was flipped. For Flightcontrol, it updates the setup command (`yarn rw setup deploy flightcontrol`) so that it handles Corepack and updates the corresponding deploy command (`yarn rw deploy flightcontrol`) so that it detects the server file similar to the Coherence fix. - - fix(deps): update opentelemetry-js monorepo (#10065) Updates our opentelemetry packages. This is a breaking change for users of @@ -56,6 +52,10 @@ Note that this feature is mainly for local scripting. Most deploy providers don't let you upload dotfiles and usually have their own way of determining environments. +## v7.0.5 + +- See https://github.com/redwoodjs/redwood/releases/tag/v7.0.5 + ## v7.0.4 - See https://github.com/redwoodjs/redwood/releases/tag/v7.0.4 From d83d52d2f91afbaafc9e0f32edf4d3d075901057 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 29 Feb 2024 16:58:51 +0530 Subject: [PATCH 8/8] RSC: Fix server build root (#10076) --- .../src/plugins/babel-plugin-redwood-cell.ts | 75 +++++-------------- packages/vite/src/rsc/rscBuildServer.ts | 2 +- 2 files changed, 20 insertions(+), 57 deletions(-) diff --git a/packages/babel-config/src/plugins/babel-plugin-redwood-cell.ts b/packages/babel-config/src/plugins/babel-plugin-redwood-cell.ts index 2a7dd74be9db..9b160d29dfb4 100644 --- a/packages/babel-config/src/plugins/babel-plugin-redwood-cell.ts +++ b/packages/babel-config/src/plugins/babel-plugin-redwood-cell.ts @@ -32,38 +32,18 @@ const EXPECTED_EXPORTS_FROM_CELL = [ ] export default function ({ types: t }: { types: typeof types }): PluginObj { - // This array will - // - collect exports from the Cell file during ExportNamedDeclaration + // This array will collect exports from the Cell file during + // ExportNamedDeclaration // - collected exports will then be passed to `createCell` - // - be cleared after Program exit to prepare for the next file + // - The array is reset every time we `enter` a new Program let exportNames: string[] = [] let hasDefaultExport = false - // TODO (RSC): - // This code relies on the fact that all cells first become client side - // cells. And then we do a second pass over all cells and transform them to - // server cells if applicable - // It'd be better if we could only do one pass over all cells. So the real - // todo here is to first figure out why we do two passes, and then update - // this code to directly generate `createCell` or `createServerCell` HoCs - return { name: 'babel-plugin-redwood-cell', visitor: { - ExportDefaultDeclaration(path) { + ExportDefaultDeclaration() { hasDefaultExport = true - - // This is for RSC cells: - // Determine if this is `export default createCell(...)` - // If it is, then we change it to `export default createServerCell(...)` - const declaration = path.node.declaration - if ( - t.isCallExpression(declaration) && - t.isIdentifier(declaration.callee) && - declaration.callee.name === 'createCell' - ) { - declaration.callee.name = 'createServerCell' - } }, ExportNamedDeclaration(path) { const declaration = path.node.declaration @@ -85,34 +65,6 @@ export default function ({ types: t }: { types: typeof types }): PluginObj { exportNames.push(name) } }, - ImportDeclaration(path) { - // This is for RSC cells: - // Change createCell imports to createServerCell - const source = path.node.source.value - if (source === '@redwoodjs/web') { - const specifiers = path.node.specifiers - const createCellSpecifier: types.ImportSpecifier | undefined = - specifiers.find((specifier): specifier is types.ImportSpecifier => { - return ( - t.isImportSpecifier(specifier) && - t.isIdentifier(specifier.imported) && - specifier.imported.name === 'createCell' - ) - }) - - if ( - createCellSpecifier && - t.isIdentifier(createCellSpecifier.imported) - ) { - createCellSpecifier.imported.name = 'createServerCell' - createCellSpecifier.local.name = 'createServerCell' - - // Also update where we import from - path.node.source.value = - '@redwoodjs/web/dist/components/cell/createServerCell.js' - } - } - }, Program: { enter() { // Reset variables as they're still in scope from the previous file @@ -134,17 +86,28 @@ export default function ({ types: t }: { types: typeof types }): PluginObj { return } + // TODO (RSC): When we want to support `data = async () => {}` in + // client cells as well, we'll need a different heuristic here + // If we want to support `QUERY` (gql) cells on the server we'll + // also need a different heuristic + const createCellHookName = exportNames.includes('data') + ? 'createServerCell' + : 'createCell' + const importFrom = exportNames.includes('data') + ? '@redwoodjs/web/dist/components/cell/createServerCell' + : '@redwoodjs/web' + // Insert at the top of the file: // + import { createCell } from '@redwoodjs/web' path.node.body.unshift( t.importDeclaration( [ t.importSpecifier( - t.identifier('createCell'), - t.identifier('createCell') + t.identifier(createCellHookName), + t.identifier(createCellHookName) ), ], - t.stringLiteral('@redwoodjs/web') + t.stringLiteral(importFrom) ) ) @@ -152,7 +115,7 @@ export default function ({ types: t }: { types: typeof types }): PluginObj { // + export default createCell({ QUERY?, Loading?, Success?, Failure?, Empty?, beforeQuery?, isEmpty, afterQuery?, displayName? }) path.node.body.push( t.exportDefaultDeclaration( - t.callExpression(t.identifier('createCell'), [ + t.callExpression(t.identifier(createCellHookName), [ t.objectExpression([ ...exportNames.map((name) => t.objectProperty( diff --git a/packages/vite/src/rsc/rscBuildServer.ts b/packages/vite/src/rsc/rscBuildServer.ts index e87735f4c1f5..28da442e08fe 100644 --- a/packages/vite/src/rsc/rscBuildServer.ts +++ b/packages/vite/src/rsc/rscBuildServer.ts @@ -45,7 +45,7 @@ export async function rscBuildServer( const serverBuildOutput = await viteBuild({ // ...configFileConfig, - root: rwPaths.web.base, + root: rwPaths.web.src, envPrefix: 'REDWOOD_ENV_', publicDir: path.join(rwPaths.web.base, 'public'), envFile: false,