Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(build): properly resolve node_modules (#1337)
  • Loading branch information
brc-dd committed Sep 14, 2022
1 parent 5868a2e commit 0672a69
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -148,6 +148,7 @@
"npm-run-all": "^4.1.5",
"ora": "^5.4.1",
"picocolors": "^1.0.0",
"pkg-dir": "^5.0.0",
"playwright-chromium": "^1.25.1",
"polka": "^0.5.2",
"prettier": "^2.7.1",
Expand Down
45 changes: 44 additions & 1 deletion pnpm-lock.yaml

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

22 changes: 13 additions & 9 deletions src/node/build/build.ts
Expand Up @@ -8,6 +8,7 @@ import { renderPage } from './render'
import { bundle, okMark, failMark } from './bundle'
import { createRequire } from 'module'
import { pathToFileURL } from 'url'
import pkgDir from 'pkg-dir'

export async function build(
root?: string,
Expand All @@ -17,7 +18,7 @@ export async function build(

process.env.NODE_ENV = 'production'
const siteConfig = await resolveConfig(root, 'build', 'production')
const unlinkVue = linkVue(siteConfig.root)
const unlinkVue = linkVue()

if (buildOptions.base) {
siteConfig.site.base = buildOptions.base
Expand Down Expand Up @@ -106,14 +107,17 @@ export async function build(
console.log(`build complete in ${((Date.now() - start) / 1000).toFixed(2)}s.`)
}

function linkVue(root: string) {
const dest = path.resolve(root, 'node_modules/vue')
// if user did not install vue by themselves, link VitePress' version
if (!fs.existsSync(dest)) {
const src = path.dirname(createRequire(import.meta.url).resolve('vue'))
fs.ensureSymlinkSync(src, dest, 'junction')
return () => {
fs.unlinkSync(dest)
function linkVue() {
const root = pkgDir.sync()
if (root) {
const dest = path.resolve(root, 'node_modules/vue')
// if user did not install vue by themselves, link VitePress' version
if (!fs.existsSync(dest)) {
const src = path.dirname(createRequire(import.meta.url).resolve('vue'))
fs.ensureSymlinkSync(src, dest, 'junction')
return () => {
fs.unlinkSync(dest)
}
}
}
return () => {}
Expand Down

0 comments on commit 0672a69

Please sign in to comment.