From bef82fa985be8273198a3de5e3b8766af6698dda Mon Sep 17 00:00:00 2001 From: Divyansh Singh <40380293+brc-dd@users.noreply.github.com> Date: Sat, 28 May 2022 18:31:15 +0530 Subject: [PATCH] fix: convert paths in dynamic imports to file urls --- package.json | 2 +- src/node/build/render.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 949d176b..7c4e2142 100644 --- a/package.json +++ b/package.json @@ -151,7 +151,7 @@ } }, "simple-git-hooks": { - "pre-commit": "lint-staged" + "pre-commit": "pnpm lint-staged" }, "lint-staged": { "*": [ diff --git a/src/node/build/render.ts b/src/node/build/render.ts index 87bd2e45..72bc71ac 100644 --- a/src/node/build/render.ts +++ b/src/node/build/render.ts @@ -1,7 +1,7 @@ import { createRequire } from 'module' import fs from 'fs-extra' import path from 'path' -import escape from 'escape-html' +import { pathToFileURL } from 'url' import { normalizePath, transformWithEsbuild } from 'vite' import { RollupOutput, OutputChunk, OutputAsset } from 'rollup' import { HeadConfig, createTitle } from '../shared' @@ -19,7 +19,9 @@ export async function renderPage( pageToHashMap: Record, hashMapString: string ) { - const { createApp } = await import(path.join(config.tempDir, `app.js`)) + const { createApp } = await import( + pathToFileURL(path.join(config.tempDir, `app.js`)).toString() + ) const { app, router } = createApp() const routePath = `/${page.replace(/\.md$/, '')}` const siteData = resolveSiteDataByRoute(config.site, routePath) @@ -37,7 +39,9 @@ export async function renderPage( } // render page - const content = await import(rendererPath).then((r) => r.renderToString(app)) + const content = await import(pathToFileURL(rendererPath).toString()).then( + (r) => r.renderToString(app) + ) const pageName = page.replace(/\//g, '_') // server build doesn't need hash @@ -49,7 +53,7 @@ export async function renderPage( // resolve page data so we can render head tags const { __pageData } = await import( - path.join(config.tempDir, pageServerJsFileName) + pathToFileURL(path.join(config.tempDir, pageServerJsFileName)).toString() ) const pageData = JSON.parse(__pageData)