Skip to content
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

Support Yarn PnP Imports #2196

Merged
merged 2 commits into from
Nov 14, 2023
Merged

Support Yarn PnP Imports #2196

merged 2 commits into from
Nov 14, 2023

Conversation

DavidArchibald
Copy link
Contributor

@DavidArchibald DavidArchibald commented Nov 8, 2023

Resolves #1514 which describes the crux of the issue. Specifically imports in your svelete.config.js won't be able to resolve because they use ESM imports and Node doesn't have a loader set up.

This is my first contribution to the repo so let me know if anything doesn't fit the style etc.!

The PR itself is fairly simple but it shouldn't be merged until yarnpkg/berry#5953 is ready as otherwise yarn dlx @yarnpkg/sdks vscode won't set up the VSCode setting. Arguably more importantly if the --loader ./.pnp.loader.mjs approach is inappropriate here I'm sure they'll let me know on that PR!

@dummdidumm
Copy link
Member

Code looks good apart from one thing - could you add that setting to the restrictedConfigurations setting in that same file further above?

The primary purpose of this is to be able to add a Yarn loader for mjs.
@DavidArchibald
Copy link
Contributor Author

Sounds good! Should be done.

I also realised that the ls-path setting uses hyphens and I was using camelCase so I went ahead and renamed it to runtime-args. I went ahead and force pushed the change because I figured two commits was probably overkill for this PR but maybe squashing is the norm?

@dummdidumm
Copy link
Member

Re commits: Sqash-merging is the norm here, so don't worry about the commit history 😄

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👍 Let me know when the changes have landed on the other end and we can merge this one

arcanis pushed a commit to yarnpkg/berry that referenced this pull request Nov 13, 2023
**What's the problem this PR addresses?**
My PR sveltejs/language-tools#2196 introduces
a small change alongside a new setting that allows
sveltejs-language-tools to resolve PnP in ESM files, most importantly in
a `svelte.config.js`. Please note that this PR shouldn't go in until
that PR is ready as otherwise the Svelte language server itself will not
have the setting available.

Also I'm no expert in Yarn PnP so if this is the wrong implementation
avenue I would welcome advice!

**How did you fix it?**
The main portion of the solution is in the linked PR. The addition here
is to set `svelte.language-server.runtime-args` to `["--loader",
"./.pnp.loader.mjs"]`.

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
@DavidArchibald
Copy link
Contributor Author

It's been merged in yarnpkg/berry!

@DavidArchibald
Copy link
Contributor Author

DavidArchibald commented Nov 13, 2023

It looks like the tests are now failing:

packages/language-server test:   1) CompletionProviderImpl
packages/language-server test:        doesnt suggest svelte auto import when already other import with same name present:
packages/language-server test:      Error: Could not find source file: '/home/runner/work/language-tools/language-tools/packages/language-server/test/plugins/typescript/testfiles/completions/ScndImport.svelte'.
packages/language-server test:       at getValidSourceFile (/home/runner/work/language-tools/language-tools/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:141757:24)
packages/language-server test:       at Object.getCompletionsAtPosition2 [as getCompletionsAtPosition] (/home/runner/work/language-tools/language-tools/node_modules/.pnpm/[email protected]/node_modules/typescript/lib/typescript.js:142039:9)
packages/language-server test:       at CompletionsProviderImpl.getCompletions (src/plugins/typescript/features/CompletionProvider.ts:208:31)
packages/language-server test:       at async openFileToBeImported (test/plugins/typescript/features/CompletionProvider.test.ts:793:9)
packages/language-server test:       at async Context.<anonymous> (test/plugins/typescript/features/CompletionProvider.test.ts:899:9)
packages/language-server test: Initialize new ts service at  /home/runner/work/language-tools/language-tools/packages/language-server/test/plugins/typescript/testfiles/tsconfig.json
packages/language-server test: Trying to load configs for /home/runner/work/language-tools/language-tools/packages/language-server/test/plugins/typescript/testfiles
packages/language-server test: No svelte.config.js found. Using https://github.com/sveltejs/svelte-preprocess as fallback
packages/language-server test: SnapshotManager File Statistics:
packages/language-server test: Project files: 132
packages/language-server test: Svelte files: 113
packages/language-server test: From node_modules: 0
packages/language-server test: Total: 132
packages/language-server test: Failed

I'm confused how I could've changed anything that'd impact this test though because the behaviour when not configured should be identical. I suppose I reordered the flags, they used to be ["--no-lazy", "--experimental-modules", `--inspect=${port}`] and now will be ["--no-lazy", `--inspect=${port}`, "--experimental-modules"] in debug mode. I feel like that shouldn't have made a test start failing though.

@jasonlyu123
Copy link
Member

Don't worry about this one. It's a flaky test. It failed in the master branch a few times as well. It's likely a race condition that only happened in the tests. It is not a blocking issue. I'll try to fix it later.

@dummdidumm dummdidumm merged commit d7457f4 into sveltejs:master Nov 14, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yarn 2 PnP ERR_MODULE_NOT_FOUND in SvelteKit
3 participants