Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 121 additions & 2 deletions .pnp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .yarn/versions/4d235eca.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
releases:
"@yarnpkg/plugin-compat": prerelease
"@yarnpkg/pnpify": prerelease

declined:
- "@yarnpkg/plugin-node-modules"
- vscode-zipfs
- "@yarnpkg/builder"
- "@yarnpkg/cli"
- "@yarnpkg/pnp"
37 changes: 37 additions & 0 deletions packages/gatsby/content/advanced/editor-sdks.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,43 @@ yarn pnpify --sdk

3. Set [`tsserver.tsdk`](https://github.com/neoclide/coc-tsserver#configuration-options) to `.vscode/pnpify/typescript/lib`

### Emacs

The SDK comes with a typescript-language-server wrapper which enables you to use the ts-ls LSP client.

1. Add PnPify to your dependencies:

```bash
yarn add @yarnpkg/pnpify
```

2. Run the following command, which will generate a new directory called `.vscode/pnpify`:

```bash
yarn pnpify --sdk
```

3. Create a `.dir-locals.el` with the following content to enable Flycheck and LSP support:

```lisp
((typescript-mode
. (
;; Enable typescript-language-server and eslint LSP clients.
(lsp-enabled-clients . (ts-ls eslint))
(eval . (let ((project-directory (car (dir-locals-find-file "."))))
(set (make-local-variable 'flycheck-javascript-eslint-executable)
(concat project-directory ".vscode/pnpify/eslint/bin/eslint.js"))

(lsp-dependency 'typescript-language-server
`(:system ,(concat project-directory ".vscode/pnpify/typescript-language-server/lib/cli.js")))
(lsp-dependency 'typescript
`(:system ,(concat project-directory ".vscode/pnpify/typescript/bin/tsserver")))

;; Re-(start) LSP to pick up the dependency changes above.
(lsp)
)))))
```

## Caveat

- Since the Yarn packages are kept within their archives, editors need to understand how to work with such paths should you want to actually open the files (for example when command-clicking on an import path originating from an external package). This can only be implemented by those editors, and we can't do much more than opening issues to ask for this feature to be implemented (for example, here's the VSCode issue: [#75559](https://github.com/microsoft/vscode/issues/75559)).
Expand Down
7 changes: 7 additions & 0 deletions packages/plugin-compat/sources/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ export const packageExtensions: Array<[string, any]> = [
[`@types/keyv`]: `^3.1.1`,
},
}],
// https://github.com/theia-ide/typescript-language-server/issues/144
[`typescript-language-server@*`, {
dependencies: {
[`vscode-jsonrpc`]: `^5.0.1`,
[`vscode-languageserver-protocol`]: `^3.15.0`,
},
}],
];
55 changes: 32 additions & 23 deletions packages/yarnpkg-pnpify/sources/generateSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,29 +131,6 @@ class Wrapper {
}
}

const generateTypescriptWrapper = async (pnpApi: PnpApi, target: PortablePath) => {
const wrapper = new Wrapper(`typescript` as PortablePath, {pnpApi, target});

await wrapper.writeManifest();

await wrapper.writeBinary(`bin/tsc` as PortablePath);
await wrapper.writeBinary(`bin/tsserver` as PortablePath);

await wrapper.writeFile(`lib/tsc.js` as PortablePath);
await wrapper.writeFile(`lib/tsserver.js` as PortablePath);
await wrapper.writeFile(`lib/typescript.js` as PortablePath);

await addVSCodeWorkspaceSettings(pnpApi, {
[`typescript.tsdk`]: npath.fromPortablePath(
ppath.dirname(
wrapper.getProjectPathTo(
`lib/tsserver.js` as PortablePath,
),
),
),
});
};

export const generateEslintWrapper = async (pnpApi: PnpApi, target: PortablePath) => {
const wrapper = new Wrapper(`eslint` as PortablePath, {pnpApi, target});

Expand Down Expand Up @@ -189,9 +166,41 @@ export const generatePrettierWrapper = async (pnpApi: PnpApi, target: PortablePa
});
};

export const generateTypescriptLanguageServerWrapper = async (pnpApi: PnpApi, target: PortablePath) => {
const wrapper = new Wrapper(`typescript-language-server` as PortablePath, {pnpApi, target});

await wrapper.writeManifest();

await wrapper.writeBinary(`lib/cli.js` as PortablePath);
};

const generateTypescriptWrapper = async (pnpApi: PnpApi, target: PortablePath) => {
const wrapper = new Wrapper(`typescript` as PortablePath, {pnpApi, target});

await wrapper.writeManifest();

await wrapper.writeBinary(`bin/tsc` as PortablePath);
await wrapper.writeBinary(`bin/tsserver` as PortablePath);

await wrapper.writeFile(`lib/tsc.js` as PortablePath);
await wrapper.writeFile(`lib/tsserver.js` as PortablePath);
await wrapper.writeFile(`lib/typescript.js` as PortablePath);

await addVSCodeWorkspaceSettings(pnpApi, {
[`typescript.tsdk`]: npath.fromPortablePath(
ppath.dirname(
wrapper.getProjectPathTo(
`lib/tsserver.js` as PortablePath,
),
),
),
});
};

const SDKS: Array<[string, (pnpApi: PnpApi, target: PortablePath) => Promise<void>]> = [
[`eslint`, generateEslintWrapper],
[`prettier`, generatePrettierWrapper],
[`typescript-language-server`, generateTypescriptLanguageServerWrapper],
[`typescript`, generateTypescriptWrapper],
];

Expand Down