fix(build): properly resolve node_modules (#1337)

pull/1338/head
Divyansh Singh 2 years ago committed by GitHub
parent 5868a2e373
commit 0672a696a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -148,6 +148,7 @@
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"ora": "^5.4.1", "ora": "^5.4.1",
"picocolors": "^1.0.0", "picocolors": "^1.0.0",
"pkg-dir": "^5.0.0",
"playwright-chromium": "^1.25.1", "playwright-chromium": "^1.25.1",
"polka": "^0.5.2", "polka": "^0.5.2",
"prettier": "^2.7.1", "prettier": "^2.7.1",

@ -66,6 +66,7 @@ importers:
nprogress: ^0.2.0 nprogress: ^0.2.0
ora: ^5.4.1 ora: ^5.4.1
picocolors: ^1.0.0 picocolors: ^1.0.0
pkg-dir: ^5.0.0
playwright-chromium: ^1.25.1 playwright-chromium: ^1.25.1
polka: ^0.5.2 polka: ^0.5.2
prettier: ^2.7.1 prettier: ^2.7.1
@ -153,6 +154,7 @@ importers:
npm-run-all: 4.1.5 npm-run-all: 4.1.5
ora: 5.4.1 ora: 5.4.1
picocolors: 1.0.0 picocolors: 1.0.0
pkg-dir: 5.0.0
playwright-chromium: 1.25.1 playwright-chromium: 1.25.1
polka: 0.5.2 polka: 0.5.2
prettier: 2.7.1 prettier: 2.7.1
@ -1550,8 +1552,8 @@ packages:
engines: {node: '>=10'} engines: {node: '>=10'}
hasBin: true hasBin: true
dependencies: dependencies:
is-text-path: 1.0.1
JSONStream: 1.3.5 JSONStream: 1.3.5
is-text-path: 1.0.1
lodash: 4.17.21 lodash: 4.17.21
meow: 8.1.2 meow: 8.1.2
split2: 3.2.2 split2: 3.2.2
@ -2018,6 +2020,14 @@ packages:
path-exists: 4.0.0 path-exists: 4.0.0
dev: true dev: true
/find-up/5.0.0:
resolution: {integrity: sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==}
engines: {node: '>=10'}
dependencies:
locate-path: 6.0.0
path-exists: 4.0.0
dev: true
/follow-redirects/1.15.1_debug@4.3.4: /follow-redirects/1.15.1_debug@4.3.4:
resolution: {integrity: sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==} resolution: {integrity: sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==}
engines: {node: '>=4.0'} engines: {node: '>=4.0'}
@ -2610,6 +2620,13 @@ packages:
p-locate: 4.1.0 p-locate: 4.1.0
dev: true dev: true
/locate-path/6.0.0:
resolution: {integrity: sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==}
engines: {node: '>=10'}
dependencies:
p-locate: 5.0.0
dev: true
/lodash.ismatch/4.4.0: /lodash.ismatch/4.4.0:
resolution: {integrity: sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==} resolution: {integrity: sha512-fPMfXjGQEV9Xsq/8MTSgUf255gawYRbjwMyDbcvDhXgV7enSZA0hynz6vMPnpAb5iONEzBHBPsT+0zes5Z301g==}
dev: true dev: true
@ -2970,6 +2987,13 @@ packages:
p-try: 2.2.0 p-try: 2.2.0
dev: true dev: true
/p-limit/3.1.0:
resolution: {integrity: sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==}
engines: {node: '>=10'}
dependencies:
yocto-queue: 0.1.0
dev: true
/p-locate/2.0.0: /p-locate/2.0.0:
resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==} resolution: {integrity: sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==}
engines: {node: '>=4'} engines: {node: '>=4'}
@ -2984,6 +3008,13 @@ packages:
p-limit: 2.3.0 p-limit: 2.3.0
dev: true dev: true
/p-locate/5.0.0:
resolution: {integrity: sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==}
engines: {node: '>=10'}
dependencies:
p-limit: 3.1.0
dev: true
/p-map/4.0.0: /p-map/4.0.0:
resolution: {integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==} resolution: {integrity: sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==}
engines: {node: '>=10'} engines: {node: '>=10'}
@ -3093,6 +3124,13 @@ packages:
engines: {node: '>=4'} engines: {node: '>=4'}
dev: true dev: true
/pkg-dir/5.0.0:
resolution: {integrity: sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==}
engines: {node: '>=10'}
dependencies:
find-up: 5.0.0
dev: true
/playwright-chromium/1.25.1: /playwright-chromium/1.25.1:
resolution: {integrity: sha512-X/B6ycySwV4L+smHu9t+rytPnBLCLI5RAV5TpjVwInv6RPYF6TWZ62zymwiSLxYXeNkyyx0pxTS7jqeOEmMM2g==} resolution: {integrity: sha512-X/B6ycySwV4L+smHu9t+rytPnBLCLI5RAV5TpjVwInv6RPYF6TWZ62zymwiSLxYXeNkyyx0pxTS7jqeOEmMM2g==}
engines: {node: '>=14'} engines: {node: '>=14'}
@ -4026,3 +4064,8 @@ packages:
y18n: 5.0.8 y18n: 5.0.8
yargs-parser: 20.2.9 yargs-parser: 20.2.9
dev: true dev: true
/yocto-queue/0.1.0:
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
engines: {node: '>=10'}
dev: true

@ -8,6 +8,7 @@ import { renderPage } from './render'
import { bundle, okMark, failMark } from './bundle' import { bundle, okMark, failMark } from './bundle'
import { createRequire } from 'module' import { createRequire } from 'module'
import { pathToFileURL } from 'url' import { pathToFileURL } from 'url'
import pkgDir from 'pkg-dir'
export async function build( export async function build(
root?: string, root?: string,
@ -17,7 +18,7 @@ export async function build(
process.env.NODE_ENV = 'production' process.env.NODE_ENV = 'production'
const siteConfig = await resolveConfig(root, 'build', 'production') const siteConfig = await resolveConfig(root, 'build', 'production')
const unlinkVue = linkVue(siteConfig.root) const unlinkVue = linkVue()
if (buildOptions.base) { if (buildOptions.base) {
siteConfig.site.base = buildOptions.base siteConfig.site.base = buildOptions.base
@ -106,14 +107,17 @@ export async function build(
console.log(`build complete in ${((Date.now() - start) / 1000).toFixed(2)}s.`) console.log(`build complete in ${((Date.now() - start) / 1000).toFixed(2)}s.`)
} }
function linkVue(root: string) { function linkVue() {
const dest = path.resolve(root, 'node_modules/vue') const root = pkgDir.sync()
// if user did not install vue by themselves, link VitePress' version if (root) {
if (!fs.existsSync(dest)) { const dest = path.resolve(root, 'node_modules/vue')
const src = path.dirname(createRequire(import.meta.url).resolve('vue')) // if user did not install vue by themselves, link VitePress' version
fs.ensureSymlinkSync(src, dest, 'junction') if (!fs.existsSync(dest)) {
return () => { const src = path.dirname(createRequire(import.meta.url).resolve('vue'))
fs.unlinkSync(dest) fs.ensureSymlinkSync(src, dest, 'junction')
return () => {
fs.unlinkSync(dest)
}
} }
} }
return () => {} return () => {}

Loading…
Cancel
Save