-
Notifications
You must be signed in to change notification settings - Fork 93
feat: Yarn PnP support #370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,5 +70,8 @@ | |
| "vite": "^5.4.3", | ||
| "vitest": "^2.1.1", | ||
| "wait-on": "^8.0.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "vite": "*" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,24 @@ | ||
| import { existsSync, mkdirSync, writeFile, writeFileSync } from 'fs'; | ||
| import { dirname, join, parse, resolve, basename } from 'pathe'; | ||
| import { basename, join, resolve } from 'pathe'; | ||
| import { packageNameDecode, packageNameEncode } from '../utils/packageNameUtils'; | ||
| import { getNormalizeModuleFederationOptions } from './normalizeModuleFederationOptions'; | ||
|
|
||
| // Cache root path | ||
| let rootDir: string | undefined; | ||
|
|
||
| function findNodeModulesDir(root: string = process.cwd()) { | ||
| let currentDir = root; | ||
|
|
||
| while (currentDir !== parse(currentDir).root) { | ||
| const nodeModulesPath = join(currentDir, 'node_modules'); | ||
| if (existsSync(nodeModulesPath)) { | ||
| return nodeModulesPath; | ||
| } | ||
| currentDir = dirname(currentDir); | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
|
|
||
| // Cache nodeModulesDir result to avoid repeated calculations | ||
| let cachedNodeModulesDir: string | undefined; | ||
|
|
||
| function getNodeModulesDir() { | ||
| if (!cachedNodeModulesDir) { | ||
| cachedNodeModulesDir = findNodeModulesDir(rootDir); | ||
| if (cachedNodeModulesDir) { | ||
| return cachedNodeModulesDir; | ||
| } | ||
| const targetRoot = rootDir || process.cwd(); | ||
| const nodeModulesPath = join(targetRoot, 'node_modules'); | ||
| if (!existsSync(nodeModulesPath)) { | ||
| mkdirSync(nodeModulesPath, { recursive: true }); | ||
| } | ||
| cachedNodeModulesDir = nodeModulesPath; | ||
| return cachedNodeModulesDir; | ||
|
Comment on lines
+16
to
22
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using vite project's root instead of traversing for existing folder because pnp doesn't generate node_modules and this seems more natural
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, I'm not sure if this is working on monorepo projects. cc @Xeikim you added this fix long time ago for monorepos.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original problem was that rootDir find traversal was using process.cwd not the actual vite project's root
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
|
|
@@ -89,18 +81,17 @@ export default class VirtualModule { | |
| const virtualPackagePath = resolve(nodeModulesDir, virtualModuleDir); | ||
|
|
||
| if (!existsSync(virtualPackagePath)) { | ||
| mkdirSync(virtualPackagePath); | ||
| mkdirSync(virtualPackagePath, { recursive: true }); | ||
| writeFileSync(resolve(virtualPackagePath, 'empty.js'), ''); | ||
| writeFileSync( | ||
| resolve(virtualPackagePath, 'package.json'), | ||
| JSON.stringify({ | ||
| name: virtualModuleDir, | ||
| main: 'empty.js', | ||
| }) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| static getVirtualModuleDirPath() { | ||
| const nodeModulesDir = getNodeModulesDir(); | ||
| const { virtualModuleDir } = getNormalizeModuleFederationOptions(); | ||
| return resolve(nodeModulesDir, virtualModuleDir); | ||
| } | ||
|
|
||
| static findModule(tag: string, str: string = ''): VirtualModule | undefined { | ||
| if (!patternMap[tag]) | ||
| patternMap[tag] = new RegExp(`(.*${packageNameEncode(tag)}(.+?)${packageNameEncode(tag)}.*)`); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.