full site update
This commit is contained in:
7
node_modules/vitefu/package.json
generated
vendored
7
node_modules/vitefu/package.json
generated
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "vitefu",
|
||||
"description": "Utilities for building frameworks with Vite",
|
||||
"version": "1.0.6",
|
||||
"version": "1.1.1",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
"types": "./src/index.d.ts",
|
||||
@@ -30,7 +30,7 @@
|
||||
"test": "uvu tests \".*\\.test\\.js\""
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0"
|
||||
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0-beta.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"vite": {
|
||||
@@ -45,6 +45,7 @@
|
||||
},
|
||||
"workspaces": [
|
||||
"tests/deps/*",
|
||||
"tests/projects/*"
|
||||
"tests/projects/*",
|
||||
"tests/projects/workspace/packages/*"
|
||||
]
|
||||
}
|
||||
|
1
node_modules/vitefu/src/index.d.cts
generated
vendored
1
node_modules/vitefu/src/index.d.cts
generated
vendored
@@ -3,6 +3,7 @@
|
||||
export interface CrawlFrameworkPkgsOptions {
|
||||
root: string
|
||||
isBuild: boolean
|
||||
workspaceRoot?: string
|
||||
viteUserConfig?: any
|
||||
isFrameworkPkgByJson?: (pkgJson: Record<string, any>) => boolean
|
||||
isFrameworkPkgByName?: (pkgName: string) => boolean | undefined
|
||||
|
11
node_modules/vitefu/src/index.d.ts
generated
vendored
11
node_modules/vitefu/src/index.d.ts
generated
vendored
@@ -9,6 +9,15 @@ export interface CrawlFrameworkPkgsOptions {
|
||||
* Whether we're currently in a Vite build
|
||||
*/
|
||||
isBuild: boolean
|
||||
|
||||
/**
|
||||
* Path to workspace root of the project
|
||||
*
|
||||
* setting this enables crawling devDependencies of private packages inside the workspace
|
||||
* you can use `import {searchForWorkspaceRoot} from 'vite'` to find it.
|
||||
*/
|
||||
workspaceRoot?: string
|
||||
|
||||
/**
|
||||
* Optional. If a Vite user config is passed, the output Vite config will respect the
|
||||
* set `optimizeDeps` and `ssr` options so it doesn't override it
|
||||
@@ -89,7 +98,7 @@ export declare function crawlFrameworkPkgs(
|
||||
*/
|
||||
export declare function findDepPkgJsonPath(
|
||||
dep: string,
|
||||
parent: string
|
||||
parent: string,
|
||||
): Promise<string | undefined>
|
||||
|
||||
/**
|
||||
|
55
node_modules/vitefu/src/index.js
generated
vendored
55
node_modules/vitefu/src/index.js
generated
vendored
@@ -11,9 +11,17 @@ import {
|
||||
|
||||
/** @type {import('pnpapi')} */
|
||||
let pnp
|
||||
|
||||
|
||||
/** @type {Array<{ name: string; reference: string; }>} */
|
||||
let pnpWorkspaceLocators;
|
||||
|
||||
if (process.versions.pnp) {
|
||||
try {
|
||||
pnp = createRequire(import.meta.url)('pnpapi')
|
||||
// returns a set of physical locators https://yarnpkg.com/advanced/pnpapi#getdependencytreeroots
|
||||
// @ts-expect-error unfortunately doesn't exist in the `@types` package
|
||||
pnpWorkspaceLocators = pnp.getDependencyTreeRoots()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
@@ -101,11 +109,11 @@ export async function crawlFrameworkPkgs(options) {
|
||||
*/
|
||||
async function crawl(pkgJsonPath, pkgJson, parentDepNames = []) {
|
||||
const isRoot = parentDepNames.length === 0
|
||||
|
||||
const crawlDevDependencies = isRoot || isPrivateWorkspacePackage(pkgJsonPath,pkgJson,options.workspaceRoot)
|
||||
/** @type {string[]} */
|
||||
let deps = [
|
||||
...Object.keys(pkgJson.dependencies || {}),
|
||||
...(isRoot ? Object.keys(pkgJson.devDependencies || {}) : [])
|
||||
...((crawlDevDependencies) ? Object.keys(pkgJson.devDependencies || {}) : [])
|
||||
]
|
||||
|
||||
deps = deps.filter((dep) => {
|
||||
@@ -143,7 +151,7 @@ export async function crawlFrameworkPkgs(options) {
|
||||
})
|
||||
|
||||
const promises = deps.map(async (dep) => {
|
||||
const depPkgJsonPath = await findDepPkgJsonPath(dep, pkgJsonPath)
|
||||
const depPkgJsonPath = await _findDepPkgJsonPath(dep, pkgJsonPath, !!options.workspaceRoot)
|
||||
if (!depPkgJsonPath) return
|
||||
const depPkgJson = await readJson(depPkgJsonPath).catch(() => {})
|
||||
if (!depPkgJson) return
|
||||
@@ -188,10 +196,33 @@ export async function crawlFrameworkPkgs(options) {
|
||||
await Promise.all(promises)
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {import('./index.d.ts').findDepPkgJsonPath} */
|
||||
export async function findDepPkgJsonPath(dep, parent) {
|
||||
return _findDepPkgJsonPath(dep, parent, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* internal implementation to avoid exposing the usePnpWorkspaceLocators flag
|
||||
*
|
||||
* @param {string} dep
|
||||
* @param {string} parent
|
||||
* @param {boolean} usePnpWorkspaceLocators
|
||||
* @returns {Promise<undefined|string>}
|
||||
* @private
|
||||
*/
|
||||
async function _findDepPkgJsonPath(dep, parent, usePnpWorkspaceLocators) {
|
||||
if (pnp) {
|
||||
if(usePnpWorkspaceLocators) {
|
||||
try {
|
||||
// if we're in a workspace and the dep is a workspace dep,
|
||||
// then we'll try to resolve to it's real location
|
||||
const locator = pnpWorkspaceLocators.find((root) => root.name === dep)
|
||||
if (locator) {
|
||||
const pkgPath = pnp.getPackageInformation(locator).packageLocation
|
||||
return path.resolve(pkgPath, 'package.json')
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
try {
|
||||
const depRoot = pnp.resolveToUnqualified(dep, parent)
|
||||
if (!depRoot) return undefined
|
||||
@@ -266,3 +297,19 @@ export async function pkgNeedsOptimization(pkgJson, pkgJsonPath) {
|
||||
async function readJson(findDepPkgJsonPath) {
|
||||
return JSON.parse(await fs.readFile(findDepPkgJsonPath, 'utf8'))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} pkgJsonPath
|
||||
* @param {Record<string,any>} pkgJson
|
||||
* @param {string} [workspaceRoot]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function isPrivateWorkspacePackage(pkgJsonPath,pkgJson,workspaceRoot = undefined) {
|
||||
return !!(
|
||||
workspaceRoot &&
|
||||
pkgJson.private &&
|
||||
!pkgJsonPath.match(/[/\\]node_modules[/\\]/) &&
|
||||
!path.relative(workspaceRoot,pkgJsonPath).startsWith('..')
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user