-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Discussion] IntelliJ and Yarn 2 integration #499
Comments
Hi Sergey!
It's possible; projects can toggle off import {hydratePnpFile} from '@yarnpkg/pnp';
hydratePnpFile(`${pathToProject}/.pnp.data.json`).then(pnp => {
// Use `pnp` as an instance of the PnP API, cf
// https://next.yarnpkg.com/advanced/pnpapi
});
Yep exactly. I will add a section about this in the documentation, it should definitely be mentioned in at least a few places!
Yep.
Just to be sure we're on the same page: "script" is used here in the sense of "an entry of the It's actually pretty cool because it allows your users to configure exactly how {
"scripts": {
"gulp": "gulp \"$@\" | tee -a /tmp/gulp.log"
}
}
Do you mean something like
Not silly! At the moment we don't have mechanisms to do that (especially since the packages are now kept within their archives). |
Awesome, thanks! Regarding resolution mappings as a JSON file, unfortunately,
Correct. My concert is that, for instance
Not exactly, sorry for being unclear. I meant a simple scenario to run an application. It is done with |
Although it would be possible if Yarn's PnP implementation was the only one, I'm not a fan. There are various reasons for that:
In this particular case I used In general yes users can redefine the commands, but I'm not too concerned - it should be quite uncommon, and it's easy to surface special feedback when it happens by checking whether a script of the given name exists. I see as a feature more than a bug.
I have to check - iirc Gulp is using a package that traverses up the
When working from the CLI you have {
"scripts": {
"start": "node ./index.js"
}
} |
Just to clarify the point of @arcanis about PnP API consumption and generating static file with the format you want: In the example above the PnP tree is traversed, you can add serialization logic to this code and write PnP tree into a static file with the format you want. |
I just double-checked; we're compatible with Gulp, the problem is that For testing we now use dedicated E2E workflows that run every few hours against the latest releases of the projects we watch (Gulp isn't one of them at the moment, but it's probably still relevant enough to be worth tracking). |
Great, thank you guys for the answers! It makes sense.
Ah, looks like I didn't realize fully that PnP is not restricted to Yarn. Could PnP just use different sources (
Oops, right you are! :) In general, redefining commands is usually needed to specify some custom options. Then, if IDE passes the same options, it's unclear what will happen (the first wins, the latter wins or an error is thrown). I will let you know once I have a particular case.
Confirming, it works fine with
Thanks, didn't know about it. It did the trick! Couldn't find it in https://yarnpkg.com/en/docs/cli/. Seems it was added to Yarn 2. |
It's also in Yarn 1, but I forgot to put it on its documentation 😅 The v2 one is here.
Yarn (both v1 and v2) enforce child processes to always call the exact same Node and Yarn binaries as the ones that are running Yarn itself. So if you call Yarn with Node 8, for example, all subprocesses spawned with In fact, |
@Vlasenko Thanks for the link! Tried to consume API in the following way:
and got
What's wrong? |
Conducted the following experiment
Seems Yarn and the child process are run with different Node versions. |
The
I don't reproduce that, be it the v1 or v2 ... 🤔 |
Updating to an up-to date release doesn't help:
|
@arcanis Never mind, it works now after removing ~/.yarnrc that was pointing to yarn v2 installed via |
Opened #502 regarding running Yarn itself and child process with different Node versions. |
IDE needs to index a dependency to provide coding assistance. Trying to fetch a local real path (inside a zip archive) for a package:
The problem is that @arcanis Is it possible to fetch a real path on file system for a package using PnP API? |
Hm not using the API, although you can do it like this: const {statSync} = require(`fs`);
const path = process.argv[2];
const parts = path.split(`/`);
let current = ``;
let base = null;
for (let t = 0; t < parts.length; ++t) {
current += `/${parts[t]}`;
if (statSync(current).isFile()) {
base = current;
break;
}
}
console.log(base); |
IIUC, this code returns |
Seems like IDE needs to repeat |
Right, virtual paths mess with that approach 🤔 Right now I think replicating the VirtualFS logic is the simplest way to unblock this. We could fix that for zip archives (by mounting the virtual paths into the archives themselves, so you'd encounter the archive before the virtual folder), but that wouldn't work for workspaces. |
Replicating the VirtualFS logic is done and it works. Would be great to get rid of this replication in future, because it feels a bit unsafe. Are there any chances to hit wrong .zip archive by simply removing |
Simply removing this part isn't enough, in particular because the archives can be located outside of the
So for example:
Note that I understand your concerns - I'll try to think of a long-term solution to avoid having to hardcode this logic in the code. |
@arcanis Small questions:
|
Better to read the version from the package files. The PnP API itself only deals with packages dependencies and locations, not their metadata per se.
By default yes, but the |
Thanks, I see. Then, maybe |
Often, but there might be other |
I'm trying to locate all yarn internal files inside project to exclude them from indexing, so symbols defined in these files are not suggested in user's code. Currently, |
Oh I see - for this purpose, |
Alright, thanks! JSON files can be kept as is (not excluded), because they are not indexed. BTW, curious, is |
Yep! I misremembered the name, it's |
Fyi, new Yarn builds (not yet released but you can test them with |
@arcanis Thanks! It works fine. What does mean the versions object in the function's documentation?
A general question regarding And a related question: am I right that Couldn't find the exact answers in the docs, but I suspect the answers could be concluded. |
It's the
Yep! The
Yep, the return of Btw, do you have a rough idea when WebStorm will release a beta with PnP support? I have some engineers at my company that are pretty excited about it! 😄 |
Cool, thanks! I'm detecting I hope the next WebStorm 2019.3 EAP (planned for the next week) will have more or less ready to use PnP support. Also, https://youtrack.jetbrains.com/issue/WEB-35034 will be updated, you will receive a notification! ;) |
Eheh I already lurk around this issue 😄 Awesome, thanks!
That's fine - the version number may be useful for backward compatibility (for example later on we might add options, in which case you'll be able to check the version field to know whether they are supported by the API you work with), but for the first version a good old |
@arcanis Do you know if it's possible to run ESLint in a default create-react-app project (with deps installed by Yarn PnP)? Currently, it seems to be not working (https://youtrack.jetbrains.com/issue/WEB-42177). |
I think this problem is because the default Create-React-App ESLint configuration relies on hoisting to work properly. The Imo the best solution would come from CRA, by exposing a new file in {
"eslintConfig": {
"extends": "react-scripts/eslint-config"
}
} Unfortunately the problem is that ESLint currently always prefixes the package name with The second best solution is to simply add cc @iansu - do you have another idea? |
Thanks, interesting. IIUC, both solutions assume that {
"dependencies": {
"eslint": "*",
"eslint-config-react-scripts": "*",
"... other deps ..."
},
"eslintConfig": {
"extends": "react-scripts"
}
} Will it work? Is there an issue to track ESLint support in create-react-app? Thanks! |
WebStorm 2019.3 EAP build 193.5096.13 brings supports for Yarn PnP. 🎉 |
Reviving this old discussion with a question to its contributors: Have you encountered a problem where IntelliJ (and VS Code!) are constantly re-indexing stuff? I can only tab out of WebStorm (which - on changes - will save unsaved files) and when I come back it'll reindex. Every time. This is with yarn berry zero-install and I've reinstalled to no avail, and this happens on multiple computers. Also, when I monitor my project's files with chokidar-cli, i see that it's constantly changing/touching the cache files, without me making any changes. This stops immediately when I close the IDE. Excerpt:
I know this may also belong in JetBrain's issue trackers but I think more relevant people will see it here. edit: In classic rubberduck manner, the fact that I posted it here made me think about it in new ways and I found the culprit: The official NX plugin for WebStorm (and, I would assume, for VSCode). It seems to be having trouble with PNP. Disabling it fixed the re-indexing issue. Hope this will help someone! nrwl/nx-console#2062 |
Opening this issue to discuss ways to integrate IntelliJ/WebStorm and Yarn 2 (with PnP) (https://youtrack.jetbrains.com/issue/WEB-35034). // cc @arcanis
Some questions regarding initial integration:
Is possible to always generate resolution mappings as a JSON file under .pnp/ folder? That would allow IDE to not evaluate .pnp.js file and simplify obtaining whole dependency tree. If it's impossible right now, what do you think about adding it in future versions?
IDE needs to index dependencies to provide coding assistance. Tried https://github.com/yarnpkg/pnp-sample-app (with
yarn --version
: 2.0.0-rc.6). For example, I have the following output:Am I right that the tarballs downloaded from the registry are not unpacked anymore in yarn 2? Couldn't find such info at https://next.yarnpkg.com/features/pnp.
Is there a way to access a particular file in a dependency? Previously, IDE could run
/path/to/node <node options> /path/to/app/node_modules/gulp/bin/gulp.js <gulp options>
. Should it be replaced withyarn run <binary name exposed by a dependency=gulp>
?According to
yarn run -h=1
, it says thatyarn run gulp
will try to run a script with the same name first. It feels a bit unsafe to run an arbitrary command. Probably, not a big deal, however is it possible to ensure that a binary exposed by a local dependency is run?What's the recommended way to run a a local application (not a local dependency)?
It might sound silly, but is there an option to create symlinks for each dependency to have node_modules with symlinks?
The text was updated successfully, but these errors were encountered: