Skip to content

Commit

Permalink
fix: path resolve on Windows, close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 5, 2021
1 parent a2564ba commit 6a2d9e5
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"devDependencies": {
"@antfu/eslint-config": "^0.6.4",
"@antfu/ni": "^0.7.0",
"@antfu/utils": "^0.1.4",
"@antfu/utils": "^0.1.5",
"@slidev/cli": "workspace:*",
"@slidev/parser": "workspace:*",
"@types/cli-progress": "^3.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"homepage": "https://sli.dev",
"bugs": "https://github.com/slidevjs/slidev/issues",
"dependencies": {
"@antfu/utils": "^0.1.4",
"@antfu/utils": "^0.1.5",
"@slidev/parser": "workspace:*",
"@slidev/types": "workspace:*",
"@vueuse/core": "^4.9.1",
Expand Down
5 changes: 3 additions & 2 deletions packages/slidev/node/common.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { promises as fs, existsSync } from 'fs'
import { join, posix } from 'path'
import { join } from 'path'
import { uniq } from '@antfu/utils'
import { ResolvedSlidevOptions } from './options'
import { toAtFS } from './utils'

export async function getIndexHtml({ clientRoot, themeRoots }: ResolvedSlidevOptions): Promise<string> {
let main = await fs.readFile(join(clientRoot, 'index.html'), 'utf-8')
Expand All @@ -25,7 +26,7 @@ export async function getIndexHtml({ clientRoot, themeRoots }: ResolvedSlidevOpt
}

main = main
.replace('__ENTRY__', `/@fs${posix.join(clientRoot, 'main.ts')}`)
.replace('__ENTRY__', toAtFS(join(clientRoot, 'main.ts')))
.replace('<!-- head -->', head)
.replace('<!-- body -->', body)

Expand Down
3 changes: 2 additions & 1 deletion packages/slidev/node/plugins/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { existsSync } from 'fs'
import { join, resolve } from 'path'
import { Plugin } from 'vite'
import { ResolvedSlidevOptions } from '../options'
import { toAtFS } from '../utils'

export function createEntryPlugin({ clientRoot, themeRoots, userRoot }: ResolvedSlidevOptions): Plugin {
const mainEntry = resolve(clientRoot, 'main.ts')
Expand All @@ -24,7 +25,7 @@ export function createEntryPlugin({ clientRoot, themeRoots, userRoot }: Resolved

for (const style of styles) {
if (existsSync(style)) {
imports.push(`import "/@fs${style}"`)
imports.push(`import "${toAtFS(style)}"`)
return
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/slidev/node/plugins/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import mila from 'markdown-it-link-attributes'
import { SlideInfo, SlideInfoExtended } from '@slidev/types'
import * as parser from '@slidev/parser/fs'
import { ResolvedSlidevOptions, SlidevPluginOptions } from '../options'
import { toAtFS } from '../utils'

const regexId = /^\/\@slidev\/slide\/(\d+)\.(md|json)(?:\?import)?$/
const regexIdQuery = /(\d+?)\.(md|json)$/
Expand Down Expand Up @@ -210,8 +211,8 @@ export function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRo
throw new Error(`Unknown layout "${layoutName}"`)

const imports = [
`import InjectedLayout from "/@fs${layouts[layoutName]}"`,
`import { next, nextSlide, prev, prevSlide } from "/@fs${clientRoot}/logic/nav"`,
`import InjectedLayout from "${toAtFS(layouts[layoutName])}"`,
`import { next, nextSlide, prev, prevSlide } from "${toAtFS(clientRoot)}/logic/nav"`,
]

code = code.replace(/(<script setup.*>)/g, `$1${imports.join('\n')}\n`)
Expand Down Expand Up @@ -253,7 +254,7 @@ export function createSlidesLoader({ data, entry, clientRoot, themeRoots, userRo
const layouts = objectMap(
await getLayouts(),
(k, v) => {
imports.push(`import __layout_${k} from "/@fs${v}"`)
imports.push(`import __layout_${k} from "${toAtFS(v)}"`)
return [k, `__layout_${k}`]
},
)
Expand Down
3 changes: 2 additions & 1 deletion packages/slidev/node/plugins/setupClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join, resolve } from 'path'
import { slash } from '@antfu/utils'
import { Plugin } from 'vite'
import { ResolvedSlidevOptions } from '../options'
import { toAtFS } from '../utils'

export function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }: ResolvedSlidevOptions): Plugin {
const setupEntry = slash(resolve(clientRoot, 'setup'))
Expand All @@ -26,7 +27,7 @@ export function createClientSetupPlugin({ clientRoot, themeRoots, userRoot }: Re
if (!existsSync(path))
return

imports.push(`import __n${idx} from '/@fs${slash(path)}'`)
imports.push(`import __n${idx} from '${toAtFS(path)}'`)
injections.push(
`// ${path}`,
`__n${idx}()`,
Expand Down
5 changes: 5 additions & 0 deletions packages/slidev/node/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ensurePrefix, slash } from '@antfu/utils'

export function toAtFS(path: string) {
return `/@fs${ensurePrefix('/', slash(path))}`
}
2 changes: 1 addition & 1 deletion packages/slidev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
},
"dependencies": {
"@antfu/utils": "^0.1.4",
"@antfu/utils": "^0.1.5",
"@iconify/json": "^1.1.338",
"@slidev/client": "workspace:*",
"@slidev/parser": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dev": "nr build --watch"
},
"devDependencies": {
"@antfu/utils": "^0.1.4",
"@antfu/utils": "^0.1.5",
"monaco-editor": "^0.23.0",
"shiki": "^0.9.3",
"vue": "^3.0.11",
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a2d9e5

Please sign in to comment.