Skip to content

Commit

Permalink
fix: resolve --root arg
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Aug 10, 2021
1 parent 508589b commit 6a51f2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion vite-plugin-ssr/cli/bin.node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cac } from 'cac'
import { resolve } from 'path'
import { prerender } from '../prerender'
import { projectInfo } from '../utils'

Expand All @@ -18,7 +19,8 @@ cli
.option('--client-router', 'serialize `pageContext` to JSON files for Client-side Routing')
.option('--base <path>', `[string] public base path (default: /)`)
.action(async (options) => {
const { partial, extraDir, clientRouter, base, root } = options
const { partial, extraDir, clientRouter, base } = options
const root = resolve(options.root)
const noExtraDir = !extraDir
await prerender({ partial, noExtraDir, clientRouter, base, root })
})
Expand Down
8 changes: 5 additions & 3 deletions vite-plugin-ssr/prerender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import './page-files/setup.node'
import fs from 'fs'
const { writeFile, mkdir } = fs.promises
import { join, sep, dirname } from 'path'
import { join, sep, dirname, isAbsolute } from 'path'
import { getFilesystemRoute, getPageIds, isErrorPage, isStaticRoute, loadPageRoutes, route } from './route.shared'
import { assert, assertUsage, assertWarning, hasProp, getFileUrl, isPlainObject, castProp, projectInfo } from './utils'
import { moduleExists } from './utils/moduleExists'
Expand Down Expand Up @@ -39,7 +39,7 @@ async function prerender({
clientRouter?: boolean
base?: string
} = {}) {
assertArguments(partial, noExtraDir, clientRouter, base)
assertArguments(partial, noExtraDir, clientRouter, base, root)
console.log(`${cyan(`vite-plugin-ssr ${projectInfo.version}`)} ${green('pre-rendering HTML...')}`)

const { pluginManifest, pluginManifestPath } = getPluginManifest(root)
Expand Down Expand Up @@ -319,9 +319,11 @@ function getPluginManifest(root: string): {
return { pluginManifest, pluginManifestPath }
}

function assertArguments(partial: unknown, noExtraDir: unknown, clientRouter: unknown, base: unknown) {
function assertArguments(partial: unknown, noExtraDir: unknown, clientRouter: unknown, base: unknown, root: unknown) {
assertUsage(partial === true || partial === false, '[prerender()] Option `partial` should be a boolean.')
assertUsage(noExtraDir === true || noExtraDir === false, '[prerender()] Option `noExtraDir` should be a boolean.')
assertWarning(clientRouter === false, '[prerender()] Option `clientRouter` is deprecated and has no-effect.')
assertWarning(base === undefined, '[prerender()] Option `base` is deprecated and has no-effect.')
assertUsage(typeof root === 'string', '[prerender()] Option `root` should be a string.')
assertUsage(isAbsolute(root), '[prerender()] The path `root` is not absolute. Make sure to provide an absolute path.')
}

0 comments on commit 6a51f2a

Please sign in to comment.