From ad2db042bd215797f8118e3a5169959396b1e451 Mon Sep 17 00:00:00 2001 From: Andre Wachsmuth Date: Tue, 5 Aug 2025 21:13:43 +0200 Subject: [PATCH] Add documentation for opts.conditions of resolveRequest from pnpapi Is the `conditions` option for the `resolveRequest` function from the pnpapi public? It's currently not documented anywhere. I came across this as part of visjs/vis-timeline#1898. `resolveRequest` would not resolve the request properly, complaining that it's not defined in the `exports` conditions of the `package.json`. Then I looked through the .pnpapi.cjs code and found that `resolveRequest` has a `conditions` option that defaults to `node, require`. After setting it to `import`, it could resolve it successfully. --- .../docusaurus/docs/advanced/03-pnp/pnp-api.mdx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/docs/advanced/03-pnp/pnp-api.mdx b/packages/docusaurus/docs/advanced/03-pnp/pnp-api.mdx index b5433338194b..d5f0ee19af10 100644 --- a/packages/docusaurus/docs/advanced/03-pnp/pnp-api.mdx +++ b/packages/docusaurus/docs/advanced/03-pnp/pnp-api.mdx @@ -223,6 +223,10 @@ Note that in some cases you may just have a folder to work with as `issuer` para This function will return `null` if the request is a builtin module, unless `considerBuiltins` is set to `false`. +Options: + +- `considerBuiltins`: Whether to consider builtins during resolution, such as `node:fs` or `node:path`. + ### `resolveUnqualified(...)` ```ts @@ -245,10 +249,14 @@ Might very well be resolved into: /my/cache/lodash/1.0.0/node_modules/lodash/uniq/index.js ``` +Options: + +- `extensions`: A list of file extensions to try and resolve, such as [".js", ".ts"]. + ### `resolveRequest(...)` ```ts -export function resolveRequest(request: string, issuer: string | null, opts?: {considerBuiltins?: boolean, extensions?: string[]]}): string | null; +export function resolveRequest(request: string, issuer: string | null, opts?: {considerBuiltins?: boolean, extensions?: string[]], conditions: Set}): string | null; ``` The `resolveRequest` function is a wrapper around both `resolveToUnqualified` and `resolveUnqualified`. In essence, it's a bit like calling `resolveUnqualified(resolveToUnqualified(...))`, but shorter. @@ -269,6 +277,12 @@ Might very well be resolved into: This function will return `null` if the request is a builtin module, unless `considerBuiltins` is set to `false`. +Options: + +- `considerBuiltins`: Whether to consider builtins during resolution, such as `node:fs` or `node:path`. +- `extensions`: A list of file extensions to try and resolve, such as [".js", ".ts"]. +- `conditions`: Export conditions to consider, when the `package.json` contains an `exports` field. Defaults to `["node", "require"]`. + ### `resolveVirtual(...)` ```ts