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

feat: support yarn PnP out of box, propagate PnP runtime #98

Merged
merged 8 commits into from Aug 10, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-comics-smell.md
@@ -0,0 +1,5 @@
---
"synckit": patch
---

feat: support yarn PnP out of box, propagate PnP runtime
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -96,6 +96,7 @@
"deasync": "^0.1.27",
"esbuild-register": "^3.3.3",
"esbuild-runner": "^2.2.1",
"execa": "^6.1.0",
"jest": "^28.1.3",
"patch-package": "^6.4.7",
"sync-threads": "^1.0.1",
Expand Down
17 changes: 17 additions & 0 deletions src/index.ts
Expand Up @@ -42,6 +42,7 @@ const {
SYNCKIT_TIMEOUT,
SYNCKIT_EXEC_ARGV,
SYNCKIT_TS_RUNNER,
NODE_OPTIONS,
} = process.env

export const DEFAULT_BUFFER_SIZE = SYNCKIT_BUFFER_SIZE
Expand Down Expand Up @@ -209,6 +210,22 @@ const setupTsRunner = (
}
}

/* istanbul ignore if -- https://github.com/facebook/jest/issues/5274 */
if (process.versions.pnp) {
const nodeOptions = NODE_OPTIONS?.split(/\s+/)
const pnpApiPath = cjsRequire.resolve('pnpapi')
if (
!nodeOptions?.some(
(option, index) =>
['-r', '--require'].includes(option) &&
pnpApiPath === cjsRequire.resolve(nodeOptions[index + 1]),
) &&
!execArgv.includes(pnpApiPath)
) {
execArgv = ['-r', pnpApiPath, ...execArgv]
}
}

return {
ext,
isTs,
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/yarn-pnp.spec.ts
@@ -0,0 +1,11 @@
import { resolve } from 'node:path'

import { execaNode } from 'execa'

test('yarn-pnp', async () => {
const { stdout } = await execaNode('index.js', [], {
nodeOptions: ['-r', './.pnp.cjs'],
cwd: resolve('test/fixtures/yarn-pnp'),
})
expect(stdout).toBe([1, 2, 5].join(' '))
})