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

fix: accept absolute paths in vite dev server #16148

Merged
merged 4 commits into from
Apr 22, 2021
Merged
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
15 changes: 10 additions & 5 deletions npm/vite-dev-server/src/makeCypressPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { resolve, sep } from 'path'
import { resolve, posix, sep } from 'path'
import { readFile } from 'fs'
import { promisify } from 'util'
import { Plugin, ViteDevServer } from 'vite'

const read = promisify(readFile)

const pluginName = 'cypress-transform-html'

const OSSepRE = new RegExp(`\\${sep}`, 'g')

const INIT_FILEPATH = resolve(__dirname, '../client/initCypressTests.js').replace(OSSepRE, '/')
function convertPathToPosix (path: string): string {
return sep === '/'
? path
: path.replace(OSSepRE, '/')
}

const INIT_FILEPATH = posix.resolve(__dirname, '../client/initCypressTests.js')

export const makeCypressPlugin = (
projectRoot: string,
Expand All @@ -18,7 +23,7 @@ export const makeCypressPlugin = (
): Plugin => {
let base = '/'

const posixSupportFilePath = supportFilePath ? resolve(projectRoot, supportFilePath).replace(OSSepRE, '/') : undefined
const posixSupportFilePath = supportFilePath ? convertPathToPosix(resolve(projectRoot, supportFilePath)) : undefined

const normalizedSupportFilePath = posixSupportFilePath ? `${base}@fs/${posixSupportFilePath}` : undefined

Expand All @@ -30,7 +35,7 @@ export const makeCypressPlugin = (
return {
define: {
'import.meta.env.__cypress_supportPath': JSON.stringify(normalizedSupportFilePath),
'import.meta.env.__cypress_originAutUrl': JSON.stringify('__cypress/iframes/'),
'import.meta.env.__cypress_originAutUrl': JSON.stringify(`__cypress/iframes/${convertPathToPosix(projectRoot)}/`),
},
}
}
Expand Down