Skip to content

Commit

Permalink
fix isSSR option of resolveOutDir()
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Feb 9, 2025
1 parent acdccff commit f197ca6
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions vike/node/plugin/shared/getOutDirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,27 @@ function getOutDirs(config: ResolvedConfig): OutDirs {

/** Appends `client/` or `server/` to `config.build.outDir` */
function resolveOutDir(config: UserConfig, isSSR?: true): string {
const isServerSide = viteIsSSR(config) || isSSR
debug('resolveOutDir()', new Error().stack)
const isServerSide = viteIsSSR(config) || isSSR
debug('isServerSide', isServerSide)
const outDir = getOutDirFromViteUserConfig(config) || 'dist'
debug('outDir', 'outDir')
// outDir may already be resolved when using Telefunc + vike (because both Telefunc and vike use this logic)
if (!isOutDirRoot(outDir)) {
assertOutDirResolved(outDir, config)
return outDir
debug('outDir', outDir)
/* outDir may already be resolved when using Telefunc + Vike (because both Telefunc and Vike use this logic)
assert(isOutDirRoot(outDir))
*/

const { outDirClient, outDirServer } = getOutDirsAll(outDir)
if (isServerSide) {
debug('outDirServer', 'outDirServer')
return outDirServer
} else {
const { outDirClient, outDirServer } = determineOutDirs(outDir)
if (isServerSide) {
debug('outDirServer', 'outDirServer')
return outDirServer
} else {
debug('outDirClient', 'outDirClient')
return outDirClient
}
debug('outDirClient', 'outDirClient')
return outDirClient
}
}

function determineOutDirs(outDirRoot: string) {
assertPosixPath(outDirRoot)
assert(!outDirRoot.endsWith('/'))
assert(isOutDirRoot(outDirRoot))
const outDirClient = pathJoin(outDirRoot, 'client')
const outDirServer = pathJoin(outDirRoot, 'server')
Expand All @@ -58,7 +56,7 @@ function determineOutDirs(outDirRoot: string) {
return { outDirClient, outDirServer }
}

function getOutDirsAll(outDir: string, root: string) {
function getOutDirsAll(outDir: string, root?: string) {
let outDirRoot: string
{
if (isOutDirRoot(outDir)) {
Expand All @@ -70,13 +68,21 @@ function getOutDirsAll(outDir: string, root: string) {
}
}
debug('outDirRoot', outDirRoot)
const outDirs = getOutDirsAllFromRoot(outDirRoot, root)
let outDirs: OutDirs
if (root) {
outDirs = getOutDirsAllFromRootNormalized(outDirRoot, root)
} else {
outDirs = getOutDirsAllFromRoot(outDirRoot)
}
debug('outDirs', outDirs)
return outDirs
}

function getOutDirsAllFromRoot(outDirRoot: string, root: string): OutDirs {
if (!outDirIsAbsolutePath(outDirRoot)) {
function getOutDirsAllFromRoot(outDirRoot: string) {
let { outDirClient, outDirServer } = determineOutDirs(outDirRoot)
return { outDirRoot, outDirClient, outDirServer }
}
function getOutDirsAllFromRootNormalized(outDirRoot: string, root: string): OutDirs {
if (root && !outDirIsAbsolutePath(outDirRoot)) {
assertPosixPath(outDirRoot)
assertPosixPath(root)
outDirRoot = pathJoin(root, outDirRoot)
Expand All @@ -87,15 +93,15 @@ function getOutDirsAllFromRoot(outDirRoot: string, root: string): OutDirs {
outDirClient = outDirClient + '/'
outDirServer = outDirServer + '/'

assertNormalization(outDirRoot)
assertNormalization(outDirClient)
assertNormalization(outDirServer)
assertNormalization(outDirRoot, root)
assertNormalization(outDirClient, root)
assertNormalization(outDirServer, root)

return { outDirRoot, outDirClient, outDirServer }
}
function assertNormalization(outDirAny: string) {
function assertNormalization(outDirAny: string, root: string | undefined) {
assertPosixPath(outDirAny)
assert(outDirIsAbsolutePath(outDirAny))
if (root) assert(outDirIsAbsolutePath(outDirAny))
assert(outDirAny.endsWith('/'))
assert(!outDirAny.endsWith('//'))
}
Expand Down

0 comments on commit f197ca6

Please sign in to comment.