Skip to content

Commit

Permalink
RSC: Patch vite when running setup command (#9192)
Browse files Browse the repository at this point in the history
This is needed until vitejs/vite#13487 is merged
and released and RW uses that new version of Vite
  • Loading branch information
Tobbe committed Sep 17, 2023
1 parent a436b1c commit a7bab85
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/cli/src/commands/experimental/setupRscHandler.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs'
import path from 'path'

import execa from 'execa'
import { Listr } from 'listr2'

import { getConfig, getConfigPath } from '@redwoodjs/project-config'
Expand Down Expand Up @@ -184,6 +185,46 @@ export const handler = async ({ force, verbose }) => {
})
},
},
{
title: 'Patch vite',
task: async () => {
const vitePatchTemplate = fs.readFileSync(
path.resolve(
__dirname,
'templates',
'rsc',
'vite-npm-4.4.9-e845c1bbf8.patch.template'
),
'utf-8'
)

const yarnPatchDir = path.join(rwPaths.base, '.yarn', 'patches')
const vitePatchPath = path.join(
yarnPatchDir,
'vite-npm-4.4.9-e845c1bbf8.patch'
)
writeFile(vitePatchPath, vitePatchTemplate, {
overwriteExisting: force,
})

const packageJsonPath = path.join(rwPaths.base, 'package.json')
const packageJson = JSON.parse(
fs.readFileSync(packageJsonPath, 'utf-8')
)
packageJson.resolutions = packageJson.resolutions || {}
packageJson.resolutions['vite@4.4.9'] =
'patch:vite@npm%3A4.4.9#./.yarn/patches/vite-npm-4.4.9-e845c1bbf8.patch'
writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2), {
overwriteExisting: true,
})

await execa('yarn install', {
stdio: 'ignore',
shell: true,
cwd: rwPaths.base,
})
},
},
{
task: () => {
printTaskEpilogue(command, description, EXPERIMENTAL_TOPIC_ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/dist/node/chunks/dep-df561101.js b/dist/node/chunks/dep-df561101.js
index 1bc8674177fe73120171b22436e6104713c5d764..f0fee7b385868cb01c6d47b80d7f64a7368c0412 100644
--- a/dist/node/chunks/dep-df561101.js
+++ b/dist/node/chunks/dep-df561101.js
@@ -55890,12 +55890,12 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
};
urlStack = urlStack.concat(url);
const isCircular = (url) => urlStack.includes(url);
- const { isProduction, resolve: { dedupe, preserveSymlinks }, root, } = server.config;
+ const { isProduction, resolve: { dedupe, preserveSymlinks, conditions }, root, } = server.config;
const resolveOptions = {
mainFields: ['main'],
browserField: true,
conditions: [],
- overrideConditions: ['production', 'development'],
+ overrideConditions: [...conditions, 'production', 'development'],
extensions: ['.js', '.cjs', '.json'],
dedupe,
preserveSymlinks,

0 comments on commit a7bab85

Please sign in to comment.