mirror of
https://github.com/tuono-labs/tuono
synced 2026-07-25 12:52:47 -07:00
fix(packages/tuono): build error when config contains vite plugins (#415)
This commit is contained in:
committed by
GitHub
parent
dcedb1c6c0
commit
21ee89ada4
@@ -0,0 +1,32 @@
|
||||
import fs from 'fs/promises'
|
||||
|
||||
import { describe, expect, it, vitest } from 'vitest'
|
||||
import react from '@vitejs/plugin-react-swc'
|
||||
|
||||
import { createJsonConfig } from './create-json-config'
|
||||
|
||||
const writeFileSpy = vitest.spyOn(fs, 'writeFile').mockResolvedValue(void 0)
|
||||
|
||||
describe('createJsonConfig', () => {
|
||||
const sampleConfig = { server: { host: 'h', port: 1 } }
|
||||
|
||||
it('should process config with only server property', async () => {
|
||||
await createJsonConfig(sampleConfig)
|
||||
|
||||
expect(writeFileSpy).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.stringContaining(JSON.stringify(sampleConfig)),
|
||||
expect.any(String),
|
||||
)
|
||||
})
|
||||
|
||||
it('should process config with plugins', async () => {
|
||||
await createJsonConfig({ ...sampleConfig, vite: { plugins: [react()] } })
|
||||
|
||||
expect(writeFileSpy).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
expect.stringContaining(JSON.stringify(sampleConfig)),
|
||||
expect.any(String),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -21,9 +21,25 @@ const CONFIG_PATH = path.join(
|
||||
function removeViteProperties(
|
||||
config: InternalTuonoConfig,
|
||||
): Omit<InternalTuonoConfig, 'vite'> {
|
||||
const newConfig = structuredClone(config)
|
||||
delete newConfig['vite']
|
||||
return newConfig
|
||||
/**
|
||||
* Using {@link structuredClone} cause the following errors based on runtime env:
|
||||
* ```text
|
||||
* node
|
||||
* DOMException [DataCloneError]: configureServer(s){a.push(s)} could not be cloned.
|
||||
*
|
||||
* vitest
|
||||
* DataCloneError: (id) => id === runtimePublicPath ? id : void 0 could not be cloned.
|
||||
* ```
|
||||
* when vite plugins are passed inside to the config.
|
||||
*
|
||||
* Since the purpose of this function is to remove the vite object
|
||||
* we are going to use destructing rather than {@link structuredClone} and `delete`
|
||||
*
|
||||
* @see https://github.com/tuono-labs/tuono/issues/414
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const { vite, ...configRest } = config
|
||||
return structuredClone(configRest)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user