Skip to content

Commit

Permalink
chore: fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Apr 8, 2023
1 parent 2a7d225 commit 806b725
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/vite/src/node/optimizer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from '../utils'
import { transformWithEsbuild } from '../plugins/esbuild'
import { ESBUILD_MODULES_TARGET } from '../constants'
import { resolvePackageData } from '../packages'
import type { ViteDevServer } from '../server'
import { esbuildCjsExternalPlugin, esbuildDepPlugin } from './esbuildDepPlugin'
import { scanImports } from './scan'
Expand Down
26 changes: 18 additions & 8 deletions packages/vite/src/node/optimizer/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import path from 'node:path'
import glob from 'fast-glob'
import micromatch from 'micromatch'
import type { ResolvedConfig } from '../config'
import {
escapeRegex,
getNpmPackageName,
nestedResolveFrom,
slash,
} from '../utils'
import { escapeRegex, getNpmPackageName, slash } from '../utils'
import { resolvePackageData } from '../packages'

export function createOptimizeDepsIncludeResolver(
Expand All @@ -19,6 +14,7 @@ export function createOptimizeDepsIncludeResolver(
scan: true,
ssrOptimizeCheck: ssr,
ssrConfig: config.ssr,
packageCache: new Map(),
})
return async (id: string) => {
const lastArrowIndex = id.lastIndexOf('>')
Expand All @@ -29,11 +25,10 @@ export function createOptimizeDepsIncludeResolver(
// 'foo > bar > baz' => 'foo > bar' & 'baz'
const nestedRoot = id.substring(0, lastArrowIndex).trim()
const nestedPath = id.substring(lastArrowIndex + 1).trim()
const basedir = nestedResolveFrom(
const basedir = nestedResolveBasedir(
nestedRoot,
config.root,
config.resolve.preserveSymlinks,
ssr,
)
return await resolve(nestedPath, basedir, undefined, ssr)
}
Expand Down Expand Up @@ -156,3 +151,18 @@ function getFirstExportStringValue(
}
}
}

/**
* Continuously resolve the basedir of packages separated by '>'
*/
function nestedResolveBasedir(
id: string,
basedir: string,
preserveSymlinks = false,
) {
const pkgs = id.split('>').map((pkg) => pkg.trim())
for (const pkg of pkgs) {
basedir = resolvePackageData(pkg, basedir, preserveSymlinks)?.dir || basedir
}
return basedir
}

0 comments on commit 806b725

Please sign in to comment.