-
Notifications
You must be signed in to change notification settings - Fork 35
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
Fix yarn workspaces #517
Fix yarn workspaces #517
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
const packageManager = require(path.join(workspace, "package.json")).packageManager; | ||
|
||
if (packageManager) { | ||
const regex = /^([a-zA-Z]+)@/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have an example in the comment above, like "yarn@3.6.4". I initially thought this was related to @xxx/yyy
format.
regex
name doesn't help at all, we can basically inline it IMO.
pathExists(resolve(workspace, "yarn.lock")), | ||
pathExists(resolve(workspace, "package-lock.json")), | ||
pathExists(resolve(workspace, "pnpm-lock.yaml")), | ||
pathExists(resolve(workspace, "bun.lockb")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny thing to consider: we could read the dir and the check existence in JS, should be faster than doing 4 syscalls. Probably doesn't matter though.
import fs from "node:fs/promises";
async f() {
const lockFiles = new Map(
Object.entries({
"yarn.lock": "yarn",
"package-lock.json": "npm",
"pnpm-lock.yaml": "pnpm",
"bun.lockb": "bun",
} as const)
);
const files = await fs.readdir(workspace);
for (const file of files) {
const packageManager = lockFiles.get(file);
if (packageManager) {
return packageManager;
}
}
}
const packageJsonPath = path.join(currentDir, "package.json"); | ||
if (!existsSync(packageJsonPath)) { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just read the file and catch if doesn't exist, something like that:
function walkDirectoriesUntilRoot(
start: string,
shouldStop: (current: string) => boolean
): string | undefined {
let currentDir = start;
let parentDir = path.resolve(currentDir, "..");
while (parentDir !== currentDir) {
currentDir = parentDir;
parentDir = path.resolve(currentDir, "..");
if (shouldStop(currentDir)) {
return currentDir;
}
}
return undefined;
}
function findWorkspace(appRoot: string) {
return walkDirectoriesUntilRoot(appRoot, (currentDir) => {
try {
const packageJsonPath = path.join(currentDir, "package.json");
const hasWorkspaces = require(packageJsonPath).workspaces !== undefined;
return hasWorkspaces;
} catch (error) {
// No package.json
return false;
}
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did that just reaarengedsome functions to reuse code
const openLaunchConfigButton = "Open Launch Configuration"; | ||
window | ||
.showErrorMessage( | ||
`multiple reat-native applications were detected in the workspace, ${appRootCandidates[0]} were chosen, but you can change the root of your application in lunch configuration.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some text that says that in order to get rid of this error, people should specify app root in the launch configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, "lunch configuration" typo. 🥪
This PR probably broke react-native-ide. Now node_modules don't work. I had to downgrade to 0.17 |
@DorianMazur hello, thank you so much for your feedback would you mind sharing React Native IDE logs from 0.18 version with us? you can find them in the output section of your vscode. Why do you think it is this PR that broke it for you? |
I'm using yarn with corepack in a project and it basically can't find node_modules. After downgrading to 0.17 everything works like a charm. I analyzed all commits between versions 0.18 and 0.17 and found only one that refers to node_modules. This one. |
This PR fixes node_modules detection for yarn workspaces and adds a working example of a set up in which workspaces are used.
relates to: #514