Skip to content
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
3 changes: 3 additions & 0 deletions packages/plugin-rsc/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ Best for testing specific edge cases or isolated features. See `e2e/ssr-thenable
# Build packages
pnpm dev # pnpm -C packages/plugin-rsc dev

# Type check
pnpm -C packages/plugin-rsc tsc-dev

# Run examples
pnpm -C packages/plugin-rsc/examples/basic dev # build / preview
pnpm -C packages/plugin-rsc/examples/starter dev # build / preview
Expand Down
18 changes: 13 additions & 5 deletions packages/plugin-rsc/e2e/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function editFileJson(filepath: string, edit: (s: string) => string) {
export async function setupInlineFixture(options: {
src: string
dest: string
files?: Record<string, string>
files?: Record<string, string | { cp: string }>
}) {
fs.rmSync(options.dest, { recursive: true, force: true })
fs.mkdirSync(options.dest, { recursive: true })
Expand All @@ -214,16 +214,24 @@ export async function setupInlineFixture(options: {
// write additional files
if (options.files) {
for (let [filename, contents] of Object.entries(options.files)) {
let filepath = path.join(options.dest, filename)
fs.mkdirSync(path.dirname(filepath), { recursive: true })
// strip indent
const destFile = path.join(options.dest, filename)
fs.mkdirSync(path.dirname(destFile), { recursive: true })

// custom command
if (typeof contents === 'object' && 'cp' in contents) {
const srcFile = path.join(options.dest, contents.cp)
fs.copyFileSync(srcFile, destFile)
continue
}

// write a new file
contents = contents.replace(/^\n*/, '').replace(/\s*$/, '\n')
const indent = contents.match(/^\s*/)?.[0] ?? ''
const strippedContents = contents
.split('\n')
.map((line) => line.replace(new RegExp(`^${indent}`), ''))
.join('\n')
fs.writeFileSync(filepath, strippedContents)
fs.writeFileSync(destFile, strippedContents)
}
}
}
58 changes: 21 additions & 37 deletions packages/plugin-rsc/e2e/starter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,28 @@ test.describe(() => {
src: 'examples/starter',
dest: root,
files: {
'vite.config.base.ts': { cp: 'vite.config.ts' },
'vite.config.ts': /* js */ `
import rsc from '@vitejs/plugin-rsc'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { defineConfig, mergeConfig } from 'vite'
import baseConfig from './vite.config.base.ts'

delete baseConfig.plugins

export default defineConfig({
const overrideConfig = defineConfig({
plugins: [
react({
babel: { plugins: ['babel-plugin-react-compiler'] },
}).map((p) => ({
...p,
applyToEnvironment: (e) => e.name === 'client',
})),
rsc({
entries: {
client: './src/framework/entry.browser.tsx',
ssr: './src/framework/entry.ssr.tsx',
rsc: './src/framework/entry.rsc.tsx',
}
}),
rsc(),
],
})

export default mergeConfig(baseConfig, overrideConfig)
`,
},
})
Expand Down Expand Up @@ -145,24 +145,16 @@ test.describe(() => {
src: 'examples/starter',
dest: root,
files: {
'vite.config.base.ts': { cp: 'vite.config.ts' },
'vite.config.ts': /* js */ `
import rsc from '@vitejs/plugin-rsc'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { defineConfig, mergeConfig } from 'vite'
import baseConfig from './vite.config.base.ts'

export default defineConfig({
const overrideConfig = defineConfig({
base: '/custom-base/',
plugins: [
react(),
rsc({
entries: {
client: './src/framework/entry.browser.tsx',
ssr: './src/framework/entry.ssr.tsx',
rsc: './src/framework/entry.rsc.tsx',
}
}),
],
})

export default mergeConfig(baseConfig, overrideConfig)
`,
},
})
Expand Down Expand Up @@ -193,22 +185,12 @@ test.describe(() => {
src: 'examples/starter',
dest: root,
files: {
'vite.config.base.ts': { cp: 'vite.config.ts' },
'vite.config.ts': /* js */ `
import rsc from '@vitejs/plugin-rsc'
import react from '@vitejs/plugin-react'
import { defineConfig, createRunnableDevEnvironment } from 'vite'
import { defineConfig, mergeConfig, createRunnableDevEnvironment } from 'vite'
import baseConfig from './vite.config.base.ts'

export default defineConfig({
plugins: [
react(),
rsc({
entries: {
client: './src/framework/entry.browser.tsx',
ssr: './src/framework/entry.ssr.tsx',
rsc: './src/framework/entry.rsc.tsx',
}
}),
],
const overrideConfig = defineConfig({
environments: {
ssr: {
dev: {
Expand All @@ -234,6 +216,8 @@ test.describe(() => {
},
},
})

export default mergeConfig(baseConfig, overrideConfig)
`,
},
})
Expand Down
Loading